Skip to contentSkip to conversation

/proc/partitions broken in 2.5.23

DISCUSSION Dave Jones 3 participants 6 messages Jun 19, 2002 Block layer

lore
Share & tools
lore

Dave Jones

author
#0 lore raw

I got a bug report about an issue with LVM in 2.5.22-dj1, which turns out to be caused by broken /proc/partitions in mainline.

(davej@mesh:davej)$ cat /proc/partitions 
major minor  #blocks  name

8 0 0 sda
22 0 1515870810 hdc
22 64 1515870810 hdd

   3     0   29316672 hda
   3     1     117400 hda1
   3     2          1 hda2
   3     5     999904 hda5
   3     6    1499872 hda6
   3     7     683392 hda7
   3     8   26015944 hda8

3 64 1515870810 hdb

Note the huge numbers in hex are 0x5a5a5a5a, so something seems to be getting poisoned somewhere.

Also, should partitions with 0 blocks be showing up ? I don't recall that happening with the old-style 2.4 code.

Dave

Signature · 2 lines
| Dave Jones.        http://www.codemonkey.org.uk
| SuSE Labs
#1 lore raw
Quoted 16 lines · Dave Jones

I got a bug report about an issue with LVM in 2.5.22-dj1, which turns out to be caused by broken /proc/partitions in mainline.

(davej@mesh:davej)$ cat /proc/partitions 
major minor  #blocks  name

8 0 0 sda
22 0 1515870810 hdc
22 64 1515870810 hdd

   3     0   29316672 hda
   3     1     117400 hda1
   3     2          1 hda2
   3     5     999904 hda5
   3     6    1499872 hda6
   3     7     683392 hda7
   3     8   26015944 hda8
Quoted 7 lines

3 64 1515870810 hdb

Note the huge numbers in hex are 0x5a5a5a5a, so something seems to be getting poisoned somewhere.

Also, should partitions with 0 blocks be showing up ? I don't recall that happening with the old-style 2.4 code.

I changed something here a few weeks ago. The idea was to avoid listing partitions of size 0 but do list full devices, regardless of size. Especially in case of removable media that is useful. For example, a

	blockdev --rereadpt /dev/sda

might show that there is something there now.

Will look at what might cause your strange numbers. Unfortunately recent 2.5 kernels do not boot for me.

Andries

author
#2 lore raw
Quoted 10 lines · Andries Brouwer
Quoted 10 lines

22 0 1515870810 hdc
22 64 1515870810 hdd

   3     0   29316672 hda
   3     1     117400 hda1
   3     2          1 hda2
   3     5     999904 hda5
   3     6    1499872 hda6
   3     7     683392 hda7
   3     8   26015944 hda8

3 64 1515870810 hdb

Quoted 6 lines

I changed something here a few weeks ago. The idea was to avoid listing partitions of size 0 but do list full devices, regardless of size. Especially in case of removable media that is useful. For example, a

	blockdev --rereadpt /dev/sda

might show that there is something there now.

Seems it doesn't handle the case of 'no media in drive' too well. hdc - cdrom, hdd - zip drive, hdb - no device there.

hda2 is odd looking too showing a #blocks of '1', when it's actually..

Device Boot Start End Blocks Id System
/dev/hda2 234 58168 29199240 5 Extended

Oddly, on another machine, it detects an LS-120 drive with no media correctly..
22 64 0 hdd

(but still gets the 'no device' case wrong on that box).

Dave.

Signature · 2 lines
| Dave Jones.        http://www.codemonkey.org.uk
| SuSE Labs
#3 lore raw
Quoted 5 lines · Dave Jones

hda2 is odd looking too showing a #blocks of '1', when it's actually..

Device Boot Start End Blocks Id System
/dev/hda2 234 58168 29199240 5 Extended

That is correct, and something I did before you were born.

An extended partition is a box containing logical partitions. It is almost always an error when people want to write directly to it (confusing the extended partition with some logical partition inside). After a number of reports of people who messed up their disk by doing mkswap or mkfs on an extended partition I changed the length of an extended partition to 1 block, enough for LILO but stopping mkswap and mkfs.
People who really want to access these blocks, like e.g. fdisk, can do so via /dev/hda.

Andries

author
#4 lore raw
Quoted 7 lines · Andries Brouwer

An extended partition is a box containing logical partitions. It is almost always an error when people want to write directly to it (confusing the extended partition with some logical partition inside). After a number of reports of people who messed up their disk by doing mkswap or mkfs on an extended partition I changed the length of an extended partition to 1 block, enough for LILO but stopping mkswap and mkfs.

Ah, that makes perfect sense to me now.

Dave.

Signature · 2 lines
| Dave Jones.        http://www.codemonkey.org.uk
| SuSE Labs
#5 lore raw
In reply to Andries Brouwer
Quoted 3 lines · you

I changed something here a few weeks ago. The idea was to avoid listing partitions of size 0 but do list full devices, regardless of size. Especially in case of removable media that is useful.

I traced the change to the part of mainline ChangeSet 1.496 given below (warning: cut and pasted). It seems to cause every possible device that a driver could provide to show up in /proc/partitions. For LVM, that's a zillion devices, and /proc/partitions overflows, showing some random pages from memory. Reverting the patch below makes /proc/partitions and LVM happy again.

Cheers,
Wayne

drivers/block/genhd.c +3 -2
@@ -177,9 +177,10 @@
 	if (sgp == gendisk_head)
 		seq_puts(part, "major minor  #blocks  name\n\n");
 
-	/* show all non-0 size partitions of this disk */
+	/* show the full disk and all non-0 size partitions of it */
 	for (n = 0; n < (sgp->nr_real << sgp->minor_shift); n++) {
-		if (sgp->part[n].nr_sects == 0)
+		int minormask = (1<<sgp->minor_shift) - 1;
+		if ((n & minormask) && sgp->part[n].nr_sects == 0)
 			continue;
 		seq_printf(part, "%4d  %4d %10d %s\n",
 			sgp->major, n, sgp->sizes[n],