]> git.ipfire.org Git - thirdparty/mdadm.git/blobdiff - util.c
util: md_array_valid(): Introduce md_array_valid() helper
[thirdparty/mdadm.git] / util.c
diff --git a/util.c b/util.c
index 21a63c9a638ca9e6bbb6d5a1b2ea4b5e6d3efaa5..c7585aca3e4a76e98cda5d288fc39e3323c30bca 100644 (file)
--- a/util.c
+++ b/util.c
@@ -200,6 +200,30 @@ out:
        return ret;
 }
 
+int md_array_valid(int fd)
+{
+       struct mdinfo *sra;
+       int ret;
+
+       sra = sysfs_read(fd, NULL, GET_ARRAY_STATE);
+       if (sra) {
+               if (sra->array_state != ARRAY_UNKNOWN_STATE)
+                       ret = 0;
+               else
+                       ret = -ENODEV;
+
+               free(sra);
+       } else {
+               /*
+                * GET_ARRAY_INFO doesn't provide access to the proper state
+                * information, so fallback to a basic check for raid_disks != 0
+                */
+               ret = ioctl(fd, RAID_VERSION);
+       }
+
+       return !ret;
+}
+
 int md_array_active(int fd)
 {
        struct mdinfo *sra;