1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 /* 22 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 23 * Use is subject to license terms. 24 */ 25 #ifndef _NFS4_ATTRMAP_H 26 #define _NFS4_ATTRMAP_H 27 28 #pragma ident "%Z%%M% %I% %E% SMI" 29 30 #ifdef _KERNEL 31 #ifdef __cplusplus 32 extern "C" { 33 #endif 34 35 /* 36 * ATTRMAP_SET sets (to 1) bits in tgt_map 37 * which are set in mask_map. 38 */ 39 #define ATTRMAP_SET(tgt_map, mask_map) { \ 40 (tgt_map).d.d0 |= (mask_map).d.d0; \ 41 (tgt_map).d.d1 |= (mask_map).d.d1; \ 42 } 43 44 /* 45 * ATTRMAP_CLR clears (sets to 0) bits in tgt_map 46 * which are set in mask_map 47 */ 48 #define ATTRMAP_CLR(tgt_map, mask_map) { \ 49 (tgt_map).d.d0 &= ~(mask_map).d.d0; \ 50 (tgt_map).d.d1 &= ~(mask_map).d.d1; \ 51 } 52 53 /* 54 * ATTRMAP_MASK clears (sets to 0) bits in tgt_map 55 * which are not set in mask_map 56 */ 57 #define ATTRMAP_MASK(tgt_map, mask_map) { \ 58 (tgt_map).d.d0 &= (mask_map).d.d0; \ 59 (tgt_map).d.d1 &= (mask_map).d.d1; \ 60 } 61 62 /* 63 * ATTRMAP_XOR xors tgt_map and mask_map. 64 * Result is stored in tgt_map. 65 */ 66 #define ATTRMAP_XOR(tgt_map, mask_map) { \ 67 (tgt_map).d.d0 ^= (mask_map).d.d0; \ 68 (tgt_map).d.d1 ^= (mask_map).d.d1; \ 69 } 70 71 72 /* 73 * ATTRMAP_TST evaluates to nonzero if any of the mask_map bits 74 * are set in map. 75 */ 76 #define ATTRMAP_TST(map, mask_map) \ 77 (((map).d.d0 & (mask_map).d.d0) != 0 || \ 78 ((map).d.d1 & (mask_map).d.d1) != 0) 79 80 /* 81 * ATTRMAP_TST_CMPL evaluates to nonzero if any bits not set 82 * in mask_map are set in map. (tests complement of map mask) 83 */ 84 #define ATTRMAP_TST_CMPL(map, mask_map) \ 85 (((map).d.d0 & ~((mask_map).d.d0)) != 0 || \ 86 ((map).d.d1 & ~((mask_map).d.d1)) != 0) 87 88 /* 89 * ATTRMAP_EQL evaluates to nonzero if both dwords of map1 are 90 * equal to both dwords of map2 91 */ 92 #define ATTRMAP_EQL(map1, map2) \ 93 ((map1).d.d0 == (map2).d.d0 && (map1).d.d1 == (map2).d.d1) 94 95 /* 96 * ATTRMAP_EMPTY evaluates to nonzero if both map dwords are 0 97 * (no bits are set in map) 98 */ 99 #define ATTRMAP_EMPTY(map) ((map).d.d0 == 0 && (map).d.d1 == 0) 100 101 102 #if defined(_BIG_ENDIAN) 103 104 struct am4word { 105 uint32_t w0; 106 uint32_t w1; 107 uint32_t w2; 108 uint32_t w3; 109 }; 110 111 #elif defined(_LITTLE_ENDIAN) 112 113 struct am4word { 114 uint32_t w1; 115 uint32_t w0; 116 uint32_t w3; 117 uint32_t w2; 118 }; 119 120 #endif 121 122 typedef struct am4word am4word_t; 123 124 struct am4dword { 125 uint64_t d0; 126 uint64_t d1; 127 }; 128 typedef struct am4dword am4dword_t; 129 130 131 union attrmap4_u { 132 am4dword_t d; 133 am4word_t w; 134 }; 135 typedef union attrmap4_u attrmap4; 136 137 /* 138 * The ATTR_* macros take an attrmap4 and the short 139 * attribute name. The short name doesn't include 140 * the FATTR4_ prefix (or the _MASK suffix). 141 * 142 * ATTR_ISSET evaluates to non-zero if the attr_nm is set 143 * in the attrmap (am4). 144 * 145 * ATTR_CLR sets the attr bit in am4 to 0 146 * 147 * ATTR_SET sets the attr bit in am4 to 1 148 */ 149 #define ATTR_ISSET(am4, attr_nm) \ 150 (((am4).__dw_##attr_nm & FATTR4_##attr_nm##_MASK) != 0) 151 152 #define ATTR_CLR(am4, attr_nm) \ 153 (am4).__dw_##attr_nm &= ~(FATTR4_##attr_nm##_MASK) 154 155 #define ATTR_SET(am4, attr_nm) \ 156 (am4).__dw_##attr_nm |= FATTR4_##attr_nm##_MASK 157 158 #ifdef __cplusplus 159 } 160 #endif 161 #endif /* _KERNEL */ 162 #endif /* _NFS4_ATTRMAP_H */ 163