From hpernu@snakemail.hut.fiSun Feb 5 18:16:56 1995 Date: Sat, 4 Feb 1995 21:50:40 +0200 (EET) From: Heikki Johannes Pernu To: linux-kernel@vger.rutgers.edu Cc: torvalds@cc.helsinki.fi Subject: Patch to modularize all filesystems At the end of this message is a patch to modularize filesystems not yet modularized. These are ext, ext2 and hpfs filesystems. hpfs has been tested a bit since I have a hpfs partition, but ext ( I don't use it ) and ext2 ( I'm using it as root -> has to be compiled in the kernel ) have not been teste. They should work though. Most people probably don't need this patch but for me hpfs- module is useful and I heard that umsdos users might also find ext2-module useful. Patch is contained in the end of this message. It's against 1.1.88 ( It's pretty long - about 16 kilobytes ) All filesystems should be modules now. :-) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ tel: +358-0-2786 837 e-mail: hpernu@snakemail.hut.fi Try 'finger hpernu@beta.hut.fi' for more info. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ diff -r --unified -H linux.orig/fs/Makefile linux/fs/Makefile --- linux.orig/fs/Makefile Mon Jan 23 10:38:28 1995 +++ linux/fs/Makefile Sat Feb 4 18:36:34 1995 @@ -17,10 +17,14 @@ ifdef CONFIG_EXT_FS FS_SUBDIRS := $(FS_SUBDIRS) ext +else +MODULE_FS_SUBDIRS := $(MODULES_FS_SUBDIRS) ext endif ifdef CONFIG_EXT2_FS FS_SUBDIRS := $(FS_SUBDIRS) ext2 +else +MODULE_FS_SUBDIRS := $(MODULE_FS_SUBDIRS) ext2 endif ifdef CONFIG_MSDOS_FS @@ -65,6 +69,8 @@ ifdef CONFIG_HPFS_FS FS_SUBDIRS := $(FS_SUBDIRS) hpfs +else +MODULE_FS_SUBDIRS := $(MODULE_FS_SUBDIRS) hpfs endif ifdef CONFIG_BINFMT_ELF diff -r --unified -H linux.orig/fs/ext/Makefile linux/fs/ext/Makefile --- linux.orig/fs/ext/Makefile Wed Dec 1 14:44:15 1993 +++ linux/fs/ext/Makefile Sat Feb 4 18:37:08 1995 @@ -23,6 +23,8 @@ dep: $(CPP) -M *.c > .depend +modules: ext.o + # # include a dependency file if one exists # diff -r --unified -H linux.orig/fs/ext/dir.c linux/fs/ext/dir.c --- linux.orig/fs/ext/dir.c Wed Oct 19 10:23:03 1994 +++ linux/fs/ext/dir.c Sat Feb 4 18:39:01 1995 @@ -12,6 +12,10 @@ * ext directory handling functions */ +#ifdef MODULE +#include +#endif + #include #include diff -r --unified -H linux.orig/fs/ext/file.c linux/fs/ext/file.c --- linux.orig/fs/ext/file.c Mon Apr 18 11:38:16 1994 +++ linux/fs/ext/file.c Sat Feb 4 18:39:19 1995 @@ -12,6 +12,10 @@ * ext regular file handling primitives */ +#ifdef MODULE +#include +#endif + #include #include diff -r --unified -H linux.orig/fs/ext/freelists.c linux/fs/ext/freelists.c --- linux.orig/fs/ext/freelists.c Sat Oct 22 16:38:32 1994 +++ linux/fs/ext/freelists.c Sat Feb 4 18:39:30 1995 @@ -30,6 +30,10 @@ */ +#ifdef MODULE +#include +#endif + #include #include #include diff -r --unified -H linux.orig/fs/ext/fsync.c linux/fs/ext/fsync.c --- linux.orig/fs/ext/fsync.c Mon Dec 27 07:35:59 1993 +++ linux/fs/ext/fsync.c Sat Feb 4 18:39:42 1995 @@ -11,6 +11,10 @@ * extfs fsync primitive */ +#ifdef MODULE +#include +#endif + #include #include diff -r --unified -H linux.orig/fs/ext/inode.c linux/fs/ext/inode.c --- linux.orig/fs/ext/inode.c Mon Aug 15 15:53:47 1994 +++ linux/fs/ext/inode.c Sat Feb 4 18:44:42 1995 @@ -10,6 +10,14 @@ * Copyright (C) 1991, 1992 Linus Torvalds */ +#ifdef MODULE +#include +#include +#else +#define MOD_INC_USE_COUNT +#define MOD_DEC_USE_COUNT +#endif + #include #include #include @@ -40,6 +48,7 @@ if (sb->u.ext_sb.s_firstfreeblock) brelse (sb->u.ext_sb.s_firstfreeblock); unlock_super(sb); + MOD_DEC_USE_COUNT; return; } @@ -61,12 +70,14 @@ struct ext_super_block *es; int dev = s->s_dev,block; + MOD_INC_USE_COUNT; lock_super(s); set_blocksize(dev, BLOCK_SIZE); if (!(bh = bread(dev, 1, BLOCK_SIZE))) { s->s_dev=0; unlock_super(s); printk("EXT-fs: unable to read superblock\n"); + MOD_DEC_USE_COUNT; return NULL; } es = (struct ext_super_block *) bh->b_data; @@ -89,6 +100,7 @@ if (!silent) printk("VFS: Can't find an extfs filesystem on dev 0x%04x.\n", dev); + MOD_DEC_USE_COUNT; return NULL; } if (!s->u.ext_sb.s_firstfreeblocknumber) @@ -99,6 +111,7 @@ printk("ext_read_super: unable to read first free block\n"); s->s_dev = 0; unlock_super(s); + MOD_DEC_USE_COUNT; return NULL; } if (!s->u.ext_sb.s_firstfreeinodenumber) @@ -110,6 +123,7 @@ brelse(s->u.ext_sb.s_firstfreeblock); s->s_dev = 0; unlock_super (s); + MOD_DEC_USE_COUNT; return NULL; } } @@ -120,6 +134,7 @@ if (!(s->s_mounted = iget(s,EXT_ROOT_INO))) { s->s_dev=0; printk("EXT-fs: get root inode failed\n"); + MOD_DEC_USE_COUNT; return NULL; } return s; @@ -442,3 +457,23 @@ return err; } +#ifdef MODULE + +char kernel_version[] = UTS_RELEASE; + +static struct file_system_type ext_fs_type = { + ext_read_super, "ext", 1, NULL +}; + +int init_module(void) +{ + register_filesystem(&ext_fs_type); + return 0; +} + +void cleanup_module(void) +{ + unregister_filesystem(&ext_fs_type); +} + +#endif diff -r --unified -H linux.orig/fs/ext/namei.c linux/fs/ext/namei.c --- linux.orig/fs/ext/namei.c Wed Jan 18 09:51:48 1995 +++ linux/fs/ext/namei.c Sat Feb 4 18:40:08 1995 @@ -10,6 +10,10 @@ * Copyright (C) 1991, 1992 Linus Torvalds */ +#ifdef MODULE +#include +#endif + #include #include #include diff -r --unified -H linux.orig/fs/ext/symlink.c linux/fs/ext/symlink.c --- linux.orig/fs/ext/symlink.c Mon May 2 18:34:26 1994 +++ linux/fs/ext/symlink.c Sat Feb 4 18:40:20 1995 @@ -12,6 +12,10 @@ * ext symlink handling code */ +#ifdef MODULE +#include +#endif + #include #include diff -r --unified -H linux.orig/fs/ext/truncate.c linux/fs/ext/truncate.c --- linux.orig/fs/ext/truncate.c Mon Apr 18 11:38:17 1994 +++ linux/fs/ext/truncate.c Sat Feb 4 18:40:30 1995 @@ -10,6 +10,10 @@ * Copyright (C) 1991, 1992 Linus Torvalds */ +#ifdef MODULE +#include +#endif + #include #include #include diff -r --unified -H linux.orig/fs/ext2/Makefile linux/fs/ext2/Makefile --- linux.orig/fs/ext2/Makefile Fri Jul 29 14:35:03 1994 +++ linux/fs/ext2/Makefile Sat Feb 4 18:35:15 1995 @@ -23,6 +23,8 @@ dep: $(CPP) -M *.c > .depend +modules: ext2.o + # # include a dependency file if one exists # diff -r --unified -H linux.orig/fs/ext2/acl.c linux/fs/ext2/acl.c --- linux.orig/fs/ext2/acl.c Wed Jan 11 08:11:02 1995 +++ linux/fs/ext2/acl.c Sat Feb 4 18:18:56 1995 @@ -11,6 +11,10 @@ * second extended file system. */ +#ifdef MODULE +#include +#endif + #include #include #include diff -r --unified -H linux.orig/fs/ext2/balloc.c linux/fs/ext2/balloc.c --- linux.orig/fs/ext2/balloc.c Wed Nov 30 21:47:39 1994 +++ linux/fs/ext2/balloc.c Sat Feb 4 18:19:41 1995 @@ -23,6 +23,10 @@ * when a file system is mounted (see ext2_read_super). */ +#ifdef MODULE +#include +#endif + #include #include #include diff -r --unified -H linux.orig/fs/ext2/bitmap.c linux/fs/ext2/bitmap.c --- linux.orig/fs/ext2/bitmap.c Fri Dec 31 11:59:48 1993 +++ linux/fs/ext2/bitmap.c Sat Feb 4 18:38:18 1995 @@ -6,6 +6,10 @@ * Universite Pierre et Marie Curie (Paris VI) */ +#ifdef MODULE +#include +#endif + #include #include diff -r --unified -H linux.orig/fs/ext2/dir.c linux/fs/ext2/dir.c --- linux.orig/fs/ext2/dir.c Fri Oct 21 09:39:35 1994 +++ linux/fs/ext2/dir.c Sat Feb 4 18:20:14 1995 @@ -14,6 +14,10 @@ * ext2 directory handling functions */ +#ifdef MODULE +#include +#endif + #include #include diff -r --unified -H linux.orig/fs/ext2/file.c linux/fs/ext2/file.c --- linux.orig/fs/ext2/file.c Wed Oct 26 09:42:21 1994 +++ linux/fs/ext2/file.c Sat Feb 4 18:20:28 1995 @@ -14,6 +14,10 @@ * ext2 fs regular file handling primitives */ +#ifdef MODULE +#include +#endif + #include #include diff -r --unified -H linux.orig/fs/ext2/fsync.c linux/fs/ext2/fsync.c --- linux.orig/fs/ext2/fsync.c Fri Dec 31 11:59:48 1993 +++ linux/fs/ext2/fsync.c Sat Feb 4 18:20:51 1995 @@ -12,6 +12,10 @@ * ext2fs fsync primitive */ +#ifdef MODULE +#include +#endif + #include #include diff -r --unified -H linux.orig/fs/ext2/ialloc.c linux/fs/ext2/ialloc.c --- linux.orig/fs/ext2/ialloc.c Wed Nov 30 21:47:39 1994 +++ linux/fs/ext2/ialloc.c Sat Feb 4 18:21:08 1995 @@ -24,6 +24,10 @@ * when a file system is mounted (see ext2_read_super). */ +#ifdef MODULE +#include +#endif + #include #include #include diff -r --unified -H linux.orig/fs/ext2/inode.c linux/fs/ext2/inode.c --- linux.orig/fs/ext2/inode.c Mon Jan 23 23:04:10 1995 +++ linux/fs/ext2/inode.c Sat Feb 4 18:37:59 1995 @@ -14,6 +14,10 @@ * Goal-directed block allocation by Stephen Tweedie (sct@dcs.ed.ac.uk), 1993 */ +#ifdef MODULE +#include +#endif + #include #include diff -r --unified -H linux.orig/fs/ext2/ioctl.c linux/fs/ext2/ioctl.c --- linux.orig/fs/ext2/ioctl.c Mon Jan 23 23:04:10 1995 +++ linux/fs/ext2/ioctl.c Sat Feb 4 18:21:25 1995 @@ -6,6 +6,10 @@ * Universite Pierre et Marie Curie (Paris VI) */ +#ifdef MODULE +#include +#endif + #include #include diff -r --unified -H linux.orig/fs/ext2/namei.c linux/fs/ext2/namei.c --- linux.orig/fs/ext2/namei.c Wed Oct 19 10:23:17 1994 +++ linux/fs/ext2/namei.c Sat Feb 4 18:21:53 1995 @@ -12,6 +12,10 @@ * Copyright (C) 1991, 1992 Linus Torvalds */ +#ifdef MODULE +#include +#endif + #include #include diff -r --unified -H linux.orig/fs/ext2/super.c linux/fs/ext2/super.c --- linux.orig/fs/ext2/super.c Fri Nov 4 12:38:45 1994 +++ linux/fs/ext2/super.c Sat Feb 4 18:46:30 1995 @@ -12,6 +12,14 @@ * Copyright (C) 1991, 1992 Linus Torvalds */ +#ifdef MODULE +#include +#include +#else +#define MOD_INC_USE_COUNT +#define MOD_DEC_USE_COUNT +#endif + #include #include @@ -113,6 +121,7 @@ brelse (sb->u.ext2_sb.s_block_bitmap[i]); brelse (sb->u.ext2_sb.s_sbh); unlock_super (sb); + MOD_DEC_USE_COUNT; return; } @@ -404,6 +413,7 @@ int fs_converted = 0; #endif + set_opt (sb->u.ext2_sb.s_mount_opt, CHECK_NORMAL); if (!parse_options ((char *) data, &sb_block, &resuid, &resgid, &sb->u.ext2_sb.s_mount_opt)) { @@ -411,12 +421,14 @@ return NULL; } + MOD_INC_USE_COUNT; lock_super (sb); set_blocksize (dev, BLOCK_SIZE); if (!(bh = bread (dev, sb_block, BLOCK_SIZE))) { sb->s_dev = 0; unlock_super (sb); printk ("EXT2-fs: unable to read superblock\n"); + MOD_DEC_USE_COUNT; return NULL; } /* @@ -437,6 +449,8 @@ if (!silent) printk ("VFS: Can't find an ext2 filesystem on dev %d/%d.\n", MAJOR(dev), MINOR(dev)); + + MOD_DEC_USE_COUNT; return NULL; } sb->s_blocksize = EXT2_MIN_BLOCK_SIZE << es->s_log_block_size; @@ -451,8 +465,10 @@ logic_sb_block = (sb_block*BLOCK_SIZE) / sb->s_blocksize; offset = (sb_block*BLOCK_SIZE) % sb->s_blocksize; bh = bread (dev, logic_sb_block, sb->s_blocksize); - if(!bh) - return NULL; + if(!bh) { + MOD_DEC_USE_COUNT; + return NULL; + } es = (struct ext2_super_block *) (((char *)bh->b_data) + offset); sb->u.ext2_sb.s_es = es; if (es->s_magic != EXT2_SUPER_MAGIC) { @@ -460,6 +476,7 @@ unlock_super (sb); brelse (bh); printk ("EXT2-fs: Magic mismatch, very weird !\n"); + MOD_DEC_USE_COUNT; return NULL; } } @@ -503,6 +520,7 @@ brelse (bh); printk ("EXT2-fs: trying to mount a pre-0.2b file" "system which cannot be converted\n"); + MOD_DEC_USE_COUNT; return NULL; } printk ("EXT2-fs: mounting a pre 0.2b file system, " @@ -512,6 +530,7 @@ unlock_super (sb); brelse (bh); printk ("EXT2-fs: cannot convert a read-only fs\n"); + MOD_DEC_USE_COUNT; return NULL; } if (!convert_pre_02b_fs (sb, bh)) { @@ -519,6 +538,7 @@ unlock_super (sb); brelse (bh); printk ("EXT2-fs: conversion failed !!!\n"); + MOD_DEC_USE_COUNT; return NULL; } printk ("EXT2-fs: conversion succeeded !!!\n"); @@ -532,6 +552,7 @@ if (!silent) printk ("VFS: Can't find an ext2 filesystem on dev %d/%d.\n", MAJOR(dev), MINOR(dev)); + MOD_DEC_USE_COUNT; return NULL; } if (sb->s_blocksize != bh->b_size) { @@ -541,6 +562,7 @@ if (!silent) printk ("VFS: Unsupported blocksize on dev 0x%04x.\n", dev); + MOD_DEC_USE_COUNT; return NULL; } @@ -550,6 +572,7 @@ brelse (bh); printk ("EXT2-fs: fragsize %lu != blocksize %lu (not supported yet)\n", sb->u.ext2_sb.s_frag_size, sb->s_blocksize); + MOD_DEC_USE_COUNT; return NULL; } @@ -565,6 +588,7 @@ unlock_super (sb); brelse (bh); printk ("EXT2-fs: not enough memory\n"); + MOD_DEC_USE_COUNT; return NULL; } for (i = 0; i < db_count; i++) { @@ -579,6 +603,7 @@ db_count * sizeof (struct buffer_head *)); brelse (bh); printk ("EXT2-fs: unable to read group descriptors\n"); + MOD_DEC_USE_COUNT; return NULL; } } @@ -591,6 +616,7 @@ db_count * sizeof (struct buffer_head *)); brelse (bh); printk ("EXT2-fs: group descriptors corrupted !\n"); + MOD_DEC_USE_COUNT; return NULL; } for (i = 0; i < EXT2_MAX_GROUP_LOADED; i++) { @@ -617,6 +643,7 @@ db_count * sizeof (struct buffer_head *)); brelse (bh); printk ("EXT2-fs: get root inode failed\n"); + MOD_DEC_USE_COUNT; return NULL; } #ifdef EXT2FS_PRE_02B_COMPAT @@ -753,3 +780,24 @@ put_fs_long (EXT2_NAME_LEN, &buf->f_namelen); /* Don't know what value to put in buf->f_fsid */ } + +#ifdef MODULE + +char kernel_version[] = UTS_RELEASE; + +static struct file_system_type ext2_fs_type = { + ext2_read_super, "ext2", 1, NULL +}; + +int init_module(void) +{ + register_filesystem(&ext2_fs_type); + return 0; +} + +void cleanup_module(void) +{ + unregister_filesystem(&ext2_fs_type); +} + +#endif diff -r --unified -H linux.orig/fs/ext2/symlink.c linux/fs/ext2/symlink.c --- linux.orig/fs/ext2/symlink.c Mon Aug 15 15:53:48 1994 +++ linux/fs/ext2/symlink.c Sat Feb 4 18:28:44 1995 @@ -14,6 +14,10 @@ * ext2 symlink handling code */ +#ifdef MODULE +#include +#endif + #include #include diff -r --unified -H linux.orig/fs/ext2/truncate.c linux/fs/ext2/truncate.c --- linux.orig/fs/ext2/truncate.c Fri Aug 19 13:42:54 1994 +++ linux/fs/ext2/truncate.c Sat Feb 4 18:29:04 1995 @@ -17,6 +17,10 @@ * Idea from Pierre del Perugia */ +#ifdef MODULE +#include +#endif + #include #include #include diff -r --unified -H linux.orig/fs/hpfs/Makefile linux/fs/hpfs/Makefile --- linux.orig/fs/hpfs/Makefile Wed Dec 1 14:44:15 1993 +++ linux/fs/hpfs/Makefile Sat Feb 4 14:45:38 1995 @@ -22,6 +22,8 @@ dep: $(CPP) -M *.c > .depend +modules: hpfs.o + # # include a dependency file if one exists # diff -r --unified -H linux.orig/fs/hpfs/hpfs_fs.c linux/fs/hpfs/hpfs_fs.c --- linux.orig/fs/hpfs/hpfs_fs.c Wed Oct 19 10:23:18 1994 +++ linux/fs/hpfs/hpfs_fs.c Sat Feb 4 18:37:20 1995 @@ -12,6 +12,16 @@ * linux/fs/isofs Copyright (C) 1991 Eric Youngdale */ +/* Modular HPFS */ +#ifdef MODULE +#include +#include +#else +#define MOD_INC_USE_COUNT +#define MOD_DEC_USE_COUNT +#endif + + #include #include #include @@ -360,7 +370,7 @@ /* * Fill in the super block struct */ - + MOD_INC_USE_COUNT; lock_super(s); dev = s->s_dev; set_blocksize(dev, 512); @@ -485,6 +495,7 @@ if (!s->s_mounted) { printk("HPFS: hpfs_read_super: inode get failed\n"); s->s_dev = 0; + MOD_DEC_USE_COUNT; return 0; } @@ -499,6 +510,7 @@ printk("HPFS: " "hpfs_read_super: root dir isn't in the root dir\n"); s->s_dev = 0; + MOD_DEC_USE_COUNT; return 0; } @@ -518,6 +530,7 @@ bail: s->s_dev = 0; unlock_super(s); + MOD_DEC_USE_COUNT; return 0; } @@ -719,6 +732,7 @@ lock_super(s); s->s_dev = 0; unlock_super(s); + MOD_DEC_USE_COUNT; } /* @@ -1725,3 +1739,28 @@ brelse(qbh->bh[0]); kfree_s(qbh->data, 2048); } + + + +#ifdef MODULE + +/* Now register the hpfs filesystem to kernel when using modules */ + +char kernel_version[] = UTS_RELEASE; + +static struct file_system_type hpfs_fs_type = { + hpfs_read_super, "hpfs", 1, NULL +}; + +int init_module(void) +{ + register_filesystem(&hpfs_fs_type); + return 0; +} + +void cleanup_module(void) +{ + unregister_filesystem(&hpfs_fs_type); +} + +#endif