bpffs

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Mar 31, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package bpffs provides functions to check and mount the BPF filesystem.

Index

Constants

View Source
const (
	// DefaultMountPoint is the standard location for the BPF
	// filesystem.
	DefaultMountPoint = "/sys/fs/bpf"

	// DefaultMountInfoPath is the path to the mountinfo file.
	DefaultMountInfoPath = "/proc/self/mountinfo"
)

Variables

This section is empty.

Functions

func EnsureMounted

func EnsureMounted(mountInfoPath, mountPoint string) error

EnsureMounted ensures a bpffs is mounted at mountPoint. It checks mountInfoPath (e.g. /proc/self/mountinfo) for an existing bpf mount at mountPoint; if none is found, it mounts one.

Equivalent to:

if ! findmnt --noheadings --types bpf <mountPoint>; then
  mount bpffs <mountPoint> -t bpf
fi

func IsMounted

func IsMounted(mountInfoPath, mountPoint string) (bool, error)

IsMounted reports whether a bpffs is mounted at mountPoint by parsing mountInfoPath (e.g. /proc/self/mountinfo).

The mountinfo format is documented in proc(5). Each line contains:

mount_id parent_id major:minor root mount_point options [optional_fields...] - fstype source super_options

Example bpffs entry:

30 22 0:27 / /sys/fs/bpf rw,nosuid shared:9 - bpf bpf rw,mode=700
              ↑                               ↑
              mount_point (fields[4])         fstype (after " - ")

The key insight from libmount (util-linux) is that the separator " - " must be found using string search, not by assuming a fixed field position. This is because optional fields (like "shared:N" for mount propagation) may be present between the mount options and the separator.

func Mount

func Mount(mountPoint string) error

Mount mounts a bpffs at mountPoint, creating the directory if needed.

func Unmount

func Unmount(mountPoint string) error

Unmount unmounts the bpffs at mountPoint.

Types

This section is empty.

Jump to

Keyboard shortcuts

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