sysfs question: how to map major:minor to name under /sys

From: Neil Brown
Date: Wed Dec 14 2005 - 22:15:52 EST



Hi,
I have a question about sysfs related usage.

Suppose I have a major:minor number for a block device - maybe from
fstat of a filedescriptor I was given, or stat of a name in /dev.
How do I find the directory in /sys/block that contains relevant
information?

It seems to me that there is no direct way, and maybe there should
be. (I can do a find of 'dev' file and compare, which is fine in a
one-off shell script, but sub-optimal in general).

The most obvious solution would be to have a directory somewhere full
of symlinks:
/sys/block_dev/8:0 -> ../block/sda
or whatever.
Is this reasonable? Should I try it?

The particular case that I am interested in involves md.
In this case I can find the right /sys/block/mdX entry easily enough
because I *know* how the names are generated. However when a block
device is added to an array, it gets an entry like
/sys/block/md4/md/dev-sda
I would like to be able to easily find that given just the
information that 8:0 was added.
If the above directory of symlinks existed, I could readlink the
relevant entry, take the basename, and add "md/dev-" to front of
that.

Comments?

NeilBrown
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/