-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_example_1.c
56 lines (42 loc) · 1.34 KB
/
client_example_1.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
#include <stdio.h>
#include "udp.h"
#include "mfs.h"
// client code
int main(int argc, char *argv[])
{
char *hostname = "localhost";
int port = client_port;
int fd = MFS_Init(hostname, port);
if (fd == -1)
{
return 0;
}
char buffer[SIZE_BLOCK];
MFS_Creat(0, MFS_DIRECTORY, "myDir");
int inum = MFS_Lookup(0, "myDir");
MFS_Stat_t m;
MFS_Stat(inum, &m);
printf("Stat ==============> type %d, size %d\n", m.type, m.size);
MFS_Creat(inum, MFS_REGULAR_FILE, "myFile");
int fileInum = MFS_Lookup(inum, "myFile");
printf("myFile inum : %d\n", fileInum);
MFS_Write(fileInum, "myFile content block 0", 0);
MFS_Write(fileInum, "myFile content block 1", 1);
MFS_Write(fileInum, "myFile content block 4", 4);
MFS_Read(fileInum, buffer, 0);
printf("myFile content block 0 : %s\n", buffer);
MFS_Read(fileInum, buffer, 1);
printf("myFile content block 1 : %s\n", buffer);
MFS_Read(fileInum, buffer, 4);
printf("myFile content block 4 : %s\n", buffer);
inum = MFS_Lookup(0, "myDir");
int pinum = MFS_Lookup(inum, "..");
MFS_Unlink(pinum, "myDir");
fileInum = MFS_Lookup(inum, "myFile");
printf("myFile inum : %d\n", fileInum);
MFS_Unlink(inum, "myFile");
MFS_Unlink(pinum, "myDir");
MFS_Shutdown();
// UDP_Close(fd);
return 0;
}