~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

Linux Cross Reference
Linux/fs/ufs/swab.h

Version: ~ [ 2.4.0 ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  linux/fs/ufs/swab.h
  3  *
  4  * Copyright (C) 1997, 1998 Francois-Rene Rideau <fare@tunes.org>
  5  * Copyright (C) 1998 Jakub Jelinek <jj@ultra.linux.cz>
  6  */
  7 
  8 #ifndef _UFS_SWAB_H
  9 #define _UFS_SWAB_H
 10 
 11 /*
 12  * Notes:
 13  *    HERE WE ASSUME EITHER BIG OR LITTLE ENDIAN UFSes
 14  *    in case there are ufs implementations that have strange bytesexes,
 15  *    you'll need to modify code here as well as in ufs_super.c and ufs_fs.h
 16  *    to support them.
 17  *
 18  *    WE ALSO ASSUME A REMOTELY SANE ARCHITECTURE BYTESEX.
 19  *    We are not ready to confront insane bytesexual perversions where
 20  *    conversion to/from little/big-endian is not an involution.
 21  *    That is, we require that XeYZ_to_cpu(x) == cpu_to_XeYZ(x)
 22  *
 23  *    NOTE that swab macros depend on a variable (or macro) swab being in
 24  *    scope and properly initialized (usually from sb->u.ufs_sb.s_swab).
 25  *    Its meaning depends on whether the architecture is sane-endian or not.
 26  *    For sane architectures, it's a flag taking values UFS_NATIVE_ENDIAN (0)
 27  *    or UFS_SWABBED_ENDIAN (1), indicating whether to swab or not.
 28  *    For pervert architectures, it's either UFS_LITTLE_ENDIAN or
 29  *    UFS_BIG_ENDIAN whose meaning you'll have to guess.
 30  *
 31  *    It is important to keep these conventions in synch with ufs_fs.h
 32  *    and super.c. Failure to do so (initializing swab to 0 both for
 33  *    NATIVE_ENDIAN and LITTLE_ENDIAN) led to nasty crashes on big endian
 34  *    machines reading little endian UFSes. Search for "swab =" in super.c.
 35  *
 36  *    I also suspect the whole UFS code to trust the on-disk structures
 37  *    much too much, which might lead to losing badly when mounting
 38  *    inconsistent partitions as UFS filesystems. fsck required (but of
 39  *    course, no fsck.ufs has yet to be ported from BSD to Linux as of 199808).
 40  */
 41 
 42 #include <linux/ufs_fs.h>
 43 #include <asm/byteorder.h>
 44 
 45 /*
 46  * These are only valid inside ufs routines,
 47  * after swab has been initialized to sb->u.ufs_sb.s_swab
 48  */
 49 #define SWAB16(x) ufs_swab16(swab,x)
 50 #define SWAB32(x) ufs_swab32(swab,x)
 51 #define SWAB64(x) ufs_swab64(swab,x)
 52 
 53 /*
 54  * We often use swabing, when we want to increment/decrement some value,
 55  * so these macros might become handy and increase readability. (Daniel)
 56  */
 57 #define INC_SWAB16(x)   ((x)=ufs_swab16_add(swab,x,1))
 58 #define INC_SWAB32(x)   ((x)=ufs_swab32_add(swab,x,1))
 59 #define INC_SWAB64(x)   ((x)=ufs_swab64_add(swab,x,1))
 60 #define DEC_SWAB16(x)   ((x)=ufs_swab16_add(swab,x,-1))
 61 #define DEC_SWAB32(x)   ((x)=ufs_swab32_add(swab,x,-1))
 62 #define DEC_SWAB64(x)   ((x)=ufs_swab64_add(swab,x,-1))
 63 #define ADD_SWAB16(x,y) ((x)=ufs_swab16_add(swab,x,y))
 64 #define ADD_SWAB32(x,y) ((x)=ufs_swab32_add(swab,x,y))
 65 #define ADD_SWAB64(x,y) ((x)=ufs_swab64_add(swab,x,y))
 66 #define SUB_SWAB16(x,y) ((x)=ufs_swab16_add(swab,x,-(y)))
 67 #define SUB_SWAB32(x,y) ((x)=ufs_swab32_add(swab,x,-(y)))
 68 #define SUB_SWAB64(x,y) ((x)=ufs_swab64_add(swab,x,-(y)))
 69 
 70 #if defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN) /* sane bytesex */
 71 extern __inline__ __const__ __u16 ufs_swab16(unsigned swab, __u16 x) {
 72         if (swab)
 73                 return swab16(x);
 74         else
 75                 return x;
 76 }
 77 extern __inline__ __const__ __u32 ufs_swab32(unsigned swab, __u32 x) {
 78         if (swab)
 79                 return swab32(x);
 80         else
 81                 return x;
 82 }
 83 extern __inline__ __const__ __u64 ufs_swab64(unsigned swab, __u64 x) {
 84         if (swab)
 85                 return swab64(x);
 86         else
 87                 return x;
 88 }
 89 extern __inline__ __const__ __u16 ufs_swab16_add(unsigned swab, __u16 x, __u16 y) {
 90         if (swab)
 91                 return swab16(swab16(x)+y);
 92         else
 93                 return x + y;
 94 }
 95 extern __inline__ __const__ __u32 ufs_swab32_add(unsigned swab, __u32 x, __u32 y) {
 96         if (swab)
 97                 return swab32(swab32(x)+y);
 98         else
 99                 return x + y;
100 }
101 extern __inline__ __const__ __u64 ufs_swab64_add(unsigned swab, __u64 x, __u64 y) {
102         if (swab)
103                 return swab64(swab64(x)+y);
104         else
105                 return x + y;
106 }
107 #else /* bytesexual perversion -- BEWARE! Read note at top of file! */
108 extern __inline__ __const__ __u16 ufs_swab16(unsigned swab, __u16 x) {
109         if (swab == UFS_LITTLE_ENDIAN)
110                 return le16_to_cpu(x);
111         else
112                 return be16_to_cpu(x);
113 }
114 extern __inline__ __const__ __u32 ufs_swab32(unsigned swab, __u32 x) {
115         if (swab == UFS_LITTLE_ENDIAN)
116                 return le32_to_cpu(x);
117         else
118                 return be32_to_cpu(x);
119 }
120 extern __inline__ __const__ __u64 ufs_swab64(unsigned swab, __u64 x) {
121         if (swab == UFS_LITTLE_ENDIAN)
122                 return le64_to_cpu(x);
123         else
124                 return be64_to_cpu(x);
125 }
126 extern __inline__ __const__ __u16 ufs_swab16_add(unsigned swab, __u16 x, __u16 y) {
127         return ufs_swab16(swab, ufs_swab16(swab, x) + y);
128 }
129 extern __inline__ __const__ __u32 ufs_swab32_add(unsigned swab, __u32 x, __u32 y) {
130         return ufs_swab32(swab, ufs_swab32(swab, x) + y);
131 }
132 extern __inline__ __const__ __u64 ufs_swab64_add(unsigned swab, __u64 x, __u64 y) {
133         return ufs_swab64(swab, ufs_swab64(swab, x) + y);
134 }
135 #endif /* byte sexuality */
136 
137 #endif /* _UFS_SWAB_H */
138 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~ [ freetext search ] ~ [ file search ] ~

This page was automatically generated by the LXR engine.
Visit the LXR main site for more information.