patch-2.4.10 linux/fs/minix/inode.c

Next file: linux/fs/minix/itree_common.c
Previous file: linux/fs/minix/file.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.4.9/linux/fs/minix/inode.c linux/fs/minix/inode.c
@@ -11,23 +11,15 @@
 
 #include <linux/module.h>
 
-#include <linux/sched.h>
-#include <linux/kernel.h>
-#include <linux/mm.h>
+#include <linux/fs.h>
+#include <linux/minix_fs.h>
 #include <linux/slab.h>
-#include <linux/string.h>
-#include <linux/stat.h>
 #include <linux/locks.h>
 #include <linux/init.h>
 #include <linux/smp_lock.h>
 #include <linux/highuid.h>
 #include <linux/blkdev.h>
 
-#include <asm/system.h>
-#include <asm/bitops.h>
-
-#include <linux/minix_fs.h>
-
 static void minix_read_inode(struct inode * inode);
 static void minix_write_inode(struct inode * inode, int wait);
 static int minix_statfs(struct super_block *sb, struct statfs *buf);
@@ -127,48 +119,6 @@
 	return 0;
 }
 
-/*
- * Check the root directory of the filesystem to make sure
- * it really _is_ a Minix filesystem, and to check the size
- * of the directory entry.
- */
-static const char * minix_checkroot(struct super_block *s, struct inode *dir)
-{
-	struct buffer_head *bh;
-	struct minix_dir_entry *de;
-	const char * errmsg;
-	int dirsize;
-
-	if (!S_ISDIR(dir->i_mode))
-		return "root directory is not a directory";
-
-	bh = minix_bread(dir, 0, 0);
-	if (!bh)
-		return "unable to read root directory";
-
-	de = (struct minix_dir_entry *) bh->b_data;
-	errmsg = "bad root directory '.' entry";
-	dirsize = BLOCK_SIZE;
-	if (de->inode == MINIX_ROOT_INO && strcmp(de->name, ".") == 0) {
-		errmsg = "bad root directory '..' entry";
-		dirsize = 8;
-	}
-
-	while ((dirsize <<= 1) < BLOCK_SIZE) {
-		de = (struct minix_dir_entry *) (bh->b_data + dirsize);
-		if (de->inode != MINIX_ROOT_INO)
-			continue;
-		if (strcmp(de->name, ".."))
-			continue;
-		s->u.minix_sb.s_dirsize = dirsize;
-		s->u.minix_sb.s_namelen = dirsize - 2;
-		errmsg = NULL;
-		break;
-	}
-	brelse(bh);
-	return errmsg;
-}
-
 static struct super_block *minix_read_super(struct super_block *s, void *data,
 				     int silent)
 {
@@ -177,9 +127,9 @@
 	struct minix_super_block *ms;
 	int i, block;
 	kdev_t dev = s->s_dev;
-	const char * errmsg;
 	struct inode *root_inode;
 	unsigned int hblock;
+	struct minix_sb_info *sbi = &s->u.minix_sb;
 
 	/* N.B. These should be compile-time tests.
 	   Unfortunately that is impossible. */
@@ -197,104 +147,96 @@
 		goto out_bad_sb;
 
 	ms = (struct minix_super_block *) bh->b_data;
-	s->u.minix_sb.s_ms = ms;
-	s->u.minix_sb.s_sbh = bh;
-	s->u.minix_sb.s_mount_state = ms->s_state;
+	sbi->s_ms = ms;
+	sbi->s_sbh = bh;
+	sbi->s_mount_state = ms->s_state;
 	s->s_blocksize = BLOCK_SIZE;
 	s->s_blocksize_bits = BLOCK_SIZE_BITS;
-	s->u.minix_sb.s_ninodes = ms->s_ninodes;
-	s->u.minix_sb.s_nzones = ms->s_nzones;
-	s->u.minix_sb.s_imap_blocks = ms->s_imap_blocks;
-	s->u.minix_sb.s_zmap_blocks = ms->s_zmap_blocks;
-	s->u.minix_sb.s_firstdatazone = ms->s_firstdatazone;
-	s->u.minix_sb.s_log_zone_size = ms->s_log_zone_size;
-	s->u.minix_sb.s_max_size = ms->s_max_size;
+	sbi->s_ninodes = ms->s_ninodes;
+	sbi->s_nzones = ms->s_nzones;
+	sbi->s_imap_blocks = ms->s_imap_blocks;
+	sbi->s_zmap_blocks = ms->s_zmap_blocks;
+	sbi->s_firstdatazone = ms->s_firstdatazone;
+	sbi->s_log_zone_size = ms->s_log_zone_size;
+	sbi->s_max_size = ms->s_max_size;
 	s->s_magic = ms->s_magic;
 	if (s->s_magic == MINIX_SUPER_MAGIC) {
-		s->u.minix_sb.s_version = MINIX_V1;
-		s->u.minix_sb.s_dirsize = 16;
-		s->u.minix_sb.s_namelen = 14;
-		s->u.minix_sb.s_link_max = MINIX_LINK_MAX;
+		sbi->s_version = MINIX_V1;
+		sbi->s_dirsize = 16;
+		sbi->s_namelen = 14;
+		sbi->s_link_max = MINIX_LINK_MAX;
 	} else if (s->s_magic == MINIX_SUPER_MAGIC2) {
-		s->u.minix_sb.s_version = MINIX_V1;
-		s->u.minix_sb.s_dirsize = 32;
-		s->u.minix_sb.s_namelen = 30;
-		s->u.minix_sb.s_link_max = MINIX_LINK_MAX;
+		sbi->s_version = MINIX_V1;
+		sbi->s_dirsize = 32;
+		sbi->s_namelen = 30;
+		sbi->s_link_max = MINIX_LINK_MAX;
 	} else if (s->s_magic == MINIX2_SUPER_MAGIC) {
-		s->u.minix_sb.s_version = MINIX_V2;
-		s->u.minix_sb.s_nzones = ms->s_zones;
-		s->u.minix_sb.s_dirsize = 16;
-		s->u.minix_sb.s_namelen = 14;
-		s->u.minix_sb.s_link_max = MINIX2_LINK_MAX;
+		sbi->s_version = MINIX_V2;
+		sbi->s_nzones = ms->s_zones;
+		sbi->s_dirsize = 16;
+		sbi->s_namelen = 14;
+		sbi->s_link_max = MINIX2_LINK_MAX;
 	} else if (s->s_magic == MINIX2_SUPER_MAGIC2) {
-		s->u.minix_sb.s_version = MINIX_V2;
-		s->u.minix_sb.s_nzones = ms->s_zones;
-		s->u.minix_sb.s_dirsize = 32;
-		s->u.minix_sb.s_namelen = 30;
-		s->u.minix_sb.s_link_max = MINIX2_LINK_MAX;
+		sbi->s_version = MINIX_V2;
+		sbi->s_nzones = ms->s_zones;
+		sbi->s_dirsize = 32;
+		sbi->s_namelen = 30;
+		sbi->s_link_max = MINIX2_LINK_MAX;
 	} else
 		goto out_no_fs;
 
 	/*
 	 * Allocate the buffer map to keep the superblock small.
 	 */
-	i = (s->u.minix_sb.s_imap_blocks + s->u.minix_sb.s_zmap_blocks) * sizeof(bh);
+	i = (sbi->s_imap_blocks + sbi->s_zmap_blocks) * sizeof(bh);
 	map = kmalloc(i, GFP_KERNEL);
 	if (!map)
 		goto out_no_map;
 	memset(map, 0, i);
-	s->u.minix_sb.s_imap = &map[0];
-	s->u.minix_sb.s_zmap = &map[s->u.minix_sb.s_imap_blocks];
+	sbi->s_imap = &map[0];
+	sbi->s_zmap = &map[sbi->s_imap_blocks];
 
 	block=2;
-	for (i=0 ; i < s->u.minix_sb.s_imap_blocks ; i++) {
-		if (!(s->u.minix_sb.s_imap[i]=bread(dev,block,BLOCK_SIZE)))
+	for (i=0 ; i < sbi->s_imap_blocks ; i++) {
+		if (!(sbi->s_imap[i]=bread(dev,block,BLOCK_SIZE)))
 			goto out_no_bitmap;
 		block++;
 	}
-	for (i=0 ; i < s->u.minix_sb.s_zmap_blocks ; i++) {
-		if (!(s->u.minix_sb.s_zmap[i]=bread(dev,block,BLOCK_SIZE)))
+	for (i=0 ; i < sbi->s_zmap_blocks ; i++) {
+		if (!(sbi->s_zmap[i]=bread(dev,block,BLOCK_SIZE)))
 			goto out_no_bitmap;
 		block++;
 	}
 
-	minix_set_bit(0,s->u.minix_sb.s_imap[0]->b_data);
-	minix_set_bit(0,s->u.minix_sb.s_zmap[0]->b_data);
+	minix_set_bit(0,sbi->s_imap[0]->b_data);
+	minix_set_bit(0,sbi->s_zmap[0]->b_data);
 
 	/* set up enough so that it can read an inode */
 	s->s_op = &minix_sops;
 	root_inode = iget(s, MINIX_ROOT_INO);
 	if (!root_inode)
 		goto out_no_root;
-	/*
-	 * Check the fs before we get the root dentry ...
-	 */
-	errmsg = minix_checkroot(s, root_inode);
-	if (errmsg)
-		goto out_bad_root;
 
 	s->s_root = d_alloc_root(root_inode);
 	if (!s->s_root)
 		goto out_iput;
 
-	s->s_root->d_op = &minix_dentry_operations;
+	if (!NO_TRUNCATE)
+		s->s_root->d_op = &minix_dentry_operations;
 
 	if (!(s->s_flags & MS_RDONLY)) {
 		ms->s_state &= ~MINIX_VALID_FS;
 		mark_buffer_dirty(bh);
 		s->s_dirt = 1;
 	}
-	if (!(s->u.minix_sb.s_mount_state & MINIX_VALID_FS))
+	if (!(sbi->s_mount_state & MINIX_VALID_FS))
 		printk ("MINIX-fs: mounting unchecked file system, "
 			"running fsck is recommended.\n");
- 	else if (s->u.minix_sb.s_mount_state & MINIX_ERROR_FS)
+ 	else if (sbi->s_mount_state & MINIX_ERROR_FS)
 		printk ("MINIX-fs: mounting file system with errors, "
 			"running fsck is recommended.\n");
 	return s;
 
-out_bad_root:
-	if (!silent)
-		printk("MINIX-fs: %s\n", errmsg);
 out_iput:
 	iput(root_inode);
 	goto out_freemap;
@@ -307,11 +249,11 @@
 out_no_bitmap:
 	printk("MINIX-fs: bad superblock or unable to read bitmaps\n");
     out_freemap:
-	for (i = 0; i < s->u.minix_sb.s_imap_blocks; i++)
-		brelse(s->u.minix_sb.s_imap[i]);
-	for (i = 0; i < s->u.minix_sb.s_zmap_blocks; i++)
-		brelse(s->u.minix_sb.s_zmap[i]);
-	kfree(s->u.minix_sb.s_imap);
+	for (i = 0; i < sbi->s_imap_blocks; i++)
+		brelse(sbi->s_imap[i]);
+	for (i = 0; i < sbi->s_zmap_blocks; i++)
+		brelse(sbi->s_zmap[i]);
+	kfree(sbi->s_imap);
 	goto out_release;
 
 out_no_map:
@@ -359,45 +301,6 @@
 		return V2_minix_get_block(inode, block, bh_result, create);
 }
 
-/*
- * the global minix fs getblk function.
- */
-struct buffer_head *minix_getblk(struct inode *inode, int block, int create)
-{
-	struct buffer_head dummy;
-	int error;
-
-	dummy.b_state = 0;
-	dummy.b_blocknr = -1000;
-	error = minix_get_block(inode, block, &dummy, create);
-	if (!error && buffer_mapped(&dummy)) {
-		struct buffer_head *bh;
-		bh = getblk(dummy.b_dev, dummy.b_blocknr, BLOCK_SIZE);
-		if (buffer_new(&dummy)) {
-			memset(bh->b_data, 0, BLOCK_SIZE);
-			mark_buffer_uptodate(bh, 1);
-			mark_buffer_dirty(bh);
-		}
-		return bh;
-	}
-	return NULL;
-}
-
-struct buffer_head * minix_bread(struct inode * inode, int block, int create)
-{
-	struct buffer_head * bh;
-
-	bh = minix_getblk(inode, block, create);
-	if (!bh || buffer_uptodate(bh))
-		return bh;
-	ll_rw_block(READ, 1, &bh);
-	wait_on_buffer(bh);
-	if (buffer_uptodate(bh))
-		return bh;
-	brelse(bh);
-	return NULL;
-}
-
 static int minix_writepage(struct page *page)
 {
 	return block_write_full_page(page,minix_get_block);
@@ -414,7 +317,7 @@
 {
 	return generic_block_bmap(mapping,block,minix_get_block);
 }
-struct address_space_operations minix_aops = {
+static struct address_space_operations minix_aops = {
 	readpage: minix_readpage,
 	writepage: minix_writepage,
 	sync_page: block_sync_page,
@@ -423,6 +326,23 @@
 	bmap: minix_bmap
 };
 
+void minix_set_inode(struct inode *inode, dev_t rdev)
+{
+	if (S_ISREG(inode->i_mode)) {
+		inode->i_op = &minix_file_inode_operations;
+		inode->i_fop = &minix_file_operations;
+		inode->i_mapping->a_ops = &minix_aops;
+	} else if (S_ISDIR(inode->i_mode)) {
+		inode->i_op = &minix_dir_inode_operations;
+		inode->i_fop = &minix_dir_operations;
+		inode->i_mapping->a_ops = &minix_aops;
+	} else if (S_ISLNK(inode->i_mode)) {
+		inode->i_op = &page_symlink_inode_operations;
+		inode->i_mapping->a_ops = &minix_aops;
+	} else
+		init_special_inode(inode, inode->i_mode, rdev);
+}
+
 /*
  * The minix V1 function to read an inode.
  */
@@ -430,26 +350,11 @@
 {
 	struct buffer_head * bh;
 	struct minix_inode * raw_inode;
-	int block, ino;
+	int i;
 
-	ino = inode->i_ino;
-	inode->i_mode = 0;
-	if (!ino || ino > inode->i_sb->u.minix_sb.s_ninodes) {
-		printk("Bad inode number on dev %s"
-		       ": %d is out of range\n",
-			kdevname(inode->i_dev), ino);
+	raw_inode = minix_V1_raw_inode(inode->i_sb, inode->i_ino, &bh);
+	if (!raw_inode)
 		return;
-	}
-	block = 2 + inode->i_sb->u.minix_sb.s_imap_blocks +
-		    inode->i_sb->u.minix_sb.s_zmap_blocks +
-		    (ino-1)/MINIX_INODES_PER_BLOCK;
-	if (!(bh=bread(inode->i_dev,block, BLOCK_SIZE))) {
-		printk("Major problem: unable to read inode from dev "
-		       "%s\n", kdevname(inode->i_dev));
-		return;
-	}
-	raw_inode = ((struct minix_inode *) bh->b_data) +
-		    (ino-1)%MINIX_INODES_PER_BLOCK;
 	inode->i_mode = raw_inode->i_mode;
 	inode->i_uid = (uid_t)raw_inode->i_uid;
 	inode->i_gid = (gid_t)raw_inode->i_gid;
@@ -457,20 +362,9 @@
 	inode->i_size = raw_inode->i_size;
 	inode->i_mtime = inode->i_atime = inode->i_ctime = raw_inode->i_time;
 	inode->i_blocks = inode->i_blksize = 0;
-	for (block = 0; block < 9; block++)
-		inode->u.minix_i.u.i1_data[block] = raw_inode->i_zone[block];
-	if (S_ISREG(inode->i_mode)) {
-		inode->i_op = &minix_file_inode_operations;
-		inode->i_fop = &minix_file_operations;
-		inode->i_mapping->a_ops = &minix_aops;
-	} else if (S_ISDIR(inode->i_mode)) {
-		inode->i_op = &minix_dir_inode_operations;
-		inode->i_fop = &minix_dir_operations;
-	} else if (S_ISLNK(inode->i_mode)) {
-		inode->i_op = &page_symlink_inode_operations;
-		inode->i_mapping->a_ops = &minix_aops;
-	} else
-		init_special_inode(inode, inode->i_mode, raw_inode->i_zone[0]);
+	for (i = 0; i < 9; i++)
+		inode->u.minix_i.u.i1_data[i] = raw_inode->i_zone[i];
+	minix_set_inode(inode, raw_inode->i_zone[0]);
 	brelse(bh);
 }
 
@@ -481,26 +375,11 @@
 {
 	struct buffer_head * bh;
 	struct minix2_inode * raw_inode;
-	int block, ino;
+	int i;
 
-	ino = inode->i_ino;
-	inode->i_mode = 0;
-	if (!ino || ino > inode->i_sb->u.minix_sb.s_ninodes) {
-		printk("Bad inode number on dev %s"
-		       ": %d is out of range\n",
-			kdevname(inode->i_dev), ino);
-		return;
-	}
-	block = 2 + inode->i_sb->u.minix_sb.s_imap_blocks +
-		    inode->i_sb->u.minix_sb.s_zmap_blocks +
-		    (ino-1)/MINIX2_INODES_PER_BLOCK;
-	if (!(bh=bread(inode->i_dev,block, BLOCK_SIZE))) {
-		printk("Major problem: unable to read inode from dev "
-		       "%s\n", kdevname(inode->i_dev));
+	raw_inode = minix_V2_raw_inode(inode->i_sb, inode->i_ino, &bh);
+	if (!raw_inode)
 		return;
-	}
-	raw_inode = ((struct minix2_inode *) bh->b_data) +
-		    (ino-1)%MINIX2_INODES_PER_BLOCK;
 	inode->i_mode = raw_inode->i_mode;
 	inode->i_uid = (uid_t)raw_inode->i_uid;
 	inode->i_gid = (gid_t)raw_inode->i_gid;
@@ -510,20 +389,9 @@
 	inode->i_atime = raw_inode->i_atime;
 	inode->i_ctime = raw_inode->i_ctime;
 	inode->i_blocks = inode->i_blksize = 0;
-	for (block = 0; block < 10; block++)
-		inode->u.minix_i.u.i2_data[block] = raw_inode->i_zone[block];
-	if (S_ISREG(inode->i_mode)) {
-		inode->i_op = &minix_file_inode_operations;
-		inode->i_fop = &minix_file_operations;
-		inode->i_mapping->a_ops = &minix_aops;
-	} else if (S_ISDIR(inode->i_mode)) {
-		inode->i_op = &minix_dir_inode_operations;
-		inode->i_fop = &minix_dir_operations;
-	} else if (S_ISLNK(inode->i_mode)) {
-		inode->i_op = &page_symlink_inode_operations;
-		inode->i_mapping->a_ops = &minix_aops;
-	} else
-		init_special_inode(inode, inode->i_mode, raw_inode->i_zone[0]);
+	for (i = 0; i < 10; i++)
+		inode->u.minix_i.u.i2_data[i] = raw_inode->i_zone[i];
+	minix_set_inode(inode, raw_inode->i_zone[0]);
 	brelse(bh);
 }
 
@@ -545,23 +413,11 @@
 {
 	struct buffer_head * bh;
 	struct minix_inode * raw_inode;
-	int ino, block;
+	int i;
 
-	ino = inode->i_ino;
-	if (!ino || ino > inode->i_sb->u.minix_sb.s_ninodes) {
-		printk("Bad inode number on dev %s"
-		       ": %d is out of range\n",
-			kdevname(inode->i_dev), ino);
-		return 0;
-	}
-	block = 2 + inode->i_sb->u.minix_sb.s_imap_blocks + inode->i_sb->u.minix_sb.s_zmap_blocks +
-		(ino-1)/MINIX_INODES_PER_BLOCK;
-	if (!(bh=bread(inode->i_dev, block, BLOCK_SIZE))) {
-		printk("unable to read i-node block\n");
+	raw_inode = minix_V1_raw_inode(inode->i_sb, inode->i_ino, &bh);
+	if (!raw_inode)
 		return 0;
-	}
-	raw_inode = ((struct minix_inode *)bh->b_data) +
-		(ino-1)%MINIX_INODES_PER_BLOCK;
 	raw_inode->i_mode = inode->i_mode;
 	raw_inode->i_uid = fs_high2lowuid(inode->i_uid);
 	raw_inode->i_gid = fs_high2lowgid(inode->i_gid);
@@ -570,8 +426,8 @@
 	raw_inode->i_time = inode->i_mtime;
 	if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
 		raw_inode->i_zone[0] = kdev_t_to_nr(inode->i_rdev);
-	else for (block = 0; block < 9; block++)
-		raw_inode->i_zone[block] = inode->u.minix_i.u.i1_data[block];
+	else for (i = 0; i < 9; i++)
+		raw_inode->i_zone[i] = inode->u.minix_i.u.i1_data[i];
 	mark_buffer_dirty(bh);
 	return bh;
 }
@@ -583,23 +439,11 @@
 {
 	struct buffer_head * bh;
 	struct minix2_inode * raw_inode;
-	int ino, block;
+	int i;
 
-	ino = inode->i_ino;
-	if (!ino || ino > inode->i_sb->u.minix_sb.s_ninodes) {
-		printk("Bad inode number on dev %s"
-		       ": %d is out of range\n",
-			kdevname(inode->i_dev), ino);
+	raw_inode = minix_V2_raw_inode(inode->i_sb, inode->i_ino, &bh);
+	if (!raw_inode)
 		return 0;
-	}
-	block = 2 + inode->i_sb->u.minix_sb.s_imap_blocks + inode->i_sb->u.minix_sb.s_zmap_blocks +
-		(ino-1)/MINIX2_INODES_PER_BLOCK;
-	if (!(bh=bread(inode->i_dev, block, BLOCK_SIZE))) {
-		printk("unable to read i-node block\n");
-		return 0;
-	}
-	raw_inode = ((struct minix2_inode *)bh->b_data) +
-		(ino-1)%MINIX2_INODES_PER_BLOCK;
 	raw_inode->i_mode = inode->i_mode;
 	raw_inode->i_uid = fs_high2lowuid(inode->i_uid);
 	raw_inode->i_gid = fs_high2lowgid(inode->i_gid);
@@ -610,8 +454,8 @@
 	raw_inode->i_ctime = inode->i_ctime;
 	if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode))
 		raw_inode->i_zone[0] = kdev_t_to_nr(inode->i_rdev);
-	else for (block = 0; block < 10; block++)
-		raw_inode->i_zone[block] = inode->u.minix_i.u.i2_data[block];
+	else for (i = 0; i < 10; i++)
+		raw_inode->i_zone[i] = inode->u.minix_i.u.i2_data[i];
 	mark_buffer_dirty(bh);
 	return bh;
 }

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)