mount

package
v0.41.0-rc2 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2026 License: Apache-2.0, MIT, Apache-2.0, + 1 more Imports: 15 Imported by: 0

Documentation

Overview

package mount provides a simple abstraction around a mount point

Index

Constants

View Source
const (
	DefaultFileModeRW = os.FileMode(0o644)
	DefaultDirModeRW  = os.ModeDir | 0o755
)

Writable mounts (/ipns, /mfs): standard POSIX defaults matching umask 022.

View Source
const (
	DefaultFileModeRO = os.FileMode(0o444)
	DefaultDirModeRO  = os.ModeDir | 0o555
)

Read-only mount (/ipfs): no write bits.

View Source
const DefaultBlksize = 1024 * 1024

DefaultBlksize is the preferred I/O size (stat.st_blksize) FUSE mounts advertise when no chunker-derived value applies (readonly /ipfs, or writable /mfs with a rabin/buzhash chunker). Larger hints let tools like cp, dd, and rsync use bigger buffers, amortizing FUSE syscall and DAG-walk overhead. 1 MiB matches the chunk size of Kubo's cross-implementation CID-deterministic import profile (IPIP-499). Hardcoded instead of tracking boxo's chunker default so the stat(2) contract stays stable across Kubo and boxo upgrades.

View Source
const MaxReadAhead = 64 * 1024 * 1024

MaxReadAhead tells the kernel how far ahead to read in a single FUSE request. 64 MiB works well for sequential access (streaming, file copies) because most data is served from the local blockstore after the initial fetch. Network-backed reads are already chunked by the DAG layer, so oversized readahead does not cause extra round-trips.

View Source
const NamespaceRootMode = os.ModeDir | 0o111

NamespaceRootMode is for the /ipfs/ and /ipns/ root directories. Execute-only: these are virtual namespaces where users traverse by name (CID or IPNS key) but listing the full namespace is not possible.

View Source
const StatBlockSize = 512

StatBlockSize is the POSIX stat(2) block unit. The st_blocks field reports allocation in 512-byte units regardless of the filesystem's real block size (see `man 2 stat`). Tools like `du`, `ls -s`, and `find -size` multiply st_blocks by this constant to compute bytes.

View Source
const SymlinkMode = os.FileMode(0o777)

SymlinkMode is the POSIX permission bits for symlinks. Symlink permissions are always 0777; access control uses the target's mode.

View Source
const WritableMountCapabilities = fuse.CAP_ATOMIC_O_TRUNC

WritableMountCapabilities are FUSE capabilities requested for writable mounts (/ipns, /mfs).

CAP_ATOMIC_O_TRUNC tells the kernel to pass O_TRUNC to Open instead of sending a separate SETATTR(size=0) before Open. Without this, the kernel does SETATTR first, which requires opening a write descriptor inside Setattr. MFS only allows one write descriptor at a time, so that deadlocks. With this capability, O_TRUNC is handled inside Open where we already hold the descriptor.

View Source
const XattrCID = "ipfs.cid"

XattrCID is the extended attribute name for the node's CID. Follows the convention used by CephFS (ceph.*), Btrfs (btrfs.*), and GlusterFS (glusterfs.*) of using a project-specific namespace.

View Source
const XattrCIDDeprecated = "ipfs_cid"

XattrCIDDeprecated is the old xattr name. Getxattr normalizes it to XattrCID and logs a deprecation error so existing tooling keeps working while users migrate. TODO: remove after 2 releases.

Variables

View Source
var ErrNotMounted = errors.New("not mounted")
View Source
var MountTimeout = time.Second * 5

Functions

func BlksizeFromChunker

func BlksizeFromChunker(chunkerStr string) uint32

BlksizeFromChunker derives the preferred I/O size hint for the writable mounts from the user's Import.UnixFSChunker setting. It extracts the byte count from `size-<bytes>` and returns DefaultBlksize for rabin, buzhash, or malformed values (where there is no single preferred size). Values are clamped to fuse.MAX_KERNEL_WRITE because the kernel splits any larger userspace read/write into MAX_KERNEL_WRITE-sized FUSE ops regardless, so hinting past the ceiling just wastes userspace buffers.

func Closer added in v0.3.6

func Closer(m Mount) io.Closer

func ForceUnmount

func ForceUnmount(m Mount) error

ForceUnmount attempts to forcibly unmount a given mount. It does so by calling diskutil or fusermount directly.

func ForceUnmountManyTimes

func ForceUnmountManyTimes(m Mount, attempts int) error

ForceUnmountManyTimes attempts to forcibly unmount a given mount, many times. It does so by calling diskutil or fusermount directly. Attempts a given number of times.

func PlatformMountOpts

func PlatformMountOpts(_ *fuse.MountOptions)

PlatformMountOpts is a no-op on Linux and FreeBSD.

func ReadErrno

func ReadErrno(err error) syscall.Errno

ReadErrno maps an error from a context-aware read or write to a FUSE errno. It exists so context cancellation surfaces as EINTR rather than the unspecified code that fs.ToErrno produces for context.Canceled.

The kernel sends FUSE_INTERRUPT when a userspace process is killed mid-syscall (Ctrl-C, SIGKILL on a stuck `cat`). go-fuse cancels the per-request context in response. Returning EINTR tells the kernel to abort the syscall with the right errno; without this, fs.ToErrno turns context.Canceled into something the caller can't act on.

func SizeToStatBlocks

func SizeToStatBlocks(size uint64) uint64

SizeToStatBlocks converts a byte size to the number of 512-byte blocks reported by POSIX stat(2) in the st_blocks field, rounded up so a non-empty file reports at least one block.

func UnmountCmd added in v0.4.18

func UnmountCmd(point string) (*exec.Cmd, error)

UnmountCmd creates an exec.Cmd that is GOOS-specific for unmount a FUSE mount.

Types

type Mount

type Mount interface {
	// MountPoint is the path at which this mount is mounted
	MountPoint() string

	// Unmounts the mount
	Unmount() error

	// Checks if the mount is still active.
	IsActive() bool
}

Mount represents a filesystem mount.

func NewMount

func NewMount(root fs.InodeEmbedder, mountpoint string, opts *fs.Options) (Mount, error)

NewMount mounts a FUSE filesystem at a given location, and returns a Mount instance.

Jump to

Keyboard shortcuts

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