fd-util: rename loop_get_diskseq() -> fd_get_diskseq()

And move it from loop-util.[ch] -> fd-util.[ch]
This commit is contained in:
Yu Watanabe
2022-03-31 03:25:45 +09:00
parent 2076612f84
commit 7e93a65868
3 changed files with 26 additions and 24 deletions

View File

@@ -3,6 +3,7 @@
#include <errno.h>
#include <fcntl.h>
#include <linux/btrfs.h>
#include <linux/fs.h>
#include <linux/magic.h>
#include <sys/ioctl.h>
#include <sys/resource.h>
@@ -17,6 +18,7 @@
#include "io-util.h"
#include "macro.h"
#include "missing_fcntl.h"
#include "missing_fs.h"
#include "missing_syscall.h"
#include "parse-util.h"
#include "path-util.h"
@@ -788,3 +790,24 @@ int btrfs_defrag_fd(int fd) {
return RET_NERRNO(ioctl(fd, BTRFS_IOC_DEFRAG, NULL));
}
int fd_get_diskseq(int fd, uint64_t *ret) {
uint64_t diskseq;
assert(fd >= 0);
assert(ret);
if (ioctl(fd, BLKGETDISKSEQ, &diskseq) < 0) {
/* Note that the kernel is weird: non-existing ioctls currently return EINVAL
* rather than ENOTTY on loopback block devices. They should fix that in the kernel,
* but in the meantime we accept both here. */
if (!ERRNO_IS_NOT_SUPPORTED(errno) && errno != EINVAL)
return -errno;
return -EOPNOTSUPP;
}
*ret = diskseq;
return 0;
}

View File

@@ -109,6 +109,7 @@ static inline int make_null_stdio(void) {
int fd_reopen(int fd, int flags);
int read_nr_open(void);
int btrfs_defrag_fd(int fd);
int fd_get_diskseq(int fd, uint64_t *ret);
/* The maximum length a buffer for a /proc/self/fd/<fd> path needs */
#define PROC_FD_PATH_MAX \