2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1989, 1993, 1995
25 * The Regents of the University of California. All rights reserved.
27 * This code is derived from software contributed to Berkeley by
28 * Rick Macklem at The University of Guelph.
30 * Redistribution and use in source and binary forms, with or without
31 * modification, are permitted provided that the following conditions
33 * 1. Redistributions of source code must retain the above copyright
34 * notice, this list of conditions and the following disclaimer.
35 * 2. Redistributions in binary form must reproduce the above copyright
36 * notice, this list of conditions and the following disclaimer in the
37 * documentation and/or other materials provided with the distribution.
38 * 3. All advertising materials mentioning features or use of this software
39 * must display the following acknowledgement:
40 * This product includes software developed by the University of
41 * California, Berkeley and its contributors.
42 * 4. Neither the name of the University nor the names of its contributors
43 * may be used to endorse or promote products derived from this software
44 * without specific prior written permission.
46 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
49 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
50 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
58 * @(#)nfs.h 8.4 (Berkeley) 5/1/95
59 * FreeBSD-Id: nfs.h,v 1.32 1997/10/12 20:25:38 phk Exp $
65 #include <sys/appleapiopts.h>
66 #include <sys/cdefs.h>
68 #ifdef __APPLE_API_PRIVATE
70 * Tunable constants for nfs
73 #define NFS_MAXIOVEC 34
74 #define NFS_TICKINTVL 5 /* Desired time for a tick (msec) */
75 #define NFS_HZ (hz / nfs_ticks) /* Ticks/sec */
76 #define NFS_TIMEO (1 * NFS_HZ) /* Default timeout = 1 second */
77 #define NFS_MINTIMEO (1 * NFS_HZ) /* Min timeout to use */
78 #define NFS_MAXTIMEO (60 * NFS_HZ) /* Max timeout to backoff to */
79 #define NFS_MINIDEMTIMEO (5 * NFS_HZ) /* Min timeout for non-idempotent ops*/
80 #define NFS_MAXREXMIT 100 /* Stop counting after this many */
81 #define NFS_MAXWINDOW 1024 /* Max number of outstanding requests */
82 #define NFS_RETRANS 10 /* Num of retrans for soft mounts */
83 #define NFS_TRYLATERDEL 15 /* Initial try later delay (sec) */
84 #define NFS_MAXGRPS 16 /* Max. size of groups list */
85 #ifndef NFS_MINATTRTIMO
86 #define NFS_MINATTRTIMO 5 /* Attribute cache timeout in sec */
88 #ifndef NFS_MAXATTRTIMO
89 #define NFS_MAXATTRTIMO 60
91 #ifndef NFS_MINDIRATTRTIMO
92 #define NFS_MINDIRATTRTIMO 5 /* directory attribute cache timeout in sec */
94 #ifndef NFS_MAXDIRATTRTIMO
95 #define NFS_MAXDIRATTRTIMO 60
97 #define NFS_WSIZE 16384 /* Def. write data size <= 16K */
98 #define NFS_RSIZE 16384 /* Def. read data size <= 16K */
99 #define NFS_DGRAM_WSIZE 8192 /* UDP Def. write data size <= 8K */
100 #define NFS_DGRAM_RSIZE 8192 /* UDP Def. read data size <= 8K */
101 #define NFS_READDIRSIZE 8192 /* Def. readdir size */
102 #define NFS_DEFRAHEAD 4 /* Def. read ahead # blocks */
103 #define NFS_MAXRAHEAD 16 /* Max. read ahead # blocks */
104 #define NFS_MAXUIDHASH 64 /* Max. # of hashed uid entries/mp */
105 #define NFS_MAXASYNCDAEMON 32 /* Max. number async_daemons runnable */
106 #define NFS_MAXGATHERDELAY 100 /* Max. write gather delay (msec) */
107 #ifndef NFS_GATHERDELAY
108 #define NFS_GATHERDELAY 10 /* Default write gather delay (msec) */
110 #define NFS_DIRBLKSIZ 4096 /* Must be a multiple of DIRBLKSIZ */
111 #if defined(KERNEL) && !defined(DIRBLKSIZ)
112 #define DIRBLKSIZ 512 /* XXX we used to use ufs's DIRBLKSIZ */
113 /* can't be larger than NFS_FABLKSIZE */
119 #define NMOD(a) ((a) % nfs_asyncdaemons)
120 #define NFS_CMPFH(n, f, s) \
121 ((n)->n_fhsize == (s) && !bcmp((caddr_t)(n)->n_fhp, (caddr_t)(f), (s)))
122 #define NFS_ISV3(v) (VFSTONFS(vnode_mount(v))->nm_flag & NFSMNT_NFSV3)
123 #define NFS_SRVMAXDATA(n) \
124 (((n)->nd_flag & ND_NFSV3) ? (((n)->nd_nam2) ? \
125 NFS_MAXDGRAMDATA : NFS_MAXDATA) : NFS_V2MAXDATA)
129 * The NB_INVAFTERWRITE flag should be set to whatever is required by the
130 * buffer cache code to say "Invalidate the block after it is written back".
133 #define NB_INVAFTERWRITE NB_NOCACHE
135 #define NB_INVAFTERWRITE NB_INVAL
139 * The IO_METASYNC flag should be implemented for local file systems.
140 * (Until then, it is nothin at all.)
143 #define IO_METASYNC 0
147 * Expected allocation sizes for major data structures. If the actual size
148 * of the structure exceeds these sizes, then malloc() will be allocating
149 * almost twice the memory required. This is used in nfs_init() to warn
150 * the sysadmin that the size of a structure should be reduced.
151 * (These sizes are always a power of 2. If the kernel malloc() changes
152 * to one that does not allocate space in powers of 2 size, then this all
154 * Note that some of these structures come out of there own nfs zones.
156 #define NFS_NODEALLOC 512
157 #define NFS_MNTALLOC 512
158 #define NFS_SVCALLOC 256
159 #define NFS_UIDALLOC 128
162 * Arguments to mount NFS
164 #define NFS_ARGSVERSION 4 /* change when nfs_args changes */
166 int version
; /* args structure version number */
167 struct sockaddr
*addr
; /* file server address */
168 int addrlen
; /* length of address */
169 int sotype
; /* Socket type */
170 int proto
; /* and Protocol */
171 u_char
*fh
; /* File handle to be mounted */
172 int fhsize
; /* Size, in bytes, of fh */
173 int flags
; /* flags */
174 int wsize
; /* write size in bytes */
175 int rsize
; /* read size in bytes */
176 int readdirsize
; /* readdir size in bytes */
177 int timeo
; /* initial timeout in .1 secs */
178 int retrans
; /* times to retry send */
179 int maxgrouplist
; /* Max. size of group list */
180 int readahead
; /* # of blocks to readahead */
181 int leaseterm
; /* obsolete: Term (sec) of lease */
182 int deadthresh
; /* obsolete: Retrans threshold */
183 char *hostname
; /* server's name */
184 /* NFS_ARGSVERSION 3 ends here */
185 int acregmin
; /* reg file min attr cache timeout */
186 int acregmax
; /* reg file max attr cache timeout */
187 int acdirmin
; /* dir min attr cache timeout */
188 int acdirmax
; /* dir max attr cache timeout */
192 int version
; /* args structure version number */
193 struct sockaddr
*addr
; /* file server address */
194 int addrlen
; /* length of address */
195 int sotype
; /* Socket type */
196 int proto
; /* and Protocol */
197 u_char
*fh
; /* File handle to be mounted */
198 int fhsize
; /* Size, in bytes, of fh */
199 int flags
; /* flags */
200 int wsize
; /* write size in bytes */
201 int rsize
; /* read size in bytes */
202 int readdirsize
; /* readdir size in bytes */
203 int timeo
; /* initial timeout in .1 secs */
204 int retrans
; /* times to retry send */
205 int maxgrouplist
; /* Max. size of group list */
206 int readahead
; /* # of blocks to readahead */
207 int leaseterm
; /* obsolete: Term (sec) of lease */
208 int deadthresh
; /* obsolete: Retrans threshold */
209 char *hostname
; /* server's name */
212 // LP64todo - should this move?
214 /* LP64 version of nfs_args. all pointers and longs
215 * grow when we're dealing with a 64-bit process.
216 * WARNING - keep in sync with nfs_args
218 #if __DARWIN_ALIGN_NATURAL
219 #pragma options align=natural
222 struct user_nfs_args
{
223 int version
; /* args structure version number */
224 user_addr_t addr
; /* file server address */
225 int addrlen
; /* length of address */
226 int sotype
; /* Socket type */
227 int proto
; /* and Protocol */
228 user_addr_t fh
; /* File handle to be mounted */
229 int fhsize
; /* Size, in bytes, of fh */
230 int flags
; /* flags */
231 int wsize
; /* write size in bytes */
232 int rsize
; /* read size in bytes */
233 int readdirsize
; /* readdir size in bytes */
234 int timeo
; /* initial timeout in .1 secs */
235 int retrans
; /* times to retry send */
236 int maxgrouplist
; /* Max. size of group list */
237 int readahead
; /* # of blocks to readahead */
238 int leaseterm
; /* obsolete: Term (sec) of lease */
239 int deadthresh
; /* obsolete: Retrans threshold */
240 user_addr_t hostname
; /* server's name */
241 /* NFS_ARGSVERSION 3 ends here */
242 int acregmin
; /* reg file min attr cache timeout */
243 int acregmax
; /* reg file max attr cache timeout */
244 int acdirmin
; /* dir min attr cache timeout */
245 int acdirmax
; /* dir max attr cache timeout */
247 struct user_nfs_args3
{
248 int version
; /* args structure version number */
249 user_addr_t addr
; /* file server address */
250 int addrlen
; /* length of address */
251 int sotype
; /* Socket type */
252 int proto
; /* and Protocol */
253 user_addr_t fh
; /* File handle to be mounted */
254 int fhsize
; /* Size, in bytes, of fh */
255 int flags
; /* flags */
256 int wsize
; /* write size in bytes */
257 int rsize
; /* read size in bytes */
258 int readdirsize
; /* readdir size in bytes */
259 int timeo
; /* initial timeout in .1 secs */
260 int retrans
; /* times to retry send */
261 int maxgrouplist
; /* Max. size of group list */
262 int readahead
; /* # of blocks to readahead */
263 int leaseterm
; /* obsolete: Term (sec) of lease */
264 int deadthresh
; /* obsolete: Retrans threshold */
265 user_addr_t hostname
; /* server's name */
268 #if __DARWIN_ALIGN_NATURAL
269 #pragma options align=reset
275 * NFS mount option flags
277 #define NFSMNT_SOFT 0x00000001 /* soft mount (hard is default) */
278 #define NFSMNT_WSIZE 0x00000002 /* set write size */
279 #define NFSMNT_RSIZE 0x00000004 /* set read size */
280 #define NFSMNT_TIMEO 0x00000008 /* set initial timeout */
281 #define NFSMNT_RETRANS 0x00000010 /* set number of request retries */
282 #define NFSMNT_MAXGRPS 0x00000020 /* set maximum grouplist size */
283 #define NFSMNT_INT 0x00000040 /* allow interrupts on hard mount */
284 #define NFSMNT_NOCONN 0x00000080 /* Don't Connect the socket */
285 #define NFSMNT_NFSV3 0x00000200 /* Use NFS Version 3 protocol */
286 #define NFSMNT_KERB 0x00000400 /* Use Kerberos authentication */
287 #define NFSMNT_DUMBTIMR 0x00000800 /* Don't estimate rtt dynamically */
288 #define NFSMNT_READAHEAD 0x00002000 /* set read ahead */
289 #define NFSMNT_RESVPORT 0x00008000 /* Allocate a reserved port */
290 #define NFSMNT_RDIRPLUS 0x00010000 /* Use Readdirplus for V3 */
291 #define NFSMNT_READDIRSIZE 0x00020000 /* Set readdir size */
292 #define NFSMNT_NOLOCKS 0x00040000 /* don't support file locking */
293 #define NFSMNT_ACREGMIN 0x00100000 /* reg min attr cache timeout */
294 #define NFSMNT_ACREGMAX 0x00200000 /* reg max attr cache timeout */
295 #define NFSMNT_ACDIRMIN 0x00400000 /* dir min attr cache timeout */
296 #define NFSMNT_ACDIRMAX 0x00800000 /* dir max attr cache timeout */
299 * NFS mount state flags (nm_state)
301 #define NFSSTA_LOCKTIMEO 0x00002000 /* experienced a lock req timeout */
302 #define NFSSTA_MOUNTED 0x00004000 /* completely mounted */
303 #define NFSSTA_LOCKSWORK 0x00008000 /* lock ops have worked. */
304 #define NFSSTA_TIMEO 0x00010000 /* experienced a timeout. */
305 #define NFSSTA_FORCE 0x00020000 /* doing a forced unmount. */
306 #define NFSSTA_HASWRITEVERF 0x00040000 /* Has write verifier for V3 */
307 #define NFSSTA_GOTPATHCONF 0x00080000 /* Got the V3 pathconf info */
308 #define NFSSTA_GOTFSINFO 0x00100000 /* Got the V3 fsinfo */
309 #define NFSSTA_MNTD 0x00200000 /* Mnt server for mnt point */
310 #define NFSSTA_SNDLOCK 0x01000000 /* Send socket lock */
311 #define NFSSTA_WANTSND 0x02000000 /* Want above */
312 #define NFSSTA_RCVLOCK 0x04000000 /* Rcv socket lock */
313 #define NFSSTA_WANTRCV 0x08000000 /* Want above */
314 #define NFSSTA_WAITAUTH 0x10000000 /* Wait for authentication */
315 #define NFSSTA_HASAUTH 0x20000000 /* Has authenticator */
316 #define NFSSTA_WANTAUTH 0x40000000 /* Wants an authenticator */
317 #define NFSSTA_AUTHERR 0x80000000 /* Authentication error */
320 * NFS mount pathconf info flags (nm_fsinfo.pcflags)
322 #define NFSPCINFO_NOTRUNC 0x01
323 #define NFSPCINFO_CHOWN_RESTRICTED 0x02
324 #define NFSPCINFO_CASE_INSENSITIVE 0x04
325 #define NFSPCINFO_CASE_PRESERVING 0x08
328 * Structures for the nfssvc(2) syscall. Not that anyone but nfsd and mount_nfs
329 * should ever try and use it.
332 int sock
; /* Socket to serve */
333 caddr_t name
; /* Client addr for connection based sockets */
334 int namelen
; /* Length of name */
337 // LP64todo - should this move?
339 /* LP64 version of nfsd_args. all pointers and longs
340 * grow when we're dealing with a 64-bit process.
341 * WARNING - keep in sync with nfsd_args
343 #if __DARWIN_ALIGN_NATURAL
344 #pragma options align=natural
347 struct user_nfsd_args
{
348 int sock
; /* Socket to serve */
349 user_addr_t name
; /* Client addr for connection based sockets */
350 int namelen
; /* Length of name */
353 #if __DARWIN_ALIGN_NATURAL
354 #pragma options align=reset
359 struct nfsd_srvargs
{
360 struct nfsd
*nsd_nfsd
; /* Pointer to in kernel nfsd struct */
361 uid_t nsd_uid
; /* Effective uid mapped to cred */
362 u_long nsd_haddr
; /* Ip address of client */
363 struct ucred nsd_cr
; /* Cred. uid maps to */
364 int nsd_authlen
; /* Length of auth string (ret) */
365 u_char
*nsd_authstr
; /* Auth string (ret) */
366 int nsd_verflen
; /* and the verfier */
368 struct timeval nsd_timestamp
; /* timestamp from verifier */
369 u_long nsd_ttl
; /* credential ttl (sec) */
370 NFSKERBKEY_T nsd_key
; /* Session key */
374 char *ncd_dirp
; /* Mount dir path */
375 uid_t ncd_authuid
; /* Effective uid */
376 int ncd_authtype
; /* Type of authenticator */
377 int ncd_authlen
; /* Length of authenticator string */
378 u_char
*ncd_authstr
; /* Authenticator string */
379 int ncd_verflen
; /* and the verifier */
381 NFSKERBKEY_T ncd_key
; /* Session key */
385 * NFS Server File Handle structures
388 /* NFS export handle identifies which NFS export */
389 #define NFS_FH_VERSION 0x4e580000 /* 'NX00' */
390 struct nfs_exphandle
{
391 uint32_t nxh_version
; /* data structure version */
392 uint32_t nxh_fsid
; /* File System Export ID */
393 uint32_t nxh_expid
; /* Export ID */
394 uint16_t nxh_flags
; /* export handle flags */
395 uint8_t nxh_reserved
; /* future use */
396 uint8_t nxh_fidlen
; /* length of File ID */
400 #define NXHF_INVALIDFH 0x0001 /* file handle is invalid */
402 #define NFS_MAX_FID_SIZE (NFS_MAX_FH_SIZE - sizeof(struct nfs_exphandle))
403 #define NFSV2_MAX_FID_SIZE (NFSV2_MAX_FH_SIZE - sizeof(struct nfs_exphandle))
405 /* NFS server internal view of fhandle_t */
406 struct nfs_filehandle
{
407 int nfh_len
; /* total length of file handle */
408 struct nfs_exphandle nfh_xh
; /* export handle */
409 unsigned char nfh_fid
[NFS_MAX_FID_SIZE
]; /* File ID */
413 * NFS export data structures
416 struct nfs_export_net_args
{
417 uint32_t nxna_flags
; /* export flags */
418 struct xucred nxna_cred
; /* mapped credential for root/all user */
419 struct sockaddr_storage nxna_addr
; /* net address to which exported */
420 struct sockaddr_storage nxna_mask
; /* mask for net address */
423 struct nfs_export_args
{
424 uint32_t nxa_fsid
; /* export FS ID */
425 uint32_t nxa_expid
; /* export ID */
426 char *nxa_fspath
; /* export FS path */
427 char *nxa_exppath
; /* export sub-path */
428 uint32_t nxa_flags
; /* export arg flags */
429 uint32_t nxa_netcount
; /* #entries in ex_nets array */
430 struct nfs_export_net_args
*nxa_nets
; /* array of net args */
434 /* LP64 version of export_args */
436 #if __DARWIN_ALIGN_NATURAL
437 #pragma options align=natural
440 struct user_nfs_export_args
{
441 uint32_t nxa_fsid
; /* export FS ID */
442 uint32_t nxa_expid
; /* export ID */
443 user_addr_t nxa_fspath
; /* export FS path */
444 user_addr_t nxa_exppath
; /* export sub-path */
445 uint32_t nxa_flags
; /* export arg flags */
446 uint32_t nxa_netcount
; /* #entries in ex_nets array */
447 user_addr_t nxa_nets
; /* array of net args */
450 #if __DARWIN_ALIGN_NATURAL
451 #pragma options align=reset
456 /* nfs export arg flags */
457 #define NXA_DELETE 0x0001 /* delete the specified export(s) */
458 #define NXA_ADD 0x0002 /* add the specified export(s) */
459 #define NXA_REPLACE 0x0003 /* delete and add the specified export(s) */
460 #define NXA_DELETE_ALL 0x0004 /* delete all exports */
462 /* export option flags */
463 #define NX_READONLY 0x0001 /* exported read-only */
464 #define NX_DEFAULTEXPORT 0x0002 /* exported to the world */
465 #define NX_MAPROOT 0x0004 /* map root access to anon credential */
466 #define NX_MAPALL 0x0008 /* map all access to anon credential */
467 #define NX_KERB 0x0010 /* exported with Kerberos uid mapping */
468 #define NX_32BITCLIENTS 0x0020 /* restrict directory cookies to 32 bits */
473 struct nfs_export_options
{
474 uint32_t nxo_flags
; /* export options */
475 kauth_cred_t nxo_cred
; /* mapped credential */
478 /* Network address lookup element and individual export options */
480 struct radix_node no_rnodes
[2]; /* radix tree glue */
481 struct nfs_export_options no_opt
; /* export options */
484 /* Network export information */
485 /* one of these for each exported directory */
487 LIST_ENTRY(nfs_export
) nx_next
; /* FS export list */
488 LIST_ENTRY(nfs_export
) nx_hash
; /* export hash chain */
489 struct nfs_export
*nx_parent
; /* parent export */
490 uint32_t nx_id
; /* export ID */
491 uint32_t nx_flags
; /* export flags */
492 struct nfs_exportfs
*nx_fs
; /* exported file system */
493 char *nx_path
; /* exported file system sub-path */
494 struct nfs_filehandle nx_fh
; /* export root file handle */
495 struct nfs_export_options nx_defopt
; /* default options */
496 uint32_t nx_expcnt
; /* # exports in table */
497 struct radix_node_head
*nx_rtable
[AF_MAX
+1]; /* table of exports (netopts) */
500 /* NFS exported file system info */
501 /* one of these for each exported file system */
502 struct nfs_exportfs
{
503 LIST_ENTRY(nfs_exportfs
) nxfs_next
; /* exported file system list */
504 uint32_t nxfs_id
; /* exported file system ID */
505 char *nxfs_path
; /* exported file system path */
506 LIST_HEAD(,nfs_export
) nxfs_exports
; /* list of exports for this file system */
509 extern LIST_HEAD(nfsexpfslist
, nfs_exportfs
) nfs_exports
;
510 extern lck_rw_t nfs_export_rwlock
; // lock for export data structures
511 #define NFSEXPHASHVAL(FSID, EXPID) \
512 (((FSID) >> 24) ^ ((FSID) >> 16) ^ ((FSID) >> 8) ^ (EXPID))
513 #define NFSEXPHASH(FSID, EXPID) \
514 (&nfsexphashtbl[NFSEXPHASHVAL((FSID),(EXPID)) & nfsexphash])
515 extern LIST_HEAD(nfsexphashhead
, nfs_export
) *nfsexphashtbl
;
516 extern u_long nfsexphash
;
521 * XXX to allow amd to include nfs.h without nfsproto.h
529 int attrcache_misses
;
530 int lookupcache_hits
;
531 int lookupcache_misses
;
532 int direofcache_hits
;
533 int direofcache_misses
;
540 int biocache_readlinks
;
542 int biocache_readdirs
;
544 int rpccnt
[NFS_NPROCS
];
546 int srvrpccnt
[NFS_NPROCS
];
553 int srvcache_inproghits
;
554 int srvcache_idemdonehits
;
555 int srvcache_nonidemdonehits
;
564 * Flags for nfssvc() system call.
566 #define NFSSVC_BIOD 0x002
567 #define NFSSVC_NFSD 0x004
568 #define NFSSVC_ADDSOCK 0x008
569 #define NFSSVC_AUTHIN 0x010
570 #define NFSSVC_GOTAUTH 0x040
571 #define NFSSVC_AUTHINFAIL 0x080
572 #define NFSSVC_MNTD 0x100
573 #define NFSSVC_EXPORT 0x200
576 * Flags for nfsclnt() system call.
578 #define NFSCLNT_LOCKDANS 0x200
579 #define NFSCLNT_LOCKDFD 0x400
580 #define NFSCLNT_LOCKDWAIT 0x800
583 * fs.nfs sysctl(3) identifiers
585 #define NFS_NFSSTATS 1 /* struct: struct nfsstats */
586 #define NFS_NFSPRIVPORT 2 /* int: prohibit nfs to resvports */
588 #define FS_NFS_NAMES { \
590 { "nfsstats", CTLTYPE_STRUCT }, \
591 { "nfsprivport", CTLTYPE_INT }, \
594 #ifndef NFS_MUIDHASHSIZ
595 #define NFS_MUIDHASHSIZ 63 /* Tune the size of nfsmount with this */
597 #ifndef NFS_WDELAYHASHSIZ
598 #define NFS_WDELAYHASHSIZ 16 /* and with this */
602 * The set of signals the interrupt an I/O in progress for NFSMNT_INT mounts.
603 * What should be in this set is open to debate, but I believe that since
604 * I/O system calls on ufs are never interrupted by signals the set should
605 * be minimal. My reasoning is that many current programs that use signals
606 * such as SIGALRM will not expect file I/O system calls to be interrupted
610 #include <sys/kernel_types.h>
612 #ifdef MALLOC_DECLARE
613 MALLOC_DECLARE(M_NFSREQ
);
614 MALLOC_DECLARE(M_NFSMNT
);
615 MALLOC_DECLARE(M_NFSDIROFF
);
616 MALLOC_DECLARE(M_NFSRVDESC
);
617 MALLOC_DECLARE(M_NFSUID
);
618 MALLOC_DECLARE(M_NFSD
);
619 MALLOC_DECLARE(M_NFSBIGFH
);
622 struct uio
; struct vnode_attr
; struct nameidata
; /* XXX */
627 #define NFSINT_SIGMASK (sigmask(SIGINT)|sigmask(SIGTERM)|sigmask(SIGKILL)| \
628 sigmask(SIGHUP)|sigmask(SIGQUIT))
630 __private_extern__
int nfs_mbuf_mlen
, nfs_mbuf_mhlen
,
631 nfs_mbuf_minclsize
, nfs_mbuf_mclbytes
;
634 * Socket errors ignored for connectionless sockets??
635 * For now, ignore them all
637 #define NFSIGNORE_SOERROR(s, e) \
638 ((e) != EINTR && (e) != ERESTART && (e) != EWOULDBLOCK && \
639 (e) != EIO && ((s)) != SOCK_STREAM)
642 * Nfs outstanding request list element
645 TAILQ_ENTRY(nfsreq
) r_chain
;
650 struct nfsmount
*r_nmp
;
653 int r_flags
; /* flags on request, see below */
654 int r_retry
; /* max retransmission count */
655 int r_rexmit
; /* current retrans count */
656 int r_timer
; /* tick counter on reply */
657 u_int32_t r_procnum
; /* NFS procedure number */
658 int r_rtt
; /* RTT for rpc */
659 proc_t r_procp
; /* Proc that did I/O system call */
660 long r_lastmsg
; /* time of last tprintf */
664 * Queue head for nfsreq's
666 extern TAILQ_HEAD(nfs_reqq
, nfsreq
) nfs_reqq
;
668 /* Flag values for r_flags */
669 #define R_TIMING 0x0001 /* timing request (in mntp) */
670 #define R_SENT 0x0002 /* request has been sent */
671 #define R_SOFTTERM 0x0004 /* soft mnt, too many retries */
672 #define R_INTR 0x0008 /* intr mnt, signal pending */
673 #define R_SOCKERR 0x0010 /* Fatal error on socket */
674 #define R_TPRINTFMSG 0x0020 /* Did a tprintf msg. */
675 #define R_MUSTRESEND 0x0040 /* Must resend request */
676 #define R_BUSY 0x0100 /* Locked. */
677 #define R_WAITING 0x0200 /* Someone waiting for lock. */
678 #define R_RESENDERR 0x0400 /* resend failed. */
681 * A list of nfssvc_sock structures is maintained with all the sockets
682 * that require service by the nfsd.
683 * The nfsuid structs hang off of the nfssvc_sock structs in both lru
684 * and uid hash lists.
686 #ifndef NFS_UIDHASHSIZ
687 #define NFS_UIDHASHSIZ 13 /* Tune the size of nfssvc_sock with this */
689 #define NUIDHASH(sock, uid) \
690 (&(sock)->ns_uidhashtbl[(uid) % NFS_UIDHASHSIZ])
691 #define NWDELAYHASH(sock, f) \
692 (&(sock)->ns_wdelayhashtbl[(*((u_long *)(f))) % NFS_WDELAYHASHSIZ])
693 #define NMUIDHASH(nmp, uid) \
694 (&(nmp)->nm_uidhashtbl[(uid) % NFS_MUIDHASHSIZ])
695 #define NFSNOHASH(fhsum) \
696 (&nfsnodehashtbl[(fhsum) & nfsnodehash])
699 * Network address hash list element
707 TAILQ_ENTRY(nfsuid
) nu_lru
; /* LRU chain */
708 LIST_ENTRY(nfsuid
) nu_hash
; /* Hash list */
709 int nu_flag
; /* Flags */
710 union nethostaddr nu_haddr
; /* Host addr. for dgram sockets */
711 kauth_cred_t nu_cr
; /* Cred uid mapped to */
712 int nu_expire
; /* Expiry time (sec) */
713 struct timeval nu_timestamp
; /* Kerb. timestamp */
714 u_long nu_nickname
; /* Nickname on server */
715 NFSKERBKEY_T nu_key
; /* and session key */
718 #define nu_inetaddr nu_haddr.had_inetaddr
719 #define nu_nam nu_haddr.had_nam
720 /* Bits for nu_flag */
721 #define NU_INETADDR 0x1
723 #define NU_NETFAM(u) (((u)->nu_flag & NU_INETADDR) ? AF_INET : AF_ISO)
726 /* XXX CSM 12/2/97 When/if we merge queue.h */
728 STAILQ_ENTRY(nfsrv_rec
) nr_link
;
729 struct sockaddr
*nr_address
;
735 TAILQ_ENTRY(nfssvc_sock
) ns_chain
; /* List of all nfssvc_sock's */
736 lck_rw_t ns_rwlock
; /* lock for most fields */
750 time_t ns_timestamp
; /* socket timestamp */
751 lck_mtx_t ns_wgmutex
; /* mutex for write gather fields */
752 u_quad_t ns_wgtime
; /* next Write deadline (usec) */
753 LIST_HEAD(, nfsrv_descript
) ns_tq
; /* Write gather lists */
754 LIST_HEAD(nfsrvw_delayhash
, nfsrv_descript
) ns_wdelayhashtbl
[NFS_WDELAYHASHSIZ
];
755 TAILQ_HEAD(, nfsuid
) ns_uidlruhead
;
756 LIST_HEAD(, nfsuid
) ns_uidhashtbl
[NFS_UIDHASHSIZ
];
759 /* Bits for "ns_flag" */
760 #define SLP_VALID 0x01 /* nfs sock valid */
761 #define SLP_DOREC 0x02 /* nfs sock has received data to process */
762 #define SLP_NEEDQ 0x04 /* network socket has data to receive */
763 #define SLP_DISCONN 0x08 /* socket needs to be zapped */
764 #define SLP_GETSTREAM 0x10 /* currently in nfsrv_getstream() */
765 #define SLP_LASTFRAG 0x20 /* on last fragment of RPC record */
766 #define SLP_ALLFLAGS 0xff
768 extern TAILQ_HEAD(nfssvc_sockhead
, nfssvc_sock
) nfssvc_sockhead
, nfssvc_deadsockhead
;
770 /* locks for nfssvc_sock's */
771 extern lck_grp_attr_t
*nfs_slp_group_attr
;
772 extern lck_attr_t
*nfs_slp_lock_attr
;
773 extern lck_grp_t
*nfs_slp_rwlock_group
;
774 extern lck_grp_t
*nfs_slp_mutex_group
;
777 * One of these structures is allocated for each nfsd.
780 TAILQ_ENTRY(nfsd
) nfsd_chain
; /* List of all nfsd's */
781 int nfsd_flag
; /* NFSD_ flags */
782 struct nfssvc_sock
*nfsd_slp
; /* Current socket */
783 int nfsd_authlen
; /* Authenticator len */
784 u_char nfsd_authstr
[RPCAUTH_MAXSIZ
]; /* Authenticator data */
785 int nfsd_verflen
; /* and the Verifier */
786 u_char nfsd_verfstr
[RPCVERF_MAXSIZ
];
787 proc_t nfsd_procp
; /* Proc ptr */
788 struct nfsrv_descript
*nfsd_nd
; /* Associated nfsrv_descript */
791 /* Bits for "nfsd_flag" */
792 #define NFSD_WAITING 0x01
793 #define NFSD_REQINPROG 0x02
794 #define NFSD_NEEDAUTH 0x04
795 #define NFSD_AUTHFAIL 0x08
798 * This structure is used by the server for describing each request.
799 * Some fields are used only when write request gathering is performed.
801 struct nfsrv_descript
{
802 u_quad_t nd_time
; /* Write deadline (usec) */
803 off_t nd_off
; /* Start byte offset */
804 off_t nd_eoff
; /* and end byte offset */
805 LIST_ENTRY(nfsrv_descript
) nd_hash
; /* Hash list */
806 LIST_ENTRY(nfsrv_descript
) nd_tq
; /* and timer list */
807 LIST_HEAD(,nfsrv_descript
) nd_coalesce
; /* coalesced writes */
808 mbuf_t nd_mrep
; /* Request mbuf list */
809 mbuf_t nd_md
; /* Current dissect mbuf */
810 mbuf_t nd_mreq
; /* Reply mbuf list */
811 mbuf_t nd_nam
; /* and socket addr */
812 mbuf_t nd_nam2
; /* return socket addr */
813 caddr_t nd_dpos
; /* Current dissect pos */
814 u_int32_t nd_procnum
; /* RPC # */
815 int nd_stable
; /* storage type */
816 int nd_flag
; /* nd_flag */
817 int nd_len
; /* Length of this write */
818 int nd_repstat
; /* Reply status */
819 u_long nd_retxid
; /* Reply xid */
820 struct timeval nd_starttime
; /* Time RPC initiated */
821 struct nfs_filehandle nd_fh
; /* File handle */
822 kauth_cred_t nd_cr
; /* Credentials */
825 /* Bits for "nd_flag" */
826 #define ND_NFSV3 0x08
827 #define ND_KERBNICK 0x20
828 #define ND_KERBFULL 0x40
829 #define ND_KERBAUTH (ND_KERBNICK | ND_KERBFULL)
831 extern TAILQ_HEAD(nfsd_head
, nfsd
) nfsd_head
;
832 extern int nfsd_head_flag
;
833 #define NFSD_CHECKSLP 0x01
836 * These macros compare nfsrv_descript structures.
838 #define NFSW_CONTIG(o, n) \
839 (((o)->nd_eoff >= (n)->nd_off) && \
840 ((o)->nd_fh.nfh_len == (n)->nd_fh.nfh_len) && \
841 !bcmp((caddr_t)&(o)->nd_fh, (caddr_t)&(n)->nd_fh, (o)->nd_fh.nfh_len))
843 #define NFSW_SAMECRED(o, n) \
844 (((o)->nd_flag & ND_KERBAUTH) == ((n)->nd_flag & ND_KERBAUTH) && \
845 !bcmp((caddr_t)(o)->nd_cr, (caddr_t)(n)->nd_cr, \
846 sizeof (struct ucred)))
848 /* mutex for nfs server */
849 extern lck_grp_t
* nfsd_lck_grp
;
850 extern lck_grp_attr_t
* nfsd_lck_grp_attr
;
851 extern lck_attr_t
* nfsd_lck_attr
;
852 extern lck_mtx_t
*nfsd_mutex
;
854 extern int nfs_numnfsd
, nfsd_waiting
;
860 #define WEBNFS_ESC_CHAR '%'
861 #define WEBNFS_SPECCHAR_START 0x80
863 #define WEBNFS_NATIVE_CHAR 0x80
866 * Possibly more here in the future.
870 * Macro for converting escape characters in WebNFS pathnames.
871 * Should really be in libkern.
874 ((((c) >= 'a') && ((c) <= 'f')) || \
875 (((c) >= 'A') && ((c) <= 'F')) || \
876 (((c) >= '0') && ((c) <= '9')))
878 ((c) >= 'a' ? ((c) - ('a' - 10)) : \
879 ((c) >= 'A' ? ((c) - ('A' - 10)) : ((c) - '0')))
880 #define HEXSTRTOI(p) \
881 ((HEXTOC(p[0]) << 4) + HEXTOC(p[1]))
885 int nfs_init(struct vfsconf
*vfsp
);
886 void nfs_mbuf_init(void);
887 int nfs_reply(struct nfsreq
*);
888 int nfs_getreq(struct nfsrv_descript
*,struct nfsd
*,int);
889 int nfs_send(socket_t
, mbuf_t
, mbuf_t
, struct nfsreq
*);
890 int nfs_rephead(int, struct nfsrv_descript
*, struct nfssvc_sock
*,
891 int, mbuf_t
*, mbuf_t
*, caddr_t
*);
892 int nfs_sndlock(struct nfsreq
*);
893 void nfs_sndunlock(struct nfsreq
*);
894 int nfs_vinvalbuf(vnode_t
, int, struct ucred
*, proc_t
, int);
895 int nfs_buf_page_inval(vnode_t vp
, off_t offset
);
896 int nfs_readrpc(vnode_t
, struct uio
*, struct ucred
*, proc_t
);
897 int nfs_writerpc(vnode_t
, struct uio
*, struct ucred
*, proc_t
, int *, uint64_t *);
898 int nfs_readdirrpc(vnode_t
, struct uio
*, struct ucred
*, proc_t
);
899 int nfs_readdirplusrpc(vnode_t
, struct uio
*, struct ucred
*, proc_t
);
900 int nfs_asyncio(struct nfsbuf
*, struct ucred
*);
901 int nfs_doio(struct nfsbuf
*, struct ucred
*, proc_t
);
902 int nfs_readlinkrpc(vnode_t
, struct uio
*, struct ucred
*, proc_t
);
903 int nfs_sigintr(struct nfsmount
*, struct nfsreq
*, proc_t
);
904 int nfsm_disct(mbuf_t
*, caddr_t
*, int, int, caddr_t
*);
905 void nfsm_srvfattr(struct nfsrv_descript
*, struct vnode_attr
*,
907 void nfsm_srvwcc(struct nfsrv_descript
*, int, struct vnode_attr
*, int,
908 struct vnode_attr
*, mbuf_t
*, char **);
909 void nfsm_srvpostopattr(struct nfsrv_descript
*, int, struct vnode_attr
*,
911 int netaddr_match(int, union nethostaddr
*, mbuf_t
);
912 int nfs_request(vnode_t
, mount_t
, mbuf_t
, int, proc_t
,
913 struct ucred
*, mbuf_t
*, mbuf_t
*,
914 caddr_t
*, u_int64_t
*);
915 int nfs_parsefattr(mbuf_t
*, caddr_t
*, int, struct nfs_vattr
*);
916 int nfs_loadattrcache(struct nfsnode
*, struct nfs_vattr
*, u_int64_t
*, int);
917 int nfsm_path_mbuftond(mbuf_t
*, caddr_t
*, int, int, int *, struct nameidata
*);
918 int nfs_namei(struct nfsrv_descript
*, struct vfs_context
*, struct nameidata
*,
919 struct nfs_filehandle
*, mbuf_t
, int, vnode_t
*,
920 struct nfs_export
**, struct nfs_export_options
**);
921 void nfsm_adj(mbuf_t
, int, int);
922 int nfsm_mbuftouio(mbuf_t
*, struct uio
*, int, caddr_t
*);
923 void nfsrv_initcache(void);
924 int nfs_getauth(struct nfsmount
*, struct nfsreq
*, struct ucred
*,
925 char **, int *, char *, int *, NFSKERBKEY_T
);
926 int nfs_getnickauth(struct nfsmount
*, struct ucred
*, char **,
928 int nfs_savenickauth(struct nfsmount
*, struct ucred
*, int,
929 NFSKERBKEY_T
, mbuf_t
*, char **,
931 int nfs_adv(mbuf_t
*, caddr_t
*, int, int);
932 void nfs_nhinit(void);
933 void nfs_timer_funnel(void*);
934 void nfs_timer(void*);
935 u_long
nfs_hash(u_char
*, int);
936 int nfsrv_dorec(struct nfssvc_sock
*, struct nfsd
*,
937 struct nfsrv_descript
**);
938 int nfsrv_getcache(struct nfsrv_descript
*, struct nfssvc_sock
*,
940 void nfsrv_updatecache(struct nfsrv_descript
*, int, mbuf_t
);
941 void nfsrv_cleancache(void);
942 int nfs_bind_resv_thread_wake(void);
943 int nfs_connect(struct nfsmount
*, struct nfsreq
*);
944 void nfs_disconnect(struct nfsmount
*);
945 int nfs_getattr_no_vnode(mount_t
,u_char
*,int,struct ucred
*,proc_t
,struct nfs_vattr
*,u_int64_t
*);
946 int nfs_getattr(vnode_t vp
, struct nfs_vattr
*nvap
, struct ucred
*cred
, proc_t p
);
947 int nfs_getattrcache(vnode_t
, struct nfs_vattr
*);
948 int nfs_attrcachetimeout(vnode_t
);
949 int nfsm_strtmbuf(mbuf_t
*, char **, char *, long);
950 int nfs_bioread(vnode_t
, struct uio
*, int, struct ucred
*, proc_t
);
951 int nfsm_uiotombuf(struct uio
*, mbuf_t
*, int, caddr_t
*);
952 void nfsrv_init(int);
953 int nfs_commit(vnode_t vp
, u_quad_t offset
, u_int32_t count
,
954 struct ucred
*cred
, proc_t procp
);
955 int nfs_flushcommits(vnode_t
, proc_t
, int);
956 int nfs_flush(vnode_t
,int,struct ucred
*,proc_t
,int);
957 int nfsrv_errmap(struct nfsrv_descript
*, int);
958 void nfsrvw_sort(gid_t
*, int);
959 void nfsrv_setcred(struct ucred
*, struct ucred
*);
960 int nfs_buf_write(struct nfsbuf
*);
961 void nfsrv_wakenfsd(struct nfssvc_sock
*slp
);
962 int nfsrv_writegather(struct nfsrv_descript
**, struct nfssvc_sock
*,
964 int nfs_fsinfo(struct nfsmount
*, vnode_t
, struct ucred
*, proc_t p
);
965 int nfs_pathconfrpc(vnode_t
, struct nfsv3_pathconf
*, kauth_cred_t
, proc_t
);
966 void nfs_pathconf_cache(struct nfsmount
*, struct nfsv3_pathconf
*);
968 int nfsrv3_access(struct nfsrv_descript
*nfsd
,
969 struct nfssvc_sock
*slp
,
970 proc_t procp
, mbuf_t
*mrq
);
971 int nfsrv_commit(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
972 proc_t procp
, mbuf_t
*mrq
);
973 int nfsrv_create(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
974 proc_t procp
, mbuf_t
*mrq
);
975 int nfsrv_credcheck(struct nfsrv_descript
*, struct nfs_export
*,
976 struct nfs_export_options
*);
977 int nfsrv_export(struct user_nfs_export_args
*, struct vfs_context
*);
978 int nfsrv_fhmatch(struct nfs_filehandle
*fh1
, struct nfs_filehandle
*fh2
);
979 int nfsrv_fhtovp(struct nfs_filehandle
*, mbuf_t
, int, vnode_t
*,
980 struct nfs_export
**, struct nfs_export_options
**);
981 int nfs_ispublicfh(struct nfs_filehandle
*);
982 int nfsrv_fsinfo(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
983 proc_t procp
, mbuf_t
*mrq
);
984 int nfsrv_getattr(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
985 proc_t procp
, mbuf_t
*mrq
);
986 int nfsrv_link(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
987 proc_t procp
, mbuf_t
*mrq
);
988 int nfsrv_lookup(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
989 proc_t procp
, mbuf_t
*mrq
);
990 int nfsrv_mkdir(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
991 proc_t procp
, mbuf_t
*mrq
);
992 int nfsrv_mknod(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
993 proc_t procp
, mbuf_t
*mrq
);
994 int nfsrv_noop(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
995 proc_t procp
, mbuf_t
*mrq
);
996 int nfsrv_null(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
997 proc_t procp
, mbuf_t
*mrq
);
998 int nfsrv_pathconf(struct nfsrv_descript
*nfsd
,
999 struct nfssvc_sock
*slp
, proc_t procp
,
1001 void nfsrv_rcv(socket_t
, caddr_t arg
, int waitflag
);
1002 void nfsrv_rcv_locked(socket_t
, struct nfssvc_sock
*slp
, int waitflag
);
1003 int nfsrv_read(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
1004 proc_t procp
, mbuf_t
*mrq
);
1005 int nfsrv_readdir(struct nfsrv_descript
*nfsd
,
1006 struct nfssvc_sock
*slp
,
1007 proc_t procp
, mbuf_t
*mrq
);
1008 int nfsrv_readdirplus(struct nfsrv_descript
*nfsd
,
1009 struct nfssvc_sock
*slp
, proc_t procp
,
1011 int nfsrv_readlink(struct nfsrv_descript
*nfsd
,
1012 struct nfssvc_sock
*slp
, proc_t procp
,
1014 int nfsrv_remove(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
1015 proc_t procp
, mbuf_t
*mrq
);
1016 int nfsrv_rename(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
1017 proc_t procp
, mbuf_t
*mrq
);
1018 int nfsrv_rmdir(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
1019 proc_t procp
, mbuf_t
*mrq
);
1020 int nfsrv_setattr(struct nfsrv_descript
*nfsd
,
1021 struct nfssvc_sock
*slp
,
1022 proc_t procp
, mbuf_t
*mrq
);
1023 void nfsrv_slpderef(struct nfssvc_sock
*slp
);
1024 void nfsrv_slpfree(struct nfssvc_sock
*slp
);
1025 int nfsrv_statfs(struct nfsrv_descript
*nfsd
,
1026 struct nfssvc_sock
*slp
,
1027 proc_t procp
, mbuf_t
*mrq
);
1028 int nfsrv_symlink(struct nfsrv_descript
*nfsd
,
1029 struct nfssvc_sock
*slp
,
1030 proc_t procp
, mbuf_t
*mrq
);
1031 int nfsrv_write(struct nfsrv_descript
*nfsd
, struct nfssvc_sock
*slp
,
1032 proc_t procp
, mbuf_t
*mrq
);
1033 int nfsrv_vptofh( struct nfs_export
*, int, struct nfs_filehandle
*,
1034 vnode_t
, struct vfs_context
*, struct nfs_filehandle
*);
1036 void nfs_up(struct nfsmount
*, proc_t
, int, const char *);
1037 void nfs_down(struct nfsmount
*, proc_t
, int, int, const char *);
1039 struct nfs_diskless
;
1040 int nfs_boot_init(struct nfs_diskless
*nd
, proc_t procp
);
1041 int nfs_boot_getfh(struct nfs_diskless
*nd
, proc_t procp
, int v3
, int sotype
);
1046 #endif /* __APPLE_API_PRIVATE */