mountinfo

package module
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Mar 20, 2023 License: Apache-2.0 Imports: 4 Imported by: 11

README

mountinfo

The purpose of this library is to read the mountinfo file as a whole or as single lines in order to get information about the mount points of a specific process as described in man 5 proc.

API

  • ParseMountInfo(buffer io.Reader) ([]Mountinfo, error): ParseMountInfo parses the mountinfo content from an io.Reader, e.g a file
  • ParseMountInfoString(tx string) *Mountinfo: ParseMountInfoString transforms a mountinfo string in a struct of type Mountinfo
  • GetMountInfo(mountinfoPath string) ([]Mountinfo, error): GetMountInfo reads the mountinfo file and returns a slice of structs of type Mountinfo

Examples

Need more examples? find them in the godoc.

package main

import (
	"fmt"
	"log"

	"github.com/fntlnz/mountinfo"
)

func main() {
	minfo, err := mountinfo.GetMountInfo("/proc/self/mountinfo")
	if err != nil {
		log.Fatal("error getting mountinfo: %v", err)
	}
	fmt.Printf("Mountpoint: %s", minfo[0].MountPoint)
}

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Mountinfo

type Mountinfo struct {
	MountID        string
	ParentID       string
	MajorMinor     string
	Root           string
	MountPoint     string
	MountOptions   string
	OptionalFields string
	FilesystemType string
	MountSource    string
	SuperOptions   string
}

Mountinfo struct representing a mountinfo entry

func GetMountInfo

func GetMountInfo(mountinfoPath string) ([]Mountinfo, error)

GetMountInfo opens a mountinfo file, returns a slice of Mountinfo structs

Example
package main

import (
	"fmt"

	"github.com/fntlnz/mountinfo"
)

func main() {
	minfo, _ := mountinfo.GetMountInfo("/proc/self/mountinfo")
	fmt.Printf("Mountpoint: %s", minfo[0].MountPoint)
}
Output:

func ParseMountInfo

func ParseMountInfo(buffer io.Reader) ([]Mountinfo, error)

ParseMountInfo parses the mountinfo content from an io.Reader, e.g a file

Example
package main

import (
	"fmt"
	"strings"

	"github.com/fntlnz/mountinfo"
)

func main() {
	lines := `26 25 0:24 / /sys/fs/cgroup/systemd rw,nosuid,nodev,noexec,relatime shared:9 - cgroup cgroup rw,xattr,release_agent=/usr/lib/systemd/systemd-cgroups-agent,name=systemd
515 24 0:3 net:[4026533140] /run/docker/netns/f46c0b2da189 rw shared:188 - nsfs nsfs rw
	`
	buf := strings.NewReader(lines)
	minfo, _ := mountinfo.ParseMountInfo(buf)
	fmt.Printf("Mountpoint 0: %s\n", minfo[0].MountPoint)
	fmt.Printf("Mountpoint 1: %s\n", minfo[1].MountPoint)
	fmt.Printf("MountSource 1: %s", minfo[1].MountSource)

}
Output:

Mountpoint 0: /sys/fs/cgroup/systemd
Mountpoint 1: /run/docker/netns/f46c0b2da189
MountSource 1: nsfs

func ParseMountInfoString

func ParseMountInfoString(tx string) *Mountinfo

ParseMountInfoString transforms a mountinfo string in a struct of type Mountinfo

Jump to

Keyboard shortcuts

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