[PATCH v2 06/13] cdev: add cdev_size() helper
Sascha Hauer
s.hauer at pengutronix.de
Tue Dec 9 04:51:25 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 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
More information about the barebox
mailing list