[PATCH] unused label in drivers/block/cciss.
[safe/jmp/linux-2.6] / drivers / block / pktcdvd.c
index 93e44d0..a04f606 100644 (file)
 #include <linux/seq_file.h>
 #include <linux/miscdevice.h>
 #include <linux/suspend.h>
+#include <linux/mutex.h>
 #include <scsi/scsi_cmnd.h>
 #include <scsi/scsi_ioctl.h>
+#include <scsi/scsi.h>
 
 #include <asm/uaccess.h>
 
@@ -80,7 +82,7 @@
 static struct pktcdvd_device *pkt_devs[MAX_WRITERS];
 static struct proc_dir_entry *pkt_proc;
 static int pkt_major;
-static struct semaphore ctl_mutex;     /* Serialize open/close/setup/teardown */
+static struct mutex ctl_mutex; /* Serialize open/close/setup/teardown */
 static mempool_t *psd_pool;
 
 
@@ -228,16 +230,6 @@ static int pkt_grow_pktlist(struct pktcdvd_device *pd, int nr_packets)
        return 1;
 }
 
-static void *pkt_rb_alloc(gfp_t gfp_mask, void *data)
-{
-       return kmalloc(sizeof(struct pkt_rb_node), gfp_mask);
-}
-
-static void pkt_rb_free(void *ptr, void *data)
-{
-       kfree(ptr);
-}
-
 static inline struct pkt_rb_node *pkt_rbtree_next(struct pkt_rb_node *node)
 {
        struct rb_node *n = rb_next(&node->rb_node);
@@ -380,6 +372,7 @@ static int pkt_generic_packet(struct pktcdvd_device *pd, struct packet_command *
        memcpy(rq->cmd, cgc->cmd, CDROM_PACKET_SIZE);
        if (sizeof(rq->cmd) > CDROM_PACKET_SIZE)
                memset(rq->cmd + CDROM_PACKET_SIZE, 0, sizeof(rq->cmd) - CDROM_PACKET_SIZE);
+       rq->cmd_len = COMMAND_SIZE(rq->cmd[0]);
 
        rq->ref_count++;
        rq->flags |= REQ_NOMERGE;
@@ -1495,40 +1488,42 @@ static int pkt_set_write_settings(struct pktcdvd_device *pd)
 }
 
 /*
- * 0 -- we can write to this track, 1 -- we can't
+ * 1 -- we can write to this track, 0 -- we can't
  */
-static int pkt_good_track(track_information *ti)
+static int pkt_writable_track(struct pktcdvd_device *pd, track_information *ti)
 {
-       /*
-        * only good for CD-RW at the moment, not DVD-RW
-        */
+       switch (pd->mmc3_profile) {
+               case 0x1a: /* DVD+RW */
+               case 0x12: /* DVD-RAM */
+                       /* The track is always writable on DVD+RW/DVD-RAM */
+                       return 1;
+               default:
+                       break;
+       }
 
-       /*
-        * FIXME: only for FP
-        */
-       if (ti->fp == 0)
+       if (!ti->packet || !ti->fp)
                return 0;
 
        /*
         * "good" settings as per Mt Fuji.
         */
-       if (ti->rt == 0 && ti->blank == 0 && ti->packet == 1)
-               return 0;
+       if (ti->rt == 0 && ti->blank == 0)
+               return 1;
 
-       if (ti->rt == 0 && ti->blank == 1 && ti->packet == 1)
-               return 0;
+       if (ti->rt == 0 && ti->blank == 1)
+               return 1;
 
-       if (ti->rt == 1 && ti->blank == 0 && ti->packet == 1)
-               return 0;
+       if (ti->rt == 1 && ti->blank == 0)
+               return 1;
 
        printk("pktcdvd: bad state %d-%d-%d\n", ti->rt, ti->blank, ti->packet);
-       return 1;
+       return 0;
 }
 
 /*
- * 0 -- we can write to this disc, 1 -- we can't
+ * 1 -- we can write to this disc, 0 -- we can't
  */
-static int pkt_good_disc(struct pktcdvd_device *pd, disc_information *di)
+static int pkt_writable_disc(struct pktcdvd_device *pd, disc_information *di)
 {
        switch (pd->mmc3_profile) {
                case 0x0a: /* CD-RW */
@@ -1537,10 +1532,10 @@ static int pkt_good_disc(struct pktcdvd_device *pd, disc_information *di)
                case 0x1a: /* DVD+RW */
                case 0x13: /* DVD-RW */
                case 0x12: /* DVD-RAM */
-                       return 0;
+                       return 1;
                default:
                        VPRINTK("pktcdvd: Wrong disc profile (%x)\n", pd->mmc3_profile);
-                       return 1;
+                       return 0;
        }
 
        /*
@@ -1549,25 +1544,25 @@ static int pkt_good_disc(struct pktcdvd_device *pd, disc_information *di)
         */
        if (di->disc_type == 0xff) {
                printk("pktcdvd: Unknown disc. No track?\n");
-               return 1;
+               return 0;
        }
 
        if (di->disc_type != 0x20 && di->disc_type != 0) {
                printk("pktcdvd: Wrong disc type (%x)\n", di->disc_type);
-               return 1;
+               return 0;
        }
 
        if (di->erasable == 0) {
                printk("pktcdvd: Disc not erasable\n");
-               return 1;
+               return 0;
        }
 
        if (di->border_status == PACKET_SESSION_RESERVED) {
                printk("pktcdvd: Can't write to last track (reserved)\n");
-               return 1;
+               return 0;
        }
 
-       return 0;
+       return 1;
 }
 
 static int pkt_probe_settings(struct pktcdvd_device *pd)
@@ -1592,23 +1587,9 @@ static int pkt_probe_settings(struct pktcdvd_device *pd)
                return ret;
        }
 
-       if (pkt_good_disc(pd, &di))
-               return -ENXIO;
+       if (!pkt_writable_disc(pd, &di))
+               return -EROFS;
 
-       switch (pd->mmc3_profile) {
-               case 0x1a: /* DVD+RW */
-                       printk("pktcdvd: inserted media is DVD+RW\n");
-                       break;
-               case 0x13: /* DVD-RW */
-                       printk("pktcdvd: inserted media is DVD-RW\n");
-                       break;
-               case 0x12: /* DVD-RAM */
-                       printk("pktcdvd: inserted media is DVD-RAM\n");
-                       break;
-               default:
-                       printk("pktcdvd: inserted media is CD-R%s\n", di.erasable ? "W" : "");
-                       break;
-       }
        pd->type = di.erasable ? PACKET_CDRW : PACKET_CDR;
 
        track = 1; /* (di.last_track_msb << 8) | di.last_track_lsb; */
@@ -1617,9 +1598,9 @@ static int pkt_probe_settings(struct pktcdvd_device *pd)
                return ret;
        }
 
-       if (pkt_good_track(&ti)) {
+       if (!pkt_writable_track(pd, &ti)) {
                printk("pktcdvd: can't write to this track\n");
-               return -ENXIO;
+               return -EROFS;
        }
 
        /*
@@ -1633,7 +1614,7 @@ static int pkt_probe_settings(struct pktcdvd_device *pd)
        }
        if (pd->settings.size > PACKET_MAX_SECTORS) {
                printk("pktcdvd: packet size is too big\n");
-               return -ENXIO;
+               return -EROFS;
        }
        pd->settings.fp = ti.fp;
        pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
@@ -1675,7 +1656,7 @@ static int pkt_probe_settings(struct pktcdvd_device *pd)
                        break;
                default:
                        printk("pktcdvd: unknown data mode\n");
-                       return 1;
+                       return -EROFS;
        }
        return 0;
 }
@@ -1886,7 +1867,7 @@ static int pkt_open_write(struct pktcdvd_device *pd)
 
        if ((ret = pkt_probe_settings(pd))) {
                VPRINTK("pktcdvd: %s failed probe\n", pd->name);
-               return -EROFS;
+               return ret;
        }
 
        if ((ret = pkt_set_write_settings(pd))) {
@@ -2028,7 +2009,7 @@ static int pkt_open(struct inode *inode, struct file *file)
 
        VPRINTK("pktcdvd: entering open\n");
 
-       down(&ctl_mutex);
+       mutex_lock(&ctl_mutex);
        pd = pkt_find_dev_from_minor(iminor(inode));
        if (!pd) {
                ret = -ENODEV;
@@ -2054,14 +2035,14 @@ static int pkt_open(struct inode *inode, struct file *file)
                set_blocksize(inode->i_bdev, CD_FRAMESIZE);
        }
 
-       up(&ctl_mutex);
+       mutex_unlock(&ctl_mutex);
        return 0;
 
 out_dec:
        pd->refcnt--;
 out:
        VPRINTK("pktcdvd: failed open (%d)\n", ret);
-       up(&ctl_mutex);
+       mutex_unlock(&ctl_mutex);
        return ret;
 }
 
@@ -2070,28 +2051,18 @@ static int pkt_close(struct inode *inode, struct file *file)
        struct pktcdvd_device *pd = inode->i_bdev->bd_disk->private_data;
        int ret = 0;
 
-       down(&ctl_mutex);
+       mutex_lock(&ctl_mutex);
        pd->refcnt--;
        BUG_ON(pd->refcnt < 0);
        if (pd->refcnt == 0) {
                int flush = test_bit(PACKET_WRITABLE, &pd->flags);
                pkt_release_dev(pd, flush);
        }
-       up(&ctl_mutex);
+       mutex_unlock(&ctl_mutex);
        return ret;
 }
 
 
-static void *psd_pool_alloc(gfp_t gfp_mask, void *data)
-{
-       return kmalloc(sizeof(struct packet_stacked_data), gfp_mask);
-}
-
-static void psd_pool_free(void *ptr, void *data)
-{
-       kfree(ptr);
-}
-
 static int pkt_end_io_read_cloned(struct bio *bio, unsigned int bytes_done, int err)
 {
        struct packet_stacked_data *psd = bio->bi_private;
@@ -2484,7 +2455,8 @@ static int pkt_setup_dev(struct pkt_ctrl_command *ctrl_cmd)
        if (!pd)
                return ret;
 
-       pd->rb_pool = mempool_create(PKT_RB_POOL_SIZE, pkt_rb_alloc, pkt_rb_free, NULL);
+       pd->rb_pool = mempool_create_kmalloc_pool(PKT_RB_POOL_SIZE,
+                                                 sizeof(struct pkt_rb_node));
        if (!pd->rb_pool)
                goto out_mem;
 
@@ -2524,7 +2496,7 @@ static int pkt_setup_dev(struct pkt_ctrl_command *ctrl_cmd)
        return 0;
 
 out_new_dev:
-       blk_put_queue(disk->queue);
+       blk_cleanup_queue(disk->queue);
 out_mem2:
        put_disk(disk);
 out_mem:
@@ -2565,7 +2537,7 @@ static int pkt_remove_dev(struct pkt_ctrl_command *ctrl_cmd)
        DPRINTK("pktcdvd: writer %s unmapped\n", pd->name);
 
        del_gendisk(pd->disk);
-       blk_put_queue(pd->disk->queue);
+       blk_cleanup_queue(pd->disk->queue);
        put_disk(pd->disk);
 
        pkt_devs[idx] = NULL;
@@ -2606,21 +2578,21 @@ static int pkt_ctl_ioctl(struct inode *inode, struct file *file, unsigned int cm
        case PKT_CTRL_CMD_SETUP:
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
-               down(&ctl_mutex);
+               mutex_lock(&ctl_mutex);
                ret = pkt_setup_dev(&ctrl_cmd);
-               up(&ctl_mutex);
+               mutex_unlock(&ctl_mutex);
                break;
        case PKT_CTRL_CMD_TEARDOWN:
                if (!capable(CAP_SYS_ADMIN))
                        return -EPERM;
-               down(&ctl_mutex);
+               mutex_lock(&ctl_mutex);
                ret = pkt_remove_dev(&ctrl_cmd);
-               up(&ctl_mutex);
+               mutex_unlock(&ctl_mutex);
                break;
        case PKT_CTRL_CMD_STATUS:
-               down(&ctl_mutex);
+               mutex_lock(&ctl_mutex);
                pkt_get_status(&ctrl_cmd);
-               up(&ctl_mutex);
+               mutex_unlock(&ctl_mutex);
                break;
        default:
                return -ENOTTY;
@@ -2648,7 +2620,8 @@ static int __init pkt_init(void)
 {
        int ret;
 
-       psd_pool = mempool_create(PSD_POOL_SIZE, psd_pool_alloc, psd_pool_free, NULL);
+       psd_pool = mempool_create_kmalloc_pool(PSD_POOL_SIZE,
+                                       sizeof(struct packet_stacked_data));
        if (!psd_pool)
                return -ENOMEM;
 
@@ -2666,7 +2639,7 @@ static int __init pkt_init(void)
                goto out;
        }
 
-       init_MUTEX(&ctl_mutex);
+       mutex_init(&ctl_mutex);
 
        pkt_proc = proc_mkdir("pktcdvd", proc_root_driver);