xref: /netbsd-src/external/bsd/am-utils/dist/conf/nfs_prot/nfs_prot_bsdi2.h (revision 46f5119e40af2e51998f686b2fdcc76b5488f7f3)
1 /*	$NetBSD: nfs_prot_bsdi2.h,v 1.1.1.2 2009/03/20 20:26:51 christos Exp $	*/
2 
3 /*
4  * Copyright (c) 1997-2009 Erez Zadok
5  * Copyright (c) 1990 Jan-Simon Pendry
6  * Copyright (c) 1990 Imperial College of Science, Technology & Medicine
7  * Copyright (c) 1990 The Regents of the University of California.
8  * All rights reserved.
9  *
10  * This code is derived from software contributed to Berkeley by
11  * Jan-Simon Pendry at Imperial College, London.
12  *
13  * Redistribution and use in source and binary forms, with or without
14  * modification, are permitted provided that the following conditions
15  * are met:
16  * 1. Redistributions of source code must retain the above copyright
17  *    notice, this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright
19  *    notice, this list of conditions and the following disclaimer in the
20  *    documentation and/or other materials provided with the distribution.
21  * 3. All advertising materials mentioning features or use of this software
22  *    must display the following acknowledgment:
23  *      This product includes software developed by the University of
24  *      California, Berkeley and its contributors.
25  * 4. Neither the name of the University nor the names of its contributors
26  *    may be used to endorse or promote products derived from this software
27  *    without specific prior written permission.
28  *
29  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
30  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
31  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
32  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
33  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
34  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
35  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
36  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
37  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
38  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39  * SUCH DAMAGE.
40  *
41  *
42  * File: am-utils/conf/nfs_prot/nfs_prot_bsdi2.h
43  *
44  */
45 
46 #ifndef _AMU_NFS_PROT_H
47 #define _AMU_NFS_PROT_H
48 
49 #ifdef HAVE_NFS_NFSV2_H
50 # include <nfs/nfsv2.h>
51 #endif /* HAVE_NFS_NFSV2_H */
52 #ifdef HAVE_NFS_RPCV2_H
53 # include <nfs/rpcv2.h>
54 #endif /* HAVE_NFS_RPCV2_H */
55 #ifdef HAVE_NFS_NFS_H
56 # include <nfs/nfs.h>
57 #endif /* HAVE_NFS_NFS_H */
58 #ifdef HAVE_SYS_FS_NFS_H
59 # include <sys/fs/nfs.h>
60 #endif /* HAVE_SYS_FS_NFS_H */
61 #ifdef HAVE_RPCSVC_MOUNT_H
62 # include <rpcsvc/mount.h>
63 #endif /* HAVE_RPCSVC_MOUNT_H */
64 
65 #ifdef HAVE_UFS_UFS_UFSMOUNT_H
66 # ifndef MAXQUOTAS
67 #  define MAXQUOTAS     2
68 # endif /* not MAXQUOTAS */
69 /* fake structure: too difficult to include other headers here */
70 struct netexport { int this_is_SO_wrong; };
71 # include <ufs/ufs/ufsmount.h>
72 #endif /* HAVE_UFS_UFS_UFSMOUNT_H */
73 
74 /*
75  * <msdosfs/msdosfsmount.h> is for kernel only on bsdi2, so do not
76  * include it.
77  */
78 #ifndef ____MSDOSFS_MSDOSFSMOUNT_H__
79 # define ____MSDOSFS_MSDOSFSMOUNT_H__
80 #endif /* ____MSDOSFS_MSDOSFSMOUNT_H__ */
81 
82 /*
83  * getifaddrs() on bsdi2 is broken.  Don't use it.
84  */
85 #ifdef HAVE_GETIFADDRS
86 # undef HAVE_GETIFADDRS
87 #endif /* HAVE_GETIFADDRS */
88 
89 
90 /*
91  * MACROS
92  */
93 
94 #define NFS_PORT 2049
95 #ifndef NFS_MAXDATA
96 # define NFS_MAXDATA 8192
97 #endif /* NFS_MAXDATA */
98 #define NFS_MAXPATHLEN 1024
99 #define NFS_MAXNAMLEN 255
100 #define NFS_FHSIZE 32
101 #define NFS_COOKIESIZE 4
102 #define	MNTPATHLEN 1024
103 #define	MNTNAMLEN 255
104 
105 #define NFSMODE_FMT 0170000
106 #define NFSMODE_DIR 0040000
107 #define NFSMODE_CHR 0020000
108 #define NFSMODE_BLK 0060000
109 #define NFSMODE_REG 0100000
110 #define NFSMODE_LNK 0120000
111 #define NFSMODE_SOCK 0140000
112 #define NFSMODE_FIFO 0010000
113 
114 #ifndef NFS_PROGRAM
115 # define NFS_PROGRAM ((u_long)100003)
116 #endif /* not NFS_PROGRAM */
117 #ifndef NFS_VERSION
118 # define NFS_VERSION ((u_long)2)
119 #endif /* not NFS_VERSION */
120 
121 /*
122  * BSD/OS 2.1 deprecated NFSPROC_ROOT and NFSPROC_WRITECACHE and set them
123  * to NFSPROC_NOOP.
124  * Since amd is its own NFS server, reinstate them.
125  */
126 #if (NFSPROC_ROOT == NFSPROC_NOOP)
127 # undef NFSPROC_ROOT
128 # define NFSPROC_ROOT 3
129 #endif /* (NFSPROC_ROOT == NFSPROC_NOOP) */
130 #if (NFSPROC_WRITECACHE == NFSPROC_NOOP)
131 # undef NFSPROC_WRITECACHE
132 # define NFSPROC_WRITECACHE 7
133 #endif /* (NFSPROC_WRITECACHE == NFSPROC_NOOP) */
134 
135 /* map field names */
136 #define ex_dir ex_name
137 #define gr_name g_name
138 #define gr_next g_next
139 #define ml_directory ml_path
140 #define ml_hostname ml_name
141 #define ml_next ml_nxt
142 #define fh_data fh_bytes
143 
144 /*
145  * TYPEDEFS:
146  */
147 typedef char *dirpath;
148 typedef char *filename;
149 typedef char *name;
150 typedef char *nfspath;
151 typedef char nfscookie[NFS_COOKIESIZE];
152 typedef nfstype nfsftype;
153 typedef enum nfsstat nfsstat;
154 typedef struct attrstat nfsattrstat;
155 typedef struct createargs nfscreateargs;
156 typedef struct dirlist nfsdirlist;
157 typedef struct diropargs nfsdiropargs;
158 typedef struct diropokres nfsdiropokres;
159 typedef struct diropres nfsdiropres;
160 typedef struct entry nfsentry;
161 typedef struct exports *exports;
162 typedef struct exports exportnode;
163 typedef struct fattr nfsfattr;
164 typedef struct fhstatus fhstatus;
165 typedef struct groups *groups;
166 typedef struct groups groupnode;
167 typedef struct linkargs nfslinkargs;
168 typedef struct mountlist *mountlist;
169 typedef struct mountlist mountbody;
170 typedef struct nfstime nfstime;
171 typedef struct readargs nfsreadargs;
172 typedef struct readdirargs nfsreaddirargs;
173 typedef struct readdirres nfsreaddirres;
174 typedef struct readlinkres nfsreadlinkres;
175 typedef struct readokres nfsreadokres;
176 typedef struct readres nfsreadres;
177 typedef struct renameargs nfsrenameargs;
178 typedef struct sattr nfssattr;
179 typedef struct sattrargs nfssattrargs;
180 typedef struct statfsokres nfsstatfsokres;
181 typedef struct statfsres nfsstatfsres;
182 typedef struct symlinkargs nfssymlinkargs;
183 typedef struct writeargs nfswriteargs;
184 
185 
186 /*
187  * EXTERNALS:
188  */
189 
190 extern nfsattrstat *nfsproc_getattr_2_svc(nfsv2fh_t *, struct svc_req *);
191 extern nfsattrstat *nfsproc_setattr_2_svc(nfssattrargs *, struct svc_req *);
192 extern nfsattrstat *nfsproc_write_2_svc(nfswriteargs *, struct svc_req *);
193 extern nfsdiropres *nfsproc_create_2_svc(nfscreateargs *, struct svc_req *);
194 extern nfsdiropres *nfsproc_lookup_2_svc(nfsdiropargs *, struct svc_req *);
195 extern nfsdiropres *nfsproc_mkdir_2_svc(nfscreateargs *, struct svc_req *);
196 extern nfsstat *nfsproc_link_2_svc(nfslinkargs *, struct svc_req *);
197 extern nfsstat *nfsproc_remove_2_svc(nfsdiropargs *, struct svc_req *);
198 extern nfsstat *nfsproc_rename_2_svc(nfsrenameargs *, struct svc_req *);
199 extern nfsstat *nfsproc_rmdir_2_svc(nfsdiropargs *, struct svc_req *);
200 extern nfsstat *nfsproc_symlink_2_svc(nfssymlinkargs *, struct svc_req *);
201 extern nfsreaddirres *nfsproc_readdir_2_svc(nfsreaddirargs *, struct svc_req *);
202 extern nfsreadlinkres *nfsproc_readlink_2_svc(nfsv2fh_t *, struct svc_req *);
203 extern nfsreadres *nfsproc_read_2_svc(nfsreadargs *, struct svc_req *);
204 extern nfsstatfsres *nfsproc_statfs_2_svc(nfsv2fh_t *, struct svc_req *);
205 extern void *nfsproc_null_2_svc(void *, struct svc_req *);
206 extern void *nfsproc_root_2_svc(void *, struct svc_req *);
207 extern void *nfsproc_writecache_2_svc(void *, struct svc_req *);
208 
209 extern bool_t xdr_attrstat(XDR *, nfsattrstat*);
210 extern bool_t xdr_createargs(XDR *, nfscreateargs*);
211 extern bool_t xdr_dirlist(XDR *, nfsdirlist*);
212 extern bool_t xdr_diropargs(XDR *, nfsdiropargs*);
213 extern bool_t xdr_diropokres(XDR *, nfsdiropokres*);
214 extern bool_t xdr_diropres(XDR *, nfsdiropres*);
215 extern bool_t xdr_entry(XDR *, nfsentry*);
216 extern bool_t xdr_fattr(XDR *, nfsfattr*);
217 extern bool_t xdr_filename(XDR *, filename*);
218 extern bool_t xdr_ftype(XDR *, nfsftype*);
219 extern bool_t xdr_linkargs(XDR *, nfslinkargs*);
220 extern bool_t xdr_mountlist(XDR *xdrs, mountlist *objp);
221 extern bool_t xdr_nfs_fh(XDR *, nfsv2fh_t*);
222 extern bool_t xdr_nfscookie(XDR *, nfscookie);
223 extern bool_t xdr_nfspath(XDR *, nfspath*);
224 extern bool_t xdr_nfsstat(XDR *, nfsstat*);
225 extern bool_t xdr_nfstime(XDR *, nfstime*);
226 extern bool_t xdr_readargs(XDR *, nfsreadargs*);
227 extern bool_t xdr_readdirargs(XDR *, nfsreaddirargs*);
228 extern bool_t xdr_readdirres(XDR *, nfsreaddirres*);
229 extern bool_t xdr_readlinkres(XDR *, nfsreadlinkres*);
230 extern bool_t xdr_readokres(XDR *, nfsreadokres*);
231 extern bool_t xdr_readres(XDR *, nfsreadres*);
232 extern bool_t xdr_renameargs(XDR *, nfsrenameargs*);
233 extern bool_t xdr_sattr(XDR *, nfssattr*);
234 extern bool_t xdr_sattrargs(XDR *, nfssattrargs*);
235 extern bool_t xdr_statfsokres(XDR *, nfsstatfsokres*);
236 extern bool_t xdr_statfsres(XDR *, nfsstatfsres*);
237 extern bool_t xdr_symlinkargs(XDR *, nfssymlinkargs*);
238 extern bool_t xdr_writeargs(XDR *, nfswriteargs*);
239 
240 
241 /*
242  * ENUMS:
243  */
244 
245 /*
246  * Use AMU_ prefixes so as to not conflict with #define's in <nfs/nfsv2.h>.
247  * It is vital! that the AMU_* match one-to-one with the NFS_OK and NFSERR_*
248  * codes listed in <nfs/nfsv2.h>.
249  */
250 enum nfsstat {
251   AMU_NFS_OK = 0,
252   AMU_NFSERR_PERM = 1,
253   AMU_NFSERR_NOENT = 2,
254   AMU_NFSERR_IO = 5,
255   AMU_NFSERR_NXIO = 6,
256   AMU_NFSERR_ACCES = 13,
257   AMU_NFSERR_EXIST = 17,
258   AMU_NFSERR_NODEV = 19,
259   AMU_NFSERR_NOTDIR = 20,
260   AMU_NFSERR_ISDIR = 21,
261   AMU_NFSERR_FBIG = 27,
262   AMU_NFSERR_NOSPC = 28,
263   AMU_NFSERR_ROFS = 30,
264   AMU_NFSERR_NAMETOOLONG = 63,
265   AMU_NFSERR_NOTEMPTY = 66,
266   AMU_NFSERR_DQUOT = 69,
267   AMU_NFSERR_STALE = 70,
268   AMU_NFSERR_WFLUSH = 99
269 };
270 
271 
272 /*
273  * STRUCTURES:
274  */
275 
276 struct nfstime {
277   u_int nt_seconds;
278   u_int nt_useconds;
279 };
280 
281 struct fattr {
282   nfsftype na_type;
283   u_int na_mode;
284   u_int na_nlink;
285   u_int na_uid;
286   u_int na_gid;
287   u_int na_size;
288   u_int na_blocksize;
289   u_int na_rdev;
290   u_int na_blocks;
291   u_int na_fsid;
292   u_int na_fileid;
293   nfstime na_atime;
294   nfstime na_mtime;
295   nfstime na_ctime;
296 };
297 
298 struct sattr {
299   u_int sa_mode;
300   u_int sa_uid;
301   u_int sa_gid;
302   u_int sa_size;
303   nfstime sa_atime;
304   nfstime sa_mtime;
305 };
306 
307 struct attrstat {
308   nfsstat ns_status;
309   union {
310     nfsfattr ns_attr_u;
311   } ns_u;
312 };
313 
314 struct sattrargs {
315   nfsv2fh_t sag_fhandle;
316   nfssattr sag_attributes;
317 };
318 
319 struct diropargs {
320   nfsv2fh_t da_fhandle;		/* was dir */
321   filename da_name;
322 };
323 
324 struct diropokres {
325   nfsv2fh_t drok_fhandle;
326   nfsfattr drok_attributes;
327 };
328 
329 struct diropres {
330   nfsstat dr_status;		/* was status */
331   union {
332     nfsdiropokres dr_drok_u;	/* was diropres */
333   } dr_u;			/* was diropres_u */
334 };
335 
336 struct readlinkres {
337   nfsstat rlr_status;
338   union {
339     nfspath rlr_data_u;
340   } rlr_u;
341 };
342 
343 struct readargs {
344   nfsv2fh_t ra_fhandle;
345   u_int ra_offset;
346   u_int ra_count;
347   u_int ra_totalcount;
348 };
349 
350 struct readokres {
351   nfsfattr raok_attributes;
352   struct {
353     u_int raok_len_u;
354     char *raok_val_u;
355   } raok_u;
356 };
357 
358 struct readres {
359   nfsstat rr_status;
360   union {
361     nfsreadokres rr_reply_u;
362   } rr_u;
363 };
364 
365 struct writeargs {
366   nfsv2fh_t wra_fhandle;
367   u_int wra_beginoffset;
368   u_int wra_offset;
369   u_int wra_totalcount;
370   struct {
371     u_int wra_len_u;
372     char *wra_val_u;
373   } wra_u;
374 };
375 
376 struct createargs {
377   nfsdiropargs ca_where;
378   nfssattr ca_attributes;
379 };
380 
381 struct renameargs {
382   nfsdiropargs rna_from;
383   nfsdiropargs rna_to;
384 };
385 
386 struct linkargs {
387   nfsv2fh_t la_fhandle;
388   nfsdiropargs la_to;
389 };
390 
391 struct symlinkargs {
392   nfsdiropargs sla_from;
393   nfspath sla_to;
394   nfssattr sla_attributes;
395 };
396 
397 struct readdirargs {
398   nfsv2fh_t rda_fhandle;
399   nfscookie rda_cookie;
400   u_int rda_count;
401 };
402 
403 struct entry {
404   u_int ne_fileid;
405   filename ne_name;
406   nfscookie ne_cookie;
407   nfsentry *ne_nextentry;
408 };
409 
410 struct dirlist {
411   nfsentry *dl_entries;
412   bool_t dl_eof;
413 };
414 
415 struct readdirres {
416   nfsstat rdr_status;
417   union {
418     nfsdirlist rdr_reply_u;
419   } rdr_u;
420 };
421 
422 struct statfsokres {
423   u_int sfrok_tsize;
424   u_int sfrok_bsize;
425   u_int sfrok_blocks;
426   u_int sfrok_bfree;
427   u_int sfrok_bavail;
428 };
429 
430 struct statfsres {
431   nfsstat sfr_status;
432   union {
433     nfsstatfsokres sfr_reply_u;
434   } sfr_u;
435 };
436 
437 
438 /****************************************************************************/
439 /*** XDR ADDITIONS                                                        ***/
440 /****************************************************************************/
441 
442 struct exports {
443   dirpath ex_dir;
444   groups ex_groups;
445   exports ex_next;
446 };
447 
448 typedef char fhandle[NFS_FHSIZE];
449 
450 struct fhstatus {
451   u_int fhs_status;
452   union {
453     fhandle fhs_fhandle;
454   } fhstatus_u;
455 };
456 
457 struct groups {
458   name gr_name;
459   groups gr_next;
460 };
461 
462 struct mountlist {
463   name ml_hostname;
464   dirpath ml_directory;
465   mountlist ml_next;
466 };
467 
468 
469 /****************************************************************************/
470 /*** NFS ADDITIONS                                                        ***/
471 /****************************************************************************/
472 
473 #ifndef MOUNTPROG
474 # define MOUNTPROG RPCPROG_MNT
475 #endif /* not MOUNTPROG */
476 
477 #ifndef MOUNTVERS
478 # define MOUNTVERS RPCMNT_VER1
479 #endif /* not MOUNTVERS */
480 
481 #ifndef MOUNTPROC_MNT
482 # define MOUNTPROC_MNT RPCMNT_MOUNT
483 #endif /* not MOUNTPROC_MNT */
484 
485 #ifndef MOUNTPROC_DUMP
486 # define MOUNTPROC_DUMP RPCMNT_DUMP
487 #endif /* not MOUNTPROC_DUMP */
488 
489 #ifndef MOUNTPROC_UMNT
490 # define MOUNTPROC_UMNT RPCMNT_UMOUNT
491 #endif /* not MOUNTPROC_UMNT */
492 
493 #ifndef MOUNTPROC_UMNTALL
494 # define MOUNTPROC_UMNTALL RPCMNT_UMNTALL
495 #endif /* not MOUNTPROC_UMNTALL */
496 
497 #ifndef MOUNTPROC_EXPORT
498 # define MOUNTPROC_EXPORT RPCMNT_EXPORT
499 #endif /* not MOUNTPROC_EXPORT */
500 
501 
502 #endif /* not _AMU_NFS_PROT_H */
503