2021-06-26 02:33:11 +00:00
|
|
|
// Copyright © 2016 Zellyn Hunter <zellyn@gmail.com>
|
|
|
|
|
|
|
|
// ops.go contains the interfaces and helper functions for operating
|
|
|
|
// on disk images logically: catalog, rename, delete, create files,
|
|
|
|
// etc.
|
|
|
|
|
|
|
|
package types
|
|
|
|
|
|
|
|
// Descriptor describes a file's characteristics.
|
|
|
|
type Descriptor struct {
|
|
|
|
Name string
|
|
|
|
Fullname string // If there's a more complete filename (eg. Super-Mon), put it here.
|
|
|
|
Sectors int
|
|
|
|
Blocks int
|
|
|
|
Length int
|
|
|
|
Locked bool
|
|
|
|
Type Filetype
|
|
|
|
}
|
|
|
|
|
2021-08-01 02:10:44 +00:00
|
|
|
type DiskOrder string
|
|
|
|
|
|
|
|
const (
|
|
|
|
DiskOrderDO = DiskOrder("do")
|
|
|
|
DiskOrderPO = DiskOrder("po")
|
|
|
|
DiskOrderRaw = DiskOrder("raw")
|
|
|
|
DiskOrderAuto = DiskOrder("auto")
|
|
|
|
DiskOrderUnknown = DiskOrder("")
|
|
|
|
)
|
|
|
|
|
2021-06-26 02:33:11 +00:00
|
|
|
// OperatorFactory is the interface for getting operators, and finding out a bit
|
|
|
|
// about them before getting them.
|
|
|
|
type OperatorFactory interface {
|
|
|
|
// Name returns the name of the operator.
|
|
|
|
Name() string
|
2021-08-01 02:10:44 +00:00
|
|
|
// DiskOrder returns the Physical-to-Logical mapping order.
|
|
|
|
DiskOrder() DiskOrder
|
2021-06-26 02:33:11 +00:00
|
|
|
// SeemsToMatch returns true if the []byte disk image seems to match the
|
|
|
|
// system of this operator.
|
|
|
|
SeemsToMatch(diskbytes []byte, debug bool) bool
|
|
|
|
// Operator returns an Operator for the []byte disk image.
|
|
|
|
Operator(diskbytes []byte, debug bool) (Operator, error)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Operator is the interface that can operate on disks.
|
|
|
|
type Operator interface {
|
|
|
|
// Name returns the name of the operator.
|
|
|
|
Name() string
|
2021-08-01 02:10:44 +00:00
|
|
|
// DiskOrder returns the Physical-to-Logical mapping order.
|
|
|
|
DiskOrder() DiskOrder
|
2021-06-26 02:33:11 +00:00
|
|
|
// HasSubdirs returns true if the underlying operating system on the
|
|
|
|
// disk allows subdirectories.
|
|
|
|
HasSubdirs() bool
|
|
|
|
// Catalog returns a catalog of disk entries. subdir should be empty
|
|
|
|
// for operating systems that do not support subdirectories.
|
|
|
|
Catalog(subdir string) ([]Descriptor, error)
|
|
|
|
// GetFile retrieves a file by name.
|
|
|
|
GetFile(filename string) (FileInfo, error)
|
|
|
|
// Delete deletes a file by name. It returns true if the file was
|
|
|
|
// deleted, false if it didn't exist.
|
|
|
|
Delete(filename string) (bool, error)
|
|
|
|
// PutFile writes a file by name. If the file exists and overwrite
|
|
|
|
// is false, it returns with an error. Otherwise it returns true if
|
|
|
|
// an existing file was overwritten.
|
|
|
|
PutFile(fileInfo FileInfo, overwrite bool) (existed bool, err error)
|
2021-08-01 02:10:44 +00:00
|
|
|
// GetBytes returns the disk image bytes, in logical order.
|
|
|
|
GetBytes() []byte
|
2021-06-26 02:33:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// FileInfo represents a file descriptor plus the content.
|
|
|
|
type FileInfo struct {
|
|
|
|
Descriptor Descriptor
|
|
|
|
Data []byte
|
|
|
|
StartAddress uint16
|
|
|
|
}
|