sysfs

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2026 License: MIT Imports: 6 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package sysfs reads system metadata with bounded reusable buffers.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Bytes

func Bytes(path string) ([]byte, error)

Bytes reads a file and returns an owned copy of its contents.

func DirNames

func DirNames(path string) ([]string, error)

DirNames lists the entry names of a directory. It uses Readdirnames so the kernel is never asked to stat entries the caller may not care about.

func Each

func Each(data []byte, visit func(key, value string) bool)

Each walks a KEY=VALUE file, calling visit for every pair. Returning false from visit stops the walk. Blank lines and # comments are skipped, and matching surrounding quotes are stripped from values.

func Field

func Field(data []byte, key string) string

Field returns the value of key in a KEY=VALUE file, or "" when it is absent. Nothing is allocated until the key matches.

func IsSocket

func IsSocket(path string) bool

IsSocket reports whether path exists and is a unix socket. This is the cheapest possible "is there a display server here" check.

func LinkBase

func LinkBase(path string) string

LinkBase reads a symlink and returns the last element of its target. Sysfs uses this shape everywhere: /sys/class/drm/card0/device points at ../../../0000:00:02.0, whose base is the PCI address.

func Path

func Path(root, path string) string

Path resolves a system path under root. An empty root reads the current system.

func String

func String(path string) (string, error)

String reads a small file and returns its contents with surrounding whitespace removed. Its scratch buffer belongs to this read.

func Trimmed

func Trimmed(path string) string

Trimmed is String with the error discarded. An unreadable file yields "", which is what every caller in this library wants: an absent sysfs attribute is missing information, not a failure.

Types

This section is empty.

Jump to

Keyboard shortcuts

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