/*
* mdadm - manage Linux "md" devices aka RAID arrays.
*
- * Copyright (C) 2001-2012 Neil Brown <neilb@suse.de>
+ * Copyright (C) 2001-2013 Neil Brown <neilb@suse.de>
*
*
* This program is free software; you can redistribute it and/or modify
return strcmp(* (char * const *) p1, * (char * const *) p2);
}
+static int add_device(const char *dev, char ***p_devices,
+ int *p_max_devices, int n_devices)
+{
+ if (n_devices + 1 >= *p_max_devices) {
+ *p_max_devices += 16;
+ *p_devices = xrealloc(*p_devices, *p_max_devices *
+ sizeof(**p_devices));
+ if (!*p_devices) {
+ *p_max_devices = 0;
+ return 0;
+ }
+ };
+ (*p_devices)[n_devices] = xstrdup(dev);
+ return n_devices + 1;
+}
+
int Detail(char *dev, struct context *c)
{
/*
st = super_by_fd(fd, &subarray);
if (ioctl(fd, GET_ARRAY_INFO, &array) == 0) {
inactive = 0;
- } else if (errno == ENODEV) {
+ } else if (errno == ENODEV && sra) {
array = sra->array;
inactive = 1;
} else {
(!e || (e->percent < 0 && e->percent != RESYNC_PENDING &&
e->percent != RESYNC_DELAYED)) ? "" : sync_action[e->resync],
larray_size ? "": ", Not Started",
- e->percent == RESYNC_DELAYED ? " (DELAYED)": "",
- e->percent == RESYNC_PENDING ? " (PENDING)": "");
+ (e && e->percent == RESYNC_DELAYED) ? " (DELAYED)": "",
+ (e && e->percent == RESYNC_PENDING) ? " (PENDING)": "");
} else if (inactive) {
printf(" State : inactive\n");
}
rv |= 1;
dv=map_dev_preferred(disk.major, disk.minor, 0, c->prefer);
if (dv != NULL) {
- if (c->brief) {
- if (n_devices + 1 >= max_devices) {
- max_devices += 16;
- devices = xrealloc(devices, max_devices
- *sizeof(*devices));
- if (!devices)
- goto out;
- };
- devices[n_devices] = xstrdup(dv);
- n_devices++;
- } else
+ if (c->brief)
+ n_devices = add_device(dv, &devices,
+ &max_devices,
+ n_devices);
+ else
printf(" %s", dv);
}
if (!c->brief) printf("\n");