Skip to contentSkip to conversation

erofs-utils: Enable 64-bit off_t with AC_SYS_LARGEFILE

PATCH Gao Xiang 1 participant 2 messages Jan 4 3 messages not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): [email protected]

A message that is not in the archive (sent off-list or not yet received): rlp54h7fqffgfms2hgabxyjdbzmqx6xdhmj7gb2tarro32gj5p@nwb3nqv7jafq

Gao Xiang

author
#3 lore raw

Hi Jame,

Quoted 92 lines · James Le Cuirot
Quoted 91 lines · James Le Cuirot

I was initially just going go fix the += Bashism, but this is the safe and portable way to enable 64-bit off_t. It is not possible to enable it on some very old systems. erofs_off_t is hardcoded to u64, but I believe this will still work correctly alongside a 32-bit off_t.

Either way, you don't need HAVE_PREAD64 or HAVE_PWRITE64 because pread64/pwrite64 are aliases of pread/pwrite when off_t is 64-bit. See unistd.h and man pread(2).

---
  configure.ac |  4 +---
  lib/io.c     | 20 +-------------------
  2 files changed, 2 insertions(+), 22 deletions(-)
configure.ac +1 -3
index 4d34e1f..14332ed 100644
@@ -251,8 +251,6 @@ AC_CHECK_FUNCS(m4_flatten([
  	lsetxattr
  	memset
  	realpath
-	pread64
-	pwrite64
  	pwritev
  	posix_fadvise
  	fstatfs
@@ -554,7 +552,7 @@ AS_IF([test "x$with_xxhash" != "xno"], [
  ])
 
  # Enable 64-bit off_t
-CFLAGS+=" -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64"
+AC_SYS_LARGEFILE
 
  # Configure fuzzing mode
  AS_IF([test "x$enable_fuzzing" != "xyes"], [], [
lib/io.c +1 -19
index aa043ca..eaa5fa7 100644
@@ -74,11 +74,7 @@ ssize_t erofs_io_pwrite(struct erofs_vfile *vf, const void *buf,
 
  	pos += vf->offset;
  	do {
-#ifdef HAVE_PWRITE64
-		ret = pwrite64(vf->fd, buf, len, (off64_t)pos);
-#else
  		ret = pwrite(vf->fd, buf, len, (off_t)pos);
-#endif
  		if (ret <= 0) {
  			if (!ret)
  				break;
@@ -208,11 +204,7 @@ ssize_t erofs_io_pread(struct erofs_vfile *vf, void *buf, u64 pos, size_t len)
 
  	pos += vf->offset;
  	do {
-#ifdef HAVE_PREAD64
-		ret = pread64(vf->fd, buf, len, (off64_t)pos);
-#else
  		ret = pread(vf->fd, buf, len, (off_t)pos);
-#endif
  		if (ret <= 0) {
  			if (!ret)
  				break;
@@ -436,11 +428,7 @@ static ssize_t __erofs_copy_file_range(int fd_in, u64 *off_in,
  		char *end, *p;
 
  		to_read = min_t(size_t, length, sizeof(buf));
-#ifdef HAVE_PREAD64
-		read_count = pread64(fd_in, buf, to_read, *off_in);
-#else
  		read_count = pread(fd_in, buf, to_read, *off_in);
-#endif
  		if (read_count == 0)
  			/* End of file reached prematurely. */
  			return copied;
@@ -455,13 +443,7 @@ static ssize_t __erofs_copy_file_range(int fd_in, u64 *off_in,
  		/* Write the buffer part which was read to the destination. */
  		end = buf + read_count;
  		for (p = buf; p < end; ) {
-			ssize_t write_count;
-
-#ifdef HAVE_PWRITE64
-			write_count = pwrite64(fd_out, p, end - p, *off_out);
-#else
-			write_count = pwrite(fd_out, p, end - p, *off_out);
-#endif
+			ssize_t write_count = pwrite(fd_out, p, end - p, *off_out);
  			if (write_count < 0) {
  				/*
Quoted 8 lines
Quoted 4 lines
lib/io.c +0 -0
  				 * Adjust the input read position to match what
Signature · 1 line
2.51.2

Unfortunately, it's been pointed out to me that this change isn't safe because the config.h generated by configure is not consistently included everywhere. That could be fixed, but I don't feel like untangling that myself.

Sorry for late response.

Yes, currently config.h is not used everywhere, so it's still perferred to use CFLAGS for now.

Thanks,
Gao Xiang

author
#4 lore raw

Re: [PATCH 1/2] erofs-utils: Drop configure checks for unused functions

In reply to a message not in the archive

Hi James,

Quoted 1 line · James Le Cuirot

I will apply this patch, but Cc the erofs mailing list as well.

Thanks,
Gao Xiang

Quoted 47 lines
---
  configure.ac | 25 -------------------------
  1 file changed, 25 deletions(-)
configure.ac +0 -25
index 2d42b1f..4d34e1f 100644
@@ -233,29 +233,6 @@ AC_CHECK_MEMBERS([struct stat.st_atim])
  AC_CHECK_MEMBERS([struct stat.st_atimensec])
  AC_TYPE_UINT64_T
 
-#
-# Check to see if llseek() is declared in unistd.h.  On some libc's
-# it is, and on others it isn't..... Thank you glibc developers....
-#
-AC_CHECK_DECL(llseek,
-  [AC_DEFINE(HAVE_LLSEEK_PROTOTYPE, 1,
-    [Define to 1 if llseek declared in unistd.h])],,
-  [#include <unistd.h>])
-
-#
-# Check to see if lseek64() is declared in unistd.h.  Glibc's header files
-# are so convoluted that I can't tell whether it will always be defined,
-# and if it isn't defined while lseek64 is defined in the library,
-# disaster will strike.
-#
-# Warning!  Use of --enable-gcc-wall may throw off this test.
-#
-AC_CHECK_DECL(lseek64,[AC_DEFINE(HAVE_LSEEK64_PROTOTYPE, 1,
-  [Define to 1 if lseek64 declared in unistd.h])],,
-  [#define _LARGEFILE_SOURCE
-   #define _LARGEFILE64_SOURCE
-   #include <unistd.h>])
-
  AC_CHECK_DECL(memrchr,[AC_DEFINE(HAVE_MEMRCHR, 1,
    [Define to 1 if memrchr declared in string.h])],,
    [#define _GNU_SOURCE
@@ -274,8 +251,6 @@ AC_CHECK_FUNCS(m4_flatten([
  	lsetxattr
  	memset
  	realpath
-	lseek64
-	ftello64
  	pread64
  	pwrite64
  	pwritev