]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mountpoint-util: rename fd_is_mount_point() to is_mount_point_at()
authorMike Yuan <me@yhndnzj.com>
Mon, 20 Jan 2025 20:53:43 +0000 (21:53 +0100)
committerMike Yuan <me@yhndnzj.com>
Wed, 22 Jan 2025 00:37:31 +0000 (01:37 +0100)
fd_* functions in our codebase usually mean fd-specific operations,
while this one actually takes openat()-style params. Rename it
accordingly hence.

12 files changed:
src/basic/mountpoint-util.c
src/basic/mountpoint-util.h
src/basic/recurse-dir.c
src/dissect/dissect.c
src/shared/copy.c
src/shared/machine-id-setup.c
src/shared/mount-util.c
src/shared/pcrextend-util.c
src/shared/rm-rf.c
src/test/test-mount-util.c
src/test/test-mountpoint-util.c
src/tmpfiles/tmpfiles.c

index 750bcfa71be83a2a64dedc77c594279d9e28c620..6c03d62d2a2a426726cfce3d3d29a58b7c0080f7 100644 (file)
@@ -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) {
index f506e01a41761b379062387cd04faa3b068f141c..43e4758143d255adb007022200bc51f856b2b9c9 100644 (file)
@@ -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);
index 389a784c4059153ee9c0fe3c7101a3f3054c50a9..3d6061cfc0f91cde4d2fb0453d671a08c5b59455 100644 (file)
@@ -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);
 
index 33e651c6c16374e1129ab43415ef3eb893293075..956cac67084964dcfc57a34b2b93723712bb3639 100644 (file)
@@ -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)
index bca41cf122501c6ef613658dd07f261bab2d0d8e..cb3944b279ceaea5fbe38b14b521342ffa052319 100644 (file)
@@ -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)
index bc4d890d354b6f980dd48da646ffc0ae5da0a0e8..83f609c43f38f44cc32b713942720d42b1a7f84b 100644 (file)
@@ -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) {
index a9ce8d7e5aead1f3b9742cc6f5c96f41fd93de92..c7a9984528c5a818f5f14b4cd7492d08eccbe415 100644 (file)
@@ -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)
index 5ec9a069b71e243972ee1dfc35b3304f4a4450ac..96c1c07bc855e8815d74fdf072a739e44b8ed818 100644 (file)
@@ -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)
index 767db48cc0d7a4c4e1c348129d6493c7e01c71f9..2f50fa30ea66820f74809ecebc7a1aec12311540 100644 (file)
@@ -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)
index 0d7e803b5437b706c80c1e3ca0e5c201107830b2..352c5a1af68ce7a53a9bca9c10766c80541c75e3 100644 (file)
@@ -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);
 
index dc202cbda6defba3ffb7ad89b05012cde4b9a4be..c712cd8f2bf62102af5cf98a372fe38856f4c3b9 100644 (file)
@@ -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) {
index f3cbaf48a26de2a1a02f08763d4f0d9b41d1b2b2..6ce4a78adc1d3cd3e11a5cf31742eb5e40c2b7a3 100644 (file)
@@ -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);