Commit ab91f980 authored by Dave Jones's avatar Dave Jones

[PATCH] seq_file for /proc/partitions (take 2)

Original from Randy Dunlap <rddunlap@osdl.org>...
parent dab4075e
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <linux/blk.h> #include <linux/blk.h>
#include <linux/init.h> #include <linux/init.h>
#include <linux/spinlock.h> #include <linux/spinlock.h>
#include <linux/seq_file.h>
static rwlock_t gendisk_lock; static rwlock_t gendisk_lock;
...@@ -142,39 +143,58 @@ get_nr_sects(kdev_t dev) ...@@ -142,39 +143,58 @@ get_nr_sects(kdev_t dev)
} }
#ifdef CONFIG_PROC_FS #ifdef CONFIG_PROC_FS
int /* iterator */
get_partition_list(char *page, char **start, off_t offset, int count) static void *part_start(struct seq_file *part, loff_t *pos)
{ {
struct gendisk *gp; loff_t k = *pos;
char buf[64]; struct gendisk *sgp;
int len, n;
len = sprintf(page, "major minor #blocks name\n\n");
read_lock(&gendisk_lock); read_lock(&gendisk_lock);
for (gp = gendisk_head; gp; gp = gp->next) { for (sgp = gendisk_head; sgp; sgp = sgp->next) {
for (n = 0; n < (gp->nr_real << gp->minor_shift); n++) { if (!k--)
if (gp->part[n].nr_sects == 0) return sgp;
continue;
len += snprintf(page + len, 63,
"%4d %4d %10d %s\n",
gp->major, n, gp->sizes[n],
disk_name(gp, n, buf));
if (len < offset)
offset -= len, len = 0;
else if (len >= offset + count)
goto out;
}
} }
return NULL;
}
out: static void *part_next(struct seq_file *part, void *v, loff_t *pos)
{
++*pos;
return ((struct gendisk *)v)->next;
}
static void part_stop(struct seq_file *part, void *v)
{
read_unlock(&gendisk_lock); read_unlock(&gendisk_lock);
*start = page + offset;
len -= offset;
if (len < 0)
len = 0;
return len > count ? count : len;
} }
static int show_partition(struct seq_file *part, void *v)
{
struct gendisk *sgp = v;
int n;
char buf[64];
if (sgp == gendisk_head)
seq_puts(part, "major minor #blocks name\n\n");
/* show all non-0 size partitions of this disk */
for (n = 0; n < (sgp->nr_real << sgp->minor_shift); n++) {
if (sgp->part[n].nr_sects == 0)
continue;
seq_printf(part, "%4d %4d %10d %s\n",
sgp->major, n, sgp->sizes[n],
disk_name(sgp, n, buf));
}
return 0;
}
struct seq_operations partitions_op = {
start: part_start,
next: part_next,
stop: part_stop,
show: show_partition
};
#endif #endif
......
...@@ -51,7 +51,6 @@ ...@@ -51,7 +51,6 @@
* wrappers, but this needs further analysis wrt potential overflows. * wrappers, but this needs further analysis wrt potential overflows.
*/ */
extern int get_device_list(char *); extern int get_device_list(char *);
extern int get_partition_list(char *, char **, off_t, int);
extern int get_filesystem_list(char *); extern int get_filesystem_list(char *);
extern int get_exec_domain_list(char *); extern int get_exec_domain_list(char *);
extern int get_dma_list(char *); extern int get_dma_list(char *);
...@@ -199,6 +198,18 @@ static struct file_operations proc_cpuinfo_operations = { ...@@ -199,6 +198,18 @@ static struct file_operations proc_cpuinfo_operations = {
release: seq_release, release: seq_release,
}; };
extern struct seq_operations partitions_op;
static int partitions_open(struct inode *inode, struct file *file)
{
return seq_open(file, &partitions_op);
}
static struct file_operations proc_partitions_operations = {
open: partitions_open,
read: seq_read,
llseek: seq_lseek,
release: seq_release,
};
#ifdef CONFIG_MODULES #ifdef CONFIG_MODULES
extern struct seq_operations modules_op; extern struct seq_operations modules_op;
static int modules_open(struct inode *inode, struct file *file) static int modules_open(struct inode *inode, struct file *file)
...@@ -323,14 +334,6 @@ static int devices_read_proc(char *page, char **start, off_t off, ...@@ -323,14 +334,6 @@ static int devices_read_proc(char *page, char **start, off_t off,
return proc_calc_metrics(page, start, off, count, eof, len); return proc_calc_metrics(page, start, off, count, eof, len);
} }
static int partitions_read_proc(char *page, char **start, off_t off,
int count, int *eof, void *data)
{
int len = get_partition_list(page, start, off, count);
if (len < count) *eof = 1;
return len;
}
static void *single_start(struct seq_file *p, loff_t *pos) static void *single_start(struct seq_file *p, loff_t *pos)
{ {
return NULL + (*pos == 0); return NULL + (*pos == 0);
...@@ -538,7 +541,6 @@ void __init proc_misc_init(void) ...@@ -538,7 +541,6 @@ void __init proc_misc_init(void)
{"version", version_read_proc}, {"version", version_read_proc},
{"stat", kstat_read_proc}, {"stat", kstat_read_proc},
{"devices", devices_read_proc}, {"devices", devices_read_proc},
{"partitions", partitions_read_proc},
{"filesystems", filesystems_read_proc}, {"filesystems", filesystems_read_proc},
{"dma", dma_read_proc}, {"dma", dma_read_proc},
{"ioports", ioports_read_proc}, {"ioports", ioports_read_proc},
...@@ -562,6 +564,7 @@ void __init proc_misc_init(void) ...@@ -562,6 +564,7 @@ void __init proc_misc_init(void)
if (entry) if (entry)
entry->proc_fops = &proc_kmsg_operations; entry->proc_fops = &proc_kmsg_operations;
create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations); create_seq_entry("cpuinfo", 0, &proc_cpuinfo_operations);
create_seq_entry("partitions", 0, &proc_partitions_operations);
create_seq_entry("interrupts", 0, &proc_interrupts_operations); create_seq_entry("interrupts", 0, &proc_interrupts_operations);
create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations); create_seq_entry("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations);
#ifdef CONFIG_MODULES #ifdef CONFIG_MODULES
......
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