[PATCH] s390: use normal switch statement for ioctls in dasd_ioctlc
[powerpc.git] / drivers / block / pktcdvd.c
index fb08ae6..1d261f9 100644 (file)
@@ -56,6 +56,7 @@
 #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>
@@ -81,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;
 
 
@@ -1499,28 +1500,30 @@ static int pkt_set_write_settings(struct pktcdvd_device *pd)
 /*
  * 1 -- we can write to this track, 0 -- we can't
  */
-static int pkt_writable_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)
-               return 1;
+       if (!ti->packet || !ti->fp)
+               return 0;
 
        /*
         * "good" settings as per Mt Fuji.
         */
-       if (ti->rt == 0 && ti->blank == 0 && ti->packet == 1)
+       if (ti->rt == 0 && ti->blank == 0)
                return 1;
 
-       if (ti->rt == 0 && ti->blank == 1 && ti->packet == 1)
+       if (ti->rt == 0 && ti->blank == 1)
                return 1;
 
-       if (ti->rt == 1 && ti->blank == 0 && ti->packet == 1)
+       if (ti->rt == 1 && ti->blank == 0)
                return 1;
 
        printk("pktcdvd: bad state %d-%d-%d\n", ti->rt, ti->blank, ti->packet);
@@ -1595,7 +1598,7 @@ static int pkt_probe_settings(struct pktcdvd_device *pd)
        }
 
        if (!pkt_writable_disc(pd, &di))
-               return -ENXIO;
+               return -EROFS;
 
        pd->type = di.erasable ? PACKET_CDRW : PACKET_CDR;
 
@@ -1605,9 +1608,9 @@ static int pkt_probe_settings(struct pktcdvd_device *pd)
                return ret;
        }
 
-       if (!pkt_writable_track(&ti)) {
+       if (!pkt_writable_track(pd, &ti)) {
                printk("pktcdvd: can't write to this track\n");
-               return -ENXIO;
+               return -EROFS;
        }
 
        /*
@@ -1621,7 +1624,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);
@@ -1663,7 +1666,7 @@ static int pkt_probe_settings(struct pktcdvd_device *pd)
                        break;
                default:
                        printk("pktcdvd: unknown data mode\n");
-                       return 1;
+                       return -EROFS;
        }
        return 0;
 }
@@ -1874,7 +1877,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))) {
@@ -2016,7 +2019,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;
@@ -2042,14 +2045,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;
 }
 
@@ -2058,14 +2061,14 @@ 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;
 }
 
@@ -2512,7 +2515,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:
@@ -2553,7 +2556,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;
@@ -2594,21 +2597,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;
@@ -2654,7 +2657,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);