Commit edfaa7c3 authored by Kay Sievers's avatar Kay Sievers Committed by Greg Kroah-Hartman

Driver core: convert block from raw kobjects to core devices

This moves the block devices to /sys/class/block. It will create a
flat list of all block devices, with the disks and partitions in one
directory. For compatibility /sys/block is created and contains symlinks
to the disks.

  /sys/class/block
  |-- sda -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
  |-- sda1 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda1
  |-- sda10 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda10
  |-- sda5 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda5
  |-- sda6 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda6
  |-- sda7 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda7
  |-- sda8 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda8
  |-- sda9 -> ../../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda/sda9
  `-- sr0 -> ../../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0

  /sys/block/
  |-- sda -> ../devices/pci0000:00/0000:00:1f.2/host0/target0:0:0/0:0:0:0/block/sda
  `-- sr0 -> ../devices/pci0000:00/0000:00:1f.2/host1/target1:0:0/1:0:0:0/block/sr0
Signed-off-by: default avatarKay Sievers <kay.sievers@vrfy.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@suse.de>
parent 09f82ea9
This diff is collapsed.
...@@ -4182,7 +4182,7 @@ int blk_register_queue(struct gendisk *disk) ...@@ -4182,7 +4182,7 @@ int blk_register_queue(struct gendisk *disk)
if (!q || !q->request_fn) if (!q || !q->request_fn)
return -ENXIO; return -ENXIO;
q->kobj.parent = kobject_get(&disk->kobj); q->kobj.parent = kobject_get(&disk->dev.kobj);
ret = kobject_add(&q->kobj); ret = kobject_add(&q->kobj);
if (ret < 0) if (ret < 0)
...@@ -4209,6 +4209,6 @@ void blk_unregister_queue(struct gendisk *disk) ...@@ -4209,6 +4209,6 @@ void blk_unregister_queue(struct gendisk *disk)
kobject_uevent(&q->kobj, KOBJ_REMOVE); kobject_uevent(&q->kobj, KOBJ_REMOVE);
kobject_del(&q->kobj); kobject_del(&q->kobj);
kobject_put(&disk->kobj); kobject_put(&disk->dev.kobj);
} }
} }
...@@ -17,6 +17,7 @@ ...@@ -17,6 +17,7 @@
#include <linux/kdev_t.h> #include <linux/kdev_t.h>
#include <linux/err.h> #include <linux/err.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/genhd.h>
#include "base.h" #include "base.h"
#define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr) #define to_class_attr(_attr) container_of(_attr, struct class_attribute, attr)
...@@ -149,7 +150,13 @@ int class_register(struct class * cls) ...@@ -149,7 +150,13 @@ int class_register(struct class * cls)
if (error) if (error)
return error; return error;
#ifdef CONFIG_SYSFS_DEPRECATED
/* let the block class directory show up in the root of sysfs */
if (cls != &block_class)
cls->subsys.kobj.kset = class_kset;
#else
cls->subsys.kobj.kset = class_kset; cls->subsys.kobj.kset = class_kset;
#endif
cls->subsys.kobj.ktype = &class_ktype; cls->subsys.kobj.ktype = &class_ktype;
error = kset_register(&cls->subsys); error = kset_register(&cls->subsys);
......
...@@ -671,14 +671,15 @@ static int device_add_class_symlinks(struct device *dev) ...@@ -671,14 +671,15 @@ static int device_add_class_symlinks(struct device *dev)
#ifdef CONFIG_SYSFS_DEPRECATED #ifdef CONFIG_SYSFS_DEPRECATED
/* stacked class devices need a symlink in the class directory */ /* stacked class devices need a symlink in the class directory */
if (dev->kobj.parent != &dev->class->subsys.kobj) { if (dev->kobj.parent != &dev->class->subsys.kobj &&
dev->type != &part_type) {
error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj, error = sysfs_create_link(&dev->class->subsys.kobj, &dev->kobj,
dev->bus_id); dev->bus_id);
if (error) if (error)
goto out_subsys; goto out_subsys;
} }
if (dev->parent) { if (dev->parent && dev->type != &part_type) {
struct device *parent = dev->parent; struct device *parent = dev->parent;
char *class_name; char *class_name;
...@@ -707,10 +708,11 @@ static int device_add_class_symlinks(struct device *dev) ...@@ -707,10 +708,11 @@ static int device_add_class_symlinks(struct device *dev)
return 0; return 0;
out_device: out_device:
if (dev->parent) if (dev->parent && dev->type != &part_type)
sysfs_remove_link(&dev->kobj, "device"); sysfs_remove_link(&dev->kobj, "device");
out_busid: out_busid:
if (dev->kobj.parent != &dev->class->subsys.kobj) if (dev->kobj.parent != &dev->class->subsys.kobj &&
dev->type != &part_type)
sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
#else #else
/* link in the class directory pointing to the device */ /* link in the class directory pointing to the device */
...@@ -719,7 +721,7 @@ static int device_add_class_symlinks(struct device *dev) ...@@ -719,7 +721,7 @@ static int device_add_class_symlinks(struct device *dev)
if (error) if (error)
goto out_subsys; goto out_subsys;
if (dev->parent) { if (dev->parent && dev->type != &part_type) {
error = sysfs_create_link(&dev->kobj, &dev->parent->kobj, error = sysfs_create_link(&dev->kobj, &dev->parent->kobj,
"device"); "device");
if (error) if (error)
...@@ -743,7 +745,7 @@ static void device_remove_class_symlinks(struct device *dev) ...@@ -743,7 +745,7 @@ static void device_remove_class_symlinks(struct device *dev)
return; return;
#ifdef CONFIG_SYSFS_DEPRECATED #ifdef CONFIG_SYSFS_DEPRECATED
if (dev->parent) { if (dev->parent && dev->type != &part_type) {
char *class_name; char *class_name;
class_name = make_class_name(dev->class->name, &dev->kobj); class_name = make_class_name(dev->class->name, &dev->kobj);
...@@ -754,10 +756,11 @@ static void device_remove_class_symlinks(struct device *dev) ...@@ -754,10 +756,11 @@ static void device_remove_class_symlinks(struct device *dev)
sysfs_remove_link(&dev->kobj, "device"); sysfs_remove_link(&dev->kobj, "device");
} }
if (dev->kobj.parent != &dev->class->subsys.kobj) if (dev->kobj.parent != &dev->class->subsys.kobj &&
dev->type != &part_type)
sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
#else #else
if (dev->parent) if (dev->parent && dev->type != &part_type)
sysfs_remove_link(&dev->kobj, "device"); sysfs_remove_link(&dev->kobj, "device");
sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id); sysfs_remove_link(&dev->class->subsys.kobj, dev->bus_id);
...@@ -925,6 +928,7 @@ struct device * get_device(struct device * dev) ...@@ -925,6 +928,7 @@ struct device * get_device(struct device * dev)
*/ */
void put_device(struct device * dev) void put_device(struct device * dev)
{ {
/* might_sleep(); */
if (dev) if (dev)
kobject_put(&dev->kobj); kobject_put(&dev->kobj);
} }
......
...@@ -15,8 +15,10 @@ ...@@ -15,8 +15,10 @@
static struct kmem_cache *buf_pool_cache; static struct kmem_cache *buf_pool_cache;
static ssize_t aoedisk_show_state(struct gendisk * disk, char *page) static ssize_t aoedisk_show_state(struct device *dev,
struct device_attribute *attr, char *page)
{ {
struct gendisk *disk = dev_to_disk(dev);
struct aoedev *d = disk->private_data; struct aoedev *d = disk->private_data;
return snprintf(page, PAGE_SIZE, return snprintf(page, PAGE_SIZE,
...@@ -26,50 +28,47 @@ static ssize_t aoedisk_show_state(struct gendisk * disk, char *page) ...@@ -26,50 +28,47 @@ static ssize_t aoedisk_show_state(struct gendisk * disk, char *page)
(d->nopen && !(d->flags & DEVFL_UP)) ? ",closewait" : ""); (d->nopen && !(d->flags & DEVFL_UP)) ? ",closewait" : "");
/* I'd rather see nopen exported so we can ditch closewait */ /* I'd rather see nopen exported so we can ditch closewait */
} }
static ssize_t aoedisk_show_mac(struct gendisk * disk, char *page) static ssize_t aoedisk_show_mac(struct device *dev,
struct device_attribute *attr, char *page)
{ {
struct gendisk *disk = dev_to_disk(dev);
struct aoedev *d = disk->private_data; struct aoedev *d = disk->private_data;
return snprintf(page, PAGE_SIZE, "%012llx\n", return snprintf(page, PAGE_SIZE, "%012llx\n",
(unsigned long long)mac_addr(d->addr)); (unsigned long long)mac_addr(d->addr));
} }
static ssize_t aoedisk_show_netif(struct gendisk * disk, char *page) static ssize_t aoedisk_show_netif(struct device *dev,
struct device_attribute *attr, char *page)
{ {
struct gendisk *disk = dev_to_disk(dev);
struct aoedev *d = disk->private_data; struct aoedev *d = disk->private_data;
return snprintf(page, PAGE_SIZE, "%s\n", d->ifp->name); return snprintf(page, PAGE_SIZE, "%s\n", d->ifp->name);
} }
/* firmware version */ /* firmware version */
static ssize_t aoedisk_show_fwver(struct gendisk * disk, char *page) static ssize_t aoedisk_show_fwver(struct device *dev,
struct device_attribute *attr, char *page)
{ {
struct gendisk *disk = dev_to_disk(dev);
struct aoedev *d = disk->private_data; struct aoedev *d = disk->private_data;
return snprintf(page, PAGE_SIZE, "0x%04x\n", (unsigned int) d->fw_ver); return snprintf(page, PAGE_SIZE, "0x%04x\n", (unsigned int) d->fw_ver);
} }
static struct disk_attribute disk_attr_state = { static DEVICE_ATTR(state, S_IRUGO, aoedisk_show_state, NULL);
.attr = {.name = "state", .mode = S_IRUGO }, static DEVICE_ATTR(mac, S_IRUGO, aoedisk_show_mac, NULL);
.show = aoedisk_show_state static DEVICE_ATTR(netif, S_IRUGO, aoedisk_show_netif, NULL);
}; static struct device_attribute dev_attr_firmware_version = {
static struct disk_attribute disk_attr_mac = { .attr = { .name = "firmware-version", .mode = S_IRUGO, .owner = THIS_MODULE },
.attr = {.name = "mac", .mode = S_IRUGO }, .show = aoedisk_show_fwver,
.show = aoedisk_show_mac
};
static struct disk_attribute disk_attr_netif = {
.attr = {.name = "netif", .mode = S_IRUGO },
.show = aoedisk_show_netif
};
static struct disk_attribute disk_attr_fwver = {
.attr = {.name = "firmware-version", .mode = S_IRUGO },
.show = aoedisk_show_fwver
}; };
static struct attribute *aoe_attrs[] = { static struct attribute *aoe_attrs[] = {
&disk_attr_state.attr, &dev_attr_state.attr,
&disk_attr_mac.attr, &dev_attr_mac.attr,
&disk_attr_netif.attr, &dev_attr_netif.attr,
&disk_attr_fwver.attr, &dev_attr_firmware_version.attr,
NULL NULL,
}; };
static const struct attribute_group attr_group = { static const struct attribute_group attr_group = {
...@@ -79,12 +78,12 @@ static const struct attribute_group attr_group = { ...@@ -79,12 +78,12 @@ static const struct attribute_group attr_group = {
static int static int
aoedisk_add_sysfs(struct aoedev *d) aoedisk_add_sysfs(struct aoedev *d)
{ {
return sysfs_create_group(&d->gd->kobj, &attr_group); return sysfs_create_group(&d->gd->dev.kobj, &attr_group);
} }
void void
aoedisk_rm_sysfs(struct aoedev *d) aoedisk_rm_sysfs(struct aoedev *d)
{ {
sysfs_remove_group(&d->gd->kobj, &attr_group); sysfs_remove_group(&d->gd->dev.kobj, &attr_group);
} }
static int static int
......
...@@ -375,14 +375,17 @@ static struct request *nbd_read_stat(struct nbd_device *lo) ...@@ -375,14 +375,17 @@ static struct request *nbd_read_stat(struct nbd_device *lo)
return NULL; return NULL;
} }
static ssize_t pid_show(struct gendisk *disk, char *page) static ssize_t pid_show(struct device *dev,
struct device_attribute *attr, char *buf)
{ {
return sprintf(page, "%ld\n", struct gendisk *disk = dev_to_disk(dev);
return sprintf(buf, "%ld\n",
(long) ((struct nbd_device *)disk->private_data)->pid); (long) ((struct nbd_device *)disk->private_data)->pid);
} }
static struct disk_attribute pid_attr = { static struct device_attribute pid_attr = {
.attr = { .name = "pid", .mode = S_IRUGO }, .attr = { .name = "pid", .mode = S_IRUGO, .owner = THIS_MODULE },
.show = pid_show, .show = pid_show,
}; };
...@@ -394,7 +397,7 @@ static int nbd_do_it(struct nbd_device *lo) ...@@ -394,7 +397,7 @@ static int nbd_do_it(struct nbd_device *lo)
BUG_ON(lo->magic != LO_MAGIC); BUG_ON(lo->magic != LO_MAGIC);
lo->pid = current->pid; lo->pid = current->pid;
ret = sysfs_create_file(&lo->disk->kobj, &pid_attr.attr); ret = sysfs_create_file(&lo->disk->dev.kobj, &pid_attr.attr);
if (ret) { if (ret) {
printk(KERN_ERR "nbd: sysfs_create_file failed!"); printk(KERN_ERR "nbd: sysfs_create_file failed!");
return ret; return ret;
...@@ -403,7 +406,7 @@ static int nbd_do_it(struct nbd_device *lo) ...@@ -403,7 +406,7 @@ static int nbd_do_it(struct nbd_device *lo)
while ((req = nbd_read_stat(lo)) != NULL) while ((req = nbd_read_stat(lo)) != NULL)
nbd_end_request(req); nbd_end_request(req);
sysfs_remove_file(&lo->disk->kobj, &pid_attr.attr); sysfs_remove_file(&lo->disk->dev.kobj, &pid_attr.attr);
return 0; return 0;
} }
......
...@@ -1173,7 +1173,7 @@ static struct kobject *exact_match(dev_t dev, int *part, void *data) ...@@ -1173,7 +1173,7 @@ static struct kobject *exact_match(dev_t dev, int *part, void *data)
{ {
struct gendisk *p = data; struct gendisk *p = data;
*part &= (1 << PARTN_BITS) - 1; *part &= (1 << PARTN_BITS) - 1;
return &p->kobj; return &p->dev.kobj;
} }
static int exact_lock(dev_t dev, void *data) static int exact_lock(dev_t dev, void *data)
......
...@@ -1109,7 +1109,7 @@ static void event_callback(void *context) ...@@ -1109,7 +1109,7 @@ static void event_callback(void *context)
list_splice_init(&md->uevent_list, &uevents); list_splice_init(&md->uevent_list, &uevents);
spin_unlock_irqrestore(&md->uevent_lock, flags); spin_unlock_irqrestore(&md->uevent_lock, flags);
dm_send_uevents(&uevents, &md->disk->kobj); dm_send_uevents(&uevents, &md->disk->dev.kobj);
atomic_inc(&md->event_nr); atomic_inc(&md->event_nr);
wake_up(&md->eventq); wake_up(&md->eventq);
...@@ -1530,7 +1530,7 @@ int dm_resume(struct mapped_device *md) ...@@ -1530,7 +1530,7 @@ int dm_resume(struct mapped_device *md)
*---------------------------------------------------------------*/ *---------------------------------------------------------------*/
void dm_kobject_uevent(struct mapped_device *md) void dm_kobject_uevent(struct mapped_device *md)
{ {
kobject_uevent(&md->disk->kobj, KOBJ_CHANGE); kobject_uevent(&md->disk->dev.kobj, KOBJ_CHANGE);
} }
uint32_t dm_next_uevent_seq(struct mapped_device *md) uint32_t dm_next_uevent_seq(struct mapped_device *md)
......
...@@ -1396,9 +1396,9 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev) ...@@ -1396,9 +1396,9 @@ static int bind_rdev_to_array(mdk_rdev_t * rdev, mddev_t * mddev)
goto fail; goto fail;
if (rdev->bdev->bd_part) if (rdev->bdev->bd_part)
ko = &rdev->bdev->bd_part->kobj; ko = &rdev->bdev->bd_part->dev.kobj;
else else
ko = &rdev->bdev->bd_disk->kobj; ko = &rdev->bdev->bd_disk->dev.kobj;
if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) { if ((err = sysfs_create_link(&rdev->kobj, ko, "block"))) {
kobject_del(&rdev->kobj); kobject_del(&rdev->kobj);
goto fail; goto fail;
...@@ -3083,7 +3083,7 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data) ...@@ -3083,7 +3083,7 @@ static struct kobject *md_probe(dev_t dev, int *part, void *data)
add_disk(disk); add_disk(disk);
mddev->gendisk = disk; mddev->gendisk = disk;
mutex_unlock(&disks_mutex); mutex_unlock(&disks_mutex);
error = kobject_init_and_add(&mddev->kobj, &md_ktype, &disk->kobj, error = kobject_init_and_add(&mddev->kobj, &md_ktype, &disk->dev.kobj,
"%s", "md"); "%s", "md");
if (error) if (error)
printk(KERN_WARNING "md: cannot register %s/md - name in use\n", printk(KERN_WARNING "md: cannot register %s/md - name in use\n",
...@@ -3361,7 +3361,7 @@ static int do_md_run(mddev_t * mddev) ...@@ -3361,7 +3361,7 @@ static int do_md_run(mddev_t * mddev)
mddev->changed = 1; mddev->changed = 1;
md_new_event(mddev); md_new_event(mddev);
kobject_uevent(&mddev->gendisk->kobj, KOBJ_CHANGE); kobject_uevent(&mddev->gendisk->dev.kobj, KOBJ_CHANGE);
return 0; return 0;
} }
......
...@@ -738,9 +738,9 @@ EXPORT_SYMBOL(bd_release); ...@@ -738,9 +738,9 @@ EXPORT_SYMBOL(bd_release);
static struct kobject *bdev_get_kobj(struct block_device *bdev) static struct kobject *bdev_get_kobj(struct block_device *bdev)
{ {
if (bdev->bd_contains != bdev) if (bdev->bd_contains != bdev)
return kobject_get(&bdev->bd_part->kobj); return kobject_get(&bdev->bd_part->dev.kobj);
else else
return kobject_get(&bdev->bd_disk->kobj); return kobject_get(&bdev->bd_disk->dev.kobj);
} }
static struct kobject *bdev_get_holder(struct block_device *bdev) static struct kobject *bdev_get_holder(struct block_device *bdev)
...@@ -1176,7 +1176,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) ...@@ -1176,7 +1176,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
ret = -ENXIO; ret = -ENXIO;
goto out_first; goto out_first;
} }
kobject_get(&p->kobj); kobject_get(&p->dev.kobj);
bdev->bd_part = p; bdev->bd_part = p;
bd_set_size(bdev, (loff_t) p->nr_sects << 9); bd_set_size(bdev, (loff_t) p->nr_sects << 9);
} }
...@@ -1299,7 +1299,7 @@ static int __blkdev_put(struct block_device *bdev, int for_part) ...@@ -1299,7 +1299,7 @@ static int __blkdev_put(struct block_device *bdev, int for_part)
module_put(owner); module_put(owner);
if (bdev->bd_contains != bdev) { if (bdev->bd_contains != bdev) {
kobject_put(&bdev->bd_part->kobj); kobject_put(&bdev->bd_part->dev.kobj);
bdev->bd_part = NULL; bdev->bd_part = NULL;
} }
bdev->bd_disk = NULL; bdev->bd_disk = NULL;
......
This diff is collapsed.
...@@ -10,9 +10,19 @@ ...@@ -10,9 +10,19 @@
*/ */
#include <linux/types.h> #include <linux/types.h>
#include <linux/kdev_t.h>
#ifdef CONFIG_BLOCK #ifdef CONFIG_BLOCK
#define kobj_to_dev(k) container_of(k, struct device, kobj)
#define dev_to_disk(device) container_of(device, struct gendisk, dev)
#define dev_to_part(device) container_of(device, struct hd_struct, dev)
extern struct device_type disk_type;
extern struct device_type part_type;
extern struct kobject *block_depr;
extern struct class block_class;
enum { enum {
/* These three have identical behaviour; use the second one if DOS FDISK gets /* These three have identical behaviour; use the second one if DOS FDISK gets
confused about extended/logical partitions starting past cylinder 1023. */ confused about extended/logical partitions starting past cylinder 1023. */
...@@ -84,7 +94,7 @@ struct partition { ...@@ -84,7 +94,7 @@ struct partition {
struct hd_struct { struct hd_struct {
sector_t start_sect; sector_t start_sect;
sector_t nr_sects; sector_t nr_sects;
struct kobject kobj; struct device dev;
struct kobject *holder_dir; struct kobject *holder_dir;
unsigned ios[2], sectors[2]; /* READs and WRITEs */ unsigned ios[2], sectors[2]; /* READs and WRITEs */
int policy, partno; int policy, partno;
...@@ -117,15 +127,14 @@ struct gendisk { ...@@ -117,15 +127,14 @@ struct gendisk {
* disks that can't be partitioned. */ * disks that can't be partitioned. */
char disk_name[32]; /* name of major driver */ char disk_name[32]; /* name of major driver */
struct hd_struct **part; /* [indexed by minor] */ struct hd_struct **part; /* [indexed by minor] */
int part_uevent_suppress;
struct block_device_operations *fops; struct block_device_operations *fops;
struct request_queue *queue; struct request_queue *queue;
void *private_data; void *private_data;
sector_t capacity; sector_t capacity;
int flags; int flags;
struct device *driverfs_dev; struct device *driverfs_dev; // FIXME: remove
struct kobject kobj; struct device dev;
struct kobject *holder_dir; struct kobject *holder_dir;
struct kobject *slave_dir; struct kobject *slave_dir;
...@@ -143,13 +152,6 @@ struct gendisk { ...@@ -143,13 +152,6 @@ struct gendisk {
struct work_struct async_notify; struct work_struct async_notify;
}; };
/* Structure for sysfs attributes on block devices */
struct disk_attribute {
struct attribute attr;
ssize_t (*show)(struct gendisk *, char *);
ssize_t (*store)(struct gendisk *, const char *, size_t);
};
/* /*
* Macros to operate on percpu disk statistics: * Macros to operate on percpu disk statistics:
* *
...@@ -411,7 +413,8 @@ struct unixware_disklabel { ...@@ -411,7 +413,8 @@ struct unixware_disklabel {
#define ADDPART_FLAG_RAID 1 #define ADDPART_FLAG_RAID 1
#define ADDPART_FLAG_WHOLEDISK 2 #define ADDPART_FLAG_WHOLEDISK 2
char *disk_name (struct gendisk *hd, int part, char *buf); extern dev_t blk_lookup_devt(const char *name);
extern char *disk_name (struct gendisk *hd, int part, char *buf);
extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev); extern int rescan_partitions(struct gendisk *disk, struct block_device *bdev);
extern void add_partition(struct gendisk *, int, sector_t, sector_t, int); extern void add_partition(struct gendisk *, int, sector_t, sector_t, int);
...@@ -423,12 +426,12 @@ extern struct gendisk *alloc_disk(int minors); ...@@ -423,12 +426,12 @@ extern struct gendisk *alloc_disk(int minors);
extern struct kobject *get_disk(struct gendisk *disk); extern struct kobject *get_disk(struct gendisk *disk);
extern void put_disk(struct gendisk *disk); extern void put_disk(struct gendisk *disk);
extern void genhd_media_change_notify(struct gendisk *disk); extern void genhd_media_change_notify(struct gendisk *disk);
extern void blk_register_region(dev_t dev, unsigned long range, extern void blk_register_region(dev_t devt, unsigned long range,
struct module *module, struct module *module,
struct kobject *(*probe)(dev_t, int *, void *), struct kobject *(*probe)(dev_t, int *, void *),
int (*lock)(dev_t, void *), int (*lock)(dev_t, void *),
void *data); void *data);
extern void blk_unregister_region(dev_t dev, unsigned long range); extern void blk_unregister_region(dev_t devt, unsigned long range);
static inline struct block_device *bdget_disk(struct gendisk *disk, int index) static inline struct block_device *bdget_disk(struct gendisk *disk, int index)
{ {
...@@ -441,6 +444,12 @@ static inline struct block_device *bdget_disk(struct gendisk *disk, int index) ...@@ -441,6 +444,12 @@ static inline struct block_device *bdget_disk(struct gendisk *disk, int index)
static inline void printk_all_partitions(void) { } static inline void printk_all_partitions(void) { }
static inline dev_t blk_lookup_devt(const char *name)
{
dev_t devt = MKDEV(0, 0);
return devt;
}
#endif /* CONFIG_BLOCK */ #endif /* CONFIG_BLOCK */
#endif #endif
...@@ -55,69 +55,6 @@ static int __init readwrite(char *str) ...@@ -55,69 +55,6 @@ static int __init readwrite(char *str)
__setup("ro", readonly); __setup("ro", readonly);
__setup("rw", readwrite); __setup("rw", readwrite);
static dev_t try_name(char *name, int part)
{
char path[64];
char buf[32];
int range;
dev_t res;
char *s;
int len;
int fd;
unsigned int maj, min;
/* read device number from .../dev */
sprintf(path, "/sys/block/%s/dev", name);
fd = sys_open(path, 0, 0);
if (fd < 0)
goto fail;
len = sys_read(fd, buf, 32);
sys_close(fd);
if (len <= 0 || len == 32 || buf[len - 1] != '\n')
goto fail;
buf[len - 1] = '\0';
if (sscanf(buf, "%u:%u", &maj, &min) == 2) {
/*
* Try the %u:%u format -- see print_dev_t()
*/
res = MKDEV(maj, min);
if (maj != MAJOR(res) || min != MINOR(res))
goto fail;
} else {
/*
* Nope. Try old-style "0321"
*/
res = new_decode_dev(simple_strtoul(buf, &s, 16));
if (*s)
goto fail;
}
/* if it's there and we are not looking for a partition - that's it */
if (!part)
return res;
/* otherwise read range from .../range */
sprintf(path, "/sys/block/%s/range", name);
fd = sys_open(path, 0, 0);
if (fd < 0)
goto fail;
len = sys_read(fd, buf, 32);
sys_close(fd);
if (len <= 0 || len == 32 || buf[len - 1] != '\n')
goto fail;
buf[len - 1] = '\0';
range = simple_strtoul(buf, &s, 10);
if (*s)
goto fail;
/* if partition is within range - we got it */
if (part < range)
return res + part;
fail:
return 0;
}
/* /*
* Convert a name into device number. We accept the following variants: * Convert a name into device number. We accept the following variants:
* *
...@@ -129,12 +66,10 @@ static dev_t try_name(char *name, int part) ...@@ -129,12 +66,10 @@ static dev_t try_name(char *name, int part)
* 5) /dev/<disk_name>p<decimal> - same as the above, that form is * 5) /dev/<disk_name>p<decimal> - same as the above, that form is
* used when disk name of partitioned disk ends on a digit. * used when disk name of partitioned disk ends on a digit.
* *
* If name doesn't have fall into the categories above, we return 0. * If name doesn't have fall into the categories above, we return (0,0).
* Sysfs is used to check if something is a disk name - it has * block_class is used to check if something is a disk name. If the disk
* all known disks under bus/block/devices. If the disk name * name contains slashes, the device name has them replaced with
* contains slashes, name of sysfs node has them replaced with * bangs.
* bangs. try_name() does the actual checks, assuming that sysfs
* is mounted on rootfs /sys.
*/ */
dev_t name_to_dev_t(char *name) dev_t name_to_dev_t(char *name)
...@@ -142,13 +77,6 @@ dev_t name_to_dev_t(char *name) ...@@ -142,13 +77,6 @@ dev_t name_to_dev_t(char *name)
char s[32]; char s[32];
char *p; char *p;
dev_t res = 0; dev_t res = 0;
int part;
#ifdef CONFIG_SYSFS
int mkdir_err = sys_mkdir("/sys", 0700);
if (sys_mount("sysfs", "/sys", "sysfs", 0, NULL) < 0)
goto out;
#endif
if (strncmp(name, "/dev/", 5) != 0) { if (strncmp(name, "/dev/", 5) != 0) {
unsigned maj, min; unsigned maj, min;
...@@ -164,6 +92,7 @@ dev_t name_to_dev_t(char *name) ...@@ -164,6 +92,7 @@ dev_t name_to_dev_t(char *name)
} }
goto done; goto done;
} }
name += 5; name += 5;
res = Root_NFS; res = Root_NFS;
if (strcmp(name, "nfs") == 0) if (strcmp(name, "nfs") == 0)
...@@ -178,35 +107,14 @@ dev_t name_to_dev_t(char *name) ...@@ -178,35 +107,14 @@ dev_t name_to_dev_t(char *name)
for (p = s; *p; p++) for (p = s; *p; p++)
if (*p == '/') if (*p == '/')
*p = '!'; *p = '!';
res = try_name(s, 0); res = blk_lookup_devt(s);
if (res) if (res)
goto done; goto done;
while (p > s && isdigit(p[-1])) fail:
p--; return 0;
if (p == s || !*p || *p == '0')
goto fail;
part = simple_strtoul(p, NULL, 10);
*p = '\0';
res = try_name(s, part);
if (res)
goto done;
if (p < s + 2 || !isdigit(p[-2]) || p[-1] != 'p')
goto fail;
p[-1] = '\0';
res = try_name(s, part);
done: done:
#ifdef CONFIG_SYSFS
sys_umount("/sys", 0);
out:
if (!mkdir_err)
sys_rmdir("/sys");
#endif
return res; return res;
fail:
res = 0;
goto done;
} }
static int __init root_dev_setup(char *line) static int __init root_dev_setup(char *line)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment