fs2: github.com/timtadh/fs2/fmap Index | Files

package fmap

import "github.com/timtadh/fs2/fmap"

File memory MAP

The fmap package implements a nice way to memory map a file for block oriented operations. It's interface is block oriented and allows you to allocate and free blocks inside of the file. To support resizing the underlying file outstanding pointers are tracked and are expected to be released. This is done through run time checking.

Index

Package Files

doc.go fmap.go

Constants

const BLOCKSIZE = 4096

Variables

var CREATEFLAG = os.O_RDWR | os.O_CREATE | syscall.O_NOATIME | os.O_TRUNC

The flag used when creating the file

var OPENFLAG = os.O_RDWR | os.O_CREATE | syscall.O_NOATIME

The flag used when opening the file

func MemClr Uses

func MemClr(bytes []byte)

Zero the bytes of the passed in slice. It uses the length not the capacity of the slice. It uses the libc function memset under the hood to do this. Go has an implementation of this function in assembly in the runtime package but I could not find a nice way to expose it. So here is the libc version exposed (via several method calls and the cgo interface).

type BlockFile Uses

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

A BlockFile represents the memory mapped file. It has a blocksize all operations are done as block aligned operations.

func Anonymous Uses

func Anonymous(blksize uint32) (*BlockFile, error)

Create an anonymous blockfile. There is no backing file. The blocksize must be divisible by 4096 as usual

func CreateBlockFile Uses

func CreateBlockFile(path string) (*BlockFile, error)

Create a blockfile with the standard block size (4096 which is normally the OS page size).

func CreateBlockFileCustomBlockSize Uses

func CreateBlockFileCustomBlockSize(path string, blksize uint32) (*BlockFile, error)

Create a blockfile with a custom blocksize. Note, the size must be a multiple of 4096.

func OpenBlockFile Uses

func OpenBlockFile(path string) (*BlockFile, error)

Open a previously created BlockFile. This will fail if you didn't use the creation functions to create the file (or at least have undefined effects).

func (*BlockFile) Address Uses

func (self *BlockFile) Address() uintptr

What is the address of the file in the address space of the program. Use this at your own risk!

func (*BlockFile) Allocate Uses

func (self *BlockFile) Allocate() (offset uint64, err error)

Allocate 1 block and return its offset.

func (*BlockFile) AllocateBlocks Uses

func (self *BlockFile) AllocateBlocks(n int) (offset uint64, err error)

Allocate n blocks. Return the offset of the first block. These are guarranteed to be sequential. This always causes a file resize at the moment.

func (*BlockFile) BlockSize Uses

func (self *BlockFile) BlockSize() int

The blocksize for this file.

func (*BlockFile) Close Uses

func (self *BlockFile) Close() error

Close the file. Unmaps the region. There must be no outstanding blocks.

func (*BlockFile) ControlData Uses

func (self *BlockFile) ControlData() (data []byte, err error)

Get the "control data" this free form data which is stored in the control block file. You can put whatever you want in here.

func (*BlockFile) Do Uses

func (self *BlockFile) Do(offset, blocks uint64, do func([]byte) error) error

Load the blocks at the give offset then call the callback, `do`, passing in the loaded bytes. This function releases those bytes after your callback is done. This is the recommended interface to the contents of the memory mapped region.

func (*BlockFile) Free Uses

func (self *BlockFile) Free(offset uint64) error

Free the block at the given offset. The offset is in bytes from the start of the file.

func (*BlockFile) Get Uses

func (self *BlockFile) Get(offset, blocks uint64) ([]byte, error)

Get the bytes at the offset and block count. You probably want to use Do instead. You must call Release() on the bytes when done.

func (*BlockFile) Path Uses

func (self *BlockFile) Path() string

The file system path to this file.

func (*BlockFile) Release Uses

func (self *BlockFile) Release(bytes []byte) error

Release() bytes aquired with Get(). Should error if the bytes where not allocated from the mapping. But why take chances, you probably want to use the Do interface instead.

func (*BlockFile) Remove Uses

func (self *BlockFile) Remove() error

Remove the underlying file. (must be already closed).

func (*BlockFile) SetControlData Uses

func (self *BlockFile) SetControlData(data []byte) (err error)

Put user data into the control block of the file.

func (*BlockFile) SetControlDataNoSync Uses

func (self *BlockFile) SetControlDataNoSync(data []byte) (err error)

Same as SetControlData but does not call Sync() at the end.

func (*BlockFile) Size Uses

func (self *BlockFile) Size() (uint64, error)

func (*BlockFile) Sync Uses

func (self *BlockFile) Sync() error

Sync the mmap'ed changes to disk. This uses the async interface (via the MS_ASYNC flag) so the changes may not be written by the time this method returns. However, they will be written soon.

func (*BlockFile) Valid Uses

func (self *BlockFile) Valid(address uintptr) bool

Is the address given still the address of the memory map?

Package fmap imports 7 packages (graph) and is imported by 5 packages. Updated 2016-07-27. Refresh now. Tools for package owners.