sysfs_free(sra);
if (st) {
st->sb = NULL;
- st->subarray[0] = 0;
- *subarrayp = subarray;
+ if (subarrayp)
+ *subarrayp = subarray;
} else
free(subarray);
return st;
}
#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)
{
st->ss = orig->ss;
st->max_devs = orig->max_devs;
st->minor_version = orig->minor_version;
- strcpy(st->subarray, orig->subarray);
st->sb = NULL;
st->info = NULL;
return st;
return 1;
}
+/* Return true if this can only be a container, not a member device.
+ * i.e. is and md device and size is zero
+ */
+int must_be_container(int fd)
+{
+ unsigned long long size;
+ if (md_get_version(fd) < 0)
+ return 0;
+ if (get_dev_size(fd, NULL, &size) == 0)
+ return 1;
+ if (size == 0)
+ return 1;
+ return 0;
+}
/* Sets endofpart parameter to the last block used by the last GPT partition on the device.
* Returns: 1 if successful
goto free_sysfs;
}
- if (st->ss->load_super(st, fd, NULL)) {
+ if (!st->ss->load_container) {
if (!quiet)
- fprintf(stderr, Name ": Failed to load metadata for %s\n",
- dev);
+ fprintf(stderr, Name ": %s is not a container\n", dev);
goto free_name;
}
- if (!st->loaded_container) {
+ if (st->ss->load_container(st, fd, NULL)) {
if (!quiet)
- fprintf(stderr, Name ": %s is not a container\n", dev);
- goto free_super;
+ fprintf(stderr, Name ": Failed to load metadata for %s\n",
+ dev);
+ goto free_name;
}
info = st->ss->container_content(st, subarray);