[prev in list] [next in list] [prev in thread] [next in thread] 

List:       linux-fsdevel
Subject:    [PATCH] setting the LARGE_FILE flag
From:       Andreas Dilger <adilger () turbolinux ! com>
Date:       2001-01-16 8:50:11
[Download RAW message or body]

Alan,
included here is a patch to 2.2.18 ext2 which fixes an ext2 buglet
w.r.t. 64-bit files.  I noticed this when doing the LFS code for ext3.
Basically, the issue is that we are setting the LARGE_FILE flag on
the filesystem when there is still a chance that no large file will
be created.  This patch moves the setting of LARGE_FILE until after all
the validity checks are done, because we can either exit with EFBIG from
the resource limit, or the count could be changed to not create a large file.
It also happens to make the ext3 code cleaner...

The patch makes inode.c check "size >> 31" instead of "size >> 33" when
setting the LARGE_FILE flag.  This matches what file.c is doing and, from
what you and Al Viro said the last time this came up, is the correct thing
to do (i.e. if bit 31 or higher is set, we have a file > 2GB == LARGE).

Cheers, Andreas
=======================================================================
--- linux/fs/ext2/file.c.orig	Sun Dec 10 17:49:44 2000
+++ linux/fs/ext2/file.c	Tue Jan 16 00:28:10 2001
@@ -223,21 +223,12 @@
 
 		if (pos >= max)
 			return -EFBIG;
-		
+
 		if (pos + count > max) {
 			count = max - pos;
 			if (!count)
 				return -EFBIG;
 		}
-		if (((pos + count) >> 31) && 
-		    !(sb->u.ext2_sb.s_es->s_feature_ro_compat &
-		      cpu_to_le32(EXT2_FEATURE_RO_COMPAT_LARGE_FILE))) {
-			/* If this is the first large file created, add a flag
-			   to the superblock */
-			sb->u.ext2_sb.s_es->s_feature_ro_compat |=
-				cpu_to_le32(EXT2_FEATURE_RO_COMPAT_LARGE_FILE);
-			mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
-		}
 	}
 #endif
 
@@ -254,6 +245,17 @@
 			}
 		}
 	}
+
+#if BITS_PER_LONG == 64
+	if (((pos + count) >> 31) &&
+	    !(sb->u.ext2_sb.s_es->s_feature_ro_compat &
+	      cpu_to_le32(EXT2_FEATURE_RO_COMPAT_LARGE_FILE))) {
+		/* If this is the first large file, add a flag to superblock */
+		sb->u.ext2_sb.s_es->s_feature_ro_compat |=
+				cpu_to_le32(EXT2_FEATURE_RO_COMPAT_LARGE_FILE);
+		mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
+	}
+#endif
 
 	/*
 	 * If a file has been opened in synchronous mode, we have to ensure
--- linux/fs/ext2/inode.c.orig	Sun Dec 10 17:49:44 2000
+++ linux/fs/ext2/inode.c	Tue Jan 16 00:31:46 2001
@@ -737,26 +737,26 @@
 			send_sig(SIGXFSZ, current, 0);
 			return -EFBIG;
 		}
+	}
+
+	retval = inode_change_ok(inode, iattr);
+	if (retval != 0)
+		goto out;
 
-#if BITS_PER_LONG == 64	
-		if (size >> 33) {
-			struct super_block *sb = inode->i_sb;
-			struct ext2_super_block *es = sb->u.ext2_sb.s_es;
-			if (!(es->s_feature_ro_compat &
-			      cpu_to_le32(EXT2_FEATURE_RO_COMPAT_LARGE_FILE))){
-				/* If this is the first large file
-				 * created, add a flag to the superblock */
-				es->s_feature_ro_compat |=
+#if BITS_PER_LONG == 64
+	if (iattr->ia_valid & ATTR_SIZE && iattr->ia_size >> 31) {
+		struct super_block *sb = inode->i_sb;
+		struct ext2_super_block *es = EXT2_SB(sb)->s_es;
+		if (!(es->s_feature_ro_compat &
+		      cpu_to_le32(EXT2_FEATURE_RO_COMPAT_LARGE_FILE))){
+			/* If this is the first large file created,
+			 * add a flag to the superblock */
+			es->s_feature_ro_compat |=
 				cpu_to_le32(EXT2_FEATURE_RO_COMPAT_LARGE_FILE);
-				mark_buffer_dirty(sb->u.ext2_sb.s_sbh, 1);
-			}
+			mark_buffer_dirty(EXT2_SB(sb)->s_sbh, 1);
 		}
-#endif
 	}
-	
-	retval = inode_change_ok(inode, iattr);
-	if (retval != 0)
-		goto out;
+#endif
 
 	inode_setattr(inode, iattr);
 	
-- 
Andreas Dilger  \ "If a man ate a pound of pasta and a pound of antipasto,
                 \  would they cancel out, leaving him still hungry?"
http://www-mddsp.enel.ucalgary.ca/People/adilger/               -- Dogbert
-
To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in
the body of a message to majordomo@vger.kernel.org

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic