package fs

import "github.com/containerd/continuity/fs"

Index

Constants

const (
	// ChangeKindUnmodified represents an unmodified
	// file
	ChangeKindUnmodified = iota

	// ChangeKindAdd represents an addition of
	// a file
	ChangeKindAdd

	// ChangeKindModify represents a change to
	// an existing file
	ChangeKindModify

	// ChangeKindDelete represents a delete of
	// a file
	ChangeKindDelete
)
const (
	// MagicAufs filesystem id for Aufs
	MagicAufs = Magic(0x61756673)
	// MagicBtrfs filesystem id for Btrfs
	MagicBtrfs = Magic(0x9123683E)
	// MagicCramfs filesystem id for Cramfs
	MagicCramfs = Magic(0x28cd3d45)
	// MagicEcryptfs filesystem id for eCryptfs
	MagicEcryptfs = Magic(0xf15f)
	// MagicExtfs filesystem id for Extfs
	MagicExtfs = Magic(0x0000EF53)
	// MagicF2fs filesystem id for F2fs
	MagicF2fs = Magic(0xF2F52010)
	// MagicGPFS filesystem id for GPFS
	MagicGPFS = Magic(0x47504653)
	// MagicJffs2Fs filesystem if for Jffs2Fs
	MagicJffs2Fs = Magic(0x000072b6)
	// MagicJfs filesystem id for Jfs
	MagicJfs = Magic(0x3153464a)
	// MagicNfsFs filesystem id for NfsFs
	MagicNfsFs = Magic(0x00006969)
	// MagicRAMFs filesystem id for RamFs
	MagicRAMFs = Magic(0x858458f6)
	// MagicReiserFs filesystem id for ReiserFs
	MagicReiserFs = Magic(0x52654973)
	// MagicSmbFs filesystem id for SmbFs
	MagicSmbFs = Magic(0x0000517B)
	// MagicSquashFs filesystem id for SquashFs
	MagicSquashFs = Magic(0x73717368)
	// MagicTmpFs filesystem id for TmpFs
	MagicTmpFs = Magic(0x01021994)
	// MagicVxFS filesystem id for VxFs
	MagicVxFS = Magic(0xa501fcf5)
	// MagicXfs filesystem id for Xfs
	MagicXfs = Magic(0x58465342)
	// MagicZfs filesystem id for Zfs
	MagicZfs = Magic(0x2fc12fc1)
	// MagicOverlay filesystem id for overlay
	MagicOverlay = Magic(0x794C7630)
)
const (
	// MagicUnsupported is a predefined constant value other than a valid filesystem id.
	MagicUnsupported = Magic(0x00000000)
)

Variables

var (
	// FsNames maps filesystem id to name of the filesystem.
	FsNames = map[Magic]string{
		MagicAufs:        "aufs",
		MagicBtrfs:       "btrfs",
		MagicCramfs:      "cramfs",
		MagicExtfs:       "extfs",
		MagicF2fs:        "f2fs",
		MagicGPFS:        "gpfs",
		MagicJffs2Fs:     "jffs2",
		MagicJfs:         "jfs",
		MagicNfsFs:       "nfs",
		MagicOverlay:     "overlayfs",
		MagicRAMFs:       "ramfs",
		MagicReiserFs:    "reiserfs",
		MagicSmbFs:       "smb",
		MagicSquashFs:    "squashfs",
		MagicTmpFs:       "tmpfs",
		MagicUnsupported: "unsupported",
		MagicVxFS:        "vxfs",
		MagicXfs:         "xfs",
		MagicZfs:         "zfs",
	}
)

Functions

func Atime

func Atime(st fs.FileInfo) (time.Time, error)

func Changes

func Changes(ctx context.Context, a, b string, changeFn ChangeFunc) error

Changes computes changes between two directories calling the given change function for each computed change. The first directory is intended to the base directory and second directory the changed directory.

The change callback is called by the order of path names and should be appliable in that order.

Due to this apply ordering, the following is true
- Removed directory trees only create a single change for the root
  directory removed. Remaining changes are implied.
- A directory which is modified to become a file will not have
  delete entries for sub-path items, their removal is implied
  by the removal of the parent directory.

Opaque directories will not be treated specially and each file removed from the base directory will show up as a removal.

File content comparisons will be done on files which have timestamps which may have been truncated. If either of the files being compared has a zero value nanosecond value, each byte will be compared for differences. If 2 files have the same seconds value but different nanosecond values where one of those values is zero, the files will be considered unchanged if the content is the same. This behavior is to account for timestamp truncation during archiving.

func CopyDir

func CopyDir(dst, src string, opts ...CopyDirOpt) error

CopyDir copies the directory from src to dst. Most efficient copy of files is attempted.

func CopyFile

func CopyFile(target, source string) error

CopyFile copies the source file to the target. The most efficient means of copying is used for the platform.

func Ctime

func Ctime(st fs.FileInfo) (time.Time, error)

func DiffDirChanges

func DiffDirChanges(ctx context.Context, baseDir, diffDir string, source DiffSource, changeFn ChangeFunc) error

DiffDirChanges walks the diff directory and compares changes against the base.

NOTE: If all the children of a dir are removed, or that dir are recreated after remove, we will mark non-existing `.wh..opq` file as deleted. It's unlikely to create explicit whiteout files for all the children and all descendants. And based on OCI spec, it's not possible to create a file or dir with a name beginning with `.wh.`. So, after `.wh..opq` file has been deleted, the ChangeFunc, the receiver will add whiteout prefix to create a opaque whiteout `.wh..wh..opq`.

REF: https://github.com/opencontainers/image-spec/blob/v1.0/layer.md#whiteouts

func GetLinkInfo

func GetLinkInfo(fi os.FileInfo) (uint64, bool)

GetLinkInfo returns an identifier representing the node a hardlink is pointing to. If the file is not hard linked then 0 will be returned.

func Mtime

func Mtime(st fs.FileInfo) (time.Time, error)

func RootPath

func RootPath(root, path string) (string, error)

RootPath joins a path with a root, evaluating and bounding any symlink to the root directory.

func StatATimeAsTime

func StatATimeAsTime(st *syscall.Stat_t) time.Time

StatATimeAsTime returns st.Atim as a time.Time

func StatAtime

func StatAtime(st *syscall.Stat_t) syscall.Timespec

StatAtime returns the Atim

func StatCtime

func StatCtime(st *syscall.Stat_t) syscall.Timespec

StatCtime returns the Ctim

func StatMtime

func StatMtime(st *syscall.Stat_t) syscall.Timespec

StatMtime returns the Mtim

func SupportsDType

func SupportsDType(path string) (bool, error)

SupportsDType returns whether the filesystem mounted on path supports d_type

Types

type Change

type Change struct {
	Kind ChangeKind
	Path string
}

Change represents single change between a diff and its parent.

type ChangeFunc

type ChangeFunc func(ChangeKind, string, os.FileInfo, error) error

ChangeFunc is the type of function called for each change computed during a directory changes calculation.

type ChangeKind

type ChangeKind int

ChangeKind is the type of modification that a change is making.

func (ChangeKind) String

func (k ChangeKind) String() string

type CopyDirOpt

type CopyDirOpt func(*copyDirOpts) error

func WithAllowXAttrErrors

func WithAllowXAttrErrors() CopyDirOpt

WithAllowXAttrErrors allows ignoring xattr errors.

func WithXAttrErrorHandler

func WithXAttrErrorHandler(xeh XAttrErrorHandler) CopyDirOpt

WithXAttrErrorHandler allows specifying XAttrErrorHandler If nil XAttrErrorHandler is specified (default), CopyDir stops on a non-nil xattr error.

func WithXAttrExclude

func WithXAttrExclude(keys ...string) CopyDirOpt

WithXAttrExclude allows for exclusion of specified xattr during CopyDir operation.

type DiffSource

type DiffSource int

DiffChangeSource is the source of diff directory.

const (
	// DiffSourceOverlayFS indicates that a diff directory is from
	// OverlayFS.
	DiffSourceOverlayFS DiffSource = iota
)

type Magic

type Magic uint32

Magic unsigned id of the filesystem in use.

func GetMagic

func GetMagic(rootpath string) (Magic, error)

GetMagic returns the filesystem id given the path.

type Usage

type Usage struct {
	Inodes int64
	Size   int64
}

Usage of disk information

func DiffUsage

func DiffUsage(ctx context.Context, a, b string) (Usage, error)

DiffUsage counts the numbers of inodes and disk usage in the diff between the 2 directories. The first path is intended as the base directory and the second as the changed directory.

func DiskUsage

func DiskUsage(ctx context.Context, roots ...string) (Usage, error)

DiskUsage counts the number of inodes and disk usage for the resources under path.

type XAttrErrorHandler

type XAttrErrorHandler func(dst, src, xattrKey string, err error) error

XAttrErrorHandler transform a non-nil xattr error. Return nil to ignore an error. xattrKey can be empty for listxattr operation.

Source Files

copy.go copy_irregular_unix.go copy_linux.go copy_nondarwin.go diff.go diff_linux.go diff_unix.go dir.go dtype_linux.go du.go du_unix.go hardlink.go hardlink_unix.go magic_linux.go path.go stat_unix.go time.go

Directories

PathSynopsis
fs/fstest
Version
v0.4.5 (latest)
Published
Oct 30, 2024
Platform
linux/amd64
Imports
17 packages
Last checked
8 minutes ago

Tools for package owners.