linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: <rddunlap@osdl.org>
To: Alexander Viro <viro@math.psu.edu>
Cc: <linux-kernel@vger.kernel.org>, <davej@suse.de>
Subject: [patch 2.5] seq_file for /proc/partitions (take 2)
Date: Sat, 23 Mar 2002 21:47:35 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.33.0203232143380.5047-100000@osdlab.pdx.osdl.net> (raw)
In-Reply-To: <Pine.LNX.4.33.0203232049240.23956-100000@osdlab.pdx.osdl.net>

On Sat, 23 Mar 2002 rddunlap@osdl.org wrote:

| On Sat, 23 Mar 2002, Alexander Viro wrote:
|
| | Erm...  Actually that _is_ wrong - what you want is
| |
| | 	return ((struct gendisk)v)->next;
|
| Will repost patch after testing.

OK, here's the tested fixup.

Dave, please add to 2.5.7-dj.

Alan, I have 2.4.18 patch for this, but 2.4.19-pre3-ac6
includes more (sard ?) partition stats.
Are those going to 2.5 also?
Do you want me to merge partition stats and seq_file?

-- 
~Randy


--- ./drivers/block/genhd.c.PART	Mon Mar 18 12:37:14 2002
+++ ./drivers/block/genhd.c	Sat Mar 23 20:44:25 2002
@@ -22,6 +22,7 @@
 #include <linux/blk.h>
 #include <linux/init.h>
 #include <linux/spinlock.h>
+#include <linux/seq_file.h>


 static rwlock_t gendisk_lock;
@@ -142,39 +143,58 @@
 }

 #ifdef CONFIG_PROC_FS
-int
-get_partition_list(char *page, char **start, off_t offset, int count)
+/* iterator */
+static void *part_start(struct seq_file *part, loff_t *pos)
 {
-	struct gendisk *gp;
-	char buf[64];
-	int len, n;
+	loff_t k = *pos;
+	struct gendisk *sgp;

-	len = sprintf(page, "major minor  #blocks  name\n\n");
 	read_lock(&gendisk_lock);
-	for (gp = gendisk_head; gp; gp = gp->next) {
-		for (n = 0; n < (gp->nr_real << gp->minor_shift); n++) {
-			if (gp->part[n].nr_sects == 0)
-				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;
-		}
+	for (sgp = gendisk_head; sgp; sgp = sgp->next) {
+		if (!k--)
+			return sgp;
 	}
+	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);
-	*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


--- ./fs/proc/proc_misc.c.PART	Mon Mar 18 12:37:06 2002
+++ ./fs/proc/proc_misc.c	Sat Mar 23 16:34:07 2002
@@ -51,7 +51,6 @@
  * wrappers, but this needs further analysis wrt potential overflows.
  */
 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_exec_domain_list(char *);
 extern int get_dma_list(char *);
@@ -199,6 +198,18 @@
 	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
 extern struct seq_operations modules_op;
 static int modules_open(struct inode *inode, struct file *file)
@@ -323,14 +334,6 @@
 	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)
 {
 	return NULL + (*pos == 0);
@@ -538,7 +541,6 @@
 		{"version",	version_read_proc},
 		{"stat",	kstat_read_proc},
 		{"devices",	devices_read_proc},
-		{"partitions",	partitions_read_proc},
 		{"filesystems",	filesystems_read_proc},
 		{"dma",		dma_read_proc},
 		{"ioports",	ioports_read_proc},
@@ -562,6 +564,7 @@
 	if (entry)
 		entry->proc_fops = &proc_kmsg_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("slabinfo",S_IWUSR|S_IRUGO,&proc_slabinfo_operations);
 #ifdef CONFIG_MODULES





  reply	other threads:[~2002-03-24  5:48 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-03-24  4:05 [patch 2.5] seq_file for /proc/partitions rddunlap
2002-03-24  4:11 ` Alexander Viro
2002-03-24  4:50   ` rddunlap
2002-03-24  5:47     ` rddunlap [this message]
2002-03-24 17:04       ` [patch 2.5] seq_file for /proc/partitions (take 2) Alan Cox
2002-03-24 17:28   ` [patch 2.5] seq_file for /proc/partitions Stevie O
2002-03-24 17:39     ` Alexander Viro

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.33.0203232143380.5047-100000@osdlab.pdx.osdl.net \
    --to=rddunlap@osdl.org \
    --cc=davej@suse.de \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@math.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).