return a list of all available drives
()
| 302 | |
| 303 | // return a list of all available drives |
| 304 | func findDrives() { |
| 305 | driveKeys = []string{} |
| 306 | ignoreExp := regexp.MustCompile(`^loop.*$|^nbd.*$|^[a-z]+[0-9]+$`) |
| 307 | devs, _ := ioutil.ReadDir("/dev") |
| 308 | for _, d := range devs { |
| 309 | // this probably shouldn't be so hard |
| 310 | // but d.Mode()&os.ModeDevice == 0 doesn't work as expected |
| 311 | mode := d.Sys().(*syscall.Stat_t).Mode |
| 312 | if (mode & syscall.S_IFMT) != syscall.S_IFBLK { |
| 313 | continue |
| 314 | } |
| 315 | // ignore if it matches regexp |
| 316 | if ignoreExp.MatchString(d.Name()) { |
| 317 | continue |
| 318 | } |
| 319 | driveKeys = append(driveKeys, filepath.Join("/dev", d.Name())) |
| 320 | } |
| 321 | sort.Strings(driveKeys) |
| 322 | } |
| 323 | |
| 324 | func init() { |
| 325 | flag.StringVar(&fsTypeVar, "type", "ext4", "Type of filesystem to create") |