[PATCH/RFC] minix filesystem: V3 update for kernels 2.4.x

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Answering the suggestion from Pekka, here comes the separated version for 2.4.x


diff -ur orig.linux-2.4.32/fs/minix/bitmap.c updated.linux-2.4.32/fs/minix/bitmap.c
--- orig.linux-2.4.32/fs/minix/bitmap.c	2002-02-25 20:38:09.000000000 +0100
+++ updated.linux-2.4.32/fs/minix/bitmap.c	2006-01-14 20:57:54.000000000 +0100
@@ -27,14 +27,14 @@
 	for (i=0; i<numblocks-1; i++) {
 		if (!(bh=map[i])) 
 			return(0);
-		for (j=0; j<BLOCK_SIZE; j++)
+		for (j=0; j<bh->b_size; j++)
 			sum += nibblemap[bh->b_data[j] & 0xf]
 				+ nibblemap[(bh->b_data[j]>>4) & 0xf];
 	}
 
 	if (numblocks==0 || !(bh=map[numblocks-1]))
 		return(0);
-	i = ((numbits-(numblocks-1)*BLOCK_SIZE*8)/16)*2;
+	i = ((numbits-(numblocks-1)*bh->b_size*8)/16)*2;
 	for (j=0; j<i; j++) {
 		sum += nibblemap[bh->b_data[j] & 0xf]
 			+ nibblemap[(bh->b_data[j]>>4) & 0xf];
@@ -157,14 +157,14 @@
 	}
 	ino--;
 	block = 2 + sbi->s_imap_blocks + sbi->s_zmap_blocks +
-		 ino / MINIX2_INODES_PER_BLOCK;
+		 ino / MINIX2_INODES_PER_BLOCK(sb->s_blocksize);
 	*bh = sb_bread(sb, block);
 	if (!*bh) {
 		printk("unable to read i-node block\n");
 		return NULL;
 	}
 	p = (void *)(*bh)->b_data;
-	return p + ino % MINIX2_INODES_PER_BLOCK;
+	return p + ino % MINIX2_INODES_PER_BLOCK(sb->s_blocksize);
 }
 
 /* Clear the link count and mode of a deleted inode on disk. */
diff -ur orig.linux-2.4.32/fs/minix/dir.c updated.linux-2.4.32/fs/minix/dir.c
--- orig.linux-2.4.32/fs/minix/dir.c	2002-02-25 20:38:09.000000000 +0100
+++ updated.linux-2.4.32/fs/minix/dir.c	2006-01-14 20:57:54.000000000 +0100
@@ -4,6 +4,9 @@
  *  Copyright (C) 1991, 1992 Linus Torvalds
  *
  *  minix directory handling functions
+ *
+ *  Updated to filesystem version 3 by Daniel Aragones
+ *
  */
 
 #include <linux/fs.h>
@@ -11,6 +14,7 @@
 #include <linux/pagemap.h>
 
 typedef struct minix_dir_entry minix_dirent;
+typedef struct minix3_dir_entry minix3_dirent;
 
 static int minix_readdir(struct file *, void *, filldir_t);
 
@@ -95,14 +99,22 @@
 		limit = kaddr + PAGE_CACHE_SIZE - chunk_size;
 		for ( ; p <= limit ; p = minix_next_entry(p, sbi)) {
 			minix_dirent *de = (minix_dirent *)p;
+			minix3_dirent *de3 = (minix3_dirent *)p;
 			if (de->inode) {
 				int over;
-				unsigned l = strnlen(de->name,sbi->s_namelen);
-
-				offset = p - kaddr;
-				over = filldir(dirent, de->name, l,
-						(n<<PAGE_CACHE_SHIFT) | offset,
-						de->inode, DT_UNKNOWN);
+				if (!(sbi->s_version == MINIX_V3)) {
+					unsigned l = strnlen(de->name,sbi->s_namelen);
+					offset = p - kaddr;
+					over = filldir(dirent, de->name, l,
+					(n<<PAGE_CACHE_SHIFT) | offset,
+					de->inode, DT_UNKNOWN);
+				} else {
+					unsigned l = strnlen(de3->name,sbi->s_namelen);
+					offset = p - kaddr;
+					over = filldir(dirent, de3->name, l,
+					(n<<PAGE_CACHE_SHIFT) | offset,
+					de3->inode, DT_UNKNOWN);
+				}
 				if (over) {
 					dir_put_page(page);
 					goto done;
@@ -145,7 +157,7 @@
 	unsigned long npages = dir_pages(dir);
 	struct page *page = NULL;
 	struct minix_dir_entry *de;
-
+	struct minix3_dir_entry *de3;
 	*res_page = NULL;
 
 	for (n = 0; n < npages; n++) {
@@ -156,12 +168,22 @@
 
 		kaddr = (char*)page_address(page);
 		de = (struct minix_dir_entry *) kaddr;
+		de3 = (struct minix3_dir_entry *) kaddr;
 		kaddr += PAGE_CACHE_SIZE - sbi->s_dirsize;
-		for ( ; (char *) de <= kaddr ; de = minix_next_entry(de,sbi)) {
-			if (!de->inode)
-				continue;
-			if (namecompare(namelen,sbi->s_namelen,name,de->name))
-				goto found;
+		for ( ; (char *) de <= kaddr ;
+					de = minix_next_entry(de,sbi),
+					de3 = minix_next_entry(de3,sbi)) {
+			if (!(sbi->s_version == MINIX_V3)) {
+				if (!de->inode)
+					continue;
+				if (namecompare(namelen,sbi->s_namelen,name,de->name))
+					goto found; 		
+			} else {
+				if (!de3->inode)
+					continue;
+				if (namecompare(namelen,sbi->s_namelen,name,de3->name))
+					goto found;
+			}
 		}
 		dir_put_page(page);
 	}
@@ -181,6 +203,7 @@
 	struct minix_sb_info * sbi = &sb->u.minix_sb;
 	struct page *page = NULL;
 	struct minix_dir_entry * de;
+	struct minix3_dir_entry * de3;
 	unsigned long npages = dir_pages(dir);
 	unsigned long n;
 	char *kaddr;
@@ -195,14 +218,22 @@
 			goto out;
 		kaddr = (char*)page_address(page);
 		de = (minix_dirent *)kaddr;
+		de3 = (minix3_dirent *)kaddr;
 		kaddr += PAGE_CACHE_SIZE - sbi->s_dirsize;
 		while ((char *)de <= kaddr) {
 			if (!de->inode)
 				goto got_it;
 			err = -EEXIST;
-			if (namecompare(namelen,sbi->s_namelen,name,de->name))
-				goto out_page;
-			de = minix_next_entry(de, sbi);
+			if (!(sbi->s_version == MINIX_V3)) {
+				if (namecompare(namelen,sbi->s_namelen,name,de->name)) 		
+					goto out_page;
+ 				de = minix_next_entry(de, sbi);
+			} else {
+				if (namecompare(namelen,sbi->s_namelen,name,de3->name))
+					goto out_unlock;
+				de = minix_next_entry(de, sbi);
+				de3 = minix_next_entry(de3, sbi);
+			}
 		}
 		dir_put_page(page);
 	}
@@ -216,9 +247,15 @@
 	err = page->mapping->a_ops->prepare_write(NULL, page, from, to);
 	if (err)
 		goto out_unlock;
-	memcpy (de->name, name, namelen);
-	memset (de->name + namelen, 0, sbi->s_dirsize - namelen - 2);
-	de->inode = inode->i_ino;
+		if (!(sbi->s_version == MINIX_V3)) {
+		memcpy (de->name, name, namelen);
+		memset (de->name + namelen, 0, sbi->s_dirsize - namelen - 2);
+		de->inode = inode->i_ino;
+		} else {
+		memcpy (de3->name, name, namelen);
+		memset (de3->name + namelen, 0, sbi->s_dirsize - namelen - 4);
+		de3->inode = inode->i_ino;
+		}
 	err = dir_commit_chunk(page, from, to);
 	dir->i_mtime = dir->i_ctime = CURRENT_TIME;
 	mark_inode_dirty(dir);
@@ -258,6 +295,7 @@
 	struct page *page = grab_cache_page(mapping, 0);
 	struct minix_sb_info * sbi = &inode->i_sb->u.minix_sb;
 	struct minix_dir_entry * de;
+	struct minix3_dir_entry * de3;
 	char *base;
 	int err;
 
@@ -269,13 +307,14 @@
 
 	base = (char*)page_address(page);
 	memset(base, 0, PAGE_CACHE_SIZE);
-
-	de = (struct minix_dir_entry *) base;
-	de->inode = inode->i_ino;
-	strcpy(de->name,".");
+	de = (struct minix_dir_entry *)base;
+	de3 = (struct minix3_dir_entry *)base;
+	de->inode = de3->inode = inode->i_ino;
+	(sbi->s_version == MINIX_V3) ? strcpy(de3->name,".") : strcpy(de->name,".");
 	de = minix_next_entry(de, sbi);
-	de->inode = dir->i_ino;
-	strcpy(de->name,"..");
+	de3 = minix_next_entry(de3, sbi);
+	de->inode = de3->inode = dir->i_ino;
+	(sbi->s_version == MINIX_V3) ? strcpy(de3->name,"..") : strcpy(de->name,"..");
 
 	err = dir_commit_chunk(page, 0, 2 * sbi->s_dirsize);
 fail:
@@ -296,27 +335,42 @@
 	for (i = 0; i < npages; i++) {
 		char *kaddr;
 		minix_dirent * de;
+		minix3_dirent * de3 = NULL;
 		page = dir_get_page(inode, i);
 
 		if (IS_ERR(page))
 			continue;
 
 		kaddr = (char *)page_address(page);
+		if (sbi->s_version == MINIX_V3)
+			de3 = (minix3_dirent *)kaddr;
 		de = (minix_dirent *)kaddr;
 		kaddr += PAGE_CACHE_SIZE - sbi->s_dirsize;
 
 		while ((char *)de <= kaddr) {
 			if (de->inode != 0) {
 				/* check for . and .. */
-				if (de->name[0] != '.')
-					goto not_empty;
-				if (!de->name[1]) {
-					if (de->inode != inode->i_ino)
+				if (!(sbi->s_version == MINIX_V3)) {
+					if (de->name[0] != '.')
+						goto not_empty;
+					if (!de->name[1]) {
+						if (de->inode != inode->i_ino)
+							goto not_empty;
+					} else if (de->name[1] != '.')
+						goto not_empty;
+					else if (de->name[2])
 						goto not_empty;
-				} else if (de->name[1] != '.')
-					goto not_empty;
-				else if (de->name[2])
-					goto not_empty;
+				} else {
+					if (de3->name[0] != '.')
+						goto not_empty;
+					if (!de3->name[1]) {
+						if (de3->inode != inode->i_ino)
+							goto not_empty;
+					} else if (de3->name[1] != '.')
+						goto not_empty;
+					else if (de3->name[2])
+						goto not_empty;
+				}
 			}
 			de = minix_next_entry(de, sbi);
 		}
diff -ur orig.linux-2.4.32/fs/minix/inode.c updated.linux-2.4.32/fs/minix/inode.c
--- orig.linux-2.4.32/fs/minix/inode.c	2003-11-28 19:26:21.000000000 +0100
+++ updated.linux-2.4.32/fs/minix/inode.c	2006-01-14 20:57:55.000000000 +0100
@@ -7,6 +7,7 @@
  *	Minix V2 fs support.
  *
  *  Modified for 680x0 by Andreas Schwab
+ *  Updated to filesystem version 3 by Daniel Aragones
  */
 
 #include <linux/module.h>
@@ -28,7 +29,7 @@
 static void minix_delete_inode(struct inode *inode)
 {
 	lock_kernel();
-
+	truncate_inode_pages(&inode->i_data, 0);
 	inode->i_size = 0;
 	minix_truncate(inode);
 	minix_free_inode(inode);
@@ -45,23 +46,24 @@
 static void minix_write_super(struct super_block * sb)
 {
 	struct minix_super_block * ms;
+	struct minix_sb_info *sbi = &sb->u.minix_sb;
 
 	if (!(sb->s_flags & MS_RDONLY)) {
 		ms = sb->u.minix_sb.s_ms;
-
-		if (ms->s_state & MINIX_VALID_FS)
-			ms->s_state &= ~MINIX_VALID_FS;
-		minix_commit_super(sb);
+		if (sbi->s_version != MINIX_V3) { /* s_state is out from V3 sb */
+			if (ms->s_state & MINIX_VALID_FS)
+				ms->s_state &= ~MINIX_VALID_FS;
+			minix_commit_super(sb);
+		}
 	}
 	sb->s_dirt = 0;
 }
 
-
 static void minix_put_super(struct super_block *sb)
 {
 	int i;
-
-	if (!(sb->s_flags & MS_RDONLY)) {
+	struct minix_sb_info *sbi = &sb->u.minix_sb;
+	if (!(sb->s_flags & MS_RDONLY) && (sbi->s_version != MINIX_V3)) {
 		sb->u.minix_sb.s_ms->s_state = sb->u.minix_sb.s_mount_state;
 		mark_buffer_dirty(sb->u.minix_sb.s_sbh);
 	}
@@ -88,11 +90,12 @@
 static int minix_remount (struct super_block * sb, int * flags, char * data)
 {
 	struct minix_super_block * ms;
+	struct minix_sb_info *sbi = &sb->u.minix_sb;
 
 	ms = sb->u.minix_sb.s_ms;
 	if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
 		return 0;
-	if (*flags & MS_RDONLY) {
+	if ((*flags & MS_RDONLY) && (sbi->s_version != MINIX_V3)){
 		if (ms->s_state & MINIX_VALID_FS ||
 		    !(sb->u.minix_sb.s_mount_state & MINIX_VALID_FS))
 			return 0;
@@ -102,20 +105,21 @@
 		sb->s_dirt = 1;
 		minix_commit_super(sb);
 	}
-	else {
+	else if (sbi->s_version != MINIX_V3){
 	  	/* Mount a partition which is read-only, read-write. */
 		sb->u.minix_sb.s_mount_state = ms->s_state;
 		ms->s_state &= ~MINIX_VALID_FS;
 		mark_buffer_dirty(sb->u.minix_sb.s_sbh);
 		sb->s_dirt = 1;
+		}
+
+		if (!(sb->u.minix_sb.s_mount_state & MINIX_VALID_FS) && (sbi->s_version != MINIX_V3))
+			printk ("MINIX-fs warning: remounting unchecked Minix filesystem V%i, "
+				"running fsck is recommended.\n", sbi->s_version);
+		else if ((sb->u.minix_sb.s_mount_state & MINIX_ERROR_FS) && (sbi->s_version != MINIX_V3))
+			printk ("MINIX-fs warning: remounting Minix filesystem V%i with errors, "
+				"running fsck is recommended.\n", sbi->s_version);
 
-		if (!(sb->u.minix_sb.s_mount_state & MINIX_VALID_FS))
-			printk ("MINIX-fs warning: remounting unchecked fs, "
-				"running fsck is recommended.\n");
-		else if ((sb->u.minix_sb.s_mount_state & MINIX_ERROR_FS))
-			printk ("MINIX-fs warning: remounting fs with errors, "
-				"running fsck is recommended.\n");
-	}
 	return 0;
 }
 
@@ -182,6 +186,23 @@
 		sbi->s_dirsize = 32;
 		sbi->s_namelen = 30;
 		sbi->s_link_max = MINIX2_LINK_MAX;
+	} else if ( *(__u16 *)(bh->b_data + 24) == MINIX3_SUPER_MAGIC) {
+
+		s->s_magic = MINIX3_SUPER_MAGIC;
+		sbi->s_imap_blocks = *(__u16 *)(bh->b_data + 6);
+		sbi->s_zmap_blocks = *(__u16 *)(bh->b_data + 8);
+		sbi->s_firstdatazone = *(__u16 *)(bh->b_data + 10);
+		sbi->s_log_zone_size = *(__u16 *)(bh->b_data + 12);
+		sbi->s_max_size = *(__u32 *)(bh->b_data + 16);
+		sbi->s_nzones = *(__u32 *)(bh->b_data + 20);
+		sbi->s_dirsize = 64;
+		sbi->s_namelen = 60;
+		sbi->s_version = MINIX_V3;
+		sbi->s_link_max = MINIX2_LINK_MAX;
+			if ( *(__u16 *)(bh->b_data + 28) != 1024) {
+				if (!sb_set_blocksize(s,( *(__u16 *)(bh->b_data + 28))))
+ 				goto out_bad_hblock;
+		}
 	} else
 		goto out_no_fs;
 
@@ -224,17 +245,17 @@
 	if (!NO_TRUNCATE)
 		s->s_root->d_op = &minix_dentry_operations;
 
-	if (!(s->s_flags & MS_RDONLY)) {
-		ms->s_state &= ~MINIX_VALID_FS;
+	if (!(s->s_flags & MS_RDONLY) && (sbi->s_version != MINIX_V3)) {
+		ms->s_state &= ~MINIX_VALID_FS; /* s_state is out from V3 sb */
 		mark_buffer_dirty(bh);
 		s->s_dirt = 1;
 	}
-	if (!(sbi->s_mount_state & MINIX_VALID_FS))
-		printk ("MINIX-fs: mounting unchecked file system, "
-			"running fsck is recommended.\n");
- 	else if (sbi->s_mount_state & MINIX_ERROR_FS)
-		printk ("MINIX-fs: mounting file system with errors, "
-			"running fsck is recommended.\n");
+	if (!(sbi->s_mount_state & MINIX_VALID_FS) && (sbi->s_version != MINIX_V3))
+		printk ("MINIX-fs: mounting unchecked Minix filesystem V%i, "
+			"running fsck is recommended.\n", sbi->s_version);
+ 	else if ((sbi->s_mount_state & MINIX_ERROR_FS) && (sbi->s_version != MINIX_V3))
+		printk ("MINIX-fs: mounting Minix filesystem V%i with errors, "
+			"running fsck is recommended.\n", sbi->s_version);
 	return s;
 
 out_iput:
@@ -263,7 +284,7 @@
 
 out_no_fs:
 	if (!silent)
-		printk("VFS: Can't find a Minix or Minix V2 filesystem on device "
+		printk("VFS: Can't find a Minix filesystem V1 | V2 | V3 on device "
 		       "%s.\n", kdevname(dev));
     out_release:
 	brelse(bh);
diff -ur orig.linux-2.4.32/fs/minix/itree_common.c updated.linux-2.4.32/fs/minix/itree_common.c
--- orig.linux-2.4.32/fs/minix/itree_common.c	2002-02-25 20:38:09.000000000 +0100
+++ updated.linux-2.4.32/fs/minix/itree_common.c	2006-01-14 20:57:54.000000000 +0100
@@ -21,7 +21,7 @@
 
 static inline block_t *block_end(struct buffer_head *bh)
 {
-	return (block_t *)((char*)bh->b_data + BLOCK_SIZE);
+	return (block_t *)((char*)bh->b_data + bh->b_size);
 }
 
 static inline Indirect *get_branch(struct inode *inode,
@@ -81,7 +81,7 @@
 		branch[n].key = cpu_to_block(nr);
 		bh = sb_getblk(inode->i_sb, parent);
 		lock_buffer(bh);
-		memset(bh->b_data, 0, BLOCK_SIZE);
+		memset(bh->b_data, 0, bh->b_size);
 		branch[n].bh = bh;
 		branch[n].p = (block_t*) bh->b_data + offsets[n];
 		*branch[n].p = branch[n].key;
@@ -292,6 +292,7 @@
 
 static inline void truncate (struct inode * inode)
 {
+	struct super_block * sb = inode->i_sb;
 	block_t *idata = i_data(inode);
 	int offsets[DEPTH];
 	Indirect chain[DEPTH];
@@ -301,7 +302,7 @@
 	int first_whole;
 	long iblock;
 
-	iblock = (inode->i_size + BLOCK_SIZE-1) >> 10;
+	iblock = (inode->i_size + sb->s_blocksize -1) >> 10;
 	block_truncate_page(inode->i_mapping, inode->i_size, get_block);
 
 	n = block_to_path(inode, iblock, offsets);
diff -ur orig.linux-2.4.32/include/linux/minix_fs.h updated.linux-2.4.32/include/linux/minix_fs.h
--- orig.linux-2.4.32/include/linux/minix_fs.h	2001-09-07 18:45:51.000000000 +0200
+++ updated.linux-2.4.32/include/linux/minix_fs.h	2006-01-14 20:57:55.000000000 +0100
@@ -23,14 +23,16 @@
 #define MINIX_SUPER_MAGIC2	0x138F		/* minix fs, 30 char names */
 #define MINIX2_SUPER_MAGIC	0x2468		/* minix V2 fs */
 #define MINIX2_SUPER_MAGIC2	0x2478		/* minix V2 fs, 30 char names */
+#define MINIX3_SUPER_MAGIC	0x4d5a		/* minix V3 fs */ 
 #define MINIX_VALID_FS		0x0001		/* Clean fs. */
 #define MINIX_ERROR_FS		0x0002		/* fs has errors. */
 
 #define MINIX_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix_inode)))
-#define MINIX2_INODES_PER_BLOCK ((BLOCK_SIZE)/(sizeof (struct minix2_inode)))
+#define MINIX2_INODES_PER_BLOCK(b) ((b)/(sizeof (struct minix2_inode)))
 
 #define MINIX_V1		0x0001		/* original minix fs */
 #define MINIX_V2		0x0002		/* minix V2 fs */
+#define MINIX_V3		0x0003		/* minix V3 fs */
 
 #define INODE_VERSION(inode)	inode->i_sb->u.minix_sb.s_version
 
@@ -87,6 +89,12 @@
 	char name[0];
 };
 
+struct minix3_dir_entry {
+	__u32 inode;
+	char name[0];
+};
+
 #ifdef __KERNEL__
 
 /*

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux