edf

package
v0.0.0-...-710eabd Latest Latest
Warning

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

Go to latest
Published: Aug 11, 2014 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// EDF_VERSION is the file format version
	EDF_VERSION = 1
	// EDF_LENGTH is th number of OS pages in each slice
	EDF_LENGTH = 32
	// EDF_SIZE sets the maximum size of the mapping, represented with
	// EDF_LENGTH segments
	// Currently set arbitrarily to 128 MiB
	EDF_SIZE = 128 * (1024 * 1024)
)
View Source
const (
	// EDF_READ_ONLY means the file will only be read, modifications fail
	EDF_READ_ONLY = iota
	// EDF_READ_WRITE specifies that the file will be read and written
	EDF_READ_WRITE
	// EDF_CREATE means the file will be created and opened with EDF_READ_WRITE
	EDF_CREATE
)
View Source
const (
	// EDF_UNMAP_NOSYNC means the file won't be
	// Sync'd to disk before unmapping
	EDF_UNMAP_NOSYNC = iota
	// EDF_UNMAP_SYNC synchronises the EDF file to disk
	// during unmapping
	EDF_UNMAP_SYNC
)

Variables

This section is empty.

Functions

This section is empty.

Types

type ContentEntry

type ContentEntry struct {
	// Which thread this entry is assigned to
	Thread uint32
	// Which page this block starts at
	Start uint32
	// The page up to and including which the block ends
	End uint32
}

ContentEntry structs are stored in ContentEntry blocks which always at block 2.

type EdfFile

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

EdfFile represents a mapped file on disk or and anonymous mapping for instance storage

func EdfAnonMap

func EdfAnonMap() (*EdfFile, error)

EdfAnonMap maps the EdfFile structure into RAM IMPORTANT: everything's lost if unmapped

func EdfMap

func EdfMap(f *os.File, mode int) (*EdfFile, error)

EdfMap takes an os.File and returns an EdfMappedFile structure, which represents the mmap'd underlying file

The `mode` parameter takes the following values

EDF_CREATE: EdfMap will truncate the file to the right length and write the correct header information
EDF_READ_WRITE: EdfMap will verify header information
EDF_READ_ONLY:  EdfMap will verify header information

IMPORTANT: EDF_LENGTH (edf.go) controls the size of the address space mapping. This means that the file can be truncated to the correct size without remapping. On 32-bit systems, this is set to 2GiB.

func (*EdfFile) AllocPages

func (e *EdfFile) AllocPages(pagesRequested uint32, thread uint32) (EdfRange, error)

AllocPages allocates a |pagesRequested| chunk of pages on the Thread with the given identifier. Returns an EdfRange describing the result.

func (*EdfFile) FindThread

func (e *EdfFile) FindThread(targetName string) (uint32, error)

FindThread obtains the index of a thread in the EdfFile.

func (*EdfFile) FixedAlloc

func (e *EdfFile) FixedAlloc(bytesRequested uint32) (EdfRange, error)

FixedAlloc allocates a |bytesRequested| chunk of pages on the FIXED thread.

func (*EdfFile) GetPageRange

func (e *EdfFile) GetPageRange(pageStart uint64, pageEnd uint64) EdfRange

GetPageRange returns the segment offset and range of two pages in the file.

func (*EdfFile) GetPageSize

func (e *EdfFile) GetPageSize() uint64

GetPageSize returns the pageSize of an EdfFile

func (*EdfFile) GetSegmentSize

func (e *EdfFile) GetSegmentSize() uint64

GetSegmentSize returns the segmentSize of an EdfFile

func (*EdfFile) GetThreadBlocks

func (e *EdfFile) GetThreadBlocks(thread uint32) ([]EdfRange, error)

GetThreadBlocks returns EdfRanges containing blocks assigned to a given thread.

func (*EdfFile) GetThreadCount

func (e *EdfFile) GetThreadCount() uint32

GetThreadCount returns the number of threads in this file.

func (*EdfFile) GetThreads

func (e *EdfFile) GetThreads() (map[uint32]string, error)

GetThreads returns the thread identifier -> name map.

func (*EdfFile) IResolveRange

func (e *EdfFile) IResolveRange(r EdfRange, prev uint64) ([]byte, uint64)

IResolveRange returns a byte slice representing the current EdfRange and returns a value saying whether there's more. Subsequent calls to IncrementallyResolveRange should use the value returned by the previous one until no more ranges are available.

func (*EdfFile) Range

func (e *EdfFile) Range(byteStart uint64, byteEnd uint64) EdfRange

Range returns the segment offset and range of two positions in the file.

func (*EdfFile) ResolveRange

func (e *EdfFile) ResolveRange(r EdfRange) [][]byte

ResolveRange returns a slice of byte slices representing the underlying memory referenced by EdfRange.

WARNING: slow.

func (*EdfFile) Sync

func (e *EdfFile) Sync() error

Sync writes information to physical storage.

func (*EdfFile) Unmap

func (e *EdfFile) Unmap(flags int) error

Unmap unlinks the EdfFile from the address space. EDF_UNMAP_NOSYNC skips calling Sync() on the underlying file before this happens. IMPORTANT: attempts to use this mapping after Unmap() is called will result in crashes.

func (*EdfFile) VerifyHeader

func (e *EdfFile) VerifyHeader() error

VerifyHeader checks that this version of Golearn can read the file presented.

func (*EdfFile) WriteThread

func (e *EdfFile) WriteThread(t *Thread) error

WriteThread inserts a new thread into the EdfFile.

type EdfPosition

type EdfPosition struct {
	Segment uint64
	Byte    uint64
}

EdfPosition represents a start and finish point within the mapping

type EdfRange

type EdfRange struct {
	Start EdfPosition
	End   EdfPosition
	// contains filtered or unexported fields
}

EdfRange represents a start and an end segment mapped in an EdfFile and also the byte offsets within that segment

func (*EdfRange) Size

func (r *EdfRange) Size() uint64

Size returns the size (in bytes) of a given EdfRange

type Thread

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

Threads are streams of data encapsulated within the file.

func NewThread

func NewThread(e *EdfFile, name string) *Thread

NewThread returns a new thread.

func (*Thread) Deserialize

func (t *Thread) Deserialize(out []byte) int

Deserialize copies the input byte slice into a thread.

func (*Thread) GetId

func (t *Thread) GetId() uint32

GetId returns this Thread's identifier.

func (*Thread) GetSpaceNeeded

func (t *Thread) GetSpaceNeeded() int

GetSpaceNeeded the number of bytes needed to serialize this Thread.

func (*Thread) Serialize

func (t *Thread) Serialize(out []byte) int

Serialize copies this thread to the output byte slice Returns the number of bytes used.

Jump to

Keyboard shortcuts

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