summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKay Sievers <kay.sievers@vrfy.org>2008-11-21 05:02:02 +0100
committerKay Sievers <kay.sievers@vrfy.org>2008-11-21 05:02:02 +0100
commit405d2830431742ca156833edd1f868ede015c83b (patch)
tree964ce7bcfa83d7b5e44bf684fea67627ab073ec2
parent2b22881cae4194e453766036300098fa19ccc1e6 (diff)
vol_id: if regular files are probed, use stat() for the size value
-rw-r--r--extras/volume_id/vol_id.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/extras/volume_id/vol_id.c b/extras/volume_id/vol_id.c
index a50560c097..889bd3483d 100644
--- a/extras/volume_id/vol_id.c
+++ b/extras/volume_id/vol_id.c
@@ -31,6 +31,7 @@
#include <grp.h>
#include <getopt.h>
#include <fcntl.h>
+#include <sys/stat.h>
#include <inttypes.h>
#include <sys/ioctl.h>
@@ -214,9 +215,17 @@ int main(int argc, char *argv[])
}
if (size == 0) {
- if (ioctl(fd, BLKGETSIZE64, &size) != 0)
- size = 0;
- info(udev_ctx, "BLKGETSIZE64=%" PRIu64 " (%" PRIu64 "GB)\n", size, size >> 30);
+ if (ioctl(fd, BLKGETSIZE64, &size) == 0) {
+ info(udev_ctx, "BLKGETSIZE64=%" PRIu64 " (%" PRIu64 "GB)\n", size, size >> 30);
+ } else {
+ struct stat statbuf;
+
+ if (fstat(fd, &statbuf) == 0 && S_ISREG(statbuf.st_mode))
+ size = statbuf.st_size;
+ else
+ size = 0;
+ info(udev_ctx, "stat=%" PRIu64 " (%" PRIu64 "GB)\n", size, size >> 30);
+ }
}
/* try to drop all privileges before reading disk content */