2024-01-01 18:12:26 +00:00
|
|
|
/* Copyright (C) 1998-2024 Free Software Foundation, Inc.
|
2000-01-18 10:17:32 +00:00
|
|
|
This file is part of the GNU C Library.
|
|
|
|
|
|
|
|
The GNU C Library is free software; you can redistribute it and/or
|
2001-07-06 04:58:11 +00:00
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
2000-01-18 10:17:32 +00:00
|
|
|
|
|
|
|
The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
2001-07-06 04:58:11 +00:00
|
|
|
Lesser General Public License for more details.
|
2000-01-18 10:17:32 +00:00
|
|
|
|
2001-07-06 04:58:11 +00:00
|
|
|
You should have received a copy of the GNU Lesser General Public
|
2012-02-09 23:18:22 +00:00
|
|
|
License along with the GNU C Library; if not, see
|
Prefer https to http for gnu.org and fsf.org URLs
Also, change sources.redhat.com to sourceware.org.
This patch was automatically generated by running the following shell
script, which uses GNU sed, and which avoids modifying files imported
from upstream:
sed -ri '
s,(http|ftp)(://(.*\.)?(gnu|fsf|sourceware)\.org($|[^.]|\.[^a-z])),https\2,g
s,(http|ftp)(://(.*\.)?)sources\.redhat\.com($|[^.]|\.[^a-z]),https\2sourceware.org\4,g
' \
$(find $(git ls-files) -prune -type f \
! -name '*.po' \
! -name 'ChangeLog*' \
! -path COPYING ! -path COPYING.LIB \
! -path manual/fdl-1.3.texi ! -path manual/lgpl-2.1.texi \
! -path manual/texinfo.tex ! -path scripts/config.guess \
! -path scripts/config.sub ! -path scripts/install-sh \
! -path scripts/mkinstalldirs ! -path scripts/move-if-change \
! -path INSTALL ! -path locale/programs/charmap-kw.h \
! -path po/libc.pot ! -path sysdeps/gnu/errlist.c \
! '(' -name configure \
-execdir test -f configure.ac -o -f configure.in ';' ')' \
! '(' -name preconfigure \
-execdir test -f preconfigure.ac ';' ')' \
-print)
and then by running 'make dist-prepare' to regenerate files built
from the altered files, and then executing the following to cleanup:
chmod a+x sysdeps/unix/sysv/linux/riscv/configure
# Omit irrelevant whitespace and comment-only changes,
# perhaps from a slightly-different Autoconf version.
git checkout -f \
sysdeps/csky/configure \
sysdeps/hppa/configure \
sysdeps/riscv/configure \
sysdeps/unix/sysv/linux/csky/configure
# Omit changes that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/powerpc/powerpc64/ppc-mcount.S: trailing lines
git checkout -f \
sysdeps/powerpc/powerpc64/ppc-mcount.S \
sysdeps/unix/sysv/linux/s390/s390-64/syscall.S
# Omit change that caused a pre-commit check to fail like this:
# remote: *** error: sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S: last line does not end in newline
git checkout -f sysdeps/sparc/sparc64/multiarch/memcpy-ultra3.S
2019-09-07 05:40:42 +00:00
|
|
|
<https://www.gnu.org/licenses/>. */
|
2000-01-18 10:17:32 +00:00
|
|
|
|
2003-09-17 00:49:19 +00:00
|
|
|
#include <sys/statfs.h>
|
2021-02-07 17:43:02 +00:00
|
|
|
#include <sys/statvfs.h>
|
|
|
|
#include <internal_statvfs.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <time.h>
|
|
|
|
#include <kernel_stat.h>
|
2010-08-11 21:07:28 +00:00
|
|
|
|
|
|
|
/* Special internal-only bit value. */
|
2021-02-07 17:43:02 +00:00
|
|
|
# define ST_VALID 0x0020
|
2003-09-17 00:49:19 +00:00
|
|
|
|
2021-02-07 17:43:02 +00:00
|
|
|
#if !STATFS_IS_STATFS64
|
|
|
|
void
|
|
|
|
__internal_statvfs (struct statvfs *buf, const struct statfs *fsbuf)
|
|
|
|
{
|
|
|
|
/* Now fill in the fields we have information for. */
|
|
|
|
buf->f_bsize = fsbuf->f_bsize;
|
|
|
|
/* Linux has the f_frsize size only in later version of the kernel.
|
|
|
|
If the value is not filled in use f_bsize. */
|
|
|
|
buf->f_frsize = fsbuf->f_frsize ?: fsbuf->f_bsize;
|
|
|
|
buf->f_blocks = fsbuf->f_blocks;
|
|
|
|
buf->f_bfree = fsbuf->f_bfree;
|
|
|
|
buf->f_bavail = fsbuf->f_bavail;
|
|
|
|
buf->f_files = fsbuf->f_files;
|
|
|
|
buf->f_ffree = fsbuf->f_ffree;
|
|
|
|
if (sizeof (buf->f_fsid) == sizeof (fsbuf->f_fsid))
|
|
|
|
/* The shifting uses 'unsigned long long int' even though the target
|
|
|
|
field might only have 32 bits. This is OK since the 'if' branch
|
|
|
|
is not used in this case but the compiler would still generate
|
|
|
|
warnings. */
|
|
|
|
buf->f_fsid = ((fsbuf->f_fsid.__val[0]
|
|
|
|
& ((1ULL << (8 * sizeof (fsbuf->f_fsid.__val[0]))) - 1))
|
|
|
|
| ((unsigned long long int) fsbuf->f_fsid.__val[1]
|
|
|
|
<< (8 * (sizeof (buf->f_fsid)
|
|
|
|
- sizeof (fsbuf->f_fsid.__val[0])))));
|
|
|
|
else
|
|
|
|
/* We cannot help here. The statvfs element is not large enough to
|
|
|
|
contain both words of the statfs f_fsid field. */
|
|
|
|
buf->f_fsid = fsbuf->f_fsid.__val[0];
|
|
|
|
#ifdef _STATVFSBUF_F_UNUSED
|
|
|
|
buf->__f_unused = 0;
|
2004-04-03 07:50:20 +00:00
|
|
|
#endif
|
2021-02-07 17:43:02 +00:00
|
|
|
buf->f_namemax = fsbuf->f_namelen;
|
linux: statvfs: allocate spare for f_type
This is the only missing part in struct statvfs.
The LSB calls [f]statfs() deprecated, and its weird types are definitely
off-putting. However, its use is required to get f_type.
Instead, allocate one of the six spares to f_type,
copied directly from struct statfs.
This then becomes a small glibc extension to the standard interface
on Linux and the Hurd, instead of two different interfaces, one of which
is quite odd due to being an ABI type, and there no longer is any reason
to use statfs().
The underlying kernel type is a mess, but all architectures agree on u32
(or more) for the ABI, and all filesystem magicks are 32-bit integers.
We don't lose any generality by using u32, and by doing so we both make
the API consistent with the Hurd, and allow C++
switch(f_type) { case RAMFS_MAGIC: ...; }
Also fix tst-statvfs so that it actually fails;
as it stood, all it did was return 0 always.
Test statfs()' and statvfs()' f_types are the same.
Link: https://lore.kernel.org/linux-man/f54kudgblgk643u32tb6at4cd3kkzha6hslahv24szs4raroaz@ogivjbfdaqtb/t/#u
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2023-08-06 20:23:36 +00:00
|
|
|
buf->f_type = fsbuf->f_type;
|
2021-02-07 17:43:02 +00:00
|
|
|
memset (buf->__f_spare, '\0', sizeof (buf->__f_spare));
|
|
|
|
|
|
|
|
/* What remains to do is to fill the fields f_favail and f_flag. */
|
2004-04-03 07:50:20 +00:00
|
|
|
|
2021-02-07 17:43:02 +00:00
|
|
|
/* XXX I have no idea how to compute f_favail. Any idea??? */
|
|
|
|
buf->f_favail = buf->f_ffree;
|
|
|
|
|
|
|
|
buf->f_flag = fsbuf->f_flags ^ ST_VALID;
|
|
|
|
}
|
|
|
|
#endif
|
2004-04-03 07:50:20 +00:00
|
|
|
|
2003-09-17 00:49:19 +00:00
|
|
|
void
|
2021-02-07 17:43:02 +00:00
|
|
|
__internal_statvfs64 (struct statvfs64 *buf, const struct statfs64 *fsbuf)
|
2003-09-17 00:49:19 +00:00
|
|
|
{
|
2000-01-18 10:17:32 +00:00
|
|
|
/* Now fill in the fields we have information for. */
|
2003-09-17 00:49:19 +00:00
|
|
|
buf->f_bsize = fsbuf->f_bsize;
|
2003-06-24 18:59:03 +00:00
|
|
|
/* Linux has the f_frsize size only in later version of the kernel.
|
|
|
|
If the value is not filled in use f_bsize. */
|
2003-09-17 00:49:19 +00:00
|
|
|
buf->f_frsize = fsbuf->f_frsize ?: fsbuf->f_bsize;
|
|
|
|
buf->f_blocks = fsbuf->f_blocks;
|
|
|
|
buf->f_bfree = fsbuf->f_bfree;
|
|
|
|
buf->f_bavail = fsbuf->f_bavail;
|
|
|
|
buf->f_files = fsbuf->f_files;
|
|
|
|
buf->f_ffree = fsbuf->f_ffree;
|
|
|
|
if (sizeof (buf->f_fsid) == sizeof (fsbuf->f_fsid))
|
2011-11-12 06:31:29 +00:00
|
|
|
/* The shifting uses 'unsigned long long int' even though the target
|
|
|
|
field might only have 32 bits. This is OK since the 'if' branch
|
|
|
|
is not used in this case but the compiler would still generate
|
|
|
|
warnings. */
|
2010-09-28 02:34:21 +00:00
|
|
|
buf->f_fsid = ((fsbuf->f_fsid.__val[0]
|
2011-11-12 06:31:29 +00:00
|
|
|
& ((1ULL << (8 * sizeof (fsbuf->f_fsid.__val[0]))) - 1))
|
|
|
|
| ((unsigned long long int) fsbuf->f_fsid.__val[1]
|
2001-01-27 22:44:52 +00:00
|
|
|
<< (8 * (sizeof (buf->f_fsid)
|
2003-09-17 00:49:19 +00:00
|
|
|
- sizeof (fsbuf->f_fsid.__val[0])))));
|
2001-01-27 22:44:52 +00:00
|
|
|
else
|
|
|
|
/* We cannot help here. The statvfs element is not large enough to
|
|
|
|
contain both words of the statfs f_fsid field. */
|
2003-09-17 00:49:19 +00:00
|
|
|
buf->f_fsid = fsbuf->f_fsid.__val[0];
|
2001-01-27 22:44:52 +00:00
|
|
|
#ifdef _STATVFSBUF_F_UNUSED
|
|
|
|
buf->__f_unused = 0;
|
|
|
|
#endif
|
2003-09-17 00:49:19 +00:00
|
|
|
buf->f_namemax = fsbuf->f_namelen;
|
linux: statvfs: allocate spare for f_type
This is the only missing part in struct statvfs.
The LSB calls [f]statfs() deprecated, and its weird types are definitely
off-putting. However, its use is required to get f_type.
Instead, allocate one of the six spares to f_type,
copied directly from struct statfs.
This then becomes a small glibc extension to the standard interface
on Linux and the Hurd, instead of two different interfaces, one of which
is quite odd due to being an ABI type, and there no longer is any reason
to use statfs().
The underlying kernel type is a mess, but all architectures agree on u32
(or more) for the ABI, and all filesystem magicks are 32-bit integers.
We don't lose any generality by using u32, and by doing so we both make
the API consistent with the Hurd, and allow C++
switch(f_type) { case RAMFS_MAGIC: ...; }
Also fix tst-statvfs so that it actually fails;
as it stood, all it did was return 0 always.
Test statfs()' and statvfs()' f_types are the same.
Link: https://lore.kernel.org/linux-man/f54kudgblgk643u32tb6at4cd3kkzha6hslahv24szs4raroaz@ogivjbfdaqtb/t/#u
Signed-off-by: Ahelenia Ziemiańska <nabijaczleweli@nabijaczleweli.xyz>
Reviewed-by: Adhemerval Zanella <adhemerval.zanella@linaro.org>
2023-08-06 20:23:36 +00:00
|
|
|
buf->f_type = fsbuf->f_type;
|
2004-04-03 17:32:18 +00:00
|
|
|
memset (buf->__f_spare, '\0', sizeof (buf->__f_spare));
|
2000-01-18 10:17:32 +00:00
|
|
|
|
|
|
|
/* What remains to do is to fill the fields f_favail and f_flag. */
|
|
|
|
|
|
|
|
/* XXX I have no idea how to compute f_favail. Any idea??? */
|
|
|
|
buf->f_favail = buf->f_ffree;
|
|
|
|
|
2017-05-12 11:48:37 +00:00
|
|
|
buf->f_flag = fsbuf->f_flags ^ ST_VALID;
|
2003-09-17 00:49:19 +00:00
|
|
|
}
|