Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / block / amiflop.c
index 42c1e56..2a8af68 100644 (file)
 #define FD_HD_3        0x55555555  /* high-density 3.5" (1760K) drive */
 #define FD_DD_5        0xaaaaaaaa  /* double-density 5.25" (440K) drive */
 
-static long int fd_def_df0 = FD_DD_3;     /* default for df0 if it doesn't identify */
+static unsigned long int fd_def_df0 = FD_DD_3;     /* default for df0 if it doesn't identify */
 
-MODULE_PARM(fd_def_df0,"l");
+module_param(fd_def_df0, ulong, 0);
 MODULE_LICENSE("GPL");
 
 static struct request_queue *floppy_queue;
@@ -131,7 +131,7 @@ static struct fd_drive_type drive_types[] = {
 { FD_DD_5,     "DD 5.25", 40, 2, 14716, 13630, 1, 40, 81, 6, 30, 2},
 { FD_NODRIVE, "No Drive", 0, 0,     0,     0, 0,  0,  0,  0,  0, 0}
 };
-static int num_dr_types = sizeof(drive_types) / sizeof(drive_types[0]);
+static int num_dr_types = ARRAY_SIZE(drive_types);
 
 static int amiga_read(int), dos_read(int);
 static void amiga_write(int), dos_write(int);
@@ -163,7 +163,7 @@ static int writepending;
 static int writefromint;
 static char *raw_buf;
 
-static spinlock_t amiflop_lock = SPIN_LOCK_UNLOCKED;
+static DEFINE_SPINLOCK(amiflop_lock);
 
 #define RAW_BUF_SIZE 30000  /* size of raw disk data */
 
@@ -194,6 +194,8 @@ static DECLARE_WAIT_QUEUE_HEAD(ms_wait);
  */
 #define MAX_ERRORS 12
 
+#define custom amiga_custom
+
 /* Prevent "aliased" accesses. */
 static int fd_ref[4] = { 0,0,0,0 };
 static int fd_device[4] = { 0, 0, 0, 0 };
@@ -386,16 +388,6 @@ static void fd_motor_off(unsigned long drive)
        fd_select(drive);
        udelay (1);
        fd_deselect(drive);
-
-#ifdef MODULE
-/*
-  this is the last interrupt for any drive access, happens after
-  release (from floppy_off). So we have to wait until now to decrease
-  the use count.
-*/
-       if (decusecount)
-               MOD_DEC_USE_COUNT;
-#endif
 }
 
 static void floppy_off (unsigned int nr)
@@ -1434,25 +1426,24 @@ static void do_fd_request(request_queue_t * q)
        redo_fd_request();
 }
 
+static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo)
+{
+       int drive = MINOR(bdev->bd_dev) & 3;
+
+       geo->heads = unit[drive].type->heads;
+       geo->sectors = unit[drive].dtype->sects * unit[drive].type->sect_mult;
+       geo->cylinders = unit[drive].type->tracks;
+       return 0;
+}
+
 static int fd_ioctl(struct inode *inode, struct file *filp,
                    unsigned int cmd, unsigned long param)
 {
        int drive = iminor(inode) & 3;
        static struct floppy_struct getprm;
+       void __user *argp = (void __user *)param;
 
        switch(cmd){
-       case HDIO_GETGEO:
-       {
-               struct hd_geometry loc;
-               loc.heads = unit[drive].type->heads;
-               loc.sectors = unit[drive].dtype->sects * unit[drive].type->sect_mult;
-               loc.cylinders = unit[drive].type->tracks;
-               loc.start = 0;
-               if (copy_to_user((void *)param, (void *)&loc,
-                                sizeof(struct hd_geometry)))
-                       return -EFAULT;
-               break;
-       }
        case FDFMTBEG:
                get_fdc(drive);
                if (fd_ref[drive] > 1) {
@@ -1496,9 +1487,7 @@ static int fd_ioctl(struct inode *inode, struct file *filp,
                getprm.head=unit[drive].type->heads;
                getprm.sect=unit[drive].dtype->sects * unit[drive].type->sect_mult;
                getprm.size=unit[drive].blocks;
-               if (copy_to_user((void *)param,
-                                (void *)&getprm,
-                                sizeof(struct floppy_struct)))
+               if (copy_to_user(argp, &getprm, sizeof(struct floppy_struct)))
                        return -EFAULT;
                break;
        case FDSETPRM:
@@ -1510,8 +1499,7 @@ static int fd_ioctl(struct inode *inode, struct file *filp,
                break;
 #ifdef RAW_IOCTL
        case IOCTL_RAW_TRACK:
-               if (copy_to_user((void *)param, raw_buf,
-                                unit[drive].type->read_size))
+               if (copy_to_user(argp, raw_buf, unit[drive].type->read_size))
                        return -EFAULT;
                else
                        return unit[drive].type->read_size;
@@ -1590,10 +1578,6 @@ static int floppy_open(struct inode *inode, struct file *filp)
        local_irq_save(flags);
        fd_ref[drive]++;
        fd_device[drive] = system;
-#ifdef MODULE
-       if (unit[drive].motor == 0)
-               MOD_INC_USE_COUNT;
-#endif
        local_irq_restore(flags);
 
        unit[drive].dtype=&data_types[system];
@@ -1666,15 +1650,10 @@ static struct block_device_operations floppy_fops = {
        .open           = floppy_open,
        .release        = floppy_release,
        .ioctl          = fd_ioctl,
+       .getgeo         = fd_getgeo,
        .media_changed  = amiga_floppy_change,
 };
 
-void __init amiga_floppy_setup (char *str, int *ints)
-{
-       printk (KERN_INFO "amiflop: Setting default df0 to %x\n", ints[1]);
-       fd_def_df0 = ints[1];
-}
-
 static int __init fd_probe_drives(void)
 {
        int drive,drives,nomem;
@@ -1830,7 +1809,6 @@ out_blkdev:
 }
 
 #ifdef MODULE
-#include <linux/version.h>
 
 int init_module(void)
 {
@@ -1839,6 +1817,7 @@ int init_module(void)
        return amiga_floppy_init();
 }
 
+#if 0 /* not safe to unload */
 void cleanup_module(void)
 {
        int i;
@@ -1860,3 +1839,19 @@ void cleanup_module(void)
        unregister_blkdev(FLOPPY_MAJOR, "fd");
 }
 #endif
+
+#else
+static int __init amiga_floppy_setup (char *str)
+{
+       int n;
+       if (!MACH_IS_AMIGA)
+               return 0;
+       if (!get_option(&str, &n))
+               return 0;
+       printk (KERN_INFO "amiflop: Setting default df0 to %x\n", n);
+       fd_def_df0 = n;
+       return 1;
+}
+
+__setup("floppy=", amiga_floppy_setup);
+#endif