Skip to content

Commit

Permalink
List inode information instead of block usage with --inodes
Browse files Browse the repository at this point in the history
Fixes muesli#6.
  • Loading branch information
muesli committed Sep 24, 2020
1 parent 158ed59 commit 262f21d
Show file tree
Hide file tree
Showing 6 changed files with 104 additions and 67 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,18 @@ You can simply start duf without any command-line arguments:

duf

If you want to see all devices:
If you want to list everything (including pseudo, duplicate, inaccessible file systems):

duf --all

You can hide individual tables:

duf --hide-local --hide-network --hide-fuse --hide-special --hide-loops --hide-binds

List inode information instead of block usage:

duf --inodes

Sort the output:

# valid sort-keys are: mountpoint, size, used, avail, usage, type, filesystem
Expand Down
14 changes: 7 additions & 7 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,18 @@ import (
var (
term = termenv.ColorProfile()

all = flag.Bool("all", false, "show all devices")

all = flag.Bool("all", false, "include pseudo, duplicate, inaccessible file systems")
hideLocal = flag.Bool("hide-local", false, "hide local devices")
hideNetwork = flag.Bool("hide-network", false, "hide network devices")
hideFuse = flag.Bool("hide-fuse", false, "hide fuse devices")
hideSpecial = flag.Bool("hide-special", false, "hide special devices")
hideLoops = flag.Bool("hide-loops", true, "hide loop devices")
hideBinds = flag.Bool("hide-binds", true, "hide bind mounts")

sortBy = flag.String("sort", "mountpoint", "sort output by key (mountpoint, size, used, avail, usage, type, filesystem)")
sortBy = flag.String("sort", "mountpoint", "sort output by: mountpoint, size, used, avail, usage, type, filesystem")
width = flag.Uint("width", 0, "max output width")

inodes = flag.Bool("inodes", false, "list inode information instead of block usage")
jsonOutput = flag.Bool("json", false, "output all devices in JSON format")
)

Expand Down Expand Up @@ -73,16 +73,16 @@ func renderTables(m []Mount, sortCol int) {

// print tables
if !*hideLocal || *all {
printTable("local", local, sortCol)
printTable("local", local, sortCol, *inodes)
}
if !*hideNetwork || *all {
printTable("network", network, sortCol)
printTable("network", network, sortCol, *inodes)
}
if !*hideFuse || *all {
printTable("FUSE", fuse, sortCol)
printTable("FUSE", fuse, sortCol, *inodes)
}
if !*hideSpecial || *all {
printTable("special", special, sortCol)
printTable("special", special, sortCol, *inodes)
}
}

Expand Down
23 changes: 13 additions & 10 deletions mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,19 @@ import (
)

type Mount struct {
Device string `json:"device"`
DeviceType string `json:"device_type"`
Mountpoint string `json:"mount_point"`
Fstype string `json:"fs_type"`
Type string `json:"type"`
Opts string `json:"opts"`
Total uint64 `json:"total"`
Free uint64 `json:"free"`
Used uint64 `json:"used"`
Stat unix.Statfs_t `json:"-"`
Device string `json:"device"`
DeviceType string `json:"device_type"`
Mountpoint string `json:"mount_point"`
Fstype string `json:"fs_type"`
Type string `json:"type"`
Opts string `json:"opts"`
Total uint64 `json:"total"`
Free uint64 `json:"free"`
Used uint64 `json:"used"`
InodesTotal uint64 `json:"inodes_total"`
InodesFree uint64 `json:"inodes_free"`
InodesUsed uint64 `json:"inodes_used"`
Stat unix.Statfs_t `json:"-"`
}

func readLines(filename string) ([]string, error) {
Expand Down
21 changes: 12 additions & 9 deletions mounts_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,15 +67,18 @@ func mounts() ([]Mount, []string, error) {
}

d := Mount{
Device: device,
Mountpoint: mountPoint,
Fstype: fsType,
Type: fsType,
Opts: opts,
Stat: stat,
Total: (uint64(stat.Blocks) * uint64(stat.Bsize)),
Free: (uint64(stat.Bavail) * uint64(stat.Bsize)),
Used: (uint64(stat.Blocks) - uint64(stat.Bfree)) * uint64(stat.Bsize),
Device: device,
Mountpoint: mountPoint,
Fstype: fsType,
Type: fsType,
Opts: opts,
Stat: stat,
Total: (uint64(stat.Blocks) * uint64(stat.Bsize)),
Free: (uint64(stat.Bavail) * uint64(stat.Bsize)),
Used: (uint64(stat.Blocks) - uint64(stat.Bfree)) * uint64(stat.Bsize),
InodesTotal: stat.Files,
InodesFree: stat.Ffree,
InodesUsed: stat.Files - stat.Ffree,
}
d.DeviceType = deviceType(d)

Expand Down
21 changes: 12 additions & 9 deletions mounts_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,18 @@ func mounts() ([]Mount, []string, error) {
}

d := Mount{
Device: device,
Mountpoint: mountPoint,
Fstype: fstype,
Type: fsTypeMap[int64(stat.Type)],
Opts: mountOpts,
Stat: stat,
Total: (uint64(stat.Blocks) * uint64(stat.Bsize)),
Free: (uint64(stat.Bavail) * uint64(stat.Bsize)),
Used: (uint64(stat.Blocks) - uint64(stat.Bfree)) * uint64(stat.Bsize),
Device: device,
Mountpoint: mountPoint,
Fstype: fstype,
Type: fsTypeMap[int64(stat.Type)],
Opts: mountOpts,
Stat: stat,
Total: (uint64(stat.Blocks) * uint64(stat.Bsize)),
Free: (uint64(stat.Bavail) * uint64(stat.Bsize)),
Used: (uint64(stat.Blocks) - uint64(stat.Bfree)) * uint64(stat.Bsize),
InodesTotal: stat.Files,
InodesFree: stat.Ffree,
InodesUsed: stat.Files - stat.Ffree,
}
d.DeviceType = deviceType(d)

Expand Down
86 changes: 55 additions & 31 deletions table.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import (
)

var (
columns = table.Row{"Mounted on", "Size", "Used", "Avail", "Use%", "Type", "Filesystem"}

colorRed = term.Color("#E88388")
colorYellow = term.Color("#DBAB79")
colorGreen = term.Color("#A8CC8C")
Expand Down Expand Up @@ -52,17 +50,25 @@ func stringToColumn(s string) (int, error) {
case "mountpoint":
return 1, nil
case "size":
return 8, nil
return 12, nil
case "used":
return 9, nil
return 13, nil
case "avail":
return 10, nil
return 14, nil
case "usage":
return 11, nil
return 15, nil
case "inodes":
return 16, nil
case "inodes_used":
return 17, nil
case "inodes_avail":
return 18, nil
case "inodes_usage":
return 19, nil
case "type":
return 6, nil
return 10, nil
case "filesystem":
return 7, nil
return 11, nil

default:
return 0, fmt.Errorf("unknown column identifier: %s", s)
Expand Down Expand Up @@ -125,7 +131,7 @@ func barTransformer(val interface{}) string {
return s.String()
}

func printTable(title string, m []Mount, sortBy int) {
func printTable(title string, m []Mount, sortBy int, inodes bool) {
tab := table.NewWriter()
tab.SetAllowedRowLength(int(*width))
tab.SetOutputMirror(os.Stdout)
Expand Down Expand Up @@ -153,41 +159,59 @@ func printTable(title string, m []Mount, sortBy int) {

tab.SetColumnConfigs([]table.ColumnConfig{
{Number: 1, WidthMax: int(float64(cols) * 0.4)},
{Number: 2, Transformer: sizeTransformer, Align: text.AlignRight, AlignHeader: text.AlignRight},
{Number: 3, Transformer: sizeTransformer, Align: text.AlignRight, AlignHeader: text.AlignRight},
{Number: 4, Transformer: spaceTransformer, Align: text.AlignRight, AlignHeader: text.AlignRight},
{Number: 5, Transformer: barTransformer, AlignHeader: text.AlignCenter},
{Number: 6, WidthMax: int(float64(cols) * 0.2)},
{Number: 7, WidthMax: int(float64(cols) * 0.4)},
{Number: 8, Hidden: true}, // sortBy helper for size
{Number: 9, Hidden: true}, // sortBy helper for used
{Number: 10, Hidden: true}, // sortBy helper for avail
{Number: 11, Hidden: true}, // sortBy helper for usage
{Number: 2, Hidden: inodes, Transformer: sizeTransformer, Align: text.AlignRight, AlignHeader: text.AlignRight},
{Number: 3, Hidden: inodes, Transformer: sizeTransformer, Align: text.AlignRight, AlignHeader: text.AlignRight},
{Number: 4, Hidden: inodes, Transformer: spaceTransformer, Align: text.AlignRight, AlignHeader: text.AlignRight},
{Number: 5, Hidden: inodes, Transformer: barTransformer, AlignHeader: text.AlignCenter},
{Number: 6, Hidden: !inodes, Align: text.AlignRight, AlignHeader: text.AlignRight},
{Number: 7, Hidden: !inodes, Align: text.AlignRight, AlignHeader: text.AlignRight},
{Number: 8, Hidden: !inodes, Align: text.AlignRight, AlignHeader: text.AlignRight},
{Number: 9, Hidden: !inodes, Transformer: barTransformer, AlignHeader: text.AlignCenter},
{Number: 10, WidthMax: int(float64(cols) * 0.2)},
{Number: 11, WidthMax: int(float64(cols) * 0.4)},
{Number: 12, Hidden: true}, // sortBy helper for size
{Number: 13, Hidden: true}, // sortBy helper for used
{Number: 14, Hidden: true}, // sortBy helper for avail
{Number: 15, Hidden: true}, // sortBy helper for usage
{Number: 16, Hidden: true}, // sortBy helper for inodes size
{Number: 17, Hidden: true}, // sortBy helper for inodes used
{Number: 18, Hidden: true}, // sortBy helper for inodes avail
{Number: 19, Hidden: true}, // sortBy helper for inodes usage
})

tab.AppendHeader(columns)
tab.AppendHeader(table.Row{"Mounted on", "Size", "Used", "Avail", "Use%", "Inodes", "Used", "Avail", "Use%", "Type", "Filesystem"})

for _, v := range m {
// spew.Dump(v)

// render progress-bar
var usage float64
var usage, inodeUsage float64
if v.Total > 0 {
usage = float64(v.Used) / float64(v.Total)
}
if v.InodesTotal > 0 {
inodeUsage = float64(v.InodesUsed) / float64(v.InodesTotal)
}

tab.AppendRow([]interface{}{
termenv.String(v.Mountpoint).Foreground(colorBlue), // mounted on
v.Total, // size
v.Used, // used
v.Free, // avail
usage, // use%
v.Total, // size
v.Used, // used
v.Free, // avail
usage, // use%
v.InodesTotal, // size
v.InodesUsed, // used
v.InodesFree, // avail
inodeUsage, // use%
termenv.String(v.Fstype).Foreground(colorGray), // type
termenv.String(v.Device).Foreground(colorGray), // filesystem
v.Total, // size sorting helper
v.Used, // used sorting helper
v.Free, // avail sorting helper
usage, // use% sorting helper
v.Total, // size sorting helper
v.Used, // used sorting helper
v.Free, // avail sorting helper
usage, // use% sorting helper
v.InodesTotal, // size sorting helper
v.InodesUsed, // used sorting helper
v.InodesFree, // avail sorting helper
inodeUsage, // use% sorting helper
})
}

Expand All @@ -203,7 +227,7 @@ func printTable(title string, m []Mount, sortBy int) {

//tab.AppendFooter(table.Row{fmt.Sprintf("%d %s", tab.Length(), title)})
sortMode := table.Asc
if sortBy >= 8 && sortBy <= 11 {
if sortBy >= 12 {
sortMode = table.AscNumeric
}

Expand Down

0 comments on commit 262f21d

Please sign in to comment.