logo

utils-std

Collection of commonly available Unix tools git clone https://anongit.hacktivis.me/git/utils-std.git/
commit: caac31f9777c48d7b2b0cbad767b4b548eb266b4
parent 074ba11fffe5b3eb6110b819e60d65523d4c60cd
Author: Haelwenn (lanodan) Monnier <contact@hacktivis.me>
Date:   Wed, 11 Jun 2025 21:00:46 +0200

cmd/*: add posix_fadvise(…SEQUENTIAL) between open() & auto_{fd,file}_copy()

Diffstat:

Mcmd/cat.c3+++
Mcmd/head.c2++
Mcmd/install.c4++++
Mcmd/mv.c4++++
Mcmd/split.c6++++++
5 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/cmd/cat.c b/cmd/cat.c @@ -83,6 +83,9 @@ main(int argc, char *argv[]) return 1; } + posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); + errno = 0; + if(auto_fd_copy(fd, STDOUT_FILENO, SSIZE_MAX) < 0) { fprintf(stderr, diff --git a/cmd/head.c b/cmd/head.c @@ -45,6 +45,8 @@ copy_bytes(const char *filename) stderr, "%s: error: Failed opening file '%s': %s\n", argv0, filename, strerror(errno)); return 1; } + + posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); } int err = 0; diff --git a/cmd/install.c b/cmd/install.c @@ -136,6 +136,10 @@ do_install(char *src, char *dest, bool is_dir) if(opt_v) fprintf(stderr, "%s: Made file: %s\n", argv0, dest); + posix_fadvise(src_fd, 0, 0, POSIX_FADV_SEQUENTIAL); + posix_fadvise(dest_fd, 0, 0, POSIX_FADV_SEQUENTIAL); + errno = 0; + if(auto_file_copy(src_fd, dest_fd, src_stat.st_size, 0) < 0) { fprintf(stderr, diff --git a/cmd/mv.c b/cmd/mv.c @@ -109,6 +109,10 @@ copy_file_unlink(struct named_fd srcdir, errno = 0; } + posix_fadvise(in, 0, 0, POSIX_FADV_SEQUENTIAL); + posix_fadvise(out, 0, 0, POSIX_FADV_SEQUENTIAL); + errno = 0; + if(auto_file_copy(in, out, src_status.st_size, 0) < 0) return -1; return unlinkat(srcdir.fd, src, 0); diff --git a/cmd/split.c b/cmd/split.c @@ -77,6 +77,9 @@ split_bytes(void) return 1; } + posix_fadvise(fd_in, 0, 0, POSIX_FADV_SEQUENTIAL); + errno = 0; + int err = 0; off_t wrote = 0; int split_id = 0; @@ -94,6 +97,9 @@ split_bytes(void) break; } + posix_fadvise(fd_out, 0, 0, POSIX_FADV_SEQUENTIAL); + errno = 0; + int ret = auto_file_copy(fd_in, fd_out, bytes, 0); if(ret < 0) {