]> git.ipfire.org Git - thirdparty/util-linux.git/commit
lib/path: new implementation
authorKarel Zak <kzak@redhat.com>
Wed, 9 May 2018 13:54:12 +0000 (15:54 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 21 Jun 2018 09:58:10 +0000 (11:58 +0200)
commit1ed21c80ed3683c17708caad3d545da4d8e09b02
tree6a37d3f03c6c9e5031aa04d4554cebb6ef318e32
parent1b06b33dd0119fdae00fcc59f530200f6bdb0195
lib/path: new implementation

The goal is to avoid duplicate code in path.c and sysfs.c and make it
possible to define prefix for paths for all sysfs and procfs based
utils. Now we have /proc snapshots (for tests) for lscpu only. It
would be nice to have the same (for sysfs) for lsblk and another tools.

* very simple API to read numbers, strings and symlinks

* based on openat()

     pc = ul_new_path("/sys/block/sda");
     ul_path_read_u64(pc, &size, "size");
     ul_path_read_u64(pc, &lsz, "queue/logical_block_size");

* printf-like API to generate paths, for example:

     ul_path_readf_u64(pc, &num, "sda%d/size", partno)

* allow to define prefix to redirect hardcoded paths to another
  location, for example:

     pc = ul_new_path("/sys/block/sda");
     ul_path_set_prefix(pc, "/my/regression/dump");
     ul_path_read_u64(pc, &num, "size");

  to read /my/regression/dump/sys/block/sda/size

* allow to extend the API by "dialects", for example for sysfs:

     pc = ul_new_path(NULL);
     sysfs_blkdev_init_path(pc, devno, NULL);

  and use ul_path_* functions to read from @pc initialized by
  sysfs_blkdev_init_path()

* add test_path binary

Signed-off-by: Karel Zak <kzak@redhat.com>
include/path.h
lib/Makemodule.am
lib/path.c