1*ab413307Schristos /* $NetBSD: statvfs.h,v 1.5 2024/01/19 18:39:15 christos Exp $ */
2479c44acSchristos
3479c44acSchristos /*-
4479c44acSchristos * Copyright (c) 2019 The NetBSD Foundation, Inc.
5479c44acSchristos * All rights reserved.
6479c44acSchristos *
7479c44acSchristos * This code is derived from software contributed to The NetBSD Foundation
8479c44acSchristos * by Christos Zoulas.
9479c44acSchristos *
10479c44acSchristos * Redistribution and use in source and binary forms, with or without
11479c44acSchristos * modification, are permitted provided that the following conditions
12479c44acSchristos * are met:
13479c44acSchristos * 1. Redistributions of source code must retain the above copyright
14479c44acSchristos * notice, this list of conditions and the following disclaimer.
15479c44acSchristos * 2. Redistributions in binary form must reproduce the above copyright
16479c44acSchristos * notice, this list of conditions and the following disclaimer in the
17479c44acSchristos * documentation and/or other materials provided with the distribution.
18479c44acSchristos *
19479c44acSchristos * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20479c44acSchristos * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21479c44acSchristos * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22479c44acSchristos * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23479c44acSchristos * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24479c44acSchristos * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25479c44acSchristos * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26479c44acSchristos * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27479c44acSchristos * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28479c44acSchristos * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29479c44acSchristos * POSSIBILITY OF SUCH DAMAGE.
30479c44acSchristos */
31479c44acSchristos
32479c44acSchristos #ifndef _COMPAT_SYS_STATVFS_H_
33479c44acSchristos #define _COMPAT_SYS_STATVFS_H_
34479c44acSchristos
35479c44acSchristos #include <sys/statvfs.h>
36479c44acSchristos
37479c44acSchristos struct statvfs90 {
38479c44acSchristos unsigned long f_flag; /* copy of mount exported flags */
39479c44acSchristos unsigned long f_bsize; /* file system block size */
40479c44acSchristos unsigned long f_frsize; /* fundamental file system block size */
41479c44acSchristos unsigned long f_iosize; /* optimal file system block size */
42479c44acSchristos
43479c44acSchristos /* The following are in units of f_frsize */
44479c44acSchristos fsblkcnt_t f_blocks; /* number of blocks in file system, */
45479c44acSchristos fsblkcnt_t f_bfree; /* free blocks avail in file system */
46479c44acSchristos fsblkcnt_t f_bavail; /* free blocks avail to non-root */
47479c44acSchristos fsblkcnt_t f_bresvd; /* blocks reserved for root */
48479c44acSchristos
49479c44acSchristos fsfilcnt_t f_files; /* total file nodes in file system */
50479c44acSchristos fsfilcnt_t f_ffree; /* free file nodes in file system */
51479c44acSchristos fsfilcnt_t f_favail; /* free file nodes avail to non-root */
52479c44acSchristos fsfilcnt_t f_fresvd; /* file nodes reserved for root */
53479c44acSchristos
54479c44acSchristos uint64_t f_syncreads; /* count of sync reads since mount */
55479c44acSchristos uint64_t f_syncwrites; /* count of sync writes since mount */
56479c44acSchristos
57479c44acSchristos uint64_t f_asyncreads; /* count of async reads since mount */
58479c44acSchristos uint64_t f_asyncwrites; /* count of async writes since mount */
59479c44acSchristos
60479c44acSchristos fsid_t f_fsidx; /* NetBSD compatible fsid */
61479c44acSchristos unsigned long f_fsid; /* Posix compatible fsid */
62479c44acSchristos unsigned long f_namemax; /* maximum filename length */
63479c44acSchristos uid_t f_owner; /* user that mounted the file system */
64479c44acSchristos
65479c44acSchristos uint32_t f_spare[4]; /* spare space */
66479c44acSchristos
67479c44acSchristos char f_fstypename[_VFS_NAMELEN]; /* fs type name */
68479c44acSchristos char f_mntonname[_VFS_MNAMELEN]; /* directory on which mounted */
69479c44acSchristos char f_mntfromname[_VFS_MNAMELEN]; /* mounted file system */
70479c44acSchristos };
71479c44acSchristos
72479c44acSchristos __BEGIN_DECLS
73479c44acSchristos #ifndef _KERNEL
74479c44acSchristos #include <string.h>
75479c44acSchristos #endif
76479c44acSchristos
77479c44acSchristos static __inline void
statvfs_to_statvfs90(const struct statvfs * s,struct statvfs90 * s90)78479c44acSchristos statvfs_to_statvfs90(const struct statvfs *s, struct statvfs90 *s90)
79479c44acSchristos {
8041aa5859Sriastradh
8141aa5859Sriastradh memset(s90, 0, sizeof(*s90));
8241aa5859Sriastradh
83479c44acSchristos s90->f_flag = s->f_flag;
84479c44acSchristos s90->f_bsize = s->f_bsize;
85479c44acSchristos s90->f_frsize = s->f_frsize;
86479c44acSchristos s90->f_iosize = s->f_iosize;
87479c44acSchristos
88479c44acSchristos s90->f_blocks = s->f_blocks;
89479c44acSchristos s90->f_bfree = s->f_bfree;
90479c44acSchristos s90->f_bavail = s->f_bavail;
91479c44acSchristos s90->f_bresvd = s->f_bresvd;
92479c44acSchristos
93479c44acSchristos s90->f_files = s->f_files;
94479c44acSchristos s90->f_ffree = s->f_ffree;
95479c44acSchristos s90->f_favail = s->f_favail;
96479c44acSchristos s90->f_fresvd = s->f_fresvd;
97479c44acSchristos
98479c44acSchristos s90->f_syncreads = s->f_syncreads;
99479c44acSchristos s90->f_syncwrites = s->f_syncwrites;
100479c44acSchristos
101479c44acSchristos s90->f_asyncreads = s->f_asyncreads;
102479c44acSchristos s90->f_asyncwrites = s->f_asyncwrites;
103479c44acSchristos
104479c44acSchristos s90->f_fsidx = s->f_fsidx;
105479c44acSchristos s90->f_fsid = s->f_fsid;
106479c44acSchristos s90->f_namemax = s->f_namemax;
107479c44acSchristos s90->f_owner = s->f_owner;
108479c44acSchristos
109479c44acSchristos memcpy(s90->f_fstypename, s->f_fstypename, sizeof(s90->f_fstypename));
110479c44acSchristos memcpy(s90->f_mntonname, s->f_mntonname, sizeof(s90->f_mntonname));
111479c44acSchristos memcpy(s90->f_mntfromname, s->f_mntfromname, sizeof(s90->f_mntfromname));
112479c44acSchristos }
113479c44acSchristos
114479c44acSchristos #ifdef _KERNEL
115479c44acSchristos static __inline int
statvfs_to_statvfs90_copy(const void * vs,void * vs90,size_t l)116479c44acSchristos statvfs_to_statvfs90_copy(const void *vs, void *vs90, size_t l)
117479c44acSchristos {
118d6527692Schristos struct statvfs90 *s90 = kmem_zalloc(sizeof(*s90), KM_SLEEP);
119479c44acSchristos int error;
120479c44acSchristos
121479c44acSchristos statvfs_to_statvfs90(vs, s90);
1225a80c6a8Schristos error = copyout(s90, vs90, sizeof(*s90));
123d6527692Schristos kmem_free(s90, sizeof(*s90));
124479c44acSchristos
125479c44acSchristos return error;
126479c44acSchristos }
127479c44acSchristos #else
128479c44acSchristos
129479c44acSchristos #ifdef __LIBC12_SOURCE__
130479c44acSchristos
131479c44acSchristos int __compat_statvfs(const char *__restrict, struct statvfs90 *__restrict);
132479c44acSchristos int __compat_statvfs1(const char *__restrict, struct statvfs90 *__restrict,
133479c44acSchristos int);
134479c44acSchristos
135479c44acSchristos int __compat_fstatvfs(int, struct statvfs90 *);
136479c44acSchristos int __compat_fstatvfs1(int, struct statvfs90 *, int);
137479c44acSchristos
138479c44acSchristos int __compat___getmntinfo13(struct statvfs90 **, int);
139479c44acSchristos
140479c44acSchristos int __compat___fhstatvfs40(const void *, size_t, struct statvfs90 *);
141479c44acSchristos int __compat___fhstatvfs140(const void *, size_t, struct statvfs90 *, int);
142479c44acSchristos
143479c44acSchristos int __compat_getvfsstat(struct statvfs90 *, size_t, int);
144479c44acSchristos
145479c44acSchristos int __statvfs90(const char *__restrict, struct statvfs *__restrict);
146479c44acSchristos int __statvfs190(const char *__restrict, struct statvfs *__restrict, int);
147479c44acSchristos
148479c44acSchristos int __fstatvfs90(int, struct statvfs *);
149479c44acSchristos int __fstatvfs190(int, struct statvfs *, int);
150479c44acSchristos
151479c44acSchristos int __fhstatvfs90(const void *, size_t, struct statvfs *);
152479c44acSchristos int __fhstatvfs190(const void *, size_t, struct statvfs *, int);
153479c44acSchristos
154479c44acSchristos int __getvfsstat90(struct statvfs *, size_t, int);
155479c44acSchristos
156479c44acSchristos int __getmntinfo90(struct statvfs **, int);
157479c44acSchristos
158*ab413307Schristos struct compat_30_fhandle;
159*ab413307Schristos int fhstatvfs(const struct compat_30_fhandle *, struct statvfs90 *);
160*ab413307Schristos int fhstatvfs1(const struct compat_30_fhandle *, struct statvfs90 *, int);
161*ab413307Schristos
162479c44acSchristos #endif /* __LIBC12_SOURCE__ */
163479c44acSchristos
164479c44acSchristos #endif /* _KERNEL */
165479c44acSchristos
166479c44acSchristos __END_DECLS
167479c44acSchristos
168d6527692Schristos #endif /* !_COMPAT_SYS_STATVFS_H_ */
169