mirror of
https://github.com/systemd/systemd.git
synced 2025-01-18 10:04:04 +03:00
mountpoint-util: add public helper for comparing file handles
We already have the code, let's move it to a function of its own and export it.
This commit is contained in:
parent
a89690f719
commit
8da6413860
@ -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;
|
||||
|
@ -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) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user