]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: fix ext2fs_llseek on i386
authorPhillip Susi <psusi@ubuntu.com>
Thu, 24 Jan 2013 16:21:56 +0000 (11:21 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 25 Jan 2013 04:04:01 +0000 (23:04 -0500)
ext2fs_llseek() was using lseek instead of lseek64.  The
only time it would use lseek64 is if passed an offset that
overflowed 32 bits.  This works for SEEK_SET, but not
SEEK_CUR, which can apply a small offset to move the file
pointer past the 32 bit limit.

The code has been changed to instead try lseek64 first, and
fall back to lseek if that fails.  It also was doing a
runtime check of the size of off_t.  This has been moved to
compile time.

This fixes a problem which would cause e2image when built for
x86-32 to bomb out when used with large file systems.

Signed-off-by: Phillip Susi <psusi@ubuntu.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
configure.in
lib/config.h.in
lib/ext2fs/llseek.c

index cf96e43c39c24b5078f26af13a9d0b169189b84b..c3687bb84dac9595d8f729c7c630565627f5e106 100644 (file)
@@ -916,14 +916,17 @@ AC_CHECK_SIZEOF(short)
 AC_CHECK_SIZEOF(int)
 AC_CHECK_SIZEOF(long)
 AC_CHECK_SIZEOF(long long)
+AC_CHECK_SIZEOF(off_t)
 SIZEOF_SHORT=$ac_cv_sizeof_short
 SIZEOF_INT=$ac_cv_sizeof_int
 SIZEOF_LONG=$ac_cv_sizeof_long
 SIZEOF_LONG_LONG=$ac_cv_sizeof_long_long
+SIZEOF_OFF_T=$ac_cv_sizeof_off_t
 AC_SUBST(SIZEOF_SHORT)
 AC_SUBST(SIZEOF_INT)
 AC_SUBST(SIZEOF_LONG)
 AC_SUBST(SIZEOF_LONG_LONG)
+AC_SUBST(SIZEOF_OFF_T)
 AC_C_BIGENDIAN
 BUILD_CC="$BUILD_CC" CPP="$CPP" /bin/sh $ac_aux_dir/parse-types.sh
 ASM_TYPES_HEADER=./asm_types.h
index 90e974328156d701b0148177ef739d1850c85a0d..e14eff4f115ff4ee4b37a89bc2325ab56534151f 100644 (file)
 /* The size of `long long', as computed by sizeof. */
 #undef SIZEOF_LONG_LONG
 
+/* The size of `off_t', as computed by sizeof. */
+#undef SIZEOF_OFF_T
+
 /* The size of `short', as computed by sizeof. */
 #undef SIZEOF_SHORT
 
index b0576e406c96ea74b1c11a84e55efa8e54e61172..c3a98a2c3cf20a94d328c67bf3e9873ae266c90d 100644 (file)
@@ -90,17 +90,14 @@ static ext2_loff_t my_llseek (int fd, ext2_loff_t offset, int origin)
 
 ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
 {
+#if SIZEOF_OFF_T >= SIZEOF_LONG_LONG
+       return lseek (fd, offset, origin);
+#else
        ext2_loff_t result;
        static int do_compat = 0;
 
-       if ((sizeof(off_t) >= sizeof(ext2_loff_t)) ||
-           (offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1))))
-               return lseek(fd, (off_t) offset, origin);
-
-       if (do_compat) {
-               errno = EINVAL;
-               return -1;
-       }
+       if (do_compat)
+               goto fallback;
 
        result = my_llseek (fd, offset, origin);
        if (result == -1 && errno == ENOSYS) {
@@ -109,9 +106,14 @@ ext2_loff_t ext2fs_llseek (int fd, ext2_loff_t offset, int origin)
                 * which does not support the llseek system call
                 */
                do_compat++;
+       fallback:
+               if (offset < ((ext2_loff_t) 1 << ((sizeof(off_t)*8) -1)))
+                       return lseek(fd, (off_t) offset, origin);
                errno = EINVAL;
+               return -1;
        }
        return result;
+#endif
 }
 
 #else /* !linux */