-#include "filehdr.h"
-#include "bitmap.h"
-#include "debug.h"
-#include "malloc.h"
-#include "filesys.h"
-#include "lib.h"
+#include "filesys/filehdr.h"
+#include <bitmap.h>
+#include <debug.h>
+#include <stdio.h>
+#include "filesys/filesys.h"
+#include "threads/malloc.h"
/* Allocates sectors from bitmap B for the content of a file
whose size is LENGTH bytes, and returns a new `struct filehdr'
ASSERT (b != NULL);
ASSERT (length >= 0);
+ sector_cnt = (length / DISK_SECTOR_SIZE) + (length % DISK_SECTOR_SIZE > 0);
+ if (sector_cnt > DIRECT_CNT)
+ return false;
+
h = calloc (1, sizeof *h);
if (h == NULL)
return NULL;
h->length = length;
- sector_cnt = (length / DISK_SECTOR_SIZE) + (length % DISK_SECTOR_SIZE > 0);
while (h->sector_cnt < sector_cnt)
{
size_t sector = bitmap_find_and_set (b);
{
size_t i;
- printk ("File header: %jd bytes, %zd sectors (",
+ printf ("File header: %jd bytes, %zd sectors (",
(intmax_t) h->length, h->sector_cnt);
/* This loop could be unsafe for large h->sector_cnt, can you
for (i = 0; i < h->sector_cnt; i++)
{
if (i != 0)
- printk (", ");
- printk ("%jd", (intmax_t) h->sectors[i]);
+ printf (", ");
+ printf ("%jd", (intmax_t) h->sectors[i]);
}
- printk (")\n");
+ printf (")\n");
}