[Ocfs2-devel] [PATCH] fs: Fix default SEEK_DATA and SEEK_HOLE implementation

Sunil Mushran sunil.mushran at oracle.com
Wed May 18 19:44:43 PDT 2011


In the default SEEK_DATA implementation, as the entire file is treated as data,
all supplied offsets less than the size of the file are valid.

For empty files, SEEK_DATA and SEEK_HOLE returns -ENXIO irrespective of the
input offset.

Signed-off-by: Sunil Mushran <sunil.mushran at oracle.com>
---
 fs/read_write.c |    9 ++++-----
 1 files changed, 4 insertions(+), 5 deletions(-)

diff --git a/fs/read_write.c b/fs/read_write.c
index af9cc51..4b991e9 100644
--- a/fs/read_write.c
+++ b/fs/read_write.c
@@ -66,11 +66,10 @@ generic_file_llseek_unlocked(struct file *file, loff_t offset, int origin)
 		break;
 	case SEEK_DATA:
 		/*
-		 * In the generic case the entire file is data, so data only
-		 * starts at position 0 provided the file has an i_size,
-		 * otherwise it's an empty file and will always be ENXIO.
+		 * In the generic case the entire file is data. So all offsets
+		 * less than the file size are valid.
 		 */
-		if (offset != 0 || inode->i_size == 0)
+		if (inode->i_size == 0 || offset >= inode->i_size)
 			return -ENXIO;
 		break;
 	case SEEK_HOLE:
@@ -78,7 +77,7 @@ generic_file_llseek_unlocked(struct file *file, loff_t offset, int origin)
 		 * There is a virtual hole at the end of the file, so as long as
 		 * offset isn't i_size or larger, return i_size.
 		 */
-		if (offset >= inode->i_size)
+		if (inode->i_size == 0 || offset >= inode->i_size)
 			return -ENXIO;
 		offset = inode->i_size;
 		break;
-- 
1.7.4.1




More information about the Ocfs2-devel mailing list