1 /*	$NetBSD: nfs_prot_ncr2.h,v 1.1.1.3 2015/01/17 16:34:16 christos Exp $	*/
2 
3 /*
4  * Copyright (c) 1997-2014 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. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *
38  * File: am-utils/conf/nfs_prot/nfs_prot_ncr2.h
39  *
40  */
41 
42 #ifndef _AMU_NFS_PROT_H
43 #define _AMU_NFS_PROT_H
44 
45 /*
46  * Do NOT include <rpcsvc/nfs_prot.h> to get NFS V2 specs, because
47  * it will result in conflicts with <nfs/nfs.h>.  The latter is a must
48  * for NFS V3 specs.
49  */
50 
51 #ifdef HAVE_NFS_NFS_H
52 # include <nfs/nfs.h>
53 #endif /* HAVE_NFS_NFS_H */
54 
55 #ifdef HAVE_RPCSVC_MOUNT_H
56 # include <rpcsvc/mount.h>
57 #endif /* HAVE_RPCSVC_MOUNT_H */
58 
59 #ifdef HAVE_RPC_RPC_H
60 # include <rpc/rpc.h>
61 #endif /* HAVE_RPC_RPC_H */
62 
63 
64 /*
65  * MACROS
66  */
67 
68 /* ncr2 does not define this one!  Incredible */
69 #ifndef MNTTYPE_NFS
70 # define MNTTYPE_NFS "nfs"
71 #endif /* MNTTYPE_NFS */
72 
73 #define	NFS_PORT 2049
74 #define	NFS_MAXDATA 8192
75 #define	NFS_MAXPATHLEN 1024
76 #define	NFS_MAXNAMLEN 255
77 #define	NFS_FHSIZE 32
78 #define	NFS_COOKIESIZE 4
79 
80 #define	NFSMODE_FMT 0170000
81 #define	NFSMODE_DIR 0040000
82 #define	NFSMODE_CHR 0020000
83 #define	NFSMODE_BLK 0060000
84 #define	NFSMODE_REG 0100000
85 #define	NFSMODE_LNK 0120000
86 #define	NFSMODE_SOCK 0140000
87 #define	NFSMODE_FIFO 0010000
88 
89 #define	NFSPROC_NULL ((unsigned long)(0))
90 #define	NFSPROC_GETATTR ((unsigned long)(1))
91 #define	NFSPROC_SETATTR ((unsigned long)(2))
92 #define	NFSPROC_ROOT ((unsigned long)(3))
93 #define	NFSPROC_LOOKUP ((unsigned long)(4))
94 #define	NFSPROC_READLINK ((unsigned long)(5))
95 #define	NFSPROC_READ ((unsigned long)(6))
96 #define	NFSPROC_WRITECACHE ((unsigned long)(7))
97 #define	NFSPROC_WRITE ((unsigned long)(8))
98 #define	NFSPROC_CREATE ((unsigned long)(9))
99 #define	NFSPROC_REMOVE ((unsigned long)(10))
100 #define	NFSPROC_RENAME ((unsigned long)(11))
101 #define	NFSPROC_LINK ((unsigned long)(12))
102 #define	NFSPROC_SYMLINK ((unsigned long)(13))
103 #define	NFSPROC_MKDIR ((unsigned long)(14))
104 #define	NFSPROC_RMDIR ((unsigned long)(15))
105 #define	NFSPROC_READDIR ((unsigned long)(16))
106 #define	NFSPROC_STATFS ((unsigned long)(17))
107 
108 /* map field names */
109 #define ml_hostname ml_name
110 #define ml_directory ml_path
111 #define ml_next ml_nxt
112 #define gr_next g_next
113 #define gr_name g_name
114 #define ex_dir ex_name
115 
116 /*
117  * TYPEDEFS:
118  */
119 typedef char *dirpath;
120 typedef char *filename;
121 typedef char *nfspath;
122 typedef char nfscookie[NFS_COOKIESIZE];
123 typedef enum nfsftype nfsftype;
124 typedef enum nfsstat nfsstat;
125 typedef struct attrstat nfsattrstat;
126 typedef struct createargs nfscreateargs;
127 typedef struct dirlist nfsdirlist;
128 typedef struct diropargs nfsdiropargs;
129 typedef struct diropokres nfsdiropokres;
130 typedef struct diropres nfsdiropres;
131 typedef struct entry nfsentry;
132 typedef struct fattr nfsfattr;
133 typedef struct linkargs nfslinkargs;
134 typedef struct nfs_fh nfs_fh;
135 typedef struct nfstime nfstime;
136 typedef struct readargs nfsreadargs;
137 typedef struct readdirargs nfsreaddirargs;
138 typedef struct readdirres nfsreaddirres;
139 typedef struct readlinkres nfsreadlinkres;
140 typedef struct readokres nfsreadokres;
141 typedef struct readres nfsreadres;
142 typedef struct renameargs nfsrenameargs;
143 typedef struct sattr nfssattr;
144 typedef struct sattrargs nfssattrargs;
145 typedef struct statfsokres nfsstatfsokres;
146 typedef struct statfsres nfsstatfsres;
147 typedef struct symlinkargs nfssymlinkargs;
148 typedef struct writeargs nfswriteargs;
149 
150 typedef char *name;
151 typedef fhandle_t fhandle;
152 typedef struct exports *exports;
153 typedef struct exports exportnode;
154 typedef struct fhstatus fhstatus;
155 typedef struct groups *groups;
156 typedef struct groups groupnode;
157 typedef struct mountlist *mountlist;
158 typedef struct mountlist mountbody;
159 
160 
161 /*
162  * EXTERNALS:
163  */
164 
165 extern bool_t xdr_nfsstat(XDR *, nfsstat *);
166 extern bool_t xdr_ftype(XDR *, nfsftype *);
167 extern bool_t xdr_nfs_fh(XDR *, nfs_fh *);
168 extern bool_t xdr_nfstime(XDR *, nfstime *);
169 extern bool_t xdr_fattr(XDR *, nfsfattr *);
170 extern bool_t xdr_sattr(XDR *, nfssattr *);
171 extern bool_t xdr_filename(XDR *, filename *);
172 extern bool_t xdr_nfspath(XDR *, nfspath *);
173 extern bool_t xdr_attrstat(XDR *, nfsattrstat *);
174 extern bool_t xdr_sattrargs(XDR *, nfssattrargs *);
175 extern bool_t xdr_diropargs(XDR *, nfsdiropargs *);
176 extern bool_t xdr_diropokres(XDR *, nfsdiropokres *);
177 extern bool_t xdr_diropres(XDR *, nfsdiropres *);
178 extern bool_t xdr_readlinkres(XDR *, nfsreadlinkres *);
179 extern bool_t xdr_readargs(XDR *, nfsreadargs *);
180 extern bool_t xdr_readokres(XDR *, nfsreadokres *);
181 extern bool_t xdr_readres(XDR *, nfsreadres *);
182 extern bool_t xdr_writeargs(XDR *, nfswriteargs *);
183 extern bool_t xdr_createargs(XDR *, nfscreateargs *);
184 extern bool_t xdr_renameargs(XDR *, nfsrenameargs *);
185 extern bool_t xdr_linkargs(XDR *, nfslinkargs *);
186 extern bool_t xdr_symlinkargs(XDR *, nfssymlinkargs *);
187 extern bool_t xdr_nfscookie(XDR *, nfscookie);
188 extern bool_t xdr_readdirargs(XDR *, nfsreaddirargs *);
189 extern bool_t xdr_entry(XDR *, nfsentry *);
190 extern bool_t xdr_dirlist(XDR *, nfsdirlist *);
191 extern bool_t xdr_readdirres(XDR *, nfsreaddirres *);
192 extern bool_t xdr_statfsokres(XDR *, nfsstatfsokres *);
193 extern bool_t xdr_statfsres(XDR *, nfsstatfsres *);
194 
195 extern nfsattrstat *nfsproc_getattr_2(nfs_fh *, CLIENT *);
196 extern nfsattrstat *nfsproc_getattr_2_svc(nfs_fh *, struct svc_req *);
197 extern nfsattrstat *nfsproc_setattr_2(nfssattrargs *, CLIENT *);
198 extern nfsattrstat *nfsproc_setattr_2_svc(nfssattrargs *, struct svc_req *);
199 extern nfsattrstat *nfsproc_write_2(nfswriteargs *, CLIENT *);
200 extern nfsattrstat *nfsproc_write_2_svc(nfswriteargs *, struct svc_req *);
201 extern nfsdiropres *nfsproc_create_2(nfscreateargs *, CLIENT *);
202 extern nfsdiropres *nfsproc_create_2_svc(nfscreateargs *, struct svc_req *);
203 extern nfsdiropres *nfsproc_lookup_2(nfsdiropargs *, CLIENT *);
204 extern nfsdiropres *nfsproc_lookup_2_svc(nfsdiropargs *, struct svc_req *);
205 extern nfsdiropres *nfsproc_mkdir_2(nfscreateargs *, CLIENT *);
206 extern nfsdiropres *nfsproc_mkdir_2_svc(nfscreateargs *, struct svc_req *);
207 extern nfsstat *nfsproc_link_2(nfslinkargs *, CLIENT *);
208 extern nfsstat *nfsproc_link_2_svc(nfslinkargs *, struct svc_req *);
209 extern nfsstat *nfsproc_remove_2(nfsdiropargs *, CLIENT *);
210 extern nfsstat *nfsproc_remove_2_svc(nfsdiropargs *, struct svc_req *);
211 extern nfsstat *nfsproc_rename_2(nfsrenameargs *, CLIENT *);
212 extern nfsstat *nfsproc_rename_2_svc(nfsrenameargs *, struct svc_req *);
213 extern nfsstat *nfsproc_rmdir_2(nfsdiropargs *, CLIENT *);
214 extern nfsstat *nfsproc_rmdir_2_svc(nfsdiropargs *, struct svc_req *);
215 extern nfsstat *nfsproc_symlink_2(nfssymlinkargs *, CLIENT *);
216 extern nfsstat *nfsproc_symlink_2_svc(nfssymlinkargs *, struct svc_req *);
217 extern nfsreaddirres *nfsproc_readdir_2(nfsreaddirargs *, CLIENT *);
218 extern nfsreaddirres *nfsproc_readdir_2_svc(nfsreaddirargs *, struct svc_req *);
219 extern nfsreadlinkres *nfsproc_readlink_2(nfs_fh *, CLIENT *);
220 extern nfsreadlinkres *nfsproc_readlink_2_svc(nfs_fh *, struct svc_req *);
221 extern nfsreadres *nfsproc_read_2(nfsreadargs *, CLIENT *);
222 extern nfsreadres *nfsproc_read_2_svc(nfsreadargs *, struct svc_req *);
223 extern nfsstatfsres *nfsproc_statfs_2(nfs_fh *, CLIENT *);
224 extern nfsstatfsres *nfsproc_statfs_2_svc(nfs_fh *, struct svc_req *);
225 extern void *nfsproc_null_2(void *, CLIENT *);
226 extern void *nfsproc_null_2_svc(void *, struct svc_req *);
227 extern void *nfsproc_root_2(void *, CLIENT *);
228 extern void *nfsproc_root_2_svc(void *, struct svc_req *);
229 extern void *nfsproc_writecache_2(void *, CLIENT *);
230 extern void *nfsproc_writecache_2_svc(void *, struct svc_req *);
231 extern int nfs_program_2_freeresult(SVCXPRT *, xdrproc_t, caddr_t);
232 
233 
234 /*
235  * ENUMS:
236  */
237 
238 
239 /*
240  * STRUCTURES:
241  */
242 /* ncr2 (sysv4) forgets to include this in <sys/resource.h> */
243 struct rusage {
244   struct timeval ru_utime;	/* user time used */
245   struct timeval ru_stime;	/* system time used */
246   long	ru_maxrss;		/* XXX: 0 */
247   long	ru_ixrss;		/* XXX: 0 */
248   long	ru_idrss;		/* XXX: sum of rm_asrss */
249   long	ru_isrss;		/* XXX: 0 */
250   long	ru_minflt;		/* any page faults not requiring I/O */
251   long	ru_majflt;		/* any page faults requiring I/O */
252   long	ru_nswap;		/* swaps */
253   long	ru_inblock;		/* block input operations */
254   long	ru_oublock;		/* block output operations */
255   long	ru_msgsnd;		/* messages sent */
256   long	ru_msgrcv;		/* messages received */
257   long	ru_nsignals;		/* signals received */
258   long	ru_nvcsw;		/* voluntary context switches */
259   long	ru_nivcsw;		/* involuntary " */
260 };
261 
262 /*
263  * ncr2 has ndbm functions, but no <ndbm.h>
264  * only a partial <rpcsvc/dbm.h>
265  */
266 #define	PBLKSIZ 1024
267 #define	DBLKSIZ 4096
268 typedef struct {
269   int	dbm_dirf;		/* open directory file */
270   int	dbm_pagf;		/* open page file */
271   int	dbm_flags;		/* flags, see below */
272   long	dbm_maxbno;		/* last ``bit'' in dir file */
273   long	dbm_bitno;		/* current bit number */
274   long	dbm_hmask;		/* hash mask */
275   long	dbm_blkptr;		/* current block for dbm_nextkey */
276   int	dbm_keyptr;		/* current key for dbm_nextkey */
277   long	dbm_blkno;		/* current page to read/write */
278   long	dbm_pagbno;		/* current page in pagbuf */
279   char	dbm_pagbuf[PBLKSIZ];	/* page file block buffer */
280   long	dbm_dirbno;		/* current block in dirbuf */
281   char	dbm_dirbuf[DBLKSIZ];	/* directory file block buffer */
282 } DBM;
283 #define _DBM_RDONLY     0x1     /* data base open read-only */
284 #define _DBM_IOERR      0x2     /* data base I/O error */
285 #define dbm_rdonly(db)  ((db)->dbm_flags & _DBM_RDONLY)
286 #define dbm_error(db)   ((db)->dbm_flags & _DBM_IOERR)
287 				/* use this one at your own risk! */
288 #define dbm_clearerr(db)        ((db)->dbm_flags &= ~_DBM_IOERR)
289 /* for fstat(2) */
290 #define dbm_dirfno(db)  ((db)->dbm_dirf)
291 #define dbm_pagfno(db)  ((db)->dbm_pagf)
292 /*
293  * flags to dbm_store()
294  */
295 #define DBM_INSERT      0
296 #define DBM_REPLACE     1
297 extern DBM	*dbm_open(char *, int, int);
298 extern void	dbm_close(DBM *);
299 #ifndef DATUM
300 typedef	struct {
301   char *dptr;
302   int  dsize;
303 } datum;
304 # define DATUM
305 #endif /* not DATUM */
306 extern datum	dbm_fetch(DBM *, datum);
307 extern datum	dbm_firstkey(DBM *);
308 extern datum	dbm_nextkey(DBM *);
309 extern int	dbm_delete(DBM *, datum);
310 extern int	dbm_store(DBM *, datum, datum, int);
311 
312 
313 struct nfs_fh {
314   char fh_data[NFS_FHSIZE];
315 };
316 
317 struct nfstime {
318   u_int nt_seconds;
319   u_int nt_useconds;
320 };
321 
322 struct fattr {
323   nfsftype na_type;
324   u_int na_mode;
325   u_int na_nlink;
326   u_int na_uid;
327   u_int na_gid;
328   u_int na_size;
329   u_int na_blocksize;
330   u_int na_rdev;
331   u_int na_blocks;
332   u_int na_fsid;
333   u_int na_fileid;
334   nfstime na_atime;
335   nfstime na_mtime;
336   nfstime na_ctime;
337 };
338 
339 struct sattr {
340   u_int sa_mode;
341   u_int sa_uid;
342   u_int sa_gid;
343   u_int sa_size;
344   nfstime sa_atime;
345   nfstime sa_mtime;
346 };
347 
348 struct attrstat {
349   nfsstat ns_status;
350   union {
351     nfsfattr ns_attr_u;
352   } ns_u;
353 };
354 
355 struct sattrargs {
356   nfs_fh sag_fhandle;
357   nfssattr sag_attributes;
358 };
359 
360 struct diropargs {
361   nfs_fh da_fhandle;		/* was dir */
362   filename da_name;
363 };
364 
365 struct diropokres {
366   nfs_fh drok_fhandle;
367   nfsfattr drok_attributes;
368 };
369 
370 struct diropres {
371   nfsstat dr_status;		/* was status */
372   union {
373     nfsdiropokres dr_drok_u;	/* was diropres */
374   } dr_u;			/* was diropres_u */
375 };
376 
377 struct readlinkres {
378   nfsstat rlr_status;
379   union {
380     nfspath rlr_data_u;
381   } rlr_u;
382 };
383 
384 struct readargs {
385   nfs_fh ra_fhandle;
386   u_int ra_offset;
387   u_int ra_count;
388   u_int ra_totalcount;
389 };
390 
391 struct readokres {
392   nfsfattr raok_attributes;
393   struct {
394     u_int raok_len_u;
395     char *raok_val_u;
396   } raok_u;
397 };
398 
399 struct readres {
400   nfsstat rr_status;
401   union {
402     nfsreadokres rr_reply_u;
403   } rr_u;
404 };
405 
406 struct writeargs {
407   nfs_fh wra_fhandle;
408   u_int wra_beginoffset;
409   u_int wra_offset;
410   u_int wra_totalcount;
411   struct {
412     u_int wra_len_u;
413     char *wra_val_u;
414   } wra_u;
415 };
416 
417 struct createargs {
418   nfsdiropargs ca_where;
419   nfssattr ca_attributes;
420 };
421 
422 struct renameargs {
423   nfsdiropargs rna_from;
424   nfsdiropargs rna_to;
425 };
426 
427 struct linkargs {
428   nfs_fh la_fhandle;
429   nfsdiropargs la_to;
430 };
431 
432 struct symlinkargs {
433   nfsdiropargs sla_from;
434   nfspath sla_to;
435   nfssattr sla_attributes;
436 };
437 
438 struct readdirargs {
439   nfs_fh rda_fhandle;
440   nfscookie rda_cookie;
441   u_int rda_count;
442 };
443 
444 struct entry {
445   u_int ne_fileid;
446   filename ne_name;
447   nfscookie ne_cookie;
448   nfsentry *ne_nextentry;
449 };
450 
451 struct dirlist {
452   nfsentry *dl_entries;
453   bool_t dl_eof;
454 };
455 
456 struct readdirres {
457   nfsstat rdr_status;
458   union {
459     nfsdirlist rdr_reply_u;
460   } rdr_u;
461 };
462 
463 struct statfsokres {
464   u_int sfrok_tsize;
465   u_int sfrok_bsize;
466   u_int sfrok_blocks;
467   u_int sfrok_bfree;
468   u_int sfrok_bavail;
469 };
470 
471 struct statfsres {
472   nfsstat sfr_status;
473   union {
474     nfsstatfsokres sfr_reply_u;
475   } sfr_u;
476 };
477 
478 #endif /* not _AMU_NFS_PROT_H */
479