mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH 08/10] fs: stat_print: get cdevname from stat
Date: Thu, 27 Nov 2025 10:19:30 +0100	[thread overview]
Message-ID: <20251127-devfs-v1-8-4aff12818757@pengutronix.de> (raw)
In-Reply-To: <20251127-devfs-v1-0-4aff12818757@pengutronix.de>

In stat_print() we have to take the filename component of the input path
and retrieve the cdev from that name. Now that we have the cdevname in
struct stat we can simplify this.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/fs.c | 25 ++++---------------------
 1 file changed, 4 insertions(+), 21 deletions(-)

diff --git a/fs/fs.c b/fs/fs.c
index 41cdaf5070798388aa989d16e7bf2ace081b4a2b..4146ecbf3c01229cac89e5acdbc42d66ffc97dfc 100644
--- a/fs/fs.c
+++ b/fs/fs.c
@@ -137,7 +137,6 @@ void stat_print(int dirfd, const char *filename, const struct stat *st)
 	struct fs_device *fdev;
 	struct cdev *cdev = NULL;
 	const char *type = NULL, *typeprefix = "";
-	bool is_cdev_link = false;
 	char modestr[11];
 
 	mkmodestr(st->st_mode, modestr);
@@ -152,23 +151,10 @@ void stat_print(int dirfd, const char *filename, const struct stat *st)
 		case S_IFREG:    type = "regular file"; break;
 	}
 
-	if (st->st_mode & S_IFCHR) {
-		char *path;
-
-		path = canonicalize_path(dirfd, filename);
-		if (path) {
-			const char *devicefile = devpath_to_name(path);
-			struct cdev *lcdev;
-
-			lcdev = lcdev_by_name(devicefile);
-			cdev = cdev_readlink(lcdev);
-			if (cdev != lcdev)
-				is_cdev_link = true;
-			if (cdev)
-				bdev = cdev_get_block_device(cdev);
-
-			free(path);
-		}
+	if ((st->st_mode & S_IFCHR) && st->st_cdevname) {
+		cdev = cdev_by_name(st->st_cdevname);
+		if (cdev)
+			bdev = cdev_get_block_device(cdev);
 	}
 
 	printf("  File: %s", filename);
@@ -182,9 +168,6 @@ void stat_print(int dirfd, 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("\nSize: ");

-- 
2.47.3




  parent reply	other threads:[~2025-11-27  9:20 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-27  9:19 [PATCH 00/10] fs: Use device special nodes for devfs Sascha Hauer
2025-11-27  9:19 ` [PATCH 01/10] fs: implement mknod Sascha Hauer
2025-11-27  9:19 ` [PATCH 02/10] commands: add mknod command Sascha Hauer
2025-11-27  9:19 ` [PATCH 03/10] fs: ramfs: add device file support Sascha Hauer
2025-11-27  9:19 ` [PATCH 04/10] cdev: add cdev_size() helper Sascha Hauer
2025-11-27  9:19 ` [PATCH 05/10] fs: fix st_size for device files Sascha Hauer
2025-11-27  9:19 ` [PATCH 06/10] fs: retire devfs as filesystem Sascha Hauer
2025-11-27  9:19 ` [PATCH 07/10] fs: include cdevname in struct stat Sascha Hauer
2025-11-27  9:19 ` Sascha Hauer [this message]
2025-11-27  9:19 ` [PATCH 09/10] fs: replace cdev links with aliases Sascha Hauer
2025-11-27  9:19 ` [PATCH 10/10] ls: use ~0 for FILE_SIZE_STREAM 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=20251127-devfs-v1-8-4aff12818757@pengutronix.de \
    --to=s.hauer@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