-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathdisksize.c
More file actions
39 lines (35 loc) · 815 Bytes
/
disksize.c
File metadata and controls
39 lines (35 loc) · 815 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#include <stdio.h>
#include <stdint.h>
#include <errno.h>
#include <inttypes.h>
#include <fcntl.h>
#include <unistd.h>
#include "utils/utils.h"
#include "fastdd.h"
/*
* Print disksize of every arg on the command line
*/
int
main(int argc, char *argv[])
{
int i;
char buf[256];
for (i = 1; i < argc; i++) {
const char *fn = argv[i];
int fd = open(fn, O_RDONLY);
if (fd < 0) {
printf("%s: %s\n", fn, strerror(errno));
continue;
}
uint64_t sz = 0;
int r = Blksize(&sz, fd);
if (r < 0) {
printf("%s: blksize %s\n", fn, strerror(-r));
} else {
humanize_size(buf, sizeof buf, sz);
printf("%s: %s (%" PRIu64 ")\n", fn, buf, sz);
}
close(fd);
}
return 0;
}