/* Create the initial bitmap and reserve sectors for the
free map and root directory file headers. */
- bitmap_init (&free_map, disk_size (disk));
+ if (!bitmap_init (&free_map, disk_size (disk)))
+ panic ("bitmap creation failed");
bitmap_mark (&free_map, FREE_MAP_SECTOR);
bitmap_mark (&free_map, ROOT_DIR_SECTOR);
goto exit1;
/* Allocate a block for the file header. */
- bitmap_init (&free_map, disk_size (disk));
+ if (!bitmap_init (&free_map, disk_size (disk)))
+ goto exit1;
bitmapio_read (&free_map, &free_map_file);
hdr_sector = bitmap_find_and_set (&free_map);
if (hdr_sector == BITMAP_ERROR)
dir_init (&dir, NUM_DIR_ENTRIES);
dir_read (&dir, &root_dir_file);
if (!dir_lookup (&dir, name, &hdr_sector))
- goto exit;
+ goto exit1;
/* Read the file header. */
- filehdr_read (&filehdr, hdr_sector);
+ if (!filehdr_read (&filehdr, hdr_sector))
+ goto exit1;
/* Allocate a block for the file header. */
- bitmap_init (&free_map, disk_size (disk));
+ if (!bitmap_init (&free_map, disk_size (disk)))
+ goto exit2;
bitmapio_read (&free_map, &free_map_file);
/* Deallocate. */
success = true;
/* Clean up. */
- filehdr_destroy (&filehdr);
bitmap_destroy (&free_map);
- exit:
+ exit2:
+ filehdr_destroy (&filehdr);
+ exit1:
dir_destroy (&dir);
return success;
#include "lib.h"
#include "malloc.h"
-typedef unsigned long elem_type;
#define ELEM_BITS (sizeof (elem_type) * CHAR_BIT)
#define ELEM_IDX(BIT_IDX) ((BIT_IDX) / ELEM_BITS)
#define BIT_MASK(BIT_IDX) ((elem_type) 1 << ((BIT_IDX) % ELEM_BITS))
return sizeof (elem_type) * elem_cnt (b);
}
-void
+bool
bitmap_init (struct bitmap *b, size_t bit_cnt)
{
b->bit_cnt = bit_cnt;
b->bits = malloc (byte_cnt (b));
if (b->bits == NULL && bit_cnt > 0)
- return NULL;
+ return false;
bitmap_set_all (b, false);
- return b;
+ return true;
}
size_t
#include <stdbool.h>
#include <stddef.h>
+typedef unsigned long elem_type;
+
struct bitmap
{
size_t bit_cnt;
elem_type *bits;
};
-void bitmap_init (struct bitmap *, size_t bit_cnt);
+bool bitmap_init (struct bitmap *, size_t bit_cnt);
void bitmap_destroy (struct bitmap *);
size_t bitmap_size (const struct bitmap *);
+size_t bitmap_storage_size (const struct bitmap *);
void bitmap_set (struct bitmap *, size_t idx, bool);
void bitmap_set_all (struct bitmap *, bool);