1 /*        $NetBSD: statvfs.h,v 1.21 2020/07/03 19:37:27 jdolecek Exp $           */
2 
3 /*-
4  * Copyright (c) 2004 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   _SYS_STATVFS_H_
33 #define   _SYS_STATVFS_H_
34 
35 #include <sys/cdefs.h>
36 #include <sys/featuretest.h>
37 #include <sys/stdint.h>
38 #include <machine/ansi.h>
39 #include <sys/ansi.h>
40 #include <sys/fstypes.h>
41 
42 #define   _VFS_NAMELEN        32
43 #define   _VFS_MNAMELEN       1024
44 
45 #ifndef   fsblkcnt_t
46 typedef   __fsblkcnt_t        fsblkcnt_t;         /* fs block count (statvfs) */
47 #define   fsblkcnt_t          __fsblkcnt_t
48 #endif
49 
50 #ifndef   fsfilcnt_t
51 typedef   __fsfilcnt_t        fsfilcnt_t;         /* fs file count */
52 #define   fsfilcnt_t          __fsfilcnt_t
53 #endif
54 
55 #ifndef   uid_t
56 typedef   __uid_t             uid_t;              /* user id */
57 #define   uid_t               __uid_t
58 #endif
59 
60 #ifdef    _BSD_SIZE_T_
61 typedef   _BSD_SIZE_T_                  size_t;
62 #define   _SIZE_T
63 #undef    _BSD_SIZE_T_
64 #endif
65 
66 struct statvfs {
67           unsigned long       f_flag;             /* copy of mount exported flags */
68           unsigned long       f_bsize;  /* file system block size */
69           unsigned long       f_frsize; /* fundamental file system block size */
70           unsigned long       f_iosize; /* optimal file system block size */
71 
72           /* The following are in units of f_frsize */
73           fsblkcnt_t          f_blocks; /* number of blocks in file system, */
74           fsblkcnt_t          f_bfree;  /* free blocks avail in file system */
75           fsblkcnt_t          f_bavail; /* free blocks avail to non-root */
76           fsblkcnt_t          f_bresvd; /* blocks reserved for root */
77 
78           fsfilcnt_t          f_files;  /* total file nodes in file system */
79           fsfilcnt_t          f_ffree;  /* free file nodes in file system */
80           fsfilcnt_t          f_favail; /* free file nodes avail to non-root */
81           fsfilcnt_t          f_fresvd; /* file nodes reserved for root */
82 
83           uint64_t            f_syncreads;        /* count of sync reads since mount */
84           uint64_t            f_syncwrites;       /* count of sync writes since mount */
85 
86           uint64_t            f_asyncreads;       /* count of async reads since mount */
87           uint64_t            f_asyncwrites;      /* count of async writes since mount */
88 
89           fsid_t              f_fsidx;  /* NetBSD compatible fsid */
90           unsigned long       f_fsid;             /* Posix compatible fsid */
91           unsigned long       f_namemax;          /* maximum filename length */
92           uid_t               f_owner;  /* user that mounted the file system */
93 
94           uint64_t  f_spare[4];         /* spare space */
95 
96           char      f_fstypename[_VFS_NAMELEN];   /* fs type name */
97           char      f_mntonname[_VFS_MNAMELEN];   /* directory on which mounted */
98           char      f_mntfromname[_VFS_MNAMELEN]; /* mounted file system */
99           char      f_mntfromlabel[_VFS_MNAMELEN];  /* disk label name if avail */
100 
101 };
102 
103 #if defined(_NETBSD_SOURCE) && !defined(_POSIX_SOURCE) && \
104     !defined(_XOPEN_SOURCE)
105 #define   VFS_NAMELEN         _VFS_NAMELEN
106 #define   VFS_MNAMELEN        _VFS_MNAMELEN
107 #endif
108 
109 #define   ST_RDONLY MNT_RDONLY
110 #define   ST_SYNCHRONOUS      MNT_SYNCHRONOUS
111 #define   ST_NOEXEC MNT_NOEXEC
112 #define   ST_NOSUID MNT_NOSUID
113 #define   ST_NODEV  MNT_NODEV
114 #define   ST_UNION  MNT_UNION
115 #define   ST_ASYNC  MNT_ASYNC
116 #define   ST_ACLS             MNT_ACLS
117 #define   ST_NOCOREDUMP       MNT_NOCOREDUMP
118 #define   ST_RELATIME         MNT_RELATIME
119 #define   ST_IGNORE MNT_IGNORE
120 #define   ST_NOATIME          MNT_NOATIME
121 #define   ST_SYMPERM          MNT_SYMPERM
122 #define   ST_NODEVMTIME       MNT_NODEVMTIME
123 #define   ST_SOFTDEP          MNT_SOFTDEP
124 #define   ST_LOG              MNT_LOG
125 #define   ST_EXTATTR          MNT_EXTATTR
126 
127 #define   ST_EXRDONLY         MNT_EXRDONLY
128 #define   ST_EXPORTED         MNT_EXPORTED
129 #define   ST_DEFEXPORTED      MNT_DEFEXPORTED
130 #define   ST_EXPORTANON       MNT_EXPORTANON
131 #define   ST_EXKERB MNT_EXKERB
132 #define   ST_EXNORESPORT      MNT_EXNORESPORT
133 #define   ST_EXPUBLIC         MNT_EXPUBLIC
134 
135 #define   ST_LOCAL  MNT_LOCAL
136 #define   ST_QUOTA  MNT_QUOTA
137 #define   ST_ROOTFS MNT_ROOTFS
138 
139 
140 #define   ST_WAIT             MNT_WAIT
141 #define   ST_NOWAIT MNT_NOWAIT
142 
143 #if defined(_KERNEL) || defined(_STANDALONE)
144 struct mount;
145 struct lwp;
146 
147 int       set_statvfs_info(const char *, int, const char *, int,
148     const char *, struct mount *, struct lwp *);
149 void      copy_statvfs_info(struct statvfs *, const struct mount *);
150 int       dostatvfs(struct mount *, struct statvfs *, struct lwp *, int, int);
151 
152 #include <sys/kmem.h>
153 #define   STATVFSBUF_GET()    \
154           (struct statvfs *)kmem_zalloc(sizeof(struct statvfs), KM_SLEEP)
155 #define   STATVFSBUF_PUT(sb)  kmem_free(sb, sizeof(struct statvfs))
156 
157 #else
158 __BEGIN_DECLS
159 #ifndef __LIBC12_SOURCE__
160 int       getmntinfo(struct statvfs **, int)
161     __RENAME(__getmntinfo90);
162 
163 int       statvfs(const char *__restrict, struct statvfs *__restrict)
164     __RENAME(__statvfs90);
165 int       fstatvfs(int, struct statvfs *)
166     __RENAME(__fstatvfs90);
167 int       getvfsstat(struct statvfs *, size_t, int)
168     __RENAME(__getvfsstat90);
169 
170 #if defined(_NETBSD_SOURCE)
171 int       fhstatvfs(const void *, size_t, struct statvfs *)
172     __RENAME(__fhstatvfs90);
173 int       statvfs1(const char *__restrict, struct statvfs *__restrict, int)
174     __RENAME(__statvfs190);
175 int       fstatvfs1(int, struct statvfs *, int)
176     __RENAME(__fstatvfs190);
177 int       fhstatvfs1(const void *, size_t, struct statvfs *, int)
178     __RENAME(__fhstatvfs190);
179 #endif /* _NETBSD_SOURCE */
180 #endif /* __LIBC12_SOURCE__ */
181 __END_DECLS
182 #endif /* _KERNEL || _STANDALONE */
183 
184 #endif /* !_SYS_STATVFS_H_ */
185