File: device.go

package info (click to toggle)
golang-gopkg-freddierice-go-losetup.v1 0.0~git20170407.fc9adea-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 80 kB
  • sloc: makefile: 2
file content (26 lines) | stat: -rw-r--r-- 565 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
package losetup

import (
	"fmt"
	"os"
)

// Device represents a loop device /dev/loop#
type Device struct {
	// device number (i.e. 7 if /dev/loop7)
	number uint64

	// flags with which to open the device with
	flags int
}

// open returns a file handle to /dev/loop# and returns an error if it cannot
// be opened.
func (device Device) open() (*os.File, error) {
	return os.OpenFile(device.Path(), device.flags, 0660)
}

// Path returns the path to the loopback device
func (device Device) Path() string {
	return fmt.Sprintf(DeviceFormatString, device.number)
}