Lab 1
This commit is contained in:
67
fs/test.c
Normal file
67
fs/test.c
Normal file
@@ -0,0 +1,67 @@
|
||||
#include <inc/x86.h>
|
||||
#include <inc/string.h>
|
||||
|
||||
#include "fs.h"
|
||||
|
||||
static char *msg = "This is the NEW message of the day!\n\n";
|
||||
|
||||
void
|
||||
fs_test(void)
|
||||
{
|
||||
struct File *f;
|
||||
int r;
|
||||
char *blk;
|
||||
uint32_t *bits;
|
||||
|
||||
// back up bitmap
|
||||
if ((r = sys_page_alloc(0, (void*) PGSIZE, PTE_P|PTE_U|PTE_W)) < 0)
|
||||
panic("sys_page_alloc: %e", r);
|
||||
bits = (uint32_t*) PGSIZE;
|
||||
memmove(bits, bitmap, PGSIZE);
|
||||
// allocate block
|
||||
if ((r = alloc_block()) < 0)
|
||||
panic("alloc_block: %e", r);
|
||||
// check that block was free
|
||||
assert(bits[r/32] & (1 << (r%32)));
|
||||
// and is not free any more
|
||||
assert(!(bitmap[r/32] & (1 << (r%32))));
|
||||
cprintf("alloc_block is good\n");
|
||||
|
||||
if ((r = file_open("/not-found", &f)) < 0 && r != -E_NOT_FOUND)
|
||||
panic("file_open /not-found: %e", r);
|
||||
else if (r == 0)
|
||||
panic("file_open /not-found succeeded!");
|
||||
if ((r = file_open("/newmotd", &f)) < 0)
|
||||
panic("file_open /newmotd: %e", r);
|
||||
cprintf("file_open is good\n");
|
||||
|
||||
if ((r = file_get_block(f, 0, &blk)) < 0)
|
||||
panic("file_get_block: %e", r);
|
||||
if (strcmp(blk, msg) != 0)
|
||||
panic("file_get_block returned wrong data");
|
||||
cprintf("file_get_block is good\n");
|
||||
|
||||
*(volatile char*)blk = *(volatile char*)blk;
|
||||
assert((uvpt[PGNUM(blk)] & PTE_D));
|
||||
file_flush(f);
|
||||
assert(!(uvpt[PGNUM(blk)] & PTE_D));
|
||||
cprintf("file_flush is good\n");
|
||||
|
||||
if ((r = file_set_size(f, 0)) < 0)
|
||||
panic("file_set_size: %e", r);
|
||||
assert(f->f_direct[0] == 0);
|
||||
assert(!(uvpt[PGNUM(f)] & PTE_D));
|
||||
cprintf("file_truncate is good\n");
|
||||
|
||||
if ((r = file_set_size(f, strlen(msg))) < 0)
|
||||
panic("file_set_size 2: %e", r);
|
||||
assert(!(uvpt[PGNUM(f)] & PTE_D));
|
||||
if ((r = file_get_block(f, 0, &blk)) < 0)
|
||||
panic("file_get_block 2: %e", r);
|
||||
strcpy(blk, msg);
|
||||
assert((uvpt[PGNUM(blk)] & PTE_D));
|
||||
file_flush(f);
|
||||
assert(!(uvpt[PGNUM(blk)] & PTE_D));
|
||||
assert(!(uvpt[PGNUM(f)] & PTE_D));
|
||||
cprintf("file rewrite is good\n");
|
||||
}
|
||||
70
fs/testshell.key
Normal file
70
fs/testshell.key
Normal file
@@ -0,0 +1,70 @@
|
||||
# echo hello world | cat
|
||||
hello world
|
||||
# cat lorem
|
||||
Lorem ipsum dolor sit amet, consectetur
|
||||
adipisicing elit, sed do eiusmod tempor
|
||||
incididunt ut labore et dolore magna
|
||||
aliqua. Ut enim ad minim veniam, quis
|
||||
nostrud exercitation ullamco laboris
|
||||
nisi ut aliquip ex ea commodo consequat.
|
||||
Duis aute irure dolor in reprehenderit
|
||||
in voluptate velit esse cillum dolore eu
|
||||
fugiat nulla pariatur. Excepteur sint
|
||||
occaecat cupidatat non proident, sunt in
|
||||
culpa qui officia deserunt mollit anim
|
||||
id est laborum.
|
||||
# cat lorem |num
|
||||
1 Lorem ipsum dolor sit amet, consectetur
|
||||
2 adipisicing elit, sed do eiusmod tempor
|
||||
3 incididunt ut labore et dolore magna
|
||||
4 aliqua. Ut enim ad minim veniam, quis
|
||||
5 nostrud exercitation ullamco laboris
|
||||
6 nisi ut aliquip ex ea commodo consequat.
|
||||
7 Duis aute irure dolor in reprehenderit
|
||||
8 in voluptate velit esse cillum dolore eu
|
||||
9 fugiat nulla pariatur. Excepteur sint
|
||||
10 occaecat cupidatat non proident, sunt in
|
||||
11 culpa qui officia deserunt mollit anim
|
||||
12 id est laborum.
|
||||
# cat lorem |num |num |num |num |num
|
||||
1 1 1 1 1 Lorem ipsum dolor sit amet, consectetur
|
||||
2 2 2 2 2 adipisicing elit, sed do eiusmod tempor
|
||||
3 3 3 3 3 incididunt ut labore et dolore magna
|
||||
4 4 4 4 4 aliqua. Ut enim ad minim veniam, quis
|
||||
5 5 5 5 5 nostrud exercitation ullamco laboris
|
||||
6 6 6 6 6 nisi ut aliquip ex ea commodo consequat.
|
||||
7 7 7 7 7 Duis aute irure dolor in reprehenderit
|
||||
8 8 8 8 8 in voluptate velit esse cillum dolore eu
|
||||
9 9 9 9 9 fugiat nulla pariatur. Excepteur sint
|
||||
10 10 10 10 10 occaecat cupidatat non proident, sunt in
|
||||
11 11 11 11 11 culpa qui officia deserunt mollit anim
|
||||
12 12 12 12 12 id est laborum.
|
||||
# lsfd -1
|
||||
fd 0: name testshell.sh isdir 0 size 113 dev file
|
||||
fd 1: name <pipe> isdir 0 size 32 dev pipe
|
||||
fd 3: name <pipe> isdir 0 size 32 dev pipe
|
||||
# cat script
|
||||
echo This is from the script.
|
||||
cat lorem | num | cat
|
||||
echo These are my file descriptors.
|
||||
lsfd -1
|
||||
echo This is the end of the script.
|
||||
# sh <script
|
||||
This is from the script.
|
||||
1 Lorem ipsum dolor sit amet, consectetur
|
||||
2 adipisicing elit, sed do eiusmod tempor
|
||||
3 incididunt ut labore et dolore magna
|
||||
4 aliqua. Ut enim ad minim veniam, quis
|
||||
5 nostrud exercitation ullamco laboris
|
||||
6 nisi ut aliquip ex ea commodo consequat.
|
||||
7 Duis aute irure dolor in reprehenderit
|
||||
8 in voluptate velit esse cillum dolore eu
|
||||
9 fugiat nulla pariatur. Excepteur sint
|
||||
10 occaecat cupidatat non proident, sunt in
|
||||
11 culpa qui officia deserunt mollit anim
|
||||
12 id est laborum.
|
||||
These are my file descriptors.
|
||||
fd 0: name script isdir 0 size 132 dev file
|
||||
fd 1: name <pipe> isdir 0 size 32 dev pipe
|
||||
fd 3: name <pipe> isdir 0 size 32 dev pipe
|
||||
This is the end of the script.
|
||||
Reference in New Issue
Block a user