-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathufs_test.c
More file actions
118 lines (86 loc) · 3.27 KB
/
ufs_test.c
File metadata and controls
118 lines (86 loc) · 3.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// Created by barak on 14/06/2022.
//
#include <stdio.h>
#include "stdlib.h"
#include "ufs.h"
#include "fcntl.h"
int main() {
/** make new filesystem, open 2 files that do not exist with flag - O_CREAT
* and share the same directory that also do not exist with flag - O_CREAT
* the goal is to test if program manage to open a new file/directory when its not exist in the file system
*
* after open these files, we write to the first file ("Hello world") and check the following steps:
* check if the pointer is in the right place, expected -> 11.
* use lseek to bring the pointer to the start expected -> 0.
* read the the first 5 chars of this opened file, expected -> "Hello"
*
* closing the opened files
* saving the current filesystem changes to a desire location (int this case, the same location, for override check)
* destroying the filesystem using @destroy_mkmfs, to free all alocated memory in the program
* */
mymkfs(10000);
int ok = myopen("root/hello/OKOKOK", O_CREAT);
int sababa = myopen("root/hello/SABABA", O_CREAT);
char write_text[1024];
strcpy(write_text, "Hello World");
// printf("size of write text is -> %d\n", strlen(write_text));
int pointer = mywrite(ok, write_text, strlen(write_text));
if (pointer == 11) {
printf("~~~~~~~~~~ pointer-test Passed\n");
} else {
printf("~~~~~~~~~~ pointer-test Failed !!\n");
}
printf("curr pointer -> %d\n", pointer);
int pos = mylseek(ok, 0, SEEK_SET);
if (pos == 0) {
printf("~~~~~~~~~~ pointer-test Passed\n");
} else {
printf("~~~~~~~~~~ pointer-test Failed !!\n");
}
char read_text[1024];
myread(ok, read_text, 5);
if (!strcmp(read_text, "Hello")) {
printf("~~~~~~~~~~ read-test Passed\n");
} else {
printf("~~~~~~~~~~ read-test Failed !!,\n ex -> Hello | actual -> %s\n", read_text);
}
myclose(ok);
myclose(sababa);
print_fs();
save("my_file.txt");
destroy_mkfs();
/** load the previous saved file system and then try the methods.*/
mymount(NULL, "my_file.txt", NULL, NULL, NULL);
ok = myopen("root/hello/OKOKOK", O_CREAT);
sababa = myopen("root/hello/SABABA", O_CREAT);
memset(write_text, 0, strlen(write_text));
strcpy(write_text, "Hello World");
printf("size of write text is -> %ld\n", strlen(write_text));
pointer = mywrite(ok, write_text, strlen(write_text));
if (pointer == 11) {
printf("~~~~~~~~~~ pointer-test Passed\n");
} else {
printf("~~~~~~~~~~ pointer-test Failed !!\n");
}
printf("curr pointer -> %d\n", pointer);
pos = mylseek(ok, 0, SEEK_SET);
if (pos == 0) {
printf("~~~~~~~~~~ pointer-test Passed\n");
} else {
printf("~~~~~~~~~~ pointer-test Failed !!\n");
}
memset(read_text, 0, strlen(read_text));
int nunbytes = myread(ok, read_text, 5);
if (!strcmp(read_text, "Hello")) {
printf("~~~~~~~~~~~~~~~ read-test Passed\n");
} else {
printf("~~~~~~~~~~ read-test Failed !!,\n ex -> Hello | actual -> %s\n", read_text);
}
myclose(ok);
myclose(sababa);
print_fs();
save("my_file.txt");
destroy_mkfs();
return 0;
};