Skip to contentSkip to conversation

reserve BLKGETSIZE64 ioctl

PATCH RESEND [email protected] 2 participants 2 messages Sep 4, 2001

Subsystems (10)
lore
Share & tools
lore
#0 lore raw
Quoted 4 lines
Quoted 2 lines

Soon we'll all need a BLKGETSIZE64 ioctl, that gives the size of a block device in bytes.

I'd accepted that suggestion

Then I am happy (as long as you don't take a reserved number).

Concerning policy, of course that is up to Linus - for myself I would prefer adding a well-motivated ioctl above reserving a number. After all, an ioctl is almost always about transporting some small amount of information, hence is implemented by a dozen lines of code or so, clean, and without impact on the rest of the kernel, so if it is going to be added eventually it might as well be added immediately.

So, until Linus says otherwise, you might try once or twice to submit the actual ioctl instead of just the reservation.

Andries

#1 lore raw
Quoted 1 line · On Tue, 4 Sep 2001 [email protected] wrote:

Then I am happy (as long as you don't take a reserved number).

So the patch below is okay?

Quoted 2 lines

So, until Linus says otherwise, you might try once or twice to submit the actual ioctl instead of just the reservation.

Linus, comments?

-ben

...blkgetsize64-4.diff...

drivers/acorn/block/mfmhd.c +2 -0
diff -urN v2.4.10-pre4/drivers/acorn/block/mfmhd.c work-v2.4.10-pre4/drivers/acorn/block/mfmhd.c
@@ -1210,6 +1210,8 @@
 
 	case BLKGETSIZE:
 		return put_user (mfm[minor].nr_sects, (long *)arg);
+	case BLKGETSIZE64:
+		return put_user ((u64)mfm[minor].nr_sects << 9, (u64 *)arg);
 
 	case BLKFRASET:
 		if (!capable(CAP_SYS_ADMIN))
drivers/block/DAC960.c +3 -1
diff -urN v2.4.10-pre4/drivers/block/DAC960.c work-v2.4.10-pre4/drivers/block/DAC960.c
@@ -5090,10 +5090,12 @@
 			   sizeof(DiskGeometry_T)) ? -EFAULT : 0);
     case BLKGETSIZE:
       /* Get Device Size. */
-      if ((long *) Argument == NULL) return -EINVAL;
       return put_user(Controller->GenericDiskInfo.part[MINOR(Inode->i_rdev)]
 						 .nr_sects,
 		      (long *) Argument);
+    case BLKGETSIZE64:
+      return put_user((u64)Controller->GenericDiskInfo.part[MINOR(Inode->i_rdev)].nr_sects << 9,
+		      (u64 *) Argument);
     case BLKRAGET:
     case BLKRASET:
     case BLKFLSBUF:
drivers/block/acsi.c +4 -0
diff -urN v2.4.10-pre4/drivers/block/acsi.c work-v2.4.10-pre4/drivers/block/acsi.c
@@ -1138,6 +1138,10 @@
 		return put_user(acsi_part[MINOR(inode->i_rdev)].nr_sects,
 				(long *) arg);
 
+	  case BLKGETSIZE64:   /* Return device size */
+		return put_user((u64)acsi_part[MINOR(inode->i_rdev)].nr_sects << 9,
+				(u64 *) arg);
+
 	  case BLKROSET:
 	  case BLKROGET:
 	  case BLKFLSBUF:
drivers/block/amiflop.c +3 -0
diff -urN v2.4.10-pre4/drivers/block/amiflop.c work-v2.4.10-pre4/drivers/block/amiflop.c
@@ -1556,6 +1556,9 @@
 	case BLKGETSIZE:
 		return put_user(unit[drive].blocks,(long *)param);
 		break;
+	case BLKGETSIZE64:
+		return put_user((u64)unit[drive].blocks << 9, (u64 *)param);
+		break;
 	case FDSETPRM:
 	case FDDEFPRM:
 		return -EINVAL;
drivers/block/blkpg.c +1 -0
diff -urN v2.4.10-pre4/drivers/block/blkpg.c work-v2.4.10-pre4/drivers/block/blkpg.c
@@ -250,6 +250,7 @@
 		case BLKGETSIZE:
 			/* Today get_gendisk() requires a linear scan;
 			   add this when dev has pointer type. */
+			/* add BLKGETSIZE64 too */
 			g = get_gendisk(dev);
 			if (!g)
 				longval = 0;
drivers/block/cciss.c +3 -1
diff -urN v2.4.10-pre4/drivers/block/cciss.c work-v2.4.10-pre4/drivers/block/cciss.c
@@ -400,8 +400,10 @@
 		put_user(hba[ctlr]->hd[MINOR(inode->i_rdev)].start_sect, &geo->start);
 		return 0;
 	case BLKGETSIZE:
-		if (!arg) return -EINVAL;
 		put_user(hba[ctlr]->hd[MINOR(inode->i_rdev)].nr_sects, (long*)arg);
+		return 0;
+	case BLKGETSIZE64:
+		put_user((u64)hba[ctlr]->hd[MINOR(inode->i_rdev)].nr_sects << 9, (u64*)arg);
 		return 0;
 	case BLKRRPART:
 		return revalidate_logvol(inode->i_rdev, 1);
drivers/block/cpqarray.c +3 -3
diff -urN v2.4.10-pre4/drivers/block/cpqarray.c work-v2.4.10-pre4/drivers/block/cpqarray.c
@@ -1227,9 +1227,9 @@
 	case IDAGETDRVINFO:
 		return copy_to_user(&io->c.drv,&hba[ctlr]->drv[dsk],sizeof(drv_info_t));
 	case BLKGETSIZE:
-		if (!arg) return -EINVAL;
-		put_user(ida[(ctlr<<CTLR_SHIFT)+MINOR(inode->i_rdev)].nr_sects, (long*)arg);
-		return 0;
+		return put_user(ida[(ctlr<<CTLR_SHIFT)+MINOR(inode->i_rdev)].nr_sects, (long*)arg);
+	case BLKGETSIZE64:
+		return put_user((u64)(ida[(ctlr<<CTLR_SHIFT)+MINOR(inode->i_rdev)].nr_sects) << 9, (u64*)arg);
 	case BLKRRPART:
 		return revalidate_logvol(inode->i_rdev, 1);
 	case IDAPASSTHRU:
drivers/block/floppy.c +4 -0
diff -urN v2.4.10-pre4/drivers/block/floppy.c work-v2.4.10-pre4/drivers/block/floppy.c
@@ -3492,6 +3492,10 @@
 		case BLKGETSIZE:
 			ECALL(get_floppy_geometry(drive, type, &g));
 			return put_user(g->size, (long *) param);
+
+		case BLKGETSIZE64:
+			ECALL(get_floppy_geometry(drive, type, &g));
+			return put_user((u64)g->size << 9, (u64 *) param);
 		/* BLKRRPART is not defined as floppies don't have
 		 * partition tables */
 	}
drivers/block/loop.c +6 -3
diff -urN v2.4.10-pre4/drivers/block/loop.c work-v2.4.10-pre4/drivers/block/loop.c
@@ -849,11 +849,14 @@
 			err = -ENXIO;
 			break;
 		}
-		if (!arg) {
-			err = -EINVAL;
+		err = put_user(loop_sizes[lo->lo_number] << 1, (long *) arg);
+		break;
+	case BLKGETSIZE64:
+		if (lo->lo_state != Lo_bound) {
+			err = -ENXIO;
 			break;
 		}
-		err = put_user(loop_sizes[lo->lo_number] << 1, (long *) arg);
+		err = put_user((u64)loop_sizes[lo->lo_number] << 10, (u64*)arg);
 		break;
 	case BLKBSZGET:
 	case BLKBSZSET:
drivers/block/nbd.c +2 -0
diff -urN v2.4.10-pre4/drivers/block/nbd.c work-v2.4.10-pre4/drivers/block/nbd.c
@@ -446,6 +446,8 @@
 #endif
 	case BLKGETSIZE:
 		return put_user(nbd_bytesizes[dev] >> 9, (long *) arg);
+	case BLKGETSIZE64:
+		return put_user((u64)nbd_bytesizes[dev], (u64 *) arg);
 	}
 	return -EINVAL;
 }
drivers/block/paride/pd.c +2 -0
diff -urN v2.4.10-pre4/drivers/block/paride/pd.c work-v2.4.10-pre4/drivers/block/paride/pd.c
@@ -535,6 +535,8 @@
                 if (err) return (err);
                 put_user(pd_hd[dev].nr_sects,(long *) arg);
                 return (0);
+            case BLKGETSIZE64:
+                return put_user((u64)pd_hd[dev].nr_sects << 9, (u64 *)arg);
             case BLKRRPART:
 		if (!capable(CAP_SYS_ADMIN))
 			return -EACCES;
drivers/block/paride/pf.c +3 -5
diff -urN v2.4.10-pre4/drivers/block/paride/pf.c work-v2.4.10-pre4/drivers/block/paride/pf.c
@@ -482,11 +482,9 @@
                 put_user(0,(long *)&geo->start);
                 return 0;
             case BLKGETSIZE:
-                if (!arg) return -EINVAL;
-                err = verify_area(VERIFY_WRITE,(long *) arg,sizeof(long));
-                if (err) return (err);
-                put_user(PF.capacity,(long *) arg);
-                return (0);
+                return put_user(PF.capacity,(long *) arg);
+            case BLKGETSIZE64:
+                return put_user((u64)PF.capacity << 9,(u64 *)arg);
 	    case BLKROSET:
 	    case BLKROGET:
 	    case BLKRASET:
drivers/block/ps2esdi.c +3 -0
diff -urN v2.4.10-pre4/drivers/block/ps2esdi.c work-v2.4.10-pre4/drivers/block/ps2esdi.c
@@ -1117,6 +1117,9 @@
 			}
 			break;
 
+		case BLKGETSIZE64:
+			return put_user((u64)ps2esdi[MINOR(inode->i_rdev)].nr_sects << 9, (u64 *) arg);
+
 		case BLKRRPART:
                         if (!capable(CAP_SYS_ADMIN))
 				return -EACCES;
drivers/block/rd.c +3 -0
diff -urN v2.4.10-pre4/drivers/block/rd.c work-v2.4.10-pre4/drivers/block/rd.c
@@ -269,6 +269,9 @@
 			if (!arg)  return -EINVAL;
 			return put_user(rd_kbsize[minor] << 1, (long *) arg);
 
+         	case BLKGETSIZE64:
+			return put_user((u64)rd_kbsize[minor] << 10, (u64*)arg);
+
 		case BLKROSET:
 		case BLKROGET:
 		case BLKSSZGET:
drivers/block/xd.c +2 -0
diff -urN v2.4.10-pre4/drivers/block/xd.c work-v2.4.10-pre4/drivers/block/xd.c
@@ -339,6 +339,8 @@
 		case BLKGETSIZE:
 			if (!arg) return -EINVAL;
 			return put_user(xd_struct[MINOR(inode->i_rdev)].nr_sects,(long *) arg);
+		case BLKGETSIZE64:
+			return put_user((u64)xd_struct[MINOR(inode->i_rdev)].nr_sects << 9, (u64 *)arg);
 		case HDIO_SET_DMA:
 			if (!capable(CAP_SYS_ADMIN)) return -EACCES;
 			if (xdc_busy) return -EBUSY;
drivers/i2o/i2o_block.c +2 -0
diff -urN v2.4.10-pre4/drivers/i2o/i2o_block.c work-v2.4.10-pre4/drivers/i2o/i2o_block.c
@@ -1141,6 +1141,8 @@
 	switch (cmd) {
 		case BLKGETSIZE:
 			return put_user(i2ob[minor].nr_sects, (long *) arg);
+		case BLKGETSIZE64:
+			return put_user((u64)i2ob[minor].nr_sects << 9, (u64 *)arg);
 
 		case HDIO_GETGEO:
 		{
drivers/ide/hd.c +3 -1
diff -urN v2.4.10-pre4/drivers/ide/hd.c work-v2.4.10-pre4/drivers/ide/hd.c
@@ -639,9 +639,11 @@
 		}
 
          	case BLKGETSIZE:   /* Return device size */
-			if (!arg)  return -EINVAL;
 			return put_user(hd[MINOR(inode->i_rdev)].nr_sects,
 					(long *) arg);
+         	case BLKGETSIZE64:
+			return put_user((u64)hd[MINOR(inode->i_rdev)].nr_sects << 9,
+					(u64 *) arg);
 
 		case BLKRRPART: /* Re-read partition tables */
 			if (!capable(CAP_SYS_ADMIN))
drivers/ide/ide.c +2 -0
diff -urN v2.4.10-pre4/drivers/ide/ide.c work-v2.4.10-pre4/drivers/ide/ide.c
@@ -2663,6 +2663,8 @@
 
 	 	case BLKGETSIZE:   /* Return device size */
 			return put_user(drive->part[MINOR(inode->i_rdev)&PARTN_MASK].nr_sects, (long *) arg);
+	 	case BLKGETSIZE64:
+			return put_user((u64)drive->part[MINOR(inode->i_rdev)&PARTN_MASK].nr_sects << 9, (u64 *) arg);
 
 		case BLKRRPART: /* Re-read partition tables */
 			if (!capable(CAP_SYS_ADMIN)) return -EACCES;
drivers/md/lvm.c +5 -0
diff -urN v2.4.10-pre4/drivers/md/lvm.c work-v2.4.10-pre4/drivers/md/lvm.c
@@ -906,6 +906,11 @@
 			return -EFAULT;
 		break;
 
+	case BLKGETSIZE64:
+		if (put_user((u64)lv_ptr->lv_size << 9, (u64 *)arg))
+			return -EFAULT;
+		break;
+
 
 	case BLKFLSBUF:
 		/* flush buffer cache */
drivers/md/md.c +5 -0
diff -urN v2.4.10-pre4/drivers/md/md.c work-v2.4.10-pre4/drivers/md/md.c
@@ -2490,6 +2490,11 @@
 						(long *) arg);
 			goto done;
 
+		case BLKGETSIZE64:   /* Return device size */
+			err = md_put_user((u64)md_hd_struct[minor].nr_sects << 9,
+						(u64 *) arg);
+			goto done;
+
 		case BLKRAGET:
 		case BLKRASET:
 		case BLKFLSBUF:
drivers/mtd/ftl.c +4 -4
diff -urN v2.4.10-pre4/drivers/mtd/ftl.c work-v2.4.10-pre4/drivers/mtd/ftl.c
@@ -1174,10 +1174,10 @@
 	put_user(ftl_hd[minor].start_sect, (u_long *)&geo->start);
 	break;
     case BLKGETSIZE:
-	ret = verify_area(VERIFY_WRITE, (long *)arg, sizeof(long));
-	if (ret) return ret;
-	put_user(ftl_hd[minor].nr_sects,
-		 (long *)arg);
+	ret = put_user(ftl_hd[minor].nr_sects, (long *)arg);
+	break;
+    case BLKGETSIZE64:
+	ret = put_user((u64)ftl_hd[minor].nr_sects << 9, (u64 *)arg);
 	break;
     case BLKRRPART:
 	ret = ftl_reread_partitions(minor);
drivers/mtd/mtdblock.c +3 -4
diff -urN v2.4.10-pre4/drivers/mtd/mtdblock.c work-v2.4.10-pre4/drivers/mtd/mtdblock.c
@@ -529,10 +529,9 @@
 
 	switch (cmd) {
 	case BLKGETSIZE:   /* Return device size */
-		if (!arg)
-			return -EFAULT;
-		return put_user((mtdblk->mtd->size >> 9),
-                                (long *) arg)?-EFAULT:0;
+		return put_user((mtdblk->mtd->size >> 9), (long *) arg);
+	case BLKGETSIZE64:
+		return put_user((u64)mtdblk->mtd->size, (u64 *)arg);
 
 	case BLKFLSBUF:
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
drivers/mtd/mtdblock_ro.c +3 -3
diff -urN v2.4.10-pre4/drivers/mtd/mtdblock_ro.c work-v2.4.10-pre4/drivers/mtd/mtdblock_ro.c
@@ -211,9 +211,9 @@
 
 	switch (cmd) {
 	case BLKGETSIZE:   /* Return device size */
-		if (!arg)  return -EFAULT;
-		return Put_user((mtd->size >> 9),
-                                (long *) arg);
+		return put_user((mtd->size >> 9), (long *) arg);
+	case BLKGETSIZE64:
+		return put_user((u64)mtd->size, (u64 *)arg);
 
 	case BLKFLSBUF:
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
drivers/mtd/nftlcore.c +3 -1
diff -urN v2.4.10-pre4/drivers/mtd/nftlcore.c work-v2.4.10-pre4/drivers/mtd/nftlcore.c
@@ -791,9 +791,11 @@
 		return copy_to_user((void *)arg, &g, sizeof g) ? -EFAULT : 0;
 	}
 	case BLKGETSIZE:   /* Return device size */
-		if (!arg) return -EINVAL;
 		return put_user(part_table[MINOR(inode->i_rdev)].nr_sects,
                                 (long *) arg);
+	case BLKGETSIZE64:
+		return put_user((u64)part_table[MINOR(inode->i_rdev)].nr_sects << 9,
+                                (u64 *)arg);
 
 	case BLKFLSBUF:
 		if (!capable(CAP_SYS_ADMIN)) return -EACCES;
drivers/s390/block/dasd.c +7 -5
diff -urN v2.4.10-pre4/drivers/s390/block/dasd.c work-v2.4.10-pre4/drivers/s390/block/dasd.c
@@ -2189,11 +2189,13 @@
 	case BLKGETSIZE:{	/* Return device size */
 			long blocks = major_info->gendisk.sizes
                                       [MINOR (inp->i_rdev)] << 1;
-			rc =
-			    copy_to_user ((long *) data, &blocks,
-					  sizeof (long));
-			if (rc)
-				rc = -EFAULT;
+			rc = put_user(blocks, (long *)arg);
+			break;
+		}
+	case BLKGETSIZE64:{
+			u64 blocks = major_info->gendisk.sizes
+                                      [MINOR (inp->i_rdev)];
+			rc = put_user(blocks << 10, (u64 *)arg);
 			break;
 		}
 	case BLKRRPART:{
drivers/s390/block/xpram.c +6 -6
diff -urN v2.4.10-pre4/drivers/s390/block/xpram.c work-v2.4.10-pre4/drivers/s390/block/xpram.c
@@ -647,14 +647,14 @@
 
 	case BLKGETSIZE:  /* 0x1260 */
 		/* Return the device size, expressed in sectors */
-		if (!arg) return -EINVAL; /* NULL pointer: not valid */
-		err= 0; /* verify_area_20(VERIFY_WRITE, (long *) arg, sizeof(long));
-			 *  if (err) return err;
-			 */
-		put_user ( 1024* xpram_sizes[MINOR(inode->i_rdev)]
+		return put_user( 1024* xpram_sizes[MINOR(inode->i_rdev)]
                            / XPRAM_SOFTSECT,
 			   (long *) arg);
-		return 0;
+
+	case BLKGETSIZE64:
+		return put_user( (u64)(1024* xpram_sizes[MINOR(inode->i_rdev)]
+                           / XPRAM_SOFTSECT) << 9,
+			   (u64 *) arg);
 
 	case BLKFLSBUF: /* flush, 0x1261 */
 		fsync_dev(inode->i_rdev);
drivers/sbus/char/jsflash.c +2 -0
diff -urN v2.4.10-pre4/drivers/sbus/char/jsflash.c work-v2.4.10-pre4/drivers/sbus/char/jsflash.c
@@ -454,6 +454,8 @@
 	switch (cmd) {
 	case BLKGETSIZE:
 		return put_user(jsfd_bytesizes[dev] >> 9, (long *) arg);
+	case BLKGETSIZE64:
+		return put_user(jsfd_bytesizes[dev], (u64 *) arg);
 
 #if 0
 	case BLKROSET:
drivers/scsi/sd.c +2 -2
diff -urN v2.4.10-pre4/drivers/scsi/sd.c work-v2.4.10-pre4/drivers/scsi/sd.c
@@ -227,9 +227,9 @@
 			return 0;
 		}
 		case BLKGETSIZE:   /* Return device size */
-			if (!arg)
-				return -EINVAL;
 			return put_user(sd[SD_PARTITION(inode->i_rdev)].nr_sects, (long *) arg);
+		case BLKGETSIZE64:
+			return put_user((u64)sd[SD_PARTITION(inode->i_rdev)].nr_sects << 9, (u64 *)arg);
 
 		case BLKROSET:
 		case BLKROGET:
drivers/scsi/sr_ioctl.c +2 -0
diff -urN v2.4.10-pre4/drivers/scsi/sr_ioctl.c work-v2.4.10-pre4/drivers/scsi/sr_ioctl.c
@@ -546,6 +546,8 @@
 	switch (cmd) {
 	case BLKGETSIZE:
 		return put_user(scsi_CDs[target].capacity, (long *) arg);
+	case BLKGETSIZE64:
+		return put_user((u64)scsi_CDs[target].capacity << 9, (u64 *)arg);
 	case BLKROSET:
 	case BLKROGET:
 	case BLKRASET:
include/asm-i386/uaccess.h +8 -0
diff -urN v2.4.10-pre4/include/asm-i386/uaccess.h work-v2.4.10-pre4/include/asm-i386/uaccess.h
@@ -126,6 +126,7 @@
 extern void __put_user_1(void);
 extern void __put_user_2(void);
 extern void __put_user_4(void);
+extern void __put_user_8(void);
 
 extern void __put_user_bad(void);
 
@@ -161,6 +162,13 @@
 	  case 1: __put_user_asm(x,ptr,retval,"b","b","iq"); break;	\
 	  case 2: __put_user_asm(x,ptr,retval,"w","w","ir"); break;	\
 	  case 4: __put_user_asm(x,ptr,retval,"l","","ir"); break;	\
+	  case 8: {							\
+		u32 *__put_ptr = (void*)(ptr);				\
+		u64 __put_val = (x);					\
+		__put_user_asm((u32)__put_val,__put_ptr,retval,"l","","ir"); \
+		__put_user_asm((u32)(__put_val>>32),__put_ptr+1,retval,"l","","ir"); \
+		break;							\
+	  }								\
 	  default: __put_user_bad();					\
 	}								\
 } while (0)
include/linux/fs.h +3 -2
diff -urN v2.4.10-pre4/include/linux/fs.h work-v2.4.10-pre4/include/linux/fs.h
@@ -166,7 +166,7 @@
 #define BLKROSET   _IO(0x12,93)	/* set device read-only (0 = read-write) */
 #define BLKROGET   _IO(0x12,94)	/* get read-only status (0 = read_write) */
 #define BLKRRPART  _IO(0x12,95)	/* re-read partition table */
-#define BLKGETSIZE _IO(0x12,96)	/* return device size */
+#define BLKGETSIZE _IO(0x12,96)	/* return device size /512 (long *arg) */
 #define BLKFLSBUF  _IO(0x12,97)	/* flush buffer cache */
 #define BLKRASET   _IO(0x12,98)	/* Set read ahead for block device */
 #define BLKRAGET   _IO(0x12,99)	/* get current read ahead setting */
@@ -182,7 +182,8 @@
 /* This was here just to show that the number is taken -
    probably all these _IO(0x12,*) ioctls should be moved to blkpg.h. */
 #endif
-/* A jump here: 108-111 have been used for various private purposes. */
+/* A jump here: 108,109,111 have been used for various private purposes. */
+#define BLKGETSIZE64 _IOR(0x12,110,sizeof(u64))	/* return device size in bytes (u64 *arg) */
 #define BLKBSZGET  _IOR(0x12,112,sizeof(int))
 #define BLKBSZSET  _IOW(0x12,113,sizeof(int))