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