Documentation
¶
Overview ¶
package mount provides a simple abstraction around a mount point
Index ¶
- Constants
- Variables
- func BlksizeFromChunker(chunkerStr string) uint32
- func Closer(m Mount) io.Closer
- func ForceUnmount(m Mount) error
- func ForceUnmountManyTimes(m Mount, attempts int) error
- func PlatformMountOpts(_ *fuse.MountOptions)
- func ReadErrno(err error) syscall.Errno
- func SizeToStatBlocks(size uint64) uint64
- func UnmountCmd(point string) (*exec.Cmd, error)
- type Mount
Constants ¶
const ( DefaultFileModeRW = os.FileMode(0o644) DefaultDirModeRW = os.ModeDir | 0o755 )
Writable mounts (/ipns, /mfs): standard POSIX defaults matching umask 022.
const ( DefaultFileModeRO = os.FileMode(0o444) DefaultDirModeRO = os.ModeDir | 0o555 )
Read-only mount (/ipfs): no write bits.
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.
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.
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.
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.
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.
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.
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.
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 ¶
var ErrNotMounted = errors.New("not mounted")
var MountTimeout = time.Second * 5
Functions ¶
func BlksizeFromChunker ¶
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 ForceUnmount ¶
ForceUnmount attempts to forcibly unmount a given mount. It does so by calling diskutil or fusermount directly.
func ForceUnmountManyTimes ¶
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 ¶
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 ¶
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.