patch-2.1.10 linux/fs/ext2/super.c

Next file: linux/fs/ext2/truncate.c
Previous file: linux/fs/ext2/namei.c
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.1.9/linux/fs/ext2/super.c linux/fs/ext2/super.c
@@ -11,6 +11,9 @@
  *  linux/fs/minix/inode.c
  *
  *  Copyright (C) 1991, 1992  Linus Torvalds
+ *
+ *  Big-endian to little-endian byte-swapping/bitmaps by
+ *        David S. Miller (davem@caip.rutgers.edu), 1995
  */
 
 #include <linux/module.h>
@@ -39,7 +42,8 @@
 
 	if (!(sb->s_flags & MS_RDONLY)) {
 		sb->u.ext2_sb.s_mount_state |= EXT2_ERROR_FS;
-		sb->u.ext2_sb.s_es->s_state |= EXT2_ERROR_FS;
+		sb->u.ext2_sb.s_es->s_state =
+			cpu_to_le16(le16_to_cpu(sb->u.ext2_sb.s_es->s_state) | EXT2_ERROR_FS);
 		mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
 		sb->s_dirt = 1;
 	}
@@ -47,14 +51,14 @@
 	vsprintf (error_buf, fmt, args);
 	va_end (args);
 	if (test_opt (sb, ERRORS_PANIC) ||
-	    (sb->u.ext2_sb.s_es->s_errors == EXT2_ERRORS_PANIC &&
+	    (le16_to_cpu(sb->u.ext2_sb.s_es->s_errors) == EXT2_ERRORS_PANIC &&
 	     !test_opt (sb, ERRORS_CONT) && !test_opt (sb, ERRORS_RO)))
 		panic ("EXT2-fs panic (device %s): %s: %s\n",
 		       kdevname(sb->s_dev), function, error_buf);
 	printk (KERN_CRIT "EXT2-fs error (device %s): %s: %s\n",
 		kdevname(sb->s_dev), function, error_buf);
 	if (test_opt (sb, ERRORS_RO) ||
-	    (sb->u.ext2_sb.s_es->s_errors == EXT2_ERRORS_RO &&
+	    (le16_to_cpu(sb->u.ext2_sb.s_es->s_errors) == EXT2_ERRORS_RO &&
 	     !test_opt (sb, ERRORS_CONT) && !test_opt (sb, ERRORS_PANIC))) {
 		printk ("Remounting filesystem read-only\n");
 		sb->s_flags |= MS_RDONLY;
@@ -68,7 +72,8 @@
 
 	if (!(sb->s_flags & MS_RDONLY)) {
 		sb->u.ext2_sb.s_mount_state |= EXT2_ERROR_FS;
-		sb->u.ext2_sb.s_es->s_state |= EXT2_ERROR_FS;
+		sb->u.ext2_sb.s_es->s_state =
+			cpu_to_le16(le16_to_cpu(sb->u.ext2_sb.s_es->s_state) | EXT2_ERROR_FS);
 		mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
 		sb->s_dirt = 1;
 	}
@@ -102,7 +107,7 @@
 
 	lock_super (sb);
 	if (!(sb->s_flags & MS_RDONLY)) {
-		sb->u.ext2_sb.s_es->s_state = sb->u.ext2_sb.s_mount_state;
+		sb->u.ext2_sb.s_es->s_state = le16_to_cpu(sb->u.ext2_sb.s_mount_state);
 		mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
 	}
 	sb->s_dev = 0;
@@ -270,7 +275,7 @@
 static void ext2_setup_super (struct super_block * sb,
 			      struct ext2_super_block * es)
 {
-	if (es->s_rev_level > EXT2_MAX_SUPP_REV) {
+	if (le32_to_cpu(es->s_rev_level) > EXT2_MAX_SUPP_REV) {
 			printk ("EXT2-fs warning: revision level too high, "
 				"forcing read/only mode\n");
 			sb->s_flags |= MS_RDONLY;
@@ -282,19 +287,20 @@
 		else if ((sb->u.ext2_sb.s_mount_state & EXT2_ERROR_FS))
 			printk ("EXT2-fs warning: mounting fs with errors, "
 				"running e2fsck is recommended\n");
-		else if (es->s_max_mnt_count >= 0 &&
-		         es->s_mnt_count >= (unsigned short) es->s_max_mnt_count)
+		else if ((__s16) le16_to_cpu(es->s_max_mnt_count) >= 0 &&
+		         le16_to_cpu(es->s_mnt_count) >=
+			 (unsigned short) (__s16) le16_to_cpu(es->s_max_mnt_count))
 			printk ("EXT2-fs warning: maximal mount count reached, "
 				"running e2fsck is recommended\n");
-		else if (es->s_checkinterval &&
-			(es->s_lastcheck + es->s_checkinterval <= CURRENT_TIME))
+		else if (le32_to_cpu(es->s_checkinterval) &&
+			(le32_to_cpu(es->s_lastcheck) + le32_to_cpu(es->s_checkinterval) <= CURRENT_TIME))
 			printk ("EXT2-fs warning: checktime reached, "
 				"running e2fsck is recommended\n");
-		es->s_state &= ~EXT2_VALID_FS;
-		if (!es->s_max_mnt_count)
-			es->s_max_mnt_count = EXT2_DFL_MAX_MNT_COUNT;
-		es->s_mnt_count++;
-		es->s_mtime = CURRENT_TIME;
+		es->s_state = cpu_to_le16(le16_to_cpu(es->s_state) & ~EXT2_VALID_FS);
+		if (!(__s16) le16_to_cpu(es->s_max_mnt_count))
+			es->s_max_mnt_count = (__s16) cpu_to_le16(EXT2_DFL_MAX_MNT_COUNT);
+		es->s_mnt_count=cpu_to_le16(le16_to_cpu(es->s_mnt_count) + 1);
+		es->s_mtime = cpu_to_le32(CURRENT_TIME);
 		mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
 		sb->s_dirt = 1;
 		if (test_opt (sb, DEBUG))
@@ -317,7 +323,7 @@
 {
 	int i;
 	int desc_block = 0;
-	unsigned long block = sb->u.ext2_sb.s_es->s_first_data_block;
+	unsigned long block = le32_to_cpu(sb->u.ext2_sb.s_es->s_first_data_block);
 	struct ext2_group_desc * gdp = NULL;
 
 	ext2_debug ("Checking group descriptors");
@@ -326,32 +332,32 @@
 	{
 		if ((i % EXT2_DESC_PER_BLOCK(sb)) == 0)
 			gdp = (struct ext2_group_desc *) sb->u.ext2_sb.s_group_desc[desc_block++]->b_data;
-		if (gdp->bg_block_bitmap < block ||
-		    gdp->bg_block_bitmap >= block + EXT2_BLOCKS_PER_GROUP(sb))
+		if (le32_to_cpu(gdp->bg_block_bitmap) < block ||
+		    le32_to_cpu(gdp->bg_block_bitmap) >= block + EXT2_BLOCKS_PER_GROUP(sb))
 		{
 			ext2_error (sb, "ext2_check_descriptors",
 				    "Block bitmap for group %d"
 				    " not in group (block %lu)!",
-				    i, (unsigned long) gdp->bg_block_bitmap);
+				    i, (unsigned long) le32_to_cpu(gdp->bg_block_bitmap));
 			return 0;
 		}
-		if (gdp->bg_inode_bitmap < block ||
-		    gdp->bg_inode_bitmap >= block + EXT2_BLOCKS_PER_GROUP(sb))
+		if (le32_to_cpu(gdp->bg_inode_bitmap) < block ||
+		    le32_to_cpu(gdp->bg_inode_bitmap) >= block + EXT2_BLOCKS_PER_GROUP(sb))
 		{
 			ext2_error (sb, "ext2_check_descriptors",
 				    "Inode bitmap for group %d"
 				    " not in group (block %lu)!",
-				    i, (unsigned long) gdp->bg_inode_bitmap);
+				    i, (unsigned long) le32_to_cpu(gdp->bg_inode_bitmap));
 			return 0;
 		}
-		if (gdp->bg_inode_table < block ||
-		    gdp->bg_inode_table + sb->u.ext2_sb.s_itb_per_group >=
+		if (le32_to_cpu(gdp->bg_inode_table) < block ||
+		    le32_to_cpu(gdp->bg_inode_table) + sb->u.ext2_sb.s_itb_per_group >=
 		    block + EXT2_BLOCKS_PER_GROUP(sb))
 		{
 			ext2_error (sb, "ext2_check_descriptors",
 				    "Inode table for group %d"
 				    " not in group (block %lu)!",
-				    i, (unsigned long) gdp->bg_inode_table);
+				    i, (unsigned long) le32_to_cpu(gdp->bg_inode_table));
 			return 0;
 		}
 		block += EXT2_BLOCKS_PER_GROUP(sb);
@@ -399,7 +405,7 @@
 	 */
 	es = (struct ext2_super_block *) bh->b_data;
 	sb->u.ext2_sb.s_es = es;
-	sb->s_magic = es->s_magic;
+	sb->s_magic = le16_to_cpu(es->s_magic);
 	if (sb->s_magic != EXT2_SUPER_MAGIC) {
 		if (!silent)
 			printk ("VFS: Can't find an ext2 filesystem on dev "
@@ -412,22 +418,22 @@
 		MOD_DEC_USE_COUNT;
 		return NULL;
 	}
-	if (es->s_rev_level > EXT2_GOOD_OLD_REV) {
-		if (es->s_feature_incompat & ~EXT2_FEATURE_INCOMPAT_SUPP) {
+	if (le32_to_cpu(es->s_rev_level) > EXT2_GOOD_OLD_REV) {
+		if (le32_to_cpu(es->s_feature_incompat) & ~EXT2_FEATURE_INCOMPAT_SUPP) {
 			printk("EXT2-fs: %s: couldn't mount because of "
 			       "unsupported optional features.\n", 
 			       kdevname(dev));
 			goto failed_mount;
 		}
 		if (!(sb->s_flags & MS_RDONLY) &&
-		    (es->s_feature_ro_compat & ~EXT2_FEATURE_RO_COMPAT_SUPP)) {
+		    (le32_to_cpu(es->s_feature_ro_compat) & ~EXT2_FEATURE_RO_COMPAT_SUPP)) {
 			printk("EXT2-fs: %s: couldn't mount RDWR because of "
 			       "unsupported optional features.\n", 
 			       kdevname(dev));
 			goto failed_mount;
 		}
 	}
-	sb->s_blocksize_bits = sb->u.ext2_sb.s_es->s_log_block_size + 10;
+	sb->s_blocksize_bits = le32_to_cpu(sb->u.ext2_sb.s_es->s_log_block_size) + 10;
 	sb->s_blocksize = 1 << sb->s_blocksize_bits;
 	if (sb->s_blocksize != BLOCK_SIZE && 
 	    (sb->s_blocksize == 1024 || sb->s_blocksize == 2048 ||  
@@ -446,17 +452,17 @@
 		}
 		es = (struct ext2_super_block *) (((char *)bh->b_data) + offset);
 		sb->u.ext2_sb.s_es = es;
-		if (es->s_magic != EXT2_SUPER_MAGIC) {
+		if (es->s_magic != le16_to_cpu(EXT2_SUPER_MAGIC)) {
 			printk ("EXT2-fs: Magic mismatch, very weird !\n");
 			goto failed_mount;
 		}
 	}
-	if (es->s_rev_level == EXT2_GOOD_OLD_REV) {
+	if (le32_to_cpu(es->s_rev_level) == EXT2_GOOD_OLD_REV) {
 		sb->u.ext2_sb.s_inode_size = EXT2_GOOD_OLD_INODE_SIZE;
 		sb->u.ext2_sb.s_first_ino = EXT2_GOOD_OLD_FIRST_INO;
 	} else {
-		sb->u.ext2_sb.s_inode_size = es->s_inode_size;
-		sb->u.ext2_sb.s_first_ino = es->s_first_ino;
+		sb->u.ext2_sb.s_inode_size = le16_to_cpu(es->s_inode_size);
+		sb->u.ext2_sb.s_first_ino = le32_to_cpu(es->s_first_ino);
 		if (sb->u.ext2_sb.s_inode_size != EXT2_GOOD_OLD_INODE_SIZE) {
 			printk ("EXT2-fs: unsupported inode size: %d\n",
 				sb->u.ext2_sb.s_inode_size);
@@ -464,15 +470,15 @@
 		}
 	}
 	sb->u.ext2_sb.s_frag_size = EXT2_MIN_FRAG_SIZE <<
-				   es->s_log_frag_size;
+				   (__s32) le32_to_cpu(es->s_log_frag_size);
 	if (sb->u.ext2_sb.s_frag_size)
 		sb->u.ext2_sb.s_frags_per_block = sb->s_blocksize /
 						  sb->u.ext2_sb.s_frag_size;
 	else
 		sb->s_magic = 0;
-	sb->u.ext2_sb.s_blocks_per_group = es->s_blocks_per_group;
-	sb->u.ext2_sb.s_frags_per_group = es->s_frags_per_group;
-	sb->u.ext2_sb.s_inodes_per_group = es->s_inodes_per_group;
+	sb->u.ext2_sb.s_blocks_per_group = le32_to_cpu(es->s_blocks_per_group);
+	sb->u.ext2_sb.s_frags_per_group = le32_to_cpu(es->s_frags_per_group);
+	sb->u.ext2_sb.s_inodes_per_group = le32_to_cpu(es->s_inodes_per_group);
 	sb->u.ext2_sb.s_inodes_per_block = sb->s_blocksize /
 					   EXT2_INODE_SIZE(sb);
 	sb->u.ext2_sb.s_itb_per_group = sb->u.ext2_sb.s_inodes_per_group /
@@ -483,12 +489,12 @@
 	if (resuid != EXT2_DEF_RESUID)
 		sb->u.ext2_sb.s_resuid = resuid;
 	else
-		sb->u.ext2_sb.s_resuid = es->s_def_resuid;
+		sb->u.ext2_sb.s_resuid = le16_to_cpu(es->s_def_resuid);
 	if (resgid != EXT2_DEF_RESGID)
 		sb->u.ext2_sb.s_resgid = resgid;
 	else
-		sb->u.ext2_sb.s_resgid = es->s_def_resgid;
-	sb->u.ext2_sb.s_mount_state = es->s_state;
+		sb->u.ext2_sb.s_resgid = le16_to_cpu(es->s_def_resgid);
+	sb->u.ext2_sb.s_mount_state = le16_to_cpu(es->s_state);
 	sb->u.ext2_sb.s_rename_lock = 0;
 	sb->u.ext2_sb.s_rename_wait = NULL;
 	sb->u.ext2_sb.s_addr_per_block_bits =
@@ -531,8 +537,8 @@
 		goto failed_mount;
 	}
 
-	sb->u.ext2_sb.s_groups_count = (es->s_blocks_count -
-				        es->s_first_data_block +
+	sb->u.ext2_sb.s_groups_count = (le32_to_cpu(es->s_blocks_count) -
+				        le32_to_cpu(es->s_first_data_block) +
 				       EXT2_BLOCKS_PER_GROUP(sb) - 1) /
 				       EXT2_BLOCKS_PER_GROUP(sb);
 	db_count = (sb->u.ext2_sb.s_groups_count + EXT2_DESC_PER_BLOCK(sb) - 1) /
@@ -596,7 +602,7 @@
 static void ext2_commit_super (struct super_block * sb,
 			       struct ext2_super_block * es)
 {
-	es->s_wtime = CURRENT_TIME;
+	es->s_wtime = cpu_to_le32(CURRENT_TIME);
 	mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
 	sb->s_dirt = 0;
 }
@@ -621,9 +627,9 @@
 
 		ext2_debug ("setting valid to 0\n");
 
-		if (es->s_state & EXT2_VALID_FS) {
-			es->s_state &= ~EXT2_VALID_FS;
-			es->s_mtime = CURRENT_TIME;
+		if (le16_to_cpu(es->s_state) & EXT2_VALID_FS) {
+			es->s_state = cpu_to_le16(le16_to_cpu(es->s_state) & ~EXT2_VALID_FS);
+			es->s_mtime = cpu_to_le32(CURRENT_TIME);
 		}
 		ext2_commit_super (sb, es);
 	}
@@ -653,15 +659,15 @@
 	if ((*flags & MS_RDONLY) == (sb->s_flags & MS_RDONLY))
 		return 0;
 	if (*flags & MS_RDONLY) {
-		if (es->s_state & EXT2_VALID_FS ||
+		if (le16_to_cpu(es->s_state) & EXT2_VALID_FS ||
 		    !(sb->u.ext2_sb.s_mount_state & EXT2_VALID_FS))
 			return 0;
 		/*
 		 * OK, we are remounting a valid rw partition rdonly, so set
 		 * the rdonly flag and then mark the partition as valid again.
 		 */
-		es->s_state = sb->u.ext2_sb.s_mount_state;
-		es->s_mtime = CURRENT_TIME;
+		es->s_state = cpu_to_le16(sb->u.ext2_sb.s_mount_state);
+		es->s_mtime = cpu_to_le32(CURRENT_TIME);
 		mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
 		sb->s_dirt = 1;
 		ext2_commit_super (sb, es);
@@ -672,7 +678,7 @@
 		 * store the current valid flag.  (It may have been changed 
 		 * by e2fsck since we originally mounted the partition.)
 		 */
-		sb->u.ext2_sb.s_mount_state = es->s_state;
+		sb->u.ext2_sb.s_mount_state = le16_to_cpu(es->s_state);
 		sb->s_flags &= ~MS_RDONLY;
 		ext2_setup_super (sb, es);
 	}
@@ -722,18 +728,18 @@
 				     1 /* block bitmap */ +
 				     1 /* inode bitmap */ +
 				     sb->u.ext2_sb.s_itb_per_group /* inode table */;
-		overhead = sb->u.ext2_sb.s_es->s_first_data_block +
+		overhead = le32_to_cpu(sb->u.ext2_sb.s_es->s_first_data_block) +
 			   sb->u.ext2_sb.s_groups_count * overhead_per_group;
 	}
 
 	tmp.f_type = EXT2_SUPER_MAGIC;
 	tmp.f_bsize = sb->s_blocksize;
-	tmp.f_blocks = sb->u.ext2_sb.s_es->s_blocks_count - overhead;
+	tmp.f_blocks = le32_to_cpu(sb->u.ext2_sb.s_es->s_blocks_count) - overhead;
 	tmp.f_bfree = ext2_count_free_blocks (sb);
-	tmp.f_bavail = tmp.f_bfree - sb->u.ext2_sb.s_es->s_r_blocks_count;
-	if (tmp.f_bfree < sb->u.ext2_sb.s_es->s_r_blocks_count)
+	tmp.f_bavail = tmp.f_bfree - le32_to_cpu(sb->u.ext2_sb.s_es->s_r_blocks_count);
+	if (tmp.f_bfree < le32_to_cpu(sb->u.ext2_sb.s_es->s_r_blocks_count))
 		tmp.f_bavail = 0;
-	tmp.f_files = sb->u.ext2_sb.s_es->s_inodes_count;
+	tmp.f_files = le32_to_cpu(sb->u.ext2_sb.s_es->s_inodes_count);
 	tmp.f_ffree = ext2_count_free_inodes (sb);
 	tmp.f_namelen = EXT2_NAME_LEN;
 	copy_to_user(buf, &tmp, bufsiz);

FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen, slshen@lbl.gov