Documentation
¶
Index ¶
- Constants
- Variables
- func IsBlockZero(buf []byte) (ret bool)
- func NewSparseFile(f *os.File) *sparseFile
- type BuseDevice
- type ErrCorruptCompressedBlock
- type SparseFile
- type SparseFileWithFallback
- type SparseWriter
- type SpgzFile
- func NewFromFile(file *os.File, flag int) (f *SpgzFile, err error)
- func NewFromFileSize(file *os.File, flag int, blockSize int64) (f *SpgzFile, err error)
- func NewFromSparseFile(file SparseFile, flag int) (f *SpgzFile, err error)
- func NewFromSparseFileSize(file SparseFile, flag int, blockSize int64) (f *SpgzFile, err error)
- func OpenFile(name string, flag int, perm os.FileMode) (f *SpgzFile, err error)
- func OpenFileSize(name string, flag int, perm os.FileMode, blockSize int64) (f *SpgzFile, err error)
- func (f *SpgzFile) BlockSize() int64
- func (f *SpgzFile) Close() error
- func (f *SpgzFile) PunchHole(offset, size int64) error
- func (f *SpgzFile) Read(buf []byte) (n int, err error)
- func (f *SpgzFile) ReadAt(buf []byte, offset int64) (n int, err error)
- func (f *SpgzFile) ReadFrom(rd io.Reader) (n int64, err error)
- func (f *SpgzFile) Seek(offset int64, whence int) (int64, error)
- func (f *SpgzFile) Size() (int64, error)
- func (f *SpgzFile) Sync() error
- func (f *SpgzFile) Truncate(size int64) error
- func (f *SpgzFile) Write(buf []byte) (n int, err error)
- func (f *SpgzFile) WriteAt(buf []byte, offset int64) (n int, err error)
- func (f *SpgzFile) WriteTo(w io.Writer) (n int64, err error)
- type Truncatable
Constants ¶
const ( DefBlockSize = 128*1024 - 1 MinBlockSize = 3*4096 - 1 )
const ( FALLOC_FL_KEEP_SIZE = 0x01 /* default is extend size */ FALLOC_FL_PUNCH_HOLE = 0x02 /* de-allocates range */ )
const (
BUFSIZE = 32768
)
Variables ¶
var ( ErrInvalidFormat = errors.New("invalid file format") ErrFileIsDirectory = errors.New("file cannot be a directory") ErrWriteOnlyNotSupported = errors.New("write only mode is not supported") )
var (
ErrPunchHoleNotSupported = errors.New("this filesystem does not support punching holes. Use xfs, ext4, btrfs or such")
)
Functions ¶
func IsBlockZero ¶
func NewSparseFile ¶
Types ¶
type BuseDevice ¶
type BuseDevice struct {
*SpgzFile
}
func NewBuseDevice ¶
func NewBuseDevice(f *SpgzFile) *BuseDevice
func (*BuseDevice) Trim ¶
func (d *BuseDevice) Trim(off, length int64) error
type ErrCorruptCompressedBlock ¶
type ErrCorruptCompressedBlock struct {
// contains filtered or unexported fields
}
ErrCorruptCompressedBlock is returned when a compressed block involved in a read or a write operation is corrupt (for example as a result of a partial write). Note, this is not a media error.
Any read operation intersecting with the range specified by Offset() and Size(() will fail. Any write operation intersecting, but not fully covering the range, will also fail (therefore in order to make the file usable again one must overwrite the entire range in a single write operation).
func (*ErrCorruptCompressedBlock) Error ¶
func (e *ErrCorruptCompressedBlock) Error() string
func (*ErrCorruptCompressedBlock) Offset ¶
func (e *ErrCorruptCompressedBlock) Offset() int64
func (*ErrCorruptCompressedBlock) Size ¶
func (e *ErrCorruptCompressedBlock) Size() int64
func (*ErrCorruptCompressedBlock) Unwrap ¶
func (e *ErrCorruptCompressedBlock) Unwrap() error
type SparseFile ¶
type SparseFileWithFallback ¶
type SparseFileWithFallback struct { SparseFile // contains filtered or unexported fields }
func NewSparseFileWithFallback ¶
func NewSparseFileWithFallback(f *os.File) *SparseFileWithFallback
NewSparseFileWithFallback creates a sparse file that will fall back to writing zeros if the first call to SparseFile.PunchHole() returns ErrPunchHoleNotSupported.
func NewSparseFileWithoutHolePunching ¶
func NewSparseFileWithoutHolePunching(f *os.File) *SparseFileWithFallback
NewSparseFileWithoutHolePunching creates a sparse file that will write zeros instead of calling SparseFile.PunchHole()
func (*SparseFileWithFallback) PunchHole ¶
func (f *SparseFileWithFallback) PunchHole(offset, size int64) error
type SparseWriter ¶
type SparseWriter struct {
SparseFile
}
func NewSparseWriter ¶
func NewSparseWriter(f SparseFile) *SparseWriter
type SpgzFile ¶
func NewFromFile ¶
NewFromFile creates a new SpgzFile from the given *os.File with desired block size of DefBlockSize. See NewFromFileSize for more details.
func NewFromFileSize ¶
NewFromFileSize creates a new SpgzFile from the given *os.File. File position must be 0.
The blockSize parameter specifies the desired block size for newly created files. The actual block size will be DefBlockSize if the supplied value is 0, otherwise ((blockSize+1) &^ 0xFFF)-1 or MinBlockSize whichever is greater. For optimal I/O performance reads and writes should be sized in multiples of the actual block size and aligned at the block size boundaries. This can be achieved by using bufio.Reader and bufio.Writer. This parameter is ignored for already initialised files. The current block size can be retrieved using SpgzFile.BlockSize().
The flag parameter is similar to that of os.OpenFile(). If the file is empty it will be initialised if os.O_CREATE and os.O_RDWR are set, otherwise ErrInvalidFormat is returned. Write-only mode (os.O_WRONLY) is not supported.
Returns ErrPunchHoleNotSupported if opening for writing and the underlying OS or filesystem does not support punching holes (as space-saving will not be possible in this case).
func NewFromSparseFile ¶
func NewFromSparseFile(file SparseFile, flag int) (f *SpgzFile, err error)
func NewFromSparseFileSize ¶
func NewFromSparseFileSize(file SparseFile, flag int, blockSize int64) (f *SpgzFile, err error)
func OpenFile ¶
OpenFile opens a file as SpgzFile with block size of DefBlockSize. See OpenFileSize for more details.
func OpenFileSize ¶
func OpenFileSize(name string, flag int, perm os.FileMode, blockSize int64) (f *SpgzFile, err error)
OpenFileSize opens a file as SpgzFile. See NewFromFileSize for more details.