From: Stanislav Brabec <sbrabec@suse.cz>
To: util-linux@vger.kernel.org
Subject: [PATCH] Fix /dev to /sys node name translation
Date: Wed, 27 May 2015 15:12:08 +0200 [thread overview]
Message-ID: <5565C2A8.1070505@suse.cz> (raw)
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
next reply other threads:[~2015-05-27 13:12 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-27 13:12 Stanislav Brabec [this message]
2015-05-28 10:40 ` [PATCH] Fix /dev to /sys node name translation Karel Zak
2015-05-28 13:02 ` Stanislav Brabec
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5565C2A8.1070505@suse.cz \
--to=sbrabec@suse.cz \
--cc=util-linux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.