Introduce devname2devnum
and use it instead of opencoding.
This commit is contained in:
parent
d7161f3b51
commit
77472ff8d0
1
mdadm.h
1
mdadm.h
|
@ -775,6 +775,7 @@ extern int mdmon_running(int devnum);
|
||||||
extern int signal_mdmon(int devnum);
|
extern int signal_mdmon(int devnum);
|
||||||
|
|
||||||
extern char *devnum2devname(int num);
|
extern char *devnum2devname(int num);
|
||||||
|
extern int devname2devnum(char *name);
|
||||||
extern int fd2devnum(int fd);
|
extern int fd2devnum(int fd);
|
||||||
|
|
||||||
static inline int dev2major(int d)
|
static inline int dev2major(int d)
|
||||||
|
|
6
mdstat.c
6
mdstat.c
|
@ -191,11 +191,7 @@ struct mdstat_ent *mdstat_read(int hold, int start)
|
||||||
* there.
|
* there.
|
||||||
*/
|
*/
|
||||||
struct mdstat_ent **ih;
|
struct mdstat_ent **ih;
|
||||||
int dn2;
|
int dn2 = devname2devnum(w);
|
||||||
if (strncmp(w, "md_d", 4)==0)
|
|
||||||
dn2 = -1-strtoul(w+4, &ep, 10);
|
|
||||||
else
|
|
||||||
dn2 = strtoul(w+2, &ep, 10);
|
|
||||||
ih = &all;
|
ih = &all;
|
||||||
while (ih != insert_here && *ih &&
|
while (ih != insert_here && *ih &&
|
||||||
(*ih)->devnum != dn2)
|
(*ih)->devnum != dn2)
|
||||||
|
|
8
sysfs.c
8
sysfs.c
|
@ -59,15 +59,9 @@ void sysfs_free(struct mdinfo *sra)
|
||||||
int sysfs_open(int devnum, char *devname, char *attr)
|
int sysfs_open(int devnum, char *devname, char *attr)
|
||||||
{
|
{
|
||||||
char fname[50];
|
char fname[50];
|
||||||
char sys_name[16];
|
|
||||||
int fd;
|
int fd;
|
||||||
if (devnum >= 0)
|
|
||||||
sprintf(sys_name, "md%d", devnum);
|
|
||||||
else
|
|
||||||
sprintf(sys_name, "md_d%d",
|
|
||||||
-1-devnum);
|
|
||||||
|
|
||||||
sprintf(fname, "/sys/block/%s/md/", sys_name);
|
sprintf(fname, "/sys/block/%s/md/", devnum2devname(devnum));
|
||||||
if (devname) {
|
if (devname) {
|
||||||
strcat(fname, devname);
|
strcat(fname, devname);
|
||||||
strcat(fname, "/");
|
strcat(fname, "/");
|
||||||
|
|
16
util.c
16
util.c
|
@ -826,10 +826,7 @@ struct supertype *super_by_fd(int fd)
|
||||||
int devnum;
|
int devnum;
|
||||||
if (subarray)
|
if (subarray)
|
||||||
*subarray++ = '\0';
|
*subarray++ = '\0';
|
||||||
if (strncmp(dev, "md_d", 4) == 0)
|
devnum = devname2devnum(dev);
|
||||||
devnum = -1-atoi(dev+4);
|
|
||||||
else
|
|
||||||
devnum = atoi(dev+2);
|
|
||||||
subarray = strdup(subarray);
|
subarray = strdup(subarray);
|
||||||
if (sra)
|
if (sra)
|
||||||
sysfs_free(sra);
|
sysfs_free(sra);
|
||||||
|
@ -1013,6 +1010,17 @@ char *devnum2devname(int num)
|
||||||
return strdup(name);
|
return strdup(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int devname2devnum(char *name)
|
||||||
|
{
|
||||||
|
char *ep;
|
||||||
|
int num;
|
||||||
|
if (strncmp(name, "md_d", 4)==0)
|
||||||
|
num = -1-strtoul(name+4, &ep, 10);
|
||||||
|
else
|
||||||
|
num = strtoul(name+2, &ep, 10);
|
||||||
|
return num;
|
||||||
|
}
|
||||||
|
|
||||||
int fd2devnum(int fd)
|
int fd2devnum(int fd)
|
||||||
{
|
{
|
||||||
struct stat stb;
|
struct stat stb;
|
||||||
|
|
Loading…
Reference in New Issue