summaryrefslogtreecommitdiff
path: root/src/shared/copy.c
Commit message (Collapse)AuthorAgeFilesLines
* copy: shortcut reflink_range() to reflink() in some casesLennart Poettering2023-04-281-0/+6
|
* copy: don't call clone ioctls twiceLennart Poettering2023-04-281-9/+5
| | | | | The btrfs name and the generic name have the same values, hence there's no point in bothering with the former.
* copy: rename reflink_full() -> reflink_range()Yu Watanabe2023-04-281-2/+2
| | | | | | | | | | | | The commit b640e274a7c363a2b6394c9dce5671d9404d2e2a introduced reflink() and reflink_full(). We usually name function xyz_full() for fully parameterized version of xyz(), and xyz() is typically a inline alias of xyz_full(). But in this case, reflink() and reflink_full() call different ioctl(). Moreover, reflink_full() does partial reflink, while reflink() does full file reflink. That's super confusing. Let's rename reflink_full() to reflink_range(), the new name is consistent with ioctl name, and should be fine.
* copy: Introduce reflink() and reflink_full()Daan De Meyer2023-04-281-2/+51
| | | | | | The kernel has had filesystem independent reflink ioctls for a while now, let's try to use them and fall back to the btrfs specific ones if they're not supported.
* copy: make copy_bytes() support O_PATH fdsYu Watanabe2023-04-111-0/+8
|
* copy: Add more at() helpersDaan De Meyer2023-03-211-9/+13
|
* tmpfile-util: teach link_tmpfile() to optionally replace filesLennart Poettering2023-03-031-42/+10
|
* copy: Support both inode exclusion and contents exclusionDaan De Meyer2023-02-221-6/+19
| | | | | | | | | | | | In some cases, we want to exclude a directory's contents but not the directory itself. In other cases, we want to exclude a directory and its contents. Let's extend the denylist logic in copy.h to support both by changing the denylist from a set to hashmap so we can store the deny type as the value. We also modify the repart ExcludeFiles= option to make use of this. If a directory to exclude ends with a "/", we'll only exclude its contents. Otherwise, we'll exclude the full directory.
* copy: Add copy_file_at()Daan De Meyer2023-02-201-6/+10
|
* copy: Copy symlink xattrsDaan De Meyer2023-02-141-0/+1
| | | | | Symlinks can have xattrs as well, let's make sure we copy those as well.
* copy: Make copy_xattr() more genericDaan De Meyer2023-02-141-8/+8
| | | | | Let's make copy_xattr() a little more generic in preparation for copying symlink xattrs.
* tree-wide: use -EBADF moreYu Watanabe2022-12-211-1/+1
|
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-7/+7
| | | | | | | | | | | | | | | | -1 was used everywhere, but -EBADF or -EBADFD started being used in various places. Let's make things consistent in the new style. Note that there are two candidates: EBADF 9 Bad file descriptor EBADFD 77 File descriptor in bad state Since we're initializating the fd, we're just assigning a value that means "no fd yet", so it's just a bad file descriptor, and the first errno fits better. If instead we had a valid file descriptor that became invalid because of some operation or state change, the other errno would fit better. In some places, initialization is dropped if unnecessary.
* treewide: drop "RUN_" from "RUN_WITH_UMASK"Zbigniew Jędrzejewski-Szmek2022-12-131-1/+1
| | | | | | RUN_WITH_UMASK was initially conceived for spawning externals progs with the umask set. But nowadays we use it various syscalls and stuff that doesn't "run" anything, so the "RUN_" prefix has outlived its usefulness.
* copy: Add COPY_GRACEFUL_WARNDaan De Meyer2022-12-011-9/+27
| | | | | | | When copying between filesystems, sometimes the target filesystem might not support symlinks/fifos/sockets/... and we want to log and ignore any failures to copy such files when copying. Let's introduce a new flag to enable this behavior.
* nulstr-util: Declare NULSTR_FOREACH() iterator inlineDaan De Meyer2022-11-111-1/+0
|
* copy: Support passing a deny list of files/directories to not copyDaan De Meyer2022-11-101-5/+21
|
* copy: Respect COPY_REPLACE flag for copy_treeAlexander Wilson2022-07-271-2/+10
| | | | | - Add a test that asserts that copy_tree on an existing file will fail without COPY_REPLACE - Add a test that asserts that copy_tree with COPY_MERGE and COPY_REPLACE on an existing directory will overwrite files that already exist.
* copy.[ch]: RefactorAlexander Wilson2022-07-271-23/+75
| | | | | | - Refactor: Move HardlinkContext to header file - Refactor: Create `fd_copy_tree_generic` which isolates the functionality to check stat type and appropriately copy. - Refactor: Create `fd_copy_leaf` which handles copying leaf nodes of a file tree.
* stat-util: fix dir_is_empty() with hidden/backup filesLennart Poettering2022-05-041-1/+1
| | | | | | | | | | | | | | | | | | | | This is a follow-up for f470cb6d13558fc06131dc677d54a089a0b07359 which in turn is a follow-up for a068aceafbffcba85398cce636c25d659265087a. The latter started to honour hidden files when deciding whether a directory is empty. The former reverted to the old behaviour to fix issue #23220. It introduced a bug though: when a directory contains a larger number of hidden entries the getdents64() buffer will not suffice to read them, since we just allocate three entries for it (which is definitely enough if we just ignore the . + .. entries, but not ig we ignore more). I think it's a bit confusing that dir_is_empty() can return true even if rmdir() on the dir would return ENOTEMPTY. Hence, let's rework the function to make it optional whether hidden files are ignored or not. After all, I looking at the users of this function I am pretty sure in more cases we want to honour hidden files.
* copy: use FLAGS_SET() in copy_xattr()Franck Bui2022-03-141-1/+1
|
* copy: fix wrong argument passed to S_ISREG() in copy_file_fd_full()Franck Bui2022-03-141-1/+4
| | | | Follow-up for 2f782044986a30bf73f1fe00209dbd204b3efe33.
* shared: Handle filesystems that don't support hole punching in COPY_HOLESDaan De Meyer2022-01-311-2/+4
|
* shared: Ensure COPY_HOLES copies trailing holesDaan De Meyer2022-01-271-2/+44
| | | | | | | | | | Previously, files with a hole at the end would get silently truncated which breaks reading journal files. This commit makes sure that holes are punched in existing space and if no more space is available, that we grow the file and the hole by using ftruncate(). The corresponding test is extended to put a hole at the end of the file and we make sure that hole is copied correctly.
* journal: Copy holes when archiving BTRFS journal filesDaan De Meyer2022-01-171-11/+10
| | | | | | | | | | | Previously, the holes we punched earlier would get removed when copying the file. Let's enable the new COPY_HOLES flag to make sure this doesn't happen. In my test, this drops a 800MB btrfs journal (without compression) to 720 MB. Fixes #22087
* shared: Copy holes in sparse files in copy_bytes_full()Daan De Meyer2022-01-141-0/+41
| | | | | | Previously, all holes in sparse files copied with copy_bytes_full() would be expanded in the target file. Now, we correctly detect holes in the input file and we replicate them in the target file.
* tree-wide: make FOREACH_DIRENT_ALL define the iterator variableZbigniew Jędrzejewski-Szmek2021-12-151-1/+0
| | | | | | | | | The variable is not useful outside of the loop (it'll always be null after the loop is finished), so we can declare it inline in the loop. This saves one variable declaration and reduces the chances that somebody tries to use the variable outside of the loop. For consistency, 'de' is used everywhere for the var name.
* tree-wide: port various places over to open_mkdir_at()Lennart Poettering2021-11-171-11/+3
|
* shared: clean up mkdir.h/label.h situationLennart Poettering2021-11-161-0/+1
| | | | | | | | | | Previously the mkdir_label() family of calls was implemented in src/shared/mkdir-label.c but its functions partly declared ins src/shared/label.h and partly in src/basic/mkdir.h (!!). That's weird (and wrong). Let's clean this up, and add a proper mkdir-label.h matching the .c file.
* tree-wide: use new RET_NERRNO() helper at various placesLennart Poettering2021-11-161-4/+1
|
* basic: split out sync() family of calls from fs-util.[ch] into new c/h fileLennart Poettering2021-10-051-0/+1
| | | | No changes in code, just some splitting out.
* shared/copy: add a new flag COPY_ALL_XATTRSAndrej Lajovic2021-08-111-6/+6
| | | | | | | | When the flag COPY_ALL_XATTRS is set, it causes the complete set of xattrs to be copied. If the flag is unset, only xattrs from the "user" namespace are copied. Fixes #17178.
* copy: add COPY_SIGTERM, matching the existing COPY_SIGINTLennart Poettering2021-08-021-15/+24
|
* copy: add COPY_SYNCFS flagLennart Poettering2021-08-021-11/+27
| | | | | | | | | When copying large directory trees it should be a better idea to sync the whole fs once when we are done instead of individually for each file, hence add COPY_SYNCFS. As opposed to COPY_FSYNC/COPY_FSYNC_FULL this only really applies to the top-level directory, after completion of the whole copy.
* copy: optionally fsync() files after copying themLennart Poettering2021-08-021-7/+107
| | | | | | As a safety precaution it makes sense to fsync() files after copying them, and maybe even the directories they are contained in. Let's add a flag for these two cases.
* copy: tighten destination checks when copying filesLennart Poettering2021-08-021-6/+27
| | | | | | | | let's make sure we only operate on regular files when copying files. Also, make sure to copy file attributes only over if target is a regular file (so that copying a file to /dev/null won't alter the access mode/ownership of that device node...)
* copy: move to single clean-up pathLennart Poettering2021-08-021-21/+33
| | | | | | | | | (This might not look like a big improvement, but will shortly, when we add fsync() support to the copy logic, at which point there are more error paths we can unify that way.) While we are at it, tweak a clean-up path: only unlink a copied file if we are definitely the ones who created them, i.e. if O_EXCL is set.
* copy: port over to pop_pending_signal()Lennart Poettering2021-07-081-18/+3
|
* remove a left-over breakDavid Tardon2021-06-251-1/+0
| | | | | | | By the "same logic as above...", we want to continue to fallback here, but the break prohibits that. This is a follow-up for ee1aa61c4710ae567a2b844e0f0bb8cb0456ab8c .
* basic,shared: move a bunch of files to src/shared/Zbigniew Jędrzejewski-Szmek2021-06-241-0/+1286
| | | | | | | | | | | | The goal is to move everything that requires selinux or smack away from src/basic/. This means that src/basic/label.[ch] must move, which implies btrfs-util.[ch], copy.[ch], and a bunch of other files which form a cluster of internal use. This is just moving text around, so there should be no functional difference. test-blockdev-util is new, because path_is_encrypted() is moved to blockdev-util.c, and so far we didn't have any tests for code there.
* build-sys: split internal basic/ library from shared/Kay Sievers2015-06-111-507/+0
| | | | | | | | | | basic/ can be used by everything cannot use anything outside of basic/ libsystemd/ can use basic/ cannot use shared/ shared/ can use libsystemd/
* util: merge change_attr_fd() and chattr_fd()Lennart Poettering2015-04-081-1/+1
|
* fix gcc warnings about uninitialized variablesHarald Hoyer2015-03-271-3/+3
| | | | | | | | | | | | | like: src/shared/install.c: In function ‘unit_file_lookup_state’: src/shared/install.c:1861:16: warning: ‘r’ may be used uninitialized in this function [-Wmaybe-uninitialized] return r < 0 ? r : state; ^ src/shared/install.c:1796:13: note: ‘r’ was declared here int r; ^
* tree-wide: there is no ENOTSUP on linuxDavid Herrmann2015-03-131-2/+2
| | | | Replace ENOTSUP by EOPNOTSUPP as this is what linux actually uses.
* util: add rename_noreplaceAlban Crequy2015-03-101-3/+9
| | | | | | | | | renameat2() exists since Linux 3.15 but btrfs support for the flag RENAME_NOREPLACE was added later. This patch implements a fallback when renameat2() returns EINVAL. EINVAL is the error returned when the filesystem does not support one of the flags.
* util: the chattr flags field is actually unsigned, judging by kernel sourcesLennart Poettering2015-01-141-2/+2
| | | | Unlike some client code suggests...
* machined: when cloning a raw disk image, also set the NOCOW flagLennart Poettering2015-01-081-3/+6
|
* machinectl/machined: implement "rename", "clone", "read-only" verbs for ↵Lennart Poettering2014-12-281-6/+40
| | | | machine images
* copy: try top copy atime/time/xattrs when copying filesLennart Poettering2014-12-261-1/+102
|
* machinectl: add new commands for copying files from/to containersLennart Poettering2014-12-181-9/+15
|