Documentation
¶
Overview ¶
Package iso9660 is a pure-Go driver for the ISO 9660 (ECMA-119) CD/DVD image format produced by mkisofs/genisoimage/xorriso. It reads the Primary Volume Descriptor, walks directory records, and reads contiguous file extents.
On read, the base ECMA-119 layer (uppercase ;version-suffixed names) plus the Rock Ridge (POSIX long names/permissions/symlinks, including CE continuation areas) and Joliet (UCS-2 long names) extensions are decoded. When a tree carries Rock Ridge it takes precedence, then Joliet, then the base tree.
An existing image is read-only once mastered: every mutating method of filesystem.Filesystem (WriteFile, MkDir, ...) returns ErrReadOnly. To author a new image, use Builder (NewBuilder / AddDir / AddFile / WriteTo), which masters a base ECMA-119 image — system area, Primary Volume Descriptor, Volume Descriptor Set Terminator, Type-L/Type-M path tables, directory extents and file data. Writing covers the base ECMA-119 layer (interchange level 1); the Rock Ridge and Joliet extensions are decoded on read but not yet written.
Index ¶
- Variables
- func OpenReader(r io.ReaderAt, size int64) (filesystem.Filesystem, error)
- type Builder
- type FS
- func (fs *FS) Close() error
- func (fs *FS) DeleteDir(string) error
- func (fs *FS) DeleteFile(string) error
- func (fs *FS) ListDir(path string) ([]filesystem.DirEntry, error)
- func (fs *FS) MkDir(string, os.FileMode) error
- func (fs *FS) OpenFile(path string) (filesystem.File, error)
- func (fs *FS) ReadFile(path string) ([]byte, error)
- func (fs *FS) ReadLink(path string) (string, error)
- func (fs *FS) Rename(string, string) error
- func (fs *FS) Stat(path string) (filesystem.Stat, error)
- func (fs *FS) Volume() *Volume
- func (fs *FS) WriteFile(string, []byte, os.FileMode) error
- type Volume
Constants ¶
This section is empty.
Variables ¶
var ( // ErrReadOnly is returned by every mutating method (WriteFile, MkDir, // DeleteFile, DeleteDir, Rename). ISO 9660 is a read-only format. ErrReadOnly = errors.New("iso9660: filesystem is read-only") // ErrBadDescriptor is returned when no valid Primary Volume Descriptor // (standard identifier "CD001") is found. ErrBadDescriptor = errors.New("iso9660: no valid primary volume descriptor") // ErrNotFound is returned when a path component cannot be located. ErrNotFound = fmt.Errorf("iso9660: path not found: %w", iofs.ErrNotExist) // ErrNotDirectory is returned when ListDir targets a non-directory. ErrNotDirectory = errors.New("iso9660: not a directory") // ErrNotRegular is returned when ReadFile targets a non-regular file. ErrNotRegular = errors.New("iso9660: not a regular file") // ErrNotSymlink is returned by ReadLink when the target is not a symlink. // Symlinks come from the Rock Ridge SL entry (base ISO 9660 has none), so // this is also what ReadLink returns on a plain (non-Rock-Ridge) image. ErrNotSymlink = errors.New("iso9660: not a symbolic link") // ErrTooManyLinks is returned when path resolution exceeds the symlink hop // limit, indicating a loop. ErrTooManyLinks = errors.New("iso9660: too many symbolic link traversals") // ErrCorrupt is returned when an on-disk structure fails a sanity check. ErrCorrupt = errors.New("iso9660: corrupt image") // ErrInvalidName is returned by the Builder when an Add* path is empty or // otherwise unusable. ErrInvalidName = errors.New("iso9660: invalid name") // ErrExists is returned by the Builder when an Add* path collides with an // entry of the wrong type (a file where a directory is needed, or vice // versa). ErrExists = errors.New("iso9660: path already exists") )
Sentinel errors. Compare with errors.Is so wrapped errors continue to match.
Functions ¶
func OpenReader ¶ added in v0.3.0
func OpenReader(r io.ReaderAt, size int64) (filesystem.Filesystem, error)
OpenReader opens the ISO 9660 filesystem at the start of r, exactly as Open does, and returns it as a filesystem.Filesystem.
It exists so every driver in go-filesystems answers to ONE name for the same thing. github.com/go-filesystems/detect's Opener is func(io.ReaderAt, int64) (filesystem.Filesystem, error): Open here is the right shape but returns a concrete *FS, which is a different type and does not fit. The drivers that could only be opened from a PATH have grown this function; this one is that same function, so a caller can write
detect.Register(detect.T, driver.OpenReader)
for every driver instead of a closure per driver.
The concrete type is still there for a caller that wants what it has beyond the common interface: Open returns it.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder accumulates a directory tree in memory and then writes it as a base ISO 9660 image. Construct one with NewBuilder, populate it with AddDir and AddFile, then call WriteTo.
Builder is the write-side counterpart to Open: an image produced here reads back through this package's own reader (see the round-trip tests).
func NewBuilder ¶
NewBuilder returns an empty Builder whose root directory is "/". volumeID becomes the Primary Volume Descriptor volume identifier (uppercased and truncated to the 32-byte ECMA-119 field; empty yields "CDROM").
func (*Builder) AddDir ¶
AddDir creates the directory at the slash-separated absolute path, creating any missing parents. It is idempotent for an already-existing directory and returns an error if a path component already exists as a regular file.
type FS ¶
type FS struct {
// contains filtered or unexported fields
}
FS is an opened, read-only ISO 9660 filesystem.
func Open ¶
Open parses the ISO 9660 volume descriptors and returns a read-only handle. The caller retains ownership of rs unless it implements io.Closer. Pass size = -1 if unknown.
func (*FS) DeleteFile ¶
func (*FS) ListDir ¶
func (fs *FS) ListDir(path string) ([]filesystem.DirEntry, error)
ListDir enumerates the directory at path, excluding the "." and ".." special entries.
func (*FS) OpenFile ¶ added in v0.2.0
func (fs *FS) OpenFile(path string) (filesystem.File, error)
OpenFile opens the regular file at path for random access.
It resolves the path exactly as ReadFile does — following Rock Ridge symlinks — and then records where the file's extents live, without reading any of them. Note that this METHOD on *FS is distinct from the package-level OpenFile(path) function, which opens an image file from the host filesystem and returns an *FS; Go keeps package scope and method sets apart, and the method is the one filesystem.Opener asks for.
func (*FS) ReadLink ¶
ReadLink returns the target of a Rock Ridge symbolic link. Base ISO 9660 without Rock Ridge has no symlinks, so ReadLink reports ErrNotSymlink.
SECURITY: the returned target is the raw, UNTRUSTED Rock Ridge SL value from the image. It may contain ".." components or an absolute path, so a malicious image can point it anywhere. In-driver path resolution (resolveFrom) is unaffected — it filters "."/".." and rebases absolute targets against the image root, and caps symlink follows with a safeio.SymlinkBudget — so the link can never escape the image when traversed through this package. Callers that interpret the returned string against the HOST filesystem (for example to recreate the link on disk during extraction) MUST sanitise it first; otherwise a "../../etc/passwd" or "/etc/passwd" target is a path traversal vector.
func (*FS) Stat ¶
func (fs *FS) Stat(path string) (filesystem.Stat, error)
Stat resolves path and returns a synthesised mode (type + default perms), size and a pseudo-inode (the extent LBA).
type Volume ¶
type Volume struct {
VolumeID string
BlockSize uint32 // logical block size (usually 2048)
SpaceSize uint32 // volume space size in logical blocks
// contains filtered or unexported fields
}
Volume is the decoded volume-descriptor data the reader needs. It carries both the Primary tree root and, when present, the Joliet (UCS-2) tree root; the FS picks which to traverse.
