forked from gtowne/CS552-ramdisk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ramdisk_lib.c
164 lines (109 loc) · 3.04 KB
/
ramdisk_lib.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
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
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
/*
_____ ______ _
|_ _| | ___ \ | |
| | ___ __ _ _ __ ___ | |_/ /__ _ _ __ | |_ ___ _ __
| |/ _ \/ _` | '_ ` _ \ | // _` | '_ \| __|/ _ \| '__|
| | __/ (_| | | | | | | | |\ \ (_| | |_) | |_| (_) | |
\_/\___|\__,_|_| |_| |_| \_| \_\__,_| .__/ \__|\___/|_|
| |
|_|
Luis Carrasco, Diane Theriault, Gordon Towne
Ramdisk - Project 3 - CS552
ramdisk_lib.c
user level library to interface with RAM disk
*/
#include "ramdisk_lib.h"
int ioctl_fd;
/*
* @TODO: Pass back appropriate return values
*/
int rd_creat (char *pathname) {
struct pathname_args_t args;
if (!ioctl_fd)
ioctl_fd = open (PROC_ENTRY, O_RDONLY);
args.pathname = pathname;
args.str_len = strlen(pathname) + 1;
ioctl (ioctl_fd, RD_CREAT, &args);
return args.ret_val;
}
int rd_mkdir (char *pathname) {
struct pathname_args_t args;
if (!ioctl_fd)
ioctl_fd = open (PROC_ENTRY, O_RDONLY);
args.pathname = pathname;
args.str_len = strlen(pathname) + 1;
ioctl (ioctl_fd, RD_MKDIR, &args);
return args.ret_val;
}
int rd_open (char *pathname) {
struct pathname_args_t args;
if (!ioctl_fd)
ioctl_fd = open (PROC_ENTRY, O_RDONLY);
args.pathname = pathname;
args.str_len = strlen(pathname) + 1;
ioctl (ioctl_fd, RD_OPEN, &args);
return args.ret_val;
}
int rd_close (int fd) {
struct close_args_t args;
if (!ioctl_fd)
ioctl_fd = open (PROC_ENTRY, O_RDONLY);
args.fd = fd;
ioctl (ioctl_fd, RD_CLOSE, &args);
return args.ret_val;
}
int rd_read (int fd, char* address, int num_bytes) {
struct read_write_args_t args;
if (!ioctl_fd)
ioctl_fd = open (PROC_ENTRY, O_RDONLY);
args.fd = fd;
args.address = address;
args.num_bytes = num_bytes;
ioctl (ioctl_fd, RD_READ, &args);
return args.ret_val;
}
int rd_write (int fd, char* address, int num_bytes) {
struct read_write_args_t args;
if (!ioctl_fd)
ioctl_fd = open (PROC_ENTRY, O_RDONLY);
args.fd = fd;
args.address = address;
args.num_bytes = num_bytes;
ioctl (ioctl_fd, RD_WRITE, &args);
return args.ret_val;
}
int rd_seek (int fd, int offset) {
struct seek_args_t args;
if (!ioctl_fd)
ioctl_fd = open (PROC_ENTRY, O_RDONLY);
args.fd = fd;
args.offset = offset;
ioctl (ioctl_fd, RD_SEEK, &args);
return args.ret_val;
}
int rd_unlink (char *pathname) {
struct pathname_args_t args;
if (!ioctl_fd)
ioctl_fd = open (PROC_ENTRY, O_RDONLY);
args.pathname = pathname;
args.str_len = strlen(pathname) + 1;
ioctl (ioctl_fd, RD_UNLINK, &args);
return args.ret_val;
}
int rd_readdir (int fd, char *address) {
struct read_write_args_t args;
if (!ioctl_fd)
ioctl_fd = open (PROC_ENTRY, O_RDONLY);
args.fd = fd;
args.address = address;
ioctl (ioctl_fd, RD_READDIR, &args);
return args.ret_val;
}
int main() {
char a = 'a';
rd_read(3, &a, 12);
rd_close(10);
rd_write(5, &a, 10);
rd_seek(6, 14);
rd_readdir(12, &a);
}