]> www.pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - block/genhd.c
block: fix partial read() of /proc/{partitions,diskstats}
[linux-2.6-omap-h63xx.git] / block / genhd.c
index f03bdadc52ac0488ea227db1eb4651ca94de2e58..f34befc5484737a446f66da8afd81cf1b993b499 100644 (file)
@@ -293,37 +293,46 @@ void __init printk_all_partitions(void)
 /* iterator */
 static int find_start(struct device *dev, void *data)
 {
-       loff_t k = *(loff_t *)data;
+       loff_t *k = data;
 
        if (dev->type != &disk_type)
                return 0;
-       if (!k--)
+       if (!*k)
                return 1;
+       (*k)--;
        return 0;
 }
 
 static void *part_start(struct seq_file *part, loff_t *pos)
 {
        struct device *dev;
+       loff_t k = *pos;
+
+       if (!k)
+               seq_puts(part, "major minor  #blocks  name\n\n");
 
        mutex_lock(&block_class_lock);
-       dev = class_find_device(&block_class, NULL, (void *)pos, find_start);
+       dev = class_find_device(&block_class, NULL, &k, find_start);
        if (dev)
                return dev_to_disk(dev);
        return NULL;
 }
 
+static int find_next(struct device *dev, void *data)
+{
+       if (dev->type == &disk_type)
+               return 1;
+       return 0;
+}
+
 static void *part_next(struct seq_file *part, void *v, loff_t *pos)
 {
        struct gendisk *gp = v;
        struct device *dev;
        ++*pos;
-       list_for_each_entry(dev, &gp->dev.node, node) {
-               if (&dev->node == &block_class.devices)
-                       return NULL;
-               if (dev->type == &disk_type)
-                       return dev_to_disk(dev);
-       }
+       dev = class_find_device(&block_class, &gp->dev, NULL, find_next);
+       if (dev)
+               return dev_to_disk(dev);
        return NULL;
 }
 
@@ -338,9 +347,6 @@ static int show_partition(struct seq_file *part, void *v)
        int n;
        char buf[BDEVNAME_SIZE];
 
-       if (&sgp->dev.node == block_class.devices.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)))
@@ -563,9 +569,10 @@ static struct device_type disk_type = {
 static void *diskstats_start(struct seq_file *part, loff_t *pos)
 {
        struct device *dev;
+       loff_t k = *pos;
 
        mutex_lock(&block_class_lock);
-       dev = class_find_device(&block_class, NULL, (void *)pos, find_start);
+       dev = class_find_device(&block_class, NULL, &k, find_start);
        if (dev)
                return dev_to_disk(dev);
        return NULL;
@@ -577,12 +584,9 @@ static void *diskstats_next(struct seq_file *part, void *v, loff_t *pos)
        struct device *dev;
 
        ++*pos;
-       list_for_each_entry(dev, &gp->dev.node, node) {
-               if (&dev->node == &block_class.devices)
-                       return NULL;
-               if (dev->type == &disk_type)
-                       return dev_to_disk(dev);
-       }
+       dev = class_find_device(&block_class, &gp->dev, NULL, find_next);
+       if (dev)
+               return dev_to_disk(dev);
        return NULL;
 }