pidfd-util: use fd_to_handle_u64()
This commit is contained in:
+3
-19
@@ -1,6 +1,5 @@
|
||||
/* SPDX-License-Identifier: LGPL-2.1-or-later */
|
||||
|
||||
#include <linux/fs.h>
|
||||
#include <linux/magic.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <threads.h>
|
||||
@@ -236,25 +235,10 @@ int pidfd_get_inode_id_impl(int fd, uint64_t *ret) {
|
||||
|
||||
assert(fd >= 0);
|
||||
|
||||
/* Since kernel 6.14 (b3caba8f7a34a2bbaf45ffc6ff3a49b70afeb192), we can use name_to_handle_at(). */
|
||||
if (file_handle_supported) {
|
||||
union {
|
||||
struct file_handle file_handle;
|
||||
uint8_t space[MAX_HANDLE_SZ];
|
||||
} fh = {
|
||||
.file_handle.handle_bytes = sizeof(uint64_t),
|
||||
.file_handle.handle_type = FILEID_KERNFS,
|
||||
};
|
||||
int mnt_id;
|
||||
|
||||
r = RET_NERRNO(name_to_handle_at(fd, "", &fh.file_handle, &mnt_id, AT_EMPTY_PATH));
|
||||
if (r >= 0) {
|
||||
if (ret)
|
||||
/* Note, "struct file_handle" is 32bit aligned usually, but we need to read a 64bit value from it */
|
||||
*ret = unaligned_read_ne64(fh.file_handle.f_handle);
|
||||
return 0;
|
||||
}
|
||||
assert(r != -EOVERFLOW);
|
||||
if (is_name_to_handle_at_fatal_error(r))
|
||||
r = fd_to_handle_u64(fd, ret);
|
||||
if (r >= 0 || is_name_to_handle_at_fatal_error(r))
|
||||
return r;
|
||||
|
||||
file_handle_supported = false;
|
||||
|
||||
Reference in New Issue
Block a user