Skip to contentSkip to conversation

convert /proc/devices to use seq_file interface

PATCH New Neil Horman 1 participant 1 message Aug 26, 2005

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 convert /proc/devices to use seq_file interface

A few weeks ago Christoph suggested that the /proc/devices file be converted to use the seq_file interface. This patch does that. Tested by me, with good results.

Thanks and Regards
Neil

 drivers/block/genhd.c |  107 ++++++++++++++++++++++++++------
 fs/char_dev.c         |   97 ++++++++++++++++++++++-------
 fs/proc/proc_misc.c   |  167 +++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 323 insertions(+), 48 deletions(-)
drivers/block/genhd.c renamed from drivers/block/genhd.c.orig +89 -18
@@ -38,34 +38,105 @@ static inline int major_to_index(int maj
 	return major % MAX_PROBE_HASH;
 }
 
-#ifdef CONFIG_PROC_FS
-/* get block device names in somewhat random order */
-int get_blkdev_list(char *p, int used)
+struct blkdev_info {
+        int index;
+        struct blk_major_name *bd;
+};
+
+/*
+ * iterate over a list of blkdev_info structures.  allows
+ * the major_names array to be iterated over from outside this file
+ * must be called with the block_subsys_sem held
+ */
+void *get_next_blkdev(void *dev)
+{
+        struct blkdev_info *info;
+
+        if (dev == NULL) {
+                info = kmalloc(sizeof(struct blkdev_info),GFP_KERNEL);
+                if (!info)
+                        goto out;
+                info->index=0;
+                info->bd = major_names[info->index];
+                if(info->bd)
+                        goto out;
+        } else {
+                info = (struct blkdev_info *)dev;
+        }
+
+        while (info->index < ARRAY_SIZE(major_names)) {
+                if (info->bd)
+                        info->bd = info->bd->next;
+                if (info->bd)
+                        goto out;
+                /*
+                 *no devices on this chain, move to the next
+                 */
+                info->index++;
+                info->bd = (info->index < ARRAY_SIZE(major_names)) ? major_names[info->index] : NULL;
+                if (info->bd)
+                        goto out;
+        }
+
+out:
+        return info;
+}
+
+void *acquire_blkdev_list(void)
+{
+        struct chrdev_info *info;
+
+        down(&block_subsys_sem);
+
+        info = get_next_blkdev(NULL);
+
+        return info;
+}
+
+void release_blkdev_list(void *dev)
+{
+        up(&block_subsys_sem);
+        kfree(dev);
+}
+
+
+/*
+ * Count the number of records in the blkdev_list.
+ * must be called with the block_subsys_sem held
+ */
+int count_blkdev_list()
 {
 	struct blk_major_name *n;
-	int i, len;
+	int i, count;
 
-	len = snprintf(p, (PAGE_SIZE-used), "\nBlock devices:\n");
+	count = 0;
 
-	down(&block_subsys_sem);
 	for (i = 0; i < ARRAY_SIZE(major_names); i++) {
 		for (n = major_names[i]; n; n = n->next) {
-			/*
-			 * If the curent string plus the 5 extra characters
-			 * in the line would run us off the page, then we're done
-			 */
-			if ((len + used + strlen(n->name) + 5) >= PAGE_SIZE)
-				goto page_full;
-			len += sprintf(p+len, "%3d %s\n",
-				       n->major, n->name);
+				count++;
 		}
 	}
-page_full:
-	up(&block_subsys_sem);
+	
+	return count;
+}
+
+/*
+ * extract the major and name values from a blkdev_info struct
+ * passed in as a void to *dev.  Must be called with 
+ * block_subsys_sem held
+ */
+int get_blkdev_info(void *dev, int *major, char **name)
+{
+        struct blkdev_info *info = (struct blkdev_info *)dev;
+
+        if (info->bd == NULL)
+                return 1;
 
-	return len;
+        *major = info->bd->major;
+        *name = info->bd->name;
+        return 0;
 }
-#endif
+
 
 int register_blkdev(unsigned int major, const char *name)
 {
fs/proc/proc_misc.c renamed from fs/proc/proc_misc.c.orig +158 -9

197 lines not on this page · raw message

fs/char_dev.c renamed from fs/char_dev.c.orig +76 -21

124 lines not on this page · raw message

Signature · 8 lines
/***************************************************
 *Neil Horman
 *Software Engineer
 *Red Hat, Inc.
 *[email protected]
 *gpg keyid: 1024D / 0x92A74FA1
 *http://pgp.mit.edu
 ***************************************************/