]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
mountpoint-util: add public helper for comparing file handles
authorLennart Poettering <lennart@poettering.net>
Tue, 25 Jun 2024 10:37:32 +0000 (12:37 +0200)
committerLennart Poettering <lennart@poettering.net>
Mon, 1 Jul 2024 13:45:15 +0000 (15:45 +0200)
We already have the code, let's move it to a function of its own and
export it.

src/basic/mountpoint-util.c
src/basic/mountpoint-util.h

index 73b582f58f36c4d9837545bcf0a090d185f53460..31a077fbdf2c73240072a959811d6b62f82432bc 100644 (file)
@@ -178,6 +178,17 @@ static bool filename_possibly_with_slash_suffix(const char *s) {
         return filename_is_valid(copied);
 }
 
+bool file_handle_equal(const struct file_handle *a, const struct file_handle *b) {
+        if (a == b)
+                return true;
+        if (!a != !b)
+                return false;
+        if (a->handle_type != b->handle_type)
+                return false;
+
+        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) {
         _cleanup_free_ struct file_handle *h = NULL, *h_parent = NULL;
         int mount_id = -1, mount_id_parent = -1;
@@ -277,10 +288,7 @@ int fd_is_mount_point(int fd, const char *filename, int flags) {
 
         /* If the file handle for the directory we are interested in and its parent are identical,
          * we assume this is the root directory, which is a mount point. */
-
-        if (h->handle_type == h_parent->handle_type &&
-            memcmp_nn(h->f_handle, h->handle_bytes,
-                      h_parent->f_handle, h_parent->handle_bytes) == 0)
+        if (file_handle_equal(h_parent, h))
                 return 1;
 
         return mount_id != mount_id_parent;
index 26afbb653de7d0426e6d95aaa4d46d3f0bdde5bd..c9d730e25c3bfdc8f6f49f854a367bdaad18d386 100644 (file)
@@ -40,6 +40,8 @@ bool is_name_to_handle_at_fatal_error(int err);
 
 int name_to_handle_at_loop(int fd, const char *path, struct file_handle **ret_handle, int *ret_mnt_id, int flags);
 
+bool file_handle_equal(const struct file_handle *a, const struct file_handle *b);
+
 int path_get_mnt_id_at_fallback(int dir_fd, const char *path, int *ret);
 int path_get_mnt_id_at(int dir_fd, const char *path, int *ret);
 static inline int path_get_mnt_id(const char *path, int *ret) {