diff options
| author | Mike Frysinger <vapier@gentoo.org> | 2005-09-25 05:18:04 +0000 |
|---|---|---|
| committer | Mike Frysinger <vapier@gentoo.org> | 2005-09-25 05:18:04 +0000 |
| commit | 7ad978045dbc4bb45c0cc7b0629be18aa8d9ba7f (patch) | |
| tree | 26e67eb347ca52388d9cf5819fe1c2f80ade19e7 | |
| parent | de242f6d5f14a3a40749f97e86ab8d982c86b529 (diff) | |
| download | busybox-w32-7ad978045dbc4bb45c0cc7b0629be18aa8d9ba7f.tar.gz busybox-w32-7ad978045dbc4bb45c0cc7b0629be18aa8d9ba7f.tar.bz2 busybox-w32-7ad978045dbc4bb45c0cc7b0629be18aa8d9ba7f.zip | |
fix building with debugging enabled #413
| -rw-r--r-- | e2fsprogs/Makefile.in | 4 | ||||
| -rw-r--r-- | e2fsprogs/e2fsck/dict.c | 12 | ||||
| -rw-r--r-- | e2fsprogs/ext2fs/bitops.h | 513 | ||||
| -rw-r--r-- | e2fsprogs/ext2fs/ext2fs.h | 166 | ||||
| -rw-r--r-- | e2fsprogs/ext2fs/ext2fs_inline.c | 472 |
5 files changed, 485 insertions, 682 deletions
diff --git a/e2fsprogs/Makefile.in b/e2fsprogs/Makefile.in index 03a98149e..e1459e05f 100644 --- a/e2fsprogs/Makefile.in +++ b/e2fsprogs/Makefile.in | |||
| @@ -36,7 +36,7 @@ EXT2FS_SRC := gen_bitmap.c bitops.c ismounted.c mkjournal.c unix_io.c \ | |||
| 36 | bb_inode.c newdir.c alloc_sb.c lookup.c dirblock.c expanddir.c \ | 36 | bb_inode.c newdir.c alloc_sb.c lookup.c dirblock.c expanddir.c \ |
| 37 | dir_iterate.c link.c res_gdt.c icount.c get_pathname.c dblist.c \ | 37 | dir_iterate.c link.c res_gdt.c icount.c get_pathname.c dblist.c \ |
| 38 | dirhash.c version.c flushb.c unlink.c check_desc.c valid_blk.c \ | 38 | dirhash.c version.c flushb.c unlink.c check_desc.c valid_blk.c \ |
| 39 | ext_attr.c bmap.c dblist_dir.c | 39 | ext_attr.c bmap.c dblist_dir.c ext2fs_inline.c |
| 40 | EXT2FS_SRCS := $(patsubst %,ext2fs/%, $(EXT2FS_SRC)) | 40 | EXT2FS_SRCS := $(patsubst %,ext2fs/%, $(EXT2FS_SRC)) |
| 41 | EXT2FS_OBJS := $(patsubst %.c,%.o, $(EXT2FS_SRCS)) | 41 | EXT2FS_OBJS := $(patsubst %.c,%.o, $(EXT2FS_SRCS)) |
| 42 | 42 | ||
| @@ -47,7 +47,7 @@ UUID_OBJS := $(patsubst %.c,%.o, $(UUID_SRCS)) | |||
| 47 | 47 | ||
| 48 | E2FSPROGS-:= | 48 | E2FSPROGS-:= |
| 49 | E2FSPROGS-$(CONFIG_CHATTR) += chattr.o $(E2P_OBJS) | 49 | E2FSPROGS-$(CONFIG_CHATTR) += chattr.o $(E2P_OBJS) |
| 50 | E2FSPROGS-$(CONFIG_E2FSCK) += e2fsck.o $(BLKID_OBJS) $(E2FSCK_OBJS) | 50 | E2FSPROGS-$(CONFIG_E2FSCK) += e2fsck.o util.o $(BLKID_OBJS) $(E2FSCK_OBJS) |
| 51 | E2FSPROGS-$(CONFIG_FSCK) += fsck.o base_device.o | 51 | E2FSPROGS-$(CONFIG_FSCK) += fsck.o base_device.o |
| 52 | E2FSPROGS-$(CONFIG_LSATTR) += lsattr.o $(E2P_OBJS) | 52 | E2FSPROGS-$(CONFIG_LSATTR) += lsattr.o $(E2P_OBJS) |
| 53 | E2FSPROGS-$(CONFIG_MKE2FS) += mke2fs.o util.o $(E2P_OBJS) $(BLKID_OBJS) $(EXT2FS_OBJS) $(UUID_OBJS) | 53 | E2FSPROGS-$(CONFIG_MKE2FS) += mke2fs.o util.o $(E2P_OBJS) $(BLKID_OBJS) $(EXT2FS_OBJS) $(UUID_OBJS) |
diff --git a/e2fsprogs/e2fsck/dict.c b/e2fsprogs/e2fsck/dict.c index 3d6c85f5a..48a1e74f7 100644 --- a/e2fsprogs/e2fsck/dict.c +++ b/e2fsprogs/e2fsck/dict.c | |||
| @@ -562,9 +562,11 @@ void dict_insert(dict_t *dict, dnode_t *node, const void *key) | |||
| 562 | 562 | ||
| 563 | node->key = key; | 563 | node->key = key; |
| 564 | 564 | ||
| 565 | #ifndef NDEBUG | ||
| 565 | assert (!dict_isfull(dict)); | 566 | assert (!dict_isfull(dict)); |
| 566 | assert (!dict_contains(dict, node)); | 567 | assert (!dict_contains(dict, node)); |
| 567 | assert (!dnode_is_in_a_dict(node)); | 568 | assert (!dnode_is_in_a_dict(node)); |
| 569 | #endif | ||
| 568 | 570 | ||
| 569 | /* basic binary tree insert */ | 571 | /* basic binary tree insert */ |
| 570 | 572 | ||
| @@ -642,7 +644,9 @@ void dict_insert(dict_t *dict, dnode_t *node, const void *key) | |||
| 642 | 644 | ||
| 643 | dict_root(dict)->color = dnode_black; | 645 | dict_root(dict)->color = dnode_black; |
| 644 | 646 | ||
| 647 | #ifdef E2FSCK_NOTUSED | ||
| 645 | assert (dict_verify(dict)); | 648 | assert (dict_verify(dict)); |
| 649 | #endif | ||
| 646 | } | 650 | } |
| 647 | 651 | ||
| 648 | #ifdef E2FSCK_NOTUSED | 652 | #ifdef E2FSCK_NOTUSED |
| @@ -816,7 +820,9 @@ dnode_t *dict_delete(dict_t *dict, dnode_t *delete) | |||
| 816 | dict_root(dict)->color = dnode_black; | 820 | dict_root(dict)->color = dnode_black; |
| 817 | } | 821 | } |
| 818 | 822 | ||
| 823 | #ifdef E2FSCK_NOTUSED | ||
| 819 | assert (dict_verify(dict)); | 824 | assert (dict_verify(dict)); |
| 825 | #endif | ||
| 820 | 826 | ||
| 821 | return delete; | 827 | return delete; |
| 822 | } | 828 | } |
| @@ -998,7 +1004,9 @@ dnode_t *dnode_init(dnode_t *dnode, void *data) | |||
| 998 | 1004 | ||
| 999 | void dnode_destroy(dnode_t *dnode) | 1005 | void dnode_destroy(dnode_t *dnode) |
| 1000 | { | 1006 | { |
| 1007 | #ifndef NDEBUG | ||
| 1001 | assert (!dnode_is_in_a_dict(dnode)); | 1008 | assert (!dnode_is_in_a_dict(dnode)); |
| 1009 | #endif | ||
| 1002 | free(dnode); | 1010 | free(dnode); |
| 1003 | } | 1011 | } |
| 1004 | 1012 | ||
| @@ -1055,10 +1063,10 @@ void dict_load_next(dict_load_t *load, dnode_t *newnode, const void *key) | |||
| 1055 | dict_t *dict = load->dictptr; | 1063 | dict_t *dict = load->dictptr; |
| 1056 | dnode_t *nil = &load->nilnode; | 1064 | dnode_t *nil = &load->nilnode; |
| 1057 | 1065 | ||
| 1066 | #ifndef NDEBUG | ||
| 1058 | assert (!dnode_is_in_a_dict(newnode)); | 1067 | assert (!dnode_is_in_a_dict(newnode)); |
| 1059 | assert (dict->nodecount < dict->maxcount); | 1068 | assert (dict->nodecount < dict->maxcount); |
| 1060 | 1069 | ||
| 1061 | #ifndef NDEBUG | ||
| 1062 | if (dict->nodecount > 0) { | 1070 | if (dict->nodecount > 0) { |
| 1063 | if (dict->dupes) | 1071 | if (dict->dupes) |
| 1064 | assert (dict->compare(nil->left->key, key) <= 0); | 1072 | assert (dict->compare(nil->left->key, key) <= 0); |
| @@ -1152,7 +1160,9 @@ void dict_load_end(dict_load_t *load) | |||
| 1152 | complete->color = dnode_black; | 1160 | complete->color = dnode_black; |
| 1153 | dict_root(dict) = complete; | 1161 | dict_root(dict) = complete; |
| 1154 | 1162 | ||
| 1163 | #ifdef E2FSCK_NOTUSED | ||
| 1155 | assert (dict_verify(dict)); | 1164 | assert (dict_verify(dict)); |
| 1165 | #endif | ||
| 1156 | } | 1166 | } |
| 1157 | 1167 | ||
| 1158 | void dict_merge(dict_t *dest, dict_t *source) | 1168 | void dict_merge(dict_t *dest, dict_t *source) |
diff --git a/e2fsprogs/ext2fs/bitops.h b/e2fsprogs/ext2fs/bitops.h index 96db548d6..b6446efa2 100644 --- a/e2fsprogs/ext2fs/bitops.h +++ b/e2fsprogs/ext2fs/bitops.h | |||
| @@ -103,516 +103,3 @@ extern int ext2fs_mark_generic_bitmap(ext2fs_generic_bitmap bitmap, | |||
| 103 | __u32 bitno); | 103 | __u32 bitno); |
| 104 | extern int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap, | 104 | extern int ext2fs_unmark_generic_bitmap(ext2fs_generic_bitmap bitmap, |
| 105 | blk_t bitno); | 105 | blk_t bitno); |
| 106 | /* | ||
| 107 | * The inline routines themselves... | ||
| 108 | * | ||
| 109 | * If NO_INLINE_FUNCS is defined, then we won't try to do inline | ||
| 110 | * functions at all; they will be included as normal functions in | ||
| 111 | * inline.c | ||
| 112 | */ | ||
| 113 | #ifdef NO_INLINE_FUNCS | ||
| 114 | #if (defined(__GNUC__) && (defined(__i386__) || defined(__i486__) || \ | ||
| 115 | defined(__i586__) || defined(__mc68000__) || \ | ||
| 116 | defined(__sparc__))) | ||
| 117 | /* This prevents bitops.c from trying to include the C */ | ||
| 118 | /* function version of these functions */ | ||
| 119 | #define _EXT2_HAVE_ASM_BITOPS_ | ||
| 120 | #endif | ||
| 121 | #endif /* NO_INLINE_FUNCS */ | ||
| 122 | |||
| 123 | #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) | ||
| 124 | #ifdef INCLUDE_INLINE_FUNCS | ||
| 125 | #define _INLINE_ extern | ||
| 126 | #else | ||
| 127 | #ifdef __GNUC__ | ||
| 128 | #define _INLINE_ extern __inline__ | ||
| 129 | #else /* For Watcom C */ | ||
| 130 | #define _INLINE_ extern inline | ||
| 131 | #endif | ||
| 132 | #endif | ||
| 133 | |||
| 134 | #if ((defined __GNUC__) && !defined(_EXT2_USE_C_VERSIONS_) && \ | ||
| 135 | (defined(__i386__) || defined(__i486__) || defined(__i586__))) | ||
| 136 | |||
| 137 | #define _EXT2_HAVE_ASM_BITOPS_ | ||
| 138 | #define _EXT2_HAVE_ASM_SWAB_ | ||
| 139 | #define _EXT2_HAVE_ASM_FINDBIT_ | ||
| 140 | |||
| 141 | /* | ||
| 142 | * These are done by inline assembly for speed reasons..... | ||
| 143 | * | ||
| 144 | * All bitoperations return 0 if the bit was cleared before the | ||
| 145 | * operation and != 0 if it was not. Bit 0 is the LSB of addr; bit 32 | ||
| 146 | * is the LSB of (addr+1). | ||
| 147 | */ | ||
| 148 | |||
| 149 | /* | ||
| 150 | * Some hacks to defeat gcc over-optimizations.. | ||
| 151 | */ | ||
| 152 | struct __dummy_h { unsigned long a[100]; }; | ||
| 153 | #define EXT2FS_ADDR (*(struct __dummy_h *) addr) | ||
| 154 | #define EXT2FS_CONST_ADDR (*(const struct __dummy_h *) addr) | ||
| 155 | |||
| 156 | _INLINE_ int ext2fs_set_bit(int nr, void * addr) | ||
| 157 | { | ||
| 158 | int oldbit; | ||
| 159 | |||
| 160 | __asm__ __volatile__("btsl %2,%1\n\tsbbl %0,%0" | ||
| 161 | :"=r" (oldbit),"=m" (EXT2FS_ADDR) | ||
| 162 | :"r" (nr)); | ||
| 163 | return oldbit; | ||
| 164 | } | ||
| 165 | |||
| 166 | _INLINE_ int ext2fs_clear_bit(int nr, void * addr) | ||
| 167 | { | ||
| 168 | int oldbit; | ||
| 169 | |||
| 170 | __asm__ __volatile__("btrl %2,%1\n\tsbbl %0,%0" | ||
| 171 | :"=r" (oldbit),"=m" (EXT2FS_ADDR) | ||
| 172 | :"r" (nr)); | ||
| 173 | return oldbit; | ||
| 174 | } | ||
| 175 | |||
| 176 | _INLINE_ int ext2fs_test_bit(int nr, const void * addr) | ||
| 177 | { | ||
| 178 | int oldbit; | ||
| 179 | |||
| 180 | __asm__ __volatile__("btl %2,%1\n\tsbbl %0,%0" | ||
| 181 | :"=r" (oldbit) | ||
| 182 | :"m" (EXT2FS_CONST_ADDR),"r" (nr)); | ||
| 183 | return oldbit; | ||
| 184 | } | ||
| 185 | |||
| 186 | #if 0 | ||
| 187 | _INLINE_ int ext2fs_find_first_bit_set(void * addr, unsigned size) | ||
| 188 | { | ||
| 189 | int d0, d1, d2; | ||
| 190 | int res; | ||
| 191 | |||
| 192 | if (!size) | ||
| 193 | return 0; | ||
| 194 | /* This looks at memory. Mark it volatile to tell gcc not to move it around */ | ||
| 195 | __asm__ __volatile__( | ||
| 196 | "cld\n\t" | ||
| 197 | "xorl %%eax,%%eax\n\t" | ||
| 198 | "xorl %%edx,%%edx\n\t" | ||
| 199 | "repe; scasl\n\t" | ||
| 200 | "je 1f\n\t" | ||
| 201 | "movl -4(%%edi),%%eax\n\t" | ||
| 202 | "subl $4,%%edi\n\t" | ||
| 203 | "bsfl %%eax,%%edx\n" | ||
| 204 | "1:\tsubl %%esi,%%edi\n\t" | ||
| 205 | "shll $3,%%edi\n\t" | ||
| 206 | "addl %%edi,%%edx" | ||
| 207 | :"=d" (res), "=&c" (d0), "=&D" (d1), "=&a" (d2) | ||
| 208 | :"1" ((size + 31) >> 5), "2" (addr), "S" (addr)); | ||
| 209 | return res; | ||
| 210 | } | ||
| 211 | |||
| 212 | _INLINE_ int ext2fs_find_next_bit_set (void * addr, int size, int offset) | ||
| 213 | { | ||
| 214 | unsigned long * p = ((unsigned long *) addr) + (offset >> 5); | ||
| 215 | int set = 0, bit = offset & 31, res; | ||
| 216 | |||
| 217 | if (bit) { | ||
| 218 | /* | ||
| 219 | * Look for zero in first byte | ||
| 220 | */ | ||
| 221 | __asm__("bsfl %1,%0\n\t" | ||
| 222 | "jne 1f\n\t" | ||
| 223 | "movl $32, %0\n" | ||
| 224 | "1:" | ||
| 225 | : "=r" (set) | ||
| 226 | : "r" (*p >> bit)); | ||
| 227 | if (set < (32 - bit)) | ||
| 228 | return set + offset; | ||
| 229 | set = 32 - bit; | ||
| 230 | p++; | ||
| 231 | } | ||
| 232 | /* | ||
| 233 | * No bit found yet, search remaining full bytes for a bit | ||
| 234 | */ | ||
| 235 | res = ext2fs_find_first_bit_set(p, size - 32 * (p - (unsigned long *) addr)); | ||
| 236 | return (offset + set + res); | ||
| 237 | } | ||
| 238 | #endif | ||
| 239 | |||
| 240 | #ifdef EXT2FS_ENABLE_SWAPFS | ||
| 241 | _INLINE_ __u32 ext2fs_swab32(__u32 val) | ||
| 242 | { | ||
| 243 | #ifdef EXT2FS_REQUIRE_486 | ||
| 244 | __asm__("bswap %0" : "=r" (val) : "0" (val)); | ||
| 245 | #else | ||
| 246 | __asm__("xchgb %b0,%h0\n\t" /* swap lower bytes */ | ||
| 247 | "rorl $16,%0\n\t" /* swap words */ | ||
| 248 | "xchgb %b0,%h0" /* swap higher bytes */ | ||
| 249 | :"=q" (val) | ||
| 250 | : "0" (val)); | ||
| 251 | #endif | ||
| 252 | return val; | ||
| 253 | } | ||
| 254 | |||
| 255 | _INLINE_ __u16 ext2fs_swab16(__u16 val) | ||
| 256 | { | ||
| 257 | __asm__("xchgb %b0,%h0" /* swap bytes */ \ | ||
| 258 | : "=q" (val) \ | ||
| 259 | : "0" (val)); \ | ||
| 260 | return val; | ||
| 261 | } | ||
| 262 | #endif | ||
| 263 | |||
| 264 | #undef EXT2FS_ADDR | ||
| 265 | |||
| 266 | #endif /* i386 */ | ||
| 267 | |||
| 268 | #ifdef __mc68000__ | ||
| 269 | |||
| 270 | #define _EXT2_HAVE_ASM_BITOPS_ | ||
| 271 | |||
| 272 | _INLINE_ int ext2fs_set_bit(int nr,void * addr) | ||
| 273 | { | ||
| 274 | char retval; | ||
| 275 | |||
| 276 | __asm__ __volatile__ ("bfset %2@{%1:#1}; sne %0" | ||
| 277 | : "=d" (retval) : "d" (nr^7), "a" (addr)); | ||
| 278 | |||
| 279 | return retval; | ||
| 280 | } | ||
| 281 | |||
| 282 | _INLINE_ int ext2fs_clear_bit(int nr, void * addr) | ||
| 283 | { | ||
| 284 | char retval; | ||
| 285 | |||
| 286 | __asm__ __volatile__ ("bfclr %2@{%1:#1}; sne %0" | ||
| 287 | : "=d" (retval) : "d" (nr^7), "a" (addr)); | ||
| 288 | |||
| 289 | return retval; | ||
| 290 | } | ||
| 291 | |||
| 292 | _INLINE_ int ext2fs_test_bit(int nr, const void * addr) | ||
| 293 | { | ||
| 294 | char retval; | ||
| 295 | |||
| 296 | __asm__ __volatile__ ("bftst %2@{%1:#1}; sne %0" | ||
| 297 | : "=d" (retval) : "d" (nr^7), "a" (addr)); | ||
| 298 | |||
| 299 | return retval; | ||
| 300 | } | ||
| 301 | |||
| 302 | #endif /* __mc68000__ */ | ||
| 303 | |||
| 304 | |||
| 305 | #if !defined(_EXT2_HAVE_ASM_SWAB_) && defined(EXT2FS_ENABLE_SWAPFS) | ||
| 306 | |||
| 307 | _INLINE_ __u16 ext2fs_swab16(__u16 val) | ||
| 308 | { | ||
| 309 | return (val >> 8) | (val << 8); | ||
| 310 | } | ||
| 311 | |||
| 312 | _INLINE_ __u32 ext2fs_swab32(__u32 val) | ||
| 313 | { | ||
| 314 | return ((val>>24) | ((val>>8)&0xFF00) | | ||
| 315 | ((val<<8)&0xFF0000) | (val<<24)); | ||
| 316 | } | ||
| 317 | |||
| 318 | #endif /* !_EXT2_HAVE_ASM_SWAB */ | ||
| 319 | |||
| 320 | #if !defined(_EXT2_HAVE_ASM_FINDBIT_) | ||
| 321 | _INLINE_ int ext2fs_find_first_bit_set(void * addr, unsigned size) | ||
| 322 | { | ||
| 323 | unsigned char *cp = (unsigned char *) addr; | ||
| 324 | int res = 0, d0; | ||
| 325 | |||
| 326 | if (!size) | ||
| 327 | return 0; | ||
| 328 | |||
| 329 | while ((size > res) && (*cp == 0)) { | ||
| 330 | cp++; | ||
| 331 | res += 8; | ||
| 332 | } | ||
| 333 | d0 = ffs(*cp); | ||
| 334 | if (d0 == 0) | ||
| 335 | return size; | ||
| 336 | |||
| 337 | return res + d0 - 1; | ||
| 338 | } | ||
| 339 | |||
| 340 | _INLINE_ int ext2fs_find_next_bit_set (void * addr, int size, int offset) | ||
| 341 | { | ||
| 342 | unsigned char * p; | ||
| 343 | int set = 0, bit = offset & 7, res = 0, d0; | ||
| 344 | |||
| 345 | res = offset >> 3; | ||
| 346 | p = ((unsigned char *) addr) + res; | ||
| 347 | |||
| 348 | if (bit) { | ||
| 349 | set = ffs(*p & ~((1 << bit) - 1)); | ||
| 350 | if (set) | ||
| 351 | return (offset & ~7) + set - 1; | ||
| 352 | p++; | ||
| 353 | res += 8; | ||
| 354 | } | ||
| 355 | while ((size > res) && (*p == 0)) { | ||
| 356 | p++; | ||
| 357 | res += 8; | ||
| 358 | } | ||
| 359 | d0 = ffs(*p); | ||
| 360 | if (d0 == 0) | ||
| 361 | return size; | ||
| 362 | |||
| 363 | return (res + d0 - 1); | ||
| 364 | } | ||
| 365 | #endif | ||
| 366 | |||
| 367 | _INLINE_ int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap, | ||
| 368 | blk_t bitno); | ||
| 369 | |||
| 370 | _INLINE_ int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap, | ||
| 371 | blk_t bitno) | ||
| 372 | { | ||
| 373 | if ((bitno < bitmap->start) || (bitno > bitmap->end)) { | ||
| 374 | ext2fs_warn_bitmap2(bitmap, EXT2FS_TEST_ERROR, bitno); | ||
| 375 | return 0; | ||
| 376 | } | ||
| 377 | return ext2fs_test_bit(bitno - bitmap->start, bitmap->bitmap); | ||
| 378 | } | ||
| 379 | |||
| 380 | _INLINE_ int ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap, | ||
| 381 | blk_t block) | ||
| 382 | { | ||
| 383 | return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) | ||
| 384 | bitmap, | ||
| 385 | block); | ||
| 386 | } | ||
| 387 | |||
| 388 | _INLINE_ int ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap, | ||
| 389 | blk_t block) | ||
| 390 | { | ||
| 391 | return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, | ||
| 392 | block); | ||
| 393 | } | ||
| 394 | |||
| 395 | _INLINE_ int ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap, | ||
| 396 | blk_t block) | ||
| 397 | { | ||
| 398 | return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap, | ||
| 399 | block); | ||
| 400 | } | ||
| 401 | |||
| 402 | _INLINE_ int ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap, | ||
| 403 | ext2_ino_t inode) | ||
| 404 | { | ||
| 405 | return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap, | ||
| 406 | inode); | ||
| 407 | } | ||
| 408 | |||
| 409 | _INLINE_ int ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap, | ||
| 410 | ext2_ino_t inode) | ||
| 411 | { | ||
| 412 | return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, | ||
| 413 | inode); | ||
| 414 | } | ||
| 415 | |||
| 416 | _INLINE_ int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap, | ||
| 417 | ext2_ino_t inode) | ||
| 418 | { | ||
| 419 | return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap, | ||
| 420 | inode); | ||
| 421 | } | ||
| 422 | |||
| 423 | _INLINE_ void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap, | ||
| 424 | blk_t block) | ||
| 425 | { | ||
| 426 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 427 | if ((block < bitmap->start) || (block > bitmap->end)) { | ||
| 428 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block, | ||
| 429 | bitmap->description); | ||
| 430 | return; | ||
| 431 | } | ||
| 432 | #endif | ||
| 433 | ext2fs_set_bit(block - bitmap->start, bitmap->bitmap); | ||
| 434 | } | ||
| 435 | |||
| 436 | _INLINE_ void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap, | ||
| 437 | blk_t block) | ||
| 438 | { | ||
| 439 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 440 | if ((block < bitmap->start) || (block > bitmap->end)) { | ||
| 441 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, | ||
| 442 | block, bitmap->description); | ||
| 443 | return; | ||
| 444 | } | ||
| 445 | #endif | ||
| 446 | ext2fs_clear_bit(block - bitmap->start, bitmap->bitmap); | ||
| 447 | } | ||
| 448 | |||
| 449 | _INLINE_ int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap, | ||
| 450 | blk_t block) | ||
| 451 | { | ||
| 452 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 453 | if ((block < bitmap->start) || (block > bitmap->end)) { | ||
| 454 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST, | ||
| 455 | block, bitmap->description); | ||
| 456 | return 0; | ||
| 457 | } | ||
| 458 | #endif | ||
| 459 | return ext2fs_test_bit(block - bitmap->start, bitmap->bitmap); | ||
| 460 | } | ||
| 461 | |||
| 462 | _INLINE_ void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap, | ||
| 463 | ext2_ino_t inode) | ||
| 464 | { | ||
| 465 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 466 | if ((inode < bitmap->start) || (inode > bitmap->end)) { | ||
| 467 | ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_MARK, | ||
| 468 | inode, bitmap->description); | ||
| 469 | return; | ||
| 470 | } | ||
| 471 | #endif | ||
| 472 | ext2fs_set_bit(inode - bitmap->start, bitmap->bitmap); | ||
| 473 | } | ||
| 474 | |||
| 475 | _INLINE_ void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap, | ||
| 476 | ext2_ino_t inode) | ||
| 477 | { | ||
| 478 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 479 | if ((inode < bitmap->start) || (inode > bitmap->end)) { | ||
| 480 | ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_UNMARK, | ||
| 481 | inode, bitmap->description); | ||
| 482 | return; | ||
| 483 | } | ||
| 484 | #endif | ||
| 485 | ext2fs_clear_bit(inode - bitmap->start, bitmap->bitmap); | ||
| 486 | } | ||
| 487 | |||
| 488 | _INLINE_ int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap, | ||
| 489 | ext2_ino_t inode) | ||
| 490 | { | ||
| 491 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 492 | if ((inode < bitmap->start) || (inode > bitmap->end)) { | ||
| 493 | ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_TEST, | ||
| 494 | inode, bitmap->description); | ||
| 495 | return 0; | ||
| 496 | } | ||
| 497 | #endif | ||
| 498 | return ext2fs_test_bit(inode - bitmap->start, bitmap->bitmap); | ||
| 499 | } | ||
| 500 | |||
| 501 | _INLINE_ blk_t ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap) | ||
| 502 | { | ||
| 503 | return bitmap->start; | ||
| 504 | } | ||
| 505 | |||
| 506 | _INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap) | ||
| 507 | { | ||
| 508 | return bitmap->start; | ||
| 509 | } | ||
| 510 | |||
| 511 | _INLINE_ blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap) | ||
| 512 | { | ||
| 513 | return bitmap->end; | ||
| 514 | } | ||
| 515 | |||
| 516 | _INLINE_ ext2_ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap) | ||
| 517 | { | ||
| 518 | return bitmap->end; | ||
| 519 | } | ||
| 520 | |||
| 521 | _INLINE_ int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap, | ||
| 522 | blk_t block, int num) | ||
| 523 | { | ||
| 524 | int i; | ||
| 525 | |||
| 526 | if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { | ||
| 527 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST, | ||
| 528 | block, bitmap->description); | ||
| 529 | return 0; | ||
| 530 | } | ||
| 531 | for (i=0; i < num; i++) { | ||
| 532 | if (ext2fs_fast_test_block_bitmap(bitmap, block+i)) | ||
| 533 | return 0; | ||
| 534 | } | ||
| 535 | return 1; | ||
| 536 | } | ||
| 537 | |||
| 538 | _INLINE_ int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap, | ||
| 539 | blk_t block, int num) | ||
| 540 | { | ||
| 541 | int i; | ||
| 542 | |||
| 543 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 544 | if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { | ||
| 545 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST, | ||
| 546 | block, bitmap->description); | ||
| 547 | return 0; | ||
| 548 | } | ||
| 549 | #endif | ||
| 550 | for (i=0; i < num; i++) { | ||
| 551 | if (ext2fs_fast_test_block_bitmap(bitmap, block+i)) | ||
| 552 | return 0; | ||
| 553 | } | ||
| 554 | return 1; | ||
| 555 | } | ||
| 556 | |||
| 557 | _INLINE_ void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap, | ||
| 558 | blk_t block, int num) | ||
| 559 | { | ||
| 560 | int i; | ||
| 561 | |||
| 562 | if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { | ||
| 563 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block, | ||
| 564 | bitmap->description); | ||
| 565 | return; | ||
| 566 | } | ||
| 567 | for (i=0; i < num; i++) | ||
| 568 | ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap); | ||
| 569 | } | ||
| 570 | |||
| 571 | _INLINE_ void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap, | ||
| 572 | blk_t block, int num) | ||
| 573 | { | ||
| 574 | int i; | ||
| 575 | |||
| 576 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 577 | if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { | ||
| 578 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block, | ||
| 579 | bitmap->description); | ||
| 580 | return; | ||
| 581 | } | ||
| 582 | #endif | ||
| 583 | for (i=0; i < num; i++) | ||
| 584 | ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap); | ||
| 585 | } | ||
| 586 | |||
| 587 | _INLINE_ void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap, | ||
| 588 | blk_t block, int num) | ||
| 589 | { | ||
| 590 | int i; | ||
| 591 | |||
| 592 | if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { | ||
| 593 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block, | ||
| 594 | bitmap->description); | ||
| 595 | return; | ||
| 596 | } | ||
| 597 | for (i=0; i < num; i++) | ||
| 598 | ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap); | ||
| 599 | } | ||
| 600 | |||
| 601 | _INLINE_ void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap, | ||
| 602 | blk_t block, int num) | ||
| 603 | { | ||
| 604 | int i; | ||
| 605 | |||
| 606 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 607 | if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { | ||
| 608 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block, | ||
| 609 | bitmap->description); | ||
| 610 | return; | ||
| 611 | } | ||
| 612 | #endif | ||
| 613 | for (i=0; i < num; i++) | ||
| 614 | ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap); | ||
| 615 | } | ||
| 616 | #undef _INLINE_ | ||
| 617 | #endif | ||
| 618 | |||
diff --git a/e2fsprogs/ext2fs/ext2fs.h b/e2fsprogs/ext2fs/ext2fs.h index 4bf5e5bba..bad2f9e58 100644 --- a/e2fsprogs/ext2fs/ext2fs.h +++ b/e2fsprogs/ext2fs/ext2fs.h | |||
| @@ -962,172 +962,6 @@ extern int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino); | |||
| 962 | extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs, | 962 | extern blk_t ext2fs_inode_data_blocks(ext2_filsys fs, |
| 963 | struct ext2_inode *inode); | 963 | struct ext2_inode *inode); |
| 964 | 964 | ||
| 965 | /* | ||
| 966 | * The actual inlined functions definitions themselves... | ||
| 967 | * | ||
| 968 | * If NO_INLINE_FUNCS is defined, then we won't try to do inline | ||
| 969 | * functions at all! | ||
| 970 | */ | ||
| 971 | #if (defined(INCLUDE_INLINE_FUNCS) || !defined(NO_INLINE_FUNCS)) | ||
| 972 | #ifdef INCLUDE_INLINE_FUNCS | ||
| 973 | #define _INLINE_ extern | ||
| 974 | #else | ||
| 975 | #ifdef __GNUC__ | ||
| 976 | #define _INLINE_ extern __inline__ | ||
| 977 | #else /* For Watcom C */ | ||
| 978 | #define _INLINE_ extern inline | ||
| 979 | #endif | ||
| 980 | #endif | ||
| 981 | |||
| 982 | #ifndef EXT2_CUSTOM_MEMORY_ROUTINES | ||
| 983 | /* | ||
| 984 | * Allocate memory | ||
| 985 | */ | ||
| 986 | _INLINE_ errcode_t ext2fs_get_mem(unsigned long size, void *ptr) | ||
| 987 | { | ||
| 988 | void **pp = (void **)ptr; | ||
| 989 | |||
| 990 | *pp = malloc(size); | ||
| 991 | if (!*pp) | ||
| 992 | return EXT2_ET_NO_MEMORY; | ||
| 993 | return 0; | ||
| 994 | } | ||
| 995 | |||
| 996 | /* | ||
| 997 | * Free memory | ||
| 998 | */ | ||
| 999 | _INLINE_ errcode_t ext2fs_free_mem(void *ptr) | ||
| 1000 | { | ||
| 1001 | void **pp = (void **)ptr; | ||
| 1002 | |||
| 1003 | free(*pp); | ||
| 1004 | *pp = 0; | ||
| 1005 | return 0; | ||
| 1006 | } | ||
| 1007 | |||
| 1008 | /* | ||
| 1009 | * Resize memory | ||
| 1010 | */ | ||
| 1011 | _INLINE_ errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size, | ||
| 1012 | unsigned long size, void *ptr) | ||
| 1013 | { | ||
| 1014 | void *p; | ||
| 1015 | void **pp = (void **)ptr; | ||
| 1016 | |||
| 1017 | p = realloc(*pp, size); | ||
| 1018 | if (!p) | ||
| 1019 | return EXT2_ET_NO_MEMORY; | ||
| 1020 | *pp = p; | ||
| 1021 | return 0; | ||
| 1022 | } | ||
| 1023 | #endif /* Custom memory routines */ | ||
| 1024 | |||
| 1025 | /* | ||
| 1026 | * Mark a filesystem superblock as dirty | ||
| 1027 | */ | ||
| 1028 | _INLINE_ void ext2fs_mark_super_dirty(ext2_filsys fs) | ||
| 1029 | { | ||
| 1030 | fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED; | ||
| 1031 | } | ||
| 1032 | |||
| 1033 | /* | ||
| 1034 | * Mark a filesystem as changed | ||
| 1035 | */ | ||
| 1036 | _INLINE_ void ext2fs_mark_changed(ext2_filsys fs) | ||
| 1037 | { | ||
| 1038 | fs->flags |= EXT2_FLAG_CHANGED; | ||
| 1039 | } | ||
| 1040 | |||
| 1041 | /* | ||
| 1042 | * Check to see if a filesystem has changed | ||
| 1043 | */ | ||
| 1044 | _INLINE_ int ext2fs_test_changed(ext2_filsys fs) | ||
| 1045 | { | ||
| 1046 | return (fs->flags & EXT2_FLAG_CHANGED); | ||
| 1047 | } | ||
| 1048 | |||
| 1049 | /* | ||
| 1050 | * Mark a filesystem as valid | ||
| 1051 | */ | ||
| 1052 | _INLINE_ void ext2fs_mark_valid(ext2_filsys fs) | ||
| 1053 | { | ||
| 1054 | fs->flags |= EXT2_FLAG_VALID; | ||
| 1055 | } | ||
| 1056 | |||
| 1057 | /* | ||
| 1058 | * Mark a filesystem as NOT valid | ||
| 1059 | */ | ||
| 1060 | _INLINE_ void ext2fs_unmark_valid(ext2_filsys fs) | ||
| 1061 | { | ||
| 1062 | fs->flags &= ~EXT2_FLAG_VALID; | ||
| 1063 | } | ||
| 1064 | |||
| 1065 | /* | ||
| 1066 | * Check to see if a filesystem is valid | ||
| 1067 | */ | ||
| 1068 | _INLINE_ int ext2fs_test_valid(ext2_filsys fs) | ||
| 1069 | { | ||
| 1070 | return (fs->flags & EXT2_FLAG_VALID); | ||
| 1071 | } | ||
| 1072 | |||
| 1073 | /* | ||
| 1074 | * Mark the inode bitmap as dirty | ||
| 1075 | */ | ||
| 1076 | _INLINE_ void ext2fs_mark_ib_dirty(ext2_filsys fs) | ||
| 1077 | { | ||
| 1078 | fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED; | ||
| 1079 | } | ||
| 1080 | |||
| 1081 | /* | ||
| 1082 | * Mark the block bitmap as dirty | ||
| 1083 | */ | ||
| 1084 | _INLINE_ void ext2fs_mark_bb_dirty(ext2_filsys fs) | ||
| 1085 | { | ||
| 1086 | fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED; | ||
| 1087 | } | ||
| 1088 | |||
| 1089 | /* | ||
| 1090 | * Check to see if a filesystem's inode bitmap is dirty | ||
| 1091 | */ | ||
| 1092 | _INLINE_ int ext2fs_test_ib_dirty(ext2_filsys fs) | ||
| 1093 | { | ||
| 1094 | return (fs->flags & EXT2_FLAG_IB_DIRTY); | ||
| 1095 | } | ||
| 1096 | |||
| 1097 | /* | ||
| 1098 | * Check to see if a filesystem's block bitmap is dirty | ||
| 1099 | */ | ||
| 1100 | _INLINE_ int ext2fs_test_bb_dirty(ext2_filsys fs) | ||
| 1101 | { | ||
| 1102 | return (fs->flags & EXT2_FLAG_BB_DIRTY); | ||
| 1103 | } | ||
| 1104 | |||
| 1105 | /* | ||
| 1106 | * Return the group # of a block | ||
| 1107 | */ | ||
| 1108 | _INLINE_ int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk) | ||
| 1109 | { | ||
| 1110 | return (blk - fs->super->s_first_data_block) / | ||
| 1111 | fs->super->s_blocks_per_group; | ||
| 1112 | } | ||
| 1113 | |||
| 1114 | /* | ||
| 1115 | * Return the group # of an inode number | ||
| 1116 | */ | ||
| 1117 | _INLINE_ int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino) | ||
| 1118 | { | ||
| 1119 | return (ino - 1) / fs->super->s_inodes_per_group; | ||
| 1120 | } | ||
| 1121 | |||
| 1122 | _INLINE_ blk_t ext2fs_inode_data_blocks(ext2_filsys fs, | ||
| 1123 | struct ext2_inode *inode) | ||
| 1124 | { | ||
| 1125 | return inode->i_blocks - | ||
| 1126 | (inode->i_file_acl ? fs->blocksize >> 9 : 0); | ||
| 1127 | } | ||
| 1128 | #undef _INLINE_ | ||
| 1129 | #endif | ||
| 1130 | |||
| 1131 | #ifdef __cplusplus | 965 | #ifdef __cplusplus |
| 1132 | } | 966 | } |
| 1133 | #endif | 967 | #endif |
diff --git a/e2fsprogs/ext2fs/ext2fs_inline.c b/e2fsprogs/ext2fs/ext2fs_inline.c new file mode 100644 index 000000000..d1d1b835a --- /dev/null +++ b/e2fsprogs/ext2fs/ext2fs_inline.c | |||
| @@ -0,0 +1,472 @@ | |||
| 1 | /* | ||
| 2 | * ext2fs.h --- ext2fs | ||
| 3 | * | ||
| 4 | * Copyright (C) 1993, 1994, 1995, 1996 Theodore Ts'o. | ||
| 5 | * | ||
| 6 | * %Begin-Header% | ||
| 7 | * This file may be redistributed under the terms of the GNU Public | ||
| 8 | * License. | ||
| 9 | * %End-Header% | ||
| 10 | */ | ||
| 11 | |||
| 12 | #include "ext2fs/ext2fs.h" | ||
| 13 | #include "ext2fs/bitops.h" | ||
| 14 | |||
| 15 | /* | ||
| 16 | * Allocate memory | ||
| 17 | */ | ||
| 18 | errcode_t ext2fs_get_mem(unsigned long size, void *ptr) | ||
| 19 | { | ||
| 20 | void **pp = (void **)ptr; | ||
| 21 | |||
| 22 | *pp = malloc(size); | ||
| 23 | if (!*pp) | ||
| 24 | return EXT2_ET_NO_MEMORY; | ||
| 25 | return 0; | ||
| 26 | } | ||
| 27 | |||
| 28 | /* | ||
| 29 | * Free memory | ||
| 30 | */ | ||
| 31 | errcode_t ext2fs_free_mem(void *ptr) | ||
| 32 | { | ||
| 33 | void **pp = (void **)ptr; | ||
| 34 | |||
| 35 | free(*pp); | ||
| 36 | *pp = 0; | ||
| 37 | return 0; | ||
| 38 | } | ||
| 39 | |||
| 40 | /* | ||
| 41 | * Resize memory | ||
| 42 | */ | ||
| 43 | errcode_t ext2fs_resize_mem(unsigned long EXT2FS_ATTR((unused)) old_size, | ||
| 44 | unsigned long size, void *ptr) | ||
| 45 | { | ||
| 46 | void *p; | ||
| 47 | void **pp = (void **)ptr; | ||
| 48 | |||
| 49 | p = realloc(*pp, size); | ||
| 50 | if (!p) | ||
| 51 | return EXT2_ET_NO_MEMORY; | ||
| 52 | *pp = p; | ||
| 53 | return 0; | ||
| 54 | } | ||
| 55 | |||
| 56 | /* | ||
| 57 | * Mark a filesystem superblock as dirty | ||
| 58 | */ | ||
| 59 | void ext2fs_mark_super_dirty(ext2_filsys fs) | ||
| 60 | { | ||
| 61 | fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_CHANGED; | ||
| 62 | } | ||
| 63 | |||
| 64 | /* | ||
| 65 | * Mark a filesystem as changed | ||
| 66 | */ | ||
| 67 | void ext2fs_mark_changed(ext2_filsys fs) | ||
| 68 | { | ||
| 69 | fs->flags |= EXT2_FLAG_CHANGED; | ||
| 70 | } | ||
| 71 | |||
| 72 | /* | ||
| 73 | * Check to see if a filesystem has changed | ||
| 74 | */ | ||
| 75 | int ext2fs_test_changed(ext2_filsys fs) | ||
| 76 | { | ||
| 77 | return (fs->flags & EXT2_FLAG_CHANGED); | ||
| 78 | } | ||
| 79 | |||
| 80 | /* | ||
| 81 | * Mark a filesystem as valid | ||
| 82 | */ | ||
| 83 | void ext2fs_mark_valid(ext2_filsys fs) | ||
| 84 | { | ||
| 85 | fs->flags |= EXT2_FLAG_VALID; | ||
| 86 | } | ||
| 87 | |||
| 88 | /* | ||
| 89 | * Mark a filesystem as NOT valid | ||
| 90 | */ | ||
| 91 | void ext2fs_unmark_valid(ext2_filsys fs) | ||
| 92 | { | ||
| 93 | fs->flags &= ~EXT2_FLAG_VALID; | ||
| 94 | } | ||
| 95 | |||
| 96 | /* | ||
| 97 | * Check to see if a filesystem is valid | ||
| 98 | */ | ||
| 99 | int ext2fs_test_valid(ext2_filsys fs) | ||
| 100 | { | ||
| 101 | return (fs->flags & EXT2_FLAG_VALID); | ||
| 102 | } | ||
| 103 | |||
| 104 | /* | ||
| 105 | * Mark the inode bitmap as dirty | ||
| 106 | */ | ||
| 107 | void ext2fs_mark_ib_dirty(ext2_filsys fs) | ||
| 108 | { | ||
| 109 | fs->flags |= EXT2_FLAG_IB_DIRTY | EXT2_FLAG_CHANGED; | ||
| 110 | } | ||
| 111 | |||
| 112 | /* | ||
| 113 | * Mark the block bitmap as dirty | ||
| 114 | */ | ||
| 115 | void ext2fs_mark_bb_dirty(ext2_filsys fs) | ||
| 116 | { | ||
| 117 | fs->flags |= EXT2_FLAG_BB_DIRTY | EXT2_FLAG_CHANGED; | ||
| 118 | } | ||
| 119 | |||
| 120 | /* | ||
| 121 | * Check to see if a filesystem's inode bitmap is dirty | ||
| 122 | */ | ||
| 123 | int ext2fs_test_ib_dirty(ext2_filsys fs) | ||
| 124 | { | ||
| 125 | return (fs->flags & EXT2_FLAG_IB_DIRTY); | ||
| 126 | } | ||
| 127 | |||
| 128 | /* | ||
| 129 | * Check to see if a filesystem's block bitmap is dirty | ||
| 130 | */ | ||
| 131 | int ext2fs_test_bb_dirty(ext2_filsys fs) | ||
| 132 | { | ||
| 133 | return (fs->flags & EXT2_FLAG_BB_DIRTY); | ||
| 134 | } | ||
| 135 | |||
| 136 | /* | ||
| 137 | * Return the group # of a block | ||
| 138 | */ | ||
| 139 | int ext2fs_group_of_blk(ext2_filsys fs, blk_t blk) | ||
| 140 | { | ||
| 141 | return (blk - fs->super->s_first_data_block) / | ||
| 142 | fs->super->s_blocks_per_group; | ||
| 143 | } | ||
| 144 | |||
| 145 | /* | ||
| 146 | * Return the group # of an inode number | ||
| 147 | */ | ||
| 148 | int ext2fs_group_of_ino(ext2_filsys fs, ext2_ino_t ino) | ||
| 149 | { | ||
| 150 | return (ino - 1) / fs->super->s_inodes_per_group; | ||
| 151 | } | ||
| 152 | |||
| 153 | blk_t ext2fs_inode_data_blocks(ext2_filsys fs, | ||
| 154 | struct ext2_inode *inode) | ||
| 155 | { | ||
| 156 | return inode->i_blocks - | ||
| 157 | (inode->i_file_acl ? fs->blocksize >> 9 : 0); | ||
| 158 | } | ||
| 159 | |||
| 160 | |||
| 161 | |||
| 162 | |||
| 163 | |||
| 164 | |||
| 165 | |||
| 166 | |||
| 167 | |||
| 168 | __u16 ext2fs_swab16(__u16 val) | ||
| 169 | { | ||
| 170 | return (val >> 8) | (val << 8); | ||
| 171 | } | ||
| 172 | |||
| 173 | __u32 ext2fs_swab32(__u32 val) | ||
| 174 | { | ||
| 175 | return ((val>>24) | ((val>>8)&0xFF00) | | ||
| 176 | ((val<<8)&0xFF0000) | (val<<24)); | ||
| 177 | } | ||
| 178 | |||
| 179 | int ext2fs_find_first_bit_set(void * addr, unsigned size) | ||
| 180 | { | ||
| 181 | char *cp = (unsigned char *) addr; | ||
| 182 | int res = 0, d0; | ||
| 183 | |||
| 184 | if (!size) | ||
| 185 | return 0; | ||
| 186 | |||
| 187 | while ((size > res) && (*cp == 0)) { | ||
| 188 | cp++; | ||
| 189 | res += 8; | ||
| 190 | } | ||
| 191 | d0 = ffs(*cp); | ||
| 192 | if (d0 == 0) | ||
| 193 | return size; | ||
| 194 | |||
| 195 | return res + d0 - 1; | ||
| 196 | } | ||
| 197 | |||
| 198 | int ext2fs_find_next_bit_set (void * addr, int size, int offset) | ||
| 199 | { | ||
| 200 | unsigned char * p; | ||
| 201 | int set = 0, bit = offset & 7, res = 0, d0; | ||
| 202 | |||
| 203 | res = offset >> 3; | ||
| 204 | p = ((unsigned char *) addr) + res; | ||
| 205 | |||
| 206 | if (bit) { | ||
| 207 | set = ffs(*p & ~((1 << bit) - 1)); | ||
| 208 | if (set) | ||
| 209 | return (offset & ~7) + set - 1; | ||
| 210 | p++; | ||
| 211 | res += 8; | ||
| 212 | } | ||
| 213 | while ((size > res) && (*p == 0)) { | ||
| 214 | p++; | ||
| 215 | res += 8; | ||
| 216 | } | ||
| 217 | d0 = ffs(*p); | ||
| 218 | if (d0 == 0) | ||
| 219 | return size; | ||
| 220 | |||
| 221 | return (res + d0 - 1); | ||
| 222 | } | ||
| 223 | |||
| 224 | int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap, | ||
| 225 | blk_t bitno); | ||
| 226 | |||
| 227 | int ext2fs_test_generic_bitmap(ext2fs_generic_bitmap bitmap, | ||
| 228 | blk_t bitno) | ||
| 229 | { | ||
| 230 | if ((bitno < bitmap->start) || (bitno > bitmap->end)) { | ||
| 231 | ext2fs_warn_bitmap2(bitmap, EXT2FS_TEST_ERROR, bitno); | ||
| 232 | return 0; | ||
| 233 | } | ||
| 234 | return ext2fs_test_bit(bitno - bitmap->start, bitmap->bitmap); | ||
| 235 | } | ||
| 236 | |||
| 237 | int ext2fs_mark_block_bitmap(ext2fs_block_bitmap bitmap, | ||
| 238 | blk_t block) | ||
| 239 | { | ||
| 240 | return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) | ||
| 241 | bitmap, | ||
| 242 | block); | ||
| 243 | } | ||
| 244 | |||
| 245 | int ext2fs_unmark_block_bitmap(ext2fs_block_bitmap bitmap, | ||
| 246 | blk_t block) | ||
| 247 | { | ||
| 248 | return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, | ||
| 249 | block); | ||
| 250 | } | ||
| 251 | |||
| 252 | int ext2fs_test_block_bitmap(ext2fs_block_bitmap bitmap, | ||
| 253 | blk_t block) | ||
| 254 | { | ||
| 255 | return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap, | ||
| 256 | block); | ||
| 257 | } | ||
| 258 | |||
| 259 | int ext2fs_mark_inode_bitmap(ext2fs_inode_bitmap bitmap, | ||
| 260 | ext2_ino_t inode) | ||
| 261 | { | ||
| 262 | return ext2fs_mark_generic_bitmap((ext2fs_generic_bitmap) bitmap, | ||
| 263 | inode); | ||
| 264 | } | ||
| 265 | |||
| 266 | int ext2fs_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap, | ||
| 267 | ext2_ino_t inode) | ||
| 268 | { | ||
| 269 | return ext2fs_unmark_generic_bitmap((ext2fs_generic_bitmap) bitmap, | ||
| 270 | inode); | ||
| 271 | } | ||
| 272 | |||
| 273 | int ext2fs_test_inode_bitmap(ext2fs_inode_bitmap bitmap, | ||
| 274 | ext2_ino_t inode) | ||
| 275 | { | ||
| 276 | return ext2fs_test_generic_bitmap((ext2fs_generic_bitmap) bitmap, | ||
| 277 | inode); | ||
| 278 | } | ||
| 279 | |||
| 280 | void ext2fs_fast_mark_block_bitmap(ext2fs_block_bitmap bitmap, | ||
| 281 | blk_t block) | ||
| 282 | { | ||
| 283 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 284 | if ((block < bitmap->start) || (block > bitmap->end)) { | ||
| 285 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block, | ||
| 286 | bitmap->description); | ||
| 287 | return; | ||
| 288 | } | ||
| 289 | #endif | ||
| 290 | ext2fs_set_bit(block - bitmap->start, bitmap->bitmap); | ||
| 291 | } | ||
| 292 | |||
| 293 | void ext2fs_fast_unmark_block_bitmap(ext2fs_block_bitmap bitmap, | ||
| 294 | blk_t block) | ||
| 295 | { | ||
| 296 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 297 | if ((block < bitmap->start) || (block > bitmap->end)) { | ||
| 298 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, | ||
| 299 | block, bitmap->description); | ||
| 300 | return; | ||
| 301 | } | ||
| 302 | #endif | ||
| 303 | ext2fs_clear_bit(block - bitmap->start, bitmap->bitmap); | ||
| 304 | } | ||
| 305 | |||
| 306 | int ext2fs_fast_test_block_bitmap(ext2fs_block_bitmap bitmap, | ||
| 307 | blk_t block) | ||
| 308 | { | ||
| 309 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 310 | if ((block < bitmap->start) || (block > bitmap->end)) { | ||
| 311 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST, | ||
| 312 | block, bitmap->description); | ||
| 313 | return 0; | ||
| 314 | } | ||
| 315 | #endif | ||
| 316 | return ext2fs_test_bit(block - bitmap->start, bitmap->bitmap); | ||
| 317 | } | ||
| 318 | |||
| 319 | void ext2fs_fast_mark_inode_bitmap(ext2fs_inode_bitmap bitmap, | ||
| 320 | ext2_ino_t inode) | ||
| 321 | { | ||
| 322 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 323 | if ((inode < bitmap->start) || (inode > bitmap->end)) { | ||
| 324 | ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_MARK, | ||
| 325 | inode, bitmap->description); | ||
| 326 | return; | ||
| 327 | } | ||
| 328 | #endif | ||
| 329 | ext2fs_set_bit(inode - bitmap->start, bitmap->bitmap); | ||
| 330 | } | ||
| 331 | |||
| 332 | void ext2fs_fast_unmark_inode_bitmap(ext2fs_inode_bitmap bitmap, | ||
| 333 | ext2_ino_t inode) | ||
| 334 | { | ||
| 335 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 336 | if ((inode < bitmap->start) || (inode > bitmap->end)) { | ||
| 337 | ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_UNMARK, | ||
| 338 | inode, bitmap->description); | ||
| 339 | return; | ||
| 340 | } | ||
| 341 | #endif | ||
| 342 | ext2fs_clear_bit(inode - bitmap->start, bitmap->bitmap); | ||
| 343 | } | ||
| 344 | |||
| 345 | int ext2fs_fast_test_inode_bitmap(ext2fs_inode_bitmap bitmap, | ||
| 346 | ext2_ino_t inode) | ||
| 347 | { | ||
| 348 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 349 | if ((inode < bitmap->start) || (inode > bitmap->end)) { | ||
| 350 | ext2fs_warn_bitmap(EXT2_ET_BAD_INODE_TEST, | ||
| 351 | inode, bitmap->description); | ||
| 352 | return 0; | ||
| 353 | } | ||
| 354 | #endif | ||
| 355 | return ext2fs_test_bit(inode - bitmap->start, bitmap->bitmap); | ||
| 356 | } | ||
| 357 | |||
| 358 | blk_t ext2fs_get_block_bitmap_start(ext2fs_block_bitmap bitmap) | ||
| 359 | { | ||
| 360 | return bitmap->start; | ||
| 361 | } | ||
| 362 | |||
| 363 | ext2_ino_t ext2fs_get_inode_bitmap_start(ext2fs_inode_bitmap bitmap) | ||
| 364 | { | ||
| 365 | return bitmap->start; | ||
| 366 | } | ||
| 367 | |||
| 368 | blk_t ext2fs_get_block_bitmap_end(ext2fs_block_bitmap bitmap) | ||
| 369 | { | ||
| 370 | return bitmap->end; | ||
| 371 | } | ||
| 372 | |||
| 373 | ext2_ino_t ext2fs_get_inode_bitmap_end(ext2fs_inode_bitmap bitmap) | ||
| 374 | { | ||
| 375 | return bitmap->end; | ||
| 376 | } | ||
| 377 | |||
| 378 | int ext2fs_test_block_bitmap_range(ext2fs_block_bitmap bitmap, | ||
| 379 | blk_t block, int num) | ||
| 380 | { | ||
| 381 | int i; | ||
| 382 | |||
| 383 | if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { | ||
| 384 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST, | ||
| 385 | block, bitmap->description); | ||
| 386 | return 0; | ||
| 387 | } | ||
| 388 | for (i=0; i < num; i++) { | ||
| 389 | if (ext2fs_fast_test_block_bitmap(bitmap, block+i)) | ||
| 390 | return 0; | ||
| 391 | } | ||
| 392 | return 1; | ||
| 393 | } | ||
| 394 | |||
| 395 | int ext2fs_fast_test_block_bitmap_range(ext2fs_block_bitmap bitmap, | ||
| 396 | blk_t block, int num) | ||
| 397 | { | ||
| 398 | int i; | ||
| 399 | |||
| 400 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 401 | if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { | ||
| 402 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_TEST, | ||
| 403 | block, bitmap->description); | ||
| 404 | return 0; | ||
| 405 | } | ||
| 406 | #endif | ||
| 407 | for (i=0; i < num; i++) { | ||
| 408 | if (ext2fs_fast_test_block_bitmap(bitmap, block+i)) | ||
| 409 | return 0; | ||
| 410 | } | ||
| 411 | return 1; | ||
| 412 | } | ||
| 413 | |||
| 414 | void ext2fs_mark_block_bitmap_range(ext2fs_block_bitmap bitmap, | ||
| 415 | blk_t block, int num) | ||
| 416 | { | ||
| 417 | int i; | ||
| 418 | |||
| 419 | if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { | ||
| 420 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block, | ||
| 421 | bitmap->description); | ||
| 422 | return; | ||
| 423 | } | ||
| 424 | for (i=0; i < num; i++) | ||
| 425 | ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap); | ||
| 426 | } | ||
| 427 | |||
| 428 | void ext2fs_fast_mark_block_bitmap_range(ext2fs_block_bitmap bitmap, | ||
| 429 | blk_t block, int num) | ||
| 430 | { | ||
| 431 | int i; | ||
| 432 | |||
| 433 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 434 | if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { | ||
| 435 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_MARK, block, | ||
| 436 | bitmap->description); | ||
| 437 | return; | ||
| 438 | } | ||
| 439 | #endif | ||
| 440 | for (i=0; i < num; i++) | ||
| 441 | ext2fs_set_bit(block + i - bitmap->start, bitmap->bitmap); | ||
| 442 | } | ||
| 443 | |||
| 444 | void ext2fs_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap, | ||
| 445 | blk_t block, int num) | ||
| 446 | { | ||
| 447 | int i; | ||
| 448 | |||
| 449 | if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { | ||
| 450 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block, | ||
| 451 | bitmap->description); | ||
| 452 | return; | ||
| 453 | } | ||
| 454 | for (i=0; i < num; i++) | ||
| 455 | ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap); | ||
| 456 | } | ||
| 457 | |||
| 458 | void ext2fs_fast_unmark_block_bitmap_range(ext2fs_block_bitmap bitmap, | ||
| 459 | blk_t block, int num) | ||
| 460 | { | ||
| 461 | int i; | ||
| 462 | |||
| 463 | #ifdef EXT2FS_DEBUG_FAST_OPS | ||
| 464 | if ((block < bitmap->start) || (block+num-1 > bitmap->end)) { | ||
| 465 | ext2fs_warn_bitmap(EXT2_ET_BAD_BLOCK_UNMARK, block, | ||
| 466 | bitmap->description); | ||
| 467 | return; | ||
| 468 | } | ||
| 469 | #endif | ||
| 470 | for (i=0; i < num; i++) | ||
| 471 | ext2fs_clear_bit(block + i - bitmap->start, bitmap->bitmap); | ||
| 472 | } | ||
