]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fd-util: rename loop_get_diskseq() -> fd_get_diskseq()
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 30 Mar 2022 18:25:45 +0000 (03:25 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Fri, 1 Apr 2022 06:13:18 +0000 (15:13 +0900)
And move it from loop-util.[ch] -> fd-util.[ch]

src/basic/fd-util.c
src/basic/fd-util.h
src/shared/loop-util.c

index c02b52992bc20592059a2210fe42faf7f6d06828..6c1de92a26caa786211cdda45b209d5ed59eb07f 100644 (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;
+}
index f5cfcb4edeb79af46292c8870c040121aa77f4b5..808cac4d5d4a10a9733de2ecb1cbec7e45a7bd38 100644 (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 \
index 8736c930ad8881151f56385b43794e9ccbde9e2c..6356ff44d8c1002a5cc2e5ae1fb74b5f678ece1a 100644 (file)
@@ -23,7 +23,6 @@
 #include "fd-util.h"
 #include "fileio.h"
 #include "loop-util.h"
-#include "missing_fs.h"
 #include "missing_loop.h"
 #include "parse-util.h"
 #include "random-util.h"
@@ -129,27 +128,6 @@ static int device_has_block_children(sd_device *d) {
         return 0;
 }
 
-static int loop_get_diskseq(int fd, uint64_t *ret_diskseq) {
-        uint64_t diskseq;
-
-        assert(fd >= 0);
-        assert(ret_diskseq);
-
-        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 = diskseq;
-
-        return 0;
-}
-
 static int loop_configure(
                 int fd,
                 int nr,
@@ -454,7 +432,7 @@ static int loop_device_make_internal(
                         if (copy < 0)
                                 return copy;
 
-                        r = loop_get_diskseq(copy, &diskseq);
+                        r = fd_get_diskseq(copy, &diskseq);
                         if (r < 0 && r != -EOPNOTSUPP)
                                 return r;
 
@@ -593,7 +571,7 @@ static int loop_device_make_internal(
         assert(S_ISBLK(st.st_mode));
 
         uint64_t diskseq = 0;
-        r = loop_get_diskseq(loop_with_fd, &diskseq);
+        r = fd_get_diskseq(loop_with_fd, &diskseq);
         if (r < 0 && r != -EOPNOTSUPP)
                 return r;