Friday, June 20, 2014

new cfdisk (util-linux v2.25)

cfdisk is a popular ncurses partitioning tool. Unfortunately, it has been ignored by developers for many many years. The original version does not a have clue
about 4K disks, modern disk I/O limits (alignment offset, optimal I/O sizes, etc),
and it was all about MBR (DOS) only.

It was impossible to improve the old code by refactoring, so the new version is written from scratch. The new cfdisk is based on on the same code like fdisk, so it shares all the necessary features required for new disks and it supports MBR, GPT, SGI and SUN disk labels. Some features have been removed:
  • it does not have a clue about CHS addressing any more
  • it's impossible to play any games with disk geometry (use fdisk if you believe that CHS setting makes any sense)
  • 'm' command (maximize disk usage of the current partition) is not implemented
  • 'p' command and --print command line option are not implemented (use partx or lsblk)
  •  'u' (units) command is not implemented, all is based on sectors or real sizes
The idea is to keep cfdisk pretty simple and easy to use for end users. Advanced users or users who want to do some unusual things have to use fdisk or parted.

New features:
  • output formatting based on libsmartcols
  • tree-like output for MBR extended and logical partitions
  • show free space on place where the gap is really located
  • colors
  • new 's'ort command to reorder partition according to start sectors
  • partitions aligned to I/O limits, 1MiB start offset, etc.
  • it's still possible to recompile with slang library (although I personallyprefer ncursesw)

For full size screenshots see g+

What next? sfdisk and stable public API fro libfdisk... let's wait for v2.26 :-)




Friday, May 30, 2014

libsmartcols - pretty output for everyone!

util-linux 2.25 is going to contain libsmartcols. The library code is based on code originally developed for lsblk(8), findmnt(8), lslocks(8) etc.  The goal is to share formatting code to print pretty tables and trees.

Features:
  • tree-like output (see lsblk(8) or findmnt(8))
  • table-like output (see lslocks(8))
  • formatting sensitive to terminal width
  • fully supports UTF8 (correctly truncate data in cells, tree lines, ...)
  • dynamic or fixed columns width
  • truncate data in cell on demand
  • raw (no formatting) output mode
  • NAME=value output mode
  • custom cells and lines delimiters (for example for CSV output)
  • built-in ASCII, UTF8 or custom symbols to draw trees
  • per column, line or cell colors
  • colors specified by words (e.g. "red") or ESC sequences
  • sort lines
  • enable/disable heading
  • output to FILE stream (default stdout), or to string
  • all columns, lines and cells accessible by iterators (no callbacks)
  • output data specified by strings (no crazy unions or to-string conversion functions in the library)
  • reference counting
  • integrated debug output (sensitive to LIBSMARTCOLS_DEBUG env)
  • usable to keep parent<->child relationship
  • library symbols versioning (no soname changes)

See bellow a trivial (so no errors handling, etc.) example.

int main(void)
{
        struct libscols_table *tb;
        struct libscols_line *ln, *dad, *gdad;
        enum { COL_NAME, COL_AGE };

        setlocale(LC_ALL, "");

        tb = scols_new_table();
        scols_table_new_column(tb, "NAME", 0.1, SCOLS_FL_TREE);
        scols_table_new_column(tb, "AGE",     2, SCOLS_FL_RIGHT);

        ln = gdad = scols_table_new_line(tb, NULL);
        scols_line_set_data(ln, COL_NAME, "Grandfather Bob");
        scols_line_set_data(ln, COL_AGE, "61");

        ln = dad = scols_table_new_line(tb, ln);
        scols_line_set_data(ln, COL_NAME, "Father Adam");
        scols_line_set_data(ln, COL_AGE, "38");

        ln = scols_table_new_line(tb, dad);
        scols_line_set_data(ln, COL_NAME, "Baby Val");
        scols_line_set_data(ln, COL_AGE, "9");

        ln = scols_table_new_line(tb, dad);
        scols_line_set_data(ln, COL_NAME, "Baby Dilbert");
        scols_line_set_data(ln, COL_AGE, "5");

        ln = scols_table_new_line(tb, gdad);
        scols_line_set_data(ln, COL_NAME, "Aunt Gaga");
        scols_line_set_data(ln, COL_AGE, "35");

        scols_print_table(tb);
        scols_unref_table(tb);
        return 0;
}

... and output:

NAME             AGE
Grandfather Bob   61
├─Father Adam     38
│ ├─Baby Val       9
│ └─Baby Dilbert   5
└─Aunt Gaga       35 

Tuesday, April 1, 2014

terminal-colors.d

I have already talked about it at g+. For util-linux we don't want to follow the current strange behavior when command-line utils have disabled colors by default, but distributions use shell aliases in profile files to revert the default.

It does not mean that we want ignore color blind people, obscure terminals or people who just don't like colors. The solution is to provide simple, elegant and package independent way how to control (disable) colorized output. And yes, aliases are not elegant.

The next util-linux release is going to introduce /etc/terminal-colors.d directory
to control colors for terminal utils. It's pretty simple:

Synopsis:
/etc/terminal-colors.d/[name.]disable
/etc/terminal-colors.d/name.enable
Examples:
  •  disable colors for all utils:
    # touch /etc/terminal-colors.d/disable 
    
  • disable colors for dmesg(1):
    # touch /etc/terminal-colors.d/dmesg.disable
  • disable colors for all utils except dmesg(1):
    # touch /etc/terminal-colors.d/disable
    # touch /etc/terminal-colors.d/dmesg.enable
For utils from util-linux the command line option --color[={auto,never,always}] overrides the setting from terminal-colors.d (so if you for some reason love shell aliases then it's still possible...).

The terminal-colors.d concept is completely open, it would be nice to see it supported in another projects (hint: gcc, grep, coreutils:-) too. It's so trivial that all you need is a few access(F_OK) calls. The thing we maintain in util-linux is terminal-colors.d.5 man page only.

Maybe later for util-linux we will also use the directory (or/and copy in $HOME) to store color schemes.

Keep your Bike-sheds colorized! :-)

Wednesday, February 5, 2014

stable mutt-kz 1.5.22.1

The first official mutt-kz release with tarballs is available now. If you have no idea about mutt-kz: it is mutt fork with virtual folders, tags and fulltext search (based on notmuch), supports INBOX->archive use case, integrated index-color and sidebar patches. All changes to the original mutt are backported to mutt-kz.

I'm really happy that there is a community around the project with testers and contributors. The mutt-kz mailing list has 80 members now. Thanks!

Features:

  • virtual folder (based on notmuch queries) - defined in .muttrc
  • virtual folders on-the-fly generated from queries
  • command to see entire thread for specific message (including already archived messages or messages excluded from the current virtual folder)
  • UI to modify notmuch labels 
  • labels transformation to special chars (e.g. funny unicode text icons) in mutt index
  • new %g and %Gx mutt index and pager format sequences to display notmuch labels 
  • special labels for sent emails 
  • really smart fulltext search (thanks to notmuch and Xapian), for example: "from:kzak tag:ul date:1year.." to search for my posts to util-linux (ul tag) mailing list in last year. 
  • nested if-else conditional and date format expressions (for index format)
  • new mutt pattern modifier for labels 
  • all implemented by regular mutt commands (no hacks) so usable in mutt hooks and macros 
  • you really don't have to delete messages, just move things to archive, notmuch is fast enough to work with large sets of messages 
  • sidebar to show mailboxes or virtual folders 
  • and more... 
my .muttrc: http://people.redhat.com/kzak/mutt-kz/muttrc

Tuesday, October 15, 2013

util-linux v2.24 - fdisk(8)

This release is mostly about small incremental changes, a small exception is fdisk(8).

I have finished fdisk(8) refactoring, this task we started with Davidlohr Bueso and Petr Uzel two releases ago. The result is a code that is easy to extend and all disklabel specific code is no more maintained together as a ball of spaghetti.

The goal is to have one library (libfdisk) shared between all the fdisks (sfdisk, cfdisk, ...). Now it's used in fdisk only. I hope that one day we're going to have shared library with a public stable API.

 The most visible changes:
  • fdisk dialogs and output unification, more verbose messages
  • colors for warnings
  • new (but backwardly compatible) menus
  • all operations for all disklabels based on sectors by default
  • man page clean up
  • improved GPT disklabel support (rename partition, partition and disk UUID modification)

    The last missing thing is support for manual modification of hybrid GPT. This is planned for the next release v2.25.

    My laptop with GPT:
# fdisk -l /dev/sda

Disk /dev/sda: 149.1 GiB, 160041885696 bytes, 312581808 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: gpt
Disk identifier: 3549290F-417C-4941-8503-F7835109B821

Device           Start          End   Size Type
/dev/sda1         2048      2050047  1000M EFI System
/dev/sda2      2050048      6146047     2G Microsoft basic data
/dev/sda3      6146048     26462207   9.7G Linux swap
/dev/sda4     26462208     98142207  34.2G Microsoft basic data
/dev/sda5     98142208    230662143  63.2G Microsoft basic data
/dev/sda6    230662144    312580095  39.1G Microsoft basic data
  • disklabel hex dump (command 'D')

    This is nice feature for advanced users. You don't have to fight with hexdump, search the right offsets etc. fdisk(8) will locate all relevant disklabel parts on the device and print all in hex format. (Don't forget that many things don't use static offsets -- for example GPT array with partitions, MBR extended partitions, etc).

  • For example (disk with two logical partitoins):
# echo -e 'x\nD\nq\n' | fdisk  /dev/sdb
 
Welcome to fdisk (util-linux 2.24.rc2-22-1d8c-dirty).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.
 
Command (m for help): 
Expert command (m for help): 
MBR: offset = 0, size = 512 bytes. 
00000000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
*
000001b0  00 00 00 00 00 00 00 00  14 92 2b 9e 00 00 00 20
000001c0  21 00 83 df 13 0c 00 08  00 00 00 20 03 00 00 df
000001d0  14 0c 05 7c 30 4c 00 28  03 00 00 98 0f 00 00 00
000001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
000001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa
 
EBR: offset = 105906176, size = 512 bytes.
06500000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
*
065001c0  34 0d 83 bf 26 19 00 08  00 00 00 20 03 00 00 bf
065001d0  27 19 05 9f 39 26 00 28  03 00 00 28 03 00 00 00
065001e0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
065001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa
 
EBR: offset = 211812352, size = 512 bytes.
0ca00000  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
*
0ca001b0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 e0
0ca001c0  08 19 83 9f 39 26 00 08  00 00 00 20 03 00 00 00
0ca001d0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 00 00
*
0ca001f0  00 00 00 00 00 00 00 00  00 00 00 00 00 00 55 aa

Thursday, August 22, 2013

libmount Python binding

This week I merged Python libmount binding into util-linux. The original prototype was from Ondrej Oprala (Thanks!).

The binding provides the same functionality as libmount in C -- for now supported objects are:
  • Fs - filesystem description
  • Table - tab files parser and container for filesystems
  • Context - high-level API to mount/umount.   

Examples:
$ python                                                        
>>> import libmount                                             
>>> tb = libmount.Table('/proc/self/mountinfo')                 
>>> fs = tb.find_target('/home/kzak')                           
>>> print fs.source                                             
/dev/mapper/luks-10d813de-fa82-4f67-a86c-23d5d0e7c30e  
 
# python                                                        
>>> import libmount                                             
>>> cx = libmount.Context()                                     
>>> cx.target = '/mnt/backup'                                   
>>> cx.mount()                                                   
>>> fs = cx.mtab.find_target('/mnt/backup')                     
>>> print fs.fstype
nfs4
# python -c "import libmount; libmount.Context(target='/mnt/backup').umount()"

The side effect of the work on the Python binding is that libmount uses reference counting for libmnt_{fs,table,cache} objects now. So we're ready for more complicated scenarios.

.. and --without-python if you don't like it ;-)

Monday, April 29, 2013

dmesg -H is sexy

dmesg(1) from util-linux 2.23 provides some small usability improvements and all the improvements is possible to enable by -H,--human command line option.
  • enable pager (you know this for example from 'git log')
  • enable relative timestamps to display local time and delta in human readable format
  • enable colors for timestamp prefix, subsystem prefix and message body (different colors for different log levels)
dmesg -H util-linux 2.23

Hint: add

    alias dmesg="dmesg --human" 

somewhere to your /etc/profile.d/ directory.