Skip to contentSkip to conversation

minix filesystem: Corrected patch

PATCH/RFC Daniel Aragonés 2 participants 2 messages Jan 22, 2006

lore
Share & tools
lore
#0 lore raw

Answering to the suggestion of Randy, here come the patches already corrected.

This patches concern the update for Minix V3 support for both kernels 2.6.x.y and 2.4.x.

Attached as text files "V3_2dot6_patch.txt" and "V3_2dot4_patch.txt" are the corrected versions of my first post dated January 19. As I wrote there...

The modifications I have made to the preexistent code have been four:

1.- The layout of the superblock variables is different in version V3.

2.- Disable writings to "s_state" because it has been droped out from the superblock, and its former address is now used by another parameter.

3.- Change the references to the constant "BLOCK_SIZE" to the variables "s_blocksize" or "b_size", so allowing for multiple size blocks.

4.- Introduce the new structure "minix3_dir_entry" to cope with the 4 byte pointers employed in the new directory entries of 64 bytes.

fs/minix/bitmap.c +5 -5
diff -ur orig.linux-2.6.14.5/fs/minix/bitmap.c updated.linux-2.6.14.5/fs/minix/bitmap.c
@@ -26,14 +26,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];
@@ -145,15 +145,15 @@
 		return NULL;
 	}
 	ino--;
-	block = 2 + sbi->s_imap_blocks + sbi->s_zmap_blocks +
-		 ino / MINIX2_INODES_PER_BLOCK;
+	block = 2 + sbi->s_imap_blocks + sbi->s_zmap_blocks + 
+		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. */
fs/minix/dir.c +84 -31

208 lines not on this page · raw message

fs/minix/inode.c +45 -21

120 lines not on this page · raw message

fs/minix/itree_common.c +4 -3
diff -ur orig.linux-2.6.14.5/fs/minix/itree_common.c updated.linux-2.6.14.5/fs/minix/itree_common.c
@@ -23,7 +23,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,
@@ -85,7 +85,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);
fs/minix/minix.h +1 -0
diff -ur orig.linux-2.6.14.5/fs/minix/minix.h updated.linux-2.6.14.5/fs/minix/minix.h
@@ -12,6 +12,7 @@
 
 #define MINIX_V1		0x0001		/* original minix fs */
 #define MINIX_V2		0x0002		/* minix V2 fs */
+#define MINIX_V3		0x0003		/* minix V3 fs */
 
 /*
  * minix fs inode data in memory
include/linux/minix_fs.h +6 -1
diff -ur orig.linux-2.6.14.5/include/linux/minix_fs.h updated.linux-2.6.14.5/include/linux/minix_fs.h
@@ -23,11 +23,12 @@
 #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)))
 
 /*
  * This is the original minix inode layout on disk.
@@ -82,4 +83,9 @@
 	char name[0];
 };
 
+struct minix3_dir_entry {
+	__u32 inode;
+	char name[0];
+};
 #endif
fs/minix/bitmap.c +4 -4
diff -ur orig.linux-2.4.32/fs/minix/bitmap.c updated.linux-2.4.32/fs/minix/bitmap.c
@@ -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. */
fs/minix/dir.c +86 -32

206 lines not on this page · raw message

fs/minix/inode.c +47 -26

144 lines not on this page · raw message

fs/minix/itree_common.c +4 -3
diff -ur orig.linux-2.4.32/fs/minix/itree_common.c updated.linux-2.4.32/fs/minix/itree_common.c
@@ -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);
include/linux/minix_fs.h +8 -1
diff -ur orig.linux-2.4.32/include/linux/minix_fs.h updated.linux-2.4.32/include/linux/minix_fs.h
@@ -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__
 
 /*
#1 lore raw

Hi Daniel,

Quoted 5 lines · Daniel Aragonés

Answering to the suggestion of Randy, here come the patches already corrected.

This patches concern the update for Minix V3 support for both kernels 2.6.x.y and 2.4.x.

Attached as text files "V3_2dot6_patch.txt" and "V3_2dot4_patch.txt" are the corrected versions of my first post dated January 19. As I wrote there...

Please post the 2.4 and 2.6 patches as separetely and inline the patch in the mail as per Documentation/SubmittingPatches. I am unable to apply your patch because my mail client meshes them together.

Quoted 15 lines
fs/minix/dir.c +3 -6
@@ -108,14 +111,22 @@
                limit = kaddr + minix_last_byte(inode, n) - 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);

fs/minix/dir.c line 128

Quoted 10 lines
fs/minix/dir.c +10 -0
+                                       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);

Hmm, strange formatting. Wouldn't it be better if you introduced a name pointer and moved those filldir bits outside of the if-else block? Less code duplication that way.

Quoted 9 lines
fs/minix/dir.c +4 -5
-               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)) {

fs/minix/dir.c line 198

Quoted 10 lines
fs/minix/dir.c +10 -0
+                               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;
+                       }

Same here.

Quoted 6 lines
fs/minix/dir.c +0 -2
@@ -226,9 +248,16 @@
                        if (!de->inode)
                                goto got_it;
                        err = -EEXIST;
-                       if (namecompare(namelen,sbi->s_namelen,name,de->name))
-                               goto out_unlock;

fs/minix/dir.c line 259

Quoted 10 lines
fs/minix/dir.c +9 -1
-                       de = minix_next_entry(de, sbi);
+                       if (!(sbi->s_version == MINIX_V3)) {
+                               if (namecompare(namelen,sbi->s_namelen,name,de->name))
+                                       goto out_unlock;
+                               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);

Why do you do both here?

Quoted 6 lines
fs/minix/dir.c +0 -2
@@ -242,9 +271,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);

fs/minix/dir.c line 282

Quoted 10 lines
fs/minix/dir.c +9 -1
-       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;
+               }

Strange formatting.

Quoted 6 lines
fs/minix/dir.c +0 -2
@@ -301,11 +337,13 @@
        memset(kaddr, 0, PAGE_CACHE_SIZE);
 
        de = (struct minix_dir_entry *)kaddr;
-       de->inode = inode->i_ino;
-       strcpy(de->name,".");

fs/minix/dir.c line 347

Quoted 10 lines
fs/minix/dir.c +6 -2
+       de3 = (struct minix3_dir_entry *)kaddr;
+       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,"..");
        kunmap_atomic(kaddr, KM_USER0);

Formatting and please use if-else instead.

Quoted 22 lines
(quoted diff) +0 -0
                while ((char *)de <= kaddr) {
                        if (de->inode != 0) {
                                /* check for . and .. */
fs/minix/dir.c +12 -6
-                               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 (de3->name[0] != '.')
                                                goto not_empty;
-                               } else if (de->name[1] != '.')
-                                       goto not_empty;

fs/minix/dir.c line 402

Quoted 10 lines
fs/minix/dir.c +8 -2
-                               else if (de->name[2])
-                                       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;
+                               }

Formatting. Shouldn't you make that non_empty check a separate function so you don't need to duplicate it?

fs/minix/inode.c line 212

Quoted 13 lines
fs/minix/inode.c +9 -0
@@ -197,6 +201,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);

You probably want to introduce a struct minix3_super_block for this. It's much more readable that way.

fs/minix/inode.c line 220

Quoted 8 lines
fs/minix/inode.c +8 -0
+               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;
+               }

You're now setting the block size twice for the V3 case.

include/linux/minix_fs.h line 31

Quoted 3 lines
include/linux/minix_fs.h +1 -1
 #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)))

Maybe this should be called minix_inodes_per_block instead and be a static inline function?