From 6e16c5a1ad342a623d8702267ae4319c9ef8d0a3 Mon Sep 17 00:00:00 2001 From: !flatcap Date: Thu, 22 Aug 2002 18:09:47 +0000 Subject: [PATCH] whitespace and include guards 2002/07/02 23:47:10-00:00 !antona Global replacement of __[su]{8,16,32,64} with [su]{8,16,32,64} and layout.h define it. 2002/04/14 15:26:23-00:00 !antona Remove find_first_attr and make all users use get_attr_search_ctx + find_attr instead. 2002/04/14 13:56:45-00:00 !antona cleanup header files. 2001/06/01 02:07:24-00:00 !antona It has been a long time since last commit. At moment have done a lot of work on mkntfs but also at the moment ntfsfix and ntfsdump_logfile and libntfs are broken. Basically only mkntfs works and that is not complete either. 2001/04/10 22:20:19-00:00 !antona Ok, ntfsd was a mistake for userspace. It increases complexity no end while not giving us much functionality. Lets get it working and then worry about the kernel. - As it was the idea originally anyway, so this is just a return on the right track. (-8 We keep the timer and signal handler but the only thing we do is to set a bool flag (ntfs_need_sync) and we will just check this in appropriate places and if it is true we call ntfs_sync_volumes() which sets it back to false. This means no more locking at all of any description and no need to worry about the signal handler interrupting things in bad ways and/or at bad times in the main code. 2001/04/08 03:02:55-00:00 !antona Added cvs Id header. 2001/04/05 20:14:45-00:00 !antona Commit of current state of development including locking a la kernel. This doesn't work on user space (semaphores don't work). Just want to have it committed. Will take out locking / modify it where necessary to use pthreads ASAP. 2001/04/03 22:41:30-00:00 !antona We now have files and keep track of them on a per volume basis and same for inodes (mft_records). At least conceptually anyway. 2001/01/25 22:25:43-00:00 !antona More files added to ntfs lib. Fixed some consistency problems. 2001/01/24 15:01:18-00:00 !antona Added bitmap header. (Logical change 1.5) --- include/bitmap.h | 105 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 105 insertions(+) diff --git a/include/bitmap.h b/include/bitmap.h index e69de29b..0da0c107 100644 --- a/include/bitmap.h +++ b/include/bitmap.h @@ -0,0 +1,105 @@ +/* + * $Id$ + * + * bitmap.h - Exports for bitmap handling. Part of the Linux-NTFS project. + * + * Copyright (c) 2000-2002 Anton Altaparmakov. + * + * This program/include file is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License as published + * by the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program/include file is distributed in the hope that it will be + * useful, but WITHOUT ANY WARRANTY; without even the implied warranty + * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program (in the main directory of the Linux-NTFS + * distribution in the file COPYING); if not, write to the Free Software + * Foundation,Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef _NTFS_BITMAP_H +#define _NTFS_BITMAP_H + +#include "types.h" + +/* + * NOTES: + * + * - Operations are 8-bit only to ensure the functions work both on little + * and big endian machines! So don't make them 32-bit ops! + * - bitmap starts at bit = 0 and ends at bit = bitmap size - 1. + * - _Caller_ has to make sure that the bit to operate on is less than the + * size of the bitmap. + */ + +/** + * ntfs_set_bit - set a bit in a field of bits + * @bitmap: field of bits + * @bit: bit to set + * @new_value: value to set bit to (0 or 1) + * + * Set the bit @bit in the @bitmap to @new_value. Ignore all errors. + */ +static __inline__ void ntfs_set_bit(u8 *bitmap, const u64 bit, + const u8 new_value) +{ +// Dprintf("bitmap %p, bit 0x%Lx, new_value %i\n", bitmap, bit, new_value); + if (!bitmap || new_value > 1) + return; + if (!new_value) + bitmap[bit >> 3] &= ~(1 << (bit & 7)); + else + bitmap[bit >> 3] |= (1 << (bit & 7)); +} + +/** + * ntfs_get_bit - get value of a bit in a field of bits + * @bitmap: field of bits + * @bit: bit to get + * + * Get and return the value of the bit @bit in @bitmap (0 or 1). + * Return -1 on error. + */ +static __inline__ char ntfs_get_bit(const u8 *bitmap, const u64 bit) +{ + if (!bitmap) + return -1; + return (bitmap[bit >> 3] >> (bit & 7)) & 1; +} + +static __inline__ void ntfs_change_bit(u8 *bitmap, const u64 bit) +{ + if (!bitmap) + return; + bitmap[bit >> 3] ^= 1 << (bit & 7); +} + +/** + * ntfs_get_and_set_bit - get value of a bit in a field of bits and set it + * @bitmap: field of bits + * @bit: bit to get/set + * @new_value: value to set bit to (0 or 1) + * + * Return the value of the bit @bit and set it to @new_value (0 or 1). + * Return -1 on error. + */ +static __inline__ char ntfs_get_and_set_bit(u8 *bitmap, const u64 bit, + const u8 new_value) +{ + register u8 old_bit, shift; + + if (!bitmap || new_value > 1) + return -1; + shift = bit & 7; + old_bit = (bitmap[bit >> 3] >> shift) & 1; + if (new_value != old_bit) + bitmap[bit >> 3] ^= 1 << shift; + return old_bit; +} + +#endif /* defined _NTFS_BITMAP_H */ +