[Tux3] [PATCH] Fix maximum file size boundary checking. I added a test which attempts to

Shapor Naghibzadeh shapor at gmail.com
Thu Aug 28 00:29:30 PDT 2008


# HG changeset patch
# User shapor at yzf.shapor.com
# Date 1219908532 25200
# Node ID 9d9b2984124deee26f07bfefe6439513ef35ab26
# Parent  7e62bd3ac0f032a991ed96c2527ca2f8f62d6525
Fix maximum file size boundary checking.  I added a test which attempts to
write past the end of the maximum filesize and found it didn't fail until
it submitted the io.  It turns out we were checking the block (which is
shifted) intead of the file position.  For write I test pos + len, but I'm
not sure if this is write.  Are we supposed to do a short write in that
case or not?

diff -r 7e62bd3ac0f0 -r 9d9b2984124d user/test/inode.c
--- a/user/test/inode.c	Wed Aug 27 21:12:32 2008 -0700
+++ b/user/test/inode.c	Thu Aug 28 00:28:52 2008 -0700
@@ -279,7 +279,7 @@ int tuxread(struct file *file, char *dat
 	if (inode->i_size < pos + len)
 		len = inode->i_size - pos;
 	warn("read %Lx/%x", (L)pos, len);
-	if (block & (-1LL << MAX_FILESIZE_BITS))
+	if (pos & (-1LL << MAX_FILESIZE_BITS))
 		return -EIO;
 	struct buffer *blockbuf = getblk(inode->map, block);
 	if (!blockbuf)
@@ -297,8 +297,8 @@ int tuxwrite(struct file *file, char *da
 	struct inode *inode = file->f_inode;
 	block_t block = pos >> inode->sb->blockbits;
 	//warn("write %Lx/%x", pos & inode->sb->blockmask, len);
-	if (block & (-1LL << MAX_FILESIZE_BITS))
-		return -EIO;
+	if ((pos + len) & (-1LL << MAX_FILESIZE_BITS))
+		return -EFBIG;
 	struct buffer *blockbuf = getblk(inode->map, block);
 	if (!blockbuf)
 		return -EIO;
@@ -433,8 +433,10 @@ printf("---- create file ----\n");
 	char buf[100] = { };
 	struct file *file = &(struct file){ .f_inode = inode };
 	tuxseek(file, (1LL << 60) - 12);
-	int err = tuxwrite(file, "hello ", 6);
-printf("err = %i\n", err);
+	int err = tuxwrite(file, "01234567890123456789", 20);
+	printf("err = %i\n", err);
+	err = tuxwrite(file, "hello ", 6);
+	printf("err = %i\n", err);
 	tuxwrite(file, "world!", 6);
 	tuxsync(inode);
 	tuxsync(sb->bitmap);
diff -r 7e62bd3ac0f0 -r 9d9b2984124d user/test/trace.h
--- a/user/test/trace.h	Wed Aug 27 21:12:32 2008 -0700
+++ b/user/test/trace.h	Thu Aug 28 00:28:52 2008 -0700
@@ -7,7 +7,7 @@
 //#define die(code) exit(code)
 #define die(code) asm("int3")
 #define warn(string, args...) do {\
-	fprintf(stderr, "[%u] %s: " string "\n", getpid(), __func__, ##args);\
+	fprintf(stderr, "%s: " string "\n", __func__, ##args);\
 } while (0)
 
 #define error(string, args...) do { warn(string, ##args); die(99); } while (0) 

_______________________________________________
Tux3 mailing list
Tux3 at tux3.org
http://tux3.org/cgi-bin/mailman/listinfo/tux3



More information about the Tux3 mailing list