From: Ahmad Fatoum <a.fatoum@pengutronix.de>
To: barebox@lists.infradead.org
Cc: Ahmad Fatoum <a.fatoum@pengutronix.de>
Subject: [PATCH 2/2] commands: stat: add basic handling for cdev links
Date: Wed, 31 May 2023 15:23:31 +0200 [thread overview]
Message-ID: <20230531132331.2152268-2-a.fatoum@pengutronix.de> (raw)
In-Reply-To: <20230531132331.2152268-1-a.fatoum@pengutronix.de>
cdev links are not symlinks and cdev_by_name will always resolve them.
As the barebox stat command is a convenience for VFS developers, it's
useful to have the command identify links, so let's teach it just that.
There's no behavior difference between specifying -L and not. This
should be rather achieved by removing the concept of cdev links and
using symlinks instead, but that's some refactoring for another time.
Signed-off-by: Ahmad Fatoum <a.fatoum@pengutronix.de>
---
fs/devfs-core.c | 3 +++
fs/fs.c | 14 +++++++++++---
2 files changed, 14 insertions(+), 3 deletions(-)
diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index fbcf68e81597..68a41ed20dd1 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -49,6 +49,9 @@ int devfs_partition_complete(struct string_list *sl, char *instr)
struct cdev *cdev_readlink(struct cdev *cdev)
{
+ if (!cdev)
+ return NULL;
+
if (cdev->link)
cdev = cdev->link;
diff --git a/fs/fs.c b/fs/fs.c
index 311571ba3088..68e6bf5735f0 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -115,7 +115,8 @@ void stat_print(const char *filename, const struct stat *st)
struct block_device *bdev = NULL;
struct fs_device *fdev;
struct cdev *cdev = NULL;
- const char *type = NULL;
+ const char *type = NULL, *typeprefix = "";
+ bool is_cdev_link = false;
char modestr[11];
mkmodestr(st->st_mode, modestr);
@@ -136,8 +137,12 @@ void stat_print(const char *filename, const struct stat *st)
path = canonicalize_path(filename);
if (path) {
const char *devicefile = devpath_to_name(path);
+ struct cdev *lcdev;
- cdev = cdev_by_name(devicefile);
+ lcdev = lcdev_by_name(devicefile);
+ cdev = cdev_readlink(lcdev);
+ if (cdev != lcdev)
+ is_cdev_link = true;
if (cdev)
bdev = cdev_get_block_device(cdev);
@@ -156,6 +161,9 @@ void stat_print(const char *filename, const struct stat *st)
printf(" -> <readlink error %pe>", ERR_PTR(ret));
else
printf(" -> %s", realname);
+ } else if (is_cdev_link) {
+ printf(" ~> %s", cdev->name);
+ typeprefix = "cdev link to ";
}
printf("\n");
@@ -166,7 +174,7 @@ void stat_print(const char *filename, const struct stat *st)
(u64)bdev->num_blocks, 1 << bdev->blockbits);
if (type)
- printf(" %s", type);
+ printf(" %s%s", typeprefix, type);
fdev = get_fsdevice_by_path(filename);
--
2.39.2
next prev parent reply other threads:[~2023-05-31 13:24 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-31 13:23 [PATCH 1/2] commands: stat: print symlink destination when called without -L Ahmad Fatoum
2023-05-31 13:23 ` Ahmad Fatoum [this message]
2023-06-01 7:06 ` Sascha Hauer
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=20230531132331.2152268-2-a.fatoum@pengutronix.de \
--to=a.fatoum@pengutronix.de \
--cc=barebox@lists.infradead.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox