iso9660

package module
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2023 License: BSD-2-Clause Imports: 17 Imported by: 33

README

iso9660

Go Reference codecov Go Report Card

A package for reading and creating ISO9660

Joliet extension is NOT supported.

Experimental support for reading Rock Ridge extension is currently in the works. If you are experiencing issues, please use the v0.3 release, which ignores Rock Ridge.

References for the format:

Examples

Extracting an ISO

package main

import (
  "log"

  "github.com/kdomanski/iso9660/util"
)

func main() {
  f, err := os.Open("/home/user/myImage.iso")
  if err != nil {
    log.Fatalf("failed to open file: %s", err)
  }
  defer f.Close()

  if err = util.ExtractImageToDirectory(f, "/home/user/target_dir"); err != nil {
    log.Fatalf("failed to extract image: %s", err)
  }
}

Creating an ISO

package main

import (
  "log"
  "os"

  "github.com/kdomanski/iso9660"
)

func main() {
  writer, err := iso9660.NewWriter()
  if err != nil {
    log.Fatalf("failed to create writer: %s", err)
  }
  defer writer.Cleanup()

  f, err := os.Open("/home/user/myFile.txt")
  if err != nil {
    log.Fatalf("failed to open file: %s", err)
  }
  defer f.Close()

  err = writer.AddFile(f, "folder/MYFILE.TXT")
  if err != nil {
    log.Fatalf("failed to add file: %s", err)
  }

  outputFile, err := os.OpenFile("/home/user/output.iso", os.O_WRONLY | os.O_TRUNC | os.O_CREATE, 0644)
  if err != nil {
    log.Fatalf("failed to create file: %s", err)
  }

  err = writer.WriteTo(outputFile, "testvol")
  if err != nil {
    log.Fatalf("failed to write ISO image: %s", err)
  }

  err = outputFile.Close()
  if err != nil {
    log.Fatalf("failed to close output file: %s", err)
  }
}

Recursively create an ISO image from the given directories

package main

import (
  "fmt"
  "log"
  "os"
  "path/filepath"
  "strings"

  "github.com/kdomanski/iso9660"
)

func main() {
  writer, err := iso9660.NewWriter()
  if err != nil {
    log.Fatalf("failed to create writer: %s", err)
  }
  defer writer.Cleanup()

  isoFile, err := os.OpenFile("C:/output.iso", os.O_WRONLY|os.O_TRUNC|os.O_CREATE, 0644)
  if err != nil {
    log.Fatalf("failed to create file: %s", err)
  }
  defer isoFile.Close()

  prefix := "F:\\" // the prefix to remove in the output iso file
  sourceFolders := []string{"F:\\test1", "F:\\test2"} // the given directories to create an ISO file from

  for _, folderName := range sourceFolders {
    folderPath := strings.Join([]string{prefix, folderName}, "/")

    walk_err := filepath.Walk(folderPath, func(path string, info os.FileInfo, err error) error {
      if err != nil {
        log.Fatalf("walk: %s", err)
        return err
      }
      if info.IsDir() {
        return nil
      }
      outputPath := strings.TrimPrefix(path, prefix) // remove the source drive name
      fmt.Printf("Adding file: %s\n", outputPath)

      fileToAdd, err := os.Open(path)
      if err != nil {
        log.Fatalf("failed to open file: %s", err)
      }
      defer fileToAdd.Close()

      err = writer.AddFile(fileToAdd, outputPath)
      if err != nil {
        log.Fatalf("failed to add file: %s", err)
      }
      return nil
    })
    if walk_err != nil {
      log.Fatalf("%s", walk_err)
    }
  }

  err = writer.WriteTo(isoFile, "Test")
  if err != nil {
    log.Fatalf("failed to write ISO image: %s", err)
  }
}

Documentation

Overview

Package iso9660 implements reading and creating basic ISO9660 images.

Index

Constants

View Source
const (
	RockRidgeIdentifier = "RRIP_1991A"
	RockRidgeVersion    = 1
)
View Source
const (
	SUEType_ContinuationArea          = "CE"
	SUEType_PaddingField              = "PD"
	SUEType_SharingProtocolIndicator  = "SP"
	SUEType_SharingProtocolTerminator = "ST"
	SUEType_ExtensionsReference       = "ER"
	SUEType_ExtensionSelector         = "ES"
)

Variables

View Source
var (
	// ErrFileTooLarge is returned when trying to process a file of size greater
	// than 4GB, which due to the 32-bit address limitation is not possible
	// except with ISO 9660-Level 3
	ErrFileTooLarge = errors.New("file is exceeding the maximum file size of 4GB")
)
View Source
var ErrUDFNotSupported = errors.New("UDF volumes are not supported")

Functions

func MarshalString

func MarshalString(s string, padToLength int) []byte

MarshalString encodes the given string as a byte array padded to the given length

func UnmarshalInt16LSBMSB

func UnmarshalInt16LSBMSB(data []byte) (int16, error)

UnmarshalInt16LSBMSB decodes a 16-bit integer in both byte orders, as defined in ECMA-119 7.3.3

func UnmarshalInt32LSBMSB

func UnmarshalInt32LSBMSB(data []byte) (int32, error)

UnmarshalInt32LSBMSB decodes a 32-bit integer in both byte orders, as defined in ECMA-119 7.3.3

func UnmarshalUint32LSBMSB added in v0.3.2

func UnmarshalUint32LSBMSB(data []byte) (uint32, error)

UnmarshalUint32LSBMSB is the same as UnmarshalInt32LSBMSB but returns an unsigned integer

func WriteInt16LSBMSB

func WriteInt16LSBMSB(dst []byte, value int16)

WriteInt16LSBMSB writes a 16-bit integer in both byte orders, as defined in ECMA-119 7.2.3

func WriteInt32LSBMSB

func WriteInt32LSBMSB(dst []byte, value int32)

WriteInt32LSBMSB writes a 32-bit integer in both byte orders, as defined in ECMA-119 7.3.3

Types

type BootVolumeDescriptorBody

type BootVolumeDescriptorBody struct {
	BootSystemIdentifier string
	BootIdentifier       string
	BootSystemUse        [1977]byte
}

BootVolumeDescriptorBody represents the data in bytes 7-2047 of a Boot Record as defined in ECMA-119 8.2

func (*BootVolumeDescriptorBody) UnmarshalBinary

func (bvd *BootVolumeDescriptorBody) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes a BootVolumeDescriptorBody from binary form

type ContinuationEntry added in v0.4.0

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

SUSP-112 5.1

type DirectoryEntry

type DirectoryEntry struct {
	ExtendedAtributeRecordLength byte
	ExtentLocation               int32
	ExtentLength                 uint32
	RecordingDateTime            RecordingTimestamp
	FileFlags                    byte
	FileUnitSize                 byte
	InterleaveGap                byte
	VolumeSequenceNumber         int16
	Identifier                   string
	SystemUse                    []byte
	SystemUseEntries             SystemUseEntrySlice
}

DirectoryEntry contains data from a Directory Descriptor as described by ECMA-119 9.1

func (*DirectoryEntry) Clone

func (de *DirectoryEntry) Clone() DirectoryEntry

Clone creates a copy of the DirectoryEntry

func (*DirectoryEntry) MarshalBinary

func (de *DirectoryEntry) MarshalBinary() ([]byte, error)

MarshalBinary encodes a DirectoryEntry to binary form

func (*DirectoryEntry) UnmarshalBinary

func (de *DirectoryEntry) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes a DirectoryEntry from binary form

type ExtensionRecord added in v0.4.0

type ExtensionRecord struct {
	Version    int
	Identifier string
	Descriptor string
	Source     string
}

func ExtensionRecordDecode added in v0.4.0

func ExtensionRecordDecode(e SystemUseEntry) (*ExtensionRecord, error)

See SUSP-112 5.5

type File

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

File is a os.FileInfo-compatible wrapper around an ISO9660 directory entry

func (*File) GetAllChildren added in v0.4.0

func (f *File) GetAllChildren() ([]*File, error)

GetAllChildren returns the children entries in case of a directory or an error in case of a file. It includes the "." and ".." entries.

func (*File) GetChildren

func (f *File) GetChildren() ([]*File, error)

GetChildren returns the children entries in case of a directory or an error in case of a file. It does NOT include the "." and ".." entries.

func (*File) GetDotEntry added in v0.4.0

func (f *File) GetDotEntry() (*File, error)

GetDotEntry returns the "." entry of a directory or an error in case of a file.

func (*File) IsDir

func (f *File) IsDir() bool

IsDir returns true if the entry is a directory or false otherwise

func (*File) ModTime

func (f *File) ModTime() time.Time

ModTime returns the entry's recording time

func (*File) Mode

func (f *File) Mode() os.FileMode

Mode returns file mode when available. Otherwise it returns os.FileMode flag set with the os.ModeDir flag enabled in case of directories.

func (*File) Name

func (f *File) Name() string

Name returns the base name of the given entry

func (*File) Reader

func (f *File) Reader() io.Reader

Reader returns a reader that allows to read the file's data. If File is a directory, it returns nil.

func (*File) Size

func (f *File) Size() int64

Size returns the size in bytes of the extent occupied by the file or directory

func (*File) Sys

func (f *File) Sys() interface{}

Sys returns nil

type Image

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

Image is a wrapper around an image file that allows reading its ISO9660 data

func OpenImage

func OpenImage(ra io.ReaderAt) (*Image, error)

OpenImage returns an Image reader reating from a given file

func (*Image) Label added in v0.3.5

func (i *Image) Label() (string, error)

RootDir returns the label of the first Primary Volume

func (*Image) RootDir

func (i *Image) RootDir() (*File, error)

RootDir returns the File structure corresponding to the root directory of the first primary volume

type ImageWriter

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

ImageWriter is responsible for staging an image's contents and writing them to an image.

func NewWriter

func NewWriter() (*ImageWriter, error)

NewWriter creates a new ImageWrite and initializes its temporary staging dir. Cleanup should be called after the ImageWriter is no longer needed.

func (*ImageWriter) AddFile

func (iw *ImageWriter) AddFile(data io.Reader, filePath string) error

AddFile adds a file to the ImageWriter's staging area. All path components are mangled to match basic ISO9660 filename requirements.

func (*ImageWriter) AddLocalDirectory added in v0.3.0

func (iw *ImageWriter) AddLocalDirectory(origin, target string) error

AddLocalDirectory adds a directory recursively to the ImageWriter's staging area.

func (*ImageWriter) AddLocalFile added in v0.2.1

func (iw *ImageWriter) AddLocalFile(origin, target string) error

AddLocalFile adds a file identified by its path to the ImageWriter's staging area.

func (*ImageWriter) Cleanup

func (iw *ImageWriter) Cleanup() error

Cleanup deletes the underlying temporary staging directory of an ImageWriter. It can be called multiple times without issues.

func (*ImageWriter) WriteTo

func (iw *ImageWriter) WriteTo(w io.Writer, volumeIdentifier string) error

WriteTo writes the image to the given WriterAt

type PrimaryVolumeDescriptorBody

type PrimaryVolumeDescriptorBody struct {
	SystemIdentifier              string
	VolumeIdentifier              string
	VolumeSpaceSize               int32
	VolumeSetSize                 int16
	VolumeSequenceNumber          int16
	LogicalBlockSize              int16
	PathTableSize                 int32
	TypeLPathTableLoc             int32
	OptTypeLPathTableLoc          int32
	TypeMPathTableLoc             int32
	OptTypeMPathTableLoc          int32
	RootDirectoryEntry            *DirectoryEntry
	VolumeSetIdentifier           string
	PublisherIdentifier           string
	DataPreparerIdentifier        string
	ApplicationIdentifier         string
	CopyrightFileIdentifier       string
	AbstractFileIdentifier        string
	BibliographicFileIdentifier   string
	VolumeCreationDateAndTime     VolumeDescriptorTimestamp
	VolumeModificationDateAndTime VolumeDescriptorTimestamp
	VolumeExpirationDateAndTime   VolumeDescriptorTimestamp
	VolumeEffectiveDateAndTime    VolumeDescriptorTimestamp
	FileStructureVersion          byte
	ApplicationUsed               [512]byte
}

PrimaryVolumeDescriptorBody represents the data in bytes 7-2047 of a Primary Volume Descriptor as defined in ECMA-119 8.4

func (PrimaryVolumeDescriptorBody) MarshalBinary

func (pvd PrimaryVolumeDescriptorBody) MarshalBinary() ([]byte, error)

MarshalBinary encodes the PrimaryVolumeDescriptorBody to its binary form

func (*PrimaryVolumeDescriptorBody) UnmarshalBinary

func (pvd *PrimaryVolumeDescriptorBody) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes a PrimaryVolumeDescriptorBody from binary form as defined in ECMA-119 8.4

type RecordingTimestamp

type RecordingTimestamp time.Time

RecordingTimestamp represents a time and date format that can be encoded according to ECMA-119 9.1.5

func (RecordingTimestamp) MarshalBinary

func (ts RecordingTimestamp) MarshalBinary(dst []byte)

MarshalBinary encodes the RecordingTimestamp in its binary form to a buffer of the length of 7 or more bytes

func (*RecordingTimestamp) UnmarshalBinary

func (ts *RecordingTimestamp) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes a RecordingTimestamp from binary form

type RockRidgeNameEntry added in v0.4.0

type RockRidgeNameEntry struct {
	Flags byte
	Name  string
}

type SPRecord added in v0.4.0

type SPRecord struct {
	BytesSkipped uint8
}

func SPRecordDecode added in v0.4.0

func SPRecordDecode(e SystemUseEntry) (*SPRecord, error)

See SUSP-112 5.3

type SUSPMetadata added in v0.4.0

type SUSPMetadata struct {
	Offset       uint8
	HasRockRidge bool
}

func (*SUSPMetadata) Clone added in v0.4.0

func (sm *SUSPMetadata) Clone() *SUSPMetadata

type SystemUseEntry added in v0.4.0

type SystemUseEntry []byte

SUSP-112 4.1

func (SystemUseEntry) Data added in v0.4.0

func (e SystemUseEntry) Data() []byte

func (SystemUseEntry) Length added in v0.4.0

func (e SystemUseEntry) Length() int

func (SystemUseEntry) Type added in v0.4.0

func (e SystemUseEntry) Type() string

type SystemUseEntrySlice added in v0.4.0

type SystemUseEntrySlice []SystemUseEntry

func (SystemUseEntrySlice) GetExtensionRecords added in v0.4.0

func (s SystemUseEntrySlice) GetExtensionRecords() ([]*ExtensionRecord, error)

func (SystemUseEntrySlice) GetPosixAttr added in v0.4.0

func (s SystemUseEntrySlice) GetPosixAttr() (fs.FileMode, error)

func (SystemUseEntrySlice) GetRockRidgeName added in v0.4.0

func (s SystemUseEntrySlice) GetRockRidgeName() string

type VolumeDescriptorTimestamp

type VolumeDescriptorTimestamp struct {
	Year      int
	Month     int
	Day       int
	Hour      int
	Minute    int
	Second    int
	Hundredth int
	Offset    int
}

VolumeDescriptorTimestamp represents a time and date format that can be encoded according to ECMA-119 8.4.26.1

func VolumeDescriptorTimestampFromTime

func VolumeDescriptorTimestampFromTime(t time.Time) VolumeDescriptorTimestamp

VolumeDescriptorTimestampFromTime converts time.Time to VolumeDescriptorTimestamp

func (*VolumeDescriptorTimestamp) MarshalBinary

func (ts *VolumeDescriptorTimestamp) MarshalBinary() ([]byte, error)

MarshalBinary encodes the timestamp into a binary form

func (*VolumeDescriptorTimestamp) UnmarshalBinary

func (ts *VolumeDescriptorTimestamp) UnmarshalBinary(data []byte) error

UnmarshalBinary decodes a VolumeDescriptorTimestamp from binary form

Notes

Bugs

  • If there are multiple RR PX entries (which is forbidden by the spec), the reader will use the first one.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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