Skip to content

Commit

Permalink
block: fix partial read() of /proc/{partitions,diskstats}
Browse files Browse the repository at this point in the history
The proc files get truncated if they do not fit into the buffer with
a single read(). We need to move the seq_file index from the callback
of class_find_device() to the caller of class_find_device(), to keep
its value across multiple invocations of the callback.

Signed-off-by: Kay Sievers <[email protected]>
Signed-off-by: Greg Kroah-Hartman <[email protected]>
  • Loading branch information
kaysievers authored and gregkh committed Aug 21, 2008
1 parent f5a6d95 commit 068281d
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -293,25 +293,26 @@ 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 n = *pos;
loff_t k = *pos;

if (!n)
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;
Expand Down Expand Up @@ -568,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;
Expand Down

0 comments on commit 068281d

Please sign in to comment.