]> err.no Git - util-linux/commitdiff
lib: use fstat() as fallback in blkdev_get_size()
authorKarel Zak <kzak@redhat.com>
Wed, 10 Mar 2010 23:59:04 +0000 (00:59 +0100)
committerKarel Zak <kzak@redhat.com>
Wed, 10 Mar 2010 23:59:04 +0000 (00:59 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
lib/blkdev.c

index 824a87c40530b324030a13bf3eef6bc6faf2ab48..aa323f21830f86aabd6c98e73dcdd9408412809f 100644 (file)
@@ -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;
 }