3 #include <inc/string.h>
9 strecmp(char *a
, char *b
)
17 static char *msg
= "This is the NEW message of the day!\n\n";
28 if ((r
= sys_page_alloc(0, (void*) PGSIZE
, PTE_P
|PTE_U
|PTE_W
)) < 0)
29 panic("sys_page_alloc: %e", r
);
30 bits
= (uint32_t*) PGSIZE
;
31 memmove(bits
, bitmap
, PGSIZE
);
33 if ((r
= alloc_block()) < 0)
34 panic("alloc_block: %e", r
);
35 // check that block was free
36 assert(bits
[r
/32] & (1 << (r
%32)));
37 // and is not free any more
38 assert(!(bitmap
[r
/32] & (1 << (r
%32))));
39 cprintf("alloc_block is good\n");
41 if ((r
= file_open("/not-found", &f
)) < 0 && r
!= -E_NOT_FOUND
)
42 panic("file_open /not-found: %e", r
);
44 panic("file_open /not-found succeeded!");
45 if ((r
= file_open("/newmotd", &f
)) < 0)
46 panic("file_open /newmotd: %e", r
);
47 cprintf("file_open is good\n");
49 if ((r
= file_get_block(f
, 0, &blk
)) < 0)
50 panic("file_get_block: %e", r
);
51 if (strecmp(blk
, msg
) != 0)
52 panic("file_get_block returned wrong data");
53 cprintf("file_get_block is good\n");
55 *(volatile char*)blk
= *(volatile char*)blk
;
56 assert((vpt
[VPN(blk
)] & PTE_D
));
58 assert(!(vpt
[VPN(blk
)] & PTE_D
));
59 cprintf("file_flush is good\n");
61 if ((r
= file_set_size(f
, 0)) < 0)
62 panic("file_set_size: %e", r
);
63 assert(f
->f_direct
[0] == 0);
64 assert(!(vpt
[VPN(f
)] & PTE_D
));
65 cprintf("file_truncate is good\n");
67 if ((r
= file_set_size(f
, strlen(msg
))) < 0)
68 panic("file_set_size 2: %e", r
);
69 assert(!(vpt
[VPN(f
)] & PTE_D
));
70 if ((r
= file_get_block(f
, 0, &blk
)) < 0)
71 panic("file_get_block 2: %e", r
);
73 assert((vpt
[VPN(blk
)] & PTE_D
));
75 assert(!(vpt
[VPN(blk
)] & PTE_D
));
77 assert(!(vpt
[VPN(f
)] & PTE_D
));
78 cprintf("file rewrite is good\n");