mirror of
https://github.com/morgan9e/systemd
synced 2026-04-14 08:25:20 +09:00
mountpoint-util: rename fd_is_mount_point() to is_mount_point_at()
fd_* functions in our codebase usually mean fd-specific operations, while this one actually takes openat()-style params. Rename it accordingly hence.
This commit is contained in:
@@ -212,7 +212,7 @@ bool file_handle_equal(const struct file_handle *a, const struct file_handle *b)
|
||||
return memcmp_nn(a->f_handle, a->handle_bytes, b->f_handle, b->handle_bytes) == 0;
|
||||
}
|
||||
|
||||
int fd_is_mount_point(int fd, const char *filename, int flags) {
|
||||
int is_mount_point_at(int fd, const char *filename, int flags) {
|
||||
bool fd_is_self;
|
||||
int r;
|
||||
|
||||
@@ -376,7 +376,7 @@ int path_is_mount_point_full(const char *path, const char *root, int flags) {
|
||||
if (path_equal(path, "/"))
|
||||
return 1;
|
||||
|
||||
/* we need to resolve symlinks manually, we can't just rely on fd_is_mount_point() to do that for us;
|
||||
/* we need to resolve symlinks manually, we can't just rely on is_mount_point_at() to do that for us;
|
||||
* if we have a structure like /bin -> /usr/bin/ and /usr is a mount point, then the parent that we
|
||||
* look at needs to be /usr, not /. */
|
||||
if (FLAGS_SET(flags, AT_SYMLINK_FOLLOW)) {
|
||||
@@ -391,7 +391,7 @@ int path_is_mount_point_full(const char *path, const char *root, int flags) {
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
return fd_is_mount_point(fd, last_path_component(path), flags);
|
||||
return is_mount_point_at(fd, last_path_component(path), flags);
|
||||
}
|
||||
|
||||
int path_get_mnt_id_at_fallback(int dir_fd, const char *path, int *ret) {
|
||||
|
||||
@@ -49,7 +49,7 @@ static inline int path_get_mnt_id(const char *path, int *ret) {
|
||||
return path_get_mnt_id_at(AT_FDCWD, path, ret);
|
||||
}
|
||||
|
||||
int fd_is_mount_point(int fd, const char *filename, int flags);
|
||||
int is_mount_point_at(int fd, const char *filename, int flags);
|
||||
int path_is_mount_point_full(const char *path, const char *root, int flags);
|
||||
static inline int path_is_mount_point(const char *path) {
|
||||
return path_is_mount_point_full(path, NULL, 0);
|
||||
|
||||
@@ -384,7 +384,7 @@ int recurse_dir(
|
||||
if (sx_valid && FLAGS_SET(sx.stx_attributes_mask, STATX_ATTR_MOUNT_ROOT))
|
||||
is_mount = FLAGS_SET(sx.stx_attributes, STATX_ATTR_MOUNT_ROOT);
|
||||
else {
|
||||
r = fd_is_mount_point(dir_fd, de->entries[i]->d_name, 0);
|
||||
r = is_mount_point_at(dir_fd, de->entries[i]->d_name, 0);
|
||||
if (r < 0)
|
||||
log_debug_errno(r, "Failed to determine whether %s is a submount, assuming not: %m", p);
|
||||
|
||||
|
||||
@@ -1762,7 +1762,7 @@ static int action_umount(const char *path) {
|
||||
if (fd < 0)
|
||||
return log_error_errno(fd, "Failed to resolve path '%s': %m", path);
|
||||
|
||||
r = fd_is_mount_point(fd, NULL, 0);
|
||||
r = is_mount_point_at(fd, NULL, 0);
|
||||
if (r == 0)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "'%s' is not a mount point", canonical);
|
||||
if (r < 0)
|
||||
|
||||
@@ -1147,7 +1147,7 @@ static int fd_copy_directory(
|
||||
if (buf.st_dev != original_device)
|
||||
continue;
|
||||
|
||||
r = fd_is_mount_point(dirfd(d), de->d_name, 0);
|
||||
r = is_mount_point_at(dirfd(d), de->d_name, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0)
|
||||
|
||||
@@ -329,7 +329,7 @@ int machine_id_commit(const char *root) {
|
||||
if (!etc_machine_id)
|
||||
return log_oom();
|
||||
|
||||
r = fd_is_mount_point(etc_fd, "machine-id", /* flags= */ 0);
|
||||
r = is_mount_point_at(etc_fd, "machine-id", /* flags= */ 0);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to determine whether %s is a mount point: %m", etc_machine_id);
|
||||
if (r == 0) {
|
||||
|
||||
@@ -1346,7 +1346,7 @@ int fd_make_mount_point(int fd) {
|
||||
|
||||
assert(fd >= 0);
|
||||
|
||||
r = fd_is_mount_point(fd, NULL, 0);
|
||||
r = is_mount_point_at(fd, NULL, 0);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to determine whether file descriptor is a mount point: %m");
|
||||
if (r > 0)
|
||||
|
||||
@@ -97,7 +97,7 @@ int pcrextend_file_system_word(const char *path, char **ret_word, char **ret_nor
|
||||
if (dfd < 0)
|
||||
return log_error_errno(dfd, "Failed to open path '%s': %m", path);
|
||||
|
||||
r = fd_is_mount_point(dfd, NULL, 0);
|
||||
r = is_mount_point_at(dfd, NULL, 0);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to determine if path '%s' is mount point: %m", normalized_path);
|
||||
if (r == 0)
|
||||
|
||||
@@ -219,7 +219,7 @@ static int rm_rf_inner_child(
|
||||
return 0;
|
||||
|
||||
/* Stop at mount points */
|
||||
r = fd_is_mount_point(fd, fname, 0);
|
||||
r = is_mount_point_at(fd, fname, 0);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0)
|
||||
|
||||
@@ -452,14 +452,14 @@ TEST(fd_make_mount_point) {
|
||||
fd = open(s, O_PATH|O_CLOEXEC);
|
||||
assert_se(fd >= 0);
|
||||
|
||||
assert_se(fd_is_mount_point(fd, NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(is_mount_point_at(fd, NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
|
||||
assert_se(fd_make_mount_point(fd) > 0);
|
||||
|
||||
/* Reopen the inode so that we end up on the new mount */
|
||||
fd2 = open(s, O_PATH|O_CLOEXEC);
|
||||
|
||||
assert_se(fd_is_mount_point(fd2, NULL, AT_SYMLINK_FOLLOW) > 0);
|
||||
assert_se(is_mount_point_at(fd2, NULL, AT_SYMLINK_FOLLOW) > 0);
|
||||
|
||||
assert_se(fd_make_mount_point(fd2) == 0);
|
||||
|
||||
|
||||
@@ -271,7 +271,7 @@ TEST(path_is_mount_point) {
|
||||
assert_se(rm_rf(tmp_dir, REMOVE_ROOT|REMOVE_PHYSICAL) == 0);
|
||||
}
|
||||
|
||||
TEST(fd_is_mount_point) {
|
||||
TEST(is_mount_point_at) {
|
||||
_cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL;
|
||||
_cleanup_free_ char *pwd = NULL;
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
@@ -281,42 +281,42 @@ TEST(fd_is_mount_point) {
|
||||
assert_se(fd >= 0);
|
||||
|
||||
/* Not allowed, since "/" is a path, not a plain filename */
|
||||
assert_se(fd_is_mount_point(fd, "/", 0) == -EINVAL);
|
||||
assert_se(fd_is_mount_point(fd, "..", 0) == -EINVAL);
|
||||
assert_se(fd_is_mount_point(fd, "../", 0) == -EINVAL);
|
||||
assert_se(fd_is_mount_point(fd, "/proc", 0) == -EINVAL);
|
||||
assert_se(fd_is_mount_point(fd, "/proc/", 0) == -EINVAL);
|
||||
assert_se(fd_is_mount_point(fd, "proc/sys", 0) == -EINVAL);
|
||||
assert_se(fd_is_mount_point(fd, "proc/sys/", 0) == -EINVAL);
|
||||
assert_se(is_mount_point_at(fd, "/", 0) == -EINVAL);
|
||||
assert_se(is_mount_point_at(fd, "..", 0) == -EINVAL);
|
||||
assert_se(is_mount_point_at(fd, "../", 0) == -EINVAL);
|
||||
assert_se(is_mount_point_at(fd, "/proc", 0) == -EINVAL);
|
||||
assert_se(is_mount_point_at(fd, "/proc/", 0) == -EINVAL);
|
||||
assert_se(is_mount_point_at(fd, "proc/sys", 0) == -EINVAL);
|
||||
assert_se(is_mount_point_at(fd, "proc/sys/", 0) == -EINVAL);
|
||||
|
||||
/* This one definitely is a mount point */
|
||||
assert_se(fd_is_mount_point(fd, "proc", 0) > 0);
|
||||
assert_se(fd_is_mount_point(fd, "proc/", 0) > 0);
|
||||
assert_se(is_mount_point_at(fd, "proc", 0) > 0);
|
||||
assert_se(is_mount_point_at(fd, "proc/", 0) > 0);
|
||||
|
||||
safe_close(fd);
|
||||
fd = open("/tmp", O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY);
|
||||
assert_se(fd >= 0);
|
||||
|
||||
assert_se(mkdtemp_malloc("/tmp/not-mounted-XXXXXX", &tmpdir) >= 0);
|
||||
assert_se(fd_is_mount_point(fd, basename(tmpdir), 0) == 0);
|
||||
assert_se(fd_is_mount_point(fd, strjoina(basename(tmpdir), "/"), 0) == 0);
|
||||
assert_se(is_mount_point_at(fd, basename(tmpdir), 0) == 0);
|
||||
assert_se(is_mount_point_at(fd, strjoina(basename(tmpdir), "/"), 0) == 0);
|
||||
|
||||
safe_close(fd);
|
||||
fd = open("/proc", O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY);
|
||||
assert_se(fd >= 0);
|
||||
|
||||
ASSERT_OK_POSITIVE(fd_is_mount_point(fd, NULL, 0));
|
||||
ASSERT_OK_POSITIVE(fd_is_mount_point(fd, "", 0));
|
||||
ASSERT_OK_POSITIVE(fd_is_mount_point(fd, ".", 0));
|
||||
ASSERT_OK_POSITIVE(fd_is_mount_point(fd, "./", 0));
|
||||
ASSERT_OK_ZERO(fd_is_mount_point(fd, "version", 0));
|
||||
ASSERT_OK_POSITIVE(is_mount_point_at(fd, NULL, 0));
|
||||
ASSERT_OK_POSITIVE(is_mount_point_at(fd, "", 0));
|
||||
ASSERT_OK_POSITIVE(is_mount_point_at(fd, ".", 0));
|
||||
ASSERT_OK_POSITIVE(is_mount_point_at(fd, "./", 0));
|
||||
ASSERT_OK_ZERO(is_mount_point_at(fd, "version", 0));
|
||||
|
||||
ASSERT_OK(safe_getcwd(&pwd));
|
||||
ASSERT_OK_ERRNO(fchdir(fd));
|
||||
|
||||
ASSERT_OK_POSITIVE(fd_is_mount_point(AT_FDCWD, NULL, 0));
|
||||
ASSERT_OK_POSITIVE(fd_is_mount_point(AT_FDCWD, "", 0));
|
||||
ASSERT_OK_POSITIVE(fd_is_mount_point(AT_FDCWD, "./", 0));
|
||||
ASSERT_OK_POSITIVE(is_mount_point_at(AT_FDCWD, NULL, 0));
|
||||
ASSERT_OK_POSITIVE(is_mount_point_at(AT_FDCWD, "", 0));
|
||||
ASSERT_OK_POSITIVE(is_mount_point_at(AT_FDCWD, "./", 0));
|
||||
|
||||
ASSERT_OK_ERRNO(chdir(pwd));
|
||||
|
||||
@@ -324,7 +324,7 @@ TEST(fd_is_mount_point) {
|
||||
fd = open("/proc/version", O_RDONLY|O_CLOEXEC|O_NOCTTY);
|
||||
assert_se(fd >= 0);
|
||||
|
||||
r = fd_is_mount_point(fd, NULL, 0);
|
||||
r = is_mount_point_at(fd, NULL, 0);
|
||||
assert_se(IN_SET(r, 0, -ENOTDIR)); /* on old kernels we can't determine if regular files are mount points if we have no directory fd */
|
||||
|
||||
if (!mount_new_api_supported())
|
||||
@@ -354,7 +354,7 @@ TEST(fd_is_mount_point) {
|
||||
ASSERT_OK(readlinkat_malloc(fd, "regular", &t));
|
||||
ASSERT_STREQ(t, "/usr");
|
||||
|
||||
ASSERT_OK(fd_is_mount_point(fd, "regular", 0));
|
||||
ASSERT_OK(is_mount_point_at(fd, "regular", 0));
|
||||
}
|
||||
|
||||
TEST(ms_nosymfollow_supported) {
|
||||
|
||||
@@ -744,7 +744,7 @@ static int dir_cleanup(
|
||||
if (S_ISDIR(sx.stx_mode)) {
|
||||
int q;
|
||||
|
||||
q = fd_is_mount_point(dirfd(d), de->d_name, 0);
|
||||
q = is_mount_point_at(dirfd(d), de->d_name, 0);
|
||||
if (q < 0)
|
||||
log_debug_errno(q, "Failed to determine whether \"%s/%s\" is a mount point, ignoring: %m", p, de->d_name);
|
||||
else if (q > 0) {
|
||||
@@ -2687,7 +2687,7 @@ static int rm_if_wrong_type_safe(
|
||||
}
|
||||
|
||||
/* Do not remove mount points. */
|
||||
r = fd_is_mount_point(parent_fd, name, follow_links ? AT_SYMLINK_FOLLOW : 0);
|
||||
r = is_mount_point_at(parent_fd, name, follow_links ? AT_SYMLINK_FOLLOW : 0);
|
||||
if (r < 0)
|
||||
(void) log_warning_errno(r, "Failed to check if \"%s/%s\" is a mount point: %m; continuing.",
|
||||
parent_name ?: "...", name);
|
||||
|
||||
Reference in New Issue
Block a user