-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfsdemo.cpp
More file actions
122 lines (74 loc) · 1.61 KB
/
fsdemo.cpp
File metadata and controls
122 lines (74 loc) · 1.61 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
/** @file filesystem.cpp
*
* File System demo program
*
* @author Copyright Aniesh Chawla, Sept 2006
**/
#include "includes.h"
#include "RAMDisk.h"
#include "VDisk.h"
#include "Volume.h"
#include "FS.h"
void demo_dir(FS& fs, Volume& V);
void demo_file(FS& fs, Volume& V);
int main()
{
FS fs;
RAMDisk RAM;
RAM.format(100);
Volume A("A", RAM);
demo_dir(fs, A);
demo_file(fs, A);
banner("Trying VDisk");
VDisk VDSK;
if (VDSK.format(50) != DISK_ERROR)
{
Volume B("B", VDSK);
demo_dir(fs, B);
demo_file(fs, B);
}
return 0;
}
void demo_dir(FS& fs, Volume& V)
{
banner("Creating directory foo");
fs.mkdir(V, "/", "foo");
banner("Creating directory bar within foo");
fs.mkdir(V, "/foo", "bar");
banner("Listing /");
fs.ls(V, "/");
banner("Listing /foo");
fs.ls(V, "/foo");
banner("Removing directory bar from foo");
fs.rmdir(V, "/foo", "bar");
banner("Listing /foo");
fs.ls(V, "/foo");
}
void demo_file(FS& fs, Volume& V)
{
banner("Opening abc");
int fd = fs.open(V, "/", "abc");
if (fd != DISK_ERROR)
{
char buf[15];
buf[14] = '\0';
banner("Storing text in abc");
fs.write(fd, "Hello World!", 14);
fs.seek(fd, 0);
fs.read(fd, buf, 14);
printf("text: %s\n", buf);
fs.seek(fd, 0);
fs.write(fd, "Goodbye", 7);
fs.seek(fd, 0);
fs.read(fd, buf, 14);
printf("text: %s\n", buf);
banner("Closing abc");
fs.close(fd);
banner("Listing /");
fs.ls(V, "/");
banner("Removing abc");
fs.rm(V, "/", "abc");
banner("Listing /");
fs.ls(V, "/");
}
}