Re: [PATCH] loop: fix zero sized loop for block special file

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Aug 25, 2025 at 04:56:55PM +0800, Ming Lei wrote:
> `stat $BDEV_PATH` never works for getting bdev size, so it looks wrong
> to call vfs_getattr_nosec() with bdev path for retrieving bdev's size.

Exactly.

> So just wondering why not take the following more readable way?
> 
> 	/* vfs_getattr() never works for retrieving bdev size */
> 	if (S_ISBLK(stat.mode)) {
> 		loopsize = i_size_read(file->f_mapping->host);
> 	} else {
>           ret = vfs_getattr_nosec(&file->f_path, &stat, STATX_SIZE, 0);
>           if (ret)
>                   return 0;
>           loopsize = stat.size;
> 	}
> 
> Also the above looks like how application reads file size in case of bdev
> involved.

That's not just more readable, but simply the way to go.  Maybe split
it into a helper for readability, though.




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux