1 /* $NetBSD: nfs_prot_ncr2.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_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 */ 123 typedef char *dirpath; 124 typedef char *filename; 125 typedef char *nfspath; 126 typedef char nfscookie[NFS_COOKIESIZE]; 127 typedef enum nfsftype nfsftype; 128 typedef enum nfsstat nfsstat; 129 typedef struct attrstat nfsattrstat; 130 typedef struct createargs nfscreateargs; 131 typedef struct dirlist nfsdirlist; 132 typedef struct diropargs nfsdiropargs; 133 typedef struct diropokres nfsdiropokres; 134 typedef struct diropres nfsdiropres; 135 typedef struct entry nfsentry; 136 typedef struct fattr nfsfattr; 137 typedef struct linkargs nfslinkargs; 138 typedef struct nfs_fh nfs_fh; 139 typedef struct nfstime nfstime; 140 typedef struct readargs nfsreadargs; 141 typedef struct readdirargs nfsreaddirargs; 142 typedef struct readdirres nfsreaddirres; 143 typedef struct readlinkres nfsreadlinkres; 144 typedef struct readokres nfsreadokres; 145 typedef struct readres nfsreadres; 146 typedef struct renameargs nfsrenameargs; 147 typedef struct sattr nfssattr; 148 typedef struct sattrargs nfssattrargs; 149 typedef struct statfsokres nfsstatfsokres; 150 typedef struct statfsres nfsstatfsres; 151 typedef struct symlinkargs nfssymlinkargs; 152 typedef struct writeargs nfswriteargs; 153 154 typedef char *name; 155 typedef fhandle_t fhandle; 156 typedef struct exports *exports; 157 typedef struct exports exportnode; 158 typedef struct fhstatus fhstatus; 159 typedef struct groups *groups; 160 typedef struct groups groupnode; 161 typedef struct mountlist *mountlist; 162 typedef struct mountlist mountbody; 163 164 165 /* 166 * EXTERNALS: 167 */ 168 169 extern bool_t xdr_nfsstat(XDR *, nfsstat *); 170 extern bool_t xdr_ftype(XDR *, nfsftype *); 171 extern bool_t xdr_nfs_fh(XDR *, nfs_fh *); 172 extern bool_t xdr_nfstime(XDR *, nfstime *); 173 extern bool_t xdr_fattr(XDR *, nfsfattr *); 174 extern bool_t xdr_sattr(XDR *, nfssattr *); 175 extern bool_t xdr_filename(XDR *, filename *); 176 extern bool_t xdr_nfspath(XDR *, nfspath *); 177 extern bool_t xdr_attrstat(XDR *, nfsattrstat *); 178 extern bool_t xdr_sattrargs(XDR *, nfssattrargs *); 179 extern bool_t xdr_diropargs(XDR *, nfsdiropargs *); 180 extern bool_t xdr_diropokres(XDR *, nfsdiropokres *); 181 extern bool_t xdr_diropres(XDR *, nfsdiropres *); 182 extern bool_t xdr_readlinkres(XDR *, nfsreadlinkres *); 183 extern bool_t xdr_readargs(XDR *, nfsreadargs *); 184 extern bool_t xdr_readokres(XDR *, nfsreadokres *); 185 extern bool_t xdr_readres(XDR *, nfsreadres *); 186 extern bool_t xdr_writeargs(XDR *, nfswriteargs *); 187 extern bool_t xdr_createargs(XDR *, nfscreateargs *); 188 extern bool_t xdr_renameargs(XDR *, nfsrenameargs *); 189 extern bool_t xdr_linkargs(XDR *, nfslinkargs *); 190 extern bool_t xdr_symlinkargs(XDR *, nfssymlinkargs *); 191 extern bool_t xdr_nfscookie(XDR *, nfscookie); 192 extern bool_t xdr_readdirargs(XDR *, nfsreaddirargs *); 193 extern bool_t xdr_entry(XDR *, nfsentry *); 194 extern bool_t xdr_dirlist(XDR *, nfsdirlist *); 195 extern bool_t xdr_readdirres(XDR *, nfsreaddirres *); 196 extern bool_t xdr_statfsokres(XDR *, nfsstatfsokres *); 197 extern bool_t xdr_statfsres(XDR *, nfsstatfsres *); 198 199 extern nfsattrstat *nfsproc_getattr_2(nfs_fh *, CLIENT *); 200 extern nfsattrstat *nfsproc_getattr_2_svc(nfs_fh *, struct svc_req *); 201 extern nfsattrstat *nfsproc_setattr_2(nfssattrargs *, CLIENT *); 202 extern nfsattrstat *nfsproc_setattr_2_svc(nfssattrargs *, struct svc_req *); 203 extern nfsattrstat *nfsproc_write_2(nfswriteargs *, CLIENT *); 204 extern nfsattrstat *nfsproc_write_2_svc(nfswriteargs *, struct svc_req *); 205 extern nfsdiropres *nfsproc_create_2(nfscreateargs *, CLIENT *); 206 extern nfsdiropres *nfsproc_create_2_svc(nfscreateargs *, struct svc_req *); 207 extern nfsdiropres *nfsproc_lookup_2(nfsdiropargs *, CLIENT *); 208 extern nfsdiropres *nfsproc_lookup_2_svc(nfsdiropargs *, struct svc_req *); 209 extern nfsdiropres *nfsproc_mkdir_2(nfscreateargs *, CLIENT *); 210 extern nfsdiropres *nfsproc_mkdir_2_svc(nfscreateargs *, struct svc_req *); 211 extern nfsstat *nfsproc_link_2(nfslinkargs *, CLIENT *); 212 extern nfsstat *nfsproc_link_2_svc(nfslinkargs *, struct svc_req *); 213 extern nfsstat *nfsproc_remove_2(nfsdiropargs *, CLIENT *); 214 extern nfsstat *nfsproc_remove_2_svc(nfsdiropargs *, struct svc_req *); 215 extern nfsstat *nfsproc_rename_2(nfsrenameargs *, CLIENT *); 216 extern nfsstat *nfsproc_rename_2_svc(nfsrenameargs *, struct svc_req *); 217 extern nfsstat *nfsproc_rmdir_2(nfsdiropargs *, CLIENT *); 218 extern nfsstat *nfsproc_rmdir_2_svc(nfsdiropargs *, struct svc_req *); 219 extern nfsstat *nfsproc_symlink_2(nfssymlinkargs *, CLIENT *); 220 extern nfsstat *nfsproc_symlink_2_svc(nfssymlinkargs *, struct svc_req *); 221 extern nfsreaddirres *nfsproc_readdir_2(nfsreaddirargs *, CLIENT *); 222 extern nfsreaddirres *nfsproc_readdir_2_svc(nfsreaddirargs *, struct svc_req *); 223 extern nfsreadlinkres *nfsproc_readlink_2(nfs_fh *, CLIENT *); 224 extern nfsreadlinkres *nfsproc_readlink_2_svc(nfs_fh *, struct svc_req *); 225 extern nfsreadres *nfsproc_read_2(nfsreadargs *, CLIENT *); 226 extern nfsreadres *nfsproc_read_2_svc(nfsreadargs *, struct svc_req *); 227 extern nfsstatfsres *nfsproc_statfs_2(nfs_fh *, CLIENT *); 228 extern nfsstatfsres *nfsproc_statfs_2_svc(nfs_fh *, struct svc_req *); 229 extern void *nfsproc_null_2(void *, CLIENT *); 230 extern void *nfsproc_null_2_svc(void *, struct svc_req *); 231 extern void *nfsproc_root_2(void *, CLIENT *); 232 extern void *nfsproc_root_2_svc(void *, struct svc_req *); 233 extern void *nfsproc_writecache_2(void *, CLIENT *); 234 extern void *nfsproc_writecache_2_svc(void *, struct svc_req *); 235 extern 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> */ 247 struct 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 272 typedef 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 301 extern DBM *dbm_open(char *, int, int); 302 extern void dbm_close(DBM *); 303 #ifndef DATUM 304 typedef struct { 305 char *dptr; 306 int dsize; 307 } datum; 308 # define DATUM 309 #endif /* not DATUM */ 310 extern datum dbm_fetch(DBM *, datum); 311 extern datum dbm_firstkey(DBM *); 312 extern datum dbm_nextkey(DBM *); 313 extern int dbm_delete(DBM *, datum); 314 extern int dbm_store(DBM *, datum, datum, int); 315 316 317 struct nfs_fh { 318 char fh_data[NFS_FHSIZE]; 319 }; 320 321 struct nfstime { 322 u_int nt_seconds; 323 u_int nt_useconds; 324 }; 325 326 struct 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 343 struct 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 352 struct attrstat { 353 nfsstat ns_status; 354 union { 355 nfsfattr ns_attr_u; 356 } ns_u; 357 }; 358 359 struct sattrargs { 360 nfs_fh sag_fhandle; 361 nfssattr sag_attributes; 362 }; 363 364 struct diropargs { 365 nfs_fh da_fhandle; /* was dir */ 366 filename da_name; 367 }; 368 369 struct diropokres { 370 nfs_fh drok_fhandle; 371 nfsfattr drok_attributes; 372 }; 373 374 struct diropres { 375 nfsstat dr_status; /* was status */ 376 union { 377 nfsdiropokres dr_drok_u; /* was diropres */ 378 } dr_u; /* was diropres_u */ 379 }; 380 381 struct readlinkres { 382 nfsstat rlr_status; 383 union { 384 nfspath rlr_data_u; 385 } rlr_u; 386 }; 387 388 struct readargs { 389 nfs_fh ra_fhandle; 390 u_int ra_offset; 391 u_int ra_count; 392 u_int ra_totalcount; 393 }; 394 395 struct readokres { 396 nfsfattr raok_attributes; 397 struct { 398 u_int raok_len_u; 399 char *raok_val_u; 400 } raok_u; 401 }; 402 403 struct readres { 404 nfsstat rr_status; 405 union { 406 nfsreadokres rr_reply_u; 407 } rr_u; 408 }; 409 410 struct 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 421 struct createargs { 422 nfsdiropargs ca_where; 423 nfssattr ca_attributes; 424 }; 425 426 struct renameargs { 427 nfsdiropargs rna_from; 428 nfsdiropargs rna_to; 429 }; 430 431 struct linkargs { 432 nfs_fh la_fhandle; 433 nfsdiropargs la_to; 434 }; 435 436 struct symlinkargs { 437 nfsdiropargs sla_from; 438 nfspath sla_to; 439 nfssattr sla_attributes; 440 }; 441 442 struct readdirargs { 443 nfs_fh rda_fhandle; 444 nfscookie rda_cookie; 445 u_int rda_count; 446 }; 447 448 struct entry { 449 u_int ne_fileid; 450 filename ne_name; 451 nfscookie ne_cookie; 452 nfsentry *ne_nextentry; 453 }; 454 455 struct dirlist { 456 nfsentry *dl_entries; 457 bool_t dl_eof; 458 }; 459 460 struct readdirres { 461 nfsstat rdr_status; 462 union { 463 nfsdirlist rdr_reply_u; 464 } rdr_u; 465 }; 466 467 struct 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 475 struct 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