file

package
v0.0.0-...-bbc9ce3 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2021 License: BSD-2-Clause Imports: 6 Imported by: 3

Documentation

Overview

Package file implements the block.Device interface backed by a traditional file.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type File

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

File represents a block device backed by a file on a traditional file system.

func New

func New(f *os.File, defaultBlockSize int64) (*File, error)

New creates and returns a new File, using f as the backing store. The size of the block device represented by the returned File will be the size of f. New will not close f if any errors occur. New will also attempt to detect the block size for f and will use defaultBlockSize if it is unable to do so. If there is an error, it will be of type *os.PathError.

func NewRange

func NewRange(f *os.File, blockSize, offset, size int64) (*File, error)

NewRange creates and returns a new File, using a subset of f as the backing store. The blockSize, offset and size must be provided.

func (*File) BlockSize

func (f *File) BlockSize() int64

BlockSize returns the size in bytes of the smallest block that can be written by the File. The return value is undefined after Close() is called.

func (*File) Close

func (f *File) Close() error

Close calls Flush() and then closes the device, rendering it unusable for I/O. It returns an error, if any.

func (*File) Discard

func (f *File) Discard(off, len int64) error

Discard marks the address range [off, off+size) as being unused, allowing it to be reclaimed by the device for other purposes. Both off and size must be multiples of Blocksize(). Returns an error, if any.

func (*File) Flush

func (f *File) Flush() error

Flush forces any writes that have been cached in memory to be committed to persistent storage. Returns an error, if any.

func (*File) ReadAt

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

ReadAt reads len(p) bytes from the device starting at offset off. Both off and len(p) must be multiples of BlockSize(). It returns the number of bytes read and the error, if any. ReadAt always returns a non-nil error when n < len(p).

func (*File) Size

func (f *File) Size() int64

Size returns the fixed size of the File in bytes. The return value is undefined after Close() is called.

func (*File) WriteAt

func (f *File) WriteAt(p []byte, off int64) (n int, err error)

WriteAt writes the contents of p to the devices starting at offset off. Both off and len(p) must be multiples of BlockSize(). It returns the number of bytes written and an error, if any. WriteAt always returns a non-nil error when n < len(p).

Jump to

Keyboard shortcuts

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