Ansel 0.0
A darktable fork - bloat + design vision
Loading...
Searching...
No Matches
statvfs.c
Go to the documentation of this file.
1/*
2 This file is part of darktable,
3 Copyright (C) 2016-2017 Peter Budai.
4 Copyright (C) 2017 Tobias Ellinghaus.
5 Copyright (C) 2020 Pascal Obry.
6 Copyright (C) 2022 Martin Bařinka.
7 Copyright (C) 2026 Aurélien PIERRE.
8 Copyright (C) 2026 Guillaume Stutin.
9
10 darktable is free software: you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation, either version 3 of the License, or
13 (at your option) any later version.
14
15 darktable is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with darktable. If not, see <http://www.gnu.org/licenses/>.
22*/
23
45#include "system/mem_alloc.h"
46#include <glib.h>
47
48#include <string.h>
49
50//#include <winpr/crt.h>
51#include "win/win.h"
52
53#include "statvfs.h"
54
55/* GetDiskFreeSpaceExW takes any directory, where GetDiskFreeSpaceW needs a drive root, which cannot
56 * be built for a UNC share or a drive mounted as a folder. Its counts are in bytes, so they are
57 * reported with f_frsize == 1: f_frsize * f_bavail is exact, and the cluster geometry is not known.
58 * Returns 0 on success and -1 on failure, like POSIX.
59 */
60int statvfs(const char *path, struct statvfs *buf)
61{
62 if(IS_NULL_PTR(path) || IS_NULL_PTR(buf)) return -1;
63
64 memset(buf, 0, sizeof(*buf));
65 buf->f_namemax = 250;
66
67 wchar_t *wpath = g_utf8_to_utf16(path, -1, NULL, NULL, NULL);
68 if(IS_NULL_PTR(wpath)) return -1;
69
70 ULARGE_INTEGER free_to_caller = { 0 };
71 ULARGE_INTEGER total_bytes = { 0 };
72 ULARGE_INTEGER total_free = { 0 };
73 const BOOL res = GetDiskFreeSpaceExW(wpath, &free_to_caller, &total_bytes, &total_free);
74
75 dt_free(wpath);
76
77 if(!res) return -1;
78
79 buf->f_bsize = 1; /* file system block size */
80 buf->f_frsize = 1; /* fragment size: bytes, see above */
81 buf->f_blocks = (fsblkcnt_t)total_bytes.QuadPart; /* size of fs in f_frsize units */
82 buf->f_bfree = (fsblkcnt_t)total_free.QuadPart; /* # free blocks */
83 buf->f_bavail = (fsblkcnt_t)free_to_caller.QuadPart; /* # free blocks for unprivileged users */
84
85 return 0;
86}
87
88// clang-format off
89// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
90// vim: shiftwidth=2 expandtab tabstop=2 cindent
91// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
92// clang-format on
93
const int res
Definition dtpthread.h:351
#define IS_NULL_PTR(p)
C is way too permissive with !=, == and if(var) checks, which can mean too many things depending on w...
Definition macros.h:96
#define dt_free(ptr)
g_free() ptr and set it to NULL, skipping both if it is already NULL.
Definition mem_alloc.h:171
unsigned long long fsblkcnt_t
Definition statvfs.h:47
unsigned long f_namemax
Definition statvfs.h:62
unsigned long f_bsize
Definition statvfs.h:52
fsblkcnt_t f_bavail
Definition statvfs.h:56
fsblkcnt_t f_blocks
Definition statvfs.h:54
fsblkcnt_t f_bfree
Definition statvfs.h:55
unsigned long f_frsize
Definition statvfs.h:53