system

package
v0.0.0-...-5969d1b Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2023 License: Apache-2.0 Imports: 14 Imported by: 9

Documentation

Index

Constants

View Source
const (
	// ioctl magics from <linux/fs.h>
	IOCTL_FIFREEZE_MAGIC uint = 0xC0045877 // _IOWR('X', 119, int)
	IOCTL_FITHAW_MAGIC   uint = 0xC0045878 // _IOWR('X', 120, int)
)

Variables

View Source
var (
	ErrDevNotMounted = fmt.Errorf("device not mounted")
	NotABlockDevice  = fmt.Errorf("not a block device")
)

Functions

func FreezeFS

func FreezeFS(fd int) error

FreezeFS freezes the filesystem for which the inode that fd points to belongs to, maintaining read-consistency. All write operations to the filesystem will be blocked until ThawFS is called.

func GetBlockDeviceFromID

func GetBlockDeviceFromID(devID [2]uint32) (string, error)

GetBlockDeviceFromID returns the expanded path to the device with the given device ID, devID, on the form [2]uint32{major, minor}

func GetBlockDeviceSectorSize

func GetBlockDeviceSectorSize(file *os.File) (int, error)

func GetBlockDeviceSize

func GetBlockDeviceSize(file *os.File) (uint64, error)

func GetDeviceIDFromPath

func GetDeviceIDFromPath(path string) ([2]uint32, error)

GetDeviceIDFromPath retrieves the device id for the block device pointed to by the inode at path.

func GetPipeSize

func GetPipeSize(fd int) int

GetPipeSize returns the buffer-size of a pipe or 1 if the file descriptor is not a pipe.

func IsUbiBlockDevice

func IsUbiBlockDevice(deviceName string) bool

func NewCmdLoggerStderr

func NewCmdLoggerStderr(cmd string) *cmdLogger

func NewCmdLoggerStdout

func NewCmdLoggerStdout(cmd string) *cmdLogger

func SetUbiUpdateVolume

func SetUbiUpdateVolume(file *os.File, imageSize uint64) error

func ThawFS

func ThawFS(fd int) error

ThawFS unfreezes the filesystem after FreezeFS is called. The error returned by this function is system critical, if we can't unfreeze the filesystem, we need to ask the user to run `fsfreeze -u /` if this fails then the user has no option but to "pull the plug" (or sys request unfreeze?)

Types

type Cmd

type Cmd struct {
	*exec.Cmd
}

func Command

func Command(name string, arg ...string) *Cmd

Command wraps the golang/exec Cmd struct, and captures the stderr/stdout output by default, and logs properly.

func (*Cmd) CombinedOutput

func (c *Cmd) CombinedOutput() ([]byte, error)

func (*Cmd) Output

func (c *Cmd) Output() ([]byte, error)

func (*Cmd) Run

func (c *Cmd) Run() error

func (*Cmd) StderrPipe

func (c *Cmd) StderrPipe() (io.ReadCloser, error)

func (*Cmd) StdoutPipe

func (c *Cmd) StdoutPipe() (io.ReadCloser, error)

func (*Cmd) Wait

func (c *Cmd) Wait() error

type Commander

type Commander interface {
	Command(name string, arg ...string) *Cmd
}

type Flusher

type Flusher interface {
	Flush()
}

type MountInfo

type MountInfo struct {
	// MountID: is the unique identifier of the mount
	MountID uint32 // (1)
	// ParentID: is the MountID of the parent (or self if on top)
	ParentID uint32 // (2)
	// DevID: is the st_dev uint32{Major, Minor} number of the device
	DevID [2]uint32 // (3)
	// Root: root of the mount within the filesystem
	Root string // (4)
	// MountPoint: mount point relative to the process's root
	MountPoint string // (5)
	// MountSource: filesystem specific information or "none"
	MountSource string // (10)
	// FSType: name of the filesystem of the form "type[.subtype]"
	FSType string // (9)
	// MountOptions: per mount options
	MountOptions []string // (6)
	// TagFields: optional list of fields of the form "tag[:value]"
	TagFields []string // (7)
	// SuperOptions: per super block options
	SuperOptions []string // (11)
}

MountInfo maps a single line in /proc/<pid|self>/mountinfo See the linux kernel documentation: linux/Documentation/filesystems/proc.txt A line takes the form: 36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue (1)(2)(3) (4) (5) (6) (7) (8) (9) (10) (11)

func GetMountInfoFromDeviceID

func GetMountInfoFromDeviceID(devID [2]uint32) (*MountInfo, error)

GetMountInfoFromDeviceID parses /proc/self/mountinfo and, on success, returns a populated MountInfo for the device given the devID ([2]uint32{major, minor}). If the device is not mounted ErrDevNotMounted is returned, otherwise the function returns an internal error with a descriptive error message. NOTE: You can get the mount info of an arbitrary path by first calling

"GetDeviceIDFromPath".

Pro tip: use together with GetDeviceIDFromPath to get

type OsCalls

type OsCalls struct {
}

we need real OS implementation

func (OsCalls) Command

func (OsCalls) Command(name string, arg ...string) *Cmd

func (OsCalls) Stat

func (OsCalls) Stat(name string) (os.FileInfo, error)

type StatCommander

type StatCommander interface {
	Stat(string) (os.FileInfo, error)
	Commander
}

type SysLinux

type SysLinux interface {
	Stat(string, *stat) error
	RawSyscall(uintptr, uintptr, uintptr, uintptr) (uintptr, uintptr, unix.Errno)
	IoctlSetInt(int, uint, int) error
	OpenMountInfo() (io.ReadCloser, error)
	DeviceFromID([2]uint32) (string, error)
	GetPipeSize(fd int) int
}

SysLinux wraps the interface to unix-specific system calls or functions that make assertions about the system is running linux.

type SystemRebootCmd

type SystemRebootCmd struct {
	// contains filtered or unexported fields
}

func NewSystemRebootCmd

func NewSystemRebootCmd(command Commander) *SystemRebootCmd

func (*SystemRebootCmd) Reboot

func (s *SystemRebootCmd) Reboot() error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL