]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
Util: get device size from id
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index ac5d8b137822583569fa415f486497b5c874a88c..1ecce3b8fd73d598051955bd8c6343b65bf29a9b 100644 (file)
--- a/util.c
+++ b/util.c
@@ -1094,6 +1094,22 @@ struct supertype *super_by_fd(int fd, char **subarrayp)
 }
 #endif /* !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) */
 
+int dev_size_from_id(unsigned int id, unsigned long long *size)
+{
+       char buf[20];
+       int fd;
+
+       sprintf(buf, "%d:%d", major(id), minor(id));
+       fd = dev_open(buf, O_RDONLY);
+       if (fd < 0)
+               return 0;
+       if (get_dev_size(fd, NULL, size)) {
+               close(fd);
+               return 1;
+       }
+       close(fd);
+       return 0;
+}
 
 struct supertype *dup_super(struct supertype *orig)
 {