Skip to contentSkip to conversation

scsi BLKGETSIZE breakage in -pre2

PATCH Andrew Morton 3 participants 3 messages Nov 10, 2001 Block layer

lore
Share & tools
lore
#0 lore raw

sd_ioctl() was changed to pass BLKGETSIZE off to blk_ioctl(), but blk_ioctl() doesn't implement it.

So `cfdisk /dev/sda' is failing.

Simply copying the -ac version of blkpg.c across fixes it for me.

drivers/block/blkpg.c +13 -12
@@ -195,8 +195,13 @@ int blkpg_ioctl(kdev_t dev, struct blkpg
 
 int blk_ioctl(kdev_t dev, unsigned int cmd, unsigned long arg)
 {
+	struct gendisk *g;
+	u64 ullval = 0;
 	int intval;
 
+	if (!dev)
+		return -EINVAL;
+
 	switch (cmd) {
 		case BLKROSET:
 			if (!capable(CAP_SYS_ADMIN))
@@ -212,7 +217,7 @@ int blk_ioctl(kdev_t dev, unsigned int c
 		case BLKRASET:
 			if(!capable(CAP_SYS_ADMIN))
 				return -EACCES;
-			if(!dev || arg > 0xff)
+			if(arg > 0xff)
 				return -EINVAL;
 			read_ahead[MAJOR(dev)] = arg;
 			return 0;
@@ -224,8 +229,6 @@ int blk_ioctl(kdev_t dev, unsigned int c
 		case BLKFLSBUF:
 			if(!capable(CAP_SYS_ADMIN))
 				return -EACCES;
-			if (!dev)
-				return -EINVAL;
 			fsync_dev(dev);
 			invalidate_buffers(dev);
 			return 0;
@@ -235,18 +238,16 @@ int blk_ioctl(kdev_t dev, unsigned int c
 			intval = get_hardsect_size(dev);
 			return put_user(intval, (int *) arg);
 
-#if 0
 		case BLKGETSIZE:
-			/* Today get_gendisk() requires a linear scan;
-			   add this when dev has pointer type. */
-			/* add BLKGETSIZE64 too */
+		case BLKGETSIZE64:
 			g = get_gendisk(dev);
-			if (!g)
-				ulongval = 0;
+			if (g)
+				ullval = g->part[MINOR(dev)].nr_sects;
+
+			if (cmd == BLKGETSIZE)
+				return put_user((unsigned long)ullval, (unsigned long *)arg);
 			else
-				ulongval = g->part[MINOR(dev)].nr_sects;
-			return put_user(ulongval, (unsigned long *) arg);
-#endif
+				return put_user(ullval, (u64 *)arg);
 #if 0
 		case BLKRRPART: /* Re-read partition tables */
 			if (!capable(CAP_SYS_ADMIN))
#1 lore raw
Quoted 7 lines

sd_ioctl() was changed to pass BLKGETSIZE off to blk_ioctl(), but blk_ioctl() doesn't implement it.

So `cfdisk /dev/sda' is failing.

Simply copying the -ac version of blkpg.c across fixes it for me.

I'm feeding Linus stuff bit by bit - I managed to misorder that one.

#2 lore raw
Quoted 9 lines · Alan Cox
Quoted 7 lines

sd_ioctl() was changed to pass BLKGETSIZE off to blk_ioctl(), but blk_ioctl() doesn't implement it.

So `cfdisk /dev/sda' is failing.

Simply copying the -ac version of blkpg.c across fixes it for me.

I'm feeding Linus stuff bit by bit - I managed to misorder that one.

It has one positive side: mkntfs failed so I finally got round to implementing device size determination via binary lseek search (a la e2fsutils library) and I can test it without having to modify the mkntfs source by booting into -pre2. (-:

Anton

Signature · 5 lines
  "I've not lost my mind. It's backed up on tape somewhere." - Unknown
-- 
Anton Altaparmakov <aia21 at cam.ac.uk> (replace at with @)
Linux NTFS Maintainer / WWW: http://linux-ntfs.sf.net/
ICQ: 8561279 / WWW: http://www-stu.christs.cam.ac.uk/~aia21/