iso9660

package
v0.0.0-...-5fe3b72 Latest Latest
Warning

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

Go to latest
Published: Jan 9, 2020 License: Apache-2.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MaxDirectoryRecordLen           = 255
	MaxDirectoryRecordIdentifierLen = 30
)
View Source
const (
	CD001 = "CD001"
)
View Source
const (
	LogicalBlockSize = 2048
)
View Source
const (
	MaxPartSize = 4294965248 // (1 << 32) - 2048
)
View Source
const SymlinkRecursionLimit = 40

Variables

View Source
var (
	ErrDirectoryRecordTooBig = errors.New("DirectoryRecord larger than sector")
	ErrDirectoryTooBig       = errors.New("Directory larger than MaxUint32")
)
View Source
var (
	ErrDirectoryRecordIdentifierOverflow = errors.New("DirectoryRecord.Identifier longer than 30 bytes")
)
View Source
var (
	ErrInodesExhausted = errors.New("inodes exhausted")
)
View Source
var (
	StrARunes map[rune]struct{}
)
View Source
var (
	StrDRunes map[rune]struct{}
)

Functions

func DecodeDirectory

func DecodeDirectory(r io.Reader, dir *Directory) (err error)

func DecodeDirectoryRecord

func DecodeDirectoryRecord(r io.Reader, rec *DirectoryRecord) (err error)

Assumes the length has already been consumed from r

func DecodePrimaryVolumeDescriptor

func DecodePrimaryVolumeDescriptor(r io.Reader, pvd *PrimaryVolumeDescriptor) (err error)

func DecodeSystemUseEntries

func DecodeSystemUseEntries(r io.Reader) (entries []susp.SystemUseEntry, err error)

func InodeSystemUseEntries

func InodeSystemUseEntries(identifier string, name string, inode Inode) ([]susp.SystemUseEntry, error)

func PathTableEncodedLen

func PathTableEncodedLen(pt *PathTable) int64

func StrA

func StrA(input string, length int) string

func StrD

func StrD(input string, length int) string

Types

type ContinuationArea

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

A continuation of a directory record's system use area.

func NewContinuationArea

func NewContinuationArea(start LogicalBlockAddress) ContinuationArea

func (*ContinuationArea) Append

func (*ContinuationArea) Len

func (ca *ContinuationArea) Len() (n int)

func (*ContinuationArea) WriteTo

func (ca *ContinuationArea) WriteTo(w io.Writer) (int64, error)

type CountingReader

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

func (*CountingReader) Consumed

func (cr *CountingReader) Consumed() uint64

func (*CountingReader) Read

func (cr *CountingReader) Read(buf []byte) (int, error)

type CountingWriter

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

func (*CountingWriter) Write

func (cw *CountingWriter) Write(p []byte) (n int, err error)

func (*CountingWriter) Written

func (cw *CountingWriter) Written() int64

type Directory

type Directory struct {
	Records []DirectoryRecord
}

The contents of a directory extent.

func (*Directory) Size

func (d *Directory) Size() int64

func (*Directory) WriteTo

func (d *Directory) WriteTo(w io.Writer) (int64, error)

Write Records to w sequentially, ensure that no record is split across a sector boundary.

type DirectoryInode

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

DirectoryInode implements Inode interface for directories

func NewDirectoryInode

func NewDirectoryInode(ia InodeAllocator, validator NameValidator) (*DirectoryInode, error)

NewDirectoryInode returns a new *DirectoryInode

func (*DirectoryInode) AddChild

func (d *DirectoryInode) AddChild(name string, child Inode) error

AddChild adds a child Inode to the DirectoryInode. It validates the name and checks for collisions before adding the child

func (*DirectoryInode) AddParent

func (d *DirectoryInode) AddParent(parent *DirectoryInode)

AddParent adds a parent of the DirectoryInode

func (*DirectoryInode) AdditionalSystemUseEntries

func (d *DirectoryInode) AdditionalSystemUseEntries() ([]susp.SystemUseEntry, error)

AdditionalSystemUseEntries is a noop

func (*DirectoryInode) Created

func (d *DirectoryInode) Created() time.Time

Created returns the creation time

func (*DirectoryInode) GetChild

func (d *DirectoryInode) GetChild(name string) (Inode, bool)

GetChild returns a child Inode based on the name. If no child is found, it returns (nil, false)

func (*DirectoryInode) InodeNumber

func (d *DirectoryInode) InodeNumber() InodeNumber

InodeNumber returns the inode number

func (*DirectoryInode) IsRoot

func (d *DirectoryInode) IsRoot() bool

IsRoot returns true if the DirectoryInode has no parent

func (*DirectoryInode) Modified

func (d *DirectoryInode) Modified() time.Time

Modified returns the modified time

func (d *DirectoryInode) Nlink() uint32

Nlink returns the number of links from the DirectoryInode

func (*DirectoryInode) Parts

func (d *DirectoryInode) Parts() []InodePart

Parts returns the inode parts

func (*DirectoryInode) Perm

func (d *DirectoryInode) Perm() os.FileMode

Perm returns the Unix permissions for this inode

func (*DirectoryInode) SetCreated

func (d *DirectoryInode) SetCreated(created time.Time)

SetCreated sets the creation time

func (*DirectoryInode) SetModified

func (d *DirectoryInode) SetModified(modified time.Time)

SetModified returns the modified time

func (*DirectoryInode) SetPerm

func (d *DirectoryInode) SetPerm(perm os.FileMode)

SetPerm sets the Unix permissions for this inode

func (*DirectoryInode) SetSize

func (d *DirectoryInode) SetSize(size uint32)

SetSize sets the size

func (*DirectoryInode) SetStart

func (d *DirectoryInode) SetStart(start LogicalBlockAddress)

SetStart sets the starting address

func (*DirectoryInode) Start

Start returns the starting address

func (*DirectoryInode) ToDirectory

func (d *DirectoryInode) ToDirectory() (Directory, ContinuationArea, error)

ToDirectory returns the Directory and ContinurationArea of the inode

func (*DirectoryInode) ToPathTable

func (d *DirectoryInode) ToPathTable() PathTable

ToPathTable computes the PathTable for the inode

func (*DirectoryInode) Type

func (d *DirectoryInode) Type() InodeType

Type return InodeTypeDirectory

func (*DirectoryInode) VisitDirectories

func (d *DirectoryInode) VisitDirectories(visit Visitor) error

VisitDirectories walks the directory structure, visiting only directories, in level order.

func (*DirectoryInode) VisitFiles

func (d *DirectoryInode) VisitFiles(visit Visitor) error

VisitFiles walks the directory structure, visiting only files, in level order.

type DirectoryRecord

type DirectoryRecord struct {
	Identifier               string
	Start                    LogicalBlockAddress
	Length                   uint32
	Flags                    FileFlag
	Recorded                 time.Time
	SystemUse                []susp.SystemUseEntry
	ExtendedAttrRecordLength byte
	FileUnitSize             byte
	InterleaveGap            byte
	VolumeID                 uint16
}

func (*DirectoryRecord) Len

func (rec *DirectoryRecord) Len() int

func (*DirectoryRecord) WriteTo

func (rec *DirectoryRecord) WriteTo(w io.Writer) (int64, error)

type DirectoryRecordIterator

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

func NewDirectoryRecordIterator

func NewDirectoryRecordIterator(iso io.ReaderAt, start LogicalBlockAddress, size int64, off int64) *DirectoryRecordIterator

NewDirectoryRecordIterator creates a new iterator of DirectoryRecords for a directory with start and size and off offset into the directory.

func (*DirectoryRecordIterator) Err

func (it *DirectoryRecordIterator) Err() error

Err should be checked once Next returns false

func (*DirectoryRecordIterator) Next

func (it *DirectoryRecordIterator) Next() bool

Next reads the next DirectoryRecord. It returns true if another record was present, and false on EOF or if an error occurred.

func (*DirectoryRecordIterator) RecordAndLen

func (it *DirectoryRecordIterator) RecordAndLen() (*DirectoryRecord, int64)

RecordAndLen returns the DirectoryRecord that was read by Next and the number of bytes that were read from the directory.

func (*DirectoryRecordIterator) Tell

func (it *DirectoryRecordIterator) Tell() int64

The current position in the directory

type File

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

func (*File) Close

func (f *File) Close() error

func (*File) Name

func (f *File) Name() string

func (*File) Read

func (f *File) Read(p []byte) (n int, err error)

func (*File) ReadAt

func (f *File) ReadAt(p []byte, off int64) (n int, err error)

func (*File) ReadDir

func (f *File) ReadDir() ([]*FileInfo, error)

func (*File) Seek

func (f *File) Seek(offset int64, whence int) (int64, error)

func (*File) Size

func (f *File) Size() int64

type FileFlag

type FileFlag byte
const (
	FileFlagHidden FileFlag = 1 << iota
	FileFlagDir
	FileFlagAssociated
	FileFlagExtendedFormatInfo
	FileFlagExtendedPermissions
	FileFlagReserved1
	FileFlagReserved2
	FileFlagNonTerminal // this is not the final directory record for this file (for files spanning several extents, for example files over 4GiB long.
)

type FileInfo

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

func (*FileInfo) Extent

func (fi *FileInfo) Extent() LogicalBlockAddress

func (*FileInfo) Gid

func (fi *FileInfo) Gid() uint32

func (*FileInfo) Ino

func (fi *FileInfo) Ino() uint32

func (*FileInfo) IsDir

func (fi *FileInfo) IsDir() bool

func (*FileInfo) ModTime

func (fi *FileInfo) ModTime() time.Time

func (*FileInfo) Mode

func (fi *FileInfo) Mode() os.FileMode

func (*FileInfo) Name

func (fi *FileInfo) Name() string
func (fi *FileInfo) Nlink() uint32

func (*FileInfo) Size

func (fi *FileInfo) Size() int64

func (*FileInfo) Sys

func (fi *FileInfo) Sys() interface{}

func (*FileInfo) Target

func (fi *FileInfo) Target() string

func (*FileInfo) Uid

func (fi *FileInfo) Uid() uint32

type FileInode

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

A posix symbolic link

func NewFileInode

func NewFileInode(ia InodeAllocator, o storage.Object) (*FileInode, error)

func (*FileInode) AddParent

func (f *FileInode) AddParent(parent *DirectoryInode)

func (*FileInode) AdditionalSystemUseEntries

func (f *FileInode) AdditionalSystemUseEntries() ([]susp.SystemUseEntry, error)

func (*FileInode) Created

func (f *FileInode) Created() time.Time

func (*FileInode) InodeNumber

func (f *FileInode) InodeNumber() InodeNumber

func (*FileInode) IsRoot

func (f *FileInode) IsRoot() bool

func (*FileInode) Modified

func (f *FileInode) Modified() time.Time
func (f *FileInode) Nlink() uint32

func (*FileInode) Object

func (f *FileInode) Object() storage.Object

func (*FileInode) Parts

func (f *FileInode) Parts() []InodePart

func (*FileInode) Perm

func (f *FileInode) Perm() os.FileMode

Perm returns the Unix permissions for this inode

func (*FileInode) SetCreated

func (f *FileInode) SetCreated(created time.Time)

func (*FileInode) SetModified

func (f *FileInode) SetModified(modified time.Time)

func (*FileInode) SetPerm

func (f *FileInode) SetPerm(perm os.FileMode)

SetPerm sets the Unix permissions for this inode

func (*FileInode) SetStart

func (f *FileInode) SetStart(start LogicalBlockAddress)

func (*FileInode) Start

func (f *FileInode) Start() LogicalBlockAddress

func (*FileInode) Type

func (f *FileInode) Type() InodeType

func (*FileInode) WriteTo

func (f *FileInode) WriteTo(w io.Writer) (n int64, err error)

type IdentifierAllocator

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

Assign unique (hidden) names to directory entries

func NewIdentifierAllocator

func NewIdentifierAllocator() *IdentifierAllocator

func (*IdentifierAllocator) Next

func (ia *IdentifierAllocator) Next() string

type Inode

type Inode interface {
	// The type of inode
	Type() InodeType

	// The unique number assigned to this inode
	InodeNumber() InodeNumber

	// Each child consists of one or more parts of up to MaxPartSize bytes
	Parts() []InodePart

	// Perm returns the Unix permissions for this inode
	Perm() os.FileMode

	// SetPerm sets the Unix permissions for this inode
	SetPerm(perm os.FileMode)

	Created() time.Time

	SetCreated(time.Time)

	Modified() time.Time

	SetModified(time.Time)

	AddParent(*DirectoryInode)

	Nlink() uint32

	IsRoot() bool

	// Additional SUSP entries unique to this inode
	AdditionalSystemUseEntries() ([]susp.SystemUseEntry, error)
}

A file, directory, or symlink

type InodeAllocator

type InodeAllocator interface {
	Next() (InodeNumber, error)
}

A producer of inode numbers

func NewInodeAllocator

func NewInodeAllocator() InodeAllocator

Create a new inode number allocator

type InodeNumber

type InodeNumber uint32

type InodePart

type InodePart interface {
	Start() LogicalBlockAddress
	Size() uint32
}

A portion of a file or directory up to MaxPartSize bytes long

func InodeParts

func InodeParts(start LogicalBlockAddress, size uint64) []InodePart

Calculate the parts of an inode, each up to MaxPartSize size.

type InodeType

type InodeType byte
const (
	InodeTypeFile InodeType = iota
	InodeTypeDirectory
	InodeTypeSymlink
)

type LogicalBlockAddress

type LogicalBlockAddress uint32

type NameValidator

type NameValidator interface {
	//IsValid returns an error if name is not valid, else return nil
	IsValid(name string) error
}

NameValidator is an interface for validating directory names

type NvidiaExtendedNameValidator

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

NvidiaExtendedNameValidator is directory NameValidator with an extend character set

func NewNvidiaExtendedNameValidator

func NewNvidiaExtendedNameValidator() *NvidiaExtendedNameValidator

NewNvidiaExtendedNameValidator return a *NvidiaExtendedNameValidator

func (*NvidiaExtendedNameValidator) IsValid

func (nenv *NvidiaExtendedNameValidator) IsValid(s string) error

IsValid validates name against custom NVIDIA character set

type PathTable

type PathTable struct {
	Records []PathTableRecord
}

type PathTableEncoder

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

func NewPathTableEncoder

func NewPathTableEncoder(byteOrder binary.ByteOrder, w io.Writer) *PathTableEncoder

func (*PathTableEncoder) Encode

func (e *PathTableEncoder) Encode(pt *PathTable) (int64, error)

type PathTableRecord

type PathTableRecord struct {
	Identifier                    string
	ExtendedAttributeRecordLength byte
	Location                      LogicalBlockAddress
	ParentIndex                   uint16
}

type PosixPortableNameValidator

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

PosixPortableNameValidator enforces POSIX portable directory names

func NewPosixPortableNameValidator

func NewPosixPortableNameValidator() *PosixPortableNameValidator

NewPosixPortableNameValidator creates a *PosixPortableNameValidator

func (*PosixPortableNameValidator) IsValid

func (ppnv *PosixPortableNameValidator) IsValid(s string) error

IsValid validates name against POSIX portable character set

type PrimaryVolumeDescriptor

type PrimaryVolumeDescriptor struct {
	SystemIdentifier            string
	VolumeIdentifier            string
	VolumeSetIdentifier         string
	PublisherIdentifier         string
	DataPreparerIdentifier      string
	ApplicationIdentifier       string
	CopyrightFileIdentifier     string
	AbstractFileIdentifier      string
	BibliographicFileIdentifier string
	VolumeSpaceSize             uint32
	VolumeSetSize               uint16
	VolumeSequenceNumber        uint16
	PathTableSize               uint32
	LTableStart                 LogicalBlockAddress
	OptionalLTableStart         LogicalBlockAddress
	MTableStart                 LogicalBlockAddress
	OptionalMTableStart         LogicalBlockAddress
	RootStart                   LogicalBlockAddress
	RootLength                  uint32
	RootModified                time.Time
	Created                     time.Time
	Modified                    time.Time
	Effective                   time.Time
}

func (*PrimaryVolumeDescriptor) WriteTo

func (pvd *PrimaryVolumeDescriptor) WriteTo(w io.Writer) (int64, error)

type ReadDirIterator

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

func NewReadDirIterator

func NewReadDirIterator(iso io.ReaderAt, start LogicalBlockAddress, size int64, off int64) *ReadDirIterator

NewReadDirIterator creates an iterator of FileInfos for a directory at start of size and off offset into the directory.

func (*ReadDirIterator) Err

func (it *ReadDirIterator) Err() error

Err should be checked once Next returns false

func (*ReadDirIterator) FileInfoAndLen

func (it *ReadDirIterator) FileInfoAndLen() (*FileInfo, int64)

FileInfoAndLen returns the FileInfo consumed by calling Next() along with the number of bytes consumed in the directory.

func (*ReadDirIterator) Next

func (it *ReadDirIterator) Next() bool

Next reads one or more records from the directory, aggregating them as necessary.

type Relationship

type Relationship struct {
	Parent     *DirectoryInode
	Identifier string
	Name       string
	Child      Inode
}

type SectorAllocator

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

func NewSectorAllocator

func NewSectorAllocator() *SectorAllocator

func (*SectorAllocator) Alloc

func (sa *SectorAllocator) Alloc(numBytes uint32) LogicalBlockAddress

Returns the start of the block and reserves enough sectors to store numBytes, at least one.

func (*SectorAllocator) Allocated

func (sa *SectorAllocator) Allocated() uint32

Returns the total number of sectors allocated

type SymlinkInode

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

A posix symbolic link

func NewSymlinkInode

func NewSymlinkInode(ia InodeAllocator, target string) (*SymlinkInode, error)

func (*SymlinkInode) AddParent

func (s *SymlinkInode) AddParent(parent *DirectoryInode)

func (*SymlinkInode) AdditionalSystemUseEntries

func (s *SymlinkInode) AdditionalSystemUseEntries() ([]susp.SystemUseEntry, error)

func (*SymlinkInode) Created

func (s *SymlinkInode) Created() time.Time

func (*SymlinkInode) InodeNumber

func (s *SymlinkInode) InodeNumber() InodeNumber

func (*SymlinkInode) IsRoot

func (s *SymlinkInode) IsRoot() bool

func (*SymlinkInode) Modified

func (s *SymlinkInode) Modified() time.Time
func (s *SymlinkInode) Nlink() uint32

func (*SymlinkInode) Parts

func (s *SymlinkInode) Parts() []InodePart

func (*SymlinkInode) Perm

func (s *SymlinkInode) Perm() os.FileMode

Perm returns the Unix permissions for this inode

func (*SymlinkInode) SetCreated

func (s *SymlinkInode) SetCreated(created time.Time)

func (*SymlinkInode) SetModified

func (s *SymlinkInode) SetModified(modified time.Time)

func (*SymlinkInode) SetPerm

func (s *SymlinkInode) SetPerm(perm os.FileMode)

SetPerm sets the Unix permissions for this inode

func (*SymlinkInode) Type

func (s *SymlinkInode) Type() InodeType

type Terminator

type Terminator struct{}

func (*Terminator) WriteTo

func (t *Terminator) WriteTo(w io.Writer) (int64, error)

type Visitor

type Visitor func(Relationship) error

type Volume

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

func NewNvidiaExtendedVolume

func NewNvidiaExtendedVolume() *Volume

NewPosixPortableVolume return *Volume that allows directory names in the NVIDIA extended character set

func NewPosixPortableVolume

func NewPosixPortableVolume() *Volume

NewPosixPortableVolume return *Volume that allows POSIX portable directory names

func NewVolume

func NewVolume() *Volume

func (*Volume) AddFile

func (v *Volume) AddFile(pth string, o storage.Object) (err error)
func (v *Volume) AddSymlink(pth string, target string) (err error)

func (*Volume) SetAbstractFileIdentifier

func (v *Volume) SetAbstractFileIdentifier(val string)

func (*Volume) SetApplicationIdentifier

func (v *Volume) SetApplicationIdentifier(val string)

func (*Volume) SetBibliographicFileIdentifier

func (v *Volume) SetBibliographicFileIdentifier(val string)

func (*Volume) SetCopyrightFileIdentifier

func (v *Volume) SetCopyrightFileIdentifier(val string)

func (*Volume) SetDataPreparerIdentifier

func (v *Volume) SetDataPreparerIdentifier(val string)

func (*Volume) SetPublisherIdentifier

func (v *Volume) SetPublisherIdentifier(val string)

func (*Volume) SetSystemIdentifier

func (v *Volume) SetSystemIdentifier(val string)

func (*Volume) SetVolumeIdentifier

func (v *Volume) SetVolumeIdentifier(val string)

func (*Volume) SetVolumeSetIdentifier

func (v *Volume) SetVolumeSetIdentifier(val string)

func (*Volume) VisitFileInodes

func (v *Volume) VisitFileInodes(visit func(*FileInode) error) error

func (*Volume) VisitFiles

func (v *Volume) VisitFiles(visit func(storage.Object) error) error

func (*Volume) WriteMetadataTo

func (v *Volume) WriteMetadataTo(w io.Writer) (int64, error)

func (*Volume) WriteTo

func (v *Volume) WriteTo(w io.Writer) (int64, error)

type Walker

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

Walker provides an API for traversing a serialized ISO 9660 file system.

func NewWalker

func NewWalker(iso io.ReaderAt) *Walker

func (*Walker) Lstat

func (w *Walker) Lstat(path string) (*FileInfo, error)

Lstat returns a FileInfo describing the named file. If the file is a symbolic link, the returned FileInfo describes the symbolic link. Lstat makes no attempt to follow the link.

func (*Walker) Open

func (w *Walker) Open(name string) (*File, error)

Open opens the named file for reading. If successful, methods on the returned file can be used for reading; the associated file descriptor has mode O_RDONLY.

func (*Walker) ReadDir

func (w *Walker) ReadDir(dirname string) ([]*FileInfo, error)

ReadDir reads the directory named by dirname and returns a list of directory entries sorted by filename.

func (*Walker) Stat

func (w *Walker) Stat(path string) (*FileInfo, error)

Stat returns a FileInfo describing the named file.

func (*Walker) Walk

func (w *Walker) Walk(root string, walkFn filepath.WalkFunc) (err error)

Walk walks the file tree rooted at root, calling walkFn for each file or directory in the tree, including root. All errors that arise visiting files and directories are filtered by walkFn. The files are walked in lexical order, which makes the output deterministic but means that for very large directories Walk can be inefficient. Walk does not follow symbolic links.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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