12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- package raid
- import (
- "bufio"
- "fmt"
- "os"
- "strings"
- )
- // Get the next avaible RAID array name
- func GetNextAvailableMDDevice() (string, error) {
- for i := 0; i < 100; i++ {
- mdDevice := fmt.Sprintf("/dev/md%d", i)
- if _, err := os.Stat(mdDevice); os.IsNotExist(err) {
- return mdDevice, nil
- }
- }
- return "", fmt.Errorf("no available /dev/mdX devices found")
- }
- func DeviceIsMounted(devicePath string) (bool, error) {
- // Open the mountinfo file
- file, err := os.Open("/proc/mounts")
- if err != nil {
- return false, fmt.Errorf("error opening /proc/mounts: %v", err)
- }
- defer file.Close()
- // Scan the mountinfo file line by line
- scanner := bufio.NewScanner(file)
- for scanner.Scan() {
- line := scanner.Text()
- fields := strings.Fields(line)
- if len(fields) >= 2 && fields[0] == devicePath {
- // Device is mounted
- return true, nil
- }
- }
- // Device is not mounted
- return false, nil
- }
|