Merge pull request #31205 from YHNdnzj/path-is-mount-point

mountpoint-util: expose root and flags as path_is_mount_point_full
This commit is contained in:
Luca Boccassi
2024-02-06 12:37:20 +00:00
committed by GitHub
29 changed files with 97 additions and 94 deletions
+10 -11
View File
@@ -329,34 +329,33 @@ fallback_fstat:
}
/* flags can be AT_SYMLINK_FOLLOW or 0 */
int path_is_mount_point(const char *t, const char *root, int flags) {
int path_is_mount_point_full(const char *path, const char *root, int flags) {
_cleanup_free_ char *canonical = NULL;
_cleanup_close_ int fd = -EBADF;
int r;
assert(t);
assert(path);
assert((flags & ~AT_SYMLINK_FOLLOW) == 0);
if (path_equal(t, "/"))
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; if we have a structure like
* /bin -> /usr/bin/ and /usr is a mount point, then the parent that we
/* we need to resolve symlinks manually, we can't just rely on fd_is_mount_point() 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 & AT_SYMLINK_FOLLOW) {
r = chase(t, root, CHASE_TRAIL_SLASH, &canonical, NULL);
if (FLAGS_SET(flags, AT_SYMLINK_FOLLOW)) {
r = chase(path, root, CHASE_TRAIL_SLASH, &canonical, NULL);
if (r < 0)
return r;
t = canonical;
path = canonical;
}
fd = open_parent(t, O_PATH|O_CLOEXEC, 0);
fd = open_parent(path, O_PATH|O_CLOEXEC, 0);
if (fd < 0)
return fd;
return fd_is_mount_point(fd, last_path_component(t), flags);
return fd_is_mount_point(fd, last_path_component(path), flags);
}
int path_get_mnt_id_at_fallback(int dir_fd, const char *path, int *ret) {
+5 -1
View File
@@ -3,6 +3,7 @@
#include <fcntl.h>
#include <stdbool.h>
#include <stddef.h>
#include <sys/types.h>
/* The limit used for /dev itself. 4MB should be enough since device nodes and symlinks don't
@@ -44,7 +45,10 @@ static inline int path_get_mnt_id(const char *path, int *ret) {
}
int fd_is_mount_point(int fd, const char *filename, int flags);
int path_is_mount_point(const char *path, const char *root, 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);
}
bool fstype_is_network(const char *fstype);
bool fstype_needs_quota(const char *fstype);