Re: partitions

Alexander Viro
2002-07-24T19:02:50Z

On Wed, 24 Jul 2002, Andries Brouwer wrote:

> On Thu, Jul 25, 2002 at 12:11:08AM +0800, David Chow wrote:
>
> > Is there any global variables or list in the kernel space that I can
> > find out which partitions are available in the system?
>
> Look at the struct gendisk chain.

... and you will get a random set of things. E.g. you might very well
find a gendisk shared by hda (with its partitions) and hdb (either
unpartitioned disk or a CDROM; no way to tell which one it is). OTOH,
you will not find a SCSI CDROM. You will find IDE-floppy. You will not
find paride one. You will find a very odd gendisk for RAID devices
(even though they are not partitioned). You will not find one for loop
or nbd.

IOW, contents of /proc/partitions or (soon to be late) gendisk chain
is random - any code that relies on it to give you a meaningful set
of devices is buggered.

BTW, going through /proc/partitions and blindly opening all devices you
see is _NOT_ a good idea - it will show you absent devices if there is
something with the same major and higher minor. Why? Beats me.

Basically, gendisks are crap. Why on the earth they were created as
per-major objects instead of per-disk ones is a mistery, but whatever
reason it had, it had acted as serious source of mess. For many years.
Right now I'm cleaning that mess up in 2.5 and I have nothing nice to
say about the bright guys responsible for its creation. Sorry.