mirror of
https://github.com/morgan9e/systemd
synced 2026-04-15 17:06:39 +09:00
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:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -821,7 +821,7 @@ static int automount_start(Unit *u) {
|
||||
assert(a);
|
||||
assert(IN_SET(a->state, AUTOMOUNT_DEAD, AUTOMOUNT_FAILED));
|
||||
|
||||
if (path_is_mount_point(a->where, NULL, 0) > 0)
|
||||
if (path_is_mount_point(a->where) > 0)
|
||||
return log_unit_error_errno(u, SYNTHETIC_ERRNO(EEXIST), "Path %s is already a mount point, refusing start.", a->where);
|
||||
|
||||
r = unit_test_trigger_loaded(u);
|
||||
|
||||
@@ -777,7 +777,7 @@ static int setup_credentials_internal(
|
||||
assert(workspace);
|
||||
|
||||
if (reuse_workspace) {
|
||||
r = path_is_mount_point(workspace, NULL, 0);
|
||||
r = path_is_mount_point(workspace);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0)
|
||||
@@ -788,7 +788,7 @@ static int setup_credentials_internal(
|
||||
} else
|
||||
workspace_mounted = -1; /* ditto */
|
||||
|
||||
r = path_is_mount_point(final, NULL, 0);
|
||||
r = path_is_mount_point(final);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0) {
|
||||
|
||||
@@ -80,7 +80,7 @@ static int acquire_credential_directory(ImportCredentialContext *c, const char *
|
||||
if (c->target_dir_fd >= 0)
|
||||
return c->target_dir_fd;
|
||||
|
||||
r = path_is_mount_point(path, NULL, 0);
|
||||
r = path_is_mount_point(path);
|
||||
if (r < 0) {
|
||||
if (r != -ENOENT)
|
||||
return log_error_errno(r, "Failed to determine if %s is a mount point: %m", path);
|
||||
|
||||
@@ -1117,7 +1117,7 @@ static int mount_bind_dev(const MountEntry *m) {
|
||||
|
||||
(void) mkdir_p_label(mount_entry_path(m), 0755);
|
||||
|
||||
r = path_is_mount_point(mount_entry_path(m), NULL, 0);
|
||||
r = path_is_mount_point(mount_entry_path(m));
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Unable to determine whether /dev is already mounted: %m");
|
||||
if (r > 0) /* make this a NOP if /dev is already a mount point */
|
||||
@@ -1137,7 +1137,7 @@ static int mount_bind_sysfs(const MountEntry *m) {
|
||||
|
||||
(void) mkdir_p_label(mount_entry_path(m), 0755);
|
||||
|
||||
r = path_is_mount_point(mount_entry_path(m), NULL, 0);
|
||||
r = path_is_mount_point(mount_entry_path(m));
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Unable to determine whether /sys is already mounted: %m");
|
||||
if (r > 0) /* make this a NOP if /sys is already a mount point */
|
||||
@@ -1184,7 +1184,7 @@ static int mount_private_apivfs(
|
||||
/* When we do not have enough privileges to mount a new instance, fall back to use an
|
||||
* existing mount. */
|
||||
|
||||
r = path_is_mount_point(entry_path, /* root = */ NULL, /* flags = */ 0);
|
||||
r = path_is_mount_point(entry_path);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Unable to determine whether '%s' is already mounted: %m", entry_path);
|
||||
if (r > 0)
|
||||
@@ -1299,7 +1299,7 @@ static int mount_run(const MountEntry *m) {
|
||||
|
||||
assert(m);
|
||||
|
||||
r = path_is_mount_point(mount_entry_path(m), NULL, 0);
|
||||
r = path_is_mount_point(mount_entry_path(m));
|
||||
if (r < 0 && r != -ENOENT)
|
||||
return log_debug_errno(r, "Unable to determine whether /run is already mounted: %m");
|
||||
if (r > 0) /* make this a NOP if /run is already a mount point */
|
||||
@@ -1533,7 +1533,7 @@ static int apply_one_mount(
|
||||
case MOUNT_READ_WRITE_IMPLICIT:
|
||||
case MOUNT_EXEC:
|
||||
case MOUNT_NOEXEC:
|
||||
r = path_is_mount_point(mount_entry_path(m), root_directory, 0);
|
||||
r = path_is_mount_point_full(mount_entry_path(m), root_directory, /* flags = */ 0);
|
||||
if (r == -ENOENT && m->ignore)
|
||||
return 0;
|
||||
if (r < 0)
|
||||
@@ -2537,7 +2537,7 @@ int setup_namespace(const NamespaceParameters *p, char **error_path) {
|
||||
} else if (p->root_directory) {
|
||||
|
||||
/* A root directory is specified. Turn its directory into bind mount, if it isn't one yet. */
|
||||
r = path_is_mount_point(root, NULL, AT_SYMLINK_FOLLOW);
|
||||
r = path_is_mount_point_full(root, /* root = */ NULL, AT_SYMLINK_FOLLOW);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to detect that %s is a mount point or not: %m", root);
|
||||
if (r == 0) {
|
||||
|
||||
@@ -280,7 +280,7 @@ static int path_is_busy(const char *where) {
|
||||
assert(where);
|
||||
|
||||
/* already a mountpoint; generators run during reload */
|
||||
r = path_is_mount_point(where, NULL, AT_SYMLINK_FOLLOW);
|
||||
r = path_is_mount_point_full(where, /* root = */ NULL, AT_SYMLINK_FOLLOW);
|
||||
if (r > 0)
|
||||
return false;
|
||||
/* The directory will be created by the mount or automount unit when it is started. */
|
||||
|
||||
@@ -428,7 +428,7 @@ int user_record_test_home_directory(UserRecord *h) {
|
||||
if (r == 0)
|
||||
return -ENOTDIR;
|
||||
|
||||
r = path_is_mount_point(hd, NULL, 0);
|
||||
r = path_is_mount_point(hd);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r > 0)
|
||||
|
||||
@@ -82,7 +82,7 @@ TEST(device_is_devtype) {
|
||||
}
|
||||
|
||||
static int intro(void) {
|
||||
if (path_is_mount_point("/sys", NULL, 0) <= 0)
|
||||
if (path_is_mount_point("/sys") <= 0)
|
||||
return log_tests_skipped("/sys is not mounted");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -299,7 +299,7 @@ int main(int argc, char *argv[]) {
|
||||
if (getuid() != 0)
|
||||
return log_tests_skipped("not root");
|
||||
|
||||
if (path_is_mount_point("/sys", NULL, 0) <= 0)
|
||||
if (path_is_mount_point("/sys") <= 0)
|
||||
return log_tests_skipped("/sys is not mounted");
|
||||
|
||||
if (path_is_read_only_fs("/sys") > 0)
|
||||
|
||||
@@ -677,7 +677,7 @@ TEST(devname_from_devnum) {
|
||||
}
|
||||
|
||||
static int intro(void) {
|
||||
if (path_is_mount_point("/sys", NULL, 0) <= 0)
|
||||
if (path_is_mount_point("/sys") <= 0)
|
||||
return log_tests_skipped("/sys is not mounted");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -67,7 +67,7 @@ static int user_mkdir_runtime_path(
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to create /run/user: %m");
|
||||
|
||||
if (path_is_mount_point(runtime_path, NULL, 0) >= 0)
|
||||
if (path_is_mount_point(runtime_path) > 0)
|
||||
log_debug("%s is already a mount point", runtime_path);
|
||||
else {
|
||||
char options[sizeof("mode=0700,uid=,gid=,size=,nr_inodes=,smackfsroot=*")
|
||||
|
||||
@@ -265,7 +265,7 @@ static int mount_legacy_cgroup_hierarchy(
|
||||
|
||||
to = strjoina(strempty(dest), "/sys/fs/cgroup/", hierarchy);
|
||||
|
||||
r = path_is_mount_point(to, dest, 0);
|
||||
r = path_is_mount_point_full(to, dest, /* flags = */ 0);
|
||||
if (r < 0 && r != -ENOENT)
|
||||
return log_error_errno(r, "Failed to determine if %s is mounted already: %m", to);
|
||||
if (r > 0)
|
||||
@@ -317,7 +317,7 @@ static int mount_legacy_cgns_supported(
|
||||
(void) mkdir_p(cgroup_root, 0755);
|
||||
|
||||
/* Mount a tmpfs to /sys/fs/cgroup if it's not mounted there yet. */
|
||||
r = path_is_mount_point(cgroup_root, dest, AT_SYMLINK_FOLLOW);
|
||||
r = path_is_mount_point_full(cgroup_root, dest, AT_SYMLINK_FOLLOW);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to determine if /sys/fs/cgroup is already mounted: %m");
|
||||
if (r == 0) {
|
||||
@@ -427,7 +427,7 @@ static int mount_legacy_cgns_unsupported(
|
||||
(void) mkdir_p(cgroup_root, 0755);
|
||||
|
||||
/* Mount a tmpfs to /sys/fs/cgroup if it's not mounted there yet. */
|
||||
r = path_is_mount_point(cgroup_root, dest, AT_SYMLINK_FOLLOW);
|
||||
r = path_is_mount_point_full(cgroup_root, dest, AT_SYMLINK_FOLLOW);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to determine if /sys/fs/cgroup is already mounted: %m");
|
||||
if (r == 0) {
|
||||
@@ -529,7 +529,7 @@ static int mount_unified_cgroups(const char *dest) {
|
||||
|
||||
(void) mkdir_p(p, 0755);
|
||||
|
||||
r = path_is_mount_point(p, dest, AT_SYMLINK_FOLLOW);
|
||||
r = path_is_mount_point_full(p, dest, AT_SYMLINK_FOLLOW);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to determine if %s is mounted already: %m", p);
|
||||
if (r > 0) {
|
||||
|
||||
@@ -642,7 +642,7 @@ int mount_all(const char *dest,
|
||||
|
||||
/* Skip this entry if it is not a remount. */
|
||||
if (mount_table[k].what) {
|
||||
r = path_is_mount_point(where, NULL, 0);
|
||||
r = path_is_mount_point(where);
|
||||
if (r < 0 && r != -ENOENT)
|
||||
return log_error_errno(r, "Failed to detect whether %s is a mount point: %m", where);
|
||||
if (r > 0)
|
||||
|
||||
@@ -2560,7 +2560,7 @@ static int setup_journal(const char *directory) {
|
||||
p = strjoina("/var/log/journal/", SD_ID128_TO_STRING(arg_uuid));
|
||||
q = prefix_roota(directory, p);
|
||||
|
||||
if (path_is_mount_point(p, NULL, 0) > 0) {
|
||||
if (path_is_mount_point(p) > 0) {
|
||||
if (try)
|
||||
return 0;
|
||||
|
||||
@@ -2568,7 +2568,7 @@ static int setup_journal(const char *directory) {
|
||||
"%s: already a mount point, refusing to use for journal", p);
|
||||
}
|
||||
|
||||
if (path_is_mount_point(q, NULL, 0) > 0) {
|
||||
if (path_is_mount_point(q) > 0) {
|
||||
if (try)
|
||||
return 0;
|
||||
|
||||
@@ -3633,7 +3633,7 @@ static int setup_unix_export_dir_outside(char **ret) {
|
||||
if (!p)
|
||||
return log_oom();
|
||||
|
||||
r = path_is_mount_point(p, /* root= */ NULL, 0);
|
||||
r = path_is_mount_point(p);
|
||||
if (r > 0)
|
||||
return log_error_errno(SYNTHETIC_ERRNO(EEXIST), "Mount point '%s' exists already, refusing.", p);
|
||||
if (r < 0 && r != -ENOENT)
|
||||
@@ -5680,7 +5680,7 @@ static int run(int argc, char *argv[]) {
|
||||
/* If the specified path is a mount point we generate the new snapshot immediately
|
||||
* inside it under a random name. However if the specified is not a mount point we
|
||||
* create the new snapshot in the parent directory, just next to it. */
|
||||
r = path_is_mount_point(arg_directory, NULL, 0);
|
||||
r = path_is_mount_point(arg_directory);
|
||||
if (r < 0) {
|
||||
log_error_errno(r, "Failed to determine whether directory %s is mount point: %m", arg_directory);
|
||||
goto finish;
|
||||
|
||||
@@ -224,7 +224,7 @@ static int run(int argc, char *argv[]) {
|
||||
if (r <= 0)
|
||||
return r;
|
||||
|
||||
r = path_is_mount_point(arg_target, NULL, 0);
|
||||
r = path_is_mount_point(arg_target);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to check if \"%s\" is a mount point: %m", arg_target);
|
||||
if (r == 0)
|
||||
|
||||
@@ -5828,7 +5828,7 @@ static int find_backing_devno(
|
||||
if (r < 0)
|
||||
return r;
|
||||
|
||||
r = path_is_mount_point(resolved, NULL, 0);
|
||||
r = path_is_mount_point(resolved);
|
||||
if (r < 0)
|
||||
return r;
|
||||
if (r == 0) /* Not a mount point, then it's not a partition of its own, let's not automatically use it. */
|
||||
@@ -7037,7 +7037,7 @@ static int parse_argv(int argc, char *argv[]) {
|
||||
/* By default operate on /sysusr/ or /sysroot/ when invoked in the initrd. We prefer the
|
||||
* former, if it is mounted, so that we have deterministic behaviour on systems where /usr/
|
||||
* is vendor-supplied but the root fs formatted on first boot. */
|
||||
r = path_is_mount_point("/sysusr/usr", NULL, 0);
|
||||
r = path_is_mount_point("/sysusr/usr");
|
||||
if (r <= 0) {
|
||||
if (r < 0 && r != -ENOENT)
|
||||
log_debug_errno(r, "Unable to determine whether /sysusr/usr is a mount point, assuming it is not: %m");
|
||||
|
||||
@@ -931,7 +931,7 @@ static int condition_test_path_is_mount_point(Condition *c, char **env) {
|
||||
assert(c->parameter);
|
||||
assert(c->type == CONDITION_PATH_IS_MOUNT_POINT);
|
||||
|
||||
return path_is_mount_point(c->parameter, NULL, AT_SYMLINK_FOLLOW) > 0;
|
||||
return path_is_mount_point_full(c->parameter, /* root = */ NULL, AT_SYMLINK_FOLLOW) > 0;
|
||||
}
|
||||
|
||||
static int condition_test_path_is_read_write(Condition *c, char **env) {
|
||||
|
||||
@@ -237,7 +237,7 @@ int machine_id_commit(const char *root) {
|
||||
|
||||
etc_machine_id = prefix_roota(root, "/etc/machine-id");
|
||||
|
||||
r = path_is_mount_point(etc_machine_id, NULL, 0);
|
||||
r = path_is_mount_point(etc_machine_id);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to determine whether %s is a mount point: %m", etc_machine_id);
|
||||
if (r == 0) {
|
||||
|
||||
@@ -177,7 +177,7 @@ static int mount_one(const MountPoint *p, bool relabel) {
|
||||
if (relabel)
|
||||
(void) label_fix(p->where, LABEL_IGNORE_ENOENT|LABEL_IGNORE_EROFS);
|
||||
|
||||
r = path_is_mount_point(p->where, NULL, AT_SYMLINK_FOLLOW);
|
||||
r = path_is_mount_point_full(p->where, /* root = */ NULL, AT_SYMLINK_FOLLOW);
|
||||
if (r < 0 && r != -ENOENT) {
|
||||
log_full_errno(priority, r, "Failed to determine whether %s is a mount point: %m", p->where);
|
||||
return (p->mode & MNT_FATAL) ? r : 0;
|
||||
|
||||
@@ -347,7 +347,7 @@ int bind_remount_recursive_with_mountinfo(
|
||||
* think autofs, NFS, FUSE, …), but let's generate useful debug messages at
|
||||
* the very least. */
|
||||
|
||||
q = path_is_mount_point(x, NULL, 0);
|
||||
q = path_is_mount_point(x);
|
||||
if (IN_SET(q, 0, -ENOENT)) {
|
||||
/* Hmm, whaaaa? The mount point is not actually a mount point? Then
|
||||
* it is either obstructed by a later mount or somebody has been
|
||||
@@ -1283,7 +1283,7 @@ int make_mount_point(const char *path) {
|
||||
|
||||
/* If 'path' is already a mount point, does nothing and returns 0. If it is not it makes it one, and returns 1. */
|
||||
|
||||
r = path_is_mount_point(path, NULL, 0);
|
||||
r = path_is_mount_point(path);
|
||||
if (r < 0)
|
||||
return log_debug_errno(r, "Failed to determine whether '%s' is a mount point: %m", path);
|
||||
if (r > 0)
|
||||
@@ -1590,7 +1590,7 @@ int bind_mount_submounts(
|
||||
if (!t)
|
||||
return -ENOMEM;
|
||||
|
||||
r = path_is_mount_point(t, NULL, 0);
|
||||
r = path_is_mount_point(t);
|
||||
if (r < 0) {
|
||||
log_debug_errno(r, "Failed to detect if '%s' already is a mount point, ignoring: %m", t);
|
||||
continue;
|
||||
|
||||
@@ -144,7 +144,7 @@ int switch_root(const char *new_root,
|
||||
return log_error_errno(r, "Failed to resolve %s/%s: %m", new_root, transfer->path);
|
||||
|
||||
/* Let's see if it is a mount point already. */
|
||||
r = path_is_mount_point(chased, NULL, 0);
|
||||
r = path_is_mount_point(chased);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to determine whether %s is a mount point: %m", chased);
|
||||
if (r > 0) /* If it is already mounted, then do nothing */
|
||||
|
||||
@@ -113,7 +113,7 @@ static int is_our_mount_point(
|
||||
|
||||
assert(p);
|
||||
|
||||
r = path_is_mount_point(p, NULL, 0);
|
||||
r = path_is_mount_point(p);
|
||||
if (r == -ENOENT) {
|
||||
log_debug_errno(r, "Hierarchy '%s' doesn't exist.", p);
|
||||
return false;
|
||||
|
||||
@@ -508,11 +508,11 @@ TEST(bind_mount_submounts) {
|
||||
free(x);
|
||||
|
||||
assert_se(x = path_join(b, "x"));
|
||||
assert_se(path_is_mount_point(x, NULL, 0) > 0);
|
||||
assert_se(path_is_mount_point(x) > 0);
|
||||
free(x);
|
||||
|
||||
assert_se(x = path_join(b, "y"));
|
||||
assert_se(path_is_mount_point(x, NULL, 0) > 0);
|
||||
assert_se(path_is_mount_point(x) > 0);
|
||||
|
||||
assert_se(umount_recursive(a, 0) >= 0);
|
||||
assert_se(umount_recursive(b, 0) >= 0);
|
||||
|
||||
@@ -101,7 +101,7 @@ TEST(mnt_id) {
|
||||
* See #11505. */
|
||||
assert_se(q = hashmap_get(h, INT_TO_PTR(mnt_id2)));
|
||||
|
||||
assert_se((r = path_is_mount_point(p, NULL, 0)) >= 0);
|
||||
assert_se((r = path_is_mount_point_full(p, NULL, 0)) >= 0);
|
||||
if (r == 0) {
|
||||
/* If the path is not a mount point anymore, then it must be a sub directory of
|
||||
* the path corresponds to mnt_id2. */
|
||||
@@ -123,20 +123,20 @@ TEST(path_is_mount_point) {
|
||||
_cleanup_free_ char *dir1 = NULL, *dir1file = NULL, *dirlink1 = NULL, *dirlink1file = NULL;
|
||||
_cleanup_free_ char *dir2 = NULL, *dir2file = NULL;
|
||||
|
||||
assert_se(path_is_mount_point("/", NULL, AT_SYMLINK_FOLLOW) > 0);
|
||||
assert_se(path_is_mount_point("/", NULL, 0) > 0);
|
||||
assert_se(path_is_mount_point("//", NULL, AT_SYMLINK_FOLLOW) > 0);
|
||||
assert_se(path_is_mount_point("//", NULL, 0) > 0);
|
||||
assert_se(path_is_mount_point_full("/", NULL, AT_SYMLINK_FOLLOW) > 0);
|
||||
assert_se(path_is_mount_point_full("/", NULL, 0) > 0);
|
||||
assert_se(path_is_mount_point_full("//", NULL, AT_SYMLINK_FOLLOW) > 0);
|
||||
assert_se(path_is_mount_point_full("//", NULL, 0) > 0);
|
||||
|
||||
assert_se(path_is_mount_point("/proc", NULL, AT_SYMLINK_FOLLOW) > 0);
|
||||
assert_se(path_is_mount_point("/proc", NULL, 0) > 0);
|
||||
assert_se(path_is_mount_point("/proc/", NULL, AT_SYMLINK_FOLLOW) > 0);
|
||||
assert_se(path_is_mount_point("/proc/", NULL, 0) > 0);
|
||||
assert_se(path_is_mount_point_full("/proc", NULL, AT_SYMLINK_FOLLOW) > 0);
|
||||
assert_se(path_is_mount_point_full("/proc", NULL, 0) > 0);
|
||||
assert_se(path_is_mount_point_full("/proc/", NULL, AT_SYMLINK_FOLLOW) > 0);
|
||||
assert_se(path_is_mount_point_full("/proc/", NULL, 0) > 0);
|
||||
|
||||
assert_se(path_is_mount_point("/proc/1", NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point("/proc/1", NULL, 0) == 0);
|
||||
assert_se(path_is_mount_point("/proc/1/", NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point("/proc/1/", NULL, 0) == 0);
|
||||
assert_se(path_is_mount_point_full("/proc/1", NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point_full("/proc/1", NULL, 0) == 0);
|
||||
assert_se(path_is_mount_point_full("/proc/1/", NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point_full("/proc/1/", NULL, 0) == 0);
|
||||
|
||||
/* we'll create a hierarchy of different kinds of dir/file/link
|
||||
* layouts:
|
||||
@@ -170,10 +170,10 @@ TEST(path_is_mount_point) {
|
||||
assert_se(link1);
|
||||
assert_se(symlink("file2", link2) == 0);
|
||||
|
||||
assert_se(path_is_mount_point(file1, NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point(file1, NULL, 0) == 0);
|
||||
assert_se(path_is_mount_point(link1, NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point(link1, NULL, 0) == 0);
|
||||
assert_se(path_is_mount_point_full(file1, NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point_full(file1, NULL, 0) == 0);
|
||||
assert_se(path_is_mount_point_full(link1, NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point_full(link1, NULL, 0) == 0);
|
||||
|
||||
/* directory mountpoints */
|
||||
dir1 = path_join(tmp_dir, "dir1");
|
||||
@@ -189,10 +189,10 @@ TEST(path_is_mount_point) {
|
||||
assert_se(dir2);
|
||||
assert_se(mkdir(dir2, 0755) == 0);
|
||||
|
||||
assert_se(path_is_mount_point(dir1, NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point(dir1, NULL, 0) == 0);
|
||||
assert_se(path_is_mount_point(dirlink1, NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point(dirlink1, NULL, 0) == 0);
|
||||
assert_se(path_is_mount_point_full(dir1, NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point_full(dir1, NULL, 0) == 0);
|
||||
assert_se(path_is_mount_point_full(dirlink1, NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point_full(dirlink1, NULL, 0) == 0);
|
||||
|
||||
/* file in subdirectory mountpoints */
|
||||
dir1file = path_join(dir1, "file");
|
||||
@@ -201,10 +201,10 @@ TEST(path_is_mount_point) {
|
||||
assert_se(fd > 0);
|
||||
close(fd);
|
||||
|
||||
assert_se(path_is_mount_point(dir1file, NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point(dir1file, NULL, 0) == 0);
|
||||
assert_se(path_is_mount_point(dirlink1file, NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point(dirlink1file, NULL, 0) == 0);
|
||||
assert_se(path_is_mount_point_full(dir1file, NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point_full(dir1file, NULL, 0) == 0);
|
||||
assert_se(path_is_mount_point_full(dirlink1file, NULL, AT_SYMLINK_FOLLOW) == 0);
|
||||
assert_se(path_is_mount_point_full(dirlink1file, NULL, 0) == 0);
|
||||
|
||||
/* these tests will only work as root */
|
||||
if (mount(file1, file2, NULL, MS_BIND, NULL) >= 0) {
|
||||
@@ -214,17 +214,17 @@ TEST(path_is_mount_point) {
|
||||
/* files */
|
||||
/* capture results in vars, to avoid dangling mounts on failure */
|
||||
log_info("%s: %s", __func__, file2);
|
||||
rf = path_is_mount_point(file2, NULL, 0);
|
||||
rt = path_is_mount_point(file2, NULL, AT_SYMLINK_FOLLOW);
|
||||
rf = path_is_mount_point_full(file2, NULL, 0);
|
||||
rt = path_is_mount_point_full(file2, NULL, AT_SYMLINK_FOLLOW);
|
||||
|
||||
file2d = strjoina(file2, "/");
|
||||
log_info("%s: %s", __func__, file2d);
|
||||
rdf = path_is_mount_point(file2d, NULL, 0);
|
||||
rdt = path_is_mount_point(file2d, NULL, AT_SYMLINK_FOLLOW);
|
||||
rdf = path_is_mount_point_full(file2d, NULL, 0);
|
||||
rdt = path_is_mount_point_full(file2d, NULL, AT_SYMLINK_FOLLOW);
|
||||
|
||||
log_info("%s: %s", __func__, link2);
|
||||
rlf = path_is_mount_point(link2, NULL, 0);
|
||||
rlt = path_is_mount_point(link2, NULL, AT_SYMLINK_FOLLOW);
|
||||
rlf = path_is_mount_point_full(link2, NULL, 0);
|
||||
rlt = path_is_mount_point_full(link2, NULL, AT_SYMLINK_FOLLOW);
|
||||
|
||||
assert_se(umount(file2) == 0);
|
||||
|
||||
@@ -245,15 +245,15 @@ TEST(path_is_mount_point) {
|
||||
assert_se(mount(dir2, dir1, NULL, MS_BIND, NULL) >= 0);
|
||||
|
||||
log_info("%s: %s", __func__, dir1);
|
||||
rf = path_is_mount_point(dir1, NULL, 0);
|
||||
rt = path_is_mount_point(dir1, NULL, AT_SYMLINK_FOLLOW);
|
||||
rf = path_is_mount_point_full(dir1, NULL, 0);
|
||||
rt = path_is_mount_point_full(dir1, NULL, AT_SYMLINK_FOLLOW);
|
||||
log_info("%s: %s", __func__, dirlink1);
|
||||
rlf = path_is_mount_point(dirlink1, NULL, 0);
|
||||
rlt = path_is_mount_point(dirlink1, NULL, AT_SYMLINK_FOLLOW);
|
||||
rlf = path_is_mount_point_full(dirlink1, NULL, 0);
|
||||
rlt = path_is_mount_point_full(dirlink1, NULL, AT_SYMLINK_FOLLOW);
|
||||
log_info("%s: %s", __func__, dirlink1file);
|
||||
/* its parent is a mount point, but not /file itself */
|
||||
rl1f = path_is_mount_point(dirlink1file, NULL, 0);
|
||||
rl1t = path_is_mount_point(dirlink1file, NULL, AT_SYMLINK_FOLLOW);
|
||||
rl1f = path_is_mount_point_full(dirlink1file, NULL, 0);
|
||||
rl1t = path_is_mount_point_full(dirlink1file, NULL, AT_SYMLINK_FOLLOW);
|
||||
|
||||
assert_se(umount(dir1) == 0);
|
||||
|
||||
|
||||
@@ -73,11 +73,11 @@ TEST(is_symlink) {
|
||||
|
||||
TEST(path_is_fs_type) {
|
||||
/* run might not be a mount point in build chroots */
|
||||
if (path_is_mount_point("/run", NULL, AT_SYMLINK_FOLLOW) > 0) {
|
||||
if (path_is_mount_point_full("/run", NULL, AT_SYMLINK_FOLLOW) > 0) {
|
||||
assert_se(path_is_fs_type("/run", TMPFS_MAGIC) > 0);
|
||||
assert_se(path_is_fs_type("/run", BTRFS_SUPER_MAGIC) == 0);
|
||||
}
|
||||
if (path_is_mount_point("/proc", NULL, AT_SYMLINK_FOLLOW) > 0) {
|
||||
if (path_is_mount_point_full("/proc", NULL, AT_SYMLINK_FOLLOW) > 0) {
|
||||
assert_se(path_is_fs_type("/proc", PROC_SUPER_MAGIC) > 0);
|
||||
assert_se(path_is_fs_type("/proc", BTRFS_SUPER_MAGIC) == 0);
|
||||
}
|
||||
@@ -95,7 +95,7 @@ TEST(path_is_temporary_fs) {
|
||||
}
|
||||
|
||||
/* run might not be a mount point in build chroots */
|
||||
if (path_is_mount_point("/run", NULL, AT_SYMLINK_FOLLOW) > 0)
|
||||
if (path_is_mount_point_full("/run", NULL, AT_SYMLINK_FOLLOW) > 0)
|
||||
assert_se(path_is_temporary_fs("/run") > 0);
|
||||
assert_se(path_is_temporary_fs("/proc") == 0);
|
||||
assert_se(path_is_temporary_fs("/i-dont-exist") == -ENOENT);
|
||||
@@ -111,7 +111,7 @@ TEST(path_is_read_only_fs) {
|
||||
s, r, r < 0 ? errno_to_name(r) : yes_no(r));
|
||||
}
|
||||
|
||||
if (path_is_mount_point("/sys", NULL, AT_SYMLINK_FOLLOW) > 0)
|
||||
if (path_is_mount_point_full("/sys", NULL, AT_SYMLINK_FOLLOW) > 0)
|
||||
assert_se(IN_SET(path_is_read_only_fs("/sys"), 0, 1));
|
||||
|
||||
assert_se(path_is_read_only_fs("/proc") == 0);
|
||||
|
||||
@@ -36,7 +36,7 @@ TEST(udev_resolve_subsys_kernel) {
|
||||
}
|
||||
|
||||
static int intro(void) {
|
||||
if (path_is_mount_point("/sys", NULL, 0) <= 0)
|
||||
if (path_is_mount_point("/sys") <= 0)
|
||||
return log_tests_skipped("/sys is not mounted");
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
|
||||
@@ -81,7 +81,7 @@ static void test2(void) {
|
||||
int main(int argc, char *argv[]) {
|
||||
_cleanup_free_ char *self = NULL;
|
||||
|
||||
if (path_is_mount_point("/sys", NULL, 0) <= 0)
|
||||
if (path_is_mount_point("/sys") <= 0)
|
||||
return log_tests_skipped("/sys is not mounted");
|
||||
|
||||
if (argc > 1) {
|
||||
|
||||
@@ -154,7 +154,7 @@ static int run(int argc, char *argv[]) {
|
||||
if (!IN_SET(m, VOLATILE_YES, VOLATILE_OVERLAY))
|
||||
return 0;
|
||||
|
||||
r = path_is_mount_point(path, NULL, AT_SYMLINK_FOLLOW);
|
||||
r = path_is_mount_point_full(path, /* root = */ NULL, AT_SYMLINK_FOLLOW);
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Couldn't determine whether %s is a mount point: %m", path);
|
||||
if (r == 0)
|
||||
|
||||
Reference in New Issue
Block a user