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 04/10] cdev: add cdev_size() helper
Date: Thu, 27 Nov 2025 10:19:26 +0100	[thread overview]
Message-ID: <20251127-devfs-v1-4-4aff12818757@pengutronix.de> (raw)
In-Reply-To: <20251127-devfs-v1-0-4aff12818757@pengutronix.de>

We'll need the size of a cdev later, add a helper for retrieving the
size.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 fs/devfs-core.c  | 6 ++++++
 fs/devfs.c       | 3 +--
 include/driver.h | 1 +
 3 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/fs/devfs-core.c b/fs/devfs-core.c
index 92e7c5823ed0d3a4c54cc7b2b1c9bf32ac535907..7841ac71540675c27ec3a695f0b7333cd3b02e0c 100644
--- a/fs/devfs-core.c
+++ b/fs/devfs-core.c
@@ -435,6 +435,12 @@ int cdev_truncate(struct cdev *cdev, size_t size)
 	return -EPERM;
 }
 
+loff_t cdev_size(struct cdev *cdev)
+{
+	return cdev->flags & DEVFS_IS_CHARACTER_DEV ?
+		FILE_SIZE_STREAM : cdev->size;
+}
+
 static struct cdev *cdev_alloc(const char *name)
 {
 	struct cdev *new;
diff --git a/fs/devfs.c b/fs/devfs.c
index be3272be49e66eb843823b3ff664a1565f326790..a48c6452697b47cbd3ffc6f993230e7993e565fe 100644
--- a/fs/devfs.c
+++ b/fs/devfs.c
@@ -109,8 +109,7 @@ static int devfs_open(struct inode *inode, struct file *f)
 			return -ENOENT;
 	}
 
-	f->f_size = cdev->flags & DEVFS_IS_CHARACTER_DEV ?
-			FILE_SIZE_STREAM : cdev->size;
+	f->f_size = cdev_size(cdev);
 	f->private_data = cdev;
 
 	return cdev_open(cdev, f->f_flags);
diff --git a/include/driver.h b/include/driver.h
index c130a3cd63fd5e6dc365a33c765a22dc4e2ca90a..7d93c07c402421bd449adfda3aebaddddf5d3266 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -524,6 +524,7 @@ int cdev_protect(struct cdev*, size_t count, loff_t offset, int prot);
 int cdev_discard_range(struct cdev*, loff_t count, loff_t offset);
 int cdev_memmap(struct cdev*, void **map, int flags);
 int cdev_truncate(struct cdev*, size_t size);
+loff_t cdev_size(struct cdev *cdev);
 loff_t cdev_unallocated_space(struct cdev *cdev);
 static inline bool cdev_is_partition(const struct cdev *cdev)
 {

-- 
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 ` Sascha Hauer [this message]
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 ` [PATCH 08/10] fs: stat_print: get cdevname from stat Sascha Hauer
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-4-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