Line | Count | Source (jump to first uncovered line) |
1 | | #ifndef COMPAT_DISK_H |
2 | | #define COMPAT_DISK_H |
3 | | |
4 | | #include "abspath.h" |
5 | | #include "gettext.h" |
6 | | |
7 | | static int get_disk_info(struct strbuf *out) |
8 | 0 | { |
9 | 0 | struct strbuf buf = STRBUF_INIT; |
10 | 0 | int res = 0; |
11 | |
|
12 | | #ifdef GIT_WINDOWS_NATIVE |
13 | | char volume_name[MAX_PATH], fs_name[MAX_PATH]; |
14 | | DWORD serial_number, component_length, flags; |
15 | | ULARGE_INTEGER avail2caller, total, avail; |
16 | | |
17 | | strbuf_realpath(&buf, ".", 1); |
18 | | if (!GetDiskFreeSpaceExA(buf.buf, &avail2caller, &total, &avail)) { |
19 | | error(_("could not determine free disk size for '%s'"), |
20 | | buf.buf); |
21 | | res = -1; |
22 | | goto cleanup; |
23 | | } |
24 | | |
25 | | strbuf_setlen(&buf, offset_1st_component(buf.buf)); |
26 | | if (!GetVolumeInformationA(buf.buf, volume_name, sizeof(volume_name), |
27 | | &serial_number, &component_length, &flags, |
28 | | fs_name, sizeof(fs_name))) { |
29 | | error(_("could not get info for '%s'"), buf.buf); |
30 | | res = -1; |
31 | | goto cleanup; |
32 | | } |
33 | | strbuf_addf(out, "Available space on '%s': ", buf.buf); |
34 | | strbuf_humanise_bytes(out, avail2caller.QuadPart); |
35 | | strbuf_addch(out, '\n'); |
36 | | #else |
37 | 0 | struct statvfs stat; |
38 | |
|
39 | 0 | strbuf_realpath(&buf, ".", 1); |
40 | 0 | if (statvfs(buf.buf, &stat) < 0) { |
41 | 0 | error_errno(_("could not determine free disk size for '%s'"), |
42 | 0 | buf.buf); |
43 | 0 | res = -1; |
44 | 0 | goto cleanup; |
45 | 0 | } |
46 | | |
47 | 0 | strbuf_addf(out, "Available space on '%s': ", buf.buf); |
48 | 0 | strbuf_humanise_bytes(out, (off_t)stat.f_bsize * (off_t)stat.f_bavail); |
49 | 0 | strbuf_addf(out, " (mount flags 0x%lx)\n", stat.f_flag); |
50 | 0 | #endif |
51 | |
|
52 | 0 | cleanup: |
53 | 0 | strbuf_release(&buf); |
54 | 0 | return res; |
55 | 0 | } |
56 | | |
57 | | #endif /* COMPAT_DISK_H */ |