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 "common/darktable.h"
44#include <glib.h>
45
46#include <string.h>
47#include <malloc.h>
48
49//#include <winpr/crt.h>
50#include "win/win.h"
51
52#include "statvfs.h"
53
54int statvfs(const char *path, struct statvfs *buf)
55{
56 BOOL res;
57
58 DWORD lpSectorsPerCluster = 0;
59 DWORD lpBytesPerSector = 0;
60 DWORD lpNumberOfFreeClusters = 0;
61 DWORD lpTotalNumberOfClusters = 0;
62 char szDrive[4];
63
64 szDrive[0] = path[0];
65 szDrive[1] = ':';
66 szDrive[2] = '\\';
67 szDrive[3] = '\0';
68
69 wchar_t *wszDrive = g_utf8_to_utf16(szDrive, -1, NULL, NULL, NULL);
70
71 res = GetDiskFreeSpaceW(wszDrive, &lpSectorsPerCluster, &lpBytesPerSector, &lpNumberOfFreeClusters,
72 &lpTotalNumberOfClusters);
73
74 dt_free(wszDrive);
75
76 buf->f_bsize = lpBytesPerSector; /* file system block size */
77 buf->f_frsize = lpBytesPerSector * lpSectorsPerCluster; /* fragment size */
78 buf->f_blocks = lpTotalNumberOfClusters; /* size of fs in f_frsize units */
79 buf->f_bfree = lpNumberOfFreeClusters; /* # free blocks */
80 buf->f_bavail = lpNumberOfFreeClusters; /* # free blocks for unprivileged users */
81 buf->f_files = 0; /* # inodes */
82 buf->f_ffree = 0; /* # free inodes */
83 buf->f_favail = 0; /* # free inodes for unprivileged users */
84 buf->f_fsid = lpNumberOfFreeClusters & 0xffff; /* file system ID */
85 buf->f_flag = 0; /* mount flags */
86 buf->f_namemax = 250; /* maximum filename length */
87
88 if(res != 0)
89 return 0;
90 else
91 return 1;
92}
93
94// clang-format off
95// modelines: These editor modelines have been set for all relevant files by tools/update_modelines.py
96// vim: shiftwidth=2 expandtab tabstop=2 cindent
97// kate: tab-indents: off; indent-width 2; replace-tabs on; indent-mode cstyle; remove-trailing-spaces modified;
98// clang-format on
99
#define dt_free(ptr)
Definition darktable.h:456
unsigned long f_namemax
Definition statvfs.h:61
unsigned long f_fsid
Definition statvfs.h:59
unsigned long f_bsize
Definition statvfs.h:51
fsblkcnt_t f_bavail
Definition statvfs.h:55
fsfilcnt_t f_files
Definition statvfs.h:56
fsfilcnt_t f_ffree
Definition statvfs.h:57
fsfilcnt_t f_favail
Definition statvfs.h:58
fsblkcnt_t f_blocks
Definition statvfs.h:53
fsblkcnt_t f_bfree
Definition statvfs.h:54
unsigned long f_flag
Definition statvfs.h:60
unsigned long f_frsize
Definition statvfs.h:52