From 88baf3e85af72f606363a85e9a60e9e61cc64a6c Mon Sep 17 00:00:00 2001 From: Jon Masters Date: Tue, 8 Nov 2005 21:34:43 -0800 Subject: [PATCH] fix floppy.c to store correct ro/rw status in underlying gendisk Evgeny Stambulchik found that doing the following always worked: # mount /dev/fd0 /mnt/floppy/ mount: block device /dev/fd0 is write-protected, mounting read-only # mount -o remount,rw /mnt/floppy # echo $? 0 This is the case because the block device /dev/fd0 is writeable but the floppy disk is marked protected. A fix is to simply have floppy_open mark the underlying gendisk policy according to reality (since the VFS doesn't provide a way for do_remount_sb to inquire as to the current device status). Signed-off-by: Jon Masters Cc: Al Viro Cc: Christoph Hellwig Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/block/floppy.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'drivers/block/floppy.c') diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 5eadbb9d4d7..dd1935d5542 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -3714,6 +3714,12 @@ static int floppy_open(struct inode *inode, struct file *filp) USETF(FD_VERIFY); } + /* set underlying gendisk policy to reflect real ro/rw status */ + if (UTESTF(FD_DISK_WRITABLE)) + inode->i_bdev->bd_disk->policy = 0; + else + inode->i_bdev->bd_disk->policy = 1; + if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (filp->f_flags & O_EXCL))) goto out2; -- cgit v1.2.3 From 8c744fb83da0771afa04695028e3550b798dad90 Mon Sep 17 00:00:00 2001 From: Christoph Hellwig Date: Tue, 8 Nov 2005 21:35:04 -0800 Subject: [PATCH] add a file_permission helper A few more callers of permission() just want to check for a different access pattern on an already open file. This patch adds a wrapper for permission() that takes a file in preparation of per-mount read-only support and to clean up the callers a little. The helper is not intended for new code, everything without the interface set in stone should use vfs_permission() Signed-off-by: Christoph Hellwig Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- drivers/block/floppy.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'drivers/block/floppy.c') diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index dd1935d5542..28002de783b 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -3776,8 +3776,7 @@ static int floppy_open(struct inode *inode, struct file *filp) /* Allow ioctls if we have write-permissions even if read-only open. * Needed so that programs such as fdrawcmd still can work on write * protected disks */ - if (filp->f_mode & 2 - || permission(filp->f_dentry->d_inode, 2, NULL) == 0) + if ((filp->f_mode & FMODE_WRITE) || !file_permission(filp, MAY_WRITE)) filp->private_data = (void *)8; if (UFDCS->rawcmd == 1) -- cgit v1.2.3