/**
* bitmap.c - Bitmap handling code. Part of the Linux-NTFS project.
*
* Copyright (c) 2002-2006 Anton Altaparmakov
* Copyright (c) 2004-2005 Richard Russon
*
* 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.
*
* 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
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_STRING_H
#include <string.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
#include "compat.h"
#include "types.h"
#include "attrib.h"
#include "bitmap.h"
#include "debug.h"
#include "logging.h"
/**
* ntfs_bitmap_set_bits_in_run - set a run of bits in a bitmap to a value
* @na: attribute containing the bitmap
* @start_bit: first bit to set
* @count: number of bits to set
* @value: value to set the bits to (i.e. 0 or 1)
*
* Set @count bits starting at bit @start_bit in the bitmap described by the
* attribute @na to @value, where @value is either 0 or 1.
*
* On success return 0 and on error return -1 with errno set to the error code.
*/
{
return -1;
}
if (bit)
firstbyte = 1;
else
firstbyte = 0;
/* Calculate the required buffer size in bytes, capping it at 8kiB. */
if (bufsize > 8192)
bufsize = 8192;
if (!buf)
return -1;
/* Depending on @value, zero or set all bits in the allocated buffer. */
/* If there is a first partial byte... */
if (bit) {
/* read it in... */
if (br != 1) {
return -1;
}
/* and set or clear the appropriate bits in it. */
if (value)
else
}
/* Update @start_bit to the new position. */
}
/* Loop until @left reaches zero. */
lastbyte = 0;
lastbyte_buf = NULL;
do {
/* If there is a last partial byte... */
if (!lastbyte_pos) {
// FIXME: Eeek! BUG!
ntfs_log_trace("lastbyte is zero. Leaving "
"inconsistent metadata.\n");
goto free_err_out;
}
/* and it is in the currently loaded bitmap window... */
if (lastbyte_pos <= bufsize) {
/* read the byte in... */
if (br != 1) {
// FIXME: Eeek! We need rollback! (AIA)
ntfs_log_trace("Read of last byte "
"failed. Leaving "
"inconsistent "
"metadata.\n");
goto free_err_out;
}
if (value)
else
}
/* We don't want to come back here... */
bit = 0;
/* We have a last byte that we have handled. */
lastbyte = 1;
}
}
/* Write the prepared buffer to disk. */
// FIXME: Eeek! We need rollback! (AIA)
ntfs_log_trace("Failed to write buffer to bitmap. "
"Leaving inconsistent metadata.\n");
goto free_err_out;
}
/* Update counters. */
if (firstbyte) {
firstbyte = 0;
/*
* Re-set the partial first byte so a subsequent write
* of the buffer does not have stale, incorrect bits.
*/
}
// FIXME: Eeek! BUG!
ntfs_log_trace("Last buffer but count is not zero (= "
"%lli). Leaving inconsistent metadata."
"\n", (long long)left);
goto free_err_out;
}
} while (left > 0);
/* Update free clusters and MFT records. */
if (value)
else
}
if (value)
else
}
/* Done! */
return 0;
return -1;
}
/**
* ntfs_bitmap_set_run - set a run of bits in a bitmap
* @na: attribute containing the bitmap
* @start_bit: first bit to set
* @count: number of bits to set
*
* Set @count bits starting at bit @start_bit in the bitmap described by the
* attribute @na.
*
* On success return 0 and on error return -1 with errno set to the error code.
*/
{
}
/**
* ntfs_bitmap_clear_run - clear a run of bits in a bitmap
* @na: attribute containing the bitmap
* @start_bit: first bit to clear
* @count: number of bits to clear
*
* Clear @count bits starting at bit @start_bit in the bitmap described by the
* attribute @na.
*
* On success return 0 and on error return -1 with errno set to the error code.
*/
{
ntfs_log_trace("Dealloc from bit 0x%llx, count 0x%llx.\n",
}