[PATCH] fadvise: provide posix_fadvice() and implement special ARM syscall
Enrico Scholz <[email protected]> Sun, 20 Feb 2011 16:16:41 +0100
| Newsgroups | gmane.linux.lib.dietlibc |
|---|---|
| Message-ID | <1298215004-28546-5-git-send-email-enrico.scholz@informatik.tu-chemnitz.de> |
Patch makes fadvise64_64 (preferred) or fadvise64 an alias for posix_fadvice(2). Prototype of this syscall was added to <fcntl.h>. ARM requires a special handling for this syscall (see notes in http://www.kernel.org/doc/man-pages/online/pages/man2/posix_fadvise.2.html). There was also added a testprogram. Signed-off-by: Enrico Scholz <[email protected]> --- arm/Makefile.add | 1 + arm/__fadvise.c | 14 ++++++++++++++ arm/arm_fadvise.S | 5 +++++ include/fcntl.h | 2 ++ lib/posix_fallocate.c | 2 +- syscalls.s/fadvise64.S | 8 ++++++++ syscalls.s/fadvise64_64.S | 3 +++ test/Makefile | 2 +- test/fadvise.c | 21 +++++++++++++++++++++ test/runtests.sh | 2 +- 10 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 arm/__fadvise.c create mode 100644 arm/arm_fadvise.S create mode 100644 test/fadvise.c diff --git a/arm/Makefile.add b/arm/Makefile.add index f6126ec..7aaae27 100644 --- a/arm/Makefile.add +++ b/arm/Makefile.add @@ -1,5 +1,6 @@ LIBOBJ+=$(OBJDIR)/md5asm.o $(OBJDIR)/__aeabi_unwind_cpp.o +LIBOBJ+=$(OBJDIR)/__fadvise.o $(OBJDIR)/arm_fadvise.o CFLAGS+=-Os -fomit-frame-pointer -fstrict-aliasing #ifdef __ARM_EABI__ CFLAGS+=-mabi=aapcs-linux -mfloat-abi=soft -mno-thumb-interwork diff --git a/arm/__fadvise.c b/arm/__fadvise.c new file mode 100644 index 0000000..0aa1246 --- /dev/null +++ b/arm/__fadvise.c @@ -0,0 +1,14 @@ +#include <fcntl.h> +#include "syscalls.h" + +#ifndef __NR_fadvise64 +long fadvise64_64(int fd, off64_t offset, off64_t len, int advice) +{ + extern long __arm_fadvise64_64(int fd, int advice, off64_t offset, off64_t len); + + return __arm_fadvise64_64(fd, advice, offset, len); +} + +int posix_fadvise(int fd, off64_t offset, off64_t len, int advise) + __attribute__((__alias__("fadvise64_64"))); +#endif diff --git a/arm/arm_fadvise.S b/arm/arm_fadvise.S new file mode 100644 index 0000000..216cdcc --- /dev/null +++ b/arm/arm_fadvise.S @@ -0,0 +1,5 @@ +#include "syscalls.h" + +#ifdef __NR_arm_fadvise64_64 +syscall(arm_fadvise64_64, __arm_fadvise64_64); +#endif diff --git a/include/fcntl.h b/include/fcntl.h index 510826c..d085ba5 100644 --- a/include/fcntl.h +++ b/include/fcntl.h @@ -673,7 +673,9 @@ int utimensat(int dirfd, const char *pathname, struct timespec* t); #endif #if defined(_XOPEN_SOURCE) && (_XOPEN_SOURCE - 0) >= 600 +#include "linux/fadvise.h" int posix_fallocate(int fd, off64_t offset, off64_t len) __THROW; +int posix_fadvise(int fd, off64_t offset, off64_t len, int advice) __THROW; #endif __END_DECLS diff --git a/lib/posix_fallocate.c b/lib/posix_fallocate.c index ef9f985..82c3e1d 100644 --- a/lib/posix_fallocate.c +++ b/lib/posix_fallocate.c @@ -1,7 +1,7 @@ #define _GNU_SOURCE #define _XOPEN_SOURCE 600 -#include <fcntl.h> +#include <fcntl.h> int posix_fallocate(int fd, off64_t offset, off64_t len) { return fallocate(fd,0,offset,len); } diff --git a/syscalls.s/fadvise64.S b/syscalls.s/fadvise64.S index 0f96da9..fe448b1 100644 --- a/syscalls.s/fadvise64.S +++ b/syscalls.s/fadvise64.S @@ -1,3 +1,11 @@ #include "syscalls.h" +#ifdef __NR_fadvise64 syscall(fadvise64,fadvise64) + +#ifndef __NR_fadvise64_64 +.set posix_fadvise, fadvise64 +.globl posix_fadvise +#endif + +#endif diff --git a/syscalls.s/fadvise64_64.S b/syscalls.s/fadvise64_64.S index 1893962..9bf66b5 100644 --- a/syscalls.s/fadvise64_64.S +++ b/syscalls.s/fadvise64_64.S @@ -2,4 +2,7 @@ #ifdef __NR_fadvise64_64 syscall(fadvise64_64,fadvise64_64) + +.set posix_fadvise, fadvise64_64 +.globl posix_fadvise #endif diff --git a/test/Makefile b/test/Makefile index eea0075..d86bb8d 100644 --- a/test/Makefile +++ b/test/Makefile @@ -7,7 +7,7 @@ CFLAGS=-nostdinc -Wall LCOMPAT=-lcompat -TESTPROGRAMS=adjtime argv asprintf atexit bsearch byteswap calloc confstr cycles empty flush fnmatch \ +TESTPROGRAMS=adjtime argv asprintf atexit bsearch byteswap calloc confstr cycles empty fadvise flush fnmatch \ fputc ftw fwrite getaddrinfo getenv getgrnam gethostbyaddr gethostbyname \ gethostbyname_r getmntent getopt getpass getpwnam getservbyname getservbyport getusershell \ glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger md5_testharness \ diff --git a/test/fadvise.c b/test/fadvise.c new file mode 100644 index 0000000..cdd6428 --- /dev/null +++ b/test/fadvise.c @@ -0,0 +1,21 @@ +#define _GNU_SOURCE +#define _XOPEN_SOURCE 600 + +#include <stdlib.h> +#include <fcntl.h> +#include <assert.h> +#include <unistd.h> + +int main(void) +{ + char file[] = "/tmp/dietlibc-fadvise-test.XXXXXX"; + int fd; + + fd = mkstemp(file); + unlink(file); + + assert(posix_fadvise(fd, 23, 42, POSIX_FADV_RANDOM) == 0); + close(fd); + + return EXIT_SUCCESS; +} diff --git a/test/runtests.sh b/test/runtests.sh index 6d89efb..f74ee0c 100644 --- a/test/runtests.sh +++ b/test/runtests.sh @@ -1,6 +1,6 @@ SUBDIRS="dirent inet stdio string stdlib time" -TESTPROGRAMS="adjtime argv atexit bsearch byteswap calloc confstr empty flush fputc ffs fnmatch ftw fwrite getaddrinfo getenv getdelim getgrnam gethostbyaddr gethostbyname gethostbyname_r getmntent getopt getpwnam getservbyname getservbyport getusershell glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger md5_testharness memccpy memchr memcmp memrchr memusage mktime mmap_test pipe printf printftest protoent prototypes putenv pwent rand48 readdir regex select sendfile servent siglist speed spent sprintf sscanf stdarg strcasecmp strcmp strncat strncpy strptime strrchr strstr strtol sysenter ungetc waitpid" +TESTPROGRAMS="adjtime argv atexit bsearch byteswap calloc confstr empty fadvise flush fputc ffs fnmatch ftw fwrite getaddrinfo getenv getdelim getgrnam gethostbyaddr gethostbyname gethostbyname_r getmntent getopt getpwnam getservbyname getservbyport getusershell glob grent hasmntopt hello iconv if_nameindex ltostr malloc-debugger md5_testharness memccpy memchr memcmp memrchr memusage mktime mmap_test pipe printf printftest protoent prototypes putenv pwent rand48 readdir regex select sendfile servent siglist speed spent sprintf sscanf stdarg strcasecmp strcmp strncat strncpy strptime strrchr strstr strtol sysenter ungetc waitpid" STDIN="read1" PASS="getpass" -- 1.7.4