-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.c
71 lines (61 loc) · 1.62 KB
/
app.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 <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "simplefs.h"
int main(int argc, char **argv) {
int ret;
int fd1, fd2, fd;
int i;
char c;
char buffer[1024];
char buffer2[8] = {50, 50, 50, 50, 50, 50, 50, 50};
int size;
char vdiskname[200];
printf ("started\n");
if (argc != 2) {
printf ("usage: app <vdiskname>\n");
exit(0);
}
strcpy (vdiskname, argv[1]);
ret = sfs_mount (vdiskname);
if (ret != 0) {
printf ("could not mount \n");
exit (1);
}
printf ("creating files\n");
sfs_create ("file1.bin");
sfs_create ("file2.bin");
sfs_create ("file3.bin");
fd1 = sfs_open ("file1.bin", MODE_APPEND);
fd2 = sfs_open ("file2.bin", MODE_APPEND);
for (i = 0; i < 10000; ++i) {
buffer[0] = (char) 65;
sfs_append (fd1, (void *) buffer, 1);
}
for (i = 0; i < 10000; ++i) {
buffer[0] = (char) 65;
buffer[1] = (char) 66;
buffer[2] = (char) 67;
buffer[3] = (char) 68;
sfs_append(fd2, (void *) buffer, 4);
}
sfs_close(fd1);
sfs_close(fd2);
fd = sfs_open("file3.bin", MODE_APPEND);
for (i = 0; i < 10000; ++i) {
memcpy (buffer, buffer2, 8); // just to show memcpy
sfs_append(fd, (void *) buffer, 8);
}
sfs_close (fd);
fd = sfs_open("file3.bin", MODE_READ);
size = sfs_getsize (fd);
for (i = 0; i < size; ++i) {
sfs_read (fd, (void *) buffer, 1);
c = (char) buffer[0];
c = c + 1;
}
sfs_delete("file3.bin");
sfs_close (fd);
ret = sfs_umount();
}