xfs

package
v1.12.4 Latest Latest
Warning

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

Go to latest
Published: Feb 12, 2026 License: MPL-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package xfs provides an extended file system interface that includes additional methods for writing files and directories, as well as utility functions for reading, writing, and manipulating files and directories within a specified file system.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AsOSFile

func AsOSFile(f fs.File, name string) (*os.File, error)

AsOSFile attempts to convert fs.File to *os.File.

func Mkdir

func Mkdir(root Root, name string, perm os.FileMode) error

Mkdir wraps (FS).Mkdir.

func MkdirAll

func MkdirAll(root Root, name string, perm os.FileMode) error

MkdirAll is equivalent of os.MkdirAll acting on specified FileSystem.

func MkdirTemp

func MkdirTemp(root Root, dir, pattern string) (string, error)

MkdirTemp creates a temporary directory in the specified directory with a given pattern.

func Open

func Open(root Root, name string) (fs.File, error)

Open wraps (FS).Open.

func ReadDir

func ReadDir(root Root, name string) ([]fs.DirEntry, error)

ReadDir wraps fs.ReadDir to read a directory from the specified FileSystem.

func ReadFile

func ReadFile(root Root, name string) ([]byte, error)

ReadFile wraps fs.ReadFile to read a file from the specified FileSystem.

func Remove

func Remove(root Root, name string) error

Remove wraps (FS).Remove.

func RemoveAll

func RemoveAll(root Root, name string) (err error)

RemoveAll is equivalent of os.RemoveAll acting on specified FileSystem.

func Rename

func Rename(root Root, oldname, newname string) error

Rename wraps (FS).Rename.

func SplitPath

func SplitPath(path string) []string

SplitPath splits a path into its components, similar to filepath.Split but returns all parts.

func Stat

func Stat(root Root, name string) (fs.FileInfo, error)

Stat wraps fs.Stat to get the file or directory information from the specified FileSystem.

func WriteFile

func WriteFile(root Root, name string, data []byte, perm os.FileMode) error

WriteFile is equivalent of os.WriteFile acting on specified FileSystem.

Types

type FS

type FS interface {
	Open() (int, error)
	io.Closer
	Repair() error

	Source() string
	FSType() string
}

FS is an interface for creating file system handles.

type File

type File interface {
	fs.File
	io.Closer
	io.Reader
	io.ReaderAt
	io.Seeker
	io.Writer
	io.WriterAt
	Fd() uintptr
}

File is an interface that extends the standard fs.File interface with additional methods for writing.

func OpenFile

func OpenFile(root Root, name string, flags int, perm os.FileMode) (File, error)

OpenFile wraps (FS).OpenFile.

type OSRoot

type OSRoot struct {
	Shadow string
}

OSRoot represents a filesystem wrapper using os interface.

func (*OSRoot) Close

func (root *OSRoot) Close() error

Close is no-op for OSRoot.

func (*OSRoot) FSType

func (root *OSRoot) FSType() string

FSType returns the type of the underlying filesystem.

func (*OSRoot) Fd

func (root *OSRoot) Fd() (int, error)

Fd is no-op for OSRoot.

func (*OSRoot) Mkdir

func (root *OSRoot) Mkdir(name string, perm os.FileMode) error

Mkdir creates a new directory in the root filesystem with the specified name and permissions.

func (*OSRoot) Open

func (root *OSRoot) Open(name string) (fs.File, error)

Open opens a file in the root filesystem with the specified name in read-only mode.

func (*OSRoot) OpenFS

func (root *OSRoot) OpenFS() error

OpenFS is no-op for OSRoot.

func (*OSRoot) OpenFile

func (root *OSRoot) OpenFile(name string, flags int, perm os.FileMode) (File, error)

OpenFile opens a file in the root filesystem with the specified name, flags, and permissions.

func (*OSRoot) Remove

func (root *OSRoot) Remove(name string) error

Remove removes a file or directory from the root filesystem.

func (*OSRoot) Rename

func (root *OSRoot) Rename(oldname, newname string) error

Rename renames a file or directory in the root filesystem from old to new.

func (*OSRoot) RepairFS

func (root *OSRoot) RepairFS() error

RepairFS is no-op for OSRoot.

func (*OSRoot) Source

func (root *OSRoot) Source() string

Source returns the source of the underlying filesystem.

type Root

type Root interface {
	fs.FS

	io.Closer
	OpenFS() error
	RepairFS() error
	Fd() (int, error)

	Mkdir(name string, perm os.FileMode) error
	OpenFile(name string, flags int, perm os.FileMode) (File, error)
	Remove(name string) error
	Rename(oldname, newname string) error

	Source() string
	FSType() string
}

Root is an interface that extends the standard fs.FS interface with Write capabilities.

type UnixRoot

type UnixRoot struct {
	Shadow string
	FS     FS
	// contains filtered or unexported fields
}

UnixRoot represents a filesystem wrapper for Unix-like systems.

func (*UnixRoot) Close

func (root *UnixRoot) Close() error

Close closes the underlying filesystem.

func (*UnixRoot) FSType

func (root *UnixRoot) FSType() string

FSType returns the type of the underlying filesystem.

func (*UnixRoot) Fd

func (root *UnixRoot) Fd() (int, error)

Fd returns the file descriptor of the mounted root filesystem. It returns an error if the filesystem is not open or has been closed. Usage of the returned file descriptior is no longer thread safe.

func (*UnixRoot) Mkdir

func (root *UnixRoot) Mkdir(name string, perm os.FileMode) error

Mkdir creates a new directory in the root filesystem with the specified name and permissions.

func (*UnixRoot) Open

func (root *UnixRoot) Open(name string) (fs.File, error)

Open opens a file in the root filesystem with the specified name in read-only mode.

func (*UnixRoot) OpenFS

func (root *UnixRoot) OpenFS() error

OpenFS opens the underlying filesystem.

func (*UnixRoot) OpenFile

func (root *UnixRoot) OpenFile(name string, flags int, perm os.FileMode) (File, error)

OpenFile opens a file in the root filesystem with the specified name, flags, and permissions.

func (*UnixRoot) Remove

func (root *UnixRoot) Remove(name string) error

Remove removes a file or directory from the root filesystem.

func (*UnixRoot) Rename

func (root *UnixRoot) Rename(oldname, newname string) error

Rename renames a file or directory in the root filesystem from old to new.

func (*UnixRoot) RepairFS

func (root *UnixRoot) RepairFS() error

RepairFS repairs the underlying filesystem if necessary.

func (*UnixRoot) Source

func (root *UnixRoot) Source() string

Source returns the source of the underlying filesystem.

Directories

Path Synopsis
Package fsopen provides a simple interface to create and manage a filesystem using the Linux syscalls for filesystem operations.
Package fsopen provides a simple interface to create and manage a filesystem using the Linux syscalls for filesystem operations.
Package opentree provides a simple interface to create and manage a subfilesystem using the `open_tree` syscall.
Package opentree provides a simple interface to create and manage a subfilesystem using the `open_tree` syscall.

Jump to

Keyboard shortcuts

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