inode

package
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2018 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func EqualXAttrs

func EqualXAttrs(pathname1, pathname2 string) (bool, error)

func MaxNlinkVal

func MaxNlinkVal(pathname string) uint64

MaxNlinkVal returns the maximum number of supported NLinks to pathname. Since the syscall interface to Pathconf isn't supported on all unixes (such as Linux, for some reason), we instead call out to the getconf program, which should always be available as a basic command on both BSDs and Linux, to obtain the value. Since this only needs to be done once per device (ie. once per Stat_t.Dev), it isn't a performance concern.

func ReadChunk added in v1.0.2

func ReadChunk(f *os.File, buf []byte) (n int, err error)

ReadChunk will retry Read() until it fills the buf, or reaches EOF or an error.

Types

type DevStatInfo

type DevStatInfo struct {
	Dev uint64
	StatInfo
}

We need the Dev value returned from stat, but it can be discarded when we separate the Info into a map indexed by the Dev value

func LStatInfo

func LStatInfo(pathname string) (DevStatInfo, error)

type Digest

type Digest uint32

func ContentDigest

func ContentDigest(pathname string, buf []byte) (Digest, error)

ContentDigest returns a short digest of the first part of the given pathname, to help determine if two files are definitely not equivalent, without doing a full comparison. Typically this will be used when a full file comparison will be performed anyway (incurring the IO overhead), and saving the digest to help quickly reduce the set of possibly equal inodes later (ie. reducing the length of the repeated linear searches).

type FilenamePaths

type FilenamePaths struct {
	FPMap map[string]pathsplitSet // key = filename
	// contains filtered or unexported fields
}

FilenamePaths holds a map of filenames to their full pathnames (ie. the different paths to an inode), and also holds an arbitrary pathname that can be used for consistency (rather than a fully random one from the map)

func (*FilenamePaths) Add

func (f *FilenamePaths) Add(ps P.Pathsplit)

func (*FilenamePaths) Any

func (f *FilenamePaths) Any() P.Pathsplit

When choosing an arbitrary pathname, remember what was chosen and return it consistently. This prevents the source link paths from changing unnecessarily, and basically makes the output a bit more friendly.

func (*FilenamePaths) AnyWithFilename

func (f *FilenamePaths) AnyWithFilename(filename string) P.Pathsplit

AnyWithFilename will return an arbitrary path with the given filename

func (*FilenamePaths) CountPaths

func (f *FilenamePaths) CountPaths() int

CountPaths returns the number of stored paths

func (*FilenamePaths) HasFilename

func (f *FilenamePaths) HasFilename(filename string) bool

func (*FilenamePaths) HasPath

func (f *FilenamePaths) HasPath(ps P.Pathsplit) bool

func (*FilenamePaths) IsEmpty

func (f *FilenamePaths) IsEmpty() bool

func (*FilenamePaths) PathsAsSlice

func (f *FilenamePaths) PathsAsSlice() []P.Pathsplit

PathsAsSlice returns a slice of all the stored paths

func (*FilenamePaths) Remove

func (f *FilenamePaths) Remove(ps P.Pathsplit)

type Hash

type Hash uint64

func HashIno

func HashIno(si StatInfo, ignoreTime, ignorePerm, ignoreOwner bool) Hash

HashIno produces an equal hash for potentially equal files, based only on Inode metadata (size, time, etc.). Content still has to be verified for equality (but unequal hashes indicate files that definitely need not be compared)

type Ino

type Ino uint64

type InoDigests

type InoDigests struct {
	InoSets        map[Digest]Set
	InosWithDigest Set
}

func NewInoDigests

func NewInoDigests() InoDigests

func (*InoDigests) Add

func (id *InoDigests) Add(pi PathInfo, digest Digest)

func (*InoDigests) GetInos

func (id *InoDigests) GetInos(d Digest) Set

func (*InoDigests) NewDigest

func (id *InoDigests) NewDigest(pi PathInfo, buf []byte) bool

type InoHashes

type InoHashes map[Hash]Set

type InoStatInfo

type InoStatInfo map[Ino]*StatInfo

type LinkableInoSets

type LinkableInoSets map[Ino]Set

func (LinkableInoSets) Add

func (l LinkableInoSets) Add(ino1, ino2 Ino)

Add places both ino1 and ino2 into the LinkableInoSets map.

Potentially races with All(), but typically all the data is collected and added with AddLinkableInos() before calling All() (so we don't bother with locking).

func (LinkableInoSets) All

func (l LinkableInoSets) All() <-chan Set

All sends all the linkable InoSets over the returned channel. The InoSets are ordered, by starting with the lowest inode and progressing through the highest (rather than returning InoSets in random order).

This method races with the Add() method, but since it is called after all the Add()s have completed (ie. the path/inode information gathering phase has completed, and moved to the link generation phase), no locking of LinkableInoSets is required.

func (LinkableInoSets) Containing

func (l LinkableInoSets) Containing(ino Ino) Set

Containing calls linkableInoSetHelper to return a single set of linkable inodes containing the given 'ino'. Linkable inodes are those determined by the algorithm to have been able to be hardlinked together (ie. have identical contents, and compatible inode parameters)

type PathInfo

type PathInfo struct {
	P.Pathsplit
	StatInfo
}

func (PathInfo) EqualMode

func (p1 PathInfo) EqualMode(p2 PathInfo) bool

func (PathInfo) EqualOwnership

func (p1 PathInfo) EqualOwnership(p2 PathInfo) bool

func (PathInfo) EqualTime

func (p1 PathInfo) EqualTime(p2 PathInfo) bool

type PathsMap

type PathsMap map[Ino]*FilenamePaths

func (PathsMap) AllPaths

func (pm PathsMap) AllPaths(ino Ino) <-chan P.Pathsplit

AllPaths returns a channel that can be iterated over to sequentially access all the paths for a given inode.

func (PathsMap) AppendPath

func (pm PathsMap) AppendPath(ino Ino, path P.Pathsplit)

func (PathsMap) ArbitraryFilenamePath

func (pm PathsMap) ArbitraryFilenamePath(ino Ino, filename string) P.Pathsplit

func (PathsMap) ArbitraryPath

func (pm PathsMap) ArbitraryPath(ino Ino) P.Pathsplit

func (PathsMap) HasPath

func (pm PathsMap) HasPath(ino Ino, path P.Pathsplit) bool

func (PathsMap) MovePath

func (pm PathsMap) MovePath(dstPath P.Pathsplit, srcIno Ino, dstIno Ino)

MovePath moves the given destination path, from the given destination inode, to the source inode.

func (PathsMap) PathCount

func (pm PathsMap) PathCount() (paths int64, dirs int64)

PathCount returns the number of unique paths and dirs encountered after the initial walk is completed. This can give us an accurate count of the number of inode nlinks we should encounter if all linked paths are included in the walk. Conversely, if we count the nlinks from all the encountered inodes, and compare to the number of paths this function returns, we should have a count of how many inode paths were not seen by the walk.

type Set

type Set map[Ino]struct{}

func NewSet

func NewSet(inos ...Ino) Set

Return a non-nil Set with the optional inos in it

func SetIntersections

func SetIntersections(sets ...Set) Set

Return an intersection of multiple Sets

func (Set) Add

func (s Set) Add(ino Ino)

Add an Ino to the Set

func (Set) AsSlice

func (s Set) AsSlice() []Ino

Return the content of Set as a slice

func (Set) Copy

func (s Set) Copy() Set

Return a duplicate of the Set

func (Set) Difference

func (s Set) Difference(other Set) Set

Return a difference of the other Set from the receiver

func (Set) Has

func (s Set) Has(ino Ino) bool

Return true if given Ino is in the Set

func (Set) HasAll

func (s Set) HasAll(inos ...Ino) bool

Return true if all given Inos are in the Set (false if empty)

func (Set) Intersection

func (s Set) Intersection(other Set) Set

Return an intersection of the receiver with a Set

func (Set) Overlaps

func (s Set) Overlaps(other Set) bool

Overlaps returns true if there is any overlap in the two sets

func (Set) Remove

func (s Set) Remove(ino Ino)

Remove an Ino to the Set

type StatInfo

type StatInfo struct {
	Size  uint64
	Ino   Ino
	Nlink uint64
	Uid   uint32
	Gid   uint32
	Mode  os.FileMode
	Mtim  time.Time
}

os.FileInfo and syscall.Stat_t fields that we care about

Jump to

Keyboard shortcuts

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