fs

package
v0.0.0-...-6d2d128 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2017 License: GPL-3.0 Imports: 16 Imported by: 4

Documentation

Overview

cryptctl - Copyright (c) 2017 SUSE Linux GmbH, Germany This source code is licensed under GPL version 3 that can be found in LICENSE file.

cryptctl - Copyright (c) 2017 SUSE Linux GmbH, Germany This source code is licensed under GPL version 3 that can be found in LICENSE file.

cryptctl - Copyright (c) 2017 SUSE Linux GmbH, Germany This source code is licensed under GPL version 3 that can be found in LICENSE file.

cryptctl - Copyright (c) 2017 SUSE Linux GmbH, Germany This source code is licensed under GPL version 3 that can be found in LICENSE file.

Index

Constants

View Source
const (
	BIN_CRYPTSETUP  = "/sbin/cryptsetup"
	LUKS_CIPHER     = "aes-xts-plain64:PBKDF2-sha512"
	LUKS_HASH       = "sha512"
	LUKS_KEY_SIZE_S = "512"
	LUKS_KEY_SIZE_I = 512
)
View Source
const (
	BIN_RSYNC        = "/usr/bin/rsync"
	ERASE_NUM_PASS   = 10
	ERASE_BLOCK_SIZE = 128 * 1024
)
View Source
const (
	BIN_MKFS   = "/usr/sbin/mkfs"
	BIN_LSBLK  = "/usr/bin/lsblk"
	BIN_MOUNT  = "/usr/bin/mount"
	BIN_UMOUNT = "/usr/bin/umount"
)

Variables

This section is empty.

Functions

func CheckBlockDevice

func CheckBlockDevice(filePath string) error

Return nil if the file specified is a block device. Return an error otherwise.

func CryptClose

func CryptClose(name string) error

Call cryptsetup luksClose on the mapped device node.

func CryptErase

func CryptErase(blockDev string) error

Call cryptsetup erase on the block device node.

func CryptFormat

func CryptFormat(key []byte, blockDev, uuid string) error

Call cryptsetup luksFormat on the block device node.

func CryptOpen

func CryptOpen(key []byte, blockDev, name string) error

Call cryptsetup luksOpen on the block device node.

func FileContains

func FileContains(paths, substr string) error

Test whether file at the specified path can be read and contains the string. Case is sensitive.

func FileSpaceUsage

func FileSpaceUsage(paths string) (totalSize int64, err error)

Count the total space usage of the specified path; the path can be either a file or a directory.

func Format

func Format(blockDev, fsType string) error

Call mkfs to make a new file system on the block device.

func FreeSpace

func FreeSpace(paths string) (int64, error)

Return amount of free space available on the disk where input paths is mounted on.

func GetSystemdMountNameForDir

func GetSystemdMountNameForDir(dirPath string) string

GetSystemdMountNameForDir returns systemd's mount unit associated with the directory, supposedly a mount point.

func IsDir

func IsDir(paths string) error

Test whether the specified directory can be read.

func MirrorFiles

func MirrorFiles(srcDir, destDir string, progressOut io.Writer) error

Call rsync to recursively copy all files under source directory, including all file attributes/links, to the destination directory. If supplied, rsync progress output will be copied to the output stream. If some files already exist in the destination and the source files are newer, they will be overwritten. Both source directory and destination directory must be absolute.

func Mount

func Mount(blockDev, fsType string, fsOptions []string, mountPoint string) error

Call mount to mount a file system. The mounted file system will be exposed to all processes on the computer.

func SecureErase

func SecureErase(filePath string, delete bool) error

Securely erase a file by overwriting it 10 times with random data, then delete the file. Needless to say this function is painfully slow. It relies on a vital assumption that the file system will overwrite data in place, bear in mind that many modern file systems and hardware designs do not satisfy the assumption, here are some examples: - Metadata/data journal. - Data compression. - Transient or persistent cache. - Additional redundancy mechanisms such as RAID.

func Umount

func Umount(mountPoint string) error

Umount un-mounts a file system by interacting with systemd.

Types

type BlockDevice

type BlockDevice struct {
	UUID       string
	Name       string // Name is the device node name
	Path       string // full path to the device node under /dev including the prefix
	Type       string // device type can be: partition, disk, encrypted, etc..
	FileSystem string
	MountPoint string
	SizeByte   int64
	PKName     string // PKName is the underlying block device's node name of a crypt block device
}

Represent a block device currently detected on the system.

func GetBlockDevice

func GetBlockDevice(node string) (blkDev BlockDevice, found bool)

Return information about the specific block device. The path of block device in return value will match the input device node path.

func (BlockDevice) IsLUKSEncrypted

func (blkDev BlockDevice) IsLUKSEncrypted() bool

Return true if the block device is LUKS encrypted.

type BlockDevices

type BlockDevices []BlockDevice

A list of block devices.

func GetBlockDevices

func GetBlockDevices() BlockDevices

Return all block devices currently detected on the system.

func ParseBlockDevs

func ParseBlockDevs(txt string) BlockDevices

Return all block devices defined in the input text. The input text is presumed to be obtained from the following command's output:

lsblk -P -b -o UUID,KNAME,TYPE,FSTYPE,MOUNTPOINT,SIZE

func (BlockDevices) GetByCriteria

func (blkDevs BlockDevices) GetByCriteria(uuid, devPath, devType, fileSystem, mountPoint, pkName, name string) (BlockDevice, bool)

Find the first block device that satisfies the given criteria. If a criteria is empty, it is ignored.

type CryptMapping

type CryptMapping struct {
	Type    string
	Cipher  string
	KeySize int
	Device  string
	Loop    string
}

Represent a cryptsetup mapping currently effective on the system.

func CryptStatus

func CryptStatus(name string) (mapping CryptMapping, err error)

Get luks device status. An error will be returned if the mapping status cannot be retrieved.

func ParseCryptStatus

func ParseCryptStatus(txt string) (mapping CryptMapping)

Return cryptsetup status (a device mapper device) parsed from the text.

func (CryptMapping) IsValid

func (mapping CryptMapping) IsValid() bool

Return true only if all fields (except Loop) are assigned.

type MountPoint

type MountPoint struct {
	DeviceNode string
	MountPoint string
	FileSystem string
	Options    []string
	Dump       int
	Fsck       int
}

Represent a mount point entry in /etc/mtab.

func (*MountPoint) DiscardBtrfsSubvolume

func (mount *MountPoint) DiscardBtrfsSubvolume()

Remove btrfs subvolume among mount options. The MountPoint is modified in-place.

func (MountPoint) Equals

func (mount1 MountPoint) Equals(mount2 MountPoint) bool

Return true only if two mount points are identical in all attributes.

func (MountPoint) GetFileSystemSizeByte

func (mount MountPoint) GetFileSystemSizeByte() (int64, error)

Return the total size of the file system in Bytes.

type MountPoints

type MountPoints []MountPoint

A list of mount points.

func ParseMountPoints

func ParseMountPoints(txt string) (mounts MountPoints)

Return all mount points defined in the input text except rootfs. Panic on malformed entry.

func ParseMtab

func ParseMtab() MountPoints

Return all mount points that appear in /etc/mtab. Panic on error.

func (MountPoints) GetByCriteria

func (mounts MountPoints) GetByCriteria(deviceNode, mountPoint, fileSystem string) (MountPoint, bool)

Find the first mount point that satisfies the given criteria. If a criteria is empty, it is ignored.

func (MountPoints) GetManyByCriteria

func (mounts MountPoints) GetManyByCriteria(deviceNode, mountPoint, fileSystem string) (ret MountPoints)

Find the all mount points that satisfy the given criteria. If a criteria is empty, it is ignored.

func (MountPoints) GetMountPointOfPath

func (mounts MountPoints) GetMountPointOfPath(fileOrDirPath string) (MountPoint, bool)

Find mount point for an arbitrary directory or file specified by an absolute path.

Jump to

Keyboard shortcuts

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