kernel

package
v0.0.0-...-ba0ec08 Latest Latest
Warning

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

Go to latest
Published: May 13, 2020 License: AGPL-3.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Basename

func Basename(path string) string

Basename is like basename(3)

func Dirname

func Dirname(path string) []string

Dirname is like dirname(3)

func Register

func Register(alias string, cmd Command)

Register registers a command

Types

type Command

type Command interface {
	Execute(*State, []string, IO) error
}

A Command is a command that can be typed on the CLI. TODO: completion

type Computer

type Computer struct {
	FS      *Filesystem
	Network Network
	// Map usernames to passwords
	Users map[string]string
	// A map in order to be type-compatible with Users. Value is ignored
	Admins   map[string]string
	Hostname string
}

A Computer represents the current state of a computer. It has a Filesystem, a Network, a set of users, some of whom may be admins, and a hostname.

func NewVM

func NewVM() *Computer

NewVM creates a new VM

func (Computer) Route

func (computer Computer) Route(addr string) (*Computer, error)

Route finds a computer based on a sequence of hops

type ErrorCode

type ErrorCode int

An ErrorCode is a command's exit status.

func (ErrorCode) Error

func (e ErrorCode) Error() string

type Exit

type Exit string

Exit means that the interpreter wants to exit. This may be used to implement exit(1). Before exiting on Exit e, the REPL should print e.Error().

func (Exit) Error

func (e Exit) Error() string

type FSFile

type FSFile struct {
	OwnerPermissions Permissions
	OtherPermissions Permissions
	Owner            string
	// contains filtered or unexported fields
}

An FSFile is a file "on disk". It doesn't contain an offset, so it can't be written to directly.

func NewFile

func NewFile(owner string) *FSFile

NewFile creates an empty file with reasonable default permissions.

type File

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

A File is an FSFile that has been opened, in order to read or write to it.

func (*File) Read

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

Read is the implementation of io.Reader for a File.

func (*File) Seek

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

Seek is the implementation of io.Seeker for a File.

func (*File) Truncate

func (f *File) Truncate(size int64) error

Truncate truncates a file to a certain size

func (*File) Write

func (f *File) Write(p []byte) (int, error)

Write is the implementation of io.Writer for a File.

type Filesystem

type Filesystem struct {
	Subdirs map[string]*Filesystem
	Files   map[string]*FSFile
}

A Filesystem is a directory. It has a set of subdirectories and a set of files.

func (*Filesystem) GetCwd

func (fs *Filesystem) GetCwd() ([]string, error)

GetCwd gets the current working directory of a filesystem.

type IO

type IO struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

IO represents the standard IO facilities given to commands.

type Network

type Network []*Computer

A Network is the set of computers to which a computer is connected.

type PermissionDenied

type PermissionDenied string

PermissionDenied means that permission was denied when reading from a file

func (PermissionDenied) Error

func (p PermissionDenied) Error() string

type Permissions

type Permissions struct {
	Read  bool
	Write bool
}

Permissions represents the actions a user may be allowed to perform on a file.

type State

type State struct {
	Computer *Computer

	Commands map[string]Command
	// contains filtered or unexported fields
}

State represents the current state of the interpreter. It is the REPL's job to store state between commands.

func NewState

func NewState() State

NewState creates a new state for use by the REPL.

func (State) Authenticate

func (state State) Authenticate() bool

Authenticate returns true if the current user is an administrator

func (*State) Cmd

func (state *State) Cmd(cmd string) error

Cmd processes a command and runs it.

func (*State) Exit

func (state *State) Exit(str string) error

Exit leaves the current computer, returning to the previous one.

func (State) GetUser

func (state State) GetUser() string

GetUser gets the current user

func (State) Open

func (state State) Open(fsf *FSFile, opts int) (*File, error)

Open creates a File from an FSFile.

func (State) OpenPath

func (state State) OpenPath(path string, opts int) (io.ReadWriteSeeker, error)

OpenPath is like open(2)

func (*State) PromptlessRepl

func (state *State) PromptlessRepl(_io IO) error

PromptlessRepl spawns a REPL without a prompt

func (*State) Push

func (state *State) Push(c *Computer, user string)

Push simulates spawning a new shell on a computer

func (State) Pwd

func (state State) Pwd() (string, error)

Pwd prints the current working directory. This is made public so that the REPL may include the current working directory in the prompt.

func (*State) Repl

func (state *State) Repl(prompt func(*State, IO), _io IO) error

Repl spawns a REPL.

func (State) ResolveDir

func (state State) ResolveDir(path []string) (*Filesystem, error)

ResolveDir turns a path into a Filesystem

func (*State) SetUser

func (state *State) SetUser(user string, _io IO) error

SetUser sets the current user after authenticating

func (*State) SetWD

func (state *State) SetWD(fs *Filesystem)

SetWD sets the working directory of a state

Jump to

Keyboard shortcuts

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