namespace

package
v7.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: BSD-3-Clause Imports: 7 Imported by: 7

Documentation

Overview

Package namespace parses name space description files https://plan9.io/magic/man2html/6/namespace

Index

Constants

View Source
const (
	// REPL Replace the old file by the new one.
	// Henceforth, an evaluation of old will be translated to the new file.
	// If they are directories (for mount, this condition is true by definition),
	// old becomes a union directory consisting of one directory (the new file).
	REPL mountflag = 0x0000
	// BEFORE Both the old and new files must be directories.
	// Add the constituent files of the new directory to the
	// union directory at old so its contents appear first in the union.
	// After an BEFORE bind or mount, the new directory will be
	// searched first when evaluating file names in the union directory.
	BEFORE mountflag = 0x0001
	// AFTER Like MBEFORE but the new directory goes at the end of the union.
	AFTER mountflag = 0x0002
	// CREATE flag that can be OR'd with any of the above.
	// When a create system call (see open(2)) attempts to create in a union directory,
	// and the file does not exist, the elements of the union are searched in order until
	// one is found with CREATE set. The file is created in that directory;
	// if that attempt fails, the create fails.
	CREATE mountflag = 0x0004
	// CACHE flag, valid for mount only, turns on caching for files made available by the mount.
	// By default, file contents are always retrieved from the server.
	// With caching enabled, the kernel may instead use a local cache
	// to satisfy read(5) requests for files accessible through this mount point.
	CACHE mountflag = 0x0010
)
View Source
const (

	// BIND is the plan9 bind syscall. https://9p.io/magic/man2html/2/bind
	BIND syzcall = 2
	// CHDIR is the plan9 bind syscall. https://9p.io/magic/man2html/2/chdir
	CHDIR syzcall = 3
	// UNMOUNT is the plan9 unmount syscall. https://9p.io/magic/man2html/2/bind
	UNMOUNT syzcall = 35
	// MOUNT is the plan9 MOUNT syscall. https://9p.io/magic/man2html/2/bind
	MOUNT syzcall = 46
	// RFORK is the plan9 rfork() syscall. https://9p.io/magic/man2html/2/fork
	// used to perform clear
	RFORK syzcall = 19
	// IMPORT is not a syscall. https://9p.io/magic/man2html/4/import
	IMPORT syzcall = 7
	// INCLUDE is not a syscall
	INCLUDE syzcall = 14
)

Variables

View Source
var DefaultNamespace = &unixnamespace{}

DefaultNamespace is the default namespace

Functions

func AddNS

func AddNS(nsfile string, user string) error

AddNS also interprets and executes the commands in nsfile. Unlike newns it applies the command to the current name space rather than starting from scratch.

func NewNS

func NewNS(nsfile string, user string) error

NewNS builds a name space for user. It opens the file nsfile (/lib/namespace is used if nsfile is ""), copies the old environment, erases the current name space, sets the environment variables user and home, and interprets the commands in nsfile. The format of nsfile is described in namespace(6).

func ParseFlags

func ParseFlags(args []string) (mountflag, []string)

ParseFlags parses flags as mount, bind would. Not using the os.Flag package here as that would break the name space description files. https://9p.io/magic/man2html/6/namespace

Types

type Builder

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

Builder helps building plan9 name spaces. Builder keeps track of directory changes when another name space file is included, another builder will be created for it's modifications, and it's final working directory will be set to be the parents working directroy after it's modifications are complete.

func NewBuilder

func NewBuilder() (*Builder, error)

NewBuilder returns a builder with defaults

func (*Builder) Parse

func (b *Builder) Parse(file string) error

Parse takes a path and parses the namespace file

type File

type File []Modifier

File are a collection of namespace modifiers

func Parse

func Parse(r io.Reader) (File, error)

Parse takes a namespace file and returns a collection of operations that build a name space in plan9.

think oci runtime spec, but don't think too much cause the json will make your head hurt.

http://man.cat-v.org/plan_9/1/ns

type Modifier

type Modifier interface {
	// Modify modifies the namespace
	Modify(ns Namespace, b *Builder) error
	String() string
}

Modifier repesents an individual command that can be applied to a plan9 name space which will modify the name space of the process or process group.

func ParseArgs

func ParseArgs(args []string) (Modifier, error)

ParseArgs could be used to parse os.Args to unify all commangs under a namespace.Main() it isn't.

func ParseLine

func ParseLine(line string) (Modifier, error)

ParseLine could be used to parse os.Args to unify all commangs under a namespace.Main() it isn't.

type Namespace

type Namespace interface {
	// Bind binds new on old.
	Bind(new, old string, flag mountflag) error
	// Mount mounts servename on old.
	Mount(servername, old, spec string, flag mountflag) error
	// Unmount unmounts new from old, or everything mounted on old if new is missing.
	Unmount(new, old string) error
	// Clear clears the name space with rfork(RFCNAMEG).
	Clear() error
	// Chdir changes the working directory to dir.
	Chdir(dir string) error
	// Import imports a name space from a remote system
	Import(host, remotepath, mountpoint string, flag mountflag) error
}

Namespace is a plan9 namespace. It implmenets the http://man.cat-v.org/plan_9/2/bind calls.

Bind and mount modify the file name space of the current process and other processes in its name space group (see http://man.cat-v.org/plan_9/2/fork). For both calls, old is the name of an existing file or directory in the current name space where the modification is to be made. The name old is evaluated as described in http://man.cat-v.org/plan_9/2/intro, except that no translation of the final path element is done.

type OpenFunc

type OpenFunc func(path string) (io.Reader, error)

OpenFunc opens files for the include or . commands in name space files. while the default open function is just os.Open for the file:// one could extend this to other protocols. Potentially we could even import files from the web.eg

. https://harvey-os.org/lib/namespace@sha256:deadbeef

could be interesting.

Jump to

Keyboard shortcuts

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