2 * Copyright (c) 2002-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_OSREFERENCE_HEADER_START@
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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
31 * Copyright (c) 1998 Berkeley Software Design, Inc. All rights reserved.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. Berkeley Software Design Inc's name may not be used to endorse or
41 * promote products derived from this software without specific prior
44 * THIS SOFTWARE IS PROVIDED BY BERKELEY SOFTWARE DESIGN INC ``AS IS'' AND
45 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
46 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
47 * ARE DISCLAIMED. IN NO EVENT SHALL BERKELEY SOFTWARE DESIGN INC BE LIABLE
48 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
49 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
50 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
51 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
53 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
56 * from nfs_lock.h,v 2.2 1998/04/28 19:38:41 don Exp
60 #include <sys/appleapiopts.h>
62 #ifdef __APPLE_API_PRIVATE
65 * lockd uses the nfsclnt system call for the unique kernel services it needs.
66 * It passes in a request structure with a version number at the start.
67 * This prevents libc from needing to change if the information passed
68 * between lockd and the kernel needs to change.
70 * If a structure changes, you must bump the version number.
73 #include <nfs/nfsproto.h>
76 * The fifo where the kernel writes requests for locks on remote NFS files,
77 * and where lockd reads these requests. Note this is no longer hardwired
78 * in the kernel binary - lockd passes the file descriptor down via nfsclnt()
80 #define _PATH_LCKFIFO "/var/run/nfslockd"
83 * The structure that the kernel hands lockd for each lock request.
85 #define LOCKD_MSG_VERSION 3
86 typedef struct nfs_lock_msg
{
87 int lm_version
; /* LOCKD_MSG version */
88 int lm_flags
; /* request flags */
89 u_int64_t lm_xid
; /* unique message transaction ID */
90 struct flock lm_fl
; /* The lock request. */
91 struct sockaddr_storage lm_addr
; /* The address. */
92 int lm_fh_len
; /* The file handle length. */
93 struct xucred lm_cred
; /* user cred for lock req */
94 u_int8_t lm_fh
[NFS_SMALLFH
]; /* The file handle. */
98 #define LOCKD_MSG_BLOCK 0x0001 /* a blocking request */
99 #define LOCKD_MSG_TEST 0x0002 /* just a lock test */
100 #define LOCKD_MSG_NFSV3 0x0004 /* NFSv3 request */
101 #define LOCKD_MSG_CANCEL 0x0008 /* cancelling blocked request */
103 /* The structure used to maintain the pending request queue */
104 typedef struct nfs_lock_msg_request
{
105 TAILQ_ENTRY(nfs_lock_msg_request
) lmr_next
; /* in-kernel pending request list */
106 int lmr_answered
; /* received an answer? */
107 int lmr_errno
; /* return status */
108 int lmr_saved_errno
; /* original return status */
109 LOCKD_MSG lmr_msg
; /* the message */
112 TAILQ_HEAD(nfs_lock_msg_queue
, nfs_lock_msg_request
);
113 typedef struct nfs_lock_msg_queue LOCKD_MSG_QUEUE
;
117 * The structure that lockd hands the kernel for each lock answer.
119 #define LOCKD_ANS_VERSION 2
121 int la_version
; /* lockd_ans version */
122 int la_errno
; /* return status */
123 u_int64_t la_xid
; /* unique message transaction ID */
124 int la_flags
; /* answer flags */
125 pid_t la_pid
; /* pid of lock requester/owner */
126 off_t la_start
; /* lock starting offset */
127 off_t la_len
; /* lock length */
128 int la_fh_len
; /* The file handle length. */
129 u_int8_t la_fh
[NFS_SMALLFH
]; /* The file handle. */
133 #define LOCKD_ANS_GRANTED 0x0001 /* NLM_GRANTED request */
134 #define LOCKD_ANS_LOCK_INFO 0x0002 /* lock info valid */
135 #define LOCKD_ANS_LOCK_EXCL 0x0004 /* lock is exclusive */
139 void nfs_lockinit(void);
140 int nfs_dolock(struct vnop_advlock_args
*ap
);
141 int nfslockdans(proc_t p
, struct lockd_ans
*ansp
);
142 int nfslockdfd(proc_t p
, int fd
);
143 int nfslockdwait(proc_t p
);
145 extern vnode_t nfslockdvnode
;
146 extern int nfslockdwaiting
;
148 #endif /* __APPLE_API_PRIVATE */