Util-Linux package development
 help / color / mirror / Atom feed
* [PATCH] Fix /dev to /sys node name translation
@ 2015-05-27 13:12 Stanislav Brabec
  2015-05-28 10:40 ` Karel Zak
  0 siblings, 1 reply; 3+ messages in thread
From: Stanislav Brabec @ 2015-05-27 13:12 UTC (permalink / raw)
  To: util-linux

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>
---
 include/sysfs.h | 20 +++++++++++++++++++-
 lib/sysfs.c     |  8 ++++++--
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/include/sysfs.h b/include/sysfs.h
index 4564124..6b08bbe 100644
--- a/include/sysfs.h
+++ b/include/sysfs.h
@@ -98,7 +98,7 @@ extern int sysfs_scsi_path_contains(struct sysfs_cxt *cxt, const char *pattern);
  * Linux kernel linux/drivers/base/core.c: device_get_devnode()
  * defines a replacement of '!' in the /sys device name by '/' in the
  * /dev device name. This helper replaces all ocurrences of '!' in
- * @name by '/'.
+ * @name by '/' to convert from /sys to /dev.
  */
 static inline void sysfs_devname_to_dev_name (char *name)
 {
@@ -109,4 +109,22 @@ static inline void sysfs_devname_to_dev_name (char *name)
 			c[0] = '/';
 }
 
+/**
+ * sysfs_dev_name_to_devname:
+ * @name: devname to be converted in place
+ *
+ * Linux kernel linux/drivers/base/core.c: device_get_devnode()
+ * defines a replacement of '!' in the /sys device name by '/' in the
+ * /dev device name. This helper replaces all ocurrences of '/' in
+ * @name by '!' to convert from /dev to /sys.
+ */
+static inline void sysfs_dev_name_to_devname (char *name)
+{
+	char *c;
+
+	if (name)
+		while ((c = strchr(name, '/')))
+			c[0] = '!';
+}
+
 #endif /* UTIL_LINUX_SYSFS_H */
diff --git a/lib/sysfs.c b/lib/sysfs.c
index 8417d2d..34a5207 100644
--- a/lib/sysfs.c
+++ b/lib/sysfs.c
@@ -74,10 +74,14 @@ dev_t sysfs_devname_to_devno(const char *name, const char *parent)
 
 	} else if (!dev) {
 		/*
-		 * Create path to /sys/block/<name>/dev
+		 * Create path to /sys/block/<sysname>/dev
 		 */
+		char sysname[PATH_MAX];
+
+		strncpy(sysname, name, sizeof(sysname));
+		sysfs_dev_name_to_devname(sysname);
 		int len = snprintf(buf, sizeof(buf),
-				_PATH_SYS_BLOCK "/%s/dev", name);
+				_PATH_SYS_BLOCK "/%s/dev", sysname);
 		if (len < 0 || (size_t) len + 1 > sizeof(buf))
 			return 0;
 		path = buf;
-- 
2.4.1

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                          e-mail: sbrabec@suse.cz
Lihovarská 1060/12                            tel: +49 911 7405384547
190 00 Praha 9                                 fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix /dev to /sys node name translation
  2015-05-27 13:12 [PATCH] Fix /dev to /sys node name translation Stanislav Brabec
@ 2015-05-28 10:40 ` Karel Zak
  2015-05-28 13:02   ` Stanislav Brabec
  0 siblings, 1 reply; 3+ messages in thread
From: Karel Zak @ 2015-05-28 10:40 UTC (permalink / raw)
  To: Stanislav Brabec; +Cc: util-linux

On Wed, May 27, 2015 at 03:12:08PM +0200, Stanislav Brabec wrote:
>  include/sysfs.h | 20 +++++++++++++++++++-
>  lib/sysfs.c     |  8 ++++++--
>  2 files changed, 25 insertions(+), 3 deletions(-)

 Applied, thanks.

>  static inline void sysfs_devname_to_dev_name (char *name)
> +static inline void sysfs_dev_name_to_devname (char *name)

 but I have renamed to

     sysfs_devname_sys_to_dev()
     sysfs_devname_dev_to_sys()

 because the original names have been too tricky :-)

 I have also changed some thing in sysfs.c, it would be nice if we can
 keep the crazy sysfs devnames (with '!') really only in sysfs specific
 code and externally provide regular device names.

 Please, test it -- especially lsblk.

    Karel

-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] Fix /dev to /sys node name translation
  2015-05-28 10:40 ` Karel Zak
@ 2015-05-28 13:02   ` Stanislav Brabec
  0 siblings, 0 replies; 3+ messages in thread
From: Stanislav Brabec @ 2015-05-28 13:02 UTC (permalink / raw)
  To: Karel Zak; +Cc: util-linux

Karel Zak wrote:
>   because the original names have been too tricky :-)
When I created the first one, I did not think that reverse will be needed.

>   I have also changed some thing in sysfs.c, it would be nice if we can
>   keep the crazy sysfs devnames (with '!') really only in sysfs specific
>   code and externally provide regular device names.
> 
>   Please, test it -- especially lsblk.

fdisk -l works, lsblk -f is broken again. lsblk worked before, but it
used '!'.


Before starting to play with '!' (687cc5d):

cciss-test:~/util-linux # ./lsblk -f
NAME           FSTYPE LABEL MOUNTPOINT
cciss!c0d0                  
├─cciss!c0d0p1              
├─cciss!c0d0p2              
└─cciss!c0d0p3              
cciss-test:~/util-linux # ./fdisk -l
cciss-test:~/util-linux # 


After 759b120: lib/sysfs: Fix /dev to /sys node name translation:
cciss-test:~/util-linux # ./lsblk -f
NAME           FSTYPE LABEL UUID                                 MOUNTPOINT
cciss!c0d0                                                       
├─cciss!c0d0p1 ext3   Boot  126055ae-08fd-4da3-a8ad-7e150d268edb /boot
├─cciss!c0d0p2 swap         e4e0d080-2b69-4ece-aeb5-e2190ad2934b [SWAP]
└─cciss!c0d0p3 btrfs        6b184ec0-512c-4620-8dc1-856a0b85969f /
cciss-test:~/util-linux # ./fdisk -l
Disk /dev/cciss/c0d0: 136.7 GiB, 146778685440 bytes, 286677120 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: dos
Disk identifier: 0x0002fc74

Device            Boot   Start       End   Sectors   Size Id Type
/dev/cciss/c0d0p1 *       2048    321535    319488   156M 83 Linux
/dev/cciss/c0d0p2       321536   4530175   4208640     2G 82 Linux swap / Solaris
/dev/cciss/c0d0p3      4530176 286676991 282146816 134.6G 83 Linux
cciss-test:~/util-linux # 


HEAD d5dbd57:
cciss-test:~/util-linux # ./lsblk -f
cciss-test:~/util-linux # ./fdisk -l
Disk /dev/cciss/c0d0: 136.7 GiB, 146778685440 bytes, 286677120 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: dos
Disk identifier: 0x0002fc74

Device            Boot   Start       End   Sectors   Size Id Type
/dev/cciss/c0d0p1 *       2048    321535    319488   156M 83 Linux
/dev/cciss/c0d0p2       321536   4530175   4208640     2G 82 Linux swap / Solaris
/dev/cciss/c0d0p3      4530176 286676991 282146816 134.6G 83 Linux
cciss-test:~/util-linux # 

-- 
Best Regards / S pozdravem,

Stanislav Brabec
software developer
---------------------------------------------------------------------
SUSE LINUX, s. r. o.                          e-mail: sbrabec@suse.cz
Lihovarská 1060/12                            tel: +49 911 7405384547
190 00 Praha 9                                 fax:  +420 284 084 001
Czech Republic                                    http://www.suse.cz/
PGP: 830B 40D5 9E05 35D8 5E27 6FA3 717C 209F A04F CD76

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2015-05-28 13:02 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-05-27 13:12 [PATCH] Fix /dev to /sys node name translation Stanislav Brabec
2015-05-28 10:40 ` Karel Zak
2015-05-28 13:02   ` Stanislav Brabec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox