diff options
author | Neil Brown <neilb@suse.de> | 2008-05-05 21:55:36 +1000 |
---|---|---|
committer | Neil Brown <neilb@suse.de> | 2008-05-05 21:55:36 +1000 |
commit | 63152c1b330f75842644c82d925fa8dcd37fe233 (patch) | |
tree | 67a29eefae0b8b7a76cfb11e286eec1b7877efea /util.c | |
parent | 5e747af24abc021073d979925628fec28052a731 (diff) |
Unify code into find_free_devnum.
Two places have code to find a free md device number. Make this
a subroutine.
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -862,6 +862,43 @@ void get_one_disk(int mdfd, mdu_array_info_t *ainf, mdu_disk_info_t *disk) if (ioctl(mdfd, GET_DISK_INFO, disk) == 0) return; } + +static int dev2major(int d) +{ + if (d >= 0) + return MD_MAJOR; + else + return get_mdp_major(); +} + +static int dev2minor(int d) +{ + if (d >= 0) + return d; + return (-1-d) << MdpMinorShift; +} + +int find_free_devnum(int use_partitions) +{ + int devnum; + for (devnum = 127; devnum != 128; + devnum = devnum ? devnum-1 : (1<<22)-1) { + char *dn; + if (mddev_busy(use_partitions ? (-1-devnum) : devnum)) + continue; + /* make sure it is new to /dev too, at least as a + * non-standard */ + dn = map_dev(dev2major(devnum), dev2minor(devnum), 0); + if (dn && ! is_standard(dn, NULL)) + continue; + break; + } + if (devnum == 128) + return NoMdDev; + return use_partitions ? (-1-devnum) : devnum; +} + + #ifdef __TINYC__ /* tinyc doesn't optimize this check in ioctl.h out ... */ unsigned int __invalid_size_argument_for_IOC = 0; |