diff options
author | Mole Shang <[email protected]> | 2024-02-19 14:10:32 +0800 |
---|---|---|
committer | Mole Shang <[email protected]> | 2024-02-19 14:36:21 +0800 |
commit | d86118fc80267649b4791c8c0c72ebd60edf1ef2 (patch) | |
tree | b792b617b4df80a5803a9c1164d0e3fdfe9cfe31 /user/bigfile.c | |
parent | b20ef9d0210fd7d9403acde1857eed1b9880c0b2 (diff) | |
parent | 0cf897cbe05fd8485162619db4244f4159d0eb52 (diff) | |
download | xv6-labs-d86118fc80267649b4791c8c0c72ebd60edf1ef2.tar.gz xv6-labs-d86118fc80267649b4791c8c0c72ebd60edf1ef2.tar.bz2 xv6-labs-d86118fc80267649b4791c8c0c72ebd60edf1ef2.zip |
Merge branch 'fs' into mmap
Conflicts:
.gitignore
Makefile
conf/lab.mk
kernel/defs.h
user/user.h
Diffstat (limited to 'user/bigfile.c')
-rw-r--r-- | user/bigfile.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/user/bigfile.c b/user/bigfile.c new file mode 100644 index 0000000..0755700 --- /dev/null +++ b/user/bigfile.c @@ -0,0 +1,58 @@ +#include "kernel/types.h" +#include "kernel/stat.h" +#include "user/user.h" +#include "kernel/fcntl.h" +#include "kernel/fs.h" + +int +main() +{ + char buf[BSIZE]; + int fd, i, blocks; + + fd = open("big.file", O_CREATE | O_WRONLY); + if(fd < 0){ + printf("bigfile: cannot open big.file for writing\n"); + exit(-1); + } + + blocks = 0; + while(1){ + *(int*)buf = blocks; + int cc = write(fd, buf, sizeof(buf)); + if(cc <= 0) + break; + blocks++; + if (blocks % 100 == 0) + printf("."); + } + + printf("\nwrote %d blocks\n", blocks); + if(blocks != 65803) { + printf("bigfile: file is too small\n"); + exit(-1); + } + + close(fd); + fd = open("big.file", O_RDONLY); + if(fd < 0){ + printf("bigfile: cannot re-open big.file for reading\n"); + exit(-1); + } + for(i = 0; i < blocks; i++){ + int cc = read(fd, buf, sizeof(buf)); + if(cc <= 0){ + printf("bigfile: read error at block %d\n", i); + exit(-1); + } + if(*(int*)buf != i){ + printf("bigfile: read the wrong data (%d) for block %d\n", + *(int*)buf, i); + exit(-1); + } + } + + printf("bigfile done; ok\n"); + + exit(0); +} |