-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtest_dir.c
More file actions
147 lines (118 loc) · 3.29 KB
/
Copy pathtest_dir.c
File metadata and controls
147 lines (118 loc) · 3.29 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#include <dolphinfs.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
void test_fs_dir(char *device)
{
printf("\n############ test fs dir on device: %s\n", device);
struct super_block dolphin_sb;
int ret;
/* 挂载文件系统 */
if (dolphin_mount(device, &dolphin_sb)) {
/* 创建文件系统 */
dolphin_mkfs(device, &dolphin_sb);
/* 再次挂载 */
if (dolphin_mount(device, &dolphin_sb)) {
printf("mount dolphinfs failed!\n");
return -1;
}
}
ret = create_dir(&dolphin_sb, "/");
if (ret)
{
printf("create root dir failed!\n");
}
ret = create_dir(&dolphin_sb, "/");
if (ret)
{
printf("create root dir failed!\n");
}
ret = create_dir(&dolphin_sb, "/abc");
if (ret)
{
printf("create root dir failed!\n");
}
ret = create_dir(&dolphin_sb, "/abc");
if (ret)
{
printf("create root dir failed!\n");
}
ret = create_dir(&dolphin_sb, "/123");
if (ret)
{
printf("create root dir failed!\n");
}
ret = create_dir(&dolphin_sb, "/123");
if (ret)
{
printf("create root dir failed!\n");
}
ret = create_dir(&dolphin_sb, "/xyz");
if (ret)
{
printf("create root dir failed!\n");
}
ret = create_dir(&dolphin_sb, "/abc/def");
if (ret)
{
printf("create root dir failed!\n");
}
ret = create_dir(&dolphin_sb, "/abc/def");
if (ret)
{
printf("create root dir failed!\n");
}
new_file(&dolphin_sb, "/abc/111", FF_RDWR);
new_file(&dolphin_sb, "/abc", FF_RDWR);
new_file(&dolphin_sb, "/456", FF_RDWR);
list_dir(&dolphin_sb, "/");
list_dir(&dolphin_sb, "/abc");
list_files(&dolphin_sb);
ret = delete_dir(&dolphin_sb, "/");
printf("del dir %d\n", ret);
ret = delete_dir(&dolphin_sb, "/abc");
printf("del dir %d\n", ret);
ret = delete_dir(&dolphin_sb, "/123");
printf("del dir %d\n", ret);
ret = delete_dir(&dolphin_sb, "/xyz");
printf("del dir %d\n", ret);
ret = delete_dir(&dolphin_sb, "/qwer");
printf("del dir %d\n", ret);
ret = delete_dir(&dolphin_sb, "/abc/def");
printf("del dir %d\n", ret);
ret = delete_dir(&dolphin_sb, "/abc");
printf("del dir %d\n", ret);
ret = delete_dir(&dolphin_sb, "/123");
printf("del dir %d\n", ret);
ret = delete_dir(&dolphin_sb, "/xyz");
printf("del dir %d\n", ret);
ret = delete_dir(&dolphin_sb, "/abc/def");
printf("del dir %d\n", ret);
ret = del_file(&dolphin_sb, "/abc/111");
printf("del file %d\n", ret);
int fd = open_file(&dolphin_sb, "/456", FF_RDWR);
if (fd >= 0) {
printf("write %d\n", write_file(fd, "hello", 5));
seek_file(fd, 0, FP_SET);
char buf[32] = {0};
printf("read %d\n", read_file(fd, buf, 5));
printf("read data %s\n", buf);
close_file(fd);
}
ret = delete_dir(&dolphin_sb, "/abc");
printf("del dir %d\n", ret);
/* umount fs */
dolphin_unmount(&dolphin_sb);
}
#define TEST_RAM_DEV "ram"
#define TEST_DISK_DEV "disk"
int cmd_test_dir(void)
{
/* init disk */
dolphin_init();
test_fs_dir(TEST_RAM_DEV);
test_fs_dir(TEST_DISK_DEV);
dolphin_exit();
return 0;
}