disk

package
v0.0.0-...-fd5963e Latest Latest
Warning

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

Go to latest
Published: Mar 13, 2019 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// If this flag is present, ChecksumFile will attempt to use fadvise to drop
	// file data from the buffer cache.
	O_DROPCACHE int = 0x10000000

	// ExtraRoom is how much room a caller can leave in the capacity of a slice
	// to read, to help us avoid copying data.
	ExtraRoom = blockLength
)
View Source
const (
	// Parameters to be used by fadvise.
	POSIX_FADV_RANDOM   = C.POSIX_FADV_RANDOM
	POSIX_FADV_DONTNEED = C.POSIX_FADV_DONTNEED

	// Error returned if the attribute was not found.
	ENOATTR = syscall.ENODATA

	// Disable all atime updates.
	O_NOATIME = syscall.O_NOATIME
)

Constants for syscalls.

Variables

View Source
var ErrCorruptData = errors.New("file is corrupt")

ErrCorruptData is returned when a block's checksum is bad, or something else happens that corrupts a ChecksumFile.

View Source
var ErrInvalidFlag = errors.New("invalid flag")

ErrInvalidFlag is returned if a ChecksumFile is opened with a bad flag.

View Source
var ErrInvalidOffset = errors.New("invalid offset")

ErrInvalidOffset is for a bad offset to Seek.

Functions

func Fgetxattr

func Fgetxattr(fd uintptr, name string) ([]byte, error)

Fgetxattr gets an extended attribute value.

func Fsetxattr

func Fsetxattr(fd uintptr, name string, value []byte) error

Fsetxattr sets an extended attribute value.

func Rename

func Rename(oldpath, newpath string) error

Rename relies on os.Remove to rename (move) a file and syncs the home directory of the newpath upon success.

Types

type ChecksumFile

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

A ChecksumFile supports a limited file interface but detects corruption of data.

func NewChecksumFile

func NewChecksumFile(path string, flags int) (*ChecksumFile, error)

NewChecksumFile opens (or creates) a new ChecksumFile at path 'path' and flags 'flags'. flags can be an OR-ing of: os.O_RDONLY -- file is opened only for reading os.O_RDWR -- file is opened for reading and writing. os.O_CREATE -- file should be created (but if existing file exists, returns error, an implicit or w/os.O_EXCL) os.O_EXCL -- if creating a file, return an error if it exists already. os.O_TRUNC -- truncate size to 0 O_DROPCACHE -- use fadvise to prevent file data from lingering in the buffer cache

The file is created with a default mode of 0600.

WARNING: ChecksumFile is not thread safe!

func (*ChecksumFile) Close

func (f *ChecksumFile) Close() (err error)

Close the open ChecksumFile.

func (*ChecksumFile) Getxattr

func (f *ChecksumFile) Getxattr(name string) ([]byte, error)

Getxattr gets an extended attribute value.

func (*ChecksumFile) Read

func (f *ChecksumFile) Read(b []byte) (n int, err error)

Read reads len(b) bytes from the file's current position Returns number of bytes written and any error encountered. The position for the next Read or Write is updated on success.

func (*ChecksumFile) ReadAt

func (f *ChecksumFile) ReadAt(b []byte, off int64) (n int, err error)

ReadAt reads len(b) bytes from 'off', verifying that the data is not corrupted. Returns an error if the underlying file returned an error, or data is corrupted. ReadAt will try to read data directly into b to minimize copying. You can help it by leaving a little extra space (ExtraRoom) in the capacity of b.

func (*ChecksumFile) Scrub

func (f *ChecksumFile) Scrub() (int64, error)

Scrub verifies that the file isn't corrupt.

func (*ChecksumFile) Seek

func (f *ChecksumFile) Seek(offset int64, whence int) (int64, error)

Seek implements io.Seeker.

func (*ChecksumFile) Setxattr

func (f *ChecksumFile) Setxattr(name string, value []byte) error

Setxattr sets an extended attribute value.

func (*ChecksumFile) Size

func (f *ChecksumFile) Size() (bytes int64, err error)

Size returns the number of bytes of data that the user has written to the ChecksumFile. Note that this will be smaller than the on-disk size as it does not account for checksum or header overhead.

func (*ChecksumFile) Write

func (f *ChecksumFile) Write(b []byte) (n int, err error)

Write reads len(b) bytes from 'f.pos' via WriteAt. Returns number of bytes written and any error encountered. The position for the next Read or Write is updated on success.

func (*ChecksumFile) WriteAt

func (f *ChecksumFile) WriteAt(b []byte, off int64) (int, error)

WriteAt writes 'b' at offset 'off'. Holes in files are padded with 0s explicitly. Failed mutations to existing data will cause file corruption. Writing to previously unallocated space will cause a short write.

type XattrError

type XattrError struct {
	Op   string  // What is the operation?
	Fd   uintptr // What is the file descriptor?
	Name string  // What is the name of the attribute?
	Err  error   // What is the error?
}

XattrError records an error and the operation, file path and attribute name that caused it.

func (*XattrError) Error

func (x *XattrError) Error() string

Error implements error.

Jump to

Keyboard shortcuts

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