summaryrefslogtreecommitdiffstats
path: root/sysfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'sysfs.c')
-rw-r--r--sysfs.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/sysfs.c b/sysfs.c
index 0f0506ca..a3bcb432 100644
--- a/sysfs.c
+++ b/sysfs.c
@@ -140,6 +140,24 @@ void sysfs_get_container_devnm(struct mdinfo *mdi, char *buf)
*p = 0;
}
+/**
+ * sysfs_open_memb_attr() - helper to get sysfs attr descriptor for member device.
+ * @array_devnm: array kernel device name.
+ * @memb_devnm: member device kernel device name.
+ * @attr: requested sysfs attribute.
+ * @oflag: open() flags.
+ *
+ * To refer member device directory, we need to append "dev-" before the member device name.
+ */
+int sysfs_open_memb_attr(char *array_devnm, char *memb_devnm, char *attr, int oflag)
+{
+ char path[PATH_MAX];
+
+ snprintf(path, PATH_MAX, "/sys/block/%s/md/dev-%s/%s", array_devnm, memb_devnm, attr);
+
+ return open(path, oflag);
+}
+
int sysfs_open(char *devnm, char *devname, char *attr)
{
char fname[MAX_SYSFS_PATH_LEN];
@@ -189,6 +207,7 @@ out:
return retval;
}
+/* If fd >= 0, get the array it is open on, else use devnm. */
struct mdinfo *sysfs_read(int fd, char *devnm, unsigned long options)
{
char fname[PATH_MAX];
@@ -817,8 +836,8 @@ int sysfs_add_disk(struct mdinfo *sra, struct mdinfo *sd, int resume)
memset(nm, 0, sizeof(nm));
dname = devid2kname(makedev(sd->disk.major, sd->disk.minor));
- strcpy(sd->sys_name, "dev-");
- strcpy(sd->sys_name+4, dname);
+
+ snprintf(sd->sys_name, sizeof(sd->sys_name), "dev-%s", dname);
/* test write to see if 'recovery_start' is available */
if (resume && sd->recovery_start < MaxSector &&