]>
git.ipfire.org Git - thirdparty/xfsprogs-dev.git/blob - db/bit.c
1b9ca054f3b1e6357c6e1e19211c3c14157aae3d
1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (c) 2000-2001,2005 Silicon Graphics, Inc.
22 return (*ptr
& mask
) >> shift
;
61 p
= (char *)obj
+ byteize(bitoff
);
62 bit
= bitoffs(bitoff
);
63 signext
= (flags
& BVSIGNED
) != 0;
70 return get_unaligned_be64(p
);
73 return (__s32
)get_unaligned_be32(p
);
74 return (__u32
)get_unaligned_be32(p
);
77 return (__s16
)get_unaligned_be16(p
);
78 return (__u16
)get_unaligned_be16(p
);
86 for (i
= 0, rval
= 0LL; i
< nbits
; i
++) {
87 if (getbit_l(p
, bit
+ i
)) {
88 /* If the last bit is on and we care about sign
89 * bits and we don't have a full 64 bit
90 * container, turn all bits on between the
91 * sign bit and the most sig bit.
94 /* handle endian swap here */
95 #if __BYTE_ORDER == LITTLE_ENDIAN
96 if (i
== 0 && signext
&& nbits
< 64)
97 rval
= (~0ULL) << nbits
;
98 rval
|= 1ULL << (nbits
- i
- 1);
100 if ((i
== (nbits
- 1)) && signext
&& nbits
< 64)
101 rval
|= ((~0ULL) << nbits
);
102 rval
|= 1ULL << (nbits
- i
- 1);
110 * The input data can be 8, 16, 32, and 64 sized numeric values
111 * aligned on a byte boundry, or odd sized numbers stored on odd
112 * aligned offset (for example the bmbt fields).
114 * The input data sent to this routine has been converted to big endian
115 * and has been adjusted in the array so that the first input bit is to
116 * be written in the first bit in the output.
118 * If the field length and the output buffer are byte aligned, then use
119 * memcpy from the input to the output, but if either entries are not byte
120 * aligned, then loop over the entire bit range reading the input value
121 * and set/clear the matching bit in the output.
123 * example when ibuf is not multiple of a byte in length:
125 * ibuf: | BBBBBBBB | bbbxxxxx |
127 * obuf+bitoff: | xBBBBBBB | Bbbbxxxx |
132 void *obuf
, /* start of buffer to write into */
133 int bitoff
, /* bit offset into the output buffer */
134 int nbits
, /* number of bits to write */
135 void *ibuf
) /* source bits */
141 if (bitoff
% NBBY
|| nbits
% NBBY
) {
142 for (bit
= 0; bit
< nbits
; bit
++)
143 setbit_l(out
, bit
+ bitoff
, getbit_l(in
, bit
));
145 memcpy(out
+ byteize(bitoff
), in
, byteize(nbits
));