From 530381d2d506d75c4dd1607bb6f556d17537f911 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Thu, 11 Mar 2010 00:59:04 +0100 Subject: [PATCH] lib: use fstat() as fallback in blkdev_get_size() Signed-off-by: Karel Zak --- lib/blkdev.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/blkdev.c b/lib/blkdev.c index 824a87c4..aa323f21 100644 --- a/lib/blkdev.c +++ b/lib/blkdev.c @@ -138,6 +138,15 @@ blkdev_get_size(int fd, unsigned long long *bytes) } #endif /* HAVE_SYS_DISKLABEL_H */ + { + struct stat st; + + if (fstat(fd, &st) == 0 && S_ISREG(st.st_mode)) { + *bytes = st.st_size; + return 0; + } + } + *bytes = blkdev_find_size(fd); return 0; } -- 2.39.5