diff options
author | NeilBrown <neilb@suse.de> | 2014-08-11 02:27:31 +0200 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2014-08-11 02:34:36 +0200 |
commit | cc742d38071c631311309b68b51f8938cdf916be (patch) | |
tree | 35b8cff7992f04fce414fa018af50e2d06325213 /util.c | |
parent | Manage: simplify `rdev` handling in Manage_subdevs. (diff) | |
download | mdadm-cc742d38071c631311309b68b51f8938cdf916be.tar.xz mdadm-cc742d38071c631311309b68b51f8938cdf916be.zip |
util: split get_maj_min() out from dev_open()
This allows other code to parse "8:3" style device names.
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 15 |
1 files changed, 10 insertions, 5 deletions
@@ -871,12 +871,20 @@ void put_md_name(char *name) } #endif /* !defined(MDASSEMBLE) || defined(MDASSEMBLE) && defined(MDASSEMBLE_AUTO) */ +int get_maj_min(char *dev, int *major, int *minor) +{ + char *e; + *major = strtoul(dev, &e, 0); + return (e > dev && *e == ':' && e[1] && + (*minor = strtoul(e+1, &e, 0)) >= 0 && + *e == 0); +} + int dev_open(char *dev, int flags) { /* like 'open', but if 'dev' matches %d:%d, create a temp * block device and open that */ - char *e; int fd = -1; char devname[32]; int major; @@ -885,10 +893,7 @@ int dev_open(char *dev, int flags) if (!dev) return -1; flags |= O_DIRECT; - major = strtoul(dev, &e, 0); - if (e > dev && *e == ':' && e[1] && - (minor = strtoul(e+1, &e, 0)) >= 0 && - *e == 0) { + if (get_maj_min(dev, &major, &minor)) { snprintf(devname, sizeof(devname), "/dev/.tmp.md.%d:%d:%d", (int)getpid(), major, minor); if (mknod(devname, S_IFBLK|0600, makedev(major, minor)) == 0) { |