system

package
v0.0.0-...-947e471 Latest Latest
Warning

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

Go to latest
Published: Apr 15, 2024 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Copyright 2023 Northern.tech AS

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

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 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 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 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 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.

Jump to

Keyboard shortcuts

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