summaryrefslogtreecommitdiff
path: root/user/bigfile.c
diff options
context:
space:
mode:
authorSanjit Bhat <[email protected]>2023-10-30 14:39:45 -0500
committerSanjit Bhat <[email protected]>2023-10-30 14:39:45 -0500
commit5464552a43916f6336787bafd1149ce2aa30f6af (patch)
treed2310242409742778c059cc60869849debf038d8 /user/bigfile.c
parent74c1eba516fdb0ec1a17b16be7e76613ccba92bf (diff)
downloadxv6-labs-5464552a43916f6336787bafd1149ce2aa30f6af.tar.gz
xv6-labs-5464552a43916f6336787bafd1149ce2aa30f6af.tar.bz2
xv6-labs-5464552a43916f6336787bafd1149ce2aa30f6af.zip
fs: release lab
Diffstat (limited to 'user/bigfile.c')
-rw-r--r--user/bigfile.c58
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);
+}