blkinfo

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2019 License: MIT Imports: 5 Imported by: 0

README

Build Status Go Report Card GoDoc GolangCI

blkinfo

A Linux Block Device Info Library

Installation

$ wget https://github.com/blp1526/blkinfo/releases/latest/download/blkinfo_linux_x86_64.tar.gz
$ tar zxvf blkinfo_linux_x86_64.tar.gz

Usage

$ blkinfo /dev/vda3
{
  "path": "/dev/vda3",
  "resolved_path": "/dev/vda3",
  "parent_path": "/dev/vda",
  "child_paths": [],
  "sys_path": "/sys/block/vda/vda3",
  "resolved_sys_path": "/sys/devices/pci0000:00/0000:00:05.0/virtio2/block/vda/vda3",
  "sys": {
    "uevent": [
      "MAJOR=252",
      "MINOR=3",
      "DEVNAME=vda3",
      "DEVTYPE=partition",
      "PARTN=3"
    ],
    "slaves": [],
    "holders": []
  },
  "major_minor": "252:3",
  "udev_data_path": "/run/udev/data/b252:3",
  "udev_data": [
    "S:disk/by-uuid/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "S:disk/by-partuuid/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "S:disk/by-path/virtio-pci-0000:00:05.0-part3",
    "S:disk/by-path/pci-0000:00:05.0-part3",
    "W:4",
    "I:1583813",
    "E:ID_SCSI=1",
    "E:ID_PART_TABLE_TYPE=gpt",
    "E:ID_PART_TABLE_UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "E:ID_PATH=pci-0000:00:05.0",
    "E:ID_PATH_TAG=pci-0000_00_05_0",
    "E:ID_FS_UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "E:ID_FS_UUID_ENC=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "E:ID_FS_VERSION=1.0",
    "E:ID_FS_TYPE=ext4",
    "E:ID_FS_USAGE=filesystem",
    "E:ID_PART_ENTRY_SCHEME=gpt",
    "E:ID_PART_ENTRY_UUID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "E:ID_PART_ENTRY_TYPE=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "E:ID_PART_ENTRY_NUMBER=3",
    "E:ID_PART_ENTRY_OFFSET=8392704",
    "E:ID_PART_ENTRY_SIZE=33548288",
    "E:ID_PART_ENTRY_DISK=252:0",
    "E:net.ifnames=0",
    "G:systemd"
  ],
  "mount_info_path": "/proc/self/mountinfo",
  "mount_info": {
    "mount_id": "28",
    "parent_id": "0",
    "major_minor": "252:3",
    "root": "/",
    "mount_point": "/",
    "mount_options": [
      "rw",
      "relatime"
    ],
    "optional_fields": [
      "shared:1"
    ],
    "filesystem_type": "ext4",
    "mount_source": "/dev/vda3",
    "super_options": [
      "rw",
      "errors=remount-ro",
      "data=ordered"
    ]
  },
  "os_release_path": "/etc/os-release",
  "os_release": {
    "BUG_REPORT_URL": "https://bugs.launchpad.net/ubuntu/",
    "HOME_URL": "https://www.ubuntu.com/",
    "ID": "ubuntu",
    "ID_LIKE": "debian",
    "NAME": "Ubuntu",
    "PRETTY_NAME": "Ubuntu 18.04.3 LTS",
    "PRIVACY_POLICY_URL": "https://www.ubuntu.com/legal/terms-and-policies/privacy-policy",
    "SUPPORT_URL": "https://help.ubuntu.com/",
    "UBUNTU_CODENAME": "bionic",
    "VERSION": "18.04.3 LTS (Bionic Beaver)",
    "VERSION_CODENAME": "bionic",
    "VERSION_ID": "18.04"
  }
}
Options
Option Description
--help, -h show help
--output value, -o value output as "json" or "yaml" (default: "json")
--version, -v print the version

Package

package main

import (
	"encoding/json"
	"fmt"

	"github.com/blp1526/blkinfo"
)

func main() {
	bi, _ := blkinfo.New("/dev/vda3")
	b, _ := json.Marshal(bi)
	fmt.Println(string(b))
}

Build

$ make

Documentation

Overview

Package blkinfo implements methods for block device information.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuiltAt

func BuiltAt() string

BuiltAt returns builtAt.

func Revision

func Revision() string

Revision returns revision.

func Version

func Version() string

Version returns version.

Types

type BlkInfo

type BlkInfo struct {
	Path             string            `json:"path"             `
	ResolvedPath     string            `json:"resolved_path"    `
	ParentPath       string            `json:"parent_path"      `
	ChildPaths       []string          `json:"child_paths"      `
	SysPath          string            `json:"sys_path"         `
	ResolevedSysPath string            `json:"resolved_sys_path"`
	Sys              *Sys              `json:"sys"              `
	MajorMinor       string            `json:"major_minor"      `
	UdevDataPath     string            `json:"udev_data_path"   `
	UdevData         []string          `json:"udev_data"        `
	MountInfoPath    string            `json:"mount_info_path"  `
	MountInfo        *MountInfo        `json:"mount_info"       `
	OSReleasePath    string            `json:"os_release_path"  `
	OSRelease        map[string]string `json:"os_release"       `
}

BlkInfo shows block device information.

func New

func New(path string) (*BlkInfo, error)

New initializes *BlkInfo.

type MountInfo

type MountInfo struct {
	// See https://github.com/torvalds/linux/blob/d8372ba8ce288acdfce67cb873b2a741785c2e88/Documentation/filesystems/proc.txt#L1711
	MountID        string   `json:"mount_id"       `
	ParentID       string   `json:"parent_id"      `
	MajorMinor     string   `json:"major_minor"    `
	Root           string   `json:"root"           `
	MountPoint     string   `json:"mount_point"    `
	MountOptions   []string `json:"mount_options"  `
	OptionalFields []string `json:"optional_fields"`
	FilesystemType string   `json:"filesystem_type"`
	MountSource    string   `json:"mount_source"   `
	SuperOptions   []string `json:"super_options"  `
}

MountInfo shows mount information.

type Sys

type Sys struct {
	// See https://github.com/torvalds/linux/blob/d13937116f1e82bf508a6325111b322c30c85eb9/fs/block_dev.c#L1229-L1242
	// /sys/block/dm-0/slaves/sda  --> /sys/block/sda
	// /sys/block/sda/holders/dm-0 --> /sys/block/dm-0
	Uevent  []string `json:"uevent" `
	Slaves  []string `json:"slaves" `
	Holders []string `json:"holders"`
}

Sys shows sys information.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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