fix build on some compilers
[pandora-kernel.git] / block / bsg.c
index 5a68b09..dcdbcd3 100644 (file)
@@ -45,8 +45,6 @@ struct bsg_device {
        char name[BUS_ID_SIZE];
        int max_queue;
        unsigned long flags;
-       struct blk_scsi_cmd_filter *cmd_filter;
-       mode_t *f_mode;
 };
 
 enum {
@@ -174,7 +172,8 @@ unlock:
 }
 
 static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
-                               struct sg_io_v4 *hdr, struct bsg_device *bd)
+                               struct sg_io_v4 *hdr, struct bsg_device *bd,
+                               int has_write_perm)
 {
        if (hdr->request_len > BLK_MAX_CDB) {
                rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
@@ -187,8 +186,7 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
                return -EFAULT;
 
        if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
-               if (blk_cmd_filter_verify_command(bd->cmd_filter, rq->cmd,
-                                                bd->f_mode))
+               if (blk_verify_command(&q->cmd_filter, rq->cmd, has_write_perm))
                        return -EPERM;
        } else if (!capable(CAP_SYS_RAWIO))
                return -EPERM;
@@ -204,6 +202,8 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
                rq->timeout = q->sg_timeout;
        if (!rq->timeout)
                rq->timeout = BLK_DEFAULT_SG_TIMEOUT;
+       if (rq->timeout < BLK_MIN_SG_TIMEOUT)
+               rq->timeout = BLK_MIN_SG_TIMEOUT;
 
        return 0;
 }
@@ -244,7 +244,7 @@ bsg_validate_sgv4_hdr(struct request_queue *q, struct sg_io_v4 *hdr, int *rw)
  * map sg_io_v4 to a request.
  */
 static struct request *
-bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr)
+bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr, int has_write_perm)
 {
        struct request_queue *q = bd->queue;
        struct request *rq, *next_rq = NULL;
@@ -266,7 +266,7 @@ bsg_map_hdr(struct bsg_device *bd, struct sg_io_v4 *hdr)
        rq = blk_get_request(q, rw, GFP_KERNEL);
        if (!rq)
                return ERR_PTR(-ENOMEM);
-       ret = blk_fill_sgv4_hdr_rq(q, rq, hdr, bd);
+       ret = blk_fill_sgv4_hdr_rq(q, rq, hdr, bd, has_write_perm);
        if (ret)
                goto out;
 
@@ -421,7 +421,7 @@ static int blk_complete_sgv4_hdr_rq(struct request *rq, struct sg_io_v4 *hdr,
        /*
         * fill in all the output members
         */
-       hdr->device_status = status_byte(rq->errors);
+       hdr->device_status = rq->errors & 0xff;
        hdr->transport_status = host_byte(rq->errors);
        hdr->driver_status = driver_byte(rq->errors);
        hdr->info = 0;
@@ -568,25 +568,6 @@ static inline void bsg_set_block(struct bsg_device *bd, struct file *file)
                set_bit(BSG_F_BLOCK, &bd->flags);
 }
 
-static void bsg_set_cmd_filter(struct bsg_device *bd,
-                          struct file *file)
-{
-       struct inode *inode;
-       struct gendisk *disk;
-
-       if (!file)
-               return;
-
-       inode = file->f_dentry->d_inode;
-       if (!inode)
-               return;
-
-       disk = inode->i_bdev->bd_disk;
-
-       bd->cmd_filter = &disk->cmd_filter;
-       bd->f_mode = &file->f_mode;
-}
-
 /*
  * Check if the error is a "real" error that we should return.
  */
@@ -608,7 +589,6 @@ bsg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
        dprintk("%s: read %Zd bytes\n", bd->name, count);
 
        bsg_set_block(bd, file);
-       bsg_set_cmd_filter(bd, file);
 
        bytes_read = 0;
        ret = __bsg_read(buf, count, bd, NULL, &bytes_read);
@@ -621,7 +601,7 @@ bsg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos)
 }
 
 static int __bsg_write(struct bsg_device *bd, const char __user *buf,
-                      size_t count, ssize_t *bytes_written)
+                      size_t count, ssize_t *bytes_written, int has_write_perm)
 {
        struct bsg_command *bc;
        struct request *rq;
@@ -652,7 +632,7 @@ static int __bsg_write(struct bsg_device *bd, const char __user *buf,
                /*
                 * get a request, fill in the blanks, and add to request queue
                 */
-               rq = bsg_map_hdr(bd, &bc->hdr);
+               rq = bsg_map_hdr(bd, &bc->hdr, has_write_perm);
                if (IS_ERR(rq)) {
                        ret = PTR_ERR(rq);
                        rq = NULL;
@@ -683,10 +663,11 @@ bsg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos)
        dprintk("%s: write %Zd bytes\n", bd->name, count);
 
        bsg_set_block(bd, file);
-       bsg_set_cmd_filter(bd, file);
 
        bytes_written = 0;
-       ret = __bsg_write(bd, buf, count, &bytes_written);
+       ret = __bsg_write(bd, buf, count, &bytes_written,
+                         file->f_mode & FMODE_WRITE);
+
        *ppos = bytes_written;
 
        /*
@@ -792,7 +773,6 @@ static struct bsg_device *bsg_add_device(struct inode *inode,
        bd->queue = rq;
 
        bsg_set_block(bd, file);
-       bsg_set_cmd_filter(bd, file);
 
        atomic_set(&bd->ref_count, 1);
        mutex_lock(&bsg_mutex);
@@ -943,7 +923,7 @@ static long bsg_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                if (copy_from_user(&hdr, uarg, sizeof(hdr)))
                        return -EFAULT;
 
-               rq = bsg_map_hdr(bd, &hdr);
+               rq = bsg_map_hdr(bd, &hdr, file->f_mode & FMODE_WRITE);
                if (IS_ERR(rq))
                        return PTR_ERR(rq);