[PATCH v2 06/13] cdev: add cdev_size() helper
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Dec 15 03:22:55 PST 2025
On 12/9/25 1:51 PM, Sascha Hauer wrote:
> 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>
Reviewed-by: Ahmad Fatoum <a.fatoum 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)
> {
>
--
Pengutronix e.K. | |
Steuerwalder Str. 21 | http://www.pengutronix.de/ |
31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |
More information about the barebox
mailing list