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
8 darktable is free software: you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation, either version 3 of the License, or
11 (at your option) any later version.
12
13 darktable is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with darktable. If not, see <http://www.gnu.org/licenses/>.
20*/
21
43#include "system/mem_alloc.h"
44#include <glib.h>
45
46#include <string.h>
47
48//#include <winpr/crt.h>
49#include "win/win.h"
50
51#include "statvfs.h"
52
53int statvfs(const char *path, struct statvfs *buf)
54{
55 BOOL res;
56
57 DWORD lpSectorsPerCluster = 0;
58 DWORD lpBytesPerSector = 0;
59 DWORD lpNumberOfFreeClusters = 0;
60 DWORD lpTotalNumberOfClusters = 0;
61 char szDrive[4];
62
63 szDrive[0] = path[0];
64 szDrive[1] = ':';
65 szDrive[2] = '\\';
66 szDrive[3] = '\0';
67
68 wchar_t *wszDrive = g_utf8_to_utf16(szDrive, -1, NULL, NULL, NULL);
69
70 res = GetDiskFreeSpaceW(wszDrive, &lpSectorsPerCluster, &lpBytesPerSector, &lpNumberOfFreeClusters,
71 &lpTotalNumberOfClusters);
72
73 dt_free(wszDrive);
74
75 buf->f_bsize = lpBytesPerSector; /* file system block size */
76 buf->f_frsize = lpBytesPerSector * lpSectorsPerCluster; /* fragment size */
77 buf->f_blocks = lpTotalNumberOfClusters; /* size of fs in f_frsize units */
78 buf->f_bfree = lpNumberOfFreeClusters; /* # free blocks */
79 buf->f_bavail = lpNumberOfFreeClusters; /* # free blocks for unprivileged users */
80 buf->f_files = 0; /* # inodes */
81 buf->f_ffree = 0; /* # free inodes */
82 buf->f_favail = 0; /* # free inodes for unprivileged users */
83 buf->f_fsid = lpNumberOfFreeClusters & 0xffff; /* file system ID */
84 buf->f_flag = 0; /* mount flags */
85 buf->f_namemax = 250; /* maximum filename length */
86
87 if(res != 0)
88 return 0;
89 else
90 return 1;
91}
92
93// clang-format off
94// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
95// vim: shiftwidth=2 expandtab tabstop=2 cindent
96// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
97// clang-format on
98
const int res
Definition dtpthread.h:351
#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 f_namemax
Definition statvfs.h:62
unsigned long f_fsid
Definition statvfs.h:60
unsigned long f_bsize
Definition statvfs.h:52
fsblkcnt_t f_bavail
Definition statvfs.h:56
fsfilcnt_t f_files
Definition statvfs.h:57
fsfilcnt_t f_ffree
Definition statvfs.h:58
fsfilcnt_t f_favail
Definition statvfs.h:59
fsblkcnt_t f_blocks
Definition statvfs.h:54
fsblkcnt_t f_bfree
Definition statvfs.h:55
unsigned long f_flag
Definition statvfs.h:61
unsigned long f_frsize
Definition statvfs.h:53