fusefrontend

package
v2.2.1 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2021 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package fusefrontend interfaces directly with the go-fuse library.

Index

Constants

View Source
const FALLOC_DEFAULT = 0x00

FALLOC_DEFAULT is a "normal" fallocate operation

View Source
const FALLOC_FL_KEEP_SIZE = 0x01

FALLOC_FL_KEEP_SIZE allocates disk space while not modifying the file size

Variables

This section is empty.

Functions

This section is empty.

Types

type Args

type Args struct {
	// Cipherdir is the backing storage directory (absolute path).
	// For reverse mode, Cipherdir actually contains *plaintext* files.
	Cipherdir      string
	PlaintextNames bool
	LongNames      bool
	// Should we chown a file after it has been created?
	// This only makes sense if (1) allow_other is set and (2) we run as root.
	PreserveOwner bool
	// Should we force ownership to be presented with a given user and group?
	// This only makes sense if allow_other is set. In *most* cases, it also
	// only makes sense with PreserveOwner set, but can also make sense without
	// PreserveOwner if the underlying filesystem acting as backing store
	// enforces ownership itself.
	ForceOwner *fuse.Owner
	// ConfigCustom is true when the user select a non-default config file
	// location. If it is false, reverse mode maps ".gocryptfs.reverse.conf"
	// to "gocryptfs.conf" in the plaintext dir.
	ConfigCustom bool
	// NoPrealloc disables automatic preallocation before writing
	NoPrealloc bool
	// Exclude is a list of paths to make inaccessible, starting match at
	// the filesystem root
	Exclude []string
	// ExcludeWildcards is a list of paths to make inaccessible, matched
	// anywhere, and supporting wildcards
	ExcludeWildcard []string
	// ExcludeFrom is a list of files from which to read exclusion patterns
	// (with wildcard syntax)
	ExcludeFrom []string
	// Suid is true if the filesystem has been mounted with the "-suid" flag.
	// If it is false, we can ignore the GETXATTR "security.capability" calls,
	// which are a performance problem for writes. See
	// https://github.com/rfjakob/gocryptfs/issues/515 for details.
	Suid bool
	// Enable the FUSE kernel_cache option
	KernelCache bool
	// SharedStorage disables caching & hard link tracking,
	// enabled via cli flag "-sharedstorage"
	SharedStorage bool
	// OneFileSystem disables crossing filesystem boundaries,
	// like rsync's `--one-file-system` does.
	// Only applicable to reverse mode.
	OneFileSystem bool
	// DeterministicNames disables gocryptfs.diriv files
	DeterministicNames bool
}

Args is a container for arguments that are passed from main() to fusefrontend

type File

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

File implements the go-fuse v2 API (github.com/hanwen/go-fuse/v2/fs)

func NewFile

func NewFile(fd int, cName string, rn *RootNode) (f *File, st *syscall.Stat_t, errno syscall.Errno)

NewFile returns a new go-fuse File instance based on an already-open file descriptor. NewFile internally calls Fstat() on the fd. The resulting Stat_t is returned because node.Create() needs it.

`cName` is only used for error logging and may be left blank.

func (*File) Allocate

func (f *File) Allocate(ctx context.Context, off uint64, sz uint64, mode uint32) syscall.Errno

Allocate - FUSE call for fallocate(2)

mode=FALLOC_FL_KEEP_SIZE is implemented directly.

mode=FALLOC_DEFAULT is implemented as a two-step process:

(1) Allocate the space using FALLOC_FL_KEEP_SIZE
(2) Set the file size using ftruncate (via truncateGrowFile)

This allows us to reuse the file grow mechanics from Truncate as they are complicated and hard to get right.

Other modes (hole punching, zeroing) are not supported.

func (*File) Flush

func (f *File) Flush(ctx context.Context) syscall.Errno

Flush - FUSE call

func (*File) Fsync

func (f *File) Fsync(ctx context.Context, flags uint32) (errno syscall.Errno)

Fsync: handles FUSE opcode FSYNC

Unfortunately, as Node.Fsync is also defined and takes precedence, File.Fsync is never called at the moment.

func (*File) Getattr

func (f *File) Getattr(ctx context.Context, a *fuse.AttrOut) syscall.Errno

Getattr FUSE call (like stat)

func (*File) Lseek

func (f *File) Lseek(ctx context.Context, off uint64, whence uint32) (uint64, syscall.Errno)

Lseek - FUSE call.

Looking at fuse_file_llseek @ https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/tree/fs/fuse/file.c?h=v5.12.7#n2634 this function is only called for SEEK_HOLE & SEEK_DATA.

func (*File) Read

func (f *File) Read(ctx context.Context, buf []byte, off int64) (resultData fuse.ReadResult, errno syscall.Errno)

Read - FUSE call

func (*File) Release

func (f *File) Release(ctx context.Context) syscall.Errno

Release - FUSE call, close file

func (*File) Setattr

func (f *File) Setattr(ctx context.Context, in *fuse.SetAttrIn, out *fuse.AttrOut) (errno syscall.Errno)

func (*File) Write

func (f *File) Write(ctx context.Context, data []byte, off int64) (uint32, syscall.Errno)

Write - FUSE call

If the write creates a hole, pads the file to the next block boundary.

type Node

type Node struct {
	fs.Inode
}

Node is a file or directory in the filesystem tree in a gocryptfs mount.

func (*Node) Create

func (n *Node) Create(ctx context.Context, name string, flags uint32, mode uint32, out *fuse.EntryOut) (inode *fs.Inode, fh fs.FileHandle, fuseFlags uint32, errno syscall.Errno)

Create - FUSE call. Creates a new file.

Symlink-safe through the use of Openat().

func (*Node) Fsync

func (n *Node) Fsync(ctx context.Context, f fs.FileHandle, flags uint32) syscall.Errno

Fsync: handles FUSE opcodes FSYNC & FDIRSYNC

Note: f is always set to nil by go-fuse

func (*Node) Getattr

func (n *Node) Getattr(ctx context.Context, f fs.FileHandle, out *fuse.AttrOut) (errno syscall.Errno)

GetAttr - FUSE call for stat()ing a file.

GetAttr is symlink-safe through use of openBackingDir() and Fstatat().

func (*Node) Getxattr

func (n *Node) Getxattr(ctx context.Context, attr string, dest []byte) (uint32, syscall.Errno)

GetXAttr - FUSE call. Reads the value of extended attribute "attr".

This function is symlink-safe through Fgetxattr.

func (n *Node) Link(ctx context.Context, target fs.InodeEmbedder, name string, out *fuse.EntryOut) (inode *fs.Inode, errno syscall.Errno)

Link - FUSE call. Creates a hard link at "newPath" pointing to file "oldPath".

Symlink-safe through use of Linkat().

func (*Node) Listxattr

func (n *Node) Listxattr(ctx context.Context, dest []byte) (uint32, syscall.Errno)

ListXAttr - FUSE call. Lists extended attributes on the file at "relPath".

This function is symlink-safe through Flistxattr.

func (*Node) Lookup

func (n *Node) Lookup(ctx context.Context, name string, out *fuse.EntryOut) (ch *fs.Inode, errno syscall.Errno)

Lookup - FUSE call for discovering a file.

func (*Node) Mkdir

func (n *Node) Mkdir(ctx context.Context, name string, mode uint32, out *fuse.EntryOut) (*fs.Inode, syscall.Errno)

Mkdir - FUSE call. Create a directory at "newPath" with permissions "mode".

Symlink-safe through use of Mkdirat().

func (*Node) Mknod

func (n *Node) Mknod(ctx context.Context, name string, mode, rdev uint32, out *fuse.EntryOut) (inode *fs.Inode, errno syscall.Errno)

Mknod - FUSE call. Create a device file.

Symlink-safe through use of Mknodat().

func (*Node) Open

func (n *Node) Open(ctx context.Context, flags uint32) (fh fs.FileHandle, fuseFlags uint32, errno syscall.Errno)

Open - FUSE call. Open already-existing file.

Symlink-safe through Openat().

func (*Node) Opendir

func (n *Node) Opendir(ctx context.Context) (errno syscall.Errno)

Opendir is a FUSE call to check if the directory can be opened.

func (*Node) Path

func (n *Node) Path() string

Path returns the relative plaintext path of this node

func (*Node) Readdir

func (n *Node) Readdir(ctx context.Context) (fs.DirStream, syscall.Errno)

Readdir - FUSE call.

This function is symlink-safe through use of openBackingDir() and ReadDirIVAt().

func (n *Node) Readlink(ctx context.Context) (out []byte, errno syscall.Errno)

Readlink - FUSE call.

Symlink-safe through openBackingDir() + Readlinkat().

func (*Node) Removexattr

func (n *Node) Removexattr(ctx context.Context, attr string) syscall.Errno

RemoveXAttr - FUSE call.

This function is symlink-safe through Fremovexattr.

func (*Node) Rename

func (n *Node) Rename(ctx context.Context, name string, newParent fs.InodeEmbedder, newName string, flags uint32) (errno syscall.Errno)

Rename - FUSE call. This function is called on the PARENT DIRECTORY of `name`.

Symlink-safe through Renameat().

func (*Node) Rmdir

func (n *Node) Rmdir(ctx context.Context, name string) (code syscall.Errno)

Rmdir - FUSE call.

Symlink-safe through Unlinkat() + AT_REMOVEDIR.

func (*Node) Setattr

func (n *Node) Setattr(ctx context.Context, f fs.FileHandle, in *fuse.SetAttrIn, out *fuse.AttrOut) (errno syscall.Errno)

Setattr - FUSE call. Called for chmod, truncate, utimens, ...

func (*Node) Setxattr

func (n *Node) Setxattr(ctx context.Context, attr string, data []byte, flags uint32) syscall.Errno

SetXAttr - FUSE call. Set extended attribute.

This function is symlink-safe through Fsetxattr.

func (*Node) Statfs

func (n *Node) Statfs(ctx context.Context, out *fuse.StatfsOut) syscall.Errno

StatFs - FUSE call. Returns information about the filesystem.

Symlink-safe because the path is ignored.

func (n *Node) Symlink(ctx context.Context, target, name string, out *fuse.EntryOut) (inode *fs.Inode, errno syscall.Errno)

Symlink - FUSE call. Create a symlink.

Symlink-safe through use of Symlinkat.

func (n *Node) Unlink(ctx context.Context, name string) (errno syscall.Errno)

Unlink - FUSE call. Delete a file.

Symlink-safe through use of Unlinkat().

type RootNode

type RootNode struct {
	Node

	// MitigatedCorruptions is used to report data corruption that is internally
	// mitigated by ignoring the corrupt item. For example, when OpenDir() finds
	// a corrupt filename, we still return the other valid filenames.
	// The corruption is logged to syslog to inform the user,	and in addition,
	// the corrupt filename is logged to this channel via
	// reportMitigatedCorruption().
	// "gocryptfs -fsck" reads from the channel to also catch these transparently-
	// mitigated corruptions.
	MitigatedCorruptions chan string
	// IsIdle flag is set to zero each time fs.isFiltered() is called
	// (uint32 so that it can be reset with CompareAndSwapUint32).
	// When -idle was used when mounting, idleMonitor() sets it to 1
	// periodically.
	IsIdle uint32
	// contains filtered or unexported fields
}

RootNode is the root of the filesystem tree of Nodes.

func (*RootNode) AfterUnmount

func (rn *RootNode) AfterUnmount()

main.doMount() calls this after unmount

func (*RootNode) DecryptPath

func (rn *RootNode) DecryptPath(cipherPath string) (plainPath string, err error)

DecryptPath implements ctlsock.Backend

DecryptPath is symlink-safe because openBackingDir() and decryptPathAt() are symlink-safe.

func (*RootNode) EncryptPath

func (rn *RootNode) EncryptPath(plainPath string) (cipherPath string, err error)

EncryptPath implements ctlsock.Backend

Symlink-safe through openBackingDir().

Jump to

Keyboard shortcuts

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