pxar

package
v0.0.0-...-fa20487 Latest Latest
Warning

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

Go to latest
Published: Aug 23, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package pxar implements the PXAR archive format: record framing constants, encoders for every entry type (v1 and the v2 split-archive additions), and the goodbye-table construction (siphash naming hash plus the casync implicit binary search tree layout).

The package is used for byte encoding and size calculation only, no filesystem access and no I/O. Every encoder has a matching size function used by the archive planner, so planned and emitted sizes can't diverge.

Index

Constants

View Source
const (
	ACLRead    uint64 = 4
	ACLWrite   uint64 = 2
	ACLExecute uint64 = 1
	// ACLNoMask marks an absent mask in ACLDefault.
	ACLNoMask uint64 = ^uint64(0)
)

ACL permission bits (per entry, rwx as in POSIX ACLs).

View Source
const (
	ACLUserSize     = HeaderSize + 16
	ACLGroupSize    = HeaderSize + 16
	ACLGroupObjSize = HeaderSize + 8
	ACLDefaultSize  = HeaderSize + 32
)

Encoded sizes of the fixed-layout ACL records.

View Source
const (
	// TypeEntry is the stat record: mode, flags, uid, gid, mtime.
	TypeEntry uint64 = 0xd5956474e588acef
	// TypeEntryV1 is the obsolete stat record layout of early pxar versions.
	// Decode-only concern; never emitted.
	TypeEntryV1 uint64 = 0x11da850a1c1cceff
	// TypeFilename precedes each directory child: name bytes + NUL.
	TypeFilename uint64 = 0x16701121063917b3
	// TypeSymlink carries the link target: target bytes + NUL.
	TypeSymlink uint64 = 0x27f971e7dbf5dc5f
	// TypeDevice carries major/minor numbers for block and char devices.
	TypeDevice uint64 = 0x9fc9e906586d5ce9
	// TypeXAttr carries one extended attribute: name + NUL + value.
	TypeXAttr uint64 = 0x0dab0229b57dcd03
	// ACL record types; bodies are defined in encode.go.
	TypeACLUser         uint64 = 0x2ce8540a457d55b8
	TypeACLGroup        uint64 = 0x136e3eceb04c03ab
	TypeACLGroupObj     uint64 = 0x10868031e9582876
	TypeACLDefault      uint64 = 0xbbbb13415a6896f5
	TypeACLDefaultUser  uint64 = 0xc89357b40532cd1f
	TypeACLDefaultGroup uint64 = 0xf90a8a5816038ffe
	// TypeFCaps carries the raw security.capability xattr value.
	TypeFCaps uint64 = 0x2da9dd9db5f7fb67
	// TypeQuotaProjID carries the filesystem quota project id.
	TypeQuotaProjID uint64 = 0xe07540e82f7d1cbb
	// TypeHardlink references an earlier entry: offset (u64) + path + NUL.
	TypeHardlink uint64 = 0x51269c8422bd7275
	// TypePayload frames regular file content.
	TypePayload uint64 = 0x28147a1b0b7c1a25
	// TypeGoodbye terminates a directory: a BST of per-child items.
	TypeGoodbye uint64 = 0x2fec4fa642d5731d
	// GoodbyeTailMarker is the hash value of the final goodbye item.
	GoodbyeTailMarker uint64 = 0xef5eed5b753e1555

	// v2 (split archive) additions.
	TypeFormatVersion  uint64 = 0x730f6c75df16a40d
	TypePrelude        uint64 = 0xe309d79d9f7b771b
	TypePayloadRef     uint64 = 0x419d3d6bc4ba977e
	PayloadStartMarker uint64 = 0x834c68c2194a4ed2
	PayloadTailMarker  uint64 = 0x6c72b78b984c81b5
)

Record type identifiers. Every item in a pxar stream is framed as a 16-byte header — type (u64 LE) followed by length (u64 LE, including the header) — and a body. Values match proxmox/pxar src/format/mod.rs.

View Source
const DeviceSize = HeaderSize + 16

DeviceSize is the full encoded size of a Device record.

View Source
const EntrySize = HeaderSize + 40

EntrySize is the full encoded size of an Entry record.

View Source
const FormatVersionSize = HeaderSize + 8

FormatVersionSize is the full encoded size of a TypeFormatVersion record.

View Source
const HeaderSize = 16

HeaderSize is the size of the type+length framing of every record.

View Source
const MarkerSize = HeaderSize

MarkerSize is the encoded size of the bare-header payload stream markers.

View Source
const PayloadRefSize = HeaderSize + 16

PayloadRefSize is the full encoded size of a TypePayloadRef record.

View Source
const QuotaProjIDSize = HeaderSize + 8

QuotaProjIDSize is the full encoded size of a TypeQuotaProjID record.

Variables

This section is empty.

Functions

func AppendACLDefault

func AppendACLDefault(dst []byte, a ACLDefault) []byte

AppendACLDefault encodes the default-ACL object permissions (TypeACLDefault).

func AppendACLDefaultGroup

func AppendACLDefaultGroup(dst []byte, a ACLGroup) []byte

AppendACLDefaultGroup encodes a default named-group ACL entry (TypeACLDefaultGroup).

func AppendACLDefaultUser

func AppendACLDefaultUser(dst []byte, a ACLUser) []byte

AppendACLDefaultUser encodes a default named-user ACL entry (TypeACLDefaultUser).

func AppendACLGroup

func AppendACLGroup(dst []byte, a ACLGroup) []byte

AppendACLGroup encodes a named-group ACL entry (TypeACLGroup).

func AppendACLGroupObj

func AppendACLGroupObj(dst []byte, permissions uint64) []byte

AppendACLGroupObj encodes the owning-group permissions (TypeACLGroupObj), present when a mask entry makes the stat group bits carry the mask instead.

func AppendACLUser

func AppendACLUser(dst []byte, a ACLUser) []byte

AppendACLUser encodes a named-user ACL entry (TypeACLUser).

func AppendDevice

func AppendDevice(dst []byte, d Device) []byte

AppendDevice encodes d as a TypeDevice record.

func AppendEntry

func AppendEntry(dst []byte, e Entry) []byte

AppendEntry encodes e as a TypeEntry record.

func AppendFCaps

func AppendFCaps(dst []byte, data []byte) []byte

AppendFCaps encodes the raw security.capability xattr value.

func AppendFilename

func AppendFilename(dst []byte, name string) []byte

AppendFilename encodes a directory child's name (NUL-terminated).

func AppendFormatVersion

func AppendFormatVersion(dst []byte, version uint64) []byte

AppendFormatVersion encodes the format version record that opens a v2 metadata stream (version 1 is expressed by the record's absence).

func AppendGoodbye

func AppendGoodbye(dst []byte, items []GoodbyeItem, dirEntryStart, goodbyeStart uint64) []byte

AppendGoodbye encodes a directory's goodbye table. dirEntryStart is the absolute offset of the directory's own TypeEntry record (i.e. after its filename record; for the root directory, the archive start), goodbyeStart the absolute offset where this goodbye record begins. Items may be in any order; they are sorted by hash and permuted into the BST layout. Item offsets are encoded as distances backwards from goodbyeStart.

func AppendHardlink(dst []byte, offset uint64, target string) []byte

AppendHardlink encodes a hardlink record: offset is the distance in bytes from the start of this hardlink's own TypeFilename record back to the start of the link target's TypeFilename record (the upstream encoder's current_position - target_position); target is the archive-relative path of the target (NUL-terminated).

func AppendPayloadHeader

func AppendPayloadHeader(dst []byte, size uint64) []byte

AppendPayloadHeader encodes the header of a TypePayload record. The size bytes of raw file content follow the header in the stream; they are written by the emitter, not by this package.

func AppendPayloadRef

func AppendPayloadRef(dst []byte, offset, size uint64) []byte

AppendPayloadRef encodes a v2 payload reference: offset addresses the payload record's *header* in the payload stream, size is the content byte count (the referenced record's length minus its header).

func AppendPayloadStartMarker

func AppendPayloadStartMarker(dst []byte) []byte

AppendPayloadStartMarker encodes the record that opens a payload stream.

func AppendPayloadTailMarker

func AppendPayloadTailMarker(dst []byte) []byte

AppendPayloadTailMarker encodes the record that closes a payload stream.

func AppendQuotaProjID

func AppendQuotaProjID(dst []byte, projid uint64) []byte

AppendQuotaProjID encodes a filesystem quota project id.

func AppendSymlink(dst []byte, target string) []byte

AppendSymlink encodes a symlink target (NUL-terminated).

func AppendXAttr

func AppendXAttr(dst []byte, name string, value []byte) []byte

AppendXAttr encodes one extended attribute: name + NUL + value.

func Hash

func Hash(name string) uint64

Hash returns the goodbye-table hash of a directory child's basename.

func SizeFCaps

func SizeFCaps(data []byte) uint64

SizeFCaps returns the encoded size of a TypeFCaps record.

func SizeFilename

func SizeFilename(name string) uint64

SizeFilename returns the encoded size of a TypeFilename record.

func SizeGoodbye

func SizeGoodbye(n int) uint64

SizeGoodbye returns the full encoded size of a goodbye record for a directory with n children (n items plus the tail marker).

func SizeHardlink(target string) uint64

SizeHardlink returns the encoded size of a TypeHardlink record.

func SizePayload

func SizePayload(size uint64) uint64

SizePayload returns the full encoded size of a payload record whose content is size bytes: the header plus the raw content that follows it.

func SizeSymlink(target string) uint64

SizeSymlink returns the encoded size of a TypeSymlink record.

func SizeXAttr

func SizeXAttr(name string, value []byte) uint64

SizeXAttr returns the encoded size of a TypeXAttr record.

func ValidateFilename

func ValidateFilename(name string) error

ValidateFilename reports whether name is usable as a pxar directory child name: non-empty, no '/', no NUL, and not "." or "..".

Types

type ACLDefault

type ACLDefault struct {
	UserObjPermissions  uint64
	GroupObjPermissions uint64
	OtherPermissions    uint64
	MaskPermissions     uint64 // ACLNoMask when no mask entry exists
}

ACLDefault is the body of a TypeACLDefault record.

type ACLGroup

type ACLGroup struct {
	GID         uint64
	Permissions uint64
}

ACLGroup is the body of TypeACLGroup and TypeACLDefaultGroup records.

type ACLUser

type ACLUser struct {
	UID         uint64
	Permissions uint64
}

ACLUser is the body of TypeACLUser and TypeACLDefaultUser records.

type Device

type Device struct {
	Major uint64
	Minor uint64
}

Device is the body of a TypeDevice record.

type Entry

type Entry struct {
	Mode       uint64 // full st_mode: type bits + permission bits
	Flags      uint64
	UID        uint32
	GID        uint32
	MtimeSecs  int64  // seconds since epoch (may be negative)
	MtimeNanos uint32 // nanoseconds within MtimeSecs
}

Entry is the stat record body (TypeEntry).

type GoodbyeItem

type GoodbyeItem struct {
	Hash   uint64 // Hash(basename)
	Start  uint64
	Length uint64
}

GoodbyeItem describes one directory child for goodbye-table construction. Start and Length are in stream coordinates: Start is the absolute offset of the child's TypeFilename record, Length the child's total encoded length (filename record through goodbye table or payload, inclusive).

Jump to

Keyboard shortcuts

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