1 //Written in the D programming language
2 
3 /++
4     D header file for FreeBSD's sys/mount.h.
5 
6     Copyright: Copyright 2018 -
7     License:   $(HTTP www.boost.org/LICENSE_1_0.txt, Boost License 1.0).
8     Authors:   $(HTTP jmdavisprog.com, Jonathan M Davis)
9  +/
10 module core.sys.freebsd.sys.mount;
11 
12 version (FreeBSD):
13 
14 import core.sys.freebsd.config;
15 import core.stdc.config : c_long;
16 import core.sys.posix.sys.stat : stat_t;
17 import core.sys.posix.sys.types : uid_t;
18 
19 extern(C) @nogc nothrow:
20 
21 struct fsid_t
22 {
23     int[2] val;
24 }
25 
26 enum MAXFIDSZ = 16;
27 
28 struct fid
29 {
30     ushort         fid_len;
31     ushort         fid_data0;
32     char[MAXFIDSZ] fid_data = 0;
33 }
34 
35 enum MFSNAMELEN = 16;
36 
37 static if (__FreeBSD_version >= 1200000)
38 {
39     enum MNAMELEN   = 1024;
40     enum STATFS_VERSION = 0x20140518;
41 }
42 else
43 {
44     enum MNAMELEN   = 88;
45     enum STATFS_VERSION = 0x20030518;
46 }
47 
48 struct statfs_t
49 {
50     uint f_version;
51     uint f_type;
52     ulong f_flags;
53     ulong f_bsize;
54     ulong f_iosize;
55     ulong f_blocks;
56     ulong f_bfree;
57     long  f_bavail;
58     ulong f_files;
59     long  f_ffree;
60     ulong f_syncwrites;
61     ulong f_asyncwrites;
62     ulong f_syncreads;
63     ulong f_asyncreads;
64     ulong[10] f_spare;
65     uint f_namemax;
66     uid_t f_owner;
67     fsid_t f_fsid;
68     char[80] f_charspare = 0;
69     char[MFSNAMELEN] f_fstypename = 0;
70     char[MNAMELEN] f_mntfromname = 0;
71     char[MNAMELEN] f_mntonname = 0;
72 }
73 
74 
75 enum ulong MNT_RDONLY = 0x0000000000000001;
76 enum ulong MNT_SYNCHRONOUS = 0x0000000000000002;
77 enum ulong MNT_NOEXEC = 0x0000000000000004;
78 enum ulong MNT_NOSUID = 0x0000000000000008;
79 enum ulong MNT_NFS4ACLS = 0x0000000000000010;
80 enum ulong MNT_UNION = 0x0000000000000020;
81 enum ulong MNT_ASYNC = 0x0000000000000040;
82 enum ulong MNT_SUIDDIR = 0x0000000000100000;
83 enum ulong MNT_SOFTDEP = 0x0000000000200000;
84 enum ulong MNT_NOSYMFOLLOW = 0x0000000000400000;
85 enum ulong MNT_GJOURNAL = 0x0000000002000000;
86 enum ulong MNT_MULTILABEL = 0x0000000004000000;
87 enum ulong MNT_ACLS = 0x0000000008000000;
88 enum ulong MNT_NOATIME = 0x0000000010000000;
89 enum ulong MNT_NOCLUSTERR = 0x0000000040000000;
90 enum ulong MNT_NOCLUSTERW = 0x0000000080000000;
91 enum ulong MNT_SUJ = 0x0000000100000000;
92 enum ulong MNT_AUTOMOUNTED = 0x0000000200000000;
93 
94 enum ulong MNT_EXRDONLY = 0x0000000000000080;
95 enum ulong MNT_EXPORTED = 0x0000000000000100;
96 enum ulong MNT_DEFEXPORTED = 0x0000000000000200;
97 enum ulong MNT_EXPORTANON = 0x0000000000000400;
98 enum ulong MNT_EXKERB = 0x0000000000000800;
99 enum ulong MNT_EXPUBLIC = 0x0000000020000000;
100 
101 enum ulong MNT_LOCAL  = 0x0000000000001000;
102 enum ulong MNT_QUOTA  = 0x0000000000002000;
103 enum ulong MNT_ROOTFS = 0x0000000000004000;
104 enum ulong MNT_USER   = 0x0000000000008000;
105 enum ulong MNT_IGNORE = 0x0000000000800000;
106 
107 enum MNT_VISFLAGMASK = MNT_RDONLY | MNT_SYNCHRONOUS | MNT_NOEXEC |
108                        MNT_NOSUID | MNT_UNION | MNT_SUJ |
109                        MNT_ASYNC | MNT_EXRDONLY  | MNT_EXPORTED |
110                        MNT_DEFEXPORTED | MNT_EXPORTANON| MNT_EXKERB |
111                        MNT_LOCAL | MNT_USER  | MNT_QUOTA |
112                        MNT_ROOTFS | MNT_NOATIME   | MNT_NOCLUSTERR |
113                        MNT_NOCLUSTERW | MNT_SUIDDIR | MNT_SOFTDEP |
114                        MNT_IGNORE | MNT_EXPUBLIC  | MNT_NOSYMFOLLOW |
115                        MNT_GJOURNAL | MNT_MULTILABEL | MNT_ACLS |
116                        MNT_NFS4ACLS | MNT_AUTOMOUNTED;
117 
118 enum MNT_UPDATEMASK = MNT_NOSUID | MNT_NOEXEC |
119                       MNT_SYNCHRONOUS | MNT_UNION | MNT_ASYNC |
120                       MNT_NOATIME |
121                       MNT_NOSYMFOLLOW | MNT_IGNORE |
122                       MNT_NOCLUSTERR | MNT_NOCLUSTERW | MNT_SUIDDIR |
123                       MNT_ACLS | MNT_USER | MNT_NFS4ACLS  |
124                       MNT_AUTOMOUNTED;
125 
126 enum ulong MNT_UPDATE = 0x0000000000010000;
127 enum ulong MNT_DELEXPORT = 0x0000000000020000;
128 enum ulong MNT_RELOAD = 0x0000000000040000;
129 enum ulong MNT_FORCE = 0x0000000000080000;
130 enum ulong MNT_SNAPSHOT = 0x0000000001000000;
131 enum ulong MNT_NONBUSY = 0x0000000004000000;
132 enum ulong MNT_BYFSID = 0x0000000008000000;
133 enum ulong MNT_CMDFLAGS = MNT_UPDATE | MNT_DELEXPORT | MNT_RELOAD |
134                           MNT_FORCE  | MNT_SNAPSHOT  | MNT_NONBUSY |
135                           MNT_BYFSID;
136 
137 enum uint MNTK_UNMOUNTF = 0x00000001;
138 enum uint MNTK_ASYNC = 0x00000002;
139 enum uint MNTK_SOFTDEP = 0x00000004;
140 enum uint MNTK_NOINSMNTQ = 0x00000008;
141 enum uint MNTK_DRAINING = 0x00000010;
142 enum uint MNTK_REFEXPIRE = 0x00000020;
143 enum uint MNTK_EXTENDED_SHARED = 0x00000040;
144 enum uint MNTK_SHARED_WRITES = 0x00000080;
145 enum uint MNTK_NO_IOPF = 0x00000100;
146 enum uint MNTK_VGONE_UPPER = 0x00000200;
147 enum uint MNTK_VGONE_WAITER = 0x00000400;
148 enum uint MNTK_LOOKUP_EXCL_DOTDOT = 0x00000800;
149 enum uint MNTK_MARKER = 0x00001000;
150 enum uint MNTK_UNMAPPED_BUFS = 0x00002000;
151 enum uint MNTK_USES_BCACHE = 0x00004000;
152 enum uint MNTK_NOASYNC = 0x00800000;
153 enum uint MNTK_UNMOUNT = 0x01000000;
154 enum uint MNTK_MWAIT = 0x02000000;
155 enum uint MNTK_SUSPEND = 0x08000000;
156 enum uint MNTK_SUSPEND2 = 0x04000000;
157 enum uint MNTK_SUSPENDED = 0x10000000;
158 enum uint MNTK_NULL_NOCACHE = 0x20000000;
159 enum uint MNTK_LOOKUP_SHARED = 0x40000000;
160 enum uint MNTK_NOKNOTE = 0x80000000;
161 
162 enum VFS_VFSCONF = 0;
163 enum VFS_GENERIC = 0;
164 
165 enum VFS_MAXTYPENUM = 1;
166 enum VFS_CONF       = 2;
167 
168 enum MNT_WAIT    = 1;
169 enum MNT_NOWAIT  = 2;
170 enum MNT_LAZY    = 3;
171 enum MNT_SUSPEND = 4;
172 
173 struct fhandle_t
174 {
175     fsid_t fh_fsid;
176     fid fh_fid;
177 }
178 
179 // TODO - requires declarations from elsewhere that we don't currently have bindings for.
180 /+
181 struct oexport_args
182 {
183     int ex_flags;
184     uid_t ex_root;
185     xucred ex_anon;
186     sockaddr* ex_addr;
187     ubyte ex_addrlen;
188     sockaddr* ex_mask;
189     ubyte ex_masklen;
190     char* ex_indexfile;
191 }
192 
193 enum MAXSECFLAVORS = 5;
194 
195 struct export_args
196 {
197     int ex_flags;
198     uid_t ex_root;
199     xucred ex_anon;
200     sockaddr* ex_addr;
201     ubyte ex_addrlen;
202     sockaddr* ex_mask;
203     ubyte ex_masklen;
204     char* ex_indexfile;
205     int ex_numsecflavors;
206     int[MAXSECFLAVORS] ex_secflavors;
207 }
208 
209 struct nfs_public
210 {
211     int np_valid;
212     fhandle_t np_handle;
213     mount_t* np_mount;
214     char* np_index;
215 }
216 
217 struct vfsconf
218 {
219     uint vfc_version;
220     char[MFSNAMELEN] vfc_name = 0;
221     vfsops* vfc_vfsops;
222     int vfc_typenum;
223     int vfc_refcount;
224     int vfc_flags;
225     vfsoptdecl* vfc_opts;
226     TAILQ_ENTRY(vfsconf) vfc_list;
227 }
228 
229 struct xvfsconf
230 {
231     vfsops* vfc_vfsops;
232     char[MFSNAMELEN] vfc_name = 0;
233     int vfc_typenum;
234     int vfc_refcount;
235     int vfc_flags;
236     vfsconf* vfc_next;
237 }
238 +/
239 
240 struct ovfsconf
241 {
242     void* vfc_vfsops;
243     char[32] vfc_name = 0;
244     int vfc_index;
245     int vfc_refcount;
246     int vfc_flags;
247 }
248 
249 enum uint VFCF_STATIC = 0x00010000;
250 enum uint VFCF_NETWORK = 0x00020000;
251 enum uint VFCF_READONLY = 0x00040000;
252 enum uint VFCF_SYNTHETIC = 0x00080000;
253 enum uint VFCF_LOOPBACK = 0x00100000;
254 enum uint VFCF_UNICODE = 0x00200000;
255 enum uint VFCF_JAIL = 0x00400000;
256 enum uint VFCF_DELEGADMIN = 0x00800000;
257 enum uint VFCF_SBDRY = 0x01000000;
258 
259 alias fsctlop_t = uint;
260 
261 struct vfsidctl
262 {
263     int vc_vers;
264     fsid_t vc_fsid;
265     char[MFSNAMELEN] vc_fstypename = 0;
266     fsctlop_t vc_op;
267     void* vc_ptr;
268     size_t vc_len;
269     uint[12] vc_spare;
270 }
271 
272 enum uint VFS_CTL_VERS1 = 0x01;
273 
274 enum uint VFS_CTL_QUERY   = 0x00010001;
275 enum uint VFS_CTL_TIMEO   = 0x00010002;
276 enum uint VFS_CTL_NOLOCKS = 0x00010003;
277 
278 struct vfsquery
279 {
280     uint vq_flags;
281     uint[31] vq_spare;
282 }
283 
284 enum uint VQ_NOTRESP  = 0x0001;
285 enum uint VQ_NEEDAUTH = 0x0002;
286 enum uint VQ_LOWDISK  = 0x0004;
287 enum uint VQ_MOUNT    = 0x0008;
288 enum uint VQ_UNMOUNT  = 0x0010;
289 enum uint VQ_DEAD     = 0x0020;
290 enum uint VQ_ASSIST   = 0x0040;
291 enum uint VQ_NOTRESPLOCK = 0x0080;
292 enum uint VQ_FLAG0100 = 0x0100;
293 enum uint VQ_FLAG0200 = 0x0200;
294 enum uint VQ_FLAG0400 = 0x0400;
295 enum uint VQ_FLAG0800 = 0x0800;
296 enum uint VQ_FLAG1000 = 0x1000;
297 enum uint VQ_FLAG2000 = 0x2000;
298 enum uint VQ_FLAG4000 = 0x4000;
299 enum uint VQ_FLAG8000 = 0x8000;
300 
301 version (GNU)
302 {
303     int fhopen(const fhandle_t*, int);
304     int fhstat(const fhandle_t*, stat_t*);
305     int fhstatfs(const fhandle_t*, statfs_t*);
306     int fstatfs(int, statfs_t*);
307     int getfh(const char*, fhandle_t*);
308     int getfsstat(statfs_t*, c_long, int);
309     int getmntinfo(statfs_t**, int);
310     int lgetfh(const char*, fhandle_t*);
311     int mount(const char*, const char*, int, void*);
312     //int nmount(iovec*, uint, int);
313     int statfs(const char*, statfs_t*);
314     int unmount(const char*, int);
315     //int getvfsbyname(const char*, xvfsconf*);
316 }
317 else
318 {
319     static if (__FreeBSD_version >= 1200000)
320     {
321         pragma(mangle, "fhstat@FBSD_1.5")     int fhstat(const fhandle_t*, stat_t*);
322         pragma(mangle, "fhstatfs@FBSD_1.5")   int fhstatfs(const fhandle_t*, statfs_t*);
323         pragma(mangle, "fstatfs@FBSD_1.5")    int fstatfs(int, statfs_t*);
324         pragma(mangle, "getfsstat@FBSD_1.5")  int getfsstat(statfs_t*, c_long, int);
325         pragma(mangle, "getmntinfo@FBSD_1.5") int getmntinfo(statfs_t**, int);
326         pragma(mangle, "statfs@FBSD_1.5")     int statfs(const char*, statfs_t*);
327     }
328     else
329     {
330         pragma(mangle, "fhstat@FBSD_1.0")     int fhstat(const fhandle_t*, stat_t*);
331         pragma(mangle, "fhstatfs@FBSD_1.0")   int fhstatfs(const fhandle_t*, statfs_t*);
332         pragma(mangle, "fstatfs@FBSD_1.0")    int fstatfs(int, statfs_t*);
333         pragma(mangle, "getfsstat@FBSD_1.0")  int getfsstat(statfs_t*, c_long, int);
334         pragma(mangle, "getmntinfo@FBSD_1.0") int getmntinfo(statfs_t**, int);
335         pragma(mangle, "statfs@FBSD_1.0")     int statfs(const char*, statfs_t*);
336     }
337     pragma(mangle, "fhopen@@FBSD_1.0")        int fhopen(const fhandle_t*, int);
338     pragma(mangle, "getfh@@FBSD_1.0")         int getfh(const char*, fhandle_t*);
339     pragma(mangle, "lgetfh@@FBSD_1.0")        int lgetfh(const char*, fhandle_t*);
340     pragma(mangle, "mount@@FBSD_1.0")         int mount(const char*, const char*, int, void*);
341     //int nmount(iovec*, uint, int);
342     pragma(mangle, "unmount@@FBSD_1.0")       int unmount(const char*, int);
343     //int getvfsbyname(const char*, xvfsconf*);
344 }