| 49 | } |
| 50 | |
| 51 | func getFreeLoopDev() (uint32, error) { |
| 52 | ctrl, err := os.OpenFile(loopControlPath, os.O_RDWR, 0) |
| 53 | if err != nil { |
| 54 | return 0, fmt.Errorf("could not open %v: %v", loopControlPath, err) |
| 55 | } |
| 56 | defer ctrl.Close() |
| 57 | num, err := unix.IoctlRetInt(int(ctrl.Fd()), unix.LOOP_CTL_GET_FREE) |
| 58 | if err != nil { |
| 59 | return 0, fmt.Errorf("could not get free loop device: %w", err) |
| 60 | } |
| 61 | return uint32(num), nil |
| 62 | } |
| 63 | |
| 64 | // setupLoopDev attaches the backing file to the loop device and returns |
| 65 | // the file handle for the loop device. The caller is responsible for |