summaryrefslogtreecommitdiffstats
path: root/lib/sysfs.c
Commit message (Collapse)AuthorAgeFilesLines
* lib/fileutils: add xreaddir()Karel Zak2019-04-111-15/+0Star
| | | | | | | Remove duplicate code and keep only one implementation in include/fileutils.h. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add function to detect partitioned devicesKarel Zak2018-12-071-0/+14
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: cleanup function namesKarel Zak2018-06-211-4/+3Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: fix sysfs_blkdev_get_wholedisk()Karel Zak2018-06-211-1/+3
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add sysfs_blkdev_get_parent()Karel Zak2018-06-211-0/+6
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: make possible to call sysfs_blkdev_deinit_path() in loopKarel Zak2018-06-211-8/+16
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/path lib/sysfs: add debugKarel Zak2018-06-211-1/+37
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add ul_new_sysfs_path() shortcutKarel Zak2018-06-211-20/+33
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: new implementationKarel Zak2018-06-211-529/+443Star
| | | | | | | | | * reuse ul_path_* API * allow to use prefix for sysfs paths, so we can use snapshots from sysfs for regression tests Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: ignore private Stratis devicesTony Asleson2018-03-091-9/+15
| | | | | | | | [kzak@redhat.com: - tiny coding style changes] References: 20e1c3dc03399d6988ef35dedc1364cfc12e9263 Signed-off-by: Tony Asleson <tasleson@redhat.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lsblk: try device/dev to read devnoKarel Zak2018-02-091-43/+54
| | | | | | | | | Now sysfs_devname_to_devno() reads devno from /dev or /sys/block/<name>/dev, but it seems that NVME uses /sys/block/<name>/device/dev. Reported-by: Potnuri Bharat Teja <bharat@chelsio.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* libblkid: don't use CDROM_GET_CAPABILITY ioctl for DM devicesKarel Zak2017-07-121-7/+11
| | | | | | | | | For some reason kernel commit e980f62353c697cbf0c4325e43df6e44399aeb64 add extra warning when the ioctl is used for DM devices. It seems we can avoid this ioctl when the device has dm/uuid. Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1469532 Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: fix gcc-7 snprintf warnings -Wformat-truncationRuediger Meier2017-06-141-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | ../lib/loopdev.c: In function 'loopcxt_next_from_sysfs': ../lib/loopdev.c:545:32: warning: '/loop/backing_file' directive output may be truncated writing 18 bytes into a region of size between 1 and 256 [-Wformat-truncation=] snprintf(name, sizeof(name), "%s/loop/backing_file", d->d_name); ^~~~~~~~~~~~~~~~~~~~~~ ../lib/loopdev.c:545:3: note: 'snprintf' output between 19 and 274 bytes into a destination of size 256 snprintf(name, sizeof(name), "%s/loop/backing_file", d->d_name); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/sysfs.c: In function 'sysfs_is_partition_dirent': ../lib/sysfs.c:343:31: warning: '/start' directive output may be truncated writing 6 bytes into a region of size between 1 and 256 [-Wformat-truncation=] snprintf(path, sizeof(path), "%s/start", d->d_name); ^~~~~~~~~~ ../lib/sysfs.c:343:2: note: 'snprintf' output between 7 and 262 bytes into a destination of size 256 snprintf(path, sizeof(path), "%s/start", d->d_name); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/sysfs.c: In function 'sysfs_partno_to_devno': ../lib/sysfs.c:372:32: warning: '/partition' directive output may be truncated writing 10 bytes into a region of size between 1 and 256 [-Wformat-truncation=] snprintf(path, sizeof(path), "%s/partition", d->d_name); ^~~~~~~~~~~~~~ ../lib/sysfs.c:372:3: note: 'snprintf' output between 11 and 266 bytes into a destination of size 256 snprintf(path, sizeof(path), "%s/partition", d->d_name); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../lib/sysfs.c:377:33: warning: '/dev' directive output may be truncated writing 4 bytes into a region of size between 1 and 256 [-Wformat-truncation=] snprintf(path, sizeof(path), "%s/dev", d->d_name); ^~~~~~~~ ../lib/sysfs.c:377:4: note: 'snprintf' output between 5 and 260 bytes into a destination of size 256 snprintf(path, sizeof(path), "%s/dev", d->d_name); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* docs: Fix word repetitionsYuri Chornoivan2017-02-131-1/+1
|
* lib: use unique ifdefs for testsKarel Zak2017-01-041-1/+1
| | | | | | | Let's use unique TEST_PROGRAM_<NAME> ifdefs to make build system more robust. Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: simplify if clauses [oclint]Sami Kerola2016-07-211-4/+2Star
| | | | Signed-off-by: Sami Kerola <kerolasa@iki.fi>
* lib/sysfs: be more smart for non-scsi devicesKarel Zak2016-06-021-1/+4
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: Fix various typosSebastian Rasmussen2016-05-311-3/+3
| | | | | | | Fix various typos in error messages, warnings, debug strings, comments and names of static functions. Signed-off-by: Sebastian Rasmussen <sebras@gmail.com>
* Revert "include sysmacros.h where used"Karel Zak2016-03-081-1/+0Star
| | | | This reverts commit 46a40c018438b7b2b25083a5e5a4a21055a0c1e9.
* include sysmacros.h where usedMike Frysinger2016-03-081-0/+1
| | | | | | | | BSD/Linux systems stick major/minor/makedev in sysmacros.h. Newer Linux libraries have been moving away from including sysmacros.h implicitly via sys/types.h, so include it directly. Signed-off-by: Mike Frysinger <vapier@gentoo.org>
* lib: remove openat fallback functions (include/at.h)Ruediger Meier2016-03-071-7/+8
| | | | | | | | | | | | | | I have validated that we are still compatible at least back to - openSUSE 11.4 - SLE 11 - RHEL/CentOS 6 - OSX 10.10.x, (Xcode 6.3) - FreeBSD 10.2 Confirmed incompatibility: - OSX 10.9.x, (Xcode 6.2) Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* misc: safer (and uniform) handling of return valueYuriy M. Kaminskiy2016-03-071-6/+6
| | | | | | When `rc` is `INT_MAX`, `rc + 1` result in signed integer overflow. Signed-off-by: Karel Zak <kzak@redhat.com>
* lsns.c: fix error returnYuriy M. Kaminskiy2016-03-071-1/+1
| | | | | | | If non-negative value returned, errno could be unset (especially 0). Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: fix some printf format stringsRuediger Meier2016-02-111-1/+1
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Fix the warnings below for OSX clang and add a few more casts for timeval: lib/at.c:131:27: warning: format specifies type 'intmax_t' (aka 'long') but the argument has type 'off_t' (aka 'long long') [-Wformat] printf("%16jd bytes ", st.st_size); ~~~~~ ^~~~~~~~~~ lib/strutils.c:522:52: warning: format specifies type 'intmax_t' (aka 'long') but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat] snprintf(buf, sizeof(buf), "%d%s%jd%s", dec, dp, frac, suffix); ~~~ ^~~~ lib/sysfs.c:468:42: warning: format specifies type 'uintmax_t' (aka 'unsigned long') but the argument has type 'uint64_t' (aka 'unsigned long long') [-Wformat] len = snprintf(buf, sizeof(buf), "%ju", num); ~~~ ^~~ libuuid/src/gen_uuid.c:316:34: warning: format specifies type 'unsigned long' but the argument has type '__darwin_suseconds_t' (aka 'int') [-Wformat] clock_seq, last.tv_sec, last.tv_usec, adjustment); ^~~~~~~~~~~~ Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* include: add missing includesRuediger Meier2016-02-111-0/+1
| | | | | | | | lib/pager.c: signal.h ... raise(3p) lib/sysfs.c: libgen.h ... basename(3p) lib/exec_shell.c: libgen.h ... basename(3p) Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
* lib/sysfs: make sysfs_get_devname()/blkid_devno_to_wholedisk() more robustKarel Zak2015-10-301-23/+25
| | | | | | | | | | Now the function uses result buffer for internal stuff (readlink), so it requires that the buffer is large enough. This is unexpected as caller assumes that the buffer has to be large enough for devname only. References: http://www.spinics.net/lists/util-linux-ng/msg12015.html Reported-by: Tom Yan <tom.ty89@gmail.com> Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: make sysfs_next_subsystem() more robustKarel Zak2015-08-311-0/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: Use dup_fd_cloexec instead of direct call to fcntlGuillem Jover2015-06-081-1/+1
| | | | Signed-off-by: Guillem Jover <guillem@hadrons.org>
* lsblk: use internally sysfs devnamesKarel Zak2015-05-291-2/+4
| | | | | | | It seems better to keep the strange sysfs devnames internally and translate to real devnames only on output or when we read from /dev. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: rename devname functions, cleanupKarel Zak2015-05-281-9/+25
| | | | | | | | | | | | | | | | | | Well, I don't have mental power to use function names like sysfs_devname_to_dev_name() so this patch renames to sysfs_devname_sys_to_dev() sysfs_devname_dev_to_sys() It also cleanups usage of the functions. We have to be sure that sysfs.c code returns regular devnames. The existence of the sysfs devnames (with '!') should be completely hidden in sysfs specific code. Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: Fix /dev to /sys node name translationStanislav Brabec2015-05-281-2/+6
| | | | | | | | | | | | | | | d0dc6c1 introduced translation of /sys names to /dev names, as required by the kernel linux/drivers/base/core.c: device_get_devnode(). But there are other places of code that use /dev names in /sys. They need reverse translation from '/' to '!'. For example, fdisk -l returns empty list since a22c6eb for device nodes in subdirectories (used e. g. by cciss driver). Introduce yet another helper sysfs_dev_name_to_devname() and use it where appropriate. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* Fix /sys to /dev node name translationStanislav Brabec2015-05-261-0/+2
| | | | | | | | | | | | | | linux/drivers/base/core.c: device_get_devnode() defines a translation of '!' in sysfs nodes to '/' in /dev nodes. The same translation has to be done to properly support device nodes with slash (e. g. device nodes of cciss driver and several other drivers). Introduce new helper sysfs_devname_to_devno() and use it where appropriate. Fixes for example lsblk -f on devices using cciss driver. Signed-off-by: Stanislav Brabec <sbrabec@suse.cz>
* lib/strv: add new functions (from systemd)Karel Zak2015-05-151-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs.c: use fcntl(..F_DUPFD_CLOEXEC) instead of dup(2)Cristian Rodríguez2015-04-141-1/+1
| | | | | "The two descriptors do not share file descriptor flags (the close-on-exec flag). The close-on-exec flag for the duplicate descriptor is off"
* lib/sysfs: use ssize_t for sysfs_readlink() [coverity scan]Karel Zak2015-01-281-4/+3Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add subsystem and hotplug detectionKarel Zak2014-12-021-1/+152
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: allow to write to sysfs attributesKarel Zak2014-08-011-6/+42
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: fix compiler warning [-Wunused-variable]Karel Zak2014-06-181-1/+0Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add sysfs_devno_is_wholedisk()Karel Zak2014-06-171-0/+18
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add sysfs_devno_is_lvm_private() from libblkidKarel Zak2014-06-171-0/+28
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/fileutils: add stripoff_last_component() from libmountKarel Zak2014-06-091-11/+1Star
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: make dirent d_type usage more robustKarel Zak2014-03-041-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: fix scanf format string [coverity scan]Karel Zak2014-01-141-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib: use O_CLOEXEC in libcommonKarel Zak2013-04-031-6/+7
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lsblk: fix hctl buffer usage [coverity scan]Karel Zak2013-03-271-1/+2
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include: cleanup copyright headersKarel Zak2013-01-081-2/+4
| | | | | | | We use the code from include/ and lib/ on many places, so use public domain if possible or LGPL for code copied from libs. Signed-off-by: Karel Zak <kzak@redhat.com>
* misc: make readlink() usage more robustKarel Zak2012-10-231-1/+1
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add SCSI link functionsKarel Zak2012-10-231-2/+50
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* lib/sysfs: add functions for SCSI host attributesKarel Zak2012-10-231-0/+52
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>
* include/sysfs: add SCSI host:channel:target:lun supportKarel Zak2012-10-231-3/+39
| | | | Signed-off-by: Karel Zak <kzak@redhat.com>