Implement some of the missing LFS64 support.
This gives us:
* <dirent.h>
struct dirent64
readdir64, readdir64_r, alphasort64, scandir64
* <fcntl.h>
creat64, openat64, open64.
* <sys/stat.h>
struct stat64
fstat64, fstatat64, lstat64, stat64.
* <sys/statvfs.h>
struct statvfs64
statvfs64, fstatvfs64.
* <sys/vfs.h>
struct statfs64
statfs64, fstatfs64.
This also removes some of the incorrect #define hacks we've had in the
past (for stat64, for example, which we promised to clean up way back
in bug 8472078).
Bug: 11865851
Bug: 8472078
Change-Id: Ia46443521918519f2dfa64d4621027dfd13ac566
diff --git a/libc/include/dirent.h b/libc/include/dirent.h
index 129cdfa..bfe4ea4 100644
--- a/libc/include/dirent.h
+++ b/libc/include/dirent.h
@@ -46,27 +46,33 @@
#define DT_WHT 14
#endif
-struct dirent {
- uint64_t d_ino;
- int64_t d_off;
- unsigned short d_reclen;
- unsigned char d_type;
- char d_name[256];
-};
+#define __DIRENT64_BODY \
+ uint64_t d_ino; \
+ int64_t d_off; \
+ unsigned short d_reclen; \
+ unsigned char d_type; \
+ char d_name[256]; \
+
+struct dirent { __DIRENT64_BODY };
+struct dirent64 { __DIRENT64_BODY };
+
#define d_fileno d_ino
-#define dirent64 dirent
typedef struct DIR DIR;
extern DIR* opendir(const char*);
extern DIR* fdopendir(int);
extern struct dirent* readdir(DIR*);
+extern struct dirent64* readdir64(DIR*);
extern int readdir_r(DIR*, struct dirent*, struct dirent**);
+extern int readdir64_r(DIR*, struct dirent64*, struct dirent64**);
extern int closedir(DIR*);
extern void rewinddir(DIR*);
extern int dirfd(DIR*);
extern int alphasort(const struct dirent**, const struct dirent**);
+extern int alphasort64(const struct dirent64**, const struct dirent64**);
extern int scandir(const char*, struct dirent***, int (*)(const struct dirent*), int (*)(const struct dirent**, const struct dirent**));
+extern int scandir64(const char*, struct dirent64***, int (*)(const struct dirent64*), int (*)(const struct dirent64**, const struct dirent64**));
extern int getdents(unsigned int, struct dirent*, unsigned int);
__END_DECLS
diff --git a/libc/include/fcntl.h b/libc/include/fcntl.h
index b7b91f2..e37e0a7 100644
--- a/libc/include/fcntl.h
+++ b/libc/include/fcntl.h
@@ -42,11 +42,14 @@
#endif
extern int creat(const char*, mode_t);
+extern int creat64(const char*, mode_t);
extern int fallocate64(int, int, off64_t, off64_t);
extern int fallocate(int, int, off_t, off_t);
extern int fcntl(int, int, ...);
extern int openat(int, const char*, int, ...);
+extern int openat64(int, const char*, int, ...);
extern int open(const char*, int, ...);
+extern int open64(const char*, int, ...);
extern int posix_fallocate64(int, off64_t, off64_t);
extern int posix_fallocate(int, off_t, off_t);
extern int unlinkat(int, const char*, int);
diff --git a/libc/include/sys/stat.h b/libc/include/sys/stat.h
index 37b8dc2..10bd01f 100644
--- a/libc/include/sys/stat.h
+++ b/libc/include/sys/stat.h
@@ -38,101 +38,101 @@
__BEGIN_DECLS
#if defined(__aarch64__)
-struct stat {
- unsigned long st_dev;
- unsigned long st_ino;
- unsigned int st_mode;
- unsigned int st_nlink;
- unsigned int st_uid;
- unsigned int st_gid;
- unsigned long st_rdev;
- unsigned long __pad1;
- long st_size;
- int st_blksize;
- int __pad2;
- long st_blocks;
- long st_atime;
- unsigned long st_atime_nsec;
- long st_mtime;
- unsigned long st_mtime_nsec;
- long st_ctime;
- unsigned long st_ctime_nsec;
- unsigned int __unused4;
- unsigned int __unused5;
-};
+#define __STAT64_BODY \
+ unsigned long st_dev; \
+ unsigned long st_ino; \
+ unsigned int st_mode; \
+ unsigned int st_nlink; \
+ unsigned int st_uid; \
+ unsigned int st_gid; \
+ unsigned long st_rdev; \
+ unsigned long __pad1; \
+ long st_size; \
+ int st_blksize; \
+ int __pad2; \
+ long st_blocks; \
+ long st_atime; \
+ unsigned long st_atime_nsec; \
+ long st_mtime; \
+ unsigned long st_mtime_nsec; \
+ long st_ctime; \
+ unsigned long st_ctime_nsec; \
+ unsigned int __unused4; \
+ unsigned int __unused5; \
+
#elif defined(__mips__)
-struct stat {
- unsigned int st_dev;
- unsigned int __pad0[3];
- unsigned long long st_ino;
- unsigned int st_mode;
- unsigned int st_nlink;
- unsigned int st_uid;
- unsigned int st_gid;
- unsigned int st_rdev;
- unsigned int __pad1[3];
- long long st_size;
- unsigned int st_atime;
- unsigned int st_atime_nsec;
- unsigned int st_mtime;
- unsigned int st_mtime_nsec;
- unsigned int st_ctime;
- unsigned int st_ctime_nsec;
- unsigned int st_blksize;
- unsigned int __pad2;
- unsigned long long st_blocks;
-};
+#define __STAT64_BODY \
+ unsigned int st_dev; \
+ unsigned int __pad0[3]; \
+ unsigned long long st_ino; \
+ unsigned int st_mode; \
+ unsigned int st_nlink; \
+ unsigned int st_uid; \
+ unsigned int st_gid; \
+ unsigned int st_rdev; \
+ unsigned int __pad1[3]; \
+ long long st_size; \
+ unsigned int st_atime; \
+ unsigned int st_atime_nsec; \
+ unsigned int st_mtime; \
+ unsigned int st_mtime_nsec; \
+ unsigned int st_ctime; \
+ unsigned int st_ctime_nsec; \
+ unsigned int st_blksize; \
+ unsigned int __pad2; \
+ unsigned long long st_blocks; \
+
#elif defined(__x86_64__)
-struct stat {
- unsigned long st_dev;
- unsigned long st_ino;
- unsigned long st_nlink;
- unsigned int st_mode;
- unsigned int st_uid;
- unsigned int st_gid;
- unsigned int __pad0;
- unsigned long st_rdev;
- long st_size;
- long st_blksize;
- long st_blocks;
- unsigned long st_atime;
- unsigned long st_atime_nsec;
- unsigned long st_mtime;
- unsigned long st_mtime_nsec;
- unsigned long st_ctime;
- unsigned long st_ctime_nsec;
- long __pad3[3];
-};
+#define __STAT64_BODY \
+ unsigned long st_dev; \
+ unsigned long st_ino; \
+ unsigned long st_nlink; \
+ unsigned int st_mode; \
+ unsigned int st_uid; \
+ unsigned int st_gid; \
+ unsigned int __pad0; \
+ unsigned long st_rdev; \
+ long st_size; \
+ long st_blksize; \
+ long st_blocks; \
+ unsigned long st_atime; \
+ unsigned long st_atime_nsec; \
+ unsigned long st_mtime; \
+ unsigned long st_mtime_nsec; \
+ unsigned long st_ctime; \
+ unsigned long st_ctime_nsec; \
+ long __pad3[3]; \
+
#else
-struct stat {
- unsigned long long st_dev;
- unsigned char __pad0[4];
- unsigned long __st_ino;
- unsigned int st_mode;
- unsigned int st_nlink;
- unsigned long st_uid;
- unsigned long st_gid;
- unsigned long long st_rdev;
- unsigned char __pad3[4];
- long long st_size;
- unsigned long st_blksize;
- unsigned long long st_blocks;
- unsigned long st_atime;
- unsigned long st_atime_nsec;
- unsigned long st_mtime;
- unsigned long st_mtime_nsec;
- unsigned long st_ctime;
- unsigned long st_ctime_nsec;
- unsigned long long st_ino;
-};
+#define __STAT64_BODY \
+ unsigned long long st_dev; \
+ unsigned char __pad0[4]; \
+ unsigned long __st_ino; \
+ unsigned int st_mode; \
+ unsigned int st_nlink; \
+ unsigned long st_uid; \
+ unsigned long st_gid; \
+ unsigned long long st_rdev; \
+ unsigned char __pad3[4]; \
+ long long st_size; \
+ unsigned long st_blksize; \
+ unsigned long long st_blocks; \
+ unsigned long st_atime; \
+ unsigned long st_atime_nsec; \
+ unsigned long st_mtime; \
+ unsigned long st_mtime_nsec; \
+ unsigned long st_ctime; \
+ unsigned long st_ctime_nsec; \
+ unsigned long long st_ino; \
+
#endif
-/* For compatibility with GLibc, we provide macro aliases
- * for the non-Posix nano-seconds accessors.
- */
-#define st_atimensec st_atime_nsec
-#define st_mtimensec st_mtime_nsec
-#define st_ctimensec st_ctime_nsec
+struct stat { __STAT64_BODY };
+struct stat64 { __STAT64_BODY };
+
+#define st_atimensec st_atime_nsec
+#define st_mtimensec st_mtime_nsec
+#define st_ctimensec st_ctime_nsec
#ifdef __USE_BSD
/* Permission macros provided by glibc for compatibility with BSDs. */
@@ -141,21 +141,26 @@
#define DEFFILEMODE (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH) /* 0666 */
#endif
-extern int chmod(const char *, mode_t);
-extern int fchmod(int, mode_t);
-extern int mkdir(const char *, mode_t);
+extern int chmod(const char*, mode_t);
+extern int fchmod(int, mode_t);
+extern int mkdir(const char*, mode_t);
-extern int stat(const char *, struct stat *);
-extern int fstat(int, struct stat *);
-extern int lstat(const char *, struct stat *);
-extern int mknod(const char *, mode_t, dev_t);
+extern int fstat(int, struct stat*);
+extern int fstat64(int, struct stat64*);
+extern int fstatat(int, const char*, struct stat*, int);
+extern int fstatat64(int, const char*, struct stat64*, int);
+extern int lstat(const char*, struct stat*);
+extern int lstat64(const char*, struct stat64*);
+extern int stat(const char*, struct stat*);
+extern int stat64(const char*, struct stat64*);
+
+extern int mknod(const char*, mode_t, dev_t);
extern mode_t umask(mode_t);
#if defined(__BIONIC_FORTIFY)
extern mode_t __umask_chk(mode_t);
-extern mode_t __umask_real(mode_t)
- __asm__(__USER_LABEL_PREFIX__ "umask");
+extern mode_t __umask_real(mode_t) __asm__(__USER_LABEL_PREFIX__ "umask");
__errordecl(__umask_invalid_mode, "umask called with invalid mode");
__BIONIC_FORTIFY_INLINE
@@ -172,20 +177,14 @@
}
#endif /* defined(__BIONIC_FORTIFY) */
-
-#define stat64 stat
-#define fstat64 fstat
-#define lstat64 lstat
-
extern int mkfifo(const char*, mode_t);
extern int fchmodat(int, const char*, mode_t, int);
-extern int fstatat(int, const char*, struct stat*, int);
extern int mkdirat(int, const char*, mode_t);
extern int mknodat(int, const char*, mode_t, dev_t);
-# define UTIME_NOW ((1l << 30) - 1l)
-# define UTIME_OMIT ((1l << 30) - 2l)
+#define UTIME_NOW ((1L << 30) - 1L)
+#define UTIME_OMIT ((1L << 30) - 2L)
extern int utimensat(int fd, const char *path, const struct timespec times[2], int flags);
extern int futimens(int fd, const struct timespec times[2]);
diff --git a/libc/include/sys/statvfs.h b/libc/include/sys/statvfs.h
index e910c03..3d8179e 100644
--- a/libc/include/sys/statvfs.h
+++ b/libc/include/sys/statvfs.h
@@ -23,19 +23,21 @@
__BEGIN_DECLS
-struct statvfs {
- unsigned long f_bsize;
- unsigned long f_frsize;
- fsblkcnt_t f_blocks;
- fsblkcnt_t f_bfree;
- fsblkcnt_t f_bavail;
- fsfilcnt_t f_files;
- fsfilcnt_t f_ffree;
- fsfilcnt_t f_favail;
- unsigned long f_fsid;
- unsigned long f_flag;
- unsigned long f_namemax;
-};
+#define __STATVFS64_BODY \
+ unsigned long f_bsize; \
+ unsigned long f_frsize; \
+ fsblkcnt_t f_blocks; \
+ fsblkcnt_t f_bfree; \
+ fsblkcnt_t f_bavail; \
+ fsfilcnt_t f_files; \
+ fsfilcnt_t f_ffree; \
+ fsfilcnt_t f_favail; \
+ unsigned long f_fsid; \
+ unsigned long f_flag; \
+ unsigned long f_namemax; \
+
+struct statvfs { __STATVFS64_BODY };
+struct statvfs64 { __STATVFS64_BODY };
#define ST_RDONLY 0x0001
#define ST_NOSUID 0x0002
@@ -48,7 +50,9 @@
#define ST_RELATIME 0x1000
extern int statvfs(const char* __restrict, struct statvfs* __restrict) __nonnull((1, 2));
+extern int statvfs64(const char* __restrict, struct statvfs64* __restrict) __nonnull((1, 2));
extern int fstatvfs(int, struct statvfs*) __nonnull((2));
+extern int fstatvfs64(int, struct statvfs64*) __nonnull((2));
__END_DECLS
diff --git a/libc/include/sys/vfs.h b/libc/include/sys/vfs.h
index 10afbc3..cd6044d 100644
--- a/libc/include/sys/vfs.h
+++ b/libc/include/sys/vfs.h
@@ -39,73 +39,73 @@
typedef __fsid_t fsid_t;
#if defined(__aarch64__) || defined(__x86_64__)
-struct statfs {
- uint64_t f_type;
- uint64_t f_bsize;
- uint64_t f_blocks;
- uint64_t f_bfree;
- uint64_t f_bavail;
- uint64_t f_files;
- uint64_t f_ffree;
- fsid_t f_fsid;
- uint64_t f_namelen;
- uint64_t f_frsize;
- uint64_t f_flags;
- uint64_t f_spare[4];
-};
+#define __STATFS64_BODY \
+ uint64_t f_type; \
+ uint64_t f_bsize; \
+ uint64_t f_blocks; \
+ uint64_t f_bfree; \
+ uint64_t f_bavail; \
+ uint64_t f_files; \
+ uint64_t f_ffree; \
+ fsid_t f_fsid; \
+ uint64_t f_namelen; \
+ uint64_t f_frsize; \
+ uint64_t f_flags; \
+ uint64_t f_spare[4]; \
+
#elif defined(__mips__) && defined(__LP64__)
/* 64-bit MIPS. */
-struct statfs {
- uint64_t f_type;
- uint64_t f_bsize;
- uint64_t f_frsize; /* Fragment size - unsupported. */
- uint64_t f_blocks;
- uint64_t f_bfree;
- uint64_t f_files;
- uint64_t f_ffree;
- uint64_t f_bavail;
- fsid_t f_fsid;
- uint64_t f_namelen;
- uint64_t f_flags;
- uint64_t f_spare[5];
-};
+#define __STATFS64_BODY \
+ uint64_t f_type; \
+ uint64_t f_bsize; \
+ uint64_t f_frsize; /* Fragment size - unsupported. */ \
+ uint64_t f_blocks; \
+ uint64_t f_bfree; \
+ uint64_t f_files; \
+ uint64_t f_ffree; \
+ uint64_t f_bavail; \
+ fsid_t f_fsid; \
+ uint64_t f_namelen; \
+ uint64_t f_flags; \
+ uint64_t f_spare[5]; \
+
#elif defined(__mips__)
/* 32-bit MIPS (corresponds to the kernel's statfs64 type). */
-struct statfs {
- uint32_t f_type;
- uint32_t f_bsize;
- uint32_t f_frsize;
- uint32_t __pad;
- uint64_t f_blocks;
- uint64_t f_bfree;
- uint64_t f_files;
- uint64_t f_ffree;
- uint64_t f_bavail;
- fsid_t f_fsid;
- uint32_t f_namelen;
- uint32_t f_flags;
- uint32_t f_spare[5];
-};
+#define __STATFS64_BODY \
+ uint32_t f_type; \
+ uint32_t f_bsize; \
+ uint32_t f_frsize; \
+ uint32_t __pad; \
+ uint64_t f_blocks; \
+ uint64_t f_bfree; \
+ uint64_t f_files; \
+ uint64_t f_ffree; \
+ uint64_t f_bavail; \
+ fsid_t f_fsid; \
+ uint32_t f_namelen; \
+ uint32_t f_flags; \
+ uint32_t f_spare[5]; \
+
#else
/* 32-bit ARM or x86 (corresponds to the kernel's statfs64 type). */
-struct statfs {
- uint32_t f_type;
- uint32_t f_bsize;
- uint64_t f_blocks;
- uint64_t f_bfree;
- uint64_t f_bavail;
- uint64_t f_files;
- uint64_t f_ffree;
- fsid_t f_fsid;
- uint32_t f_namelen;
- uint32_t f_frsize;
- uint32_t f_flags;
- uint32_t f_spare[4];
-};
+#define __STATFS64_BODY \
+ uint32_t f_type; \
+ uint32_t f_bsize; \
+ uint64_t f_blocks; \
+ uint64_t f_bfree; \
+ uint64_t f_bavail; \
+ uint64_t f_files; \
+ uint64_t f_ffree; \
+ fsid_t f_fsid; \
+ uint32_t f_namelen; \
+ uint32_t f_frsize; \
+ uint32_t f_flags; \
+ uint32_t f_spare[4]; \
+
#endif
-/* Source compatibility with glibc. */
-#define statfs64 statfs
+struct statfs { __STATFS64_BODY };
+struct statfs64 { __STATFS64_BODY };
/* Declare that we have the f_namelen, f_frsize, and f_flags fields. */
#define _STATFS_F_NAMELEN
@@ -158,7 +158,9 @@
#define _XIAFS_SUPER_MAGIC 0x012FD16D
extern int statfs(const char*, struct statfs*) __nonnull((1, 2));
+extern int statfs64(const char*, struct statfs64*) __nonnull((1, 2));
extern int fstatfs(int, struct statfs*) __nonnull((2));
+extern int fstatfs64(int, struct statfs64*) __nonnull((2));
__END_DECLS