MCPcopy
hub / github.com/etcd-io/bbolt / getFreeLoopDevice

Function getFreeLoopDevice

tests/dmflakey/loopback.go:79–91  ·  view source on GitHub ↗

getFreeLoopDevice allocates or finds a free loop device for use. REF: https://man7.org/linux/man-pages/man4/loop.4.html

()

Source from the content-addressed store, hash-verified

77//
78// REF: https://man7.org/linux/man-pages/man4/loop.4.html
79func 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}

Callers 1

attachToLoopDeviceFunction · 0.85

Calls 2

ErrorfMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected