2002-03-13 00:16:07

by Brian Gerst

[permalink] [raw]
Subject: [PATCH] struct super_block cleanup - ext2

diff -urN linux/fs/ext2/super.c linux2/fs/ext2/super.c
--- linux/fs/ext2/super.c Tue Mar 12 18:02:43 2002
+++ linux2/fs/ext2/super.c Tue Mar 12 18:36:06 2002
@@ -146,6 +146,8 @@
if (sbi->s_block_bitmap[i])
brelse (sbi->s_block_bitmap[i]);
brelse (sbi->s_sbh);
+ sb->u.generic_sbp = NULL;
+ kfree(sbi);

return;
}
@@ -463,7 +465,11 @@
int db_count;
int i, j;

- sbi = EXT2_SB(sb);
+ sbi = kmalloc(sizeof(struct ext2_super_block), GFP_KERNEL);
+ if (!sbi)
+ return -ENOMEM;
+ sb->u.generic_sbp = sbi;
+
/*
* See what the current blocksize for the device is, and
* use that as the blocksize. Otherwise (or if the blocksize
@@ -475,12 +481,12 @@
sbi->s_mount_opt = 0;
if (!parse_options ((char *) data, &sb_block, &resuid, &resgid,
&sbi->s_mount_opt))
- return -EINVAL;
+ goto failed_sbi;

blocksize = sb_min_blocksize(sb, BLOCK_SIZE);
if (!blocksize) {
printk ("EXT2-fs: unable to set blocksize\n");
- return -EINVAL;
+ goto failed_sbi;
}

/*
@@ -495,7 +501,7 @@

if (!(bh = sb_bread(sb, logic_sb_block))) {
printk ("EXT2-fs: unable to read superblock\n");
- return -EINVAL;
+ goto failed_sbi;
}
/*
* Note: s_es must be initialized as soon as possible because
@@ -541,7 +547,7 @@

if (!sb_set_blocksize(sb, blocksize)) {
printk(KERN_ERR "EXT2-fs: blocksize too small for device.\n");
- return -EINVAL;
+ goto failed_sbi;
}

logic_sb_block = (sb_block*BLOCK_SIZE) / blocksize;
@@ -699,6 +705,9 @@
kfree(sbi->s_group_desc);
failed_mount:
brelse(bh);
+failed_sbi:
+ sb->u.generic_sbp = NULL;
+ kfree(sbi);
return -EINVAL;
}

diff -urN linux/include/linux/ext2_fs.h linux2/include/linux/ext2_fs.h
--- linux/include/linux/ext2_fs.h Tue Mar 12 18:27:00 2002
+++ linux2/include/linux/ext2_fs.h Tue Mar 12 18:46:47 2002
@@ -17,6 +17,7 @@
#define _LINUX_EXT2_FS_H

#include <linux/types.h>
+#include <linux/ext2_fs_sb.h>

/*
* The second extended filesystem constants/structures
@@ -73,7 +74,7 @@
#ifdef __KERNEL__
static inline struct ext2_sb_info *EXT2_SB(struct super_block *sb)
{
- return &sb->u.ext2_sb;
+ return sb->u.generic_sbp;
}
#else
/* Assume that user mode programs are passing in an ext2fs superblock, not
diff -urN linux/include/linux/fs.h linux2/include/linux/fs.h
--- linux/include/linux/fs.h Tue Mar 12 18:26:56 2002
+++ linux2/include/linux/fs.h Tue Mar 12 18:41:11 2002
@@ -648,7 +648,6 @@
#define MNT_FORCE 0x00000001 /* Attempt to forcibily umount */
#define MNT_DETACH 0x00000002 /* Just detach from the tree */

-#include <linux/ext2_fs_sb.h>
#include <linux/ext3_fs_sb.h>
#include <linux/hpfs_fs_sb.h>
#include <linux/ntfs_fs_sb.h>
@@ -704,7 +703,6 @@
char s_id[32]; /* Informational name */

union {
- struct ext2_sb_info ext2_sb;
struct ext3_sb_info ext3_sb;
struct hpfs_sb_info hpfs_sb;
struct ntfs_sb_info ntfs_sb;


Attachments:
sb-ext2-a1 (29.58 kB)
sb-ext2-b1 (2.80 kB)
Download all attachments