sendstream

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 23, 2022 License: LGPL-3.0 Imports: 9 Imported by: 8

Documentation

Index

Constants

View Source
const (
	BTRFS_SEND_STREAM_MAGIC          = "btrfs-stream\x00"
	BTRFS_SEND_STREAM_VERSION uint32 = 2
)

Variables

View Source
var (
	ErrInvalidMagic           = errors.New("invalid magic")
	ErrInvalidVersion         = errors.New("invalid version")
	ErrHeaderAlreadyParsed    = errors.New("header already parsed")
	ErrInvalidCommandChecksum = errors.New("invalid crc32 checksum for command")
)

Functions

This section is empty.

Types

type CmdAttrs

type CmdAttrs map[SendAttribute][]byte

func (CmdAttrs) SubvolInfo

func (c CmdAttrs) SubvolInfo(cmd SendCommand) (*receivers.ReceivingSubvolume, error)

type CmdHeader

type CmdHeader struct {
	Len uint32
	Cmd SendCommand
	Crc uint32
}

type Scanner

type Scanner struct {
	io.Reader
	// contains filtered or unexported fields
}

Scanner is a send stream scanner. It reads a send stream from an io.Reader and parses it into commands. It is not safe for concurrent use.

func NewScanner

func NewScanner(r io.Reader, ignoreChecksums bool) *Scanner

NewScanner returns a new Scanner that reads from r. If ignoreChecksums is true, the scanner will ignore crc32 checksum errors.

func (*Scanner) Command

func (s *Scanner) Command() (*CmdHeader, CmdAttrs)

Command returns the most recent command generated by a call to Scan.

func (*Scanner) Err

func (s *Scanner) Err() error

Err returns the first non-EOF/non-END error that was encountered by the Scanner.

func (*Scanner) ReadCommand

func (s *Scanner) ReadCommand() (*CmdHeader, CmdAttrs, error)

ReadCommand reads the next command from r.

func (*Scanner) ReadHeader

func (s *Scanner) ReadHeader(validate bool) (*StreamHeader, error)

ReadHeader reads the stream header from r. It returns an error if the header is invalid or has already been parsed. If validate is false, the magic and version are not validated.

func (*Scanner) Scan

func (s *Scanner) Scan() bool

Scan advances the scanner to the next command. It returns false when the scan stops, either by reaching the end of the input or an error. After Scan returns false, the Err method will return any error that occurred during scanning, except that if it was io.EOF after an END command, Err will return nil. If the header has not been parsed yet, Scan will parse it before reading the first command.

type SendAttribute

type SendAttribute uint16
const (
	BTRFS_SEND_A_UNSPEC SendAttribute = 0

	/* Version 1 */
	BTRFS_SEND_A_UUID     SendAttribute = 1
	BTRFS_SEND_A_CTRANSID SendAttribute = 2

	BTRFS_SEND_A_INO   SendAttribute = 3
	BTRFS_SEND_A_SIZE  SendAttribute = 4
	BTRFS_SEND_A_MODE  SendAttribute = 5
	BTRFS_SEND_A_UID   SendAttribute = 6
	BTRFS_SEND_A_GID   SendAttribute = 7
	BTRFS_SEND_A_RDEV  SendAttribute = 8
	BTRFS_SEND_A_CTIME SendAttribute = 9
	BTRFS_SEND_A_MTIME SendAttribute = 10
	BTRFS_SEND_A_ATIME SendAttribute = 11
	BTRFS_SEND_A_OTIME SendAttribute = 12

	BTRFS_SEND_A_XATTR_NAME SendAttribute = 13
	BTRFS_SEND_A_XATTR_DATA SendAttribute = 14

	BTRFS_SEND_A_PATH      SendAttribute = 15
	BTRFS_SEND_A_PATH_TO   SendAttribute = 16
	BTRFS_SEND_A_PATH_LINK SendAttribute = 17

	BTRFS_SEND_A_FILE_OFFSET SendAttribute = 18
	/*
	 * As of send stream v2, this attribute is special: it must be the last
	 * attribute in a command, its header contains only the type, and its
	 * length is implicitly the remaining length of the command.
	 */
	BTRFS_SEND_A_DATA SendAttribute = 19

	BTRFS_SEND_A_CLONE_UUID     SendAttribute = 20
	BTRFS_SEND_A_CLONE_CTRANSID SendAttribute = 21
	BTRFS_SEND_A_CLONE_PATH     SendAttribute = 22
	BTRFS_SEND_A_CLONE_OFFSET   SendAttribute = 23
	BTRFS_SEND_A_CLONE_LEN      SendAttribute = 24

	BTRFS_SEND_A_MAX_V1 SendAttribute = 24

	/* Version 2 */
	BTRFS_SEND_A_FALLOCATE_MODE SendAttribute = 25

	/*
	 * File attributes from the FS_*_FL namespace (i_flags, xflags),
	 * translated to BTRFS_INODE_* bits (BTRFS_INODE_FLAG_MASK) and stored
	 * in btrfs_inode_item::flags (represented by btrfs_inode::flags and
	 * btrfs_inode::ro_flags).
	 */
	BTRFS_SEND_A_FILEATTR SendAttribute = 26

	BTRFS_SEND_A_UNENCODED_FILE_LEN SendAttribute = 27
	BTRFS_SEND_A_UNENCODED_LEN      SendAttribute = 28
	BTRFS_SEND_A_UNENCODED_OFFSET   SendAttribute = 29
	/*
	 * COMPRESSION and ENCRYPTION default to NONE (0) if omitted from
	 * BTRFS_SEND_C_ENCODED_WRITE.
	 */
	BTRFS_SEND_A_COMPRESSION SendAttribute = 30
	BTRFS_SEND_A_ENCRYPTION  SendAttribute = 31
	BTRFS_SEND_A_MAX_V2      SendAttribute = 31

	/* Version 3 */
	BTRFS_SEND_A_VERITY_ALGORITHM  SendAttribute = 32
	BTRFS_SEND_A_VERITY_BLOCK_SIZE SendAttribute = 33
	BTRFS_SEND_A_VERITY_SALT_DATA  SendAttribute = 34
	BTRFS_SEND_A_VERITY_SIG_DATA   SendAttribute = 35
	BTRFS_SEND_A_MAX_V3            SendAttribute = 35

	/* End */
	BTRFS_SEND_A_MAX SendAttribute = 35
)

func (SendAttribute) String

func (i SendAttribute) String() string

type SendCommand

type SendCommand uint16
const (
	BTRFS_SEND_C_UNSPEC SendCommand = 0

	/* Version 1 */
	BTRFS_SEND_C_SUBVOL   SendCommand = 1
	BTRFS_SEND_C_SNAPSHOT SendCommand = 2

	BTRFS_SEND_C_MKFILE  SendCommand = 3
	BTRFS_SEND_C_MKDIR   SendCommand = 4
	BTRFS_SEND_C_MKNOD   SendCommand = 5
	BTRFS_SEND_C_MKFIFO  SendCommand = 6
	BTRFS_SEND_C_MKSOCK  SendCommand = 7
	BTRFS_SEND_C_SYMLINK SendCommand = 8

	BTRFS_SEND_C_RENAME SendCommand = 9
	BTRFS_SEND_C_LINK   SendCommand = 10
	BTRFS_SEND_C_UNLINK SendCommand = 11
	BTRFS_SEND_C_RMDIR  SendCommand = 12

	BTRFS_SEND_C_SET_XATTR    SendCommand = 13
	BTRFS_SEND_C_REMOVE_XATTR SendCommand = 14

	BTRFS_SEND_C_WRITE SendCommand = 15
	BTRFS_SEND_C_CLONE SendCommand = 16

	BTRFS_SEND_C_TRUNCATE SendCommand = 17
	BTRFS_SEND_C_CHMOD    SendCommand = 18
	BTRFS_SEND_C_CHOWN    SendCommand = 19
	BTRFS_SEND_C_UTIMES   SendCommand = 20

	BTRFS_SEND_C_END           SendCommand = 21
	BTRFS_SEND_C_UPDATE_EXTENT SendCommand = 22
	BTRFS_SEND_C_MAX_V1        SendCommand = 22

	/* Version 2 */
	BTRFS_SEND_C_FALLOCATE     SendCommand = 23
	BTRFS_SEND_C_FILEATTR      SendCommand = 24
	BTRFS_SEND_C_ENCODED_WRITE SendCommand = 25
	BTRFS_SEND_C_MAX_V2        SendCommand = 25

	BTRFS_SEND_C_ENABLE_VERITY SendCommand = 26
	BTRFS_SEND_C_MAX_V3        SendCommand = 26
	/* End */
	BTRFS_SEND_C_MAX SendCommand = 26
)

func (SendCommand) String

func (i SendCommand) String() string

type StreamHeader

type StreamHeader struct {
	Magic   [13]byte
	Version uint32
}

Jump to

Keyboard shortcuts

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