Tentative patch: modularized disk partition systems in 2.3.99-pre2-5

From: Adam J. Richter (adam@yggdrasil.com)
Date: Sat Mar 18 2000 - 21:52:14 EST


        This patch should allow the disk partition handlers to be
compiled as loadable modules. The patch also has the side effect
of simplifying fs/partitions/Makefile. At this point, I can
only verify that the kernel itself compiles with this change.
I have not build or tried to use the modules because there are
all sorts of other build problems in other modules (at least
in drivers/net) that I will either have to fix or work around.

        The advantages of this patch are a small increment of
the benefits that we get from modularization generally. It makes
a "universal" kernel about 20kB smaller (or about 7kB compressed),
which should allow another device driver to fit on a boot floppy,
shave a few milliseconds from boot time decompression. It should
make partition recognition a tiny bit faster (since partition schemes
that you do not want will not be loaded).

        If this change looks good to everyone, then, the next change
after making sure that the modules work would be to add demand loading
of the modules via kmod. I am thinking of naming the demand loaded
module names as "partition-12345678", where "12345678" is the hexadecimal
representation of the first four bytes of the partition. If anyone
has some better suggetions, I am open to hearing them.

        Anyhow, I have attached the patch below. I welcome any
input on it.

Adam J. Richter __ ______________ 4880 Stevens Creek Blvd, Suite 104
adam@yggdrasil.com \ / San Jose, California 95129-1034
+1 408 261-6630 | g g d r a s i l United States of America
fax +1 408 261-6631 "Free Software For The Rest Of Us."
---------------------------CUT HERE-------------------------------------

Only in linux/fs/partitions: CVS
diff -u -r linux-2.3.99pre1.5/fs/partitions/Config.in linux/fs/partitions/Config.in
--- linux-2.3.99pre1.5/fs/partitions/Config.in Thu Feb 10 22:02:32 2000
+++ linux/fs/partitions/Config.in Sat Mar 18 17:12:44 2000
@@ -3,7 +3,7 @@
 #
 bool 'Advanced partition selection' CONFIG_PARTITION_ADVANCED
 if [ "$CONFIG_PARTITION_ADVANCED" = "y" ]; then
- bool ' Acorn partition support' CONFIG_ACORN_PARTITION
+ tristate ' Acorn partition support' CONFIG_ACORN_PARTITION
    if [ "$CONFIG_ACORN_PARTITION" != "n" ]; then
 # bool ' Cumana partition support' CONFIG_ACORN_PARTITION_CUMANA
       bool ' ICS partition support' CONFIG_ACORN_PARTITION_ICS
@@ -11,18 +11,18 @@
       bool ' PowerTec partition support' CONFIG_ACORN_PARTITION_POWERTEC
       bool ' RISCiX partition support' CONFIG_ACORN_PARTITION_RISCIX
    fi
- bool ' Alpha OSF partition support' CONFIG_OSF_PARTITION
- bool ' Amiga partition table support' CONFIG_AMIGA_PARTITION
- bool ' Atari partition table support' CONFIG_ATARI_PARTITION
- bool ' Macintosh partition map support' CONFIG_MAC_PARTITION
- bool ' PC BIOS (MSDOS partition tables) support' CONFIG_MSDOS_PARTITION
- if [ "$CONFIG_MSDOS_PARTITION" = "y" ]; then
+ tristate ' Alpha OSF partition support' CONFIG_OSF_PARTITION
+ tristate ' Amiga partition table support' CONFIG_AMIGA_PARTITION
+ tristate ' Atari partition table support' CONFIG_ATARI_PARTITION
+ tristate ' Macintosh partition map support' CONFIG_MAC_PARTITION
+ tristate ' PC BIOS (MSDOS partition tables) support' CONFIG_MSDOS_PARTITION
+ if [ "$CONFIG_MSDOS_PARTITION" != "n" ]; then
       bool ' BSD disklabel (FreeBSD partition tables) support' CONFIG_BSD_DISKLABEL
       bool ' Solaris (x86) partition table support' CONFIG_SOLARIS_X86_PARTITION
       bool ' Unixware slices support' CONFIG_UNIXWARE_DISKLABEL
    fi
- bool 'SGI partition support' CONFIG_SGI_PARTITION
- bool 'Sun partition tables support' CONFIG_SUN_PARTITION
+ tristate 'SGI partition support' CONFIG_SGI_PARTITION
+ tristate 'Sun partition tables support' CONFIG_SUN_PARTITION
 else
    if [ "$ARCH" = "alpha" ]; then
       define_bool CONFIG_OSF_PARTITION y
diff -u -r linux-2.3.99pre1.5/fs/partitions/Makefile linux/fs/partitions/Makefile
--- linux-2.3.99pre1.5/fs/partitions/Makefile Thu Aug 12 12:26:06 1999
+++ linux/fs/partitions/Makefile Sat Mar 18 17:05:50 2000
@@ -10,40 +10,17 @@
 O_TARGET := partitions.o
 O_OBJS := check.o
 
-ifeq ($(CONFIG_ACORN_PARTITION),y)
-O_OBJS += acorn.o
-endif
+obj-$(CONFIG_ACORN_PARTITION) += acorn.o
+obj-$(CONFIG_AMIGA_PARTITION) += amiga.o
+obj-$(CONFIG_ATARI_PARTITION) += atari.o
+obj-$(CONFIG_MAC_PARTITION) += mac.o
+obj-$(CONFIG_MSDOS_PARTITION) += msdos.o
+obj-$(CONFIG_OSF_PARTITION) += osf.o
+obj-$(CONFIG_SGI_PARTITION) += sgi.o
+obj-$(CONFIG_SUN_PARTITION) += sun.o
+obj-$(CONFIG_ULTRIX_PARTITION) += ultrix.o
 
-ifeq ($(CONFIG_AMIGA_PARTITION),y)
-O_OBJS += amiga.o
-endif
-
-ifeq ($(CONFIG_ATARI_PARTITION),y)
-O_OBJS += atari.o
-endif
-
-ifeq ($(CONFIG_MAC_PARTITION),y)
-O_OBJS += mac.o
-endif
-
-ifeq ($(CONFIG_MSDOS_PARTITION),y)
-O_OBJS += msdos.o
-endif
-
-ifeq ($(CONFIG_OSF_PARTITION),y)
-O_OBJS += osf.o
-endif
-
-ifeq ($(CONFIG_SGI_PARTITION),y)
-O_OBJS += sgi.o
-endif
-
-ifeq ($(CONFIG_SUN_PARTITION),y)
-O_OBJS += sun.o
-endif
-
-ifeq ($(CONFIG_ULTRIX_PARTITION),y)
-O_OBJS += ultrix.o
-endif
+O_OBJS += $(obj-y)
+M_OBJS += $(obj-m)
 
 include $(TOPDIR)/Rules.make
diff -u -r linux-2.3.99pre1.5/fs/partitions/acorn.c linux/fs/partitions/acorn.c
--- linux-2.3.99pre1.5/fs/partitions/acorn.c Sat Mar 18 13:00:31 2000
+++ linux/fs/partitions/acorn.c Sat Mar 18 18:22:42 2000
@@ -491,3 +491,6 @@
                 printk("\n");
         return r;
 }
+
+#define check_partition acorn_partition
+#include "partition_module.c"
diff -u -r linux-2.3.99pre1.5/fs/partitions/amiga.c linux/fs/partitions/amiga.c
--- linux-2.3.99pre1.5/fs/partitions/amiga.c Wed Feb 16 15:42:06 2000
+++ linux/fs/partitions/amiga.c Sat Mar 18 17:45:24 2000
@@ -118,3 +118,6 @@
         set_blocksize(dev,old_blocksize);
         return res;
 }
+
+#define check_partition amiga_partition
+#include "partition_module.c"
diff -u -r linux-2.3.99pre1.5/fs/partitions/atari.c linux/fs/partitions/atari.c
--- linux-2.3.99pre1.5/fs/partitions/atari.c Sun Mar 12 19:39:39 2000
+++ linux/fs/partitions/atari.c Sat Mar 18 18:22:52 2000
@@ -175,3 +175,5 @@
   return 1;
 }
 
+#define check_partition atari_partition
+#include "partition_module.c"
diff -u -r linux-2.3.99pre1.5/fs/partitions/check.c linux/fs/partitions/check.c
--- linux-2.3.99pre1.5/fs/partitions/check.c Sat Feb 26 08:25:35 2000
+++ linux/fs/partitions/check.c Sat Mar 18 18:18:19 2000
@@ -40,35 +40,35 @@
 struct gendisk *gendisk_head;
 int warn_no_part = 1; /*This is ugly: should make genhd removable media aware*/
 
-static int (*check_part[])(struct gendisk *hd, kdev_t dev, unsigned long first_sect, int first_minor) = {
+static struct partition_ops *part_ops;
+static struct partition_ops initial_part_ops[] = {
 #ifdef CONFIG_ACORN_PARTITION
- acorn_partition,
+ {acorn_partition, NULL},
 #endif
 #ifdef CONFIG_MSDOS_PARTITION
- msdos_partition,
+ {msdos_partition, NULL},
 #endif
 #ifdef CONFIG_OSF_PARTITION
- osf_partition,
+ {osf_partition, NULL},
 #endif
 #ifdef CONFIG_SUN_PARTITION
- sun_partition,
+ {sun_partition, NULL},
 #endif
 #ifdef CONFIG_AMIGA_PARTITION
- amiga_partition,
+ {amiga_partition, NULL},
 #endif
 #ifdef CONFIG_ATARI_PARTITION
- atari_partition,
+ {atari_partition, NULL},
 #endif
 #ifdef CONFIG_MAC_PARTITION
- mac_partition,
+ {mac_partition, NULL},
 #endif
 #ifdef CONFIG_SGI_PARTITION
- sgi_partition,
+ {sgi_partition, NULL},
 #endif
 #ifdef CONFIG_ULTRIX_PARTITION
- ultrix_partition,
+ {ultrix_partition, NULL},
 #endif
- NULL
 };
 
 /*
@@ -257,6 +257,7 @@
         unsigned long first_sector;
         char buf[64];
         int i;
+ struct partition_ops *ops;
 
         if (first_time)
                 printk(KERN_INFO "Partition check:\n");
@@ -279,8 +280,8 @@
                 printk(KERN_INFO " /dev/%s:", buf + i);
         else
                 printk(KERN_INFO " %s:", disk_name(hd, MINOR(dev), buf));
- for (i = 0; check_part[i]; i++)
- if (check_part[i](hd, dev, first_sector, first_part_minor))
+ for (ops = part_ops; ops != NULL; ops = ops->next)
+ if ((*ops->check)(hd, dev, first_sector, first_part_minor))
                         goto setup_devfs;
 
         printk(" unknown partition table\n");
@@ -390,6 +391,25 @@
         grok_partitions(gdev, MINOR(dev)>>gdev->minor_shift, minors, size);
 }
 
+void register_partition_ops(struct partition_ops *ops)
+{
+ ops->next = part_ops;
+ part_ops = ops;
+}
+
+void unregister_partition_ops(struct partition_ops *ops)
+{
+ struct partition_ops **tmp;
+ for (tmp = &part_ops; *tmp != NULL; tmp = &(*tmp)->next) {
+ if (*tmp == ops) {
+ *tmp = ops->next;
+ return;
+ }
+ }
+}
+
+
+
 void grok_partitions(struct gendisk *dev, int drive, unsigned minors, long size)
 {
         int i;
@@ -420,6 +440,14 @@
 
 int __init partition_setup(void)
 {
+ int i;
+
+ for (i = 0;
+ i < sizeof(initial_part_ops) / sizeof(struct partition_ops);
+ i++) {
+ register_partition_ops(&initial_part_ops[i]);
+ }
+
         device_init();
 
 #ifdef CONFIG_BLK_DEV_RAM
diff -u -r linux-2.3.99pre1.5/fs/partitions/mac.c linux/fs/partitions/mac.c
--- linux-2.3.99pre1.5/fs/partitions/mac.c Wed Feb 9 19:43:53 2000
+++ linux/fs/partitions/mac.c Sat Mar 18 18:23:07 2000
@@ -150,3 +150,5 @@
         return 1;
 }
 
+#define check_partition mac_partition
+#include "partition_module.c"
diff -u -r linux-2.3.99pre1.5/fs/partitions/msdos.c linux/fs/partitions/msdos.c
--- linux-2.3.99pre1.5/fs/partitions/msdos.c Sat Mar 18 13:00:31 2000
+++ linux/fs/partitions/msdos.c Sat Mar 18 17:45:24 2000
@@ -495,3 +495,6 @@
         bforget(bh);
         return 1;
 }
+
+#define check_partition msdos_partition
+#include "partition_module.c"
diff -u -r linux-2.3.99pre1.5/fs/partitions/osf.c linux/fs/partitions/osf.c
--- linux-2.3.99pre1.5/fs/partitions/osf.c Wed Feb 16 15:42:06 2000
+++ linux/fs/partitions/osf.c Sat Mar 18 18:23:22 2000
@@ -84,3 +84,5 @@
         return 1;
 }
 
+#define check_partition osf_partition
+#include "partition_module.c"
Only in linux/fs/partitions: partition_module.c
diff -u -r linux-2.3.99pre1.5/fs/partitions/sgi.c linux/fs/partitions/sgi.c
--- linux-2.3.99pre1.5/fs/partitions/sgi.c Sun Mar 12 19:39:39 2000
+++ linux/fs/partitions/sgi.c Sat Mar 18 17:45:24 2000
@@ -84,3 +84,6 @@
         brelse(bh);
         return 1;
 }
+
+#define check_partition sgi_partition
+#include "partition_module.c"
diff -u -r linux-2.3.99pre1.5/fs/partitions/sun.c linux/fs/partitions/sun.c
--- linux-2.3.99pre1.5/fs/partitions/sun.c Wed Feb 16 15:42:06 2000
+++ linux/fs/partitions/sun.c Sat Mar 18 18:23:36 2000
@@ -87,3 +87,5 @@
         return 1;
 }
 
+#define check_partition sun_partition
+#include "partition_module.c"
diff -u -r linux-2.3.99pre1.5/fs/partitions/ultrix.c linux/fs/partitions/ultrix.c
--- linux-2.3.99pre1.5/fs/partitions/ultrix.c Wed Feb 16 15:42:06 2000
+++ linux/fs/partitions/ultrix.c Sat Mar 18 17:45:24 2000
@@ -58,3 +58,6 @@
         }
 }
 
+
+#define check_partition ultrix_partition
+#include "partition_module.c"
--- linux-2.3.99pre1.5/include/linux/blkdev.h Tue Mar 14 18:37:04 2000
+++ linux/include/linux/blkdev.h Sat Mar 18 17:58:39 2000
@@ -107,6 +107,14 @@
         unsigned block_size_bits;
 };
 
+struct partition_ops {
+ int (*check)(struct gendisk *hd,
+ kdev_t dev,
+ unsigned long first_sect,
+ int first_minor);
+ struct partition_reader *next;
+};
+
 /*
  * Used to indicate the default queue for drivers that don't bother
  * to implement multiple queues. We have this access macro here
@@ -118,6 +126,8 @@
 extern struct sec_size * blk_sec[MAX_BLKDEV];
 extern struct blk_dev_struct blk_dev[MAX_BLKDEV];
 extern wait_queue_head_t wait_for_request;
+extern void register_partition_ops(struct partition_ops *ops);
+extern void unregister_partition_ops(struct partition_ops *ops);
 extern void grok_partitions(struct gendisk *dev, int drive, unsigned minors, long size);
 extern void register_disk(struct gendisk *dev, kdev_t first, unsigned minors, struct block_device_operations *ops, long size);
 extern void generic_unplug_device(void * data);
--- /dev/null Sat Jul 17 14:59:27 1999
+++ linux/fs/partitions/partition_module.c Sat Mar 18 18:50:15 2000
@@ -0,0 +1,27 @@
+/* Copyright 2000 Yggdrasil Computing, Inc.
+ Written by Adam J. Richter
+
+ This file may be copied under the terms and conditions of version
+ 2 of the GNU General Public License, as published by the Free
+ Software Foundation (Cambridge, Massachussetts, USA).
+*/
+
+#ifdef MODULE
+static struct partition_ops ops = {
+ partition_check,
+ NULL
+};
+
+int
+init_module(void)
+{
+ register_partition_ops(&ops);
+ return 0;
+}
+
+void
+cleanup_module(void)
+{
+ unregister_partition_ops(&ops);
+}
+#endif /* MODULE */

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/



This archive was generated by hypermail 2b29 : Thu Mar 23 2000 - 21:00:26 EST