]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
blockdev-util: add fd-based flavour of get_block_device()
authorLennart Poettering <lennart@poettering.net>
Mon, 21 Jun 2021 08:55:36 +0000 (10:55 +0200)
committerLennart Poettering <lennart@poettering.net>
Thu, 8 Jul 2021 07:29:18 +0000 (09:29 +0200)
src/shared/blockdev-util.c
src/shared/blockdev-util.h

index 4d545dfa5813e67ae826120984b39f0930bfb672..fa2d6d6add8c81a35356c4b4680fc27bbba83866 100644 (file)
@@ -57,21 +57,16 @@ int block_get_whole_disk(dev_t d, dev_t *ret) {
         return 1;
 }
 
-int get_block_device(const char *path, dev_t *ret) {
-        _cleanup_close_ int fd = -1;
+int get_block_device_fd(int fd, dev_t *ret) {
         struct stat st;
         int r;
 
-        assert(path);
+        assert(fd >= 0);
         assert(ret);
 
         /* Gets the block device directly backing a file system. If the block device is encrypted, returns
          * the device mapper block device. */
 
-        fd = open(path, O_RDONLY|O_NOFOLLOW|O_CLOEXEC);
-        if (fd < 0)
-                return -errno;
-
         if (fstat(fd, &st))
                 return -errno;
 
@@ -90,6 +85,19 @@ int get_block_device(const char *path, dev_t *ret) {
         return 0;
 }
 
+int get_block_device(const char *path, dev_t *ret) {
+        _cleanup_close_ int fd = -1;
+
+        assert(path);
+        assert(ret);
+
+        fd = open(path, O_RDONLY|O_NOFOLLOW|O_CLOEXEC);
+        if (fd < 0)
+                return -errno;
+
+        return get_block_device_fd(fd, ret);
+}
+
 int block_get_originating(dev_t dt, dev_t *ret) {
         _cleanup_closedir_ DIR *d = NULL;
         _cleanup_free_ char *t = NULL;
index 56c50cecba190a631408aeaa517aac8d5719ba77..90d9f1367322b1a0a98c2e7f7b386c8012ad9e13 100644 (file)
@@ -15,6 +15,7 @@
 int block_get_whole_disk(dev_t d, dev_t *ret);
 int block_get_originating(dev_t d, dev_t *ret);
 
+int get_block_device_fd(int fd, dev_t *ret);
 int get_block_device(const char *path, dev_t *dev);
 
 int get_block_device_harder(const char *path, dev_t *dev);