btrfsutil

package module
v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Jun 28, 2023 License: LGPL-2.1 Imports: 8 Imported by: 0

README

libbtrfsutil-go

Go bindings for libbtrfsutil

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrStopIteration          = errors.New("stop iteration")
	ErrNoMemory               = errors.New("cannot allocate memory")
	ErrInvalidArgument        = errors.New("invalid argument")
	ErrNotBtrfs               = errors.New("not a Btrfs filesystem")
	ErrNotSubvolume           = errors.New("not a Btrfs subvolume")
	ErrSubvolumeNotFound      = errors.New("subvolume not found")
	ErrOpenFailed             = errors.New("could not open")
	ErrRmdirFailed            = errors.New("could not rmdir")
	ErrUnlinkFailed           = errors.New("could not unlink")
	ErrStatFailed             = errors.New("could not stat")
	ErrStatfsFailed           = errors.New("could not statfs")
	ErrSearchFailed           = errors.New("could not search B-tree")
	ErrInoLookupFailed        = errors.New("could not lookup inode")
	ErrSubvolGetflagsFailed   = errors.New("could not get subvolume flags")
	ErrSubvolSetflagsFailed   = errors.New("could not set subvolume flags")
	ErrSubvolCreateFailed     = errors.New("could not create subvolume")
	ErrSnapCreateFailed       = errors.New("could not create snapshot")
	ErrSnapDestroyFailed      = errors.New("could not destroy subvolume/snapshot")
	ErrDefaultSubvolFailed    = errors.New("could not set default subvolume")
	ErrSyncFailed             = errors.New("could not sync filesystem")
	ErrStartSyncFailed        = errors.New("could not start filesystem sync")
	ErrWaitSyncFailed         = errors.New("could not wait for filesystem sync")
	ErrGetSubvolInfoFailed    = errors.New("could not get subvolume information with BTRFS_IOC_GET_SUBVOL_INFO")
	ErrGetSubvolRootrefFailed = errors.New("could not get rootref information with BTRFS_IOC_GET_SUBVOL_ROOTREF")
	ErrInoLookupUserFailed    = errors.New("could not resolve subvolume path with BTRFS_IOC_INO_LOOKUP_USER")
	ErrFsInfoFailed           = errors.New("could not get filesystem information")
)

Functions

func CreateSnapshot

func CreateSnapshot(source string, path string, recursive bool, read_only bool) error

CreateSnapshot creates a new snapshot from a source subvolume path. If source is not a subvolume the subvolume containing source will be snapshotted

func CreateSnapshotFd

func CreateSnapshotFd(fd uintptr, path string, recursive bool, read_only bool) error

See CreateSnapshot

func CreateSnapshotFd2

func CreateSnapshotFd2(fd uintptr, parent_fd uintptr, name string, recursive bool, read_only bool) error

CreateSnapshotFd2 creates a new snapshot form a source subvolume file descriptor, a target parent file descriptor and name.

func CreateSnapshotWithQgroup

func CreateSnapshotWithQgroup(source string, path string, recursive bool, read_only bool, qgroup_inherit *QgroupInherit) error

CreateSnapshotWithQgroup creates a new snapshot from a source subvolume path with Qgroups to inherit from.

func CreateSnapshotWithQgroupFd

func CreateSnapshotWithQgroupFd(fd uintptr, path string, recursive bool, read_only bool, qgroup_inherit *QgroupInherit) error

See CreateSnapshotWithQgroup.

func CreateSnapshotWithQgroupFd2

func CreateSnapshotWithQgroupFd2(fd uintptr, parent_fd uintptr, name string, recursive bool, read_only bool, qgroup_inherit *QgroupInherit) error

CreateSnapshotWithQgroupFd2 creates a new snapshot form a source subvolume file descriptor, a target parent file descriptor and name, with Qgroups to inherit from.

func CreateSubvolume

func CreateSubvolume(path string) error

CreateSubvolume creates a new subvolume under a given path.

func CreateSubvolumeFd

func CreateSubvolumeFd(parent_fd uintptr, name string) error

func CreateSubvolumeWithQgroup

func CreateSubvolumeWithQgroup(path string, qgroup_inherit *QgroupInherit) error

CreateSubvolumeWithQgroup creates a new subvolume under a given path, with Qgroups to inherit from.

func CreateSubvolumeWithQgroupFd

func CreateSubvolumeWithQgroupFd(parent_fd uintptr, name string, qgroup_inherit *QgroupInherit) error

CreateSubvolumeWithQgroupFd creates a new subvolume given its parent file descriptor, a name and Qgroups to inherit from.

func DeleteSubvolume

func DeleteSubvolume(path string, recursive bool) error

DeleteSubvolume deletes a subvolume or snapshot. If recursive is set subvolumes beneath the given subvolume will be deleted befor attempting to delete the given subvolume. Unless the filesystem is mounted with 'user_subvol_rm_allow', appropriate privileges are required (CAP_SYS_ADMIN).

func DeleteSubvolumeByIdFd

func DeleteSubvolumeByIdFd(parent_fd uintptr, subvolid uint64) error

DeleteSubvolumeByIdFd deletes a subvolume or snapshot by its parent file descriptor and id. See DeleteSubvolume

func DeleteSubvolumeFd

func DeleteSubvolumeFd(parent_fd uintptr, name string, recursive bool) error

DeleteSubvolumeFd deletes a subvolume or snapshot by its parent file descriptor and name. See DeleteSubvolume.

func DeletedSubvolumes

func DeletedSubvolumes(path string) ([]uint64, error)

DeletedSubvolumes returns a list of subvolume IDs which have been deleted but not yet cleaned up.

func DeletedSubvolumesFd

func DeletedSubvolumesFd(fd uintptr) ([]uint64, error)

See DeletedSubvolumesFd.

func GetCError added in v0.1.2

func GetCError(err error) uint32

func GetDefaultSubvolume

func GetDefaultSubvolume(path string) (uint64, error)

GetDefaultSubvolume returns the default subvolume ID for a filesystem.

func GetDefaultSubvolumeFd

func GetDefaultSubvolumeFd(fd uintptr) (uint64, error)

See GetDefaultSubvolume.

func GetSubvolumeReadOnly

func GetSubvolumeReadOnly(path string) (bool, error)

GetSubvolumeReadOnly returns whether a subvolume is read-only.

func GetSubvolumeReadOnlyFd

func GetSubvolumeReadOnlyFd(fd uintptr) (bool, error)

See GetSubvolumeReadOnly.

func IsSubvolume

func IsSubvolume(path string) (bool, error)

IsSubvolume returns whether a given path is a Btrfs subvolume.

func IsSubvolumeFd

func IsSubvolumeFd(fd uintptr) (bool, error)

See IsSubvolume.

func SetDefaultSubvolume

func SetDefaultSubvolume(path string, id uint64) error

SetDefaultSubvolume sets the default subvolume for a filesystem. The given path may be any path in the Btrfs filesystem; it dose not have to refer to a subvolume unless id is zero. If the given ID is zero, the subvolume ID of the subvolume containing path is used.

func SetDefaultSubvolumeFd

func SetDefaultSubvolumeFd(fd uintptr, id uint64) error

See SetDefaultSubvolume.

func SetSubvolumeReadOnly

func SetSubvolumeReadOnly(path string, read_only bool) error

SetSubvolumeReadOnly sets whether a subvolume is read-only.

func SetSubvolumeReadOnlyFd

func SetSubvolumeReadOnlyFd(fd uintptr, read_only bool) error

See SetSubvolumeReadOnly.

func StartSync

func StartSync(path string) (uint64, error)

StartsSync starts a sync on a specific Btrfs filesystem but dose not wait for it.

func StratSyncFd

func StratSyncFd(fd uintptr) (uint64, error)

See StartSync.

func SubvolumeId

func SubvolumeId(path string) (uint64, error)

SubvolumeId returns the ID of the subvolume containing a given path.

func SubvolumeIdFd

func SubvolumeIdFd(fd uintptr) (uint64, error)

See SubvolumeId.

func SubvolumePath

func SubvolumePath(path string, id uint64) (string, error)

SubvolumePath returns the path of the subvolume with a given ID.

func SubvolumePathFd

func SubvolumePathFd(fd uintptr, id uint64) (string, error)

See SubvolumePath.

func Sync

func Sync(path string) error

Sync forces a sync on a specific Btrfs filesystem.

func SyncFd

func SyncFd(fd uintptr) error

See Sync.

func WaitSync

func WaitSync(path string, transid uint64) error

WaitSync waits for a transaction with a given ID to sync. If the given ID is zero, WaitSync waits for the current transaction.

func WaitSyncFd

func WaitSyncFd(fd uintptr, transid uint64) error

See WaitSync.

Types

type QgroupInherit

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

QgroupInherit is the qgroup inheritance specifier for SubvolumeCreate or SubvolumeSnapshot.

func CreateQgroupInherit

func CreateQgroupInherit() (*QgroupInherit, error)

CreateQgroupInherit creates a qgroup inheritance specifier. The returnd QgroupInherit struct must be freed with Destroy().

func (QgroupInherit) AddGroup

func (q QgroupInherit) AddGroup(groupid uint64) error

AddGroup adds an inheritance from a qgroup with the given ID to a qgroup inheritance specifier.

func (QgroupInherit) Destroy

func (q QgroupInherit) Destroy()

Destroy destroyes the qgroup inheritance specifier.

func (QgroupInherit) GetGroups

func (q QgroupInherit) GetGroups() []uint64

GetGroups returs the qgroup IDs contained in a qgroup inheritance specifier.

type SubvolumeInfo

type SubvolumeInfo struct {
	Id           uint64
	ParentId     uint64
	DirId        uint64
	Flags        uint64
	UUID         string
	ParentUUID   string
	ReceivedUUID string
	Generation   uint64
	Ctransid     uint64
	Otransid     uint64
	Stransid     uint64
	Rtransid     uint64
	Ctime        time.Time
	Otime        time.Time
	Stime        time.Time
	Rtime        time.Time
}

SubvolumeInfo is a representation of a Btrfs subvolume or snapshot.

func GetSubvolumeInfo

func GetSubvolumeInfo(path string, id uint64) (*SubvolumeInfo, error)

GetSubvolumeInfo returns information about a subvolume with a given ID or path. The given path may be any path in the Btrfs filesystem; it dose not have to refer to a subvolume unless id is zero. If the given ID is zero, the subvolume ID of the subvolume containing path is used.

func GetSubvolumeInfoFd

func GetSubvolumeInfoFd(fd uintptr, id uint64) (*SubvolumeInfo, error)

See GetSubvolumeInfo.

type SubvolumeInfoIterator added in v0.1.3

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

func CreateSubvolumeInfoIterator added in v0.1.3

func CreateSubvolumeInfoIterator(path string, top uint64, post_order bool) (*SubvolumeInfoIterator, error)

Identical to CreateSubvolumeIterator but GetNext() returns a SubvolumeInfo insted of a subvolume Id. The returnd SubvolumeInfoIterator struct must be freed with Destroy().

func CreateSubvolumeInfoIteratorFd added in v0.1.3

func CreateSubvolumeInfoIteratorFd(fd uintptr, top uint64, post_order bool) (*SubvolumeInfoIterator, error)

See CreateSubvolumeInfoIterator.

func (*SubvolumeInfoIterator) Destroy added in v0.1.3

func (it *SubvolumeInfoIterator) Destroy()

Destroy destroyes the SubvolumeInfoIterator.

func (*SubvolumeInfoIterator) Fd added in v0.1.3

func (it *SubvolumeInfoIterator) Fd() uintptr

Fd returns the file descriptor referencing the SubvolumeInfoIterator

func (*SubvolumeInfoIterator) GetNext added in v0.1.3

GetNext gets the Path and SubvolumeInfo of the next subvolume from a SubvolumeInfoIterator.

func (*SubvolumeInfoIterator) HasNext added in v0.1.3

func (it *SubvolumeInfoIterator) HasNext() bool

HasNext returns true if the SubvolumeInfoIterator has a next value.

type SubvolumeInfoIteratorResult added in v0.1.3

type SubvolumeInfoIteratorResult struct {
	Path string
	Info *SubvolumeInfo
}

type SubvolumeIterator

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

func CreateSubvolumeIterator

func CreateSubvolumeIterator(path string, top uint64, post_order bool) (*SubvolumeIterator, error)

CreateSubvolumeIterator creates an iterator over subvolumes in a Btrfs filesystem. Lists all subvolumes beneath (but not including) the subvolume with the ID top. The given path may be any path in the Btrfs filesystem; it dose not have to refer to a subvolume unless top is zero. If the as top given ID is zero, the subvolume ID of the subvolume containing path is used. By default subvolumes are listed pre-order e.g., foo will be yielded befor foo/bar. This behavior can be reversed by setting post_order. The returnd SubvolumeIterator struct must be freed with Destroy().

func CreateSubvolumeIteratorFd

func CreateSubvolumeIteratorFd(fd uintptr, top uint64, post_order bool) (*SubvolumeIterator, error)

See CreateSubvolumeIterator.

func (*SubvolumeIterator) Destroy

func (it *SubvolumeIterator) Destroy()

Destroy destroyes the SubvolumeIterator.

func (*SubvolumeIterator) Fd

func (it *SubvolumeIterator) Fd() uintptr

Fd returns the file descriptor referencing the SubvolumeIterator

func (*SubvolumeIterator) GetNext added in v0.1.3

GetNext gets the Path and Id of the next subvolume from a SubvolumeIterator.

func (*SubvolumeIterator) HasNext added in v0.1.3

func (it *SubvolumeIterator) HasNext() bool

HasNext returns true if the SubvolumeIterator has a next value.

type SubvolumeIteratorResult added in v0.1.3

type SubvolumeIteratorResult struct {
	Path string
	Id   uint64
}

Jump to

Keyboard shortcuts

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