fibmap

package module
v0.0.0-...-cea105d Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2016 License: MIT Imports: 3 Imported by: 4

README

fibmap

Golang Linux ioctl FIBMAP, FIEMAP, SEEK_DATA/HOLE, PUNCH_HOLE, ...

Documentation

Overview

Package fibmap implements FIBMAP/FIEMAP and related Linux ioctl for dealing with low level file allocation.

Index

Constants

View Source
const (
	FiemapExtentSize = 56 // sizeof(struct fiemap_extent)
	FiemapSize       = 32 // sizeof(struct fiemap)

	// Defined in <linux/fs.h>:
	SEEK_SET      = 0 // seek relative to beginning of file
	SEEK_CUR      = 1 // seek relative to current file position
	SEEK_END      = 2 // seek relative to end of file
	SEEK_DATA     = 3 // seek to the next data
	SEEK_HOLE     = 4 // seek to the next hole
	SEEK_MAX      = SEEK_HOLE
	FIBMAP        = 1 // bmap access
	FIGETBSZ      = 2 // get the block size used for bmap
	FS_IOC_FIEMAP = 3223348747

	// Defined in <linux/fiemap.h>:
	FIEMAP_MAX_OFFSET            = ^uint64(0)
	FIEMAP_FLAG_SYNC             = 0x0001 // sync file data before map
	FIEMAP_FLAG_XATTR            = 0x0002 // map extended attribute tree
	FIEMAP_FLAG_CACHE            = 0x0004 // request caching of the extents
	FIEMAP_FLAGS_COMPAT          = (FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR)
	FIEMAP_EXTENT_LAST           = 0x0001 // Last extent in file.
	FIEMAP_EXTENT_UNKNOWN        = 0x0002 // Data location unknown.
	FIEMAP_EXTENT_DELALLOC       = 0x0004 // Location still pending. Sets EXTENT_UNKNOWN.
	FIEMAP_EXTENT_ENCODED        = 0x0008 // Data can not be read while fs is unmounted
	FIEMAP_EXTENT_DATA_ENCRYPTED = 0x0080 // Data is encrypted by fs. Sets EXTENT_NO_BYPASS.
	FIEMAP_EXTENT_NOT_ALIGNED    = 0x0100 // Extent offsets may not be block aligned.
	FIEMAP_EXTENT_DATA_INLINE    = 0x0200 // Data mixed with metadata. Sets EXTENT_NOT_ALIGNED.
	FIEMAP_EXTENT_DATA_TAIL      = 0x0400 // Multiple files in block. Sets EXTENT_NOT_ALIGNED.
	FIEMAP_EXTENT_UNWRITTEN      = 0x0800 // Space allocated, but no data (i.e. zero).
	FIEMAP_EXTENT_MERGED         = 0x1000 // File does not natively support extents. Result merged for efficiency.
	FIEMAP_EXTENT_SHARED         = 0x2000 // Space shared with other files.

	// Defined in <linux/falloc.h>:
	FALLOC_FL_KEEP_SIZE    = 0x01 // default is extend size
	FALLOC_FL_PUNCH_HOLE   = 0x02 // de-allocates range
	FALLOC_FL_NO_HIDE_STAE = 0x04 // reserved codepoint
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Extent

type Extent struct {
	Logical    uint64 // logical offset in bytes for the start of the extent from the beginning of the file
	Physical   uint64 // physical offset in bytes for the start	of the extent from the beginning of the disk
	Length     uint64 // length in bytes for this extent
	Reserved64 [2]uint64
	Flags      uint32 // FIEMAP_EXTENT_* flags for this extent
	Reserved   [3]uint32
}

based on struct fiemap_extent from <linux/fiemap.h>

type FibmapFile

type FibmapFile struct {
	*os.File
}

func NewFibmapFile

func NewFibmapFile(f *os.File) FibmapFile

return a new FibmapFile

func (FibmapFile) Fallocate

func (f FibmapFile) Fallocate(offset int64, length int64) error

allocate using fallocate

func (FibmapFile) Fibmap

func (f FibmapFile) Fibmap(block uint) (uint, syscall.Errno)

call FIBMAP ioctl

func (FibmapFile) FibmapExtents

func (f FibmapFile) FibmapExtents() ([]Extent, syscall.Errno)

emulate FIEMAP with FIBMAP

func (FibmapFile) Fiemap

func (f FibmapFile) Fiemap(size uint32) ([]Extent, syscall.Errno)

Fiemap uses the FIEMAP ioctl to return the first 'size' extents of the file.

func (FibmapFile) FiemapAt

func (f FibmapFile) FiemapAt(size uint32, start uint64) ([]Extent, syscall.Errno)

FiemapAt uses the FIEMAP ioctl to return 'size' extents, starting at logical offset 'start'.

func (FibmapFile) Figetbsz

func (f FibmapFile) Figetbsz() (int, syscall.Errno)

call FIGETBSZ ioctl

func (FibmapFile) PunchHole

func (f FibmapFile) PunchHole(offset int64, length int64) error

punch hole using fallocate

func (FibmapFile) SeekDataHole

func (f FibmapFile) SeekDataHole() []int64

use SEEK_DATA, SEEK_HOLE to find allocated data ranges in a file

Jump to

Keyboard shortcuts

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