X-Git-Url: https://mattmccutchen.net/rsync/rsync.git/blobdiff_plain/2a189350f27d092fd05e85d4a08b941a26f13718..a59a7b242393699fedeb4f66911e3fc9b4fadd73:/syscall.c diff --git a/syscall.c b/syscall.c index 1d72d198..c6c571a6 100644 --- a/syscall.c +++ b/syscall.c @@ -29,6 +29,10 @@ #include #endif +#if defined HAVE_SYS_FALLOCATE && !defined HAVE_FALLOCATE +#include +#endif + extern int dry_run; extern int am_root; extern int am_sender; @@ -60,7 +64,7 @@ int do_symlink(const char *lnk, const char *fname) if (dry_run) return 0; RETURN_ERROR_IF_RO_OR_LO; -#ifdef NO_SYMLINK_XATTRS +#if defined NO_SYMLINK_XATTRS || defined NO_SYMLINK_USER_XATTRS /* For --fake-super, we create a normal file with mode 0600 * and write the lnk into it. */ if (am_root < 0) { @@ -78,7 +82,7 @@ int do_symlink(const char *lnk, const char *fname) return symlink(lnk, fname); } -#ifdef NO_SYMLINK_XATTRS +#if defined NO_SYMLINK_XATTRS || defined NO_SYMLINK_USER_XATTRS ssize_t do_readlink(const char *path, char *buf, size_t bufsiz) { /* For --fake-super, we read the link from the file. */ @@ -226,6 +230,22 @@ int do_rename(const char *fname1, const char *fname2) return rename(fname1, fname2); } +#ifdef HAVE_FTRUNCATE +int do_ftruncate(int fd, OFF_T size) +{ + int ret; + + if (dry_run) return 0; + RETURN_ERROR_IF_RO_OR_LO; + + do { + ret = ftruncate(fd, size); + } while (ret < 0 && errno == EINTR); + + return ret; +} +#endif + void trim_trailing_slashes(char *name) { int l; @@ -401,3 +421,25 @@ int do_utime(const char *fname, time_t modtime, UNUSED(uint32 mod_nsec)) #else #error Need utimes or utime function. #endif + +#ifdef SUPPORT_PREALLOCATION +int do_fallocate(int fd, OFF_T offset, OFF_T length) +{ +#ifdef FALLOC_FL_KEEP_SIZE +#define DO_FALLOC_OPTIONS FALLOC_FL_KEEP_SIZE +#else +#define DO_FALLOC_OPTIONS 0 +#endif + RETURN_ERROR_IF(dry_run, 0); + RETURN_ERROR_IF_RO_OR_LO; +#if defined HAVE_FALLOCATE + return fallocate(fd, DO_FALLOC_OPTIONS, offset, length); +#elif defined HAVE_SYS_FALLOCATE + return syscall(SYS_fallocate, fd, DO_FALLOC_OPTIONS, (loff_t)offset, (loff_t)length); +#elif defined HAVE_EFFICIENT_POSIX_FALLOCATE + return posix_fallocate(fd, offset, length); +#else +#error Coding error in SUPPORT_PREALLOCATION logic. +#endif +} +#endif