-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sacrificed a direct block for a double-indirect block on the inode
- Loading branch information
Showing
6 changed files
with
127 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "types.h" | ||
#include "stat.h" | ||
#include "user.h" | ||
#include "fcntl.h" | ||
|
||
/* | ||
HW page: https://pdos.csail.mit.edu/6.828/2016/homework/xv6-big-files.html | ||
Expected output in xv6 shell: | ||
$ big | ||
..................................................................................................................................................................... | ||
wrote 16523 sectors | ||
done; ok | ||
*/ | ||
|
||
int | ||
main() | ||
{ | ||
char buf[512]; | ||
int fd, i, sectors; | ||
|
||
fd = open("big.file", O_CREATE | O_WRONLY); | ||
if(fd < 0){ | ||
printf(2, "big: cannot open big.file for writing\n"); | ||
exit(); | ||
} | ||
|
||
sectors = 0; | ||
while(1){ | ||
*(int*)buf = sectors; | ||
int cc = write(fd, buf, sizeof(buf)); | ||
if(cc <= 0) | ||
break; | ||
sectors++; | ||
if (sectors % 100 == 0) | ||
printf(2, "."); | ||
} | ||
|
||
printf(1, "\nwrote %d sectors\n", sectors); | ||
|
||
close(fd); | ||
fd = open("big.file", O_RDONLY); | ||
if(fd < 0){ | ||
printf(2, "big: cannot re-open big.file for reading\n"); | ||
exit(); | ||
} | ||
for(i = 0; i < sectors; i++){ | ||
int cc = read(fd, buf, sizeof(buf)); | ||
if(cc <= 0){ | ||
printf(2, "big: read error at sector %d\n", i); | ||
exit(); | ||
} | ||
if(*(int*)buf != i){ | ||
printf(2, "big: read the wrong data (%d) for sector %d\n", | ||
*(int*)buf, i); | ||
exit(); | ||
} | ||
} | ||
|
||
printf(1, "done; ok\n"); | ||
|
||
exit(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters