5
5
* Copyright (C) 1998 Andrew Tridgell
6
6
* Copyright (C) 2002 Martin Pool
7
* Copyright (C) 2003-2009 Wayne Davison
7
* Copyright (C) 2003-2013 Wayne Davison
9
9
* This program is free software; you can redistribute it and/or modify
10
10
* it under the terms of the GNU General Public License as published by
53
58
return unlink(fname);
56
int do_symlink(const char *fname1, const char *fname2)
62
int do_symlink(const char *lnk, const char *fname)
58
64
if (dry_run) return 0;
59
65
RETURN_ERROR_IF_RO_OR_LO;
60
return symlink(fname1, fname2);
67
#if defined NO_SYMLINK_XATTRS || defined NO_SYMLINK_USER_XATTRS
68
/* For --fake-super, we create a normal file with mode 0600
69
* and write the lnk into it. */
71
int ok, len = strlen(lnk);
72
int fd = open(fname, O_WRONLY|O_CREAT|O_TRUNC, S_IWUSR|S_IRUSR);
75
ok = write(fd, lnk, len) == len;
82
return symlink(lnk, fname);
85
#if defined NO_SYMLINK_XATTRS || defined NO_SYMLINK_USER_XATTRS
86
ssize_t do_readlink(const char *path, char *buf, size_t bufsiz)
88
/* For --fake-super, we read the link from the file. */
90
int fd = do_open_nofollow(path, O_RDONLY);
92
int len = read(fd, buf, bufsiz);
98
/* A real symlink needs to be turned into a fake one on the receiving
99
* side, so tell the generator that the link has no length. */
102
/* Otherwise fall through and let the sender report the real length. */
105
return readlink(path, buf, bufsiz);
64
111
int do_link(const char *fname1, const char *fname2)
375
422
#error Need utimes or utime function.
425
#ifdef SUPPORT_PREALLOCATION
426
int do_fallocate(int fd, OFF_T offset, OFF_T length)
428
#ifdef FALLOC_FL_KEEP_SIZE
429
#define DO_FALLOC_OPTIONS FALLOC_FL_KEEP_SIZE
431
#define DO_FALLOC_OPTIONS 0
433
RETURN_ERROR_IF(dry_run, 0);
434
RETURN_ERROR_IF_RO_OR_LO;
435
#if defined HAVE_FALLOCATE
436
return fallocate(fd, DO_FALLOC_OPTIONS, offset, length);
437
#elif defined HAVE_SYS_FALLOCATE
438
return syscall(SYS_fallocate, fd, DO_FALLOC_OPTIONS, (loff_t)offset, (loff_t)length);
439
#elif defined HAVE_EFFICIENT_POSIX_FALLOCATE
440
return posix_fallocate(fd, offset, length);
442
#error Coding error in SUPPORT_PREALLOCATION logic.
447
int do_open_nofollow(const char *pathname, int flags)
450
STRUCT_STAT f_st, l_st;
454
if (flags != O_RDONLY) {
455
RETURN_ERROR_IF(dry_run, 0);
456
RETURN_ERROR_IF_RO_OR_LO;
458
/* This function doesn't support write attempts w/o O_NOFOLLOW. */
465
fd = open(pathname, flags|O_NOFOLLOW);
467
if (do_lstat(pathname, &l_st) < 0)
469
if (S_ISLNK(l_st.st_mode)) {
473
if ((fd = open(pathname, flags)) < 0)
475
if (do_fstat(fd, &f_st) < 0) {
476
close_and_return_error:
478
int save_errno = errno;
484
if (l_st.st_dev != f_st.st_dev || l_st.st_ino != f_st.st_ino) {
486
goto close_and_return_error;