From: Karel Zak Date: Wed, 10 Mar 2010 23:59:04 +0000 (+0100) Subject: lib: use fstat() as fallback in blkdev_get_size() X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=530381d2d506d75c4dd1607bb6f556d17537f911;p=util-linux lib: use fstat() as fallback in blkdev_get_size() Signed-off-by: Karel Zak --- 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; }