1*342a1b22SJim906 /*-
2*342a1b22SJim906 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3*342a1b22SJim906 *
4*342a1b22SJim906 * Copyright (c) 2008 Attilio Rao <attilio@FreeBSD.org>
5*342a1b22SJim906 * All rights reserved.
6*342a1b22SJim906 *
7*342a1b22SJim906 * Redistribution and use in source and binary forms, with or without
8*342a1b22SJim906 * modification, are permitted provided that the following conditions
9*342a1b22SJim906 * are met:
10*342a1b22SJim906 * 1. Redistributions of source code must retain the above copyright
11*342a1b22SJim906 * notice(s), this list of conditions and the following disclaimer as
12*342a1b22SJim906 * the first lines of this file unmodified other than the possible
13*342a1b22SJim906 * addition of one or more copyright notices.
14*342a1b22SJim906 * 2. Redistributions in binary form must reproduce the above copyright
15*342a1b22SJim906 * notice(s), this list of conditions and the following disclaimer in the
16*342a1b22SJim906 * documentation and/or other materials provided with the distribution.
17*342a1b22SJim906 *
18*342a1b22SJim906 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY
19*342a1b22SJim906 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20*342a1b22SJim906 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21*342a1b22SJim906 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
22*342a1b22SJim906 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23*342a1b22SJim906 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
24*342a1b22SJim906 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
25*342a1b22SJim906 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*342a1b22SJim906 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*342a1b22SJim906 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
28*342a1b22SJim906 * DAMAGE.
29*342a1b22SJim906 */
30*342a1b22SJim906
31*342a1b22SJim906
32*342a1b22SJim906 // Modified to support the Haiku FAT driver.
33*342a1b22SJim906
34*342a1b22SJim906 #include "sys/param.h"
35*342a1b22SJim906 #include "sys/lockmgr.h"
36*342a1b22SJim906 #include "sys/mutex.h"
37*342a1b22SJim906 #include "sys/systm.h"
38*342a1b22SJim906
39*342a1b22SJim906
40*342a1b22SJim906 /*! @param flags LK_EXCLUSIVE or LK_SHARED by itself write- or read-locks the node, respectively.
41*342a1b22SJim906 LK_RELEASE in combination with LK_EXCLUSIVE or LK_SHARED write- or read-unlocks the node,
42*342a1b22SJim906 respectively.
43*342a1b22SJim906 @param ilk Ignored in the Haiku port.
44*342a1b22SJim906 */
45*342a1b22SJim906 void
lockmgr(struct lock * lk,u_int flags,struct mtx * ilk)46*342a1b22SJim906 lockmgr(struct lock* lk, u_int flags, struct mtx* ilk)
47*342a1b22SJim906 {
48*342a1b22SJim906 if ((flags & LK_RELEASE) != 0) {
49*342a1b22SJim906 if ((flags & LK_SHARED) != 0)
50*342a1b22SJim906 rw_lock_read_unlock(&lk->haikuRW);
51*342a1b22SJim906 else
52*342a1b22SJim906 rw_lock_write_unlock(&lk->haikuRW);
53*342a1b22SJim906 } else if ((flags & LK_EXCLUSIVE) != 0) {
54*342a1b22SJim906 rw_lock_write_lock(&lk->haikuRW);
55*342a1b22SJim906 } else if ((flags & LK_SHARED) != 0) {
56*342a1b22SJim906 rw_lock_read_lock(&lk->haikuRW);
57*342a1b22SJim906 } else {
58*342a1b22SJim906 panic("unrecognized lockmgr flag\n");
59*342a1b22SJim906 }
60*342a1b22SJim906
61*342a1b22SJim906 return;
62*342a1b22SJim906 }
63