[PATCH 04/10] cdev: add cdev_size() helper

Sascha Hauer s.hauer at pengutronix.de
Thu Nov 27 01:19:26 PST 2025


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

Signed-off-by: Sascha Hauer <s.hauer at 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




More information about the barebox mailing list