index

package
v0.0.0-...-cd18553 Latest Latest
Warning

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

Go to latest
Published: May 21, 2023 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Index metadata version. Set to ISO date (decimal) whenever there are
	// incompatible changes.
	MetadataVersion           = 20190809 // V2: Put generation first (descending) in key
	MetadataVersionUpgradable = 20161109 // V1: Orignal format using Boltdb
)

Variables

View Source
var MetadataKey = metadataKey

Functions

func KF

func KF(args ...uint64) (k btrfs.Key)

KF returns a new key useful for searching an index. To enable more natural queries, the order of the arguments is different from the one in the Key struct: Type, ObjectID, Offset.

func KL

func KL(args ...uint64) btrfs.Key

func NameHash

func NameHash(name string) uint32

NameHash computes the CRC32C value of an FS object name. The initial CRC in BTRFS is ^uint32(1) and the end result is _not_ inverted.

func NewIndexKeyFromV1

func NewIndexKeyFromV1(ik keyV1) keyV2

Types

type FullRange

type FullRange struct {
	Range
}

func (*FullRange) Next

func (r *FullRange) Next() []byte

type Index

type Index struct {
	Generation uint64
	// contains filtered or unexported fields
}

Index encapsulates metadata of a BTRFS to be recovered/analyzed. It uses a memory-mapped key-value store to quickly access FS objects. When opened read/write, concurrent access to this object must be guarded.

func Open

func Open(path string, m os.FileMode, o *Options) (*Index, error)

Open opens a metadata index with the specified options.

func OpenReadOnly

func OpenReadOnly(path string) (*Index, error)

OpenReadOnly opens a metadata index for reading/querying.

func (*Index) Chunks

func (ix *Index) Chunks() (Range, btrfs.Chunk)

Chunks returns an index range containing all of the chunk items.

func (*Index) Close

func (ix *Index) Close()

Close closes the index and its underlying bbolt database.

func (*Index) Commit

func (ix *Index) Commit() error

Commit commits any pending transaction.

func (*Index) DevItems

func (ix *Index) DevItems() (Range, btrfs.DevItem)

DevItems returns an index range containing all of the device items.

func (*Index) DirItems

func (ix *Index) DirItems(owner, id uint64) (Range, btrfs.DirItem)

func (*Index) FileExtentItems

func (ix *Index) FileExtentItems(owner, id uint64) (Range,
	btrfs.FileExtentItem)

func (*Index) FindDirItemForPath

func (ix *Index) FindDirItemForPath(owner uint64, path string) btrfs.DirItem

FindDirItemForPath finds the DirItem for a given FS path. It assumes that the path is clean, as returned by path.Clean().

func (*Index) FindExtentItem

func (ix *Index) FindExtentItem(diskByteNr, diskNumBytes uint64) btrfs.ExtentItem

func (*Index) FindFileExtentItem

func (ix *Index) FindFileExtentItem(owner uint64, id uint64) btrfs.FileExtentItem

func (*Index) FindInodeItem

func (ix *Index) FindInodeItem(owner uint64, inode uint64) btrfs.InodeItem

func (*Index) FindItem

func (ix *Index) FindItem(owner uint64, k btrfs.Key) btrfs.Item

FindItem searches for an FS key at the latest generation smaller or equal to the current index generation. If the index generation is smaller than any existing generation, the data at the earliest generatation is returned.

func (*Index) FullRange

func (ix *Index) FullRange() (FullRange, []byte)

FullRange returns an index range for all items in the index regardless of generation. This is mainly useful for debugging.

func (*Index) InsertItem

func (ix *Index) InsertItem(k btrfs.Key, h btrfs.Header, item,
	data []byte) error

InsertItem inserts a filesystem item into the index, referenceable by its BTRFS key. Also stores the item's owner and generation number, as well as its inline data.

func (*Index) Metadata

func (ix *Index) Metadata() indexMetadata

func (*Index) Physical

func (ix *Index) Physical(logical uint64) (devID uint64, offset uint64)

Physical maps a filesystem logical address to a physical, on-disk address. Note: No attempt is made to deal with "holes", missing chunk entries, or logical addresses not mapping to any chunk.

func (*Index) Range

func (ix *Index) Range(owner uint64, first, last btrfs.Key) (Range, []byte)

Range returns an index range [first, last) for the given keys.

func (*Index) RangeAll

func (ix *Index) RangeAll(owner uint64, t uint8, id uint64) (Range, []byte)

RangeAll returns an index range for all items related to the key (t id ?).

func (*Index) RawTx

func (ix *Index) RawTx(fn func(db *bbolt.DB, tx *bbolt.Tx,
	bucket *bbolt.Bucket) error) error

RawTx executes a transaction function on underlying BoltDB database. This is an advanced feature that should not be called in regular operation. It is used by the upgrade-index sub-command, for example, to upgrade legacy metadata indices. This function requires that the index was opened read-write. It behaves similar to bbolt.Update() otherwise.

func (*Index) Subvolumes

func (ix *Index) Subvolumes() (Range, btrfs.RootItem)

Subvolumes returns an index range containing all of the subvolumes. Note that this excludes the FS tree root itself, which is not considered to be a subvolume. To access the FS tree root, use

Find(KF(RootItemKey, FSTreeObjectID))

func (*Index) XAttrItems

func (ix *Index) XAttrItems(owner, id uint64) (Range, btrfs.DirItem)

type KeyV1

type KeyV1 keyV1

type KeyV2

type KeyV2 keyV2

type Options

type Options struct {
	ReadOnly        bool
	BlockSize       uint
	FSID            uuid.UUID
	Generation      uint64
	AllowOldVersion bool
}

Options sets options for opening a metadata index.

type Range

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

Range encapsulates a generic index range. Internally, it holds a cursor of the underlying key-value store as well as the current position and the end of range marker.

func (*Range) Generation

func (r *Range) Generation() uint64

func (*Range) HasNext

func (r *Range) HasNext() bool

func (*Range) Index

func (r *Range) Index() *Index

Index returns the Index that this Range refers to.

func (*Range) Item

func (r *Range) Item() btrfs.Item

func (*Range) Key

func (r *Range) Key() btrfs.Key

func (*Range) Next

func (r *Range) Next() []byte

func (*Range) Owner

func (r *Range) Owner() uint64

Jump to

Keyboard shortcuts

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