/* SPDX-License-Identifier: LGPL-2.1-or-later */
-#include <linux/fs.h>
#include <linux/magic.h>
#include <sys/ioctl.h>
#include <threads.h>
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;