summaryrefslogtreecommitdiffstats
path: root/lib/blkdev.c
diff options
context:
space:
mode:
authorKarel Zak2010-03-11 00:59:04 +0100
committerKarel Zak2010-03-11 00:59:04 +0100
commit530381d2d506d75c4dd1607bb6f556d17537f911 (patch)
tree6f3acc541d60024a658f6471f090d065207d8cd8 /lib/blkdev.c
parentmount: use unmangle/mangle() from lib (diff)
downloadkernel-qcow2-util-linux-530381d2d506d75c4dd1607bb6f556d17537f911.tar.gz
kernel-qcow2-util-linux-530381d2d506d75c4dd1607bb6f556d17537f911.tar.xz
kernel-qcow2-util-linux-530381d2d506d75c4dd1607bb6f556d17537f911.zip
lib: use fstat() as fallback in blkdev_get_size()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'lib/blkdev.c')
-rw-r--r--lib/blkdev.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/lib/blkdev.c b/lib/blkdev.c
index 824a87c40..aa323f218 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;
}