Documentation ¶
Index ¶
- Constants
- Variables
- func Backup(path string) error
- func CheckSumCompare(t string, w io.Writer, flagSet *flag.FlagSet, suppress bool) error
- func CheckSumMain(t string, w io.Writer, flagSet *flag.FlagSet, suppress bool) error
- func Checksum(t string, fp io.Reader) (string, error)
- func CompareSlice(s1, s2 []byte) (int, bool)
- func ConvertFileModeStr(mode string) (os.FileMode, error)
- func FileExists(path string) bool
- func FileNotExists(path string) bool
- func GetAllPids() ([]int, error)
- func GetMountpointByDevice(devicePath string) (*string, error)
- func Groups(uname string) ([]user.Group, error)
- func IntContains(target []int, src int) bool
- func IsDecimal(b byte) bool
- func IsDecimalStr(s string, max int) (i int, have bool)
- func IsDir(name string) (bool, error)
- func IsHidden(name string) bool
- func IsMalformedFileMode(mode os.FileMode) bool
- func IsNamedPipe(info os.FileInfo) bool
- func IsNeedStr(s string, max int, is func(b byte) bool) (i int, have bool)
- func IsNumber(s string) (int, bool)
- func IsNumeric(s string) bool
- func IsOctal(b byte) bool
- func IsOctalStr(s string, max int) (i int, haveOctal bool)
- func IsSymlink(info os.FileInfo) bool
- func IsXdigit(b byte) bool
- func IsXdigitStr(s string, max int) (i int, haveHex bool)
- func OpenTwoFiles(files []string) (sf *os.File, df *os.File, err error)
- func ReadWholeLine(b *bufio.Reader) (line string, err error)
- func RenderString(s string, ctx interface{}) (string, error)
- func StringsContains(target []string, src string) bool
- func StringsHas(target []string, src string) bool
- func TTY() (string, error)
- func UniqSortInt(src []int) []int
- func Walk(path string, info os.FileInfo, depth int, parentIgnores IgnoreMatchers, ...) error
- func WrapString(src string, lim int, delim string) string
- type BlockDev
- func (b *BlockDev) BlockSize() (int, error)
- func (b BlockDev) DevicePath() string
- func (b *BlockDev) GPTTable() (*gpt.Table, error)
- func (b *BlockDev) KernelBlockSize() (int, error)
- func (b *BlockDev) PhysicalBlockSize() (int, error)
- func (b *BlockDev) ReadPartitionTable() error
- func (b *BlockDev) Size() (uint64, error)
- func (b *BlockDev) String() string
- type BlockDevices
- func (b BlockDevices) FilterFSUUID(fsuuid string) BlockDevices
- func (b BlockDevices) FilterHavingPartitions(parts []int) BlockDevices
- func (b BlockDevices) FilterName(name string) BlockDevices
- func (b BlockDevices) FilterNames(names ...string) BlockDevices
- func (b BlockDevices) FilterPartID(guid string) BlockDevices
- func (b BlockDevices) FilterPartLabel(label string) BlockDevices
- func (b BlockDevices) FilterPartType(guid string) BlockDevices
- func (b BlockDevices) FilterZeroSize() BlockDevices
- type BufferedReader
- type IgnoreMatcher
- type IgnoreMatchers
- type Process
- type SI
- type Size
- type UnameInfo
Constants ¶
const ( B Size = 1 K = 1024 * B M = 1024 * K G = 1024 * M T = 1024 * G P = 1024 * T E = 1024 * P )
const BackupSuffix = "~"
Variables ¶
var ( // LinuxMountsPath is the standard mountpoint list path LinuxMountsPath = "/proc/mounts" // Debug function to override for verbose logging. Debug = func(string, ...interface{}) {} // SystemPartitionGUID is the GUID of EFI system partitions // EFI System partitions have GUID C12A7328-F81F-11D2-BA4B-00A0C93EC93B SystemPartitionGUID = gpt.Guid([...]byte{ 0x28, 0x73, 0x2a, 0xc1, 0x1f, 0xf8, 0xd2, 0x11, 0xba, 0x4b, 0x00, 0xa0, 0xc9, 0x3e, 0xc9, 0x3b, }) )
Functions ¶
func CheckSumCompare ¶
func CheckSumMain ¶
func CompareSlice ¶
func FileExists ¶
func FileNotExists ¶
func GetMountpointByDevice ¶
GetMountpointByDevice gets the mountpoint by given device name. Returns on first match
func IntContains ¶
IntContains checks the src in any int of the target int slice.
func IsMalformedFileMode ¶
func IsNamedPipe ¶
func RenderString ¶
RenderString renders the string `s` as a `text/template` using the provided context `ctx` as input into the template. Typically used to render the results into a Markdown document.
func StringsContains ¶
StringsContains checks the src in any string of the target string slice
func StringsHas ¶
StringsHas checks the target string slice contains src or not
func UniqSortInt ¶
Types ¶
type BlockDev ¶
BlockDev maps a device name to a BlockStat structure for a given block device
func Device ¶
Device makes sure the block device exists and returns a handle to it.
maybeDevpath can be path like /dev/sda1, /sys/class/block/sda1 or just sda1. We will just use the last component.
func (BlockDev) DevicePath ¶
DevicePath is the path to the actual device.
func (*BlockDev) GPTTable ¶
GPTTable tries to read a GPT table from the block device described by the passed BlockDev object, and returns a gpt.Table object, or an error if any
func (*BlockDev) KernelBlockSize ¶
KernelBlockSize returns the soft block size used inside the kernel (BLKBSZGET).
func (*BlockDev) PhysicalBlockSize ¶
PhysicalBlockSize returns the physical block size.
func (*BlockDev) ReadPartitionTable ¶
ReadPartitionTable prompts the kernel to re-read the partition table on this block device.
type BlockDevices ¶
type BlockDevices []*BlockDev
BlockDevices is a list of block devices.
func GetBlockDevices ¶
func GetBlockDevices() (BlockDevices, error)
GetBlockDevices iterates over /sys/class/block entries and returns a list of BlockDev objects, or an error if any
func (BlockDevices) FilterFSUUID ¶
func (b BlockDevices) FilterFSUUID(fsuuid string) BlockDevices
FilterFSUUID returns a list of BlockDev objects whose underlying block device has a filesystem with the given FSUUID.
func (BlockDevices) FilterHavingPartitions ¶
func (b BlockDevices) FilterHavingPartitions(parts []int) BlockDevices
FilterHavingPartitions returns BlockDevices with have the specified partitions. (e.g. f(1, 2) {sda, sda1, sda2, sdb} -> {sda})
func (BlockDevices) FilterName ¶
func (b BlockDevices) FilterName(name string) BlockDevices
FilterName returns a list of BlockDev objects whose underlying block device has a Name with the given Name
func (BlockDevices) FilterNames ¶
func (b BlockDevices) FilterNames(names ...string) BlockDevices
FilterNames filters block devices by the given list of device names (e.g. /dev/sda1 sda2 /sys/class/block/sda3).
func (BlockDevices) FilterPartID ¶
func (b BlockDevices) FilterPartID(guid string) BlockDevices
FilterPartID returns partitions with the given partition ID GUID.
func (BlockDevices) FilterPartLabel ¶
func (b BlockDevices) FilterPartLabel(label string) BlockDevices
FilterPartLabel returns a list of BlockDev objects whose underlying block device has the given partition label. The name comparison is case-insensitive.
func (BlockDevices) FilterPartType ¶
func (b BlockDevices) FilterPartType(guid string) BlockDevices
FilterPartType returns partitions with the given partition type GUID.
func (BlockDevices) FilterZeroSize ¶
func (b BlockDevices) FilterZeroSize() BlockDevices
FilterZeroSize attempts to find block devices that have at least one block of content.
This serves to eliminate block devices that have no backing storage, but appear in /sys/class/block anyway (like some loop, nbd, or ram devices).
type BufferedReader ¶
func NewBufferedReader ¶
func NewBufferedReader(r io.Reader) *BufferedReader
func (*BufferedReader) ReadWholeLine ¶
func (b *BufferedReader) ReadWholeLine() (line string, err error)
type IgnoreMatcher ¶
type IgnoreMatchers ¶
type IgnoreMatchers []IgnoreMatcher
type Process ¶
type Process struct { *os.Process Name string Owner int Cmdline string State string Parent int MemUsage int }
func GetProcessByPid ¶
type SI ¶
type SI struct { Uptime time.Duration // time since boot Loads [3]float64 // 1, 5, and 15 minute load averages, see e.g. UPTIME(1) Procs uint64 // number of current processes TotalRam uint64 // total usable main memory size FreeRam uint64 // available memory size BufferRam uint64 // memory used by buffers TotalSwap uint64 // total swap space size FreeSwap uint64 // swap space still available TotalHighRam uint64 // total high memory size FreeHighRam uint64 // available high memory size }
Go-ized http://man7.org/linux/man-pages/man2/sysinfo.2.html
func Sysinfo ¶
Get the linux sysinfo data structure.
Useful links in the wild web: http://man7.org/linux/man-pages/man2/sysinfo.2.html http://man7.org/linux/man-pages/man1/uptime.1.html https://github.com/capnm/golang/blob/go1.1.1/src/pkg/syscall/zsyscall_linux_amd64.go#L1050 https://github.com/capnm/golang/blob/go1.1.1/src/pkg/syscall/ztypes_linux_amd64.go#L528 https://github.com/capnm/golang/blob/go1.1.1/src/pkg/syscall/ztypes_linux_arm.go#L502