summaryrefslogtreecommitdiff
path: root/src/basic/fs-util.h
Commit message (Collapse)AuthorAgeFilesLines
* fs-util: Add xopenat_lock()Daan De Meyer2023-03-221-0/+3
| | | | open/create a file/directory and lock it using the given lock type.
* fs-util: Add open_parent_at()Daan De Meyer2023-03-211-1/+4
|
* Merge pull request #26784 from DaanDeMeyer/chase-fixDaan De Meyer2023-03-151-0/+2
|\ | | | | Allow creating files and directories with chase_symlinks_open() and further improvements
| * fs-util: Add xopenat()Daan De Meyer2023-03-141-0/+2
| | | | | | | | | | xopenat() will create directories if O_DIRECTORY and O_CREAT are specified. Note that this is not an atomic operation.
* | fs-util: Drop unlink_noerrno()Daan De Meyer2023-03-151-3/+1
|/
* fs-util: Add chown_and_chmod_at()Daan De Meyer2022-11-091-1/+4
|
* fs-util: add mknodat_atomic()Lennart Poettering2022-09-231-1/+6
|
* fs-util: make mkfifo_atomic() just a shortcut for mkfifoat_atomic()Lennart Poettering2022-09-231-1/+3
|
* fs-util: replace symlink_atomic() by symlinkat_atomic()Lennart Poettering2022-09-231-2/+2
|
* fs-util,label: introduce symlink_atomic_full() and symlink_atomic_full_label()Yu Watanabe2022-09-141-1/+4
| | | | These new functions optionally create symlink of relative path.
* fs-util: make touch() an inline functionLennart Poettering2022-08-171-1/+5
|
* fs-util: add openat_report_new() wrapper around openat()Lennart Poettering2022-03-211-0/+2
| | | | | | This is a wrapper around openat(). It works mostly the same, except for one thing: it race-freely reports whether we just created the indicated file in case O_CREAT is passed without O_EXCL.
* fs-util: add new helper open_mkdir_at()Lennart Poettering2021-11-171-0/+2
|
* tree-wide: use new RET_NERRNO() helper at various placesLennart Poettering2021-11-161-1/+1
|
* fs-util: add helper that can split CIFS services namesLennart Poettering2021-10-271-0/+2
|
* basic: spit out chase_symlinks() from fs-util.[ch] → chase-symlinks.[ch]Lennart Poettering2021-10-051-23/+0
|
* basic: split out inotify-related calls from fs-util.h → inotify-util.hLennart Poettering2021-10-051-16/+0
|
* basic: split out sync() family of calls from fs-util.[ch] into new c/h fileLennart Poettering2021-10-051-8/+0
| | | | No changes in code, just some splitting out.
* fs-util: add fsync_path_and_parent_at()Lennart Poettering2021-07-081-0/+1
|
* fs-util: add API for fsync()ing parent dir of pathLennart Poettering2021-07-081-0/+1
|
* basic,shared: move a bunch of files to src/shared/Zbigniew Jędrzejewski-Szmek2021-06-241-2/+0
| | | | | | | | | | | | 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.
* tmpfiles: add '=' action modifier.Allen Webb2021-06-081-0/+2
| | | | | | | | | | | Add the '=' action modifier that instructs tmpfiles.d to check the file type of a path and remove objects that do not match before trying to open or create the path. BUG=chromium:1186405 TEST=./test/test-systemd-tmpfiles.py "$(which systemd-tmpfiles)" Change-Id: If807dc0db427393e9e0047aba640d0d114897c26
* basic: allow copy_rights() to work without mounted /procZbigniew Jędrzejewski-Szmek2021-05-241-1/+4
| | | | This will be used in sysusers later on.
* journald: Retry if posix_fallocate returned -1 (EINTR)Igor Zhbanov2021-04-211-0/+2
| | | | | | | | | | | | | | | | | | | On some conditions (particularly when mobile CPUs are going to sleep), the posix_fallocate(), which is called when a new journal file is allocated, can return -1 (EINTR). This is counted as a fatal error. So the journald closes both old and journals, and simply throwing away further incoming events, because of no log files open. Introduce posix_fallocate_loop() that restarts the function in the case of EINTR. Also let's make code base more uniform by returning negative values on error. Fix assert in test-sigbus.c that incorrectly counted positive values as success. After changing the function return values, that will actually work. Fixes: #19041 Signed-off-by: Igor Zhbanov <i.zhbanov@omprussia.ru>
* tree-wide: coccinelle fixesFrantisek Sumsal2021-03-181-4/+3
| | | | Another batch of fixes (mostly) generated by Coccinelle.
* fs-util: rename conservative_rename() -> conservative_renameat()Yu Watanabe2021-01-221-1/+4
| | | | And this introduces conservative_rename() which does not take dirfd.
* fs-util/rm-rf: improve remove+free destructors to take and return NULLLennart Poettering2021-01-191-2/+11
| | | | | | Let#s make these helpers useful even without _cleanup_ logic, to destory arbitary fields: make them OK wiht a NULL pointer as input, and always return one as output.
* fs-util: make laccess() macro follow our usual error propagationLennart Poettering2021-01-151-1/+2
| | | | | | | | | | | | Functions defined by us are supposed to return negative errno-style errors on errors. laccess() is for access() what lstat() is for stat(), but defined by us as a macro. This led to some confusion regarding error handling. Let's return a negative errno code just in case. This means callers can it use either way: like access(), i.e. checking for a negative return value + looking at errno, or like our own code, i.e. using the negative errno code it returns.
* fs-util: add conservative_rename() that suppresses unnecessary renamesLennart Poettering2020-12-021-0/+2
| | | | | | | | if the source and destination file match in contents and basic file attributes, don#t rename, but just remove source. This is a simple way to suppress inotify events + mtime changes when atomically updating files.
* license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|
* Merge pull request #17172 from keszybz/read-login-defsLennart Poettering2020-10-021-1/+1
|\ | | | | Read /etc/login.defs
| * basic/fileio: add chase_symlinks_and_fopen_unlocked()Zbigniew Jędrzejewski-Szmek2020-10-011-1/+1
| |
* | fs-util: add new futimens_opath() helperLennart Poettering2020-09-281-0/+2
|/ | | | futimens() that works for O_PATH fds.
* fs-util: drop chmod_and_chown_unsafe() which is unused nowLennart Poettering2020-09-231-1/+0
|
* fs-util: add stat_warn_permissions() that operates on struct stat instead of fdLennart Poettering2020-06-021-0/+1
|
* fs-util: teach unlinkat_deallocate() a simple scheme for overwriting for erasingLennart Poettering2020-05-191-1/+7
| | | | With that it becomes useful for deleting password files and such.
* fs-util: add helper path_is_encrypted() that checks if a file system is ↵Lennart Poettering2020-05-071-0/+2
| | | | encrypted
* tree-wide: spellcheck using codespellZbigniew Jędrzejewski-Szmek2020-04-161-1/+1
| | | | Fixes #15436.
* basic/fs-util: add a version of chmod_and_chown that doesn not use /procZbigniew Jędrzejewski-Szmek2020-03-031-0/+1
|
* basic/fs-util: change CHASE_OPEN flag into a separate output parameterZbigniew Jędrzejewski-Szmek2019-10-241-9/+7
| | | | | | | | | | | | | chase_symlinks() would return negative on error, and either a non-negative status or a non-negative fd when CHASE_OPEN was given. This made the interface quite complicated, because dependning on the flags used, we would get two different "types" of return object. Coverity was always confused by this, and flagged every use of chase_symlinks() without CHASE_OPEN as a resource leak (because it would this that an fd is returned). This patch uses a saparate output parameter, so there is no confusion. (I think it is OK to have functions which return either an error or an fd. It's only returning *either* an fd or a non-fd that is confusing.)
* fs-util: introduce inotify_add_watch_and_warn() helperFranck Bui2019-10-051-0/+1
| | | | | | | | The default message for ENOSPC is very misleading: it says that the disk is filled, but in fact the inotify watch limit is the problem. So let's introduce and use a wrapper that simply calls inotify_add_watch(2) and which fixes the error message up in case ENOSPC is returned.
* Merge pull request #13194 from keszybz/chase-symlinks-testingLennart Poettering2019-07-261-8/+10
|\ | | | | Chase symlinks testing
| * fs-util: CHASE_NOFOLLOW is not limited to CHASE_OPENZbigniew Jędrzejewski-Szmek2019-07-261-2/+3
| | | | | | | | | | | | | | | | | | | | $ build/test-chase-symlinks /etc/os-release /etc/os-release → /usr/lib/os-release $ build/test-chase-symlinks --nofollow /etc/os-release /etc/../etc/os-release /etc/../etc/./././os-release /etc/os-release → /etc/os-release /etc/../etc/os-release → /etc/os-release /etc/../etc/./././os-release → /etc/os-release
| * fs-util: adjust punctuation in commentsZbigniew Jędrzejewski-Szmek2019-07-191-8/+9
| |
* | fs-util: add fsync_full() helperLennart Poettering2019-07-251-0/+1
|/ | | | | We usually combine an fsync() with fsync_directory_of_file() hence let's add a helper that does both in one.
* util: introduce PTR_TO_MODE and MODE_TO_PTR macrosYu Watanabe2019-05-301-0/+7
|
* fs-util.h: add missing sys/stat includeAndrej Valek2019-05-171-0/+1
| | | | | fix error: | error: passing argument 5 of 'chase_symlinks_and_stat' from incompatible pointer type [-Werror=incompatible-pointer-types]
* util: split out errno related stuffLennart Poettering2019-03-141-1/+1
|
* fs-util: add new helper syncfs_path()Lennart Poettering2019-03-011-0/+2
|
* fs-util: add new CHASE_WARN flag to chase_symlinks()Franck Bui2018-11-301-0/+1
| | | | | | | | | | This flag can be used to make chase_symlinks() emit a warning when it encounters an error. Such flag can be useful for generating a comprehensive and detailed warning since chase_symlinks() can generate a warning with a full context. For now only warnings for unsafe transitions are produced.