From: Sascha Hauer <s.hauer@pengutronix.de>
To: BAREBOX <barebox@lists.infradead.org>
Subject: [PATCH v2 06/13] cdev: add cdev_size() helper
Date: Tue, 09 Dec 2025 13:51:25 +0100 [thread overview]
Message-ID: <20251209-devfs-v2-6-62ae16698cff@pengutronix.de> (raw)
In-Reply-To: <20251209-devfs-v2-0-62ae16698cff@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 91082265d1aaa965160de5e414364e3fb14824d1..467aa51c858a8bde6ab4e17cc4c838b989606486 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 e0fddecd085c991db4f1fe34c56405d28b6f53ad..0c7a75b3d5632fdbde65ac52667e3bdee325dcf2 100644
--- a/include/driver.h
+++ b/include/driver.h
@@ -526,6 +526,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
next prev parent reply other threads:[~2025-12-09 12:52 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-12-09 12:51 [PATCH v2 00/13] fs: Use device special nodes for devfs Sascha Hauer
2025-12-09 12:51 ` [PATCH v2 01/13] fs: devfs-core: add devfs_create_link_node() Sascha Hauer
2025-12-15 11:14 ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 02/13] storage-by-alias: drop fake cdev Sascha Hauer
2025-12-15 11:15 ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 03/13] fs: implement mknod Sascha Hauer
2025-12-15 11:19 ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 04/13] commands: add mknod command Sascha Hauer
2025-12-15 11:21 ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 05/13] fs: ramfs: add device file support Sascha Hauer
2025-12-15 11:22 ` Ahmad Fatoum
2025-12-09 12:51 ` Sascha Hauer [this message]
2025-12-15 11:22 ` [PATCH v2 06/13] cdev: add cdev_size() helper Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 07/13] fs: fix st_size for device files Sascha Hauer
2025-12-15 11:24 ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 08/13] fs: retire devfs as filesystem Sascha Hauer
2025-12-15 11:25 ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 09/13] fs: include cdevname in struct stat Sascha Hauer
2025-12-15 11:25 ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 10/13] fs: stat_print: get cdevname from stat Sascha Hauer
2025-12-15 11:26 ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 11/13] common: cdev-alias: rename struct Sascha Hauer
2025-12-15 11:27 ` Ahmad Fatoum
2025-12-09 12:51 ` [PATCH v2 12/13] fs: replace cdev links with aliases Sascha Hauer
2025-12-15 11:31 ` Ahmad Fatoum
2025-12-15 12:17 ` Sascha Hauer
2025-12-09 12:51 ` [PATCH v2 13/13] ls: use ~0 for FILE_SIZE_STREAM Sascha Hauer
2025-12-15 11:32 ` Ahmad Fatoum
2025-12-15 12:16 ` [PATCH v2 00/13] fs: Use device special nodes for devfs 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=20251209-devfs-v2-6-62ae16698cff@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