patch-1.3.73 linux/drivers/block/loop.c

Next file: linux/drivers/block/rd.c
Previous file: linux/drivers/block/ide.h
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v1.3.72/linux/drivers/block/loop.c linux/drivers/block/loop.c
@@ -237,24 +237,30 @@
 
 static int loop_set_fd(struct loop_device *lo, unsigned int arg)
 {
+	struct file	*file;
 	struct inode	*inode;
 	
-	if (arg >= NR_OPEN || !current->files->fd[arg])
+	if (arg >= NR_OPEN || !(file = current->files->fd[arg]))
 		return -EBADF;
 	if (lo->lo_inode)
 		return -EBUSY;
-	inode = current->files->fd[arg]->f_inode;
+	inode = file->f_inode;
 	if (!inode) {
 		printk("loop_set_fd: NULL inode?!?\n");
 		return -EINVAL;
 	}
-	if (S_ISREG(inode->i_mode)) {
+	if (S_ISBLK(inode->i_mode)) {
+		int error = blkdev_open(inode, file);
+		if (error)
+			return error;
+		lo->lo_device = inode->i_rdev;
+		lo->lo_flags = 0;
+	} else if (S_ISREG(inode->i_mode)) {
 		lo->lo_device = inode->i_dev;
-		lo->lo_flags |= LO_FLAGS_DO_BMAP;
-	} else if (S_ISBLK(inode->i_mode))
-			lo->lo_device = inode->i_rdev;
-		else
-			return -EINVAL;
+		lo->lo_flags = LO_FLAGS_DO_BMAP;
+	} else
+		return -EINVAL;
+
 	invalidate_inode_pages (inode);
 	lo->lo_inode = inode;
 	lo->lo_inode->i_count++;
@@ -270,6 +276,8 @@
 		return -ENXIO;
 	if (lo->lo_refcnt > 1)
 		return -EBUSY;
+	if (S_ISBLK(lo->lo_inode->i_mode))
+		blkdev_release (lo->lo_inode);
 	iput(lo->lo_inode);
 	lo->lo_device = 0;
 	lo->lo_inode = NULL;
@@ -293,7 +301,7 @@
 	if (!arg)
 		return -EINVAL;
 	memcpy_fromfs(&info, arg, sizeof(info));
-	if (info.lo_encrypt_key_size > LO_KEY_SIZE)
+	if ((unsigned int) info.lo_encrypt_key_size > LO_KEY_SIZE)
 		return -EINVAL;
 	switch (info.lo_encrypt_type) {
 	case LO_CRYPT_NONE:

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov with Sam's (original) version
of this