]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
2d21ac55 | 2 | * Copyright (c) 2000-2007 Apple Inc. All rights reserved. |
5d5c5d0d | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */ | |
29 | /* | |
30 | * Copyright (c) 1989, 1993 | |
31 | * The Regents of the University of California. All rights reserved. | |
32 | * | |
33 | * This code is derived from software contributed to Berkeley by | |
34 | * Rick Macklem at The University of Guelph. | |
35 | * | |
36 | * Redistribution and use in source and binary forms, with or without | |
37 | * modification, are permitted provided that the following conditions | |
38 | * are met: | |
39 | * 1. Redistributions of source code must retain the above copyright | |
40 | * notice, this list of conditions and the following disclaimer. | |
41 | * 2. Redistributions in binary form must reproduce the above copyright | |
42 | * notice, this list of conditions and the following disclaimer in the | |
43 | * documentation and/or other materials provided with the distribution. | |
44 | * 3. All advertising materials mentioning features or use of this software | |
45 | * must display the following acknowledgement: | |
46 | * This product includes software developed by the University of | |
47 | * California, Berkeley and its contributors. | |
48 | * 4. Neither the name of the University nor the names of its contributors | |
49 | * may be used to endorse or promote products derived from this software | |
50 | * without specific prior written permission. | |
51 | * | |
52 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
53 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
54 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
55 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
56 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
57 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
58 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
59 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
60 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
61 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
62 | * SUCH DAMAGE. | |
63 | * | |
64 | * @(#)nfsnode.h 8.9 (Berkeley) 5/14/95 | |
65 | * FreeBSD-Id: nfsnode.h,v 1.24 1997/10/28 14:06:25 bde Exp $ | |
66 | */ | |
67 | ||
68 | ||
69 | #ifndef _NFS_NFSNODE_H_ | |
70 | #define _NFS_NFSNODE_H_ | |
71 | ||
9bccf70c A |
72 | #include <sys/appleapiopts.h> |
73 | ||
74 | #ifdef __APPLE_API_PRIVATE | |
1c79356b A |
75 | #ifndef _NFS_NFS_H_ |
76 | #include <nfs/nfs.h> | |
77 | #endif | |
78 | ||
79 | /* | |
80 | * Silly rename structure that hangs off the nfsnode until the name | |
2d21ac55 | 81 | * can be removed by nfs_vnop_inactive() |
1c79356b | 82 | */ |
2d21ac55 A |
83 | struct nfs_sillyrename { |
84 | kauth_cred_t nsr_cred; | |
85 | struct nfsnode *nsr_dnp; | |
86 | int nsr_namlen; | |
87 | char nsr_name[20]; | |
1c79356b A |
88 | }; |
89 | ||
90 | /* | |
91 | * This structure is used to save the logical directory offset to | |
92 | * NFS cookie mappings. | |
93 | * The mappings are stored in a list headed | |
94 | * by n_cookies, as required. | |
95 | * There is one mapping for each NFS_DIRBLKSIZ bytes of directory information | |
96 | * stored in increasing logical offset byte order. | |
97 | */ | |
98 | #define NFSNUMCOOKIES 31 | |
99 | ||
100 | struct nfsdmap { | |
101 | LIST_ENTRY(nfsdmap) ndm_list; | |
102 | int ndm_eocookie; | |
103 | nfsuint64 ndm_cookies[NFSNUMCOOKIES]; | |
104 | }; | |
105 | ||
55e303ae A |
106 | /* |
107 | * The nfsbuf is the nfs equivalent to a struct buf. | |
108 | */ | |
109 | struct nfsbuf { | |
110 | LIST_ENTRY(nfsbuf) nb_hash; /* hash chain */ | |
2d21ac55 | 111 | LIST_ENTRY(nfsbuf) nb_vnbufs; /* nfsnode's nfsbuf chain */ |
55e303ae A |
112 | TAILQ_ENTRY(nfsbuf) nb_free; /* free list position if not active. */ |
113 | volatile long nb_flags; /* NB_* flags. */ | |
91447636 A |
114 | volatile long nb_lflags; /* NBL_* flags. */ |
115 | volatile long nb_refs; /* outstanding references. */ | |
55e303ae | 116 | long nb_bufsize; /* buffer size */ |
91447636 | 117 | daddr64_t nb_lblkno; /* logical block number. */ |
8f6c56a5 | 118 | uint64_t nb_verf; /* V3 write verifier */ |
2d21ac55 | 119 | int nb_commitlevel; /* lowest write commit level */ |
91447636 | 120 | time_t nb_timestamp; /* buffer timestamp */ |
55e303ae A |
121 | int nb_error; /* errno value. */ |
122 | u_int32_t nb_valid; /* valid pages in buf */ | |
123 | u_int32_t nb_dirty; /* dirty pages in buf */ | |
124 | int nb_validoff; /* offset in buffer of valid region. */ | |
125 | int nb_validend; /* offset of end of valid region. */ | |
126 | int nb_dirtyoff; /* offset in buffer of dirty region. */ | |
127 | int nb_dirtyend; /* offset of end of dirty region. */ | |
2d21ac55 A |
128 | int nb_offio; /* offset in buffer of I/O region. */ |
129 | int nb_endio; /* offset of end of I/O region. */ | |
130 | int nb_rpcs; /* Count of RPCs remaining for this buffer. */ | |
55e303ae | 131 | caddr_t nb_data; /* mapped buffer */ |
2d21ac55 A |
132 | nfsnode_t nb_np; /* nfsnode buffer belongs to */ |
133 | kauth_cred_t nb_rcred; /* read credentials reference */ | |
134 | kauth_cred_t nb_wcred; /* write credentials reference */ | |
55e303ae A |
135 | void * nb_pagelist; /* upl */ |
136 | }; | |
137 | ||
0c530ab8 A |
138 | #define NFS_MAXBSIZE (32 * PAGE_SIZE) /* valid/dirty page masks limit buffer size */ |
139 | ||
2d21ac55 A |
140 | #define NFS_A_LOT_OF_NEEDCOMMITS 256 /* max# uncommitted buffers for a node */ |
141 | #define NFS_A_LOT_OF_DELAYED_WRITES MAX(nfsbufcnt/8,512) /* max# "delwri" buffers in system */ | |
142 | ||
91447636 | 143 | /* |
2d21ac55 | 144 | * These flags are kept in b_lflags... |
91447636 A |
145 | * nfs_buf_mutex must be held before examining/updating |
146 | */ | |
147 | #define NBL_BUSY 0x00000001 /* I/O in progress. */ | |
148 | #define NBL_WANTED 0x00000002 /* Process wants this buffer. */ | |
149 | ||
55e303ae A |
150 | /* |
151 | * These flags are kept in nb_flags and they're (purposefully) | |
152 | * very similar to the B_* flags for struct buf. | |
91447636 | 153 | * nfs_buf_mutex is not needed to examine/update these. |
55e303ae | 154 | */ |
2d21ac55 A |
155 | #define NB_STALEWVERF 0x00000001 /* write verifier changed on us */ |
156 | #define NB_NEEDCOMMIT 0x00000002 /* buffer needs to be committed */ | |
55e303ae | 157 | #define NB_ASYNC 0x00000004 /* Start I/O, do not wait. */ |
2d21ac55 A |
158 | #define NB_CACHE 0x00000020 /* buffer data found in the cache */ |
159 | #define NB_STABLE 0x00000040 /* write FILESYNC not UNSTABLE */ | |
160 | #define NB_DELWRI 0x00000080 /* delayed write: dirty range needs to be written */ | |
55e303ae A |
161 | #define NB_DONE 0x00000200 /* I/O completed. */ |
162 | #define NB_EINTR 0x00000400 /* I/O was interrupted */ | |
163 | #define NB_ERROR 0x00000800 /* I/O error occurred. */ | |
55e303ae | 164 | #define NB_INVAL 0x00002000 /* Does not contain valid info. */ |
2d21ac55 | 165 | #define NB_NCRDAHEAD 0x00004000 /* "nocache readahead" data */ |
55e303ae | 166 | #define NB_NOCACHE 0x00008000 /* Do not cache block after use. */ |
2d21ac55 | 167 | #define NB_WRITE 0x00000000 /* Write buffer (pseudo flag). */ |
55e303ae | 168 | #define NB_READ 0x00100000 /* Read buffer. */ |
2d21ac55 | 169 | #define NB_MULTASYNCRPC 0x00200000 /* multiple async RPCs issued for buffer */ |
55e303ae | 170 | #define NB_PAGELIST 0x00400000 /* Buffer describes pagelist I/O. */ |
55e303ae A |
171 | #define NB_WRITEINPROG 0x01000000 /* Write in progress. */ |
172 | #define NB_META 0x40000000 /* buffer contains meta-data. */ | |
55e303ae | 173 | |
91447636 A |
174 | /* Flags for operation type in nfs_buf_get() */ |
175 | #define NBLK_READ 0x00000001 /* buffer for read */ | |
176 | #define NBLK_WRITE 0x00000002 /* buffer for write */ | |
177 | #define NBLK_META 0x00000004 /* buffer for metadata */ | |
178 | #define NBLK_OPMASK 0x00000007 /* operation mask */ | |
179 | /* modifiers for above flags... */ | |
180 | #define NBLK_NOWAIT 0x40000000 /* don't wait on busy buffer */ | |
181 | #define NBLK_ONLYVALID 0x80000000 /* only return cached buffer */ | |
182 | ||
183 | /* These flags are used for nfsbuf iterating */ | |
184 | #define NBI_ITER 0x01 /* iteration in progress */ | |
185 | #define NBI_ITERWANT 0x02 /* waiting to iterate */ | |
186 | #define NBI_CLEAN 0x04 /* requesting clean buffers */ | |
187 | #define NBI_DIRTY 0x08 /* requesting dirty buffers */ | |
188 | #define NBI_NOWAIT 0x10 /* don't block on NBI_ITER */ | |
189 | ||
190 | /* Flags for nfs_buf_acquire */ | |
191 | #define NBAC_NOWAIT 0x01 /* Don't wait if buffer is busy */ | |
192 | #define NBAC_REMOVE 0x02 /* Remove from free list once buffer is acquired */ | |
193 | ||
194 | /* some convenience macros... */ | |
55e303ae A |
195 | #define NBOFF(BP) ((off_t)(BP)->nb_lblkno * (off_t)(BP)->nb_bufsize) |
196 | #define NBPGVALID(BP,P) (((BP)->nb_valid >> (P)) & 0x1) | |
197 | #define NBPGDIRTY(BP,P) (((BP)->nb_dirty >> (P)) & 0x1) | |
198 | #define NBPGVALID_SET(BP,P) ((BP)->nb_valid |= (1 << (P))) | |
199 | #define NBPGDIRTY_SET(BP,P) ((BP)->nb_dirty |= (1 << (P))) | |
200 | ||
91447636 A |
201 | #define NBUFSTAMPVALID(BP) ((BP)->nb_timestamp != ~0) |
202 | #define NBUFSTAMPINVALIDATE(BP) ((BP)->nb_timestamp = ~0) | |
203 | ||
55e303ae A |
204 | #define NFS_BUF_MAP(BP) \ |
205 | do { \ | |
206 | if (!(BP)->nb_data && nfs_buf_map(BP)) \ | |
207 | panic("nfs_buf_map failed"); \ | |
208 | } while (0) | |
209 | ||
210 | LIST_HEAD(nfsbuflists, nfsbuf); | |
211 | TAILQ_HEAD(nfsbuffreehead, nfsbuf); | |
212 | ||
213 | #define NFSNOLIST ((struct nfsbuf *)0xdeadbeef) | |
214 | ||
2d21ac55 A |
215 | __private_extern__ lck_mtx_t *nfs_buf_mutex; |
216 | __private_extern__ int nfsbufcnt, nfsbufmin, nfsbufmax, nfsbufmetacnt, nfsbufmetamax; | |
217 | __private_extern__ int nfsbuffreecnt, nfsbuffreemetacnt, nfsbufdelwricnt, nfsneedbuffer; | |
218 | __private_extern__ int nfs_nbdwrite; | |
219 | __private_extern__ struct nfsbuffreehead nfsbuffree, nfsbufdelwri; | |
55e303ae | 220 | |
2d21ac55 A |
221 | #ifdef NFSBUFDEBUG |
222 | #define NFSBUFCNTCHK() \ | |
55e303ae A |
223 | do { \ |
224 | if ( (nfsbufcnt < 0) || \ | |
225 | (nfsbufcnt > nfsbufmax) || \ | |
91447636 A |
226 | (nfsbufmetacnt < 0) || \ |
227 | (nfsbufmetacnt > nfsbufmetamax) || \ | |
228 | (nfsbufmetacnt > nfsbufcnt) || \ | |
55e303ae A |
229 | (nfsbuffreecnt < 0) || \ |
230 | (nfsbuffreecnt > nfsbufmax) || \ | |
231 | (nfsbuffreecnt > nfsbufcnt) || \ | |
483a1d10 A |
232 | (nfsbuffreemetacnt < 0) || \ |
233 | (nfsbuffreemetacnt > nfsbufmax) || \ | |
234 | (nfsbuffreemetacnt > nfsbufcnt) || \ | |
91447636 A |
235 | (nfsbuffreemetacnt > nfsbufmetamax) || \ |
236 | (nfsbuffreemetacnt > nfsbufmetacnt) || \ | |
55e303ae A |
237 | (nfsbufdelwricnt < 0) || \ |
238 | (nfsbufdelwricnt > nfsbufmax) || \ | |
239 | (nfsbufdelwricnt > nfsbufcnt) || \ | |
240 | (nfs_nbdwrite < 0) || \ | |
241 | (nfs_nbdwrite > nfsbufcnt) || \ | |
242 | 0) \ | |
91447636 A |
243 | panic("nfsbuf count error: max %d meta %d cnt %d meta %d free %d meta %d delwr %d bdw %d\n", \ |
244 | nfsbufmax, nfsbufmetamax, nfsbufcnt, nfsbufmetacnt, nfsbuffreecnt, nfsbuffreemetacnt, \ | |
55e303ae | 245 | nfsbufdelwricnt, nfs_nbdwrite); \ |
2d21ac55 A |
246 | } while (0) |
247 | #else | |
248 | #define NFSBUFCNTCHK() | |
249 | #endif | |
250 | ||
251 | /* | |
252 | * NFS vnode attribute structure | |
253 | */ | |
254 | #define NFSTIME_ACCESS 0 /* time of last access */ | |
255 | #define NFSTIME_MODIFY 1 /* time of last modification */ | |
256 | #define NFSTIME_CHANGE 2 /* time file changed */ | |
257 | #define NFSTIME_CREATE 3 /* time file created */ | |
258 | #define NFSTIME_BACKUP 4 /* time of last backup */ | |
259 | #define NFSTIME_COUNT 5 | |
260 | ||
261 | #define NFS_COMPARE_MTIME(TVP, NVAP, CMP) \ | |
262 | (((TVP)->tv_sec == (NVAP)->nva_timesec[NFSTIME_MODIFY]) ? \ | |
263 | ((TVP)->tv_nsec CMP (NVAP)->nva_timensec[NFSTIME_MODIFY]) : \ | |
264 | ((TVP)->tv_sec CMP (NVAP)->nva_timesec[NFSTIME_MODIFY])) | |
265 | #define NFS_COPY_TIME(TVP, NVAP, WHICH) \ | |
266 | do { \ | |
267 | (TVP)->tv_sec = (NVAP)->nva_timesec[NFSTIME_##WHICH]; \ | |
268 | (TVP)->tv_nsec = (NVAP)->nva_timensec[NFSTIME_##WHICH]; \ | |
55e303ae A |
269 | } while (0) |
270 | ||
91447636 A |
271 | struct nfs_vattr { |
272 | enum vtype nva_type; /* vnode type (for create) */ | |
2d21ac55 | 273 | uint32_t nva_mode; /* files access mode (and type) */ |
91447636 A |
274 | uid_t nva_uid; /* owner user id */ |
275 | gid_t nva_gid; /* owner group id */ | |
2d21ac55 A |
276 | nfs_specdata nva_rawdev; /* device the special file represents */ |
277 | uint32_t nva_flags; /* file flags */ | |
278 | uint32_t nva_maxlink; /* maximum # of links (v4) */ | |
279 | uint64_t nva_nlink; /* number of references to file */ | |
91447636 | 280 | uint64_t nva_fileid; /* file id */ |
2d21ac55 | 281 | nfs_fsid nva_fsid; /* file system id */ |
91447636 A |
282 | uint64_t nva_size; /* file size in bytes */ |
283 | uint64_t nva_bytes; /* bytes of disk space held by file */ | |
2d21ac55 A |
284 | uint64_t nva_change; /* change attribute */ |
285 | int64_t nva_timesec[NFSTIME_COUNT]; | |
286 | int32_t nva_timensec[NFSTIME_COUNT]; | |
287 | uint32_t nva_bitmap[NFS_ATTR_BITMAP_LEN]; /* attributes that are valid */ | |
91447636 A |
288 | }; |
289 | ||
2d21ac55 A |
290 | #define NFS_FFLAG_ARCHIVED 0x0001 |
291 | #define NFS_FFLAG_HIDDEN 0x0002 | |
292 | #define NFS_FFLAG_NAMED_ATTR 0x0004 /* file has named attributes */ | |
293 | ||
294 | /* | |
295 | * macros for detecting node changes | |
296 | * | |
297 | * These macros help us determine if a file has been changed on the server and | |
298 | * thus whether or not we need to invalidate any cached data. | |
299 | * | |
300 | * For NFSv2/v3, the modification time is used. | |
301 | * For NFSv4, the change attribute is used. | |
302 | */ | |
303 | #define NFS_CHANGED(VERS, NP, NVAP) \ | |
304 | (((VERS) >= NFS_VER4) ? \ | |
305 | ((NP)->n_change != (NVAP)->nva_change) : \ | |
306 | NFS_COMPARE_MTIME(&(NP)->n_mtime, (NVAP), !=)) | |
307 | #define NFS_CHANGED_NC(VERS, NP, NVAP) \ | |
308 | (((VERS) >= NFS_VER4) ? \ | |
309 | ((NP)->n_ncchange != (NVAP)->nva_change) : \ | |
310 | NFS_COMPARE_MTIME(&(NP)->n_ncmtime, (NVAP), !=)) | |
311 | #define NFS_CHANGED_UPDATE(VERS, NP, NVAP) \ | |
312 | do { \ | |
313 | if ((VERS) >= NFS_VER4) \ | |
314 | (NP)->n_change = (NVAP)->nva_change; \ | |
315 | else \ | |
316 | NFS_COPY_TIME(&(NP)->n_mtime, (NVAP), MODIFY); \ | |
317 | } while (0) | |
318 | #define NFS_CHANGED_UPDATE_NC(VERS, NP, NVAP) \ | |
319 | do { \ | |
320 | if ((VERS) >= NFS_VER4) \ | |
321 | (NP)->n_ncchange = (NVAP)->nva_change; \ | |
322 | else \ | |
323 | NFS_COPY_TIME(&(NP)->n_ncmtime, (NVAP), MODIFY); \ | |
324 | } while (0) | |
325 | ||
1c79356b | 326 | /* |
2d21ac55 A |
327 | * The nfsnode is the NFS equivalent of an inode. |
328 | * There is a unique nfsnode for each NFS vnode. | |
1c79356b | 329 | * An nfsnode is 'named' by its file handle. (nget/nfs_node.c) |
1c79356b A |
330 | * NB: Hopefully the current order of the fields is such that everything will |
331 | * be well aligned and, therefore, tightly packed. | |
332 | */ | |
2d21ac55 A |
333 | |
334 | #define NFS_ACCESS_CACHE_SIZE 3 | |
335 | ||
1c79356b | 336 | struct nfsnode { |
2d21ac55 A |
337 | lck_rw_t n_lock; /* nfs node lock */ |
338 | void *n_lockowner; /* nfs node lock owner (exclusive) */ | |
339 | lck_rw_t n_datalock; /* nfs node data lock */ | |
340 | void *n_datalockowner;/* nfs node data lock owner (exclusive) */ | |
1c79356b | 341 | LIST_ENTRY(nfsnode) n_hash; /* Hash chain */ |
1c79356b | 342 | u_quad_t n_size; /* Current size of file */ |
2d21ac55 A |
343 | u_quad_t n_newsize; /* new size of file (pending update) */ |
344 | u_int64_t n_xid; /* last xid to loadattr */ | |
91447636 | 345 | struct nfs_vattr n_vattr; /* Vnode attribute cache */ |
1c79356b | 346 | time_t n_attrstamp; /* Attr. cache timestamp */ |
2d21ac55 A |
347 | u_int8_t n_mode[NFS_ACCESS_CACHE_SIZE+1]; /* ACCESS mode cache */ |
348 | uid_t n_modeuid[NFS_ACCESS_CACHE_SIZE]; /* credentials having mode */ | |
349 | time_t n_modestamp[NFS_ACCESS_CACHE_SIZE]; /* mode cache timestamp */ | |
55e303ae | 350 | union { |
2d21ac55 A |
351 | struct { |
352 | struct timespec n3_mtime; /* Prev modify time. */ | |
353 | struct timespec n3_ncmtime; /* namecache modify time. */ | |
354 | } v3; | |
355 | struct { | |
356 | uint64_t n4_change; /* prev change attribute */ | |
357 | uint64_t n4_ncchange; /* namecache change attribute */ | |
358 | } v4; | |
359 | } n_un4; | |
360 | vnode_t n_parent; /* this node's parent */ | |
361 | u_char *n_fhp; /* NFS File Handle */ | |
362 | vnode_t n_vnode; /* associated vnode */ | |
363 | mount_t n_mount; /* associated mount (NHINIT) */ | |
1c79356b A |
364 | int n_error; /* Save write error value */ |
365 | union { | |
366 | struct timespec nf_atim; /* Special file times */ | |
367 | nfsuint64 nd_cookieverf; /* Cookie verifier (dir only) */ | |
368 | } n_un1; | |
369 | union { | |
2d21ac55 A |
370 | struct timespec nf_mtim; /* Special file times */ |
371 | daddr64_t nf_lastread; /* last block# read from (for readahead) */ | |
1c79356b A |
372 | off_t nd_direof; /* Dir. EOF offset cache */ |
373 | } n_un2; | |
374 | union { | |
2d21ac55 | 375 | struct nfs_sillyrename *nf_silly;/* Ptr to silly rename struct */ |
1c79356b A |
376 | LIST_HEAD(, nfsdmap) nd_cook; /* cookies */ |
377 | } n_un3; | |
2d21ac55 A |
378 | u_short n_fhsize; /* size in bytes, of fh */ |
379 | u_short n_flag; /* node flags */ | |
380 | u_short n_hflag; /* node hash flags */ | |
381 | u_short n_bflag; /* node buffer flags */ | |
91447636 | 382 | u_char n_fh[NFS_SMALLFH];/* Small File Handle */ |
55e303ae A |
383 | struct nfsbuflists n_cleanblkhd; /* clean blocklist head */ |
384 | struct nfsbuflists n_dirtyblkhd; /* dirty blocklist head */ | |
2d21ac55 | 385 | int n_wrbusy; /* # threads in write/fsync */ |
55e303ae | 386 | int n_needcommitcnt;/* # bufs that need committing */ |
91447636 | 387 | int n_bufiterflags; /* buf iterator flags */ |
1c79356b A |
388 | }; |
389 | ||
2d21ac55 A |
390 | #define NFS_NODE_LOCK_SHARED 1 |
391 | #define NFS_NODE_LOCK_EXCLUSIVE 2 | |
392 | #define NFS_NODE_LOCK_FORCE 3 | |
393 | ||
91447636 A |
394 | #define nfstimespeccmp(tvp, uvp, cmp) \ |
395 | (((tvp)->tv_sec == (uvp)->tv_sec) ? \ | |
396 | ((tvp)->tv_nsec cmp (uvp)->tv_nsec) : \ | |
397 | ((tvp)->tv_sec cmp (uvp)->tv_sec)) | |
398 | ||
55e303ae A |
399 | #define CHECK_NEEDCOMMITCNT(np) \ |
400 | do { \ | |
401 | if ((np)->n_needcommitcnt < 0) { \ | |
402 | printf("nfs: n_needcommitcnt negative\n"); \ | |
403 | (np)->n_needcommitcnt = 0; \ | |
404 | } \ | |
405 | } while (0) | |
406 | ||
2d21ac55 A |
407 | #define n_atim n_un1.nf_atim |
408 | #define n_mtim n_un2.nf_mtim | |
409 | #define n_lastread n_un2.nf_lastread | |
410 | #define n_sillyrename n_un3.nf_silly | |
411 | #define n_cookieverf n_un1.nd_cookieverf | |
412 | #define n_direofoffset n_un2.nd_direof | |
413 | #define n_cookies n_un3.nd_cook | |
414 | #define n_mtime n_un4.v3.n3_mtime | |
415 | #define n_ncmtime n_un4.v3.n3_ncmtime | |
416 | #define n_change n_un4.v4.n4_change | |
417 | #define n_ncchange n_un4.v4.n4_ncchange | |
1c79356b A |
418 | |
419 | /* | |
420 | * Flags for n_flag | |
421 | */ | |
2d21ac55 | 422 | #define NUPDATESIZE 0x0001 /* size of file needs updating */ |
1c79356b A |
423 | #define NMODIFIED 0x0004 /* Might have a modified buffer in bio */ |
424 | #define NWRITEERR 0x0008 /* Flag write errors so close will know */ | |
91447636 | 425 | #define NNEEDINVALIDATE 0x0010 /* need to call vinvalbuf() */ |
1c79356b A |
426 | #define NACC 0x0100 /* Special file accessed */ |
427 | #define NUPD 0x0200 /* Special file updated */ | |
428 | #define NCHG 0x0400 /* Special file times changed */ | |
2d21ac55 | 429 | #define NNEGNCENTRIES 0x0800 /* directory has negative name cache entries */ |
1c79356b | 430 | |
2d21ac55 A |
431 | /* |
432 | * Flags for n_hflag | |
433 | * Note: protected by nfs_node_hash_mutex | |
434 | */ | |
435 | #define NHHASHED 0x0001 /* node is in hash table */ | |
436 | #define NHINIT 0x0002 /* node is being initialized */ | |
437 | #define NHLOCKED 0x0004 /* node is locked (initting or deleting) */ | |
438 | #define NHLOCKWANT 0x0008 /* someone wants to lock */ | |
439 | ||
440 | /* | |
441 | * Flags for n_bflag | |
442 | * Note: protected by nfs_buf_mutex | |
443 | */ | |
444 | #define NBFLUSHINPROG 0x0001 /* Avoid multiple calls to nfs_flush() */ | |
445 | #define NBFLUSHWANT 0x0002 /* waiting for nfs_flush() to complete */ | |
446 | #define NBINVALINPROG 0x0004 /* Avoid multiple calls to nfs_vinvalbuf() */ | |
447 | #define NBINVALWANT 0x0008 /* waiting for nfs_vinvalbuf() to complete */ | |
448 | ||
449 | /* attr/mode timestamp macros */ | |
91447636 A |
450 | #define NATTRVALID(np) ((np)->n_attrstamp != ~0) |
451 | #define NATTRINVALIDATE(np) ((np)->n_attrstamp = ~0) | |
2d21ac55 A |
452 | #define NMODEVALID(np, slot) (((slot) >= 0) && ((slot) < 3) && ((np)->n_modestamp[(slot)] != ~0)) |
453 | #define NMODEINVALIDATE(np) \ | |
454 | do { \ | |
455 | (np)->n_modestamp[0] = ~0; \ | |
456 | (np)->n_modestamp[1] = ~0; \ | |
457 | (np)->n_modestamp[2] = ~0; \ | |
458 | (np)->n_mode[3] = 0; \ | |
459 | } while (0) | |
91447636 A |
460 | |
461 | /* | |
462 | * NFS-specific flags for nfs_vinvalbuf/nfs_flush | |
463 | */ | |
464 | #define V_IGNORE_WRITEERR 0x8000 | |
465 | ||
466 | /* | |
467 | * Flags for nfs_nget() | |
468 | */ | |
469 | #define NG_MARKROOT 0x0001 /* mark vnode as root of FS */ | |
470 | #define NG_MAKEENTRY 0x0002 /* add name cache entry for vnode */ | |
471 | ||
1c79356b A |
472 | /* |
473 | * Convert between nfsnode pointers and vnode pointers | |
474 | */ | |
2d21ac55 | 475 | #define VTONFS(vp) ((nfsnode_t)vnode_fsnode(vp)) |
91447636 A |
476 | #define NFSTOV(np) ((np)->n_vnode) |
477 | ||
478 | /* nfsnode hash table mutex */ | |
2d21ac55 | 479 | __private_extern__ lck_mtx_t *nfs_node_hash_mutex; |
1c79356b A |
480 | |
481 | /* | |
91447636 | 482 | * nfsiod structures |
1c79356b | 483 | */ |
2d21ac55 A |
484 | struct nfsiod { |
485 | TAILQ_ENTRY(nfsiod) niod_link; /* List of nfsiods */ | |
486 | struct nfsmount * niod_nmp; /* mount point for this nfsiod */ | |
487 | }; | |
488 | TAILQ_HEAD(nfsiodlist, nfsiod); | |
489 | TAILQ_HEAD(nfsiodmountlist, nfsmount); | |
490 | __private_extern__ struct nfsiodlist nfsiodfree, nfsiodwork; | |
491 | __private_extern__ struct nfsiodmountlist nfsiodmounts; | |
492 | __private_extern__ lck_mtx_t *nfsiod_mutex; | |
1c79356b A |
493 | |
494 | #if defined(KERNEL) | |
fa4905b1 | 495 | |
91447636 A |
496 | typedef int vnop_t(void *); |
497 | extern vnop_t **fifo_nfsv2nodeop_p; | |
498 | extern vnop_t **nfsv2_vnodeop_p; | |
499 | extern vnop_t **spec_nfsv2nodeop_p; | |
2d21ac55 A |
500 | extern vnop_t **fifo_nfsv4nodeop_p; |
501 | extern vnop_t **nfsv4_vnodeop_p; | |
502 | extern vnop_t **spec_nfsv4nodeop_p; | |
1c79356b A |
503 | |
504 | /* | |
505 | * Prototypes for NFS vnode operations | |
506 | */ | |
2d21ac55 A |
507 | int nfs_vnop_write(struct vnop_write_args *); |
508 | #define nfs_vnop_revoke nop_revoke | |
509 | int nfs_vnop_inactive(struct vnop_inactive_args *); | |
510 | int nfs_vnop_reclaim(struct vnop_reclaim_args *); | |
511 | ||
512 | int nfs_lock(nfsnode_t, int); | |
513 | void nfs_unlock(nfsnode_t); | |
514 | int nfs_lock2(nfsnode_t, nfsnode_t, int); | |
515 | void nfs_unlock2(nfsnode_t, nfsnode_t); | |
516 | int nfs_lock4(nfsnode_t, nfsnode_t, nfsnode_t, nfsnode_t, int); | |
517 | void nfs_unlock4(nfsnode_t, nfsnode_t, nfsnode_t, nfsnode_t); | |
518 | void nfs_data_lock(nfsnode_t, int); | |
519 | void nfs_data_lock2(nfsnode_t, int, int); | |
520 | void nfs_data_unlock(nfsnode_t); | |
521 | void nfs_data_unlock2(nfsnode_t, int); | |
522 | void nfs_data_update_size(nfsnode_t, int); | |
1c79356b | 523 | |
91447636 | 524 | /* other stuff */ |
2d21ac55 A |
525 | int nfs_removeit(struct nfs_sillyrename *); |
526 | int nfs_nget(mount_t,nfsnode_t,struct componentname *,u_char *,int,struct nfs_vattr *,u_int64_t *,int,nfsnode_t*); | |
527 | nfsuint64 *nfs_getcookie(nfsnode_t, off_t, int); | |
528 | void nfs_invaldir(nfsnode_t); | |
1c79356b | 529 | |
55e303ae A |
530 | /* nfsbuf functions */ |
531 | void nfs_nbinit(void); | |
2d21ac55 | 532 | void nfs_buf_timer(void *, void *); |
55e303ae | 533 | void nfs_buf_remfree(struct nfsbuf *); |
2d21ac55 A |
534 | boolean_t nfs_buf_is_incore(nfsnode_t, daddr64_t); |
535 | struct nfsbuf * nfs_buf_incore(nfsnode_t, daddr64_t); | |
536 | int nfs_buf_get(nfsnode_t, daddr64_t, int, thread_t, int, struct nfsbuf **); | |
55e303ae A |
537 | int nfs_buf_upl_setup(struct nfsbuf *bp); |
538 | void nfs_buf_upl_check(struct nfsbuf *bp); | |
2d21ac55 A |
539 | void nfs_buf_normalize_valid_range(nfsnode_t, struct nfsbuf *); |
540 | int nfs_buf_map(struct nfsbuf *); | |
483a1d10 | 541 | void nfs_buf_release(struct nfsbuf *, int); |
55e303ae A |
542 | int nfs_buf_iowait(struct nfsbuf *); |
543 | void nfs_buf_iodone(struct nfsbuf *); | |
2d21ac55 A |
544 | void nfs_buf_write_delayed(struct nfsbuf *); |
545 | void nfs_buf_check_write_verifier(nfsnode_t, struct nfsbuf *); | |
483a1d10 | 546 | void nfs_buf_freeup(int); |
91447636 A |
547 | void nfs_buf_refget(struct nfsbuf *bp); |
548 | void nfs_buf_refrele(struct nfsbuf *bp); | |
549 | void nfs_buf_drop(struct nfsbuf *); | |
550 | errno_t nfs_buf_acquire(struct nfsbuf *, int, int, int); | |
2d21ac55 A |
551 | int nfs_buf_iterprepare(nfsnode_t, struct nfsbuflists *, int); |
552 | void nfs_buf_itercomplete(nfsnode_t, struct nfsbuflists *, int); | |
553 | ||
554 | int nfs_bioread(nfsnode_t, struct uio *, int, int *, vfs_context_t); | |
555 | int nfs_buf_readdir(struct nfsbuf *, vfs_context_t); | |
556 | int nfs_buf_read(struct nfsbuf *); | |
557 | void nfs_buf_read_finish(struct nfsbuf *); | |
558 | int nfs_buf_read_rpc(struct nfsbuf *, thread_t, kauth_cred_t); | |
559 | void nfs_buf_read_rpc_finish(struct nfsreq *); | |
560 | int nfs_buf_write(struct nfsbuf *); | |
561 | void nfs_buf_write_finish(struct nfsbuf *, thread_t, kauth_cred_t); | |
562 | int nfs_buf_write_rpc(struct nfsbuf *, int, thread_t, kauth_cred_t); | |
563 | void nfs_buf_write_rpc_finish(struct nfsreq *); | |
564 | int nfs_buf_write_dirty_pages(struct nfsbuf *, thread_t, kauth_cred_t); | |
565 | ||
566 | int nfs_flushcommits(nfsnode_t, int); | |
567 | int nfs_flush(nfsnode_t, int, thread_t, int); | |
568 | ||
569 | int nfsiod_start(void); | |
570 | void nfs_asyncio_finish(struct nfsreq *); | |
571 | void nfs_asyncio_resend(struct nfsreq *); | |
55e303ae | 572 | |
1c79356b A |
573 | #endif /* KERNEL */ |
574 | ||
9bccf70c A |
575 | #endif /* __APPLE_API_PRIVATE */ |
576 | #endif /* _NFS_NFSNODE_H_ */ |