#include <limits.h>
#include "debug.h"
#include "lib.h"
-#include "malloc.h"
+#include "threads/malloc.h"
#ifdef FILESYS
-#include "file.h"
+#include "filesys/file.h"
#endif
\f
/* Number of bits in an element. */
ASSERT (b != NULL);
- for (i = 0; i < elem_cnt (b); i++)
- b->bits[i] = value ? (elem_type) -1 : 0;
- b->bits[elem_cnt (b) - 1] &= last_mask (b);
+ if (b->bit_cnt > 0)
+ {
+ for (i = 0; i < elem_cnt (b); i++)
+ b->bits[i] = value ? (elem_type) -1 : 0;
+ b->bits[elem_cnt (b) - 1] &= last_mask (b);
+ }
}
/* Sets the bit numbered IDX in B to true. */
void
bitmap_read (struct bitmap *b, struct file *file)
{
- file_read_at (file, b->bits, byte_cnt (b), 0);
- b->bits[elem_cnt (b) - 1] &= last_mask (b);
+ if (b->bit_cnt > 0)
+ {
+ file_read_at (file, b->bits, byte_cnt (b), 0);
+ b->bits[elem_cnt (b) - 1] &= last_mask (b);
+ }
}
/* Writes FILE to B, ignoring errors. */