Documentation ¶
Index ¶
- Constants
- Variables
- func Fgetxattr(fd uintptr, name string) ([]byte, error)
- func Fsetxattr(fd uintptr, name string, value []byte) error
- func Rename(oldpath, newpath string) error
- type ChecksumFile
- func (f *ChecksumFile) Close() (err error)
- func (f *ChecksumFile) Getxattr(name string) ([]byte, error)
- func (f *ChecksumFile) Read(b []byte) (n int, err error)
- func (f *ChecksumFile) ReadAt(b []byte, off int64) (n int, err error)
- func (f *ChecksumFile) Scrub() (int64, error)
- func (f *ChecksumFile) Seek(offset int64, whence int) (int64, error)
- func (f *ChecksumFile) Setxattr(name string, value []byte) error
- func (f *ChecksumFile) Size() (bytes int64, err error)
- func (f *ChecksumFile) Write(b []byte) (n int, err error)
- func (f *ChecksumFile) WriteAt(b []byte, off int64) (int, error)
- type XattrError
Constants ¶
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 )
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 ¶
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.
var ErrInvalidFlag = errors.New("invalid flag")
ErrInvalidFlag is returned if a ChecksumFile is opened with a bad flag.
var ErrInvalidOffset = errors.New("invalid offset")
ErrInvalidOffset is for a bad offset to Seek.
Functions ¶
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.