Skip to content

Commit

Permalink
libast: features/fs: fix for NetBSD
Browse files Browse the repository at this point in the history
There was an "implicit function definition" warning for getfsstat()
in port/mnt.c on NetBSD. On that OS, the function is gone from the
headers but still in the libraries, so iffe detects it so
port/mnt.c will use it. NetBSD has getvfsstat() instead, which is
the same function under a different name, just to be different.

src/lib/libast/features/fs:
- Add test for getvfsstat() modelled on the existing getfsstat()
  test with struct statvfs. If it is detected, the emitted code
  will define getfsstat as getvfsstat and the corresponding MNT_*
  macros as ST_* for getvfsstat, so that the port/mnt.c code will
  compile on NetBSD without further modification/complication.
- Chain the get(v)fsstat tests in an if...elif...elif...endif so
  that only one of them gets to emit results.
  • Loading branch information
McDutchie committed Aug 16, 2024
1 parent 49af17b commit 7801fb0
Showing 1 changed file with 52 additions and 38 deletions.
90 changes: 52 additions & 38 deletions src/lib/libast/features/fs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ lib statfs4 sys/types.h - sys/statfs.h - sys/vfs.h - sys/mount.h compile{
}
}end

lib getmntinfo_statvfs note{ getmntinfo uses statvfs -- since when? }end compile{
lib getmntinfo_statvfs note{ getmntinfo uses statvfs }end compile{
#include <sys/types.h>
#include <sys/mount.h>
int
Expand All @@ -118,45 +118,59 @@ lib getmntinfo_statvfs note{ getmntinfo uses statvfs -- since when? }end compile
}
}end

lib getfsstat_statvfs note{ getfsstat uses statvfs -- just in case it is confused like getmntinfo }end compile{
#include <sys/types.h>
#if _sys_mount
#include <sys/mount.h>
#endif
int
gfs(struct statvfs* fs)
{
fs->f_flag = 0;
return getfsstat(fs, sizeof(struct statvfs), MNT_WAIT);
if lib getfsstat_getvfsstat note{ getvfsstat (NetBSD) compiles }end compile{
#include <sys/types.h>
#if _sys_statvfs
#include <sys/statvfs.h>
#endif
int
gfs(struct statvfs* fs)
{
fs->f_flag = 0;
return getvfsstat(fs, sizeof(struct statvfs), ST_WAIT);
}
}end {
#define getfsstat getvfsstat
#define MNT_WAIT ST_WAIT
#define MNT_NOWAIT ST_NOWAIT
#define _lib_getfsstat 1 /* getfsstat() is actually getvfsstat() */
#define _lib_getfsstat_statvfs 1 /* ...and it uses statvfs */
}
}end pass{
cat <<!
#define _lib_getfsstat 1 /* getfsstat() uses statvfs and compiles successfully */
!
}end

lib getfsstat_statfs note{ getfsstat uses statfs }end compile{
#include <sys/types.h>
#if _sys_mount
#include <sys/mount.h>
#endif
#if _sys_param
#include <sys/param.h>
#endif
#if _sys_ucred
#include <sys/ucred.h>
#endif
int
gfs(struct statfs* fs)
{
fs->f_flags = 0;
return getfsstat(fs, sizeof(struct statfs), MNT_WAIT);
elif lib getfsstat_statvfs note{ getfsstat uses statvfs }end compile{
#include <sys/types.h>
#if _sys_mount
#include <sys/mount.h>
#endif
int
gfs(struct statvfs* fs)
{
fs->f_flag = 0;
return getfsstat(fs, sizeof(struct statvfs), MNT_WAIT);
}
}end {
#define _lib_getfsstat 1 /* getfsstat() uses statvfs */
}
}end pass{
cat <<!
#define _lib_getfsstat 1 /* getfsstat() uses statfs and compiles successfully */
!
}end
elif lib getfsstat_statfs note{ getfsstat uses statfs }end compile{
#include <sys/types.h>
#if _sys_mount
#include <sys/mount.h>
#endif
#if _sys_param
#include <sys/param.h>
#endif
#if _sys_ucred
#include <sys/ucred.h>
#endif
int
gfs(struct statfs* fs)
{
fs->f_flags = 0;
return getfsstat(fs, sizeof(struct statfs), MNT_WAIT);
}
}end {
#define _lib_getfsstat 1 /* getfsstat() uses statfs */
}
endif

cat{
#if _sys_statvfs
Expand Down

0 comments on commit 7801fb0

Please sign in to comment.