]> git.hungrycats.org Git - linux/commitdiff
[PATCH] make devfs_alloc_unique_number private to devfs
authorChristoph Hellwig <hch@lst.de>
Mon, 24 Mar 2003 02:04:50 +0000 (18:04 -0800)
committerChristoph Hellwig <hch@hera.kernel.org>
Mon, 24 Mar 2003 02:04:50 +0000 (18:04 -0800)
.. by moving a bunch of devfs-related code from fs/partition/check.c
to fs/devfs/base.c.  Also has the nice sideffect of getting rid of
a bunch of ugly ifdefs.

[This is the new and improved, rediffed, applying and compilable
 version.  In short it's perfect]

fs/devfs/util.c
fs/partitions/check.c
include/linux/devfs_fs_kernel.h

index b2db96ca4aa65a66e620ac6356db5d5190e39db0..19a5b8de334b2ed610457721812490b969048acb 100644 (file)
@@ -70,6 +70,7 @@
 #include <linux/devfs_fs_kernel.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
+#include <linux/genhd.h>
 #include <asm/bitops.h>
 #include "internal.h"
 
@@ -266,6 +267,18 @@ void devfs_dealloc_devnum(umode_t mode, dev_t devnum)
        up(&device_list_mutex);
 }
 
+struct unique_numspace
+{
+    spinlock_t init_lock;
+    unsigned char sem_initialised;
+    unsigned int num_free;          /*  Num free in bits       */
+    unsigned int length;            /*  Array length in bytes  */
+    unsigned long *bits;
+    struct semaphore semaphore;
+};
+
+#define UNIQUE_NUMBERSPACE_INITIALISER {SPIN_LOCK_UNLOCKED, 0, 0, 0, NULL}
+
 
 /**
  *     devfs_alloc_unique_number - Allocate a unique (positive) number.
@@ -339,3 +352,82 @@ void devfs_dealloc_unique_number (struct unique_numspace *space, int number)
     if (!was_set) PRINTK ("(): number %d was already free\n", number);
 }   /*  End Function devfs_dealloc_unique_number  */
 EXPORT_SYMBOL(devfs_dealloc_unique_number);
+
+static struct unique_numspace disc_numspace = UNIQUE_NUMBERSPACE_INITIALISER;
+static struct unique_numspace cdrom_numspace = UNIQUE_NUMBERSPACE_INITIALISER;
+
+void devfs_create_partitions(struct gendisk *dev)
+{
+       int pos = 0;
+       devfs_handle_t dir;
+       char dirname[64], symlink[16];
+
+       if (dev->flags & GENHD_FL_DEVFS) {
+               dir = dev->de;
+               if (!dir)  /*  Aware driver wants to block disc management  */
+                       return;
+               pos = devfs_generate_path(dir, dirname + 3, sizeof dirname-3);
+               if (pos < 0)
+                       return;
+               strncpy(dirname + pos, "../", 3);
+       } else {
+               /*  Unaware driver: construct "real" directory  */
+               sprintf(dirname, "../%s/disc%d", dev->disk_name,
+                       dev->first_minor >> dev->minor_shift);
+               dir = devfs_mk_dir(dirname + 3);
+               dev->de = dir;
+       }
+       dev->number = devfs_alloc_unique_number (&disc_numspace);
+       sprintf(symlink, "discs/disc%d", dev->number);
+       devfs_mk_symlink(symlink, dirname + pos);
+       dev->disk_de = devfs_register(dir, "disc", 0,
+                           dev->major, dev->first_minor,
+                           S_IFBLK | S_IRUSR | S_IWUSR, dev->fops, NULL);
+}
+
+void devfs_create_cdrom(struct gendisk *dev)
+{
+       char vname[23];
+
+       dev->number = devfs_alloc_unique_number(&cdrom_numspace);
+       sprintf(vname, "cdroms/cdrom%d", dev->number);
+       if (dev->de) {
+               int pos;
+               char rname[64];
+
+               dev->disk_de = devfs_register(dev->de, "cd", DEVFS_FL_DEFAULT,
+                                    dev->major, dev->first_minor,
+                                    S_IFBLK | S_IRUGO | S_IWUGO,
+                                    dev->fops, NULL);
+
+               pos = devfs_generate_path(dev->disk_de, rname+3, sizeof(rname)-3);
+               if (pos >= 0) {
+                       strncpy(rname + pos, "../", 3);
+                       devfs_mk_symlink(vname, rname + pos);
+               }
+       } else {
+               dev->disk_de = devfs_register (NULL, vname, DEVFS_FL_DEFAULT,
+                                   dev->major, dev->first_minor,
+                                   S_IFBLK | S_IRUGO | S_IWUGO,
+                                   dev->fops, NULL);
+       }
+}
+
+void devfs_remove_partitions(struct gendisk *dev)
+{
+       devfs_unregister(dev->disk_de);
+       dev->disk_de = NULL;
+
+       if (dev->flags & GENHD_FL_CD) {
+               if (dev->de)
+                       devfs_remove("cdroms/cdrom%d", dev->number);
+               devfs_dealloc_unique_number(&cdrom_numspace, dev->number);
+       } else {
+               devfs_remove("discs/disc%d", dev->number);
+               if (!(dev->flags & GENHD_FL_DEVFS)) {
+                       devfs_unregister(dev->de);
+                       dev->de = NULL;
+               }
+               devfs_dealloc_unique_number(&disc_numspace, dev->number);
+       }
+}
index b3dc098012d4ef13280799e524a71d861ca52f33..f5b6dbe5cee63e7f3649997db715c48176b94276 100644 (file)
@@ -176,93 +176,6 @@ static void devfs_register_partition(struct gendisk *dev, int part)
 #endif
 }
 
-#ifdef CONFIG_DEVFS_FS
-static struct unique_numspace disc_numspace = UNIQUE_NUMBERSPACE_INITIALISER;
-static struct unique_numspace cdrom_numspace = UNIQUE_NUMBERSPACE_INITIALISER;
-#endif
-
-static void devfs_create_partitions(struct gendisk *dev)
-{
-#ifdef CONFIG_DEVFS_FS
-       int pos = 0;
-       devfs_handle_t dir;
-       char dirname[64], symlink[16];
-
-       if (dev->flags & GENHD_FL_DEVFS) {
-               dir = dev->de;
-               if (!dir)  /*  Aware driver wants to block disc management  */
-                       return;
-               pos = devfs_generate_path(dir, dirname + 3, sizeof dirname-3);
-               if (pos < 0)
-                       return;
-               strncpy(dirname + pos, "../", 3);
-       } else {
-               /*  Unaware driver: construct "real" directory  */
-               sprintf(dirname, "../%s/disc%d", dev->disk_name,
-                       dev->first_minor >> dev->minor_shift);
-               dir = devfs_mk_dir(dirname + 3);
-               dev->de = dir;
-       }
-       dev->number = devfs_alloc_unique_number (&disc_numspace);
-       sprintf(symlink, "discs/disc%d", dev->number);
-       devfs_mk_symlink(symlink, dirname + pos);
-       dev->disk_de = devfs_register(dir, "disc", 0,
-                           dev->major, dev->first_minor,
-                           S_IFBLK | S_IRUSR | S_IWUSR, dev->fops, NULL);
-#endif
-}
-
-static void devfs_create_cdrom(struct gendisk *dev)
-{
-#ifdef CONFIG_DEVFS_FS
-       char vname[23];
-
-       dev->number = devfs_alloc_unique_number(&cdrom_numspace);
-       sprintf(vname, "cdroms/cdrom%d", dev->number);
-       if (dev->de) {
-               int pos;
-               char rname[64];
-
-               dev->disk_de = devfs_register(dev->de, "cd", DEVFS_FL_DEFAULT,
-                                    dev->major, dev->first_minor,
-                                    S_IFBLK | S_IRUGO | S_IWUGO,
-                                    dev->fops, NULL);
-
-               pos = devfs_generate_path(dev->disk_de, rname+3, sizeof(rname)-3);
-               if (pos >= 0) {
-                       strncpy(rname + pos, "../", 3);
-                       devfs_mk_symlink(vname, rname + pos);
-               }
-       } else {
-               dev->disk_de = devfs_register (NULL, vname, DEVFS_FL_DEFAULT,
-                                   dev->major, dev->first_minor,
-                                   S_IFBLK | S_IRUGO | S_IWUGO,
-                                   dev->fops, NULL);
-       }
-#endif
-}
-
-static void devfs_remove_partitions(struct gendisk *dev)
-{
-#ifdef CONFIG_DEVFS_FS
-       devfs_unregister(dev->disk_de);
-       dev->disk_de = NULL;
-       if (dev->flags & GENHD_FL_CD) {
-               if (dev->de)
-                       devfs_remove("cdroms/cdrom%d", dev->number);
-               devfs_dealloc_unique_number(&cdrom_numspace, dev->number);
-       } else {
-               devfs_remove("discs/disc%d", dev->number);
-               if (!(dev->flags & GENHD_FL_DEVFS)) {
-                       devfs_unregister(dev->de);
-                       dev->de = NULL;
-               }
-               devfs_dealloc_unique_number(&disc_numspace, dev->number);
-       }
-#endif
-}
-
-
 /*
  * sysfs bindings for partitions
  */
@@ -522,6 +435,7 @@ char *partition_name(dev_t dev)
 {
        struct gendisk *hd;
        static char nomem [] = "<nomem>";
+       char b[BDEVNAME_SIZE];
        struct dev_name *dname;
        struct list_head *tmp;
        int part;
@@ -547,7 +461,7 @@ char *partition_name(dev_t dev)
                put_disk(hd);
        }
        if (!dname->name) {
-               sprintf(dname->namebuf, "[dev %s]", kdevname(to_kdev_t(dev)));
+               sprintf(dname->namebuf, "[dev %s]", __bdevname(dev, b));
                dname->name = dname->namebuf;
        }
 
index 9d1d45877bc84093f5de99d40f1a48fe9597c67f..f484bc34339d8879b42d9b0ccd8f6f651a89d224 100644 (file)
 
 typedef struct devfs_entry * devfs_handle_t;
 
-#ifdef CONFIG_DEVFS_FS
-
-struct unique_numspace
-{
-    spinlock_t init_lock;
-    unsigned char sem_initialised;
-    unsigned int num_free;          /*  Num free in bits       */
-    unsigned int length;            /*  Array length in bytes  */
-    unsigned long *bits;
-    struct semaphore semaphore;
-};
-
-#define UNIQUE_NUMBERSPACE_INITIALISER {SPIN_LOCK_UNLOCKED, 0, 0, 0, NULL}
+struct gendisk;
 
+#ifdef CONFIG_DEVFS_FS
 extern devfs_handle_t devfs_register (devfs_handle_t dir, const char *name,
                                      unsigned int flags,
                                      unsigned int major, unsigned int minor,
@@ -47,21 +36,11 @@ extern void devfs_remove(const char *fmt, ...)
 extern int devfs_generate_path (devfs_handle_t de, char *path, int buflen);
 extern int devfs_register_tape (devfs_handle_t de);
 extern void devfs_unregister_tape(int num);
-extern int devfs_alloc_unique_number (struct unique_numspace *space);
-extern void devfs_dealloc_unique_number (struct unique_numspace *space,
-                                        int number);
-
+extern void devfs_create_partitions(struct gendisk *dev);
+extern void devfs_create_cdrom(struct gendisk *dev);
+extern void devfs_remove_partitions(struct gendisk *dev);
 extern void mount_devfs_fs (void);
-
 #else  /*  CONFIG_DEVFS_FS  */
-
-struct unique_numspace
-{
-    char dummy;
-};
-
-#define UNIQUE_NUMBERSPACE_INITIALISER {0}
-
 static inline devfs_handle_t devfs_register (devfs_handle_t dir,
                                             const char *name,
                                             unsigned int flags,
@@ -99,14 +78,14 @@ static inline int devfs_register_tape (devfs_handle_t de)
 static inline void devfs_unregister_tape(int num)
 {
 }
-static inline int devfs_alloc_unique_number (struct unique_numspace *space)
+static inline void devfs_create_partitions(struct gendisk *dev)
 {
-    return -1;
 }
-static inline void devfs_dealloc_unique_number (struct unique_numspace *space,
-                                               int number)
+static inline void devfs_create_cdrom(struct gendisk *dev)
+{
+}
+static inline void devfs_remove_partitions(struct gendisk *dev)
 {
-    return;
 }
 static inline void mount_devfs_fs (void)
 {