Commit graph

98 commits

Author SHA1 Message Date
Karel Zak
32c9ce4baf lib/sysfs: make sysfs_next_subsystem() more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-08-31 10:11:01 +02:00
Guillem Jover
fef6f84a15 lib/sysfs: Use dup_fd_cloexec instead of direct call to fcntl
Signed-off-by: Guillem Jover <guillem@hadrons.org>
2015-06-08 12:10:03 +02:00
Karel Zak
92441d5c1e lsblk: use internally sysfs devnames
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>
2015-05-29 10:55:01 +02:00
Karel Zak
6c62abc42b lib/sysfs: rename devname functions, cleanup
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>
2015-05-28 12:09:41 +02:00
Stanislav Brabec
759b120d85 lib/sysfs: Fix /dev to /sys node name translation
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>
2015-05-28 10:27:20 +02:00
Stanislav Brabec
d0dc6c17c5 Fix /sys to /dev node name translation
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>
2015-05-26 11:42:38 +02:00
Karel Zak
548b9714e8 lib/strv: add new functions (from systemd)
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-05-15 14:57:04 +02:00
Cristian Rodríguez
d1f9c0969e lib/sysfs.c: use fcntl(..F_DUPFD_CLOEXEC) instead of dup(2)
"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"
2015-04-14 11:38:02 +02:00
Karel Zak
e8b150e9ba lib/sysfs: use ssize_t for sysfs_readlink() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2015-01-28 14:55:20 +01:00
Karel Zak
e017ef8bb9 lib/sysfs: add subsystem and hotplug detection
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-12-02 10:59:48 +01:00
Karel Zak
6c987ca9d7 lib/sysfs: allow to write to sysfs attributes
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-08-01 12:08:44 +02:00
Karel Zak
e99b64e7fa lib/sysfs: fix compiler warning [-Wunused-variable]
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-18 11:25:47 +02:00
Karel Zak
b55e5886ea lib/sysfs: add sysfs_devno_is_wholedisk()
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-17 12:15:01 +02:00
Karel Zak
39866431ee lib/sysfs: add sysfs_devno_is_lvm_private() from libblkid
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-17 11:20:32 +02:00
Karel Zak
d4eaabc86a lib/fileutils: add stripoff_last_component() from libmount
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-06-09 11:54:32 +02:00
Karel Zak
ea7f012b7c lib/sysfs: make dirent d_type usage more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-03-04 11:30:03 +01:00
Karel Zak
a6d85ee0a1 lib/sysfs: fix scanf format string [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2014-01-14 18:02:06 +01:00
Karel Zak
b1fa3e2234 lib: use O_CLOEXEC in libcommon
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-04-03 16:13:06 +02:00
Karel Zak
88a6006bc8 lsblk: fix hctl buffer usage [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2013-03-27 14:18:22 +01:00
Karel Zak
0f23ee0c85 include: cleanup copyright headers
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>
2013-01-08 15:10:17 +01:00
Karel Zak
9f51089e7f misc: make readlink() usage more robust
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-23 12:40:39 +02:00
Karel Zak
a5dc4d2d95 lib/sysfs: add SCSI link functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-23 12:21:23 +02:00
Karel Zak
23a11c74a6 lib/sysfs: add functions for SCSI host attributes
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-23 12:18:57 +02:00
Karel Zak
d0f7e5b4a0 include/sysfs: add SCSI host:channel:target:lun support
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-10-23 12:15:58 +02:00
Peter Rajnoha
857db7f53c lib/sysfs: fix sysfs_devname_to_devno for dm partitions
Partitions mapped by device-mapper are not like real partitions where
there's a /sys/block/<parent>/<name>/dev sysfs path. We need to look
at /sys/block/<name>/dev like we do for any other non-partition devices.
The mapped partition is not found otherwise.

For example, this bug shows up in lsblk while specifying a device
on command line while that device is a dm mapping over a partition:
$lsblk
NAME             MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
sda                8:0    0  128M  0 disk
`-test (dm-0)    253:0    0  128M  0 dm
  `-test1 (dm-1) 253:1    0  127M  0 part

Before this patch:
$lsblk /dev/mapper/test1
lsblk: dm-1: unknown device name

With this patch:
$lsblk /dev/mapper/test1
NAME         MAJ:MIN RM  SIZE RO TYPE MOUNTPOINT
test1 (dm-1) 253:1    0  127M  0 part
2012-09-21 12:21:30 +02:00
Karel Zak
fee9431f97 lib/sysfs: more robust sysfs_opendir() [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-09-07 12:15:39 +02:00
Bernhard Voelker
f31322a289 lib/sysfs: make sysfs_partno_to_devno better readable
Signed-off-by: Bernhard Voelker <mail@bernhard-voelker.de>
2012-08-14 18:22:04 +02:00
Karel Zak
778ad369f6 lib/sysfs; add sysfs_partno_to_devno()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-08-13 22:06:18 +02:00
Karel Zak
a3b780532f lib/sysfs: expect p<N> suffix for partitions
... so for example lsblk(8) will see partitioned loop devices

loop0       7:0    0    80G  0 loop
├─loop0p1 259:0    0   100M  0 loop
└─loop0p2 259:1    0  79.9G  0 loop

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-08-13 21:11:37 +02:00
Karel Zak
657d9adb71 fix buffer overrun in some calls to sscanf
Reported-by: Sergei Antonov <saproj@gmail.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-07-09 22:26:27 +02:00
Karel Zak
1aae31c048 lib/sysfs: use warn_unused_result for sysfs_init()
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-06-21 08:28:49 +02:00
Cong Wang
cffee0de0c lib/sysfs: check if cxt->dir_path is NULL in sysfs_readlink()
cxt->dir_path could be NULL, for example, when sysfs_init() fails,
check this before calling readlink()/readlink_at().

Cc: Karel Zak <kzak@redhat.com>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
2012-06-21 08:21:23 +02:00
Sami Kerola
9d72cbc1e2 sysfs: fix printf format warnings
sysfs.c:93:3: warning: format '%u' expects argument of type 'unsigned
	int *', but argument 3 has type 'int *' [-Wformat]
sysfs.c:93:3: warning: format '%u' expects argument of type 'unsigned
	int *', but argument 4 has type 'int *' [-Wformat]

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2012-06-11 19:51:35 +02:00
Karel Zak
093b20ba21 lib/sysfs: improve sysfs_is_partition_dirent()
... to work with absolute disk device path too.

Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-29 12:42:24 +02:00
Michal Luscon
3b66f48e23 sysfs: move blkid_devno_to_wholedisk to sysfs_devno_to_wholedisk
Signed-off-by: Michal Luscon <mluscon@redhat.com>
2012-03-27 13:16:19 +02:00
Peter Rajnoha
09a71aa1d5 lsblk: add inverse tree support (-s)
$ lsblk --inverse -o NAME /dev/dm-0
NAME
luks-10d813de-fa82-4f67-a86c-23d5d0e7c30e (dm-0)
└─sda6
  └─sda

Signed-off-by: Peter Rajnoha <prajnoha@redhat.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-07 13:54:11 +01:00
Karel Zak
4c5bbc5d7e libblkid: fix sysfs context usage
Reported-by: Elan Ruusamäe <glen@delfi.ee>
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-03-06 11:24:54 +01:00
Karel Zak
5415374ddf lib/sysfs: fix handle leak
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-01 23:02:21 +01:00
Karel Zak
06ae069bc3 lib/sysfs: fix possible fd leak on error
Signed-off-by: Karel Zak <kzak@redhat.com>
2012-02-01 13:03:58 +01:00
Petr Uzel
3a18db62e6 lib: do not attempt to close(0) in sysfs_deinit()
If the 'open' fails we 'goto err' which runs 'sysfs_deinit()' on a 'cxt'
which hasn't been fully initialised. The 'dir_fd' is still 0, so
sysfs_deinit calls "close(0)".

Addresses: https://bugzilla.novell.com/show_bug.cgi?id=714151
Reported-by: Diego Ercolani <diego.ercolani@gmail.com>
Analysed-by: Neil Brown <nfbrown@suse.com>
Signed-off-by: Petr Uzel <petr.uzel@suse.cz>
2011-09-13 11:38:13 +02:00
Karel Zak
6b9166ce06 lib: [sysfs.c] fix compiler warnings [-Wsign-compare]
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-08-01 12:01:24 +02:00
Davidlohr Bueso
fb4a9e54fc sysfs: free used resources
In the sysfs lib example, we should be using sysfs_deinit() to free used
resources and for correct usage.

Signed-off-by: Davidlohr Bueso <dave@gnu.org>
2011-07-26 11:58:38 +02:00
Karel Zak
87e77645f5 lib: [sysfs.c] fix double free
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-30 16:37:46 +02:00
Karel Zak
e918cca562 build-sys: cleanup lib/ tests
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-25 16:50:44 +02:00
Karel Zak
413993fcb1 lib: [sysfs.c] add sysfs_readlink and name/path functions
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-18 16:24:37 +02:00
Karel Zak
90e9fcda3b lib: [sysfs.c] make sysfs_read_* function more robust
The functions does not modify result if the requested sysfs attribute
does not exist.

Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-18 11:57:17 +02:00
Karel Zak
d8a84552fb libblkid: use stuff from sysfs.h and at.h
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-16 20:22:52 +02:00
Karel Zak
7fe16fdaf4 lib: add generic sysfs utils
Signed-off-by: Karel Zak <kzak@redhat.com>
2011-05-16 20:22:52 +02:00