Skip to contentSkip to conversation

Enhancement of /proc/partitions output (2.5.1-pre5)

PATCH In review Anton Altaparmakov 2 participants 2 messages Dec 1, 2001 Block layer

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Enhancement of /proc/partitions output (2.5.1-pre5)

Linus,

Please consider below patch which adds the starting sector and number of sectors to /proc/partitions.

It works fine here and I find having this information output can be very useful (especially when the values in the kernel don't match the values output by fdisk for example).

Best regards,

Anton

Signature · 30 lines
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/


diff -u -urN linux-2.5.1-pre5-vanilla/drivers/block/genhd.c l251p5/drivers/block/genhd.c
--- linux-2.5.1-pre5-vanilla/drivers/block/genhd.c	Sat Dec  1 06:09:57 2001
+++ l251p5/drivers/block/genhd.c	Sat Dec  1 03:57:57 2001
@@ -149,7 +149,8 @@
 	char buf[64];
 	int len, n;
 
-	len = sprintf(page, "major minor  #blocks  name\n\n");
+	len = sprintf(page, "major minor   #blocks  start_sect   nr_sects  "
+			"name\n\n");
 	read_lock(&gendisk_lock);
 	for (gp = gendisk_head; gp; gp = gp->next) {
 		for (n = 0; n < (gp->nr_real << gp->minor_shift); n++) {
@@ -157,8 +158,10 @@
 				continue;
 
 			len += snprintf(page + len, 63,
-					"%4d  %4d %10d %s\n",
+					"%4d  %4d %10d  %10lu %10lu  %s\n",
 					gp->major, n, gp->sizes[n],
+					gp->part[n].start_sect,
+					gp->part[n].nr_sects,
 					disk_name(gp, n, buf));
 			if (len < offset)
 				offset -= len, len = 0;
#1 lore raw
Quoted 7 lines · Anton Altaparmakov

Linus,
Please consider below patch which adds the starting sector and number of sectors to /proc/partitions.

It works fine here and I find having this information output can be very useful (especially when the values in the kernel don't match the values output by fdisk for example).

Please do not accept as-is. This breaks the format of /proc/partitions terribly, and all of the code that looks at it (fsck, mount, etc). Rather add the start_sect and nr_sects parameters _after_ the name parameter, and it will be "mostly" ok.

While we are at it, how about adding the partition type to the output? This is the only reason that I ever need to re-parse the on-disk crud from DOS partition tables, and the kernel already handles it when it is parsing the partition table. For the "partitions" that don't have DOS-style partition types, we can either just put a string (like LVM or MD) which may be useful for a variety of other reasons.

(Purely hand-edited version of Anton's patch changing it to have the
new fields at the end, may not apply, may not line up strings properly. Doesn't include suggested parition type field either).

On a similar note - Linus, will you accept a patch which fixes the block device naming, to make it a per driver issue, rather than embedding it into the core code? I have one sitting around from way back, that has been itching to get in.

Cheers, Andreas
============================================================================

drivers/block/genhd.c +6 -3
diff -u -urN linux-2.5.1-pre5-vanilla/drivers/block/genhd.c l251p5/drivers/block/genhd.c
@@ -149,7 +149,8 @@
 	char buf[64];
 	int len, n;
 
-	len = sprintf(page, "major minor  #blocks  name\n\n");
+	len = sprintf(page, "major minor %9s %-16s %10s %10s\n",
+                     "#blocks", "name", "start_sect", "nr_sects");
 	read_lock(&gendisk_lock);
 	for (gp = gendisk_head; gp; gp = gp->next) {
 		for (n = 0; n < (gp->nr_real << gp->minor_shift); n++) {
@@ -157,8 +158,10 @@
 				continue;
 
 			len += snprintf(page + len, 63,
-					"%4d  %4d %10d %s\n",
+					"%4d  %4d %10d %-16s %10lu %10lu\n",
 					gp->major, n, gp->sizes[n],
-					disk_name(gp, n, buf));
+					disk_name(gp, n, buf),
+					gp->part[n].start_sect,
+					gp->part[n].nr_sects);
 			if (len < offset)
 				offset -= len, len = 0;

--
Andreas Dilger
http://sourceforge.net/projects/ext2resize/
http://www-mddsp.enel.ucalgary.ca/People/adilger/