From: Mike Yuan Date: Mon, 20 Jan 2025 20:53:43 +0000 (+0100) Subject: mountpoint-util: rename fd_is_mount_point() to is_mount_point_at() X-Git-Tag: v258-rc1~1536^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7ce2c1bb5fc07497dfd91feb2bb89554aab166c9;p=thirdparty%2Fsystemd.git 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. --- diff --git a/src/basic/mountpoint-util.c b/src/basic/mountpoint-util.c index 750bcfa71be..6c03d62d2a2 100644 --- a/src/basic/mountpoint-util.c +++ b/src/basic/mountpoint-util.c @@ -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) { diff --git a/src/basic/mountpoint-util.h b/src/basic/mountpoint-util.h index f506e01a417..43e4758143d 100644 --- a/src/basic/mountpoint-util.h +++ b/src/basic/mountpoint-util.h @@ -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); diff --git a/src/basic/recurse-dir.c b/src/basic/recurse-dir.c index 389a784c405..3d6061cfc0f 100644 --- a/src/basic/recurse-dir.c +++ b/src/basic/recurse-dir.c @@ -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); diff --git a/src/dissect/dissect.c b/src/dissect/dissect.c index 33e651c6c16..956cac67084 100644 --- a/src/dissect/dissect.c +++ b/src/dissect/dissect.c @@ -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) diff --git a/src/shared/copy.c b/src/shared/copy.c index bca41cf1225..cb3944b279c 100644 --- a/src/shared/copy.c +++ b/src/shared/copy.c @@ -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) diff --git a/src/shared/machine-id-setup.c b/src/shared/machine-id-setup.c index bc4d890d354..83f609c43f3 100644 --- a/src/shared/machine-id-setup.c +++ b/src/shared/machine-id-setup.c @@ -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) { diff --git a/src/shared/mount-util.c b/src/shared/mount-util.c index a9ce8d7e5ae..c7a9984528c 100644 --- a/src/shared/mount-util.c +++ b/src/shared/mount-util.c @@ -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) diff --git a/src/shared/pcrextend-util.c b/src/shared/pcrextend-util.c index 5ec9a069b71..96c1c07bc85 100644 --- a/src/shared/pcrextend-util.c +++ b/src/shared/pcrextend-util.c @@ -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) diff --git a/src/shared/rm-rf.c b/src/shared/rm-rf.c index 767db48cc0d..2f50fa30ea6 100644 --- a/src/shared/rm-rf.c +++ b/src/shared/rm-rf.c @@ -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) diff --git a/src/test/test-mount-util.c b/src/test/test-mount-util.c index 0d7e803b543..352c5a1af68 100644 --- a/src/test/test-mount-util.c +++ b/src/test/test-mount-util.c @@ -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); diff --git a/src/test/test-mountpoint-util.c b/src/test/test-mountpoint-util.c index dc202cbda6d..c712cd8f2bf 100644 --- a/src/test/test-mountpoint-util.c +++ b/src/test/test-mountpoint-util.c @@ -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) { diff --git a/src/tmpfiles/tmpfiles.c b/src/tmpfiles/tmpfiles.c index f3cbaf48a26..6ce4a78adc1 100644 --- a/src/tmpfiles/tmpfiles.c +++ b/src/tmpfiles/tmpfiles.c @@ -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);