-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrmdirTest2.c
71 lines (57 loc) · 1.9 KB
/
rmdirTest2.c
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
#include <comp421/yalnix.h>
#include <comp421/iolib.h>
#include <stdio.h>
#include <string.h>
#include <comp421/filesystem.h>
#include <stdlib.h>
/* Try tcreate2 before this, or try this just by itself */
int
main()
{
int fd;
int st;
st = MkDir("/foo");
printf("Status of mkdir is %d\n", st);
char name[50];
int j;
// Create 50 files in foo directory.
for (j = 0; j < 43; j++) {
snprintf(name, 50, "/foo/abc%i", j);
fd = Create(name);
printf("Here is fd %d\n", fd);
st = Close(fd);
printf("Status of close is %d\n", st);
}
// Read contents of "/foo" directory.
printf("Read contents of foo directory (must be non-empty)\n");
char buf2[sizeof(struct dir_entry)*52];
int fd3 = Open("foo");
printf("Here is fd %d\n", fd3);
int size_read = Read(fd3, buf2, sizeof(struct dir_entry)*52);
printf("Size that was read is %i\n", size_read);
int i;
for (i = 0; i < (int)(size_read/sizeof(struct dir_entry)); i++) {
printf("%i. Inode is %i\n", i, (((struct dir_entry *)buf2) + i)->inum);
printf("%i. Name is %s\n", i, (((struct dir_entry *)buf2) + i)->name);
}
// Sync();
// Delete 50 files in foo directory.
for (j = 0; j < 43; j++) {
snprintf(name, 50, "/foo/abc%i", j);
st = Unlink(name);
printf("Status of unlink is %d\n", st);
}
// Try to remove empty dir.
st = RmDir("/foo");
printf("Status of rmdir is %d\n", st);
fd3 = Open("foo");
printf("Here is fd %d\n", fd3);
size_read = Read(fd3, buf2, sizeof(struct dir_entry)*52);
printf("Size that was read is %i\n", size_read);
for (i = 0; i < (int)(size_read/sizeof(struct dir_entry)); i++) {
printf("%i. Inode is %i\n", i, (((struct dir_entry *)buf2) + i)->inum);
printf("%i. Name is %s\n", i, (((struct dir_entry *)buf2) + i)->name);
}
Shutdown();
return (0);
}