Steve Kondik | 2111ad7 | 2013-07-07 12:07:44 -0700 | [diff] [blame] | 1 | /* |
| 2 | * bitmap.h - Exports for bitmap handling. Originated from the Linux-NTFS project. |
| 3 | * |
| 4 | * Copyright (c) 2000-2004 Anton Altaparmakov |
| 5 | * Copyright (c) 2004-2005 Richard Russon |
| 6 | * |
| 7 | * This program/include file is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as published |
| 9 | * by the Free Software Foundation; either version 2 of the License, or |
| 10 | * (at your option) any later version. |
| 11 | * |
| 12 | * This program/include file is distributed in the hope that it will be |
| 13 | * useful, but WITHOUT ANY WARRANTY; without even the implied warranty |
| 14 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program (in the main directory of the NTFS-3G |
| 19 | * distribution in the file COPYING); if not, write to the Free Software |
| 20 | * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | */ |
| 22 | |
| 23 | #ifndef _NTFS_BITMAP_H |
| 24 | #define _NTFS_BITMAP_H |
| 25 | |
| 26 | #include "types.h" |
| 27 | #include "attrib.h" |
| 28 | |
| 29 | /* |
| 30 | * NOTES: |
| 31 | * |
| 32 | * - Operations are 8-bit only to ensure the functions work both on little |
| 33 | * and big endian machines! So don't make them 32-bit ops! |
| 34 | * - bitmap starts at bit = 0 and ends at bit = bitmap size - 1. |
| 35 | * - _Caller_ has to make sure that the bit to operate on is less than the |
| 36 | * size of the bitmap. |
| 37 | */ |
| 38 | |
| 39 | extern void ntfs_bit_set(u8 *bitmap, const u64 bit, const u8 new_value); |
| 40 | extern char ntfs_bit_get(const u8 *bitmap, const u64 bit); |
| 41 | extern char ntfs_bit_get_and_set(u8 *bitmap, const u64 bit, const u8 new_value); |
| 42 | extern int ntfs_bitmap_set_run(ntfs_attr *na, s64 start_bit, s64 count); |
| 43 | extern int ntfs_bitmap_clear_run(ntfs_attr *na, s64 start_bit, s64 count); |
| 44 | |
| 45 | /** |
| 46 | * ntfs_bitmap_set_bit - set a bit in a bitmap |
| 47 | * @na: attribute containing the bitmap |
| 48 | * @bit: bit to set |
| 49 | * |
| 50 | * Set the @bit in the bitmap described by the attribute @na. |
| 51 | * |
| 52 | * On success return 0 and on error return -1 with errno set to the error code. |
| 53 | */ |
| 54 | static __inline__ int ntfs_bitmap_set_bit(ntfs_attr *na, s64 bit) |
| 55 | { |
| 56 | return ntfs_bitmap_set_run(na, bit, 1); |
| 57 | } |
| 58 | |
| 59 | /** |
| 60 | * ntfs_bitmap_clear_bit - clear a bit in a bitmap |
| 61 | * @na: attribute containing the bitmap |
| 62 | * @bit: bit to clear |
| 63 | * |
| 64 | * Clear @bit in the bitmap described by the attribute @na. |
| 65 | * |
| 66 | * On success return 0 and on error return -1 with errno set to the error code. |
| 67 | */ |
| 68 | static __inline__ int ntfs_bitmap_clear_bit(ntfs_attr *na, s64 bit) |
| 69 | { |
| 70 | return ntfs_bitmap_clear_run(na, bit, 1); |
| 71 | } |
| 72 | |
| 73 | /* |
| 74 | * rol32 - rotate a 32-bit value left |
| 75 | * |
| 76 | * @word: value to rotate |
| 77 | * @shift: bits to roll |
| 78 | */ |
| 79 | static __inline__ u32 ntfs_rol32(u32 word, unsigned int shift) |
| 80 | { |
| 81 | return (word << shift) | (word >> (32 - shift)); |
| 82 | } |
| 83 | |
| 84 | /* |
| 85 | * ror32 - rotate a 32-bit value right |
| 86 | * |
| 87 | * @word: value to rotate |
| 88 | * @shift: bits to roll |
| 89 | */ |
| 90 | static __inline__ u32 ntfs_ror32(u32 word, unsigned int shift) |
| 91 | { |
| 92 | return (word >> shift) | (word << (32 - shift)); |
| 93 | } |
| 94 | |
| 95 | #endif /* defined _NTFS_BITMAP_H */ |
| 96 | |