refs/reftable: reload correct stack when creating reflog iter
[alt-git.git] / compat / disk.h
blob6c979c27d89ec858b849f87e64505c2554cb121b
1 #ifndef COMPAT_DISK_H
2 #define COMPAT_DISK_H
4 #include "git-compat-util.h"
5 #include "abspath.h"
6 #include "gettext.h"
8 static int get_disk_info(struct strbuf *out)
10 struct strbuf buf = STRBUF_INIT;
11 int res = 0;
13 #ifdef GIT_WINDOWS_NATIVE
14 char volume_name[MAX_PATH], fs_name[MAX_PATH];
15 DWORD serial_number, component_length, flags;
16 ULARGE_INTEGER avail2caller, total, avail;
18 strbuf_realpath(&buf, ".", 1);
19 if (!GetDiskFreeSpaceExA(buf.buf, &avail2caller, &total, &avail)) {
20 error(_("could not determine free disk size for '%s'"),
21 buf.buf);
22 res = -1;
23 goto cleanup;
26 strbuf_setlen(&buf, offset_1st_component(buf.buf));
27 if (!GetVolumeInformationA(buf.buf, volume_name, sizeof(volume_name),
28 &serial_number, &component_length, &flags,
29 fs_name, sizeof(fs_name))) {
30 error(_("could not get info for '%s'"), buf.buf);
31 res = -1;
32 goto cleanup;
34 strbuf_addf(out, "Available space on '%s': ", buf.buf);
35 strbuf_humanise_bytes(out, avail2caller.QuadPart);
36 strbuf_addch(out, '\n');
37 #else
38 struct statvfs stat;
40 strbuf_realpath(&buf, ".", 1);
41 if (statvfs(buf.buf, &stat) < 0) {
42 error_errno(_("could not determine free disk size for '%s'"),
43 buf.buf);
44 res = -1;
45 goto cleanup;
48 strbuf_addf(out, "Available space on '%s': ", buf.buf);
49 strbuf_humanise_bytes(out, (off_t)stat.f_bsize * (off_t)stat.f_bavail);
50 strbuf_addf(out, " (mount flags 0x%lx)\n", stat.f_flag);
51 #endif
53 cleanup:
54 strbuf_release(&buf);
55 return res;
58 #endif /* COMPAT_DISK_H */