Version 1 of Filesystem Usage / Information: di Tcl extension

Updated 2016-01-22 20:07:09 by bll

The di program now provides a Tcl extension starting with version 4.39.

Website: http ://gentoo.com/di/

Author: bll

di is a highly portable program to display disk information. It features the ability to display the disk usage in the format you prefer.

With version 4.39, a Tcl extension is now available. It provides a 'diskspace' command that returns a dictionary with the filesystem information.

The dictionary returned is nested and keyed by the mount point. The dictionary keys are: device, fstype, total, free, available, totalinodes, freeinodes, availableinodes, mountoptions, display.

The total, free and available space are returned as bytes.

'display' is returned when the di format specifier is not empty. The data returned is a tab separated list of the display items (this may change in a future release).

Any of the di options may be used to change the data returned in the 'display' key. See the di manual page for the complete list.

Example usage:

# assuming the diskspace extension is in the same directory as your script...
set ext [info sharedlibextension]
set lfn [file normalize [file join [file dirname [info script]] diskspace$ext]]
load $lfn

set di [diskspace -f {} /] ; # get only the basic information for root filesystem
/ {device /dev/sda1 fstype ext4 total 485893496832 free 269818650624 available 245113102336 totalinodes 30138368 freeinodes 29762805 availableinodes 29762805 mountoptions rw,errors=remount-ro}

set di [diskspace -f {up} /] ; # also get the used space and percentage used.
/ {display {201.2G      50%} device /dev/sda1 fstype ext4 total 485893496832 free 269818736640 available 245113188352 totalinodes 30138368 freeinodes 29762805 availableinodes 29762805 mountoptions rw,errors=remount-ro}
lassign [split [dict get $di / display] "\t"] useddisplay percused

set di [diskspace -d 1 -f up /] ; # instead, get the used value in bytes.
/ {display {216074854400        50%} device /dev/sda1 fstype ext4 total 485893496832 free 269818642432 available 245113094144 totalinodes 30138368 freeinodes 29762805 availableinodes 29762805 mountoptions rw,errors=remount-ro}
lassign [split [dict get $di / display] "\t"] usedbytes percused

set di [diskspace -f {}] ; # get information on the usual list of filesystems.

To build the Tcl extension:

Most systems:

    cd C; make -e tcl-sh

Windows Cygwin:

    cd C; make CC=gcc NO_PIE=yes tcl-sh

Windows Msys:

    # I can't build Tcl with Msys, but the following command
    # line should work.
    cd C; mingw32-make -e MAKE=mingw32-make \
        _MKCONFIG_SHELL=bash WINAPI=T NO_PIE=yes CC=gcc tcl-sh