]>
git.ipfire.org Git - thirdparty/squid.git/blob - compat/statvfs.cc
2 * Copyright (C) 1996-2019 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
10 #include "compat/statvfs.h"
14 // struct statfs has some member differences between OS versions
15 #if HAVE_F_FRSIZE_IN_STATFS
16 #define STATFS_FRSIZE(x) (x).f_frsize
18 #define STATFS_FRSIZE(x) (x).f_bsize
22 xstatvfs(const char *path
, struct statvfs
*sfs
)
24 #if !HAVE_STATFS && _SQUID_WINDOWS_
26 DWORD spc
, bps
, freec
, totalc
;
27 DWORD vsn
, maxlen
, flags
;
33 strncpy(drive
, path
, 2);
37 if (!GetDiskFreeSpace(drive
, &spc
, &bps
, &freec
, &totalc
)) {
41 if (!GetVolumeInformation(drive
, NULL
, 0, &vsn
, &maxlen
, &flags
, NULL
, 0)) {
46 memset(sfs
, 0, sizeof(*sfs
));
48 sfs
->f_bsize
= sfs
->f_frsize
= spc
* bps
; /* file system block size, fragment size */
49 sfs
->f_blocks
= totalc
; /* size of fs in f_frsize units */
50 sfs
->f_bfree
= sfs
->f_bavail
= freec
; /* # free blocks total, and available for unprivileged users */
51 sfs
->f_files
= sfs
->f_ffree
= sfs
->f_favail
= -1; /* # inodes total, free, and available for unprivileged users */
52 sfs
->f_fsid
= vsn
; /* file system ID */
53 sfs
->f_namemax
= maxlen
; /* maximum filename length */
57 // use statfs() and map results from struct statfs to struct statvfs
60 if (int x
= statfs(path
, &tmpSfs
))
63 memset(sfs
, 0, sizeof(*sfs
));
65 sfs
->f_bsize
= tmpSfs
.f_bsize
; /* file system block size */
66 sfs
->f_frsize
= STATFS_FRSIZE(tmpSfs
); /* fragment size */
67 sfs
->f_blocks
= tmpSfs
.f_blocks
; /* size of fs in f_frsize units */
68 sfs
->f_bfree
= tmpSfs
.f_bfree
; /* # free blocks */
69 sfs
->f_bavail
= tmpSfs
.f_bavail
; /* # free blocks for unprivileged users */
70 sfs
->f_files
= tmpSfs
.f_files
; /* # inodes */
71 sfs
->f_ffree
= tmpSfs
.f_ffree
; /* # free inodes */
72 sfs
->f_favail
= tmpSfs
.f_ffree
; /* # free inodes for unprivileged users */
73 sfs
->f_fsid
= tmpSfs
.f_fsid
; /* file system ID */
74 sfs
->f_namemax
= tmpSfs
.f_namelen
; /* maximum filename length */
77 #error Both statvfs() and statfs() system calls are missing.
84 #endif /* HAVE_STATVFS */