getFreeLoopDevice allocates or finds a free loop device for use. REF: https://man7.org/linux/man-pages/man4/loop.4.html
()
| 77 | // |
| 78 | // REF: https://man7.org/linux/man-pages/man4/loop.4.html |
| 79 | func getFreeLoopDevice() (string, error) { |
| 80 | control, err := os.OpenFile(loopControlDevice, os.O_RDWR, 0) |
| 81 | if err != nil { |
| 82 | return "", fmt.Errorf("failed to open %s: %w", loopControlDevice, err) |
| 83 | } |
| 84 | |
| 85 | idx, err := unix.IoctlRetInt(int(control.Fd()), unix.LOOP_CTL_GET_FREE) |
| 86 | control.Close() |
| 87 | if err != nil { |
| 88 | return "", fmt.Errorf("failed to get free loop device number: %w", err) |
| 89 | } |
| 90 | return fmt.Sprintf(loopDevicePattern, idx), nil |
| 91 | } |
no test coverage detected