PATCH: fix-readonly-policy-use-and-floppy-ro-rw-status

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[PATCH]: This modifies the gendisk and hd_struct structs to replace "policy"
with "readonly" (as that's the only use for this field). It also introduces a
new function disk_read_only, which behaves like the corresponding device
functions do. I've also replaced direct usage of the old policy fields with
calls to the appropriate function.

Signed-off-by: Jon Masters <[email protected]>

diff -urN linux-2.6.14/drivers/block/floppy.c linux-2.6.14_new/drivers/block/floppy.c
--- linux-2.6.14/drivers/block/floppy.c	2005-10-28 01:02:08.000000000 +0100
+++ linux-2.6.14_new/drivers/block/floppy.c	2005-11-05 15:30:05.000000000 +0000
@@ -3714,6 +3714,13 @@
 		USETF(FD_VERIFY);
 	}
 
+	/* set underlying gendisk readonly state to reflect real ro/rw status */
+	if (UTESTF(FD_DISK_WRITABLE)) {
+		set_device_ro(inode->i_bdev, 0);
+	} else {
+		set_device_ro(inode->i_bdev, 1);
+	}
+	
 	if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (filp->f_flags & O_EXCL)))
 		goto out2;
 
diff -urN linux-2.6.14/drivers/block/genhd.c linux-2.6.14_new/drivers/block/genhd.c
--- linux-2.6.14/drivers/block/genhd.c	2005-10-28 01:02:08.000000000 +0100
+++ linux-2.6.14_new/drivers/block/genhd.c	2005-11-05 16:17:18.000000000 +0000
@@ -655,22 +655,22 @@
 
 EXPORT_SYMBOL(put_disk);
 
-void set_device_ro(struct block_device *bdev, int flag)
+void set_device_ro(struct block_device *bdev, int state)
 {
 	if (bdev->bd_contains != bdev)
-		bdev->bd_part->policy = flag;
+		bdev->bd_part->readonly = state;
 	else
-		bdev->bd_disk->policy = flag;
+		bdev->bd_disk->readonly = state;
 }
 
 EXPORT_SYMBOL(set_device_ro);
 
-void set_disk_ro(struct gendisk *disk, int flag)
+void set_disk_ro(struct gendisk *disk, int state)
 {
 	int i;
-	disk->policy = flag;
+	disk->readonly = state;
 	for (i = 0; i < disk->minors - 1; i++)
-		if (disk->part[i]) disk->part[i]->policy = flag;
+		if (disk->part[i]) disk->part[i]->readonly = state;
 }
 
 EXPORT_SYMBOL(set_disk_ro);
@@ -680,13 +680,23 @@
 	if (!bdev)
 		return 0;
 	else if (bdev->bd_contains != bdev)
-		return bdev->bd_part->policy;
+		return bdev->bd_part->readonly;
 	else
-		return bdev->bd_disk->policy;
+		return bdev->bd_disk->readonly;
 }
 
 EXPORT_SYMBOL(bdev_read_only);
 
+int disk_read_only(struct gendisk *disk)
+{
+	if (!disk)
+		return 0;
+
+	return (disk->readonly);
+}
+
+EXPORT_SYMBOL(disk_read_only);
+
 int invalidate_partition(struct gendisk *disk, int index)
 {
 	int res = 0;
diff -urN linux-2.6.14/drivers/ide/ide-cd.c linux-2.6.14_new/drivers/ide/ide-cd.c
--- linux-2.6.14/drivers/ide/ide-cd.c	2005-10-28 01:02:08.000000000 +0100
+++ linux-2.6.14_new/drivers/ide/ide-cd.c	2005-11-05 17:27:58.000000000 +0000
@@ -313,7 +313,7 @@
 #include <linux/cdrom.h>
 #include <linux/ide.h>
 #include <linux/completion.h>
-
+ 
 #include <scsi/scsi.h>	/* For SCSI -> ATAPI command conversion */
 
 #include <asm/irq.h>
@@ -1873,7 +1873,8 @@
 	/*
 	 * disk has become write protected
 	 */
-	if (g->policy) {
+
+	if (disk_read_only(g)) {
 		cdrom_end_request(drive, 0);
 		return ide_stopped;
 	}
diff -urN linux-2.6.14/drivers/md/dm-ioctl.c linux-2.6.14_new/drivers/md/dm-ioctl.c
--- linux-2.6.14/drivers/md/dm-ioctl.c	2005-10-28 01:02:08.000000000 +0100
+++ linux-2.6.14_new/drivers/md/dm-ioctl.c	2005-11-05 17:27:37.000000000 +0000
@@ -538,7 +538,7 @@
 	} else
 		param->open_count = -1;
 
-	if (disk->policy)
+	if (disk_read_only(disk))
 		param->flags |= DM_READONLY_FLAG;
 
 	param->event_nr = dm_get_event_nr(md);
diff -urN linux-2.6.14/include/linux/genhd.h linux-2.6.14_new/include/linux/genhd.h
--- linux-2.6.14/include/linux/genhd.h	2005-10-28 01:02:08.000000000 +0100
+++ linux-2.6.14_new/include/linux/genhd.h	2005-11-05 16:19:48.000000000 +0000
@@ -79,7 +79,7 @@
 	sector_t nr_sects;
 	struct kobject kobj;
 	unsigned reads, read_sectors, writes, write_sectors;
-	int policy, partno;
+	int readonly, partno;
 };
 
 #define GENHD_FL_REMOVABLE			1
@@ -116,7 +116,7 @@
 	struct kobject kobj;
 
 	struct timer_rand_state *random;
-	int policy;
+	int readonly;			/* needed for underlying media */
 
 	atomic_t sync_io;		/* RAID */
 	unsigned long stamp, stamp_idle;
@@ -230,8 +230,9 @@
 extern void unlink_gendisk(struct gendisk *gp);
 extern struct gendisk *get_gendisk(dev_t dev, int *part);
 
-extern void set_device_ro(struct block_device *bdev, int flag);
-extern void set_disk_ro(struct gendisk *disk, int flag);
+extern void set_device_ro(struct block_device *bdev, int state);
+extern void set_disk_ro(struct gendisk *disk, int state);
+extern int disk_read_only(struct gendisk *disk);
 
 /* drivers/char/random.c */
 extern void add_disk_randomness(struct gendisk *disk);
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux