projects
/
pintos-anon
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Rename printk() to printf().
[pintos-anon]
/
src
/
filesys
/
filehdr.c
diff --git
a/src/filesys/filehdr.c
b/src/filesys/filehdr.c
index 1f35946479070e15884f839dfd3c58cbb097c94f..58179128ae27782bfbc5c4b1fdf5af244484ec4f 100644
(file)
--- a/
src/filesys/filehdr.c
+++ b/
src/filesys/filehdr.c
@@
-1,9
+1,9
@@
-#include "filehdr.h"
-#include
"bitmap.h"
-#include
"debug.h"
-#include
"malloc.h"
-#include "filesys.h"
-#include "
lib
.h"
+#include "file
sys/file
hdr.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'
/* Allocates sectors from bitmap B for the content of a file
whose size is LENGTH bytes, and returns a new `struct filehdr'
@@
-22,12
+22,15
@@
filehdr_allocate (struct bitmap *b, off_t length)
ASSERT (b != NULL);
ASSERT (length >= 0);
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;
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);
while (h->sector_cnt < sector_cnt)
{
size_t sector = bitmap_find_and_set (b);
@@
-119,7
+122,7
@@
filehdr_print (const struct filehdr *h)
{
size_t i;
{
size_t i;
- print
k
("File header: %jd bytes, %zd sectors (",
+ print
f
("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
(intmax_t) h->length, h->sector_cnt);
/* This loop could be unsafe for large h->sector_cnt, can you
@@
-127,8
+130,8
@@
filehdr_print (const struct filehdr *h)
for (i = 0; i < h->sector_cnt; i++)
{
if (i != 0)
for (i = 0; i < h->sector_cnt; i++)
{
if (i != 0)
- print
k
(", ");
- print
k
("%jd", (intmax_t) h->sectors[i]);
+ print
f
(", ");
+ print
f
("%jd", (intmax_t) h->sectors[i]);
}
}
- print
k
(")\n");
+ print
f
(")\n");
}
}