diff options
Diffstat (limited to 'include')
-rw-r--r-- | include/asm-m68k/bitops.h | 54 |
1 files changed, 52 insertions, 2 deletions
diff --git a/include/asm-m68k/bitops.h b/include/asm-m68k/bitops.h index e845daac48ad..1a61fdb56aaf 100644 --- a/include/asm-m68k/bitops.h +++ b/include/asm-m68k/bitops.h | |||
@@ -351,11 +351,61 @@ static inline int minix_test_bit(int nr, const void *vaddr) | |||
351 | 351 | ||
352 | /* Bitmap functions for the ext2 filesystem. */ | 352 | /* Bitmap functions for the ext2 filesystem. */ |
353 | 353 | ||
354 | #include <asm-generic/bitops/ext2-non-atomic.h> | 354 | #define ext2_set_bit(nr, addr) __test_and_set_bit((nr) ^ 24, (unsigned long *)(addr)) |
355 | |||
356 | #define ext2_set_bit_atomic(lock, nr, addr) test_and_set_bit((nr) ^ 24, (unsigned long *)(addr)) | 355 | #define ext2_set_bit_atomic(lock, nr, addr) test_and_set_bit((nr) ^ 24, (unsigned long *)(addr)) |
356 | #define ext2_clear_bit(nr, addr) __test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr)) | ||
357 | #define ext2_clear_bit_atomic(lock, nr, addr) test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr)) | 357 | #define ext2_clear_bit_atomic(lock, nr, addr) test_and_clear_bit((nr) ^ 24, (unsigned long *)(addr)) |
358 | 358 | ||
359 | static inline int ext2_test_bit(int nr, const void *vaddr) | ||
360 | { | ||
361 | const unsigned char *p = vaddr; | ||
362 | return (p[nr >> 3] & (1U << (nr & 7))) != 0; | ||
363 | } | ||
364 | |||
365 | static inline int ext2_find_first_zero_bit(const void *vaddr, unsigned size) | ||
366 | { | ||
367 | const unsigned long *p = vaddr, *addr = vaddr; | ||
368 | int res; | ||
369 | |||
370 | if (!size) | ||
371 | return 0; | ||
372 | |||
373 | size = (size >> 5) + ((size & 31) > 0); | ||
374 | while (*p++ == ~0UL) | ||
375 | { | ||
376 | if (--size == 0) | ||
377 | return (p - addr) << 5; | ||
378 | } | ||
379 | |||
380 | --p; | ||
381 | for (res = 0; res < 32; res++) | ||
382 | if (!ext2_test_bit (res, p)) | ||
383 | break; | ||
384 | return (p - addr) * 32 + res; | ||
385 | } | ||
386 | |||
387 | static inline int ext2_find_next_zero_bit(const void *vaddr, unsigned size, | ||
388 | unsigned offset) | ||
389 | { | ||
390 | const unsigned long *addr = vaddr; | ||
391 | const unsigned long *p = addr + (offset >> 5); | ||
392 | int bit = offset & 31UL, res; | ||
393 | |||
394 | if (offset >= size) | ||
395 | return size; | ||
396 | |||
397 | if (bit) { | ||
398 | /* Look for zero in first longword */ | ||
399 | for (res = bit; res < 32; res++) | ||
400 | if (!ext2_test_bit (res, p)) | ||
401 | return (p - addr) * 32 + res; | ||
402 | p++; | ||
403 | } | ||
404 | /* No zero yet, search remaining full bytes for a zero */ | ||
405 | res = ext2_find_first_zero_bit (p, size - 32 * (p - addr)); | ||
406 | return (p - addr) * 32 + res; | ||
407 | } | ||
408 | |||
359 | #endif /* __KERNEL__ */ | 409 | #endif /* __KERNEL__ */ |
360 | 410 | ||
361 | #endif /* _M68K_BITOPS_H */ | 411 | #endif /* _M68K_BITOPS_H */ |