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 InoFromCid(c cid.Cid) uint64
- func InoGenFromCid(c cid.Cid) (ino, gen uint64)
- 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 AutomaticIno = 1 << 63
AutomaticIno is where go-fuse starts numbering nodes a filesystem did not number itself. Mounts keep their own numbers below it, so a node that slips through unnumbered can never be mistaken for one that was numbered. NewMount pins fs.Options.FirstAutomaticIno to it rather than relying on go-fuse's default, which is the same value but free to change.
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 FirstIno = 2
FirstIno is the lowest number a mount hands out to an entry, leaving 0 (not a valid inode number) and 1 (the mount point) alone.
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 Nlink = 1
Nlink is the link count (stat.st_nlink) reported for every entry on a FUSE mount. Left unset it is 0, which POSIX gives to an inode with no remaining names, so tools read a live file as one that is on its way out.
1 is right for files and symlinks: neither IPFS nor MFS has hard links. Directories conventionally count their own entry, their parent's, and one per subdirectory, but reporting 1 for them as well is deliberate. GNU find skips the stat of a directory's children once it has seen st_nlink-2 of them, and would miss entries if the count were a guess; a count below 2 tells it to walk the directory properly instead.
const RootIno = 1
RootIno is the inode number reported for a mount point. go-fuse leaves the root's inode number at 0 unless it is told otherwise, and 0 is not a valid inode number: tools that check it read the mount point as a file that is not there. 1 is the conventional root number and is already the FUSE node ID the kernel uses for the root.
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 ¶ added in v0.41.0
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 InoFromCid ¶ added in v0.43.1
InoFromCid derives an inode number for a node on an immutable mount, where the CID is the identity of the content and nothing else has to be tracked. Two paths that resolve to the same CID get the same number on purpose: on a content-addressed tree they are the same object, and go-fuse then serves both from one node, which keeps a single page cache for the content behind both names.
func InoGenFromCid ¶ added in v0.43.1
InoGenFromCid derives both halves of a node's identity on an immutable mount: the inode number reported to userspace, and the generation that goes with it in fs.StableAttr.
go-fuse matches a lookup against the nodes it already holds by the whole of StableAttr, so two CIDs that agree on all of it are served as one object, and whichever was looked up first answers for both. The inode number alone cannot carry that identity: it is 63 bits, which two of the files a busy mount serves are liable to share, and a mount serves whatever content it is asked for, including content chosen to collide. The generation adds another 64 bits, out of reach of both.
Both numbers come from a hash of the codec together with the multihash. The codec has to be in there because the same block reached as raw and as dag-pb is decoded differently and is not the same file; the CID version is left out because a CIDv0 and a CIDv1 dag-pb of the same content are.
func PlatformMountOpts ¶ added in v0.41.0
func PlatformMountOpts(_ *fuse.MountOptions)
PlatformMountOpts is a no-op on Linux and FreeBSD.
func ReadErrno ¶ added in v0.41.0
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 ¶ added in v0.41.0
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.