utils.go 558 B

1234567891011121314151617181920212223242526272829
  1. package bingocloud
  2. import (
  3. "fmt"
  4. "strings"
  5. )
  6. func nextDeviceName(curDeviceNames []string) (string, error) {
  7. var currents []string
  8. for _, item := range curDeviceNames {
  9. currents = append(currents, strings.ToLower(item))
  10. }
  11. for i := 0; i < 25; i++ {
  12. device := fmt.Sprintf("/dev/vd%c", byte(98+i))
  13. found := false
  14. for _, item := range currents {
  15. if strings.HasPrefix(item, device) {
  16. found = true
  17. }
  18. }
  19. if !found {
  20. return device, nil
  21. }
  22. }
  23. return "", fmt.Errorf("disk devicename out of index, current deivces: %s", currents)
  24. }