Commit 9d127d20 authored by Konstantin Khlebnikov's avatar Konstantin Khlebnikov

add get_block_size()

parent 44aac25f
...@@ -329,6 +329,16 @@ out: ...@@ -329,6 +329,16 @@ out:
fclose(file); fclose(file);
} }
off_t get_device_size(int fd)
{
unsigned long long blksize;
if (ioctl(fd, BLKGETSIZE64, &blksize))
err(2, "block get size ioctl failed");
return blksize;
}
void sig_exit(int signo) void sig_exit(int signo)
{ {
(void)signo; (void)signo;
...@@ -378,16 +388,11 @@ int main (int argc, char **argv) ...@@ -378,16 +388,11 @@ int main (int argc, char **argv)
if (!quiet) if (!quiet)
parse_device(st.st_dev); parse_device(st.st_dev);
} else if (S_ISBLK(st.st_mode)) { } else if (S_ISBLK(st.st_mode)) {
unsigned long long blksize;
fd = open(path, flags); fd = open(path, flags);
if (fd < 0) if (fd < 0)
err(2, "failed to open \"%s\"", path); err(2, "failed to open \"%s\"", path);
ret = ioctl(fd, BLKGETSIZE64, &blksize); st.st_size = get_device_size(fd);
if (ret)
err(2, "block get size ioctl failed");
st.st_size = blksize;
fstype = "block"; fstype = "block";
device = "device"; device = "device";
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment