]> git.ipfire.org Git - thirdparty/glibc.git/blame - sysdeps/unix/sysv/linux/internal_statvfs.c
Update copyright dates with scripts/update-copyrights.
[thirdparty/glibc.git] / sysdeps / unix / sysv / linux / internal_statvfs.c
CommitLineData
04277e02 1/* Copyright (C) 1998-2019 Free Software Foundation, Inc.
6e9b72d3
UD
2 This file is part of the GNU C Library.
3 Contributed by Ulrich Drepper <drepper@cygnus.com>, 1998.
4
5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
6e9b72d3
UD
9
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
41bdb6e2 13 Lesser General Public License for more details.
6e9b72d3 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6
PE
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
6e9b72d3 18
a14f121d 19#include <assert.h>
d0501a24
UD
20#include <errno.h>
21#include <mntent.h>
22#include <paths.h>
23#include <stdbool.h>
24#include <stdio_ext.h>
25#include <string.h>
26#include <sys/mount.h>
27#include <sys/stat.h>
28#include <sys/statfs.h>
3aff5644 29#include "internal_statvfs.h"
d0501a24 30#include "linux_fsinfo.h"
af850b1c 31#include <kernel-features.h>
3cdaa6ad
UD
32
33
34/* Special internal-only bit value. */
35#define ST_VALID 0x0020
d0501a24
UD
36
37
08c9a553
UD
38#ifndef STATFS
39# define STATFS statfs
40# define STATVFS statvfs
41# define INTERNAL_STATVFS __internal_statvfs
6016e6f6 42#else
26b0d2e1 43extern int __statvfs_getflags (const char *name, int fstype, int fd);
08c9a553
UD
44#endif
45
46
d0501a24 47void
08c9a553 48INTERNAL_STATVFS (const char *name, struct STATVFS *buf,
26b0d2e1 49 struct STATFS *fsbuf, int fd)
d0501a24 50{
6e9b72d3 51 /* Now fill in the fields we have information for. */
d0501a24 52 buf->f_bsize = fsbuf->f_bsize;
51d1ca00
UD
53 /* Linux has the f_frsize size only in later version of the kernel.
54 If the value is not filled in use f_bsize. */
d0501a24
UD
55 buf->f_frsize = fsbuf->f_frsize ?: fsbuf->f_bsize;
56 buf->f_blocks = fsbuf->f_blocks;
57 buf->f_bfree = fsbuf->f_bfree;
58 buf->f_bavail = fsbuf->f_bavail;
59 buf->f_files = fsbuf->f_files;
60 buf->f_ffree = fsbuf->f_ffree;
61 if (sizeof (buf->f_fsid) == sizeof (fsbuf->f_fsid))
294ce126
UD
62 /* The shifting uses 'unsigned long long int' even though the target
63 field might only have 32 bits. This is OK since the 'if' branch
64 is not used in this case but the compiler would still generate
65 warnings. */
c21cc9bc 66 buf->f_fsid = ((fsbuf->f_fsid.__val[0]
294ce126
UD
67 & ((1ULL << (8 * sizeof (fsbuf->f_fsid.__val[0]))) - 1))
68 | ((unsigned long long int) fsbuf->f_fsid.__val[1]
09a2231b 69 << (8 * (sizeof (buf->f_fsid)
d0501a24 70 - sizeof (fsbuf->f_fsid.__val[0])))));
09a2231b
UD
71 else
72 /* We cannot help here. The statvfs element is not large enough to
73 contain both words of the statfs f_fsid field. */
d0501a24 74 buf->f_fsid = fsbuf->f_fsid.__val[0];
09a2231b
UD
75#ifdef _STATVFSBUF_F_UNUSED
76 buf->__f_unused = 0;
77#endif
d0501a24 78 buf->f_namemax = fsbuf->f_namelen;
6016e6f6 79 memset (buf->__f_spare, '\0', sizeof (buf->__f_spare));
6e9b72d3
UD
80
81 /* What remains to do is to fill the fields f_favail and f_flag. */
82
83 /* XXX I have no idea how to compute f_favail. Any idea??? */
84 buf->f_favail = buf->f_ffree;
85
e8f1225c 86 buf->f_flag = fsbuf->f_flags ^ ST_VALID;
d0501a24 87}