1/*	$NetBSD: statvfs.h,v 1.5 2024/01/19 18:39:15 christos Exp $	 */
2
3/*-
4 * Copyright (c) 2019 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Christos Zoulas.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 *    notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 *    notice, this list of conditions and the following disclaimer in the
17 *    documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
30 */
31
32#ifndef	_COMPAT_SYS_STATVFS_H_
33#define	_COMPAT_SYS_STATVFS_H_
34
35#include <sys/statvfs.h>
36
37struct statvfs90 {
38	unsigned long	f_flag;		/* copy of mount exported flags */
39	unsigned long	f_bsize;	/* file system block size */
40	unsigned long	f_frsize;	/* fundamental file system block size */
41	unsigned long	f_iosize;	/* optimal file system block size */
42
43	/* The following are in units of f_frsize */
44	fsblkcnt_t	f_blocks;	/* number of blocks in file system, */
45	fsblkcnt_t	f_bfree;	/* free blocks avail in file system */
46	fsblkcnt_t	f_bavail;	/* free blocks avail to non-root */
47	fsblkcnt_t	f_bresvd;	/* blocks reserved for root */
48
49	fsfilcnt_t	f_files;	/* total file nodes in file system */
50	fsfilcnt_t	f_ffree;	/* free file nodes in file system */
51	fsfilcnt_t	f_favail;	/* free file nodes avail to non-root */
52	fsfilcnt_t	f_fresvd;	/* file nodes reserved for root */
53
54	uint64_t  	f_syncreads;	/* count of sync reads since mount */
55	uint64_t  	f_syncwrites;	/* count of sync writes since mount */
56
57	uint64_t  	f_asyncreads;	/* count of async reads since mount */
58	uint64_t  	f_asyncwrites;	/* count of async writes since mount */
59
60	fsid_t		f_fsidx;	/* NetBSD compatible fsid */
61	unsigned long	f_fsid;		/* Posix compatible fsid */
62	unsigned long	f_namemax;	/* maximum filename length */
63	uid_t		f_owner;	/* user that mounted the file system */
64
65	uint32_t	f_spare[4];	/* spare space */
66
67	char	f_fstypename[_VFS_NAMELEN]; /* fs type name */
68	char	f_mntonname[_VFS_MNAMELEN];  /* directory on which mounted */
69	char	f_mntfromname[_VFS_MNAMELEN];  /* mounted file system */
70};
71
72__BEGIN_DECLS
73#ifndef _KERNEL
74#include <string.h>
75#endif
76
77static __inline void
78statvfs_to_statvfs90(const struct statvfs *s, struct statvfs90 *s90)
79{
80
81	memset(s90, 0, sizeof(*s90));
82
83	s90->f_flag = s->f_flag;
84	s90->f_bsize = s->f_bsize;
85	s90->f_frsize = s->f_frsize;
86	s90->f_iosize = s->f_iosize;
87
88	s90->f_blocks = s->f_blocks;
89	s90->f_bfree = s->f_bfree;
90	s90->f_bavail = s->f_bavail;
91	s90->f_bresvd = s->f_bresvd;
92
93	s90->f_files = s->f_files;
94	s90->f_ffree = s->f_ffree;
95	s90->f_favail = s->f_favail;
96	s90->f_fresvd = s->f_fresvd;
97
98	s90->f_syncreads = s->f_syncreads;
99	s90->f_syncwrites = s->f_syncwrites;
100
101	s90->f_asyncreads = s->f_asyncreads;
102	s90->f_asyncwrites = s->f_asyncwrites;
103
104	s90->f_fsidx = s->f_fsidx;
105	s90->f_fsid = s->f_fsid;
106	s90->f_namemax = s->f_namemax;
107	s90->f_owner = s->f_owner;
108
109	memcpy(s90->f_fstypename, s->f_fstypename, sizeof(s90->f_fstypename));
110	memcpy(s90->f_mntonname, s->f_mntonname, sizeof(s90->f_mntonname));
111	memcpy(s90->f_mntfromname, s->f_mntfromname, sizeof(s90->f_mntfromname));
112}
113
114#ifdef _KERNEL
115static __inline int
116statvfs_to_statvfs90_copy(const void *vs, void *vs90, size_t l)
117{
118	struct statvfs90 *s90 = kmem_zalloc(sizeof(*s90), KM_SLEEP);
119	int error;
120
121	statvfs_to_statvfs90(vs, s90);
122	error = copyout(s90, vs90, sizeof(*s90));
123	kmem_free(s90, sizeof(*s90));
124
125	return error;
126}
127#else
128
129#ifdef __LIBC12_SOURCE__
130
131int	__compat_statvfs(const char *__restrict, struct statvfs90 *__restrict);
132int	__compat_statvfs1(const char *__restrict, struct statvfs90 *__restrict,
133    int);
134
135int	__compat_fstatvfs(int, struct statvfs90 *);
136int	__compat_fstatvfs1(int, struct statvfs90 *, int);
137
138int	__compat___getmntinfo13(struct statvfs90 **, int);
139
140int	__compat___fhstatvfs40(const void *, size_t, struct statvfs90 *);
141int	__compat___fhstatvfs140(const void *, size_t, struct statvfs90 *, int);
142
143int	__compat_getvfsstat(struct statvfs90 *, size_t, int);
144
145int	__statvfs90(const char *__restrict, struct statvfs *__restrict);
146int	__statvfs190(const char *__restrict, struct statvfs *__restrict, int);
147
148int	__fstatvfs90(int, struct statvfs *);
149int	__fstatvfs190(int, struct statvfs *, int);
150
151int	__fhstatvfs90(const void *, size_t, struct statvfs *);
152int	__fhstatvfs190(const void *, size_t, struct statvfs *, int);
153
154int	__getvfsstat90(struct statvfs *, size_t, int);
155
156int	__getmntinfo90(struct statvfs **, int);
157
158struct compat_30_fhandle;
159int	fhstatvfs(const struct compat_30_fhandle *, struct statvfs90 *);
160int	fhstatvfs1(const struct compat_30_fhandle *, struct statvfs90 *, int);
161
162#endif /* __LIBC12_SOURCE__ */
163
164#endif /* _KERNEL */
165
166__END_DECLS
167
168#endif /* !_COMPAT_SYS_STATVFS_H_ */
169