mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
Add a shared helper that returns the logical size in bytes for both regular files and block devices using an immutable &File reference. Regular files use metadata().len(). Block devices use the BLKGETSIZE64 ioctl. Any other file type returns an InvalidInput error. This avoids seek(SeekFrom::End(0)) which requires &mut self and can return incorrect results for block devices when the file position is in an unexpected state. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>