sysfs: add /sys/dev/{char,block} to lookup sysfs path by major:minor

Why?:
There are occasions where userspace would like to access sysfs
attributes for a device but it may not know how sysfs has named the
device or the path.  For example what is the sysfs path for
/dev/disk/by-id/ata-ST3160827AS_5MT004CK?  With this change a call to
stat(2) returns the major:minor then userspace can see that
/sys/dev/block/8:32 links to /sys/block/sdc.

What are the alternatives?:
1/ Add an ioctl to return the path: Doable, but sysfs is meant to reduce
   the need to proliferate ioctl interfaces into the kernel, so this
   seems counter productive.

2/ Use udev to create these symlinks: Also doable, but it adds a
   udev dependency to utilities that might be running in a limited
   environment like an initramfs.

3/ Do a full-tree search of sysfs.

[[email protected]: fix duplicate registrations]
[[email protected]: cleanup suggestions]

Cc: Neil Brown <[email protected]>
Cc: Tejun Heo <[email protected]>
Acked-by: Kay Sievers <[email protected]>
Reviewed-by: SL Baur <[email protected]>
Acked-by: Kay Sievers <[email protected]>
Acked-by: Mark Lord <[email protected]>
Acked-by: H. Peter Anvin <[email protected]>
Signed-off-by: Dan Williams <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
This commit is contained in:
Dan Williams 2008-04-21 10:51:07 -07:00 • committed by Greg Kroah-Hartman
commit e105b8bfc7
7 changed files with 124 additions and 2 deletions

View file

@ -370,7 +370,10 @@ static struct kobject *base_probe(dev_t devt, int *part, void *data)
static int __init genhd_device_init(void)
{
int error = class_register(&block_class);
int error;
block_class.dev_kobj = sysfs_dev_block_kobj;
error = class_register(&block_class);
if (unlikely(error))
return error;
bdev_map = kobj_map_init(base_probe, &block_class_lock);