-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient_test2.cc
More file actions
84 lines (70 loc) · 2.08 KB
/
client_test2.cc
File metadata and controls
84 lines (70 loc) · 2.08 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
#include "commons.h"
#include "pfs.h"
#define ONEKB 1024
#define Filesize 150
int main(int argc, char *argv[])
{
int ifdes;
uint32_t fdes;
int err_value;
char input_fname[20];
char *buf;
//char *readbuf;
int cache_hit;
ssize_t nread;
string line;
struct pfs_stat mystat;
// Initialize the client
initialize(argc, argv);
cout<<"\n All initialization is done";
// the command line arguments include an input filename
if (argc < 2)
{
cout<<"usage: a.out <input filename>\n";
exit(0);
}
strcpy(input_fname, argv[1]);
ifstream file (input_fname);
//buf = new char[4*ONEKB];
FILE * fid=fopen(input_fname,"r");
buf = (char*) malloc (sizeof(char)*Filesize);
fseek(fid,4*ONEKB,SEEK_SET);
int result = fread (buf,1,Filesize,fid);
//cout<<buf;
//std::this_thread::sleep_for(std::chrono::seconds(10));
// create a file only once, say at client 1
err_value = pfs_create("pfs_file1", 3);
if(err_value < 0)
{
cout<<"Unable to create a file\n";
exit(0);
}
// All the clients open the file
fdes = pfs_open("pfs_file1", 'w');
if(fdes < 0)
{
cout<<"Error opening file\n";
exit(0);
}
//At Client 1
//Write the first 150 bytes of data from the input file onto pfs_file
err_value = pfs_write(fdes, (void *)buf, Filesize, 0, &cache_hit);
cout<<"Wrote %d bytes to the file\n", err_value;
std::this_thread::sleep_for(std::chrono::seconds(20));
/*err_value = pfs_read(fdes, (void *)buf, 50, 98, &cache_hit);
printf("Read %d bytes of data from the file\n", err_value);
cout<<buf;
err_value = pfs_read(fdes, (void *)buf, 40, 60, &cache_hit);
printf("Read %d bytes of data from the file\n", err_value);
cout<<buf;*/
//std::this_thread::sleep_for(std::chrono::seconds(120));
pfs_fstat(fdes, &mystat);
printf("File Metadata:\n");
printf("Time of creation: %s\n", ctime(&(mystat.pst_ctime)));
printf("Time of last modification: %s\n", ctime(&(mystat.pst_mtime)));
printf("File Size: %d\n", mystat.pst_size);
pfs_close(fdes);
pfs_delete("pfs_file1");
free(buf);
return 0;
}