mountpoint-util: our baseline includes fdinfo and mnt_id now

This commit is contained in:
Mike Yuan
2025-01-22 01:12:55 +01:00
parent 229429a799
commit e5a3127339
2 changed files with 7 additions and 12 deletions
-4
View File
@@ -1113,8 +1113,6 @@ int fds_are_same_mount(int fd1, int fd2) {
int mntid;
r = path_get_mnt_id_at_fallback(fd1, "", &mntid);
if (ERRNO_IS_NEG_NOT_SUPPORTED(r))
return true; /* skip the mount ID check */
if (r < 0)
return r;
assert(mntid >= 0);
@@ -1127,8 +1125,6 @@ int fds_are_same_mount(int fd1, int fd2) {
int mntid;
r = path_get_mnt_id_at_fallback(fd2, "", &mntid);
if (ERRNO_IS_NEG_NOT_SUPPORTED(r))
return true; /* skip the mount ID check */
if (r < 0)
return r;
assert(mntid >= 0);
+7 -8
View File
@@ -147,11 +147,10 @@ static int fd_fdinfo_mnt_id(int fd, const char *filename, int flags, int *ret_mn
char path[STRLEN("/proc/self/fdinfo/") + DECIMAL_STR_MAX(int)];
_cleanup_free_ char *fdinfo = NULL;
_cleanup_close_ int subfd = -EBADF;
char *p;
int r;
assert(ret_mnt_id);
assert((flags & ~(AT_SYMLINK_FOLLOW|AT_EMPTY_PATH)) == 0);
assert(ret_mnt_id);
if ((flags & AT_EMPTY_PATH) && isempty(filename))
xsprintf(path, "/proc/self/fdinfo/%i", fd);
@@ -164,16 +163,16 @@ static int fd_fdinfo_mnt_id(int fd, const char *filename, int flags, int *ret_mn
}
r = read_full_virtual_file(path, &fdinfo, NULL);
if (r == -ENOENT) /* The fdinfo directory is a relatively new addition */
return proc_mounted() > 0 ? -EOPNOTSUPP : -ENOSYS;
if (r == -ENOENT)
return proc_fd_enoent_errno();
if (r < 0)
return r;
p = find_line_startswith(fdinfo, "mnt_id:");
if (!p) /* The mnt_id field is a relatively new addition */
return -EOPNOTSUPP;
char *p = find_line_startswith(fdinfo, "mnt_id:");
if (!p)
return -EBADMSG;
p += strspn(p, WHITESPACE);
p = skip_leading_chars(p, /* bad = */ NULL);
p[strcspn(p, WHITESPACE)] = 0;
return safe_atoi(p, ret_mnt_id);