direntry

package
v0.0.0-...-2208570 Latest Latest
Warning

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

Go to latest
Published: Feb 27, 2021 License: BSD-2-Clause Imports: 11 Imported by: 0

Documentation

Overview

Package direntry describes FAT directory entries.

Index

Constants

View Source
const (
	// DirentrySize is the size of a direntry struct (both long and short versions).
	DirentrySize = 32
)

Variables

This section is empty.

Functions

func CreateTime

func CreateTime(t time.Time) time.Time

func FreeDirent

func FreeDirent() []byte

FreeDirent creates a byte slice representing "Free directory entry".

func LastFreeDirent

func LastFreeDirent() []byte

LastFreeDirent creates a byte slice representing "Last free directory entry".

func ModifyTime

func ModifyTime(t time.Time) time.Time

Types

type Dirent

type Dirent struct {
	Cluster uint32 // Cluster equals zero if we're opening the root directory

	Size      uint32    // The size field includes all dirents up to and including the "last free" dirent
	WriteTime time.Time // The last time the file was modified
	// contains filtered or unexported fields
}

Dirent describes an in-memory representation of a direntry. This must be an in-memory representation, rather than one which accesses persistant storage, as it gets passed back to the user when "fs.Directory.Read()" is called.

func LoadDirent

func LoadDirent(callback GetDirentryCallback, direntryIndex int) (*Dirent, int, error)

LoadDirent converts a buffer of bytes (from disk) to an in-memory dirent. Returns the number of direntry slots required to represent the logical Dirent.

If the direntry is a "short" filename (or free entry), the index points to it directly.

If the direntry is a "long" filename, the index points to the first long entry, which precedes (optional) other long entries and (required) a short entry.

Otherwise, the requested direntry is invalid.

func LookupDirent

func LookupDirent(callback GetDirentryCallback, name string) (*Dirent, int, error)

LookupDirent looks for (and loads) a dirent with a given name, along with the direntryIndex at which it was found.

If a Dirent with a matching name is not found, return "nil".

func New

func New(name string, cluster uint32, attr fs.FileType) *Dirent

New creates a new in-memory Dirent.

Does not allocate any on-disk space; simply creates an in-memory structure.

func (*Dirent) GetIno

func (d *Dirent) GetIno() uint64

GetIno implements fs.Dirent

func (*Dirent) GetName

func (d *Dirent) GetName() string

GetName implements fs.Dirent

func (*Dirent) GetType

func (d *Dirent) GetType() fs.FileType

GetType implements fs.Dirent

func (*Dirent) IsFree

func (d *Dirent) IsFree() bool

IsFree returns true if the Dirent represents a free spot.

func (*Dirent) IsLastFree

func (d *Dirent) IsLastFree() bool

IsLastFree returns true if the Dirent represents the last free spot.

func (*Dirent) Serialize

func (d *Dirent) Serialize(callback GetDirentryCallback) ([]byte, error)

Serialize converts the in-memory "Dirent" to a "disk-ready" byte slice. The result should be a multiple of "DirentrySize" bytes long.

The "callback" is used to read the containing directory, and confirm that no other files exist with the same "generation number". After the dirent has been serialized once, the generation number is stored, and the callback will no longer be used (it can be nil).

type GetDirentryCallback

type GetDirentryCallback func(int) ([]byte, error)

GetDirentryCallback returns the directory entry at an index. The index is relative to the start of the directory.

This function should only need to be called once for short direntries.

For long direntries, it may need to be called multiple times to read the long direntry components.

Jump to

Keyboard shortcuts

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