[PATCH v2 07/13] fs: fix st_size for device files
Ahmad Fatoum
a.fatoum at pengutronix.de
Mon Dec 15 03:24:15 PST 2025
On 12/9/25 1:51 PM, Sascha Hauer wrote:
> In Linux device special files have zero size, but in barebox the
> device files traditionally have the size of the underlying device.
> Initialize struct stat::s_size with the cdev size.
>
> Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
Reviewed-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
Single nitpick below:
> ---
> fs/fs.c | 14 +++++++++++++-
> 1 file changed, 13 insertions(+), 1 deletion(-)
>
> diff --git a/fs/fs.c b/fs/fs.c
> index 45bf89653c7c2e4e9546f1d41f79a6389e0b796d..9e2c95c6352cc63400f997bb8de53af44f4741cf 100644
> --- a/fs/fs.c
> +++ b/fs/fs.c
> @@ -1100,11 +1100,23 @@ EXPORT_SYMBOL(readdir);
>
> static void stat_inode(struct inode *inode, struct stat *s)
> {
> + if (inode->cdevname) {
> + struct cdev *cdev;
> +
> + cdev = cdev_by_name(inode->cdevname);
> + if (cdev) {
> + s->st_size = cdev_size(cdev);
> + } else {
> + s->st_size = 0;
> + }
s->st_size = cdev ? cdev_size(cdev) : 0;
> + } else {
> + s->st_size = inode->i_size;
> + }
> +
> s->st_ino = inode->i_ino;
> s->st_mode = inode->i_mode;
> s->st_uid = inode->i_uid;
> s->st_gid = inode->i_gid;
> - s->st_size = inode->i_size;
> }
>
> int fstat(int fd, struct stat *s)
>
--
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