summaryrefslogtreecommitdiff
path: root/sysfs.c
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2013-06-19 10:33:47 +1000
committerNeilBrown <neilb@suse.de>2013-06-19 10:33:47 +1000
commit64e103fe19c84b9ec828a833c1def500d1b70c67 (patch)
treee53c40444a07e5ec2e04f1057b3d3eb011246298 /sysfs.c
parent2161adce8f789cfb01123f6c6c1d7c986b27abb5 (diff)
sysfs_read: return devices in same order as in filesystem.
When we read devices from sysfs (../md/dev-*), store them in the same order that they appear. That makes more sense when exposed to a human (as the next patch will). Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'sysfs.c')
-rw-r--r--sysfs.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/sysfs.c b/sysfs.c
index 6bc28651..cb25a413 100644
--- a/sysfs.c
+++ b/sysfs.c
@@ -96,7 +96,7 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
char *base;
char *dbase;
struct mdinfo *sra;
- struct mdinfo *dev;
+ struct mdinfo *dev, **devp;
DIR *dir = NULL;
struct dirent *de;
@@ -235,6 +235,8 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
goto abort;
sra->array.spare_disks = 0;
+ devp = &sra->devs;
+ sra->devs = NULL;
while ((de = readdir(dir)) != NULL) {
char *ep;
if (de->d_ino == 0 ||
@@ -266,7 +268,7 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
free(dev);
goto abort;
}
-
+
}
strcpy(dev->sys_name, de->d_name);
dev->disk.raid_disk = strtoul(buf, &ep, 10);
@@ -292,8 +294,9 @@ struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
}
/* finally add this disk to the array */
- dev->next = sra->devs;
- sra->devs = dev;
+ *devp = dev;
+ devp = & dev->next;
+ dev->next = NULL;
if (options & GET_OFFSET) {
strcpy(dbase, "offset");