From: Theodore Ts'o <tytso@mit.edu>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>
Cc: psusi@ubuntu.com, "Theodore Ts'o" <tytso@mit.edu>
Subject: [PATCH] libext2fs: fix ext2fs_llseek on i386
Date: Thu, 24 Jan 2013 23:14:18 -0500 [thread overview]
Message-ID: <1359087258-13276-1-git-send-email-tytso@mit.edu> (raw)
In-Reply-To: <20130125041313.GF28908@thunk.org>
From: Phillip Susi <psusi@ubuntu.com>
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 | 3 +++
lib/config.h.in | 3 +++
lib/ext2fs/llseek.c | 18 ++++++++++--------
3 files changed, 16 insertions(+), 8 deletions(-)
diff --git a/configure.in b/configure.in
index cf96e43..c3687bb 100644
--- a/configure.in
+++ b/configure.in
@@ -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
diff --git a/lib/config.h.in b/lib/config.h.in
index 90e9743..e14eff4 100644
--- a/lib/config.h.in
+++ b/lib/config.h.in
@@ -543,6 +543,9 @@
/* 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
diff --git a/lib/ext2fs/llseek.c b/lib/ext2fs/llseek.c
index b0576e4..c3a98a2 100644
--- a/lib/ext2fs/llseek.c
+++ b/lib/ext2fs/llseek.c
@@ -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 */
--
1.7.12.rc0.22.gcdd159b
next prev parent reply other threads:[~2013-01-25 4:14 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-01-24 16:21 [PATCH] e2fslibs: fix llseek on i386 Phillip Susi
2013-01-24 19:51 ` Theodore Ts'o
2013-01-24 20:22 ` Phillip Susi
2013-01-24 20:32 ` Theodore Ts'o
2013-01-25 2:25 ` Zheng Liu
2013-01-25 2:16 ` Theodore Ts'o
2013-01-25 2:48 ` Zheng Liu
2013-01-25 4:13 ` Theodore Ts'o
2013-01-25 4:14 ` Theodore Ts'o [this message]
2013-01-25 4:34 ` [PATCH] libext2fs: fix ext2fs_llseek " Phillip Susi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1359087258-13276-1-git-send-email-tytso@mit.edu \
--to=tytso@mit.edu \
--cc=linux-ext4@vger.kernel.org \
--cc=psusi@ubuntu.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).