block: don't depend on consecutive minor space
[safe/jmp/linux-2.6] / block / genhd.c
index f2ac914..fa32d09 100644 (file)
 #include <linux/buffer_head.h>
 #include <linux/mutex.h>
 
-struct kset block_subsys;
-static DEFINE_MUTEX(block_subsys_lock);
+#include "blk.h"
+
+static DEFINE_MUTEX(block_class_lock);
+#ifndef CONFIG_SYSFS_DEPRECATED
+struct kobject *block_depr;
+#endif
+
+static struct device_type disk_type;
 
 /*
  * Can be deleted altogether. Later.
@@ -37,19 +43,17 @@ static inline int major_to_index(int major)
 }
 
 #ifdef CONFIG_PROC_FS
-
-void blkdev_show(struct seq_file *f, off_t offset)
+void blkdev_show(struct seq_file *seqf, off_t offset)
 {
        struct blk_major_name *dp;
 
        if (offset < BLKDEV_MAJOR_HASH_SIZE) {
-               mutex_lock(&block_subsys_lock);
+               mutex_lock(&block_class_lock);
                for (dp = major_names[offset]; dp; dp = dp->next)
-                       seq_printf(f, "%3d %s\n", dp->major, dp->name);
-               mutex_unlock(&block_subsys_lock);
+                       seq_printf(seqf, "%3d %s\n", dp->major, dp->name);
+               mutex_unlock(&block_class_lock);
        }
 }
-
 #endif /* CONFIG_PROC_FS */
 
 int register_blkdev(unsigned int major, const char *name)
@@ -57,7 +61,7 @@ int register_blkdev(unsigned int major, const char *name)
        struct blk_major_name **n, *p;
        int index, ret = 0;
 
-       mutex_lock(&block_subsys_lock);
+       mutex_lock(&block_class_lock);
 
        /* temporary */
        if (major == 0) {
@@ -102,7 +106,7 @@ int register_blkdev(unsigned int major, const char *name)
                kfree(p);
        }
 out:
-       mutex_unlock(&block_subsys_lock);
+       mutex_unlock(&block_class_lock);
        return ret;
 }
 
@@ -114,7 +118,7 @@ void unregister_blkdev(unsigned int major, const char *name)
        struct blk_major_name *p = NULL;
        int index = major_to_index(major);
 
-       mutex_lock(&block_subsys_lock);
+       mutex_lock(&block_class_lock);
        for (n = &major_names[index]; *n; n = &(*n)->next)
                if ((*n)->major == major)
                        break;
@@ -124,7 +128,7 @@ void unregister_blkdev(unsigned int major, const char *name)
                p = *n;
                *n = p->next;
        }
-       mutex_unlock(&block_subsys_lock);
+       mutex_unlock(&block_class_lock);
        kfree(p);
 }
 
@@ -137,29 +141,30 @@ static struct kobj_map *bdev_map;
  * range must be nonzero
  * The hash chain is sorted on range, so that subranges can override.
  */
-void blk_register_region(dev_t dev, unsigned long range, struct module *module,
+void blk_register_region(dev_t devt, unsigned long range, struct module *module,
                         struct kobject *(*probe)(dev_t, int *, void *),
                         int (*lock)(dev_t, void *), void *data)
 {
-       kobj_map(bdev_map, dev, range, module, probe, lock, data);
+       kobj_map(bdev_map, devt, range, module, probe, lock, data);
 }
 
 EXPORT_SYMBOL(blk_register_region);
 
-void blk_unregister_region(dev_t dev, unsigned long range)
+void blk_unregister_region(dev_t devt, unsigned long range)
 {
-       kobj_unmap(bdev_map, dev, range);
+       kobj_unmap(bdev_map, devt, range);
 }
 
 EXPORT_SYMBOL(blk_unregister_region);
 
-static struct kobject *exact_match(dev_t dev, int *part, void *data)
+static struct kobject *exact_match(dev_t devt, int *partno, void *data)
 {
        struct gendisk *p = data;
-       return &p->kobj;
+
+       return &p->dev.kobj;
 }
 
-static int exact_lock(dev_t dev, void *data)
+static int exact_lock(dev_t devt, void *data)
 {
        struct gendisk *p = data;
 
@@ -177,11 +182,20 @@ static int exact_lock(dev_t dev, void *data)
  */
 void add_disk(struct gendisk *disk)
 {
+       struct backing_dev_info *bdi;
+       int retval;
+
        disk->flags |= GENHD_FL_UP;
-       blk_register_region(MKDEV(disk->major, disk->first_minor),
-                           disk->minors, NULL, exact_match, exact_lock, disk);
+       disk->dev.devt = MKDEV(disk->major, disk->first_minor);
+       blk_register_region(disk_devt(disk), disk->minors, NULL,
+                           exact_match, exact_lock, disk);
        register_disk(disk);
        blk_register_queue(disk);
+
+       bdi = &disk->queue->backing_dev_info;
+       bdi_register_dev(bdi, disk_devt(disk));
+       retval = sysfs_create_link(&disk->dev.kobj, &bdi->dev->kobj, "bdi");
+       WARN_ON(retval);
 }
 
 EXPORT_SYMBOL(add_disk);
@@ -189,25 +203,59 @@ EXPORT_SYMBOL(del_gendisk);       /* in partitions/check.c */
 
 void unlink_gendisk(struct gendisk *disk)
 {
+       sysfs_remove_link(&disk->dev.kobj, "bdi");
+       bdi_unregister(&disk->queue->backing_dev_info);
        blk_unregister_queue(disk);
-       blk_unregister_region(MKDEV(disk->major, disk->first_minor),
-                             disk->minors);
+       blk_unregister_region(disk_devt(disk), disk->minors);
 }
 
-#define to_disk(obj) container_of(obj,struct gendisk,kobj)
-
 /**
  * get_gendisk - get partitioning information for a given device
- * @dev: device to get partitioning information for
+ * @devt: device to get partitioning information for
+ * @part: returned partition index
  *
  * This function gets the structure containing partitioning
- * information for the given device @dev.
+ * information for the given device @devt.
+ */
+struct gendisk *get_gendisk(dev_t devt, int *partno)
+{
+       struct kobject *kobj = kobj_lookup(bdev_map, devt, partno);
+       struct device *dev = kobj_to_dev(kobj);
+
+       return  kobj ? dev_to_disk(dev) : NULL;
+}
+
+/**
+ * bdget_disk - do bdget() by gendisk and partition number
+ * @disk: gendisk of interest
+ * @partno: partition number
+ *
+ * Find partition @partno from @disk, do bdget() on it.
+ *
+ * CONTEXT:
+ * Don't care.
+ *
+ * RETURNS:
+ * Resulting block_device on success, NULL on failure.
  */
-struct gendisk *get_gendisk(dev_t dev, int *part)
+extern struct block_device *bdget_disk(struct gendisk *disk, int partno)
 {
-       struct kobject *kobj = kobj_lookup(bdev_map, dev, part);
-       return  kobj ? to_disk(kobj) : NULL;
+       dev_t devt = MKDEV(0, 0);
+
+       if (partno == 0)
+               devt = disk_devt(disk);
+       else {
+               struct hd_struct *part = disk->part[partno - 1];
+
+               if (part && part->nr_sects)
+                       devt = part_devt(part);
+       }
+
+       if (likely(devt != MKDEV(0, 0)))
+               return bdget(devt);
+       return NULL;
 }
+EXPORT_SYMBOL(bdget_disk);
 
 /*
  * print a full list of all partitions - intended for places where the root
@@ -216,219 +264,230 @@ struct gendisk *get_gendisk(dev_t dev, int *part)
  */
 void __init printk_all_partitions(void)
 {
-       int n;
-       struct gendisk *sgp;
+       struct class_dev_iter iter;
+       struct device *dev;
 
-       mutex_lock(&block_subsys_lock);
-       /* For each block device... */
-       list_for_each_entry(sgp, &block_subsys.list, kobj.entry) {
+       class_dev_iter_init(&iter, &block_class, NULL, &disk_type);
+       while ((dev = class_dev_iter_next(&iter))) {
+               struct gendisk *disk = dev_to_disk(dev);
                char buf[BDEVNAME_SIZE];
+               int n;
+
                /*
-                * Don't show empty devices or things that have been surpressed
+                * Don't show empty devices or things that have been
+                * surpressed
                 */
-               if (get_capacity(sgp) == 0 ||
-                   (sgp->flags & GENHD_FL_SUPPRESS_PARTITION_INFO))
+               if (get_capacity(disk) == 0 ||
+                   (disk->flags & GENHD_FL_SUPPRESS_PARTITION_INFO))
                        continue;
 
                /*
-                * Note, unlike /proc/partitions, I am showing the numbers in
-                * hex - the same format as the root= option takes.
+                * Note, unlike /proc/partitions, I am showing the
+                * numbers in hex - the same format as the root=
+                * option takes.
                 */
                printk("%02x%02x %10llu %s",
-                       sgp->major, sgp->first_minor,
-                       (unsigned long long)get_capacity(sgp) >> 1,
-                       disk_name(sgp, 0, buf));
-               if (sgp->driverfs_dev != NULL &&
-                   sgp->driverfs_dev->driver != NULL)
+                      MAJOR(disk_devt(disk)), MINOR(disk_devt(disk)),
+                      (unsigned long long)get_capacity(disk) >> 1,
+                      disk_name(disk, 0, buf));
+               if (disk->driverfs_dev != NULL &&
+                   disk->driverfs_dev->driver != NULL)
                        printk(" driver: %s\n",
-                               sgp->driverfs_dev->driver->name);
+                              disk->driverfs_dev->driver->name);
                else
                        printk(" (driver?)\n");
 
                /* now show the partitions */
-               for (n = 0; n < sgp->minors - 1; ++n) {
-                       if (sgp->part[n] == NULL)
-                               continue;
-                       if (sgp->part[n]->nr_sects == 0)
+               for (n = 0; n < disk_max_parts(disk); ++n) {
+                       struct hd_struct *part = disk->part[n];
+
+                       if (!part || !part->nr_sects)
                                continue;
                        printk("  %02x%02x %10llu %s\n",
-                               sgp->major, n + 1 + sgp->first_minor,
-                               (unsigned long long)sgp->part[n]->nr_sects >> 1,
-                               disk_name(sgp, n + 1, buf));
-               } /* partition subloop */
-       } /* Block device loop */
-
-       mutex_unlock(&block_subsys_lock);
-       return;
+                              MAJOR(part_devt(part)), MINOR(part_devt(part)),
+                              (unsigned long long)part->nr_sects >> 1,
+                              disk_name(disk, part->partno, buf));
+               }
+       }
+       class_dev_iter_exit(&iter);
 }
 
 #ifdef CONFIG_PROC_FS
 /* iterator */
-static void *part_start(struct seq_file *part, loff_t *pos)
+static void *disk_seqf_start(struct seq_file *seqf, loff_t *pos)
+{
+       loff_t skip = *pos;
+       struct class_dev_iter *iter;
+       struct device *dev;
+
+       iter = kmalloc(GFP_KERNEL, sizeof(*iter));
+       if (!iter)
+               return ERR_PTR(-ENOMEM);
+
+       seqf->private = iter;
+       class_dev_iter_init(iter, &block_class, NULL, &disk_type);
+       do {
+               dev = class_dev_iter_next(iter);
+               if (!dev)
+                       return NULL;
+       } while (skip--);
+
+       return dev_to_disk(dev);
+}
+
+static void *disk_seqf_next(struct seq_file *seqf, void *v, loff_t *pos)
 {
-       struct list_head *p;
-       loff_t l = *pos;
+       struct device *dev;
+
+       (*pos)++;
+       dev = class_dev_iter_next(seqf->private);
+       if (dev)
+               return dev_to_disk(dev);
 
-       mutex_lock(&block_subsys_lock);
-       list_for_each(p, &block_subsys.list)
-               if (!l--)
-                       return list_entry(p, struct gendisk, kobj.entry);
        return NULL;
 }
 
-static void *part_next(struct seq_file *part, void *v, loff_t *pos)
+static void disk_seqf_stop(struct seq_file *seqf, void *v)
 {
-       struct list_head *p = ((struct gendisk *)v)->kobj.entry.next;
-       ++*pos;
-       return p==&block_subsys.list ? NULL :
-               list_entry(p, struct gendisk, kobj.entry);
+       struct class_dev_iter *iter = seqf->private;
+
+       /* stop is called even after start failed :-( */
+       if (iter) {
+               class_dev_iter_exit(iter);
+               kfree(iter);
+       }
 }
 
-static void part_stop(struct seq_file *part, void *v)
+static void *show_partition_start(struct seq_file *seqf, loff_t *pos)
 {
-       mutex_unlock(&block_subsys_lock);
+       static void *p;
+
+       p = disk_seqf_start(seqf, pos);
+       if (!IS_ERR(p) && p)
+               seq_puts(seqf, "major minor  #blocks  name\n\n");
+       return p;
 }
 
-static int show_partition(struct seq_file *part, void *v)
+static int show_partition(struct seq_file *seqf, void *v)
 {
        struct gendisk *sgp = v;
        int n;
        char buf[BDEVNAME_SIZE];
 
-       if (&sgp->kobj.entry == block_subsys.list.next)
-               seq_puts(part, "major minor  #blocks  name\n\n");
-
        /* Don't show non-partitionable removeable devices or empty devices */
-       if (!get_capacity(sgp) ||
-                       (sgp->minors == 1 && (sgp->flags & GENHD_FL_REMOVABLE)))
+       if (!get_capacity(sgp) || (!disk_max_parts(sgp) &&
+                                  (sgp->flags & GENHD_FL_REMOVABLE)))
                return 0;
        if (sgp->flags & GENHD_FL_SUPPRESS_PARTITION_INFO)
                return 0;
 
        /* show the full disk and all non-0 size partitions of it */
-       seq_printf(part, "%4d  %4d %10llu %s\n",
-               sgp->major, sgp->first_minor,
+       seq_printf(seqf, "%4d  %4d %10llu %s\n",
+               MAJOR(disk_devt(sgp)), MINOR(disk_devt(sgp)),
                (unsigned long long)get_capacity(sgp) >> 1,
                disk_name(sgp, 0, buf));
-       for (n = 0; n < sgp->minors - 1; n++) {
-               if (!sgp->part[n])
+       for (n = 0; n < disk_max_parts(sgp); n++) {
+               struct hd_struct *part = sgp->part[n];
+               if (!part)
                        continue;
-               if (sgp->part[n]->nr_sects == 0)
+               if (part->nr_sects == 0)
                        continue;
-               seq_printf(part, "%4d  %4d %10llu %s\n",
-                       sgp->major, n + 1 + sgp->first_minor,
-                       (unsigned long long)sgp->part[n]->nr_sects >> 1 ,
-                       disk_name(sgp, n + 1, buf));
+               seq_printf(seqf, "%4d  %4d %10llu %s\n",
+                          MAJOR(part_devt(part)), MINOR(part_devt(part)),
+                          (unsigned long long)part->nr_sects >> 1,
+                          disk_name(sgp, part->partno, buf));
        }
 
        return 0;
 }
 
-struct seq_operations partitions_op = {
-       .start =part_start,
-       .next = part_next,
-       .stop = part_stop,
-       .show = show_partition
+const struct seq_operations partitions_op = {
+       .start  = show_partition_start,
+       .next   = disk_seqf_next,
+       .stop   = disk_seqf_stop,
+       .show   = show_partition
 };
 #endif
 
 
-extern int blk_dev_init(void);
-
-static struct kobject *base_probe(dev_t dev, int *part, void *data)
+static struct kobject *base_probe(dev_t devt, int *partno, void *data)
 {
-       if (request_module("block-major-%d-%d", MAJOR(dev), MINOR(dev)) > 0)
+       if (request_module("block-major-%d-%d", MAJOR(devt), MINOR(devt)) > 0)
                /* Make old-style 2.4 aliases work */
-               request_module("block-major-%d", MAJOR(dev));
+               request_module("block-major-%d", MAJOR(devt));
        return NULL;
 }
 
 static int __init genhd_device_init(void)
 {
-       int err;
+       int error;
 
-       bdev_map = kobj_map_init(base_probe, &block_subsys_lock);
+       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);
        blk_dev_init();
-       err = subsystem_register(&block_subsys);
-       if (err < 0)
-               printk(KERN_WARNING "%s: subsystem_register error: %d\n",
-                       __FUNCTION__, err);
-       return err;
+
+#ifndef CONFIG_SYSFS_DEPRECATED
+       /* create top-level block dir */
+       block_depr = kobject_create_and_add("block", NULL);
+#endif
+       return 0;
 }
 
 subsys_initcall(genhd_device_init);
 
-
-
-/*
- * kobject & sysfs bindings for block devices
- */
-static ssize_t disk_attr_show(struct kobject *kobj, struct attribute *attr,
-                             char *page)
+static ssize_t disk_range_show(struct device *dev,
+                              struct device_attribute *attr, char *buf)
 {
-       struct gendisk *disk = to_disk(kobj);
-       struct disk_attribute *disk_attr =
-               container_of(attr,struct disk_attribute,attr);
-       ssize_t ret = -EIO;
+       struct gendisk *disk = dev_to_disk(dev);
 
-       if (disk_attr->show)
-               ret = disk_attr->show(disk,page);
-       return ret;
+       return sprintf(buf, "%d\n", disk->minors);
 }
 
-static ssize_t disk_attr_store(struct kobject * kobj, struct attribute * attr,
-                              const char *page, size_t count)
+static ssize_t disk_removable_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
 {
-       struct gendisk *disk = to_disk(kobj);
-       struct disk_attribute *disk_attr =
-               container_of(attr,struct disk_attribute,attr);
-       ssize_t ret = 0;
+       struct gendisk *disk = dev_to_disk(dev);
 
-       if (disk_attr->store)
-               ret = disk_attr->store(disk, page, count);
-       return ret;
+       return sprintf(buf, "%d\n",
+                      (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0));
 }
 
-static struct sysfs_ops disk_sysfs_ops = {
-       .show   = &disk_attr_show,
-       .store  = &disk_attr_store,
-};
-
-static ssize_t disk_uevent_store(struct gendisk * disk,
-                                const char *buf, size_t count)
+static ssize_t disk_ro_show(struct device *dev,
+                                  struct device_attribute *attr, char *buf)
 {
-       kobject_uevent(&disk->kobj, KOBJ_ADD);
-       return count;
-}
-static ssize_t disk_dev_read(struct gendisk * disk, char *page)
-{
-       dev_t base = MKDEV(disk->major, disk->first_minor); 
-       return print_dev_t(page, base);
-}
-static ssize_t disk_range_read(struct gendisk * disk, char *page)
-{
-       return sprintf(page, "%d\n", disk->minors);
-}
-static ssize_t disk_removable_read(struct gendisk * disk, char *page)
-{
-       return sprintf(page, "%d\n",
-                      (disk->flags & GENHD_FL_REMOVABLE ? 1 : 0));
+       struct gendisk *disk = dev_to_disk(dev);
 
+       return sprintf(buf, "%d\n", disk->policy ? 1 : 0);
 }
-static ssize_t disk_size_read(struct gendisk * disk, char *page)
+
+static ssize_t disk_size_show(struct device *dev,
+                             struct device_attribute *attr, char *buf)
 {
-       return sprintf(page, "%llu\n", (unsigned long long)get_capacity(disk));
+       struct gendisk *disk = dev_to_disk(dev);
+
+       return sprintf(buf, "%llu\n", (unsigned long long)get_capacity(disk));
 }
-static ssize_t disk_capability_read(struct gendisk *disk, char *page)
+
+static ssize_t disk_capability_show(struct device *dev,
+                                   struct device_attribute *attr, char *buf)
 {
-       return sprintf(page, "%x\n", disk->flags);
+       struct gendisk *disk = dev_to_disk(dev);
+
+       return sprintf(buf, "%x\n", disk->flags);
 }
-static ssize_t disk_stats_read(struct gendisk * disk, char *page)
+
+static ssize_t disk_stat_show(struct device *dev,
+                             struct device_attribute *attr, char *buf)
 {
+       struct gendisk *disk = dev_to_disk(dev);
+
        preempt_disable();
        disk_round_stats(disk);
        preempt_enable();
-       return sprintf(page,
+       return sprintf(buf,
                "%8lu %8lu %8llu %8u "
                "%8lu %8lu %8llu %8u "
                "%8u %8u %8u"
@@ -445,40 +504,21 @@ static ssize_t disk_stats_read(struct gendisk * disk, char *page)
                jiffies_to_msecs(disk_stat_read(disk, io_ticks)),
                jiffies_to_msecs(disk_stat_read(disk, time_in_queue)));
 }
-static struct disk_attribute disk_attr_uevent = {
-       .attr = {.name = "uevent", .mode = S_IWUSR },
-       .store  = disk_uevent_store
-};
-static struct disk_attribute disk_attr_dev = {
-       .attr = {.name = "dev", .mode = S_IRUGO },
-       .show   = disk_dev_read
-};
-static struct disk_attribute disk_attr_range = {
-       .attr = {.name = "range", .mode = S_IRUGO },
-       .show   = disk_range_read
-};
-static struct disk_attribute disk_attr_removable = {
-       .attr = {.name = "removable", .mode = S_IRUGO },
-       .show   = disk_removable_read
-};
-static struct disk_attribute disk_attr_size = {
-       .attr = {.name = "size", .mode = S_IRUGO },
-       .show   = disk_size_read
-};
-static struct disk_attribute disk_attr_capability = {
-       .attr = {.name = "capability", .mode = S_IRUGO },
-       .show   = disk_capability_read
-};
-static struct disk_attribute disk_attr_stat = {
-       .attr = {.name = "stat", .mode = S_IRUGO },
-       .show   = disk_stats_read
-};
 
 #ifdef CONFIG_FAIL_MAKE_REQUEST
+static ssize_t disk_fail_show(struct device *dev,
+                             struct device_attribute *attr, char *buf)
+{
+       struct gendisk *disk = dev_to_disk(dev);
 
-static ssize_t disk_fail_store(struct gendisk * disk,
+       return sprintf(buf, "%d\n", disk->flags & GENHD_FL_FAIL ? 1 : 0);
+}
+
+static ssize_t disk_fail_store(struct device *dev,
+                              struct device_attribute *attr,
                               const char *buf, size_t count)
 {
+       struct gendisk *disk = dev_to_disk(dev);
        int i;
 
        if (count > 0 && sscanf(buf, "%d", &i) > 0) {
@@ -490,147 +530,78 @@ static ssize_t disk_fail_store(struct gendisk * disk,
 
        return count;
 }
-static ssize_t disk_fail_read(struct gendisk * disk, char *page)
-{
-       return sprintf(page, "%d\n", disk->flags & GENHD_FL_FAIL ? 1 : 0);
-}
-static struct disk_attribute disk_attr_fail = {
-       .attr = {.name = "make-it-fail", .mode = S_IRUGO | S_IWUSR },
-       .store  = disk_fail_store,
-       .show   = disk_fail_read
-};
 
 #endif
 
-static struct attribute * default_attrs[] = {
-       &disk_attr_uevent.attr,
-       &disk_attr_dev.attr,
-       &disk_attr_range.attr,
-       &disk_attr_removable.attr,
-       &disk_attr_size.attr,
-       &disk_attr_stat.attr,
-       &disk_attr_capability.attr,
+static DEVICE_ATTR(range, S_IRUGO, disk_range_show, NULL);
+static DEVICE_ATTR(removable, S_IRUGO, disk_removable_show, NULL);
+static DEVICE_ATTR(ro, S_IRUGO, disk_ro_show, NULL);
+static DEVICE_ATTR(size, S_IRUGO, disk_size_show, NULL);
+static DEVICE_ATTR(capability, S_IRUGO, disk_capability_show, NULL);
+static DEVICE_ATTR(stat, S_IRUGO, disk_stat_show, NULL);
 #ifdef CONFIG_FAIL_MAKE_REQUEST
-       &disk_attr_fail.attr,
+static struct device_attribute dev_attr_fail =
+       __ATTR(make-it-fail, S_IRUGO|S_IWUSR, disk_fail_show, disk_fail_store);
 #endif
-       NULL,
+
+static struct attribute *disk_attrs[] = {
+       &dev_attr_range.attr,
+       &dev_attr_removable.attr,
+       &dev_attr_ro.attr,
+       &dev_attr_size.attr,
+       &dev_attr_capability.attr,
+       &dev_attr_stat.attr,
+#ifdef CONFIG_FAIL_MAKE_REQUEST
+       &dev_attr_fail.attr,
+#endif
+       NULL
 };
 
-static void disk_release(struct kobject * kobj)
+static struct attribute_group disk_attr_group = {
+       .attrs = disk_attrs,
+};
+
+static struct attribute_group *disk_attr_groups[] = {
+       &disk_attr_group,
+       NULL
+};
+
+static void disk_release(struct device *dev)
 {
-       struct gendisk *disk = to_disk(kobj);
+       struct gendisk *disk = dev_to_disk(dev);
+
        kfree(disk->random);
        kfree(disk->part);
        free_disk_stats(disk);
        kfree(disk);
 }
-
-static struct kobj_type ktype_block = {
-       .release        = disk_release,
-       .sysfs_ops      = &disk_sysfs_ops,
-       .default_attrs  = default_attrs,
+struct class block_class = {
+       .name           = "block",
 };
 
-extern struct kobj_type ktype_part;
-
-static int block_uevent_filter(struct kset *kset, struct kobject *kobj)
-{
-       struct kobj_type *ktype = get_ktype(kobj);
-
-       return ((ktype == &ktype_block) || (ktype == &ktype_part));
-}
-
-static int block_uevent(struct kset *kset, struct kobject *kobj,
-                       struct kobj_uevent_env *env)
-{
-       struct kobj_type *ktype = get_ktype(kobj);
-       struct device *physdev;
-       struct gendisk *disk;
-       struct hd_struct *part;
-
-       if (ktype == &ktype_block) {
-               disk = container_of(kobj, struct gendisk, kobj);
-               add_uevent_var(env, "MINOR=%u", disk->first_minor);
-       } else if (ktype == &ktype_part) {
-               disk = container_of(kobj->parent, struct gendisk, kobj);
-               part = container_of(kobj, struct hd_struct, kobj);
-               add_uevent_var(env, "MINOR=%u",
-                              disk->first_minor + part->partno);
-       } else
-               return 0;
-
-       add_uevent_var(env, "MAJOR=%u", disk->major);
-
-       /* add physical device, backing this device  */
-       physdev = disk->driverfs_dev;
-       if (physdev) {
-               char *path = kobject_get_path(&physdev->kobj, GFP_KERNEL);
-
-               add_uevent_var(env, "PHYSDEVPATH=%s", path);
-               kfree(path);
-
-               if (physdev->bus)
-                       add_uevent_var(env, "PHYSDEVBUS=%s", physdev->bus->name);
-
-               if (physdev->driver)
-                       add_uevent_var(env, physdev->driver->name);
-       }
-
-       return 0;
-}
-
-static struct kset_uevent_ops block_uevent_ops = {
-       .filter         = block_uevent_filter,
-       .uevent         = block_uevent,
+static struct device_type disk_type = {
+       .name           = "disk",
+       .groups         = disk_attr_groups,
+       .release        = disk_release,
 };
 
-decl_subsys(block, &ktype_block, &block_uevent_ops);
-
+#ifdef CONFIG_PROC_FS
 /*
  * aggregate disk stat collector.  Uses the same stats that the sysfs
  * entries do, above, but makes them available through one seq_file.
- * Watching a few disks may be efficient through sysfs, but watching
- * all of them will be more efficient through this interface.
  *
  * The output looks suspiciously like /proc/partitions with a bunch of
  * extra fields.
  */
-
-/* iterator */
-static void *diskstats_start(struct seq_file *part, loff_t *pos)
-{
-       loff_t k = *pos;
-       struct list_head *p;
-
-       mutex_lock(&block_subsys_lock);
-       list_for_each(p, &block_subsys.list)
-               if (!k--)
-                       return list_entry(p, struct gendisk, kobj.entry);
-       return NULL;
-}
-
-static void *diskstats_next(struct seq_file *part, void *v, loff_t *pos)
-{
-       struct list_head *p = ((struct gendisk *)v)->kobj.entry.next;
-       ++*pos;
-       return p==&block_subsys.list ? NULL :
-               list_entry(p, struct gendisk, kobj.entry);
-}
-
-static void diskstats_stop(struct seq_file *part, void *v)
-{
-       mutex_unlock(&block_subsys_lock);
-}
-
-static int diskstats_show(struct seq_file *s, void *v)
+static int diskstats_show(struct seq_file *seqf, void *v)
 {
        struct gendisk *gp = v;
        char buf[BDEVNAME_SIZE];
-       int n = 0;
+       int n;
 
        /*
-       if (&sgp->kobj.entry == block_subsys.kset.list.next)
-               seq_puts(s,     "major minor name"
+       if (&gp->dev.kobj.entry == block_class.devices.next)
+               seq_puts(seqf,  "major minor name"
                                "     rio rmerge rsect ruse wio wmerge "
                                "wsect wuse running use aveq"
                                "\n\n");
@@ -639,8 +610,9 @@ static int diskstats_show(struct seq_file *s, void *v)
        preempt_disable();
        disk_round_stats(gp);
        preempt_enable();
-       seq_printf(s, "%4d %4d %s %lu %lu %llu %u %lu %lu %llu %u %u %u %u\n",
-               gp->major, n + gp->first_minor, disk_name(gp, n, buf),
+       seq_printf(seqf, "%4d %4d %s %lu %lu %llu %u %lu %lu %llu %u %u %u %u\n",
+               MAJOR(disk_devt(gp)), MINOR(disk_devt(gp)),
+               disk_name(gp, 0, buf),
                disk_stat_read(gp, ios[0]), disk_stat_read(gp, merges[0]),
                (unsigned long long)disk_stat_read(gp, sectors[0]),
                jiffies_to_msecs(disk_stat_read(gp, ticks[0])),
@@ -652,26 +624,43 @@ static int diskstats_show(struct seq_file *s, void *v)
                jiffies_to_msecs(disk_stat_read(gp, time_in_queue)));
 
        /* now show all non-0 size partitions of it */
-       for (n = 0; n < gp->minors - 1; n++) {
+       for (n = 0; n < disk_max_parts(gp); n++) {
                struct hd_struct *hd = gp->part[n];
 
-               if (hd && hd->nr_sects)
-                       seq_printf(s, "%4d %4d %s %u %u %u %u\n",
-                               gp->major, n + gp->first_minor + 1,
-                               disk_name(gp, n + 1, buf),
-                               hd->ios[0], hd->sectors[0],
-                               hd->ios[1], hd->sectors[1]);
+               if (!hd || !hd->nr_sects)
+                       continue;
+
+               preempt_disable();
+               part_round_stats(hd);
+               preempt_enable();
+               seq_printf(seqf, "%4d %4d %s %lu %lu %llu "
+                          "%u %lu %lu %llu %u %u %u %u\n",
+                          MAJOR(part_devt(hd)), MINOR(part_devt(hd)),
+                          disk_name(gp, hd->partno, buf),
+                          part_stat_read(hd, ios[0]),
+                          part_stat_read(hd, merges[0]),
+                          (unsigned long long)part_stat_read(hd, sectors[0]),
+                          jiffies_to_msecs(part_stat_read(hd, ticks[0])),
+                          part_stat_read(hd, ios[1]),
+                          part_stat_read(hd, merges[1]),
+                          (unsigned long long)part_stat_read(hd, sectors[1]),
+                          jiffies_to_msecs(part_stat_read(hd, ticks[1])),
+                          hd->in_flight,
+                          jiffies_to_msecs(part_stat_read(hd, io_ticks)),
+                          jiffies_to_msecs(part_stat_read(hd, time_in_queue))
+                       );
        }
  
        return 0;
 }
 
-struct seq_operations diskstats_op = {
-       .start  = diskstats_start,
-       .next   = diskstats_next,
-       .stop   = diskstats_stop,
+const struct seq_operations diskstats_op = {
+       .start  = disk_seqf_start,
+       .next   = disk_seqf_next,
+       .stop   = disk_seqf_stop,
        .show   = diskstats_show
 };
+#endif /* CONFIG_PROC_FS */
 
 static void media_change_notify_thread(struct work_struct *work)
 {
@@ -683,16 +672,50 @@ static void media_change_notify_thread(struct work_struct *work)
         * set enviroment vars to indicate which event this is for
         * so that user space will know to go check the media status.
         */
-       kobject_uevent_env(&gd->kobj, KOBJ_CHANGE, envp);
+       kobject_uevent_env(&gd->dev.kobj, KOBJ_CHANGE, envp);
        put_device(gd->driverfs_dev);
 }
 
+#if 0
 void genhd_media_change_notify(struct gendisk *disk)
 {
        get_device(disk->driverfs_dev);
        schedule_work(&disk->async_notify);
 }
 EXPORT_SYMBOL_GPL(genhd_media_change_notify);
+#endif  /*  0  */
+
+dev_t blk_lookup_devt(const char *name, int partno)
+{
+       dev_t devt = MKDEV(0, 0);
+       struct class_dev_iter iter;
+       struct device *dev;
+
+       class_dev_iter_init(&iter, &block_class, NULL, &disk_type);
+       while ((dev = class_dev_iter_next(&iter))) {
+               struct gendisk *disk = dev_to_disk(dev);
+
+               if (strcmp(dev->bus_id, name))
+                       continue;
+               if (partno < 0 || partno > disk_max_parts(disk))
+                       continue;
+
+               if (partno == 0)
+                       devt = disk_devt(disk);
+               else {
+                       struct hd_struct *part = disk->part[partno - 1];
+
+                       if (!part || !part->nr_sects)
+                               continue;
+
+                       devt = part_devt(part);
+               }
+               break;
+       }
+       class_dev_iter_exit(&iter);
+       return devt;
+}
+EXPORT_SYMBOL(blk_lookup_devt);
 
 struct gendisk *alloc_disk(int minors)
 {
@@ -721,9 +744,10 @@ struct gendisk *alloc_disk_node(int minors, int node_id)
                        }
                }
                disk->minors = minors;
-               kobj_set_kset_s(disk,block_subsys);
-               kobject_init(&disk->kobj);
                rand_initialize_disk(disk);
+               disk->dev.class = &block_class;
+               disk->dev.type = &disk_type;
+               device_initialize(&disk->dev);
                INIT_WORK(&disk->async_notify,
                        media_change_notify_thread);
        }
@@ -743,7 +767,7 @@ struct kobject *get_disk(struct gendisk *disk)
        owner = disk->fops->owner;
        if (owner && !try_module_get(owner))
                return NULL;
-       kobj = kobject_get(&disk->kobj);
+       kobj = kobject_get(&disk->dev.kobj);
        if (kobj == NULL) {
                module_put(owner);
                return NULL;
@@ -757,7 +781,7 @@ EXPORT_SYMBOL(get_disk);
 void put_disk(struct gendisk *disk)
 {
        if (disk)
-               kobject_put(&disk->kobj);
+               kobject_put(&disk->dev.kobj);
 }
 
 EXPORT_SYMBOL(put_disk);
@@ -776,7 +800,7 @@ void set_disk_ro(struct gendisk *disk, int flag)
 {
        int i;
        disk->policy = flag;
-       for (i = 0; i < disk->minors - 1; i++)
+       for (i = 0; i < disk_max_parts(disk); i++)
                if (disk->part[i]) disk->part[i]->policy = flag;
 }
 
@@ -794,10 +818,10 @@ int bdev_read_only(struct block_device *bdev)
 
 EXPORT_SYMBOL(bdev_read_only);
 
-int invalidate_partition(struct gendisk *disk, int index)
+int invalidate_partition(struct gendisk *disk, int partno)
 {
        int res = 0;
-       struct block_device *bdev = bdget_disk(disk, index);
+       struct block_device *bdev = bdget_disk(disk, partno);
        if (bdev) {
                fsync_bdev(bdev);
                res = __invalidate_device(bdev);