1 /* $NetBSD: ufs_bswap.h,v 1.11 2002/12/01 00:12:12 matt Exp $ */ 2 3 /* 4 * Copyright (c) 1998 Manuel Bouyer. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 2. Redistributions in binary form must reproduce the above copyright 12 * notice, this list of conditions and the following disclaimer in the 13 * documentation and/or other materials provided with the distribution. 14 * 3. All advertising materials mentioning features or use of this software 15 * must display the following acknowledgement: 16 * This product includes software developed by the University of 17 * California, Berkeley and its contributors. 18 * 4. Neither the name of the University nor the names of its contributors 19 * may be used to endorse or promote products derived from this software 20 * without specific prior written permission. 21 * 22 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 23 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 24 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 25 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 27 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 31 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 32 * 33 */ 34 35 #ifndef _UFS_UFS_BSWAP_H_ 36 #define _UFS_UFS_BSWAP_H_ 37 38 #if defined(_KERNEL_OPT) 39 #include "opt_ffs.h" 40 #endif 41 42 #include <machine/bswap.h> 43 44 /* Macros to access UFS flags */ 45 #ifdef FFS_EI 46 #define UFS_MPNEEDSWAP(mp) (VFSTOUFS(mp)->um_flags & UFS_NEEDSWAP) 47 #define UFS_FSNEEDSWAP(fs) ((fs)->fs_flags & FS_SWAPPED) 48 #define UFS_IPNEEDSWAP(ip) UFS_MPNEEDSWAP(ITOV(ip)->v_mount) 49 #else 50 #define UFS_MPNEEDSWAP(mp) (0) 51 #define UFS_FSNEEDSWAP(fs) (0) 52 #define UFS_IPNEEDSWAP(ip) (0) 53 #endif 54 55 #if !defined(_KERNEL) || defined(FFS_EI) 56 /* inlines for access to swapped data */ 57 static __inline u_int16_t ufs_rw16 __P((u_int16_t, int)); 58 static __inline u_int32_t ufs_rw32 __P((u_int32_t, int)); 59 static __inline u_int64_t ufs_rw64 __P((u_int64_t, int)); 60 61 static __inline u_int16_t 62 ufs_rw16(a, ns) 63 u_int16_t a; 64 int ns; 65 { 66 return ((ns) ? bswap16(a) : (a)); 67 } 68 static __inline u_int32_t 69 ufs_rw32(a, ns) 70 u_int32_t a; 71 int ns; 72 { 73 return ((ns) ? bswap32(a) : (a)); 74 } 75 static __inline u_int64_t 76 ufs_rw64(a, ns) 77 u_int64_t a; 78 int ns; 79 { 80 return ((ns) ? bswap64(a) : (a)); 81 } 82 #else 83 #define ufs_rw16(a, ns) (a) 84 #define ufs_rw32(a, ns) (a) 85 #define ufs_rw64(a, ns) (a) 86 #endif 87 88 #define ufs_add16(a, b, ns) \ 89 (a) = ufs_rw16(ufs_rw16((a), (ns)) + (b), (ns)) 90 #define ufs_add32(a, b, ns) \ 91 (a) = ufs_rw32(ufs_rw32((a), (ns)) + (b), (ns)) 92 #define ufs_add64(a, b, ns) \ 93 (a) = ufs_rw64(ufs_rw64((a), (ns)) + (b), (ns)) 94 95 #endif /* !_UFS_UFS_BSWAP_H_ */ 96