mountpoint-util: some tweaks for fd_is_mount_point()
- Drop fstat() fallback path now that we assume fdinfo is available - Use at_flags_normalize_nofollow() - Accept empty path the same way as NULL - Accept fd being AT_FDCWD and filename being "."
This commit is contained in:
@@ -273,6 +273,7 @@ TEST(path_is_mount_point) {
|
||||
|
||||
TEST(fd_is_mount_point) {
|
||||
_cleanup_(rm_rf_physical_and_freep) char *tmpdir = NULL;
|
||||
_cleanup_free_ char *pwd = NULL;
|
||||
_cleanup_close_ int fd = -EBADF;
|
||||
int r;
|
||||
|
||||
@@ -281,11 +282,8 @@ TEST(fd_is_mount_point) {
|
||||
|
||||
/* 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, "..", 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);
|
||||
@@ -307,9 +305,20 @@ TEST(fd_is_mount_point) {
|
||||
fd = open("/proc", O_RDONLY|O_CLOEXEC|O_DIRECTORY|O_NOCTTY);
|
||||
assert_se(fd >= 0);
|
||||
|
||||
assert_se(fd_is_mount_point(fd, NULL, 0) > 0);
|
||||
assert_se(fd_is_mount_point(fd, "", 0) == -EINVAL);
|
||||
assert_se(fd_is_mount_point(fd, "version", 0) == 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(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_ERRNO(chdir(pwd));
|
||||
|
||||
safe_close(fd);
|
||||
fd = open("/proc/version", O_RDONLY|O_CLOEXEC|O_NOCTTY);
|
||||
@@ -317,7 +326,6 @@ TEST(fd_is_mount_point) {
|
||||
|
||||
r = fd_is_mount_point(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 */
|
||||
assert_se(fd_is_mount_point(fd, "", 0) == -EINVAL);
|
||||
|
||||
if (!mount_new_api_supported())
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user