fs

package
v0.17.1 Latest Latest
Warning

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

Go to latest
Published: Sep 5, 2024 License: BSD-2-Clause Imports: 17 Imported by: 0

Documentation

Overview

Package fs implements an OS independent abstraction of a file system suitable for backup purposes.

Index

Constants

View Source
const (
	O_RDONLY   int = syscall.O_RDONLY   // open the file read-only.
	O_WRONLY   int = syscall.O_WRONLY   // open the file write-only.
	O_RDWR     int = syscall.O_RDWR     // open the file read-write.
	O_APPEND   int = syscall.O_APPEND   // append data to the file when writing.
	O_CREATE   int = syscall.O_CREAT    // create a new file if none exists.
	O_EXCL     int = syscall.O_EXCL     // used with O_CREATE, file must not exist
	O_SYNC     int = syscall.O_SYNC     // open for synchronous I/O.
	O_TRUNC    int = syscall.O_TRUNC    // if possible, truncate file when opened.
	O_NONBLOCK int = syscall.O_NONBLOCK // don't block open on fifos etc.
)

Flags to OpenFile wrapping those of the underlying system. Not all flags may be implemented on a given system.

View Source
const (

	//revive:disable-next-line:var-naming ALL_CAPS
	SE_PRIVILEGE_ENABLED = windows.SE_PRIVILEGE_ENABLED

	//revive:disable-next-line:var-naming ALL_CAPS
	ERROR_NOT_ALL_ASSIGNED windows.Errno = windows.ERROR_NOT_ALL_ASSIGNED
)

Do the interface allocations only once for common Errno values.

View Source
const (
	VSS_S_ASYNC_PENDING   = 0x00042309
	VSS_S_ASYNC_FINISHED  = 0x0004230A
	VSS_S_ASYNC_CANCELLED = 0x0004230B
)

Constants for IVSSAsync api.

View Source
const O_NOFOLLOW int = 0

O_NOFOLLOW is a noop on Windows.

View Source
const (
	// STATUS_NO_EAS_ON_FILE is a constant value which indicates EAs were requested for the file but it has no EAs.
	// Windows NTSTATUS value: STATUS_NO_EAS_ON_FILE=0xC0000052
	STATUS_NO_EAS_ON_FILE = -1073741742
)

Variables

View Source
var (

	// SeBackupPrivilege allows the application to bypass file and directory ACLs to back up files and directories.
	SeBackupPrivilege = "SeBackupPrivilege"
	// SeRestorePrivilege allows the application to bypass file and directory ACLs to restore files and directories.
	SeRestorePrivilege = "SeRestorePrivilege"
	// SeSecurityPrivilege allows read and write access to all SACLs.
	SeSecurityPrivilege = "SeSecurityPrivilege"
	// SeTakeOwnershipPrivilege allows the application to take ownership of files and directories, regardless of the permissions set on them.
	SeTakeOwnershipPrivilege = "SeTakeOwnershipPrivilege"
)
View Source
var (
	TestFileSDs = []string{"AQAUvBQAAAAwAAAAAAAAAEwAAAABBQAAAAAABRUAAACIn1iuVqCC6sy9JqvqAwAAAQUAAAAAAAUVAAAAiJ9YrlaggurMvSarAQIAAAIAfAAEAAAAAAAkAKkAEgABBQAAAAAABRUAAACIn1iuVqCC6sy9JqvtAwAAABAUAP8BHwABAQAAAAAABRIAAAAAEBgA/wEfAAECAAAAAAAFIAAAACACAAAAECQA/wEfAAEFAAAAAAAFFQAAAIifWK5WoILqzL0mq+oDAAA=",
		"AQAUvBQAAAAwAAAAAAAAAEwAAAABBQAAAAAABRUAAACIn1iuVqCC6sy9JqvqAwAAAQUAAAAAAAUVAAAAiJ9YrlaggurMvSarAQIAAAIAyAAHAAAAAAAUAKkAEgABAQAAAAAABQcAAAAAABQAiQASAAEBAAAAAAAFBwAAAAAAJACpABIAAQUAAAAAAAUVAAAAiJ9YrlaggurMvSar7QMAAAAAJAC/ARMAAQUAAAAAAAUVAAAAiJ9YrlaggurMvSar6gMAAAAAFAD/AR8AAQEAAAAAAAUSAAAAAAAYAP8BHwABAgAAAAAABSAAAAAgAgAAAAAkAP8BHwABBQAAAAAABRUAAACIn1iuVqCC6sy9JqvqAwAA",
		"AQAUvBQAAAAwAAAA7AAAAEwAAAABBQAAAAAABRUAAAAvr7t03PyHGk2FokNHCAAAAQUAAAAAAAUVAAAAiJ9YrlaggurMvSarAQIAAAIAoAAFAAAAAAAkAP8BHwABBQAAAAAABRUAAAAvr7t03PyHGk2FokNHCAAAAAAkAKkAEgABBQAAAAAABRUAAACIn1iuVqCC6sy9JqvtAwAAABAUAP8BHwABAQAAAAAABRIAAAAAEBgA/wEfAAECAAAAAAAFIAAAACACAAAAECQA/wEfAAEFAAAAAAAFFQAAAIifWK5WoILqzL0mq+oDAAACAHQAAwAAAAKAJAC/AQIAAQUAAAAAAAUVAAAAL6+7dNz8hxpNhaJDtgQAAALAJAC/AQMAAQUAAAAAAAUVAAAAL6+7dNz8hxpNhaJDPgkAAAJAJAD/AQ8AAQUAAAAAAAUVAAAAL6+7dNz8hxpNhaJDtQQAAA==",
	}
	TestDirSDs = []string{"AQAUvBQAAAAwAAAAAAAAAEwAAAABBQAAAAAABRUAAACIn1iuVqCC6sy9JqvqAwAAAQUAAAAAAAUVAAAAiJ9YrlaggurMvSarAQIAAAIAfAAEAAAAAAAkAKkAEgABBQAAAAAABRUAAACIn1iuVqCC6sy9JqvtAwAAABMUAP8BHwABAQAAAAAABRIAAAAAExgA/wEfAAECAAAAAAAFIAAAACACAAAAEyQA/wEfAAEFAAAAAAAFFQAAAIifWK5WoILqzL0mq+oDAAA=",
		"AQAUvBQAAAAwAAAAAAAAAEwAAAABBQAAAAAABRUAAACIn1iuVqCC6sy9JqvqAwAAAQUAAAAAAAUVAAAAiJ9YrlaggurMvSarAQIAAAIA3AAIAAAAAAIUAKkAEgABAQAAAAAABQcAAAAAAxQAiQASAAEBAAAAAAAFBwAAAAAAJACpABIAAQUAAAAAAAUVAAAAiJ9YrlaggurMvSar7QMAAAAAJAC/ARMAAQUAAAAAAAUVAAAAiJ9YrlaggurMvSar6gMAAAALFAC/ARMAAQEAAAAAAAMAAAAAABMUAP8BHwABAQAAAAAABRIAAAAAExgA/wEfAAECAAAAAAAFIAAAACACAAAAEyQA/wEfAAEFAAAAAAAFFQAAAIifWK5WoILqzL0mq+oDAAA=",
		"AQAUvBQAAAAwAAAA7AAAAEwAAAABBQAAAAAABRUAAAAvr7t03PyHGk2FokNHCAAAAQUAAAAAAAUVAAAAiJ9YrlaggurMvSarAQIAAAIAoAAFAAAAAAAkAP8BHwABBQAAAAAABRUAAAAvr7t03PyHGk2FokNHCAAAAAAkAKkAEgABBQAAAAAABRUAAACIn1iuVqCC6sy9JqvtAwAAABMUAP8BHwABAQAAAAAABRIAAAAAExgA/wEfAAECAAAAAAAFIAAAACACAAAAEyQA/wEfAAEFAAAAAAAFFQAAAIifWK5WoILqzL0mq+oDAAACAHQAAwAAAAKAJAC/AQIAAQUAAAAAAAUVAAAAL6+7dNz8hxpNhaJDtgQAAALAJAC/AQMAAQUAAAAAAAUVAAAAL6+7dNz8hxpNhaJDPgkAAAJAJAD/AQ8AAQUAAAAAAAUVAAAAL6+7dNz8hxpNhaJDtQQAAA==",
	}
)
View Source
var (
	UIID_IVSS_ADMIN       = ole.NewGUID("{77ED5996-2F63-11d3-8A39-00C04F72D8E3}")
	CLSID_VSS_COORDINATOR = ole.NewGUID("{E579AB5F-1CC4-44b4-BED9-DE0991FF0623}")
)

UIID_IVSS_ADMIN defines the GUID of IVSSAdmin.

View Source
var ErrFileEmpty = errors.New("no data read")

ErrFileEmpty is returned inside a *os.PathError by Read() for the file opened from the fs provided by Reader when no data could be read and AllowEmptyFile is not set.

View Source
var UIID_IVSS_ASYNC = ole.NewGUID("{507C37B4-CF5B-4e95-B0AF-14EB9767467E}")

UIID_IVSS_ASYNC defines to GUID of IVSSAsync.

View Source
var UUID_IVSS = ole.NewGUID("{665c1d5f-c218-414d-a05d-7fef5f9d5c86}")

UUID_IVSS defines the GUID of IVssBackupComponents.

Functions

func Chmod

func Chmod(name string, mode os.FileMode) error

Chmod changes the mode of the named file to mode.

func Chtimes

func Chtimes(name string, atime time.Time, mtime time.Time) error

Chtimes changes the access and modification times of the named file, similar to the Unix utime() or utimes() functions.

The underlying filesystem may truncate or round the values to a less precise time unit. If there is an error, it will be of type *PathError.

func ClearAttribute added in v0.17.0

func ClearAttribute(path string, attribute uint32) error

ClearAttribute removes the specified attribute from the file.

func ClearSystem added in v0.17.0

func ClearSystem(path string) error

ClearSystem removes the system attribute from the file.

func CompareSecurityDescriptors added in v0.17.0

func CompareSecurityDescriptors(t *testing.T, testPath string, sdInputBytes, sdOutputBytes []byte)

CompareSecurityDescriptors runs tests for comparing 2 security descriptors in []byte format.

func Create

func Create(name string) (*os.File, error)

Create creates the named file with mode 0666 (before umask), truncating it if it already exists. If successful, methods on the returned File can be used for I/O; the associated file descriptor has mode O_RDWR. If there is an error, it will be of type *PathError.

func DeviceID

func DeviceID(fi os.FileInfo) (deviceID uint64, err error)

DeviceID extracts the device ID from an os.FileInfo object by casting it to syscall.Stat_t

func EncodeExtendedAttributes added in v0.17.0

func EncodeExtendedAttributes(eas []ExtendedAttribute) ([]byte, error)

EncodeExtendedAttributes encodes a list of EAs into a FILE_FULL_EA_INFORMATION buffer for use with BackupWrite, ZwSetEaFile, etc.

func GetSecurityDescriptor added in v0.17.0

func GetSecurityDescriptor(filePath string) (securityDescriptor *[]byte, err error)

GetSecurityDescriptor takes the path of the file and returns the SecurityDescriptor for the file. This needs admin permissions or SeBackupPrivilege for getting the full SD. If there are no admin permissions, only the current user's owner, group and DACL will be got.

func GetVolumeNameForVolumeMountPoint added in v0.17.0

func GetVolumeNameForVolumeMountPoint(mountPoint string) (string, error)

GetVolumeNameForVolumeMountPoint add trailing backslash to input parameter and calls the equivalent windows api.

func GetVolumePathName added in v0.17.1

func GetVolumePathName(path string) (volumeName string, err error)

GetVolumePathName returns the volume path name for the given path.

func HasPathPrefix

func HasPathPrefix(base, p string) bool

HasPathPrefix returns true if p is a subdir of (or a file within) base. It assumes a file system which is case sensitive. If the paths are not of the same type (one is relative, the other is absolute), false is returned.

func HasSufficientPrivilegesForVSS

func HasSufficientPrivilegesForVSS() error

HasSufficientPrivilegesForVSS returns nil if the user is allowed to use VSS.

func IsAccessDenied added in v0.17.0

func IsAccessDenied(err error) bool

IsAccessDenied checks if the error is due to permission error.

func IsAdmin added in v0.17.0

func IsAdmin() (isAdmin bool, err error)

IsAdmin checks if current user is an administrator.

func IsRegularFile

func IsRegularFile(fi os.FileInfo) bool

IsRegularFile returns true if fi belongs to a normal file. If fi is nil, false is returned.

func Link(oldname, newname string) error

Link creates newname as a hard link to oldname. If there is an error, it will be of type *LinkError.

func Lstat

func Lstat(name string) (os.FileInfo, error)

Lstat returns the FileInfo structure describing the named file. If the file is a symbolic link, the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link. If there is an error, it will be of type *PathError.

func Mkdir

func Mkdir(name string, perm os.FileMode) error

Mkdir creates a new directory with the specified name and permission bits. If there is an error, it will be of type *PathError.

func MkdirAll

func MkdirAll(path string, perm os.FileMode) error

MkdirAll creates a directory named path, along with any necessary parents, and returns nil, or else returns an error. The permission bits perm are used for all directories that MkdirAll creates. If path is already a directory, MkdirAll does nothing and returns nil.

func OpenFile

func OpenFile(name string, flag int, perm os.FileMode) (*os.File, error)

OpenFile is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful, methods on the returned File can be used for I/O. If there is an error, it will be of type *PathError.

func OpenHandleForEA added in v0.17.0

func OpenHandleForEA(nodeType, path string, writeAccess bool) (handle windows.Handle, err error)

OpenHandleForEA return a file handle for file or dir for setting/getting EAs

func PathSupportsExtendedAttributes added in v0.17.1

func PathSupportsExtendedAttributes(path string) (supported bool, err error)

PathSupportsExtendedAttributes returns true if the path supports extended attributes.

func PreallocateFile

func PreallocateFile(wr *os.File, size int64) error

func Readdirnames added in v0.17.0

func Readdirnames(filesystem FS, dir string, flags int) ([]string, error)

Readdirnames returns a list of file in a directory. Flags are passed to fs.OpenFile. O_RDONLY is implied.

func Readlink(name string) (string, error)

Readlink returns the destination of the named symbolic link. If there is an error, it will be of type *PathError.

func Remove

func Remove(name string) error

Remove removes the named file or directory. If there is an error, it will be of type *PathError.

func RemoveAll

func RemoveAll(path string) error

RemoveAll removes path and any children it contains. It removes everything it can but returns the first error it encounters. If the path does not exist, RemoveAll returns nil (no error).

func RemoveIfExists

func RemoveIfExists(filename string) error

RemoveIfExists removes a file, returning no error if it does not exist.

func Rename

func Rename(oldpath, newpath string) error

Rename renames (moves) oldpath to newpath. If newpath already exists, Rename replaces it. OS-specific restrictions may apply when oldpath and newpath are in different directories. If there is an error, it will be of type *LinkError.

func ResetPermissions added in v0.17.0

func ResetPermissions(path string) error

ResetPermissions resets the permissions of the file at the specified path

func SecurityDescriptorBytesToStruct added in v0.17.0

func SecurityDescriptorBytesToStruct(sd []byte) (*windows.SECURITY_DESCRIPTOR, error)

SecurityDescriptorBytesToStruct converts the security descriptor bytes representation into a pointer to windows SECURITY_DESCRIPTOR.

func SetFileEA added in v0.17.0

func SetFileEA(handle windows.Handle, attrs []ExtendedAttribute) error

SetFileEA sets the extended attributes for the file represented by `handle`. The handle must have been opened with the file access flag FILE_WRITE_EA(0x10).

func SetSecurityDescriptor added in v0.17.0

func SetSecurityDescriptor(filePath string, securityDescriptor *[]byte) error

SetSecurityDescriptor sets the SecurityDescriptor for the file at the specified path. This needs admin permissions or SeRestorePrivilege, SeSecurityPrivilege and SeTakeOwnershipPrivilege for setting the full SD. If there are no admin permissions/required privileges, only the DACL from the SD can be set and owner and group will be set based on the current user.

func Stat

func Stat(name string) (os.FileInfo, error)

Stat returns a FileInfo structure describing the named file. If there is an error, it will be of type *PathError.

func Symlink(oldname, newname string) error

Symlink creates newname as a symbolic link to oldname. If there is an error, it will be of type *LinkError.

func TempFile

func TempFile(dir, prefix string) (f *os.File, err error)

TempFile creates a temporary file which is marked as delete-on-close

func Walk

func Walk(root string, walkFn filepath.WalkFunc) error

Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walk can be inefficient. Walk does not follow symbolic links.

Types

type CommandReader added in v0.17.0

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

CommandReader wrap a command such that its standard output can be read using a io.ReadCloser. Close() waits for the command to terminate, reporting any error back to the caller.

func NewCommandReader added in v0.17.0

func NewCommandReader(ctx context.Context, args []string, logOutput io.Writer) (*CommandReader, error)

func (*CommandReader) Close added in v0.17.0

func (fp *CommandReader) Close() error

func (*CommandReader) Read added in v0.17.0

func (fp *CommandReader) Read(p []byte) (int, error)

Read populate the array with data from the process stdout.

type ErrorHandler

type ErrorHandler func(item string, err error)

ErrorHandler is used to report errors via callback.

type ExtendedAttribute added in v0.17.0

type ExtendedAttribute struct {
	Name  string
	Value []byte
	Flags uint8
}

ExtendedAttribute represents a single Windows EA.

func DecodeExtendedAttributes added in v0.17.0

func DecodeExtendedAttributes(b []byte) (eas []ExtendedAttribute, err error)

DecodeExtendedAttributes decodes a list of EAs from a FILE_FULL_EA_INFORMATION buffer retrieved from BackupRead, ZwQueryEaFile, etc.

func GetFileEA added in v0.17.0

func GetFileEA(handle windows.Handle) ([]ExtendedAttribute, error)

GetFileEA retrieves the extended attributes for the file represented by `handle`. The `handle` must have been opened with file access flag FILE_READ_EA (0x8). The extended file attribute names in windows are case-insensitive and when fetching the attributes the names are generally returned in UPPER case.

type ExtendedFileInfo

type ExtendedFileInfo struct {
	os.FileInfo

	DeviceID  uint64 // ID of device containing the file
	Inode     uint64 // Inode number
	Links     uint64 // Number of hard links
	UID       uint32 // owner user ID
	GID       uint32 // owner group ID
	Device    uint64 // Device ID (if this is a device file)
	BlockSize int64  // block size for filesystem IO
	Blocks    int64  // number of allocated filesystem blocks
	Size      int64  // file size in byte

	AccessTime time.Time // last access time stamp
	ModTime    time.Time // last (content) modification time stamp
	ChangeTime time.Time // last status change time stamp
}

ExtendedFileInfo is an extended stat_t, filled with attributes that are supported by most operating systems. The original FileInfo is embedded.

func ExtendedStat

func ExtendedStat(fi os.FileInfo) ExtendedFileInfo

ExtendedStat returns an ExtendedFileInfo constructed from the os.FileInfo.

type FS

type FS interface {
	Open(name string) (File, error)
	OpenFile(name string, flag int, perm os.FileMode) (File, error)
	Stat(name string) (os.FileInfo, error)
	Lstat(name string) (os.FileInfo, error)

	Join(elem ...string) string
	Separator() string
	Abs(path string) (string, error)
	Clean(path string) string
	VolumeName(path string) string
	IsAbs(path string) bool

	Dir(path string) string
	Base(path string) string
}

FS bundles all methods needed for a file system.

type File

type File interface {
	io.Reader
	io.Closer

	Fd() uintptr
	Readdirnames(n int) ([]string, error)
	Readdir(int) ([]os.FileInfo, error)
	Seek(int64, int) (int64, error)
	Stat() (os.FileInfo, error)
	Name() string
}

File is an open file on a file system.

func Open

func Open(name string) (File, error)

Open opens a file for reading.

type HRESULT

type HRESULT uint

HRESULT is a custom type for the windows api HRESULT type.

const (
	S_OK                                            HRESULT = 0x00000000
	S_FALSE                                         HRESULT = 0x00000001
	E_ACCESSDENIED                                  HRESULT = 0x80070005
	E_OUTOFMEMORY                                   HRESULT = 0x8007000E
	E_INVALIDARG                                    HRESULT = 0x80070057
	VSS_E_BAD_STATE                                 HRESULT = 0x80042301
	VSS_E_UNEXPECTED                                HRESULT = 0x80042302
	VSS_E_PROVIDER_ALREADY_REGISTERED               HRESULT = 0x80042303
	VSS_E_PROVIDER_NOT_REGISTERED                   HRESULT = 0x80042304
	VSS_E_PROVIDER_VETO                             HRESULT = 0x80042306
	VSS_E_PROVIDER_IN_USE                           HRESULT = 0x80042307
	VSS_E_OBJECT_NOT_FOUND                          HRESULT = 0x80042308
	VSS_E_VOLUME_NOT_SUPPORTED                      HRESULT = 0x8004230C
	VSS_E_VOLUME_NOT_SUPPORTED_BY_PROVIDER          HRESULT = 0x8004230E
	VSS_E_OBJECT_ALREADY_EXISTS                     HRESULT = 0x8004230D
	VSS_E_UNEXPECTED_PROVIDER_ERROR                 HRESULT = 0x8004230F
	VSS_E_CORRUPT_XML_DOCUMENT                      HRESULT = 0x80042310
	VSS_E_INVALID_XML_DOCUMENT                      HRESULT = 0x80042311
	VSS_E_MAXIMUM_NUMBER_OF_VOLUMES_REACHED         HRESULT = 0x80042312
	VSS_E_FLUSH_WRITES_TIMEOUT                      HRESULT = 0x80042313
	VSS_E_HOLD_WRITES_TIMEOUT                       HRESULT = 0x80042314
	VSS_E_UNEXPECTED_WRITER_ERROR                   HRESULT = 0x80042315
	VSS_E_SNAPSHOT_SET_IN_PROGRESS                  HRESULT = 0x80042316
	VSS_E_MAXIMUM_NUMBER_OF_SNAPSHOTS_REACHED       HRESULT = 0x80042317
	VSS_E_WRITER_INFRASTRUCTURE                     HRESULT = 0x80042318
	VSS_E_WRITER_NOT_RESPONDING                     HRESULT = 0x80042319
	VSS_E_WRITER_ALREADY_SUBSCRIBED                 HRESULT = 0x8004231A
	VSS_E_UNSUPPORTED_CONTEXT                       HRESULT = 0x8004231B
	VSS_E_VOLUME_IN_USE                             HRESULT = 0x8004231D
	VSS_E_MAXIMUM_DIFFAREA_ASSOCIATIONS_REACHED     HRESULT = 0x8004231E
	VSS_E_INSUFFICIENT_STORAGE                      HRESULT = 0x8004231F
	VSS_E_NO_SNAPSHOTS_IMPORTED                     HRESULT = 0x80042320
	VSS_E_SOME_SNAPSHOTS_NOT_IMPORTED               HRESULT = 0x80042321
	VSS_E_MAXIMUM_NUMBER_OF_REMOTE_MACHINES_REACHED HRESULT = 0x80042322
	VSS_E_REMOTE_SERVER_UNAVAILABLE                 HRESULT = 0x80042323
	VSS_E_REMOTE_SERVER_UNSUPPORTED                 HRESULT = 0x80042324
	VSS_E_REVERT_IN_PROGRESS                        HRESULT = 0x80042325
	VSS_E_REVERT_VOLUME_LOST                        HRESULT = 0x80042326
	VSS_E_REBOOT_REQUIRED                           HRESULT = 0x80042327
	VSS_E_TRANSACTION_FREEZE_TIMEOUT                HRESULT = 0x80042328
	VSS_E_TRANSACTION_THAW_TIMEOUT                  HRESULT = 0x80042329
	VSS_E_VOLUME_NOT_LOCAL                          HRESULT = 0x8004232D
	VSS_E_CLUSTER_TIMEOUT                           HRESULT = 0x8004232E
	VSS_E_WRITERERROR_INCONSISTENTSNAPSHOT          HRESULT = 0x800423F0
	VSS_E_WRITERERROR_OUTOFRESOURCES                HRESULT = 0x800423F1
	VSS_E_WRITERERROR_TIMEOUT                       HRESULT = 0x800423F2
	VSS_E_WRITERERROR_RETRYABLE                     HRESULT = 0x800423F3
	VSS_E_WRITERERROR_NONRETRYABLE                  HRESULT = 0x800423F4
	VSS_E_WRITERERROR_RECOVERY_FAILED               HRESULT = 0x800423F5
	VSS_E_BREAK_REVERT_ID_FAILED                    HRESULT = 0x800423F6
	VSS_E_LEGACY_PROVIDER                           HRESULT = 0x800423F7
	VSS_E_MISSING_DISK                              HRESULT = 0x800423F8
	VSS_E_MISSING_HIDDEN_VOLUME                     HRESULT = 0x800423F9
	VSS_E_MISSING_VOLUME                            HRESULT = 0x800423FA
	VSS_E_AUTORECOVERY_FAILED                       HRESULT = 0x800423FB
	VSS_E_DYNAMIC_DISK_ERROR                        HRESULT = 0x800423FC
	VSS_E_NONTRANSPORTABLE_BCD                      HRESULT = 0x800423FD
	VSS_E_CANNOT_REVERT_DISKID                      HRESULT = 0x800423FE
	VSS_E_RESYNC_IN_PROGRESS                        HRESULT = 0x800423FF
	VSS_E_CLUSTER_ERROR                             HRESULT = 0x80042400
	VSS_E_UNSELECTED_VOLUME                         HRESULT = 0x8004232A
	VSS_E_SNAPSHOT_NOT_IN_SET                       HRESULT = 0x8004232B
	VSS_E_NESTED_VOLUME_LIMIT                       HRESULT = 0x8004232C
	VSS_E_NOT_SUPPORTED                             HRESULT = 0x8004232F
	VSS_E_WRITERERROR_PARTIAL_FAILURE               HRESULT = 0x80042336
	VSS_E_WRITER_STATUS_NOT_AVAILABLE               HRESULT = 0x80042409
)

HRESULT constant values necessary for using VSS api.

func (HRESULT) Str

func (h HRESULT) Str() string

Str converts a HRESULT to a human readable string.

type IVSSAdmin added in v0.17.0

type IVSSAdmin struct {
	ole.IUnknown
}

IVSSAdmin VSS api interface.

func (*IVSSAdmin) QueryProviders added in v0.17.0

func (vssAdmin *IVSSAdmin) QueryProviders() (*IVssEnumObject, error)

QueryProviders calls the equivalent VSS api.

type IVSSAdminVTable added in v0.17.0

type IVSSAdminVTable struct {
	ole.IUnknownVtbl
	// contains filtered or unexported fields
}

IVSSAdminVTable is the vtable for IVSSAdmin. nolint:structcheck

type IVSSAsync

type IVSSAsync struct {
	ole.IUnknown
}

IVSSAsync VSS api interface.

func (*IVSSAsync) Cancel

func (vssAsync *IVSSAsync) Cancel() HRESULT

Cancel calls the equivalent VSS api.

func (*IVSSAsync) QueryStatus

func (vssAsync *IVSSAsync) QueryStatus() (HRESULT, uint32)

QueryStatus calls the equivalent VSS api.

func (*IVSSAsync) Wait

func (vssAsync *IVSSAsync) Wait(millis uint32) HRESULT

Wait calls the equivalent VSS api.

func (*IVSSAsync) WaitUntilAsyncFinished

func (vssAsync *IVSSAsync) WaitUntilAsyncFinished(timeout time.Duration) error

WaitUntilAsyncFinished waits until either the async call is finished or the given timeout is reached.

type IVSSAsyncVTable

type IVSSAsyncVTable struct {
	ole.IUnknownVtbl
	// contains filtered or unexported fields
}

IVSSAsyncVTable is the vtable for IVSSAsync.

type IVssBackupComponents

type IVssBackupComponents struct {
	ole.IUnknown
}

IVssBackupComponents VSS api interface.

func (*IVssBackupComponents) AbortBackup

func (vss *IVssBackupComponents) AbortBackup() error

AbortBackup calls the equivalent VSS api.

func (*IVssBackupComponents) AddToSnapshotSet

func (vss *IVssBackupComponents) AddToSnapshotSet(volumeName string, providerID *ole.GUID, idSnapshot *ole.GUID) error

AddToSnapshotSet calls the equivalent VSS api.

func (*IVssBackupComponents) BackupComplete

func (vss *IVssBackupComponents) BackupComplete() (*IVSSAsync, error)

BackupComplete calls the equivalent VSS api.

func (*IVssBackupComponents) DeleteSnapshots

func (vss *IVssBackupComponents) DeleteSnapshots(snapshotID ole.GUID) (int32, ole.GUID, error)

DeleteSnapshots calls the equivalent VSS api.

func (*IVssBackupComponents) DoSnapshotSet

func (vss *IVssBackupComponents) DoSnapshotSet() (*IVSSAsync, error)

DoSnapshotSet calls the equivalent VSS api.

func (*IVssBackupComponents) GatherWriterMetadata

func (vss *IVssBackupComponents) GatherWriterMetadata() (*IVSSAsync, error)

GatherWriterMetadata calls the equivalent VSS api.

func (*IVssBackupComponents) GetSnapshotProperties

func (vss *IVssBackupComponents) GetSnapshotProperties(snapshotID ole.GUID,
	properties *VssSnapshotProperties) error

GetSnapshotProperties calls the equivalent VSS api.

func (*IVssBackupComponents) InitializeForBackup

func (vss *IVssBackupComponents) InitializeForBackup() error

InitializeForBackup calls the equivalent VSS api.

func (*IVssBackupComponents) IsVolumeSupported

func (vss *IVssBackupComponents) IsVolumeSupported(providerID *ole.GUID, volumeName string) (bool, error)

IsVolumeSupported calls the equivalent VSS api.

func (*IVssBackupComponents) PrepareForBackup

func (vss *IVssBackupComponents) PrepareForBackup() (*IVSSAsync, error)

PrepareForBackup calls the equivalent VSS api.

func (*IVssBackupComponents) SetBackupState

func (vss *IVssBackupComponents) SetBackupState(selectComponents bool,
	backupBootableSystemState bool, backupType VssBackup, partialFileSupport bool,
) error

SetBackupState calls the equivalent VSS api.

func (*IVssBackupComponents) SetContext

func (vss *IVssBackupComponents) SetContext(context VssContext) error

SetContext calls the equivalent VSS api.

func (*IVssBackupComponents) StartSnapshotSet

func (vss *IVssBackupComponents) StartSnapshotSet() (ole.GUID, error)

StartSnapshotSet calls the equivalent VSS api.

type IVssBackupComponentsVTable

type IVssBackupComponentsVTable struct {
	ole.IUnknownVtbl
	// contains filtered or unexported fields
}

IVssBackupComponentsVTable is the vtable for IVssBackupComponents. nolint:structcheck

type IVssEnumObject added in v0.17.0

type IVssEnumObject struct {
	ole.IUnknown
}

IVssEnumObject VSS api interface.

func (*IVssEnumObject) Next added in v0.17.0

func (vssEnum *IVssEnumObject) Next(count uint, props unsafe.Pointer) (uint, error)

Next calls the equivalent VSS api.

type IVssEnumObjectVTable added in v0.17.0

type IVssEnumObjectVTable struct {
	ole.IUnknownVtbl
	// contains filtered or unexported fields
}

IVssEnumObjectVTable is the vtable for IVssEnumObject. nolint:structcheck

type Local

type Local struct{}

Local is the local file system. Most methods are just passed on to the stdlib.

func (Local) Abs

func (fs Local) Abs(path string) (string, error)

Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.

func (Local) Base

func (fs Local) Base(path string) string

Base returns the last element of path.

func (Local) Clean

func (fs Local) Clean(p string) string

Clean returns the cleaned path. For details, see filepath.Clean.

func (Local) Dir

func (fs Local) Dir(path string) string

Dir returns path without the last element.

func (Local) IsAbs

func (fs Local) IsAbs(path string) bool

IsAbs reports whether the path is absolute.

func (Local) Join

func (fs Local) Join(elem ...string) string

Join joins any number of path elements into a single path, adding a Separator if necessary. Join calls Clean on the result; in particular, all empty strings are ignored. On Windows, the result is a UNC path if and only if the first path element is a UNC path.

func (Local) Lstat

func (fs Local) Lstat(name string) (os.FileInfo, error)

Lstat returns the FileInfo structure describing the named file. If the file is a symbolic link, the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link. If there is an error, it will be of type *PathError.

func (Local) Open

func (fs Local) Open(name string) (File, error)

Open opens a file for reading.

func (Local) OpenFile

func (fs Local) OpenFile(name string, flag int, perm os.FileMode) (File, error)

OpenFile is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful, methods on the returned File can be used for I/O. If there is an error, it will be of type *PathError.

func (Local) Separator

func (fs Local) Separator() string

Separator returns the OS and FS dependent separator for dirs/subdirs/files.

func (Local) Stat

func (fs Local) Stat(name string) (os.FileInfo, error)

Stat returns a FileInfo describing the named file. If there is an error, it will be of type *PathError.

func (Local) VolumeName

func (fs Local) VolumeName(path string) string

VolumeName returns leading volume name. Given "C:\foo\bar" it returns "C:" on Windows. Given "\\host\share\foo" it returns "\\host\share". On other platforms it returns "".

type LocalVss

type LocalVss struct {
	FS
	// contains filtered or unexported fields
}

LocalVss is a wrapper around the local file system which uses windows volume shadow copy service (VSS) in a transparent way.

func NewLocalVss

func NewLocalVss(msgError ErrorHandler, msgMessage MessageHandler, cfg VSSConfig) *LocalVss

NewLocalVss creates a new wrapper around the windows filesystem using volume shadow copy service to access locked files.

func (*LocalVss) DeleteSnapshots

func (fs *LocalVss) DeleteSnapshots()

DeleteSnapshots deletes all snapshots that were created automatically.

func (*LocalVss) Lstat

func (fs *LocalVss) Lstat(name string) (os.FileInfo, error)

Lstat wraps the Open method of the underlying file system.

func (*LocalVss) Open

func (fs *LocalVss) Open(name string) (File, error)

Open wraps the Open method of the underlying file system.

func (*LocalVss) OpenFile

func (fs *LocalVss) OpenFile(name string, flag int, perm os.FileMode) (File, error)

OpenFile wraps the Open method of the underlying file system.

func (*LocalVss) Stat

func (fs *LocalVss) Stat(name string) (os.FileInfo, error)

Stat wraps the Open method of the underlying file system.

type MessageHandler

type MessageHandler func(msg string, args ...interface{})

MessageHandler is used to report errors/messages via callbacks.

type MountPoint

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

MountPoint wraps all information of a snapshot of a mountpoint on a volume.

func (*MountPoint) GetSnapshotDeviceObject

func (p *MountPoint) GetSnapshotDeviceObject() string

GetSnapshotDeviceObject returns root path to access the snapshot files and folders.

func (*MountPoint) IsSnapshotted

func (p *MountPoint) IsSnapshotted() bool

IsSnapshotted is true if this mount point was snapshotted successfully.

type PrivilegeError added in v0.17.0

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

PrivilegeError represents an error enabling privileges.

func (*PrivilegeError) Error added in v0.17.0

func (e *PrivilegeError) Error() string

Error returns the string message for the error.

type Reader

type Reader struct {
	Name string
	io.ReadCloser

	// for FileInfo
	Mode    os.FileMode
	ModTime time.Time
	Size    int64

	AllowEmptyFile bool
	// contains filtered or unexported fields
}

Reader is a file system which provides a directory with a single file. When this file is opened for reading, the reader is passed through. The file can be opened once, all subsequent open calls return syscall.EIO. For Lstat(), the provided FileInfo is returned.

func (*Reader) Abs

func (fs *Reader) Abs(p string) (string, error)

Abs returns an absolute representation of path. If the path is not absolute it will be joined with the current working directory to turn it into an absolute path. The absolute path name for a given file is not guaranteed to be unique. Abs calls Clean on the result.

For the Reader, all paths are absolute.

func (*Reader) Base

func (fs *Reader) Base(p string) string

Base returns the last element of p.

func (*Reader) Clean

func (fs *Reader) Clean(p string) string

Clean returns the cleaned path. For details, see filepath.Clean.

func (*Reader) Dir

func (fs *Reader) Dir(p string) string

Dir returns p without the last element.

func (*Reader) IsAbs

func (fs *Reader) IsAbs(_ string) bool

IsAbs reports whether the path is absolute. For the Reader, this is always the case.

func (*Reader) Join

func (fs *Reader) Join(elem ...string) string

Join joins any number of path elements into a single path, adding a Separator if necessary. Join calls Clean on the result; in particular, all empty strings are ignored. On Windows, the result is a UNC path if and only if the first path element is a UNC path.

func (*Reader) Lstat

func (fs *Reader) Lstat(name string) (os.FileInfo, error)

Lstat returns the FileInfo structure describing the named file. If the file is a symbolic link, the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link. If there is an error, it will be of type *os.PathError.

func (*Reader) Open

func (fs *Reader) Open(name string) (f File, err error)

Open opens a file for reading.

func (*Reader) OpenFile

func (fs *Reader) OpenFile(name string, flag int, _ os.FileMode) (f File, err error)

OpenFile is the generalized open call; most users will use Open or Create instead. It opens the named file with specified flag (O_RDONLY etc.) and perm, (0666 etc.) if applicable. If successful, methods on the returned File can be used for I/O. If there is an error, it will be of type *os.PathError.

func (*Reader) Separator

func (fs *Reader) Separator() string

Separator returns the OS and FS dependent separator for dirs/subdirs/files.

func (*Reader) Stat

func (fs *Reader) Stat(name string) (os.FileInfo, error)

Stat returns a FileInfo describing the named file. If there is an error, it will be of type *os.PathError.

func (*Reader) VolumeName

func (fs *Reader) VolumeName(_ string) string

VolumeName returns leading volume name, for the Reader file system it's always the empty string.

type Track

type Track struct {
	FS
}

Track is a wrapper around another file system which installs finalizers for open files which call panic() when they are not closed when the garbage collector releases them. This can be used to find resource leaks via open files.

func (Track) Open

func (fs Track) Open(name string) (File, error)

Open wraps the Open method of the underlying file system.

func (Track) OpenFile

func (fs Track) OpenFile(name string, flag int, perm os.FileMode) (File, error)

OpenFile wraps the OpenFile method of the underlying file system.

type VSSConfig added in v0.17.0

type VSSConfig struct {
	ExcludeAllMountPoints bool          `option:"exclude-all-mount-points" help:"exclude mountpoints from snapshotting on all volumes"`
	ExcludeVolumes        string        `` /* 136-byte string literal not displayed */
	Timeout               time.Duration `option:"timeout" help:"time that the VSS can spend creating snapshot before timing out"`
	Provider              string        `option:"provider" help:"VSS provider identifier which will be used for snapshotting"`
}

VSSConfig holds extended options of windows volume shadow copy service.

func NewVSSConfig added in v0.17.0

func NewVSSConfig() VSSConfig

NewVSSConfig returns a new VSSConfig with the default values filled in.

func ParseVSSConfig added in v0.17.0

func ParseVSSConfig(o options.Options) (VSSConfig, error)

ParseVSSConfig parses a VSS extended options to VSSConfig struct.

type VolumeFilter added in v0.17.0

type VolumeFilter func(volume string) bool

VolumeFilter is used to filter volumes by it's mount point or GUID path.

type VssBackup

type VssBackup uint

VssBackup is a custom type for the windows api VssBackup type.

const (
	VSS_BT_UNDEFINED VssBackup = iota
	VSS_BT_FULL
	VSS_BT_INCREMENTAL
	VSS_BT_DIFFERENTIAL
	VSS_BT_LOG
	VSS_BT_COPY
	VSS_BT_OTHER
)

VssBackup constant values necessary for using VSS api.

type VssContext

type VssContext uint

VssContext is a custom type for the windows api VssContext type.

const (
	VSS_CTX_BACKUP VssContext = iota
	VSS_CTX_FILE_SHARE_BACKUP
	VSS_CTX_NAS_ROLLBACK
	VSS_CTX_APP_ROLLBACK
	VSS_CTX_CLIENT_ACCESSIBLE
	VSS_CTX_CLIENT_ACCESSIBLE_WRITERS
	VSS_CTX_ALL
)

VssContext constant values necessary for using VSS api.

type VssObjectType

type VssObjectType uint

VssObjectType is a custom type for the windows api VssObjectType type.

const (
	VSS_OBJECT_UNKNOWN VssObjectType = iota
	VSS_OBJECT_NONE
	VSS_OBJECT_SNAPSHOT_SET
	VSS_OBJECT_SNAPSHOT
	VSS_OBJECT_PROVIDER
	VSS_OBJECT_TYPE_COUNT
)

VssObjectType constant values necessary for using VSS api.

type VssProviderProperties added in v0.17.0

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

VssProviderProperties defines the properties of a VSS provider as part of the VSS api. nolint:structcheck

type VssSnapshot

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

VssSnapshot wraps windows volume shadow copy api (vss) via a simple interface to create and delete a vss snapshot.

func NewVssSnapshot

func NewVssSnapshot(provider string,
	volume string, timeout time.Duration, filter VolumeFilter, msgError ErrorHandler) (VssSnapshot, error)

NewVssSnapshot creates a new vss snapshot. If creating the snapshots doesn't finish within the timeout an error is returned.

func (*VssSnapshot) Delete

func (p *VssSnapshot) Delete() error

Delete deletes the created snapshot.

func (*VssSnapshot) GetSnapshotDeviceObject

func (p *VssSnapshot) GetSnapshotDeviceObject() string

GetSnapshotDeviceObject returns root path to access the snapshot files and folders.

type VssSnapshotProperties

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

VssSnapshotProperties defines the properties of a VSS snapshot as part of the VSS api. nolint:structcheck

func (*VssSnapshotProperties) GetSnapshotDeviceObject

func (p *VssSnapshotProperties) GetSnapshotDeviceObject() string

GetSnapshotDeviceObject returns root path to access the snapshot files and folders.

Jump to

Keyboard shortcuts

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