summaryrefslogtreecommitdiff
path: root/src/basic/stat-util.c
Commit message (Collapse)AuthorAgeFilesLines
* detect-virt: add message at debug levelZbigniew Jędrzejewski-Szmek2023-04-211-2/+2
| | | | | | | | | | | | | | | | | | Normal users do not have permissions to access /proc/1/root, so 'systemd-detect-virt -r' fails, but the output, even at debug level is cryptic: $ SYSTEMD_LOG_LEVEL=debug build/systemd-detect-virt -r Failed to check for chroot() environment: Permission denied Let's make this a bit easier to figure out: $ SYSTEMD_LOG_LEVEL=debug build/systemd-detect-virt -r Cannot stat /proc/1/root: Permission denied Failed to check for chroot() environment: Permission denied I looked over other users of files_same(), and I think in general the message at debug level is OK for them too.
* stat-util: Add xstatfsat()Daan De Meyer2023-04-011-0/+14
|
* stat-util: add inode_type_to_string() helper for showing mode_t inode type ↵Lennart Poettering2023-03-291-0/+23
| | | | as string
* basic/stat-util: remove unused null_or_empty_fd()Zbigniew Jędrzejewski-Szmek2023-03-281-11/+0
|
* chase-symlinks: Rename chase_symlinks() to chase()Daan De Meyer2023-03-241-2/+2
| | | | | | | | | Chasing symlinks is a core function that's used in a lot of places so it deservers a less verbose names so let's rename it to chase() and chaseat(). We also slightly change the pattern used for the chaseat() helpers so we get chase_and_openat() and similar.
* stat-util: Add verify_regular_at()Daan De Meyer2023-03-221-0/+12
|
* chase-symlinks: Remove unused ret_fd argumentsDaan De Meyer2023-03-141-1/+1
|
* tree-wide: change initialization to use EBADF instead of EBADFDZbigniew Jędrzejewski-Szmek2022-12-191-1/+1
| | | | | Those fds never were, so it's not fair to say that they are in "bad state". Let's use the shorter and more direct errno.
* tree-wide: use -EBADF for fd initializationZbigniew Jędrzejewski-Szmek2022-12-191-1/+1
| | | | | | | | | | | | | | | | -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.
* stat-util: introduce fd_is_read_only_fs()Yu Watanabe2022-12-151-7/+18
| | | | Then, reimplement path_is_read_only_fs() by the function to avoid race.
* stat-util: Move inode_hash_ops to stat-utilDaan De Meyer2022-11-101-0/+18
| | | | TO make it usable in other code.
* stat-util: add statx_mount_same() to check if two stax refer to the same mountLennart Poettering2022-09-201-0/+13
|
* stat-util: add statx_inode_same() helper to check if two statx structs refer ↵Lennart Poettering2022-09-201-0/+13
| | | | | | | to same inode The same as stat_inode_same(), but for struct statx rather than struct stat.
* stat-util: replace is_dir() + is_dir_fd() by single is_dir_full() callLennart Poettering2022-07-141-14/+6
| | | | | This new call can execute both of the old operations, but also do generic fstatat() like behaviour.
* stat-util: fix dir_is_empty() with hidden/backup filesLennart Poettering2022-05-041-13/+25
| | | | | | | | | | | | | | | | | | | | 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.
* stat-util: ignore hidden_or_backup_file when checking if dir is emptyLuca Boccassi2022-05-011-1/+1
| | | | | | | | | | Commit https://github.com/systemd/systemd/commit/a068aceafbf changed dir_is_emtpy_at to use FOREACH_DIRENT_IN_BUFFER instead of FOREACH_DIRENT, but used dot_or_dotdot which just checks if the name is literally '.' or '..' which is not enough, previous behaviour was to ignore all hidden files, so restore that and add a test case. Fixes https://github.com/systemd/systemd/issues/23220
* basic: split out dev_t related calls into new devno-util.[ch]Lennart Poettering2022-04-131-95/+0
| | | | | | | | | | | | | | No actual code changes, just splitting out of some dev_t handling related calls from stat-util.[ch], they are quite a number already, and deserve their own module now I think. Also, try to settle on the name "devnum" as the name for the concept, instead of "devno" or "dev" or "devid". "devnum" is the name exported in udev APIs, hence probably best to stick to that. (this just renames a few symbols to "devum", local variables are left untouched, to make the patch not too invasive) No actual code changes.
* basic/stat-util: add null_or_empty_path_with_root()Zbigniew Jędrzejewski-Szmek2022-03-291-5/+10
|
* tree-wide: port various places over to new stat_inode_same() helperLennart Poettering2022-02-141-2/+1
|
* stat-util: add helper stat_inode_same() for comparing stat's st_dev/st_ino ↵Lennart Poettering2022-02-141-5/+13
| | | | | | | in one We do this all over the place, hence let's add a simple helper that does this and particularly carefully and thoroughly.
* stat-util: introduce path_is_network_fs()Yu Watanabe2022-02-041-0/+9
|
* tree-wide: explicitly unpoison getdents64() memoryLennart Poettering2021-10-251-0/+2
| | | | | | Apparently memory sanitizer doesn't grok getdents64() properly. Let's address that by explicitly marken memory initialized by getdents64() as unpoisoned.
* stat-util: make sure dir_is_empty_at() does something useful in all casesLennart Poettering2021-10-251-0/+6
|
* stat-util: optimize dir_is_empty_at() a bit, by using getdents64()Lennart Poettering2021-10-251-7/+13
| | | | | | That way we have a single syscall only for it, instead of the multiple readdir() and friends do. And we can operate entirely on the stack, no malloc() implicit.
* stat-util: specify O_DIRECTORY when reopening dir in dir_is_empty_at()Lennart Poettering2021-10-251-1/+1
| | | | | | | | That way we can fail earlier if the specified fd is not actually a directory. (Also, it's not exactly according to standards to open things without either O_RDONLY/O_RDWR...)
* basic: use filesystem databaseIago López Galeiras2021-10-061-10/+5
|
* basic: spit out chase_symlinks() from fs-util.[ch] → chase-symlinks.[ch]Lennart Poettering2021-10-051-1/+2
|
* stat-util: fix dir_is_empty_at without pathLuca Boccassi2021-02-161-5/+10
| | | | | | Use the right FD, and do a fd_reopen instead of a dup, since the latter will still share the internal pointer which then gets moved by FOREACH_DIRENT, affecting the caller's FD.
* stat-util: don't try to open path on path_is_temporary_fs()Lennart Poettering2021-01-061-4/+3
| | | | | I mean, the old code at least used O_PATH, but still, we shouldn't allocate/close an fd if we don't have to.
* Merge pull request #17431 from msekletar/udev-link-update-raceZbigniew Jędrzejewski-Szmek2020-11-101-1/+2
|\ | | | | udev: make algorithm that selects highest priority devlink less susceptible to race conditions
| * basic/stat-util: make mtime check stricter and use entire timestampMichal Sekletár2020-11-061-1/+2
| | | | | | | | | | | | | | | | | | | | Note that st_mtime member of struct stat is defined as follows, #define st_mtime st_mtim.tv_sec Hence we omitted checking nanosecond part of the timestamp (struct timespec) and possibly would miss modifications that happened within the same second.
* | license: LGPL-2.1+ -> LGPL-2.1-or-laterYu Watanabe2020-11-091-1/+1
|/
* stat-util: provide single fallback implementation of statx()Lennart Poettering2020-09-031-0/+57
| | | | | | This simplifies things quite a bit, and is reusable wherever we want to use statx() later on. Not sure why I didn't do it like this right from the beginning...
* stat-util: trivial empty_or_null() tweaksLennart Poettering2020-05-291-3/+7
| | | | | To small tweaks: /dev/null is definitely a char device. And if we have the path, to a string base comparison first.
* stat-util: add stat_inode_unmodified() helper that checks if an inode was ↵Lennart Poettering2020-05-131-0/+21
| | | | modified
* stat-util: add simpler helper for checking if /proc/ is mountedLennart Poettering2020-04-231-0/+12
|
* stat-util: no need to open a file to check fs typeLennart Poettering2020-04-231-4/+3
|
* *: convert amenable fdopendir() calls to take_fdopendir()Vito Caputo2020-03-311-2/+2
| | | | | | | Some fdopendir() calls remain where safe_close() is manually performed, those could be simplified as well by converting to use the _cleanup_close_ machinery, but makes things less trivial to review so left for a future cleanup.
* tree-wide: drop magic.h when missing_magic.h is includedYu Watanabe2019-11-041-1/+0
|
* tree-wide: drop stat.h or statfs.h when stat-util.h is includedYu Watanabe2019-11-041-1/+0
|
* tree-wide: drop dirent.h when dirent-util.h is includedYu Watanabe2019-11-041-1/+0
|
* tree-wide: drop missing.hYu Watanabe2019-10-311-1/+2
|
* basic/fs-util: change CHASE_OPEN flag into a separate output parameterZbigniew Jędrzejewski-Szmek2019-10-241-1/+1
| | | | | | | | | | | | | 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.)
* util: split out namespace related stuff into a new namespace-util.[ch] pairLennart Poettering2019-03-131-46/+0
| | | | Just some minor reorganiztion.
* Merge pull request #11345 from kirbyfan64/tmpfiles-c-emptyZbigniew Jędrzejewski-Szmek2019-01-151-3/+12
|\ | | | | tmpfiles: Make C still copy if the destination directory is empty
| * stat-util: Add dir_is_empty_atRyan Gonzalez2019-01-081-3/+12
| |
* | stat-util: remove spurious newlineLennart Poettering2019-01-071-1/+0
|/
* stat-util: add new APIs device_path_make_{major_minor|canonical}() and ↵Lennart Poettering2018-11-291-0/+98
| | | | | | | | | | | | | | | | | | | | device_path_parse_major_minor() device_path_make_{major_minor|canonical) generate device node paths given a mode_t and a dev_t. We have similar code all over the place, let's unify this in one place. The former will generate a "/dev/char/" or "/dev/block" path, and never go to disk. The latter then goes to disk and resolves that path to the actual path of the device node. device_path_parse_major_minor() reverses device_path_make_major_minor(), also withozut going to disk. We have similar code doing something like this at various places, let's unify this in a single set of functions. This also allows us to teach them special tricks, for example handling of the /run/systemd/inaccessible/{blk|chr} device nodes, which we use for masking device nodes, and which do not exist in /dev/char/* and /dev/block/*
* stat-util: add fd_verify_directory(), similar to fd_verify_regular()Lennart Poettering2018-11-261-0/+23
|
* nspawn: beef up netns checking a bit, for compat with old kernelsLennart Poettering2018-10-311-4/+36
| | | | Fixes: #10544