godirect

package module
v0.0.0-...-5dd4cb1 Latest Latest
Warning

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

Go to latest
Published: Feb 6, 2013 License: MIT Imports: 7 Imported by: 0

README

godirect - A library for direct IO in GO

This is a library meant to allow programs to utilize direct IO in GO. It exposes high and low level interfaces.

The library currently only has high level interfaces for reading.

Dependencies

Requires libblkid and it's developent files.

DOCs

http://godoc.org/github.com/ficoos/godirect

TODO

  • More tests
  • Support other OSs

Documentation

Overview

Package to allow direct IO in Go. Currently only works on Linux

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AlignedBuffer

type AlignedBuffer interface {
	Close()
	CreateSlice() []byte
}

func NewAlignedBuffer

func NewAlignedBuffer(alignment int64, size int) (AlignedBuffer, error)

The function allocates size bytes. The address of the allocated memory will be a multiple of alignment, which must be a power of two and a multiple of sizeof(void *). Alignment or size must not be 0 or the method will intentionally panic.

type DeviceTopology

type DeviceTopology struct {
	AlignmentOffset    uint64 // Meomory alignment required direct IO
	MinimumIOSize      uint64 // Minimal IO allowed
	OptimalIOSize      uint64 // Optimal IO for device
	LogicalSectorSize  uint64 // Logical sector size
	PhysicalSectorSize uint64 // Physical sector size
}

func DetectDeviceTopology

func DetectDeviceTopology(file File) DeviceTopology

Detects the topology data of a device. In case of an error getting any of the topology properties the field will be set to 0

type File

type File interface {
	Fd() uintptr
	Seek(offset int64, whence int) (ret int64, err error)
}

type Reader

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

A high level wrapper that allows reading direct IO in arbitrary locations and chunk sizes. This implementation prefers simplicity over performance. It is meant to be easily integrated with other IO operations in Go that might not expect the constraints that direct IO demands.

func NewReader

func NewReader(file File) *Reader

Creates a new Reader for that specified file It is assumed that the file has been opened with the O_DIRECT flag

func (*Reader) Read

func (r *Reader) Read(p []byte) (n int, err error)

Reads bytes from the file. Note that the movement of the offset pointer is not atomic.

func (*Reader) ReadAt

func (r *Reader) ReadAt(p []byte, off int64) (int, error)

type Writer

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

Writer implements buffering on top of a specially allocated buffer to allow for direct IO writes. If an error occurs writing to a Writer, no more data will be accepted and all subsequent writes will return the error. The user can force a write by using Flush() but the writer will fill the ramainder of the buffer with '\0' before writing.

func NewWriter

func NewWriter(file File) (*Writer, error)

NewWriter returns a new Writer with an internal buffer that is suitable for direct IO operations.

func (*Writer) Available

func (w *Writer) Available() int

Available returns how many bytes are unused in the buffer.

func (*Writer) Buffered

func (w *Writer) Buffered() int

Buffered returns the number of bytes that have been written into the current buffer.

func (*Writer) Close

func (w *Writer) Close()

Frees all internal buffers but does not close the underlying file.

func (*Writer) Flush

func (w *Writer) Flush() error

Flushes all buffered data. If there is not enough data to write a complete block the function will fill the remaining space with '\0'.

func (*Writer) Write

func (w *Writer) Write(p []byte) (nn int, err error)

Write writes the contents of p into the buffer. It returns the number of bytes written. If nn < len(p), it also returns an error explaining why the write is short.

Jump to

Keyboard shortcuts

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