1 /*- 2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD 3 * 4 * Copyright (c) 2008 Attilio Rao <attilio@FreeBSD.org> 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice(s), this list of conditions and the following disclaimer as 12 * the first lines of this file unmodified other than the possible 13 * addition of one or more copyright notices. 14 * 2. Redistributions in binary form must reproduce the above copyright 15 * notice(s), this list of conditions and the following disclaimer in the 16 * documentation and/or other materials provided with the distribution. 17 * 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER(S) ``AS IS'' AND ANY 19 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) BE LIABLE FOR ANY 22 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 28 * DAMAGE. 29 */ 30 #ifndef FAT_LOCKMGR_H 31 #define FAT_LOCKMGR_H 32 33 34 // Modified to support the Haiku FAT driver. 35 36 #ifndef FS_SHELL 37 #include <lock.h> 38 #endif 39 40 #include "sys/_mutex.h" 41 #include "sys/_rwlock.h" 42 43 44 // Flag for lockinit() that is used in the driver, but has no effect in the Haiku port. 45 #define LK_NOWITNESS 0x000010 46 47 // lockmgr() attribute flag. Has no effect in the Haiku port. 48 #define LK_NOWAIT 0x000200 49 50 // lockmgr() operation flags 51 #define LK_TYPE_MASK 0xFF0000 52 #define LK_EXCLUSIVE 0x080000 53 #define LK_RELEASE 0x100000 54 #define LK_SHARED 0x200000 55 56 // lockmgr_assert flag 57 #define KA_XLOCKED 0x00000004 58 59 60 struct lock { 61 u_int flags; 62 rw_lock haikuRW; 63 }; 64 65 void lockmgr(struct lock* lk, u_int flags, struct mtx* ilk); 66 67 68 /*! KA_XLOCKED is the only flag used by the FAT driver. 69 70 */ 71 static inline void 72 lockmgr_assert(const struct lock* lk, int what) 73 { 74 #ifndef FS_SHELL 75 if (what == KA_XLOCKED) 76 ASSERT_WRITE_LOCKED_RW_LOCK(&lk->haikuRW) 77 else 78 panic("lockmgr_assert: unrecognized flag\n"); 79 #endif // !FS_SHELL 80 81 return; 82 } 83 84 85 /*! Used to enable recursive locking. In the Haiku port, struct lock is implemented such that 86 recursive locking is always enabled. 87 */ 88 static inline void 89 lockallowrecurse(struct lock* lk) 90 { 91 return; 92 } 93 94 95 static inline void 96 lockdestroy(struct lock* lk) 97 { 98 rw_lock_destroy(&lk->haikuRW); 99 } 100 101 102 #endif // FAT_LOCKMGR_H 103