os8fs

package
v0.0.0-...-42d31b8 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2017 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package os8fs provides support for reading OS/8 Filesystems and disk images used by PDP-8 computers.

Disk images may contain multiple sides, each with their own filesystem (typically there are only 1 or 2 sides). Filenames may be prefixed by X: to indicate side X of the disk should be used. Sides are numbered starting with A (e.g., A: and B:). If a side is not indicated then the first side is assumed.

The OS/8 Filesystem is a flat filesystem, each file being contiguous on disk. A filesystem may have up to 4,096 blocks. Each block is composed of 256 12 bit words. Image files use 2 bytes per word with the first byte being the lower 8 bits of the 12 bit word and the second by being the upper 4 bits. The bits uuuullllllll are stored as:

+--------+--------+
|llllllll|0000uuuu|
+--------+--------+

File are listed in chained directory blocks starting with block 1 (block 0 is presumed to be a boot block). Each directory block starts with a header of 5 12 bit words:

+------------+
|010000-nfile|   Number of files in the directory block
+------------+
| BLOCK0     |   Index of first data block of first entry
+------------+
| NEXT BLOCK |   Index of next directory block (0 means end)
+------------+
|     ?      |   Unknown
+------------+
|     ?      |   Unknown
+------------+

Numbers are often stored as 010000 - N on a PDP-8 rather than as N. This enables using the ISZ instruction to execute a loop N times.

Following the 5 word header, up to 40 directory entries are listed. The data associated with these entries are contiguous on disk, starting with BLOCK0. Directory entires are either 2 or 6 words long and packed (e.g., 11111122333333). 2 word entries always start with a 0 word and represent free space (a deleted file). The second word is the number of blocks free:

+------------+
|000000000000|
+------------+
|010000 - len|
+------------+

6 word entries represent actual files:

+------+------+
| NAME | NAME |
+------+------+
| NAME | NAME |
+------+------+
| NAME | NAME |
+------+------+
| EXT  | EXT  |
+------+------+
| DATE        |
+-------------+
| 010000 - len|
+-------------+

The NAME and EXT are stored as 6 bit ascii. Each 6 bits represents one byte. Value 0-31 map to 64-95 and values 32-63 map as themselves (e.g., 01 is 'A' and 41 is '!'). NAME and EXT are padded with @ bytes (0). For example, the name NAME.GO would be represented in octal as 1601 1505 0000 0717.

The location of a file is computed by starting with the data block index from the directory block header and then adding all the sizes of all files, and deleted entries, listed in the directory block before the file's entry.

Dates are stored as MMMMDDDDDYYY (4 bit month, 5 bit day, 3 bit year). The year is offset from 1970 so only dates in the range of 1970-1977 can be represented. A 0 date indicates the file has no date associated with it.

When a file is deleted, it's entry is collapsed to two word, a 0 and its length. The remaining entries in the directory block are all moved up by 4 words.

Text files normally store 3 ASCII bytes as two words. The bytes aaaaaaaa, bbbbbbbb, ccccCCCC is stored as:

+------------+
+ccccaaaaaaaa|
+------------+
+CCCCbbbbbbbb|
+------------+

Index

Constants

This section is empty.

Variables

View Source
var (
	RK05 = Drive{Tracks: 204, Sectors: 16, SectorSize: 256, Bytes: 1662976, Sides: 2}
	RX01 = Drive{Tracks: 77, Sectors: 26, SectorSize: 64, Bytes: 256256, Sides: 1}
	RX02 = Drive{Tracks: 77, Sectors: 26, SectorSize: 128, Bytes: 512512, Sides: 1}
	DF32 = Drive{Tracks: 16, Sectors: 1, SectorSize: 2048, Bytes: 65536, Sides: 4}

	// Generic is a generic drive with a single side.  The size of the drive is
	// determined by the size of the disk image.
	Generic = Drive{}
)

Various know drive types for the PDP-8.

View Source
var DefaultImage = os.Getenv("PDP8_IMAGE")

DefaultImage is the name of the PDP-8 OS/8 image to use if not image is specified. By default this is the value of the PDP8_IMAGE environment variable.

View Source
var ErrNotPath = errors.New("no path to drive")

ErrNotPath is returned if GetFile is passed a path that does not contain both a drive image and file name.

Functions

func ASCII6

func ASCII6(w uint16) (a [2]byte)

ASCII6 returns w as 2 ascii bytes.

func ASCII8

func ASCII8(dst []byte, src []uint16, m byte)

ASCII8 writes the first two words of src as 3 bytes into dst, masking each byte with m.

Types

type Date

type Date uint16

A Date represents a date stamp on an OS/8 Fielsystem. Dates are limited to 1970-1977.

func (Date) String

func (d Date) String() string

type Disk

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

A Disk represents a single disk with one or more filesystems.

func OpenImage

func OpenImage(path string, rw bool) (*Disk, error)

OpenImage opens path as a PDP-8 disk image. The disk type is automatically determined by path's extension (.rk05, .rx01, or .rx02). If rw is true then the image is opened read/write.

If the disk image contains more than one side, the side number is specified by using A: or B: as a prefix to the name. A missing side prefix is taken as the first side.

If no extension is provided, or the extension is unknown, path is assumed to contain a single OS/8 filesystem.

If the path is empty, DefaultImage is used.

func (*Disk) Close

func (d *Disk) Close() error

func (*Disk) File

func (d *Disk) File(name string) (*File, error)

File returns information about the specified file on d, or an error. A missing drive prefix is assumed to be A:.

func (*Disk) List

func (d *Disk) List() ([]FileInfo, error)

List returns a list FileInfos for every file on d. If d contains multiple sides then file names will contain a drive prefix.

func (*Disk) Remove

func (d *Disk) Remove(name string) error

Remove removes the named file from d. The filename may be preceded by A: or B: to indicate which side of the disk should be used. THIS IS EXPERIMENTAL!

type Drive

type Drive struct {
	Tracks     int
	Sectors    int
	SectorSize int // in words
	Bytes      int // image size (per side)
	Sides      int
}

A Drive represents a disk drive.

func (Drive) GetFile

func (d Drive) GetFile(path string) (*File, error)

GetFile is like the function GetFile but the disk type is specified by d.

func (Drive) OpenImage

func (d Drive) OpenImage(path string, rw bool) (_ *Disk, err error)

OpenImage opens path as a disk drive of type d returning either the opened disk or an error. If rw is true, open the image read/write.

type File

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

A File represents a file in an OS/8 FileSystem.

func GetFile

func GetFile(path string) (*File, error)

GetFile returns the file named by the base name of path on the disk image specified by the directory part of path. E.g. os8.rk05/A:INIT.TX refers to the file named INIT.TX on the first side of the disk image os8.rk05. The type of disk is intuited from the image name.

func (*File) ASCII

func (f *File) ASCII(strip bool) []byte

ASCII returns the contents of f as 7 bit ASCII encoded as 3 bytes per 2 words. If strip is true, the 8th bit of each byte is stripped.

func (*File) ASCII6

func (f *File) ASCII6() []byte

ASCII6 returns the contents of f as 6 bit ASCII encoded as 2 bytes per word.

func (*File) Bytes

func (f *File) Bytes() []byte

Bytes returns the contents of f as raw bytes (2 bytes per word, second byte has only 4 bits of meaningful data).

func (*File) Name

func (f *File) Name() string

Name returns the name of the file.

func (*File) Words

func (f *File) Words() []uint16

Words returns the contents of f as 12 bit words.

type FileInfo

type FileInfo struct {
	Name   string // Name of the file
	Date   Date   // Date of the file (may be 0)
	Size   int    // Number of 256 word blocks in the file
	Offset int    // Block number to the start of the files data
}

A FileInfo contains metadata about a single file in an OS/8 filesystem.

type FileSystem

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

A FileSystem represents a single OS/8 filesystem as found on a PDP-8 disk.

func (*FileSystem) File

func (f *FileSystem) File(name string) (*File, error)

File returns information about the specified file on f, or an error. File names starting with .block represent raw blocks of data in the file system. There are two forms: .blockS and .blockS-E where S is the initial block number and E is the ending block number.

func (*FileSystem) List

func (f *FileSystem) List() ([]FileInfo, error)

// List returns a list FileInfos for every file on f.

func (*FileSystem) Remove

func (f *FileSystem) Remove(name string) error

Remove removes the named file from f. THIS IS EXPERIMENTAL!

Jump to

Keyboard shortcuts

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