@@ -2080,18 +2080,29 @@ u64 disk_size(const char *path)
u64 get_partition_size(const char *dev)
{
- u64 result;
- int fd = open(dev, O_RDONLY);
+ struct stat statbuf;
+ int r;
+ int fd;
+ char buf[100];
- if (fd < 0)
- return 0;
- if (ioctl(fd, BLKGETSIZE64, &result) < 0) {
- close(fd);
+ r = stat(dev, &statbuf);
+ if (r != 0)
return 0;
- }
+
+ snprintf(buf, sizeof(buf),
+ "/sys/dev/block/%d:%d/size", major(statbuf.st_rdev),
+ minor(statbuf.st_rdev));
+
+ fd = open(buf, O_RDONLY);
+ BUG_ON(fd < 0);
+
+ r = read(fd, buf, sizeof(buf)-1);
close(fd);
- return result;
+ BUG_ON(r < 0);
+ buf[r] = 0;
+
+ return atoll(buf) * 512;
}
/*