-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdriver.cpp
81 lines (63 loc) · 2.3 KB
/
driver.cpp
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
#include <iostream>
#include <sys/types.h>
#include <sys/xattr.h>
#include <cstdio>
#include <string.h>
#include <cmath>
//just some text cases I was using.
const int BUFFER_SIZE = 5000;
using namespace std;
int main (void)
{
off_t* value=new off_t;
*value=0x4F; //address of the end of filea.txt
setxattr("./CompFile1.cmp","user.filea.txt",value,1,0);
*value=0x117; //likewise
setxattr("CompFile1.cmp","user.fileb.txt",value,2,0);
*value=0x24F; //etc
setxattr("CompFile1.cmp","user.filec.txt",value,2,0);
*value=0x2BB;
setxattr("CompFile1.cmp","user.filed",value,2,0);
//I meant for filed not to be a text file
//it's just random binary
// *value=(int)pow(0xFF+1,sizeof(off_t))-1;
*value=-1;
setxattr("CompFile1.cmp","user.directorya",value,sizeof(off_t),0);
*value=0x00;
setxattr("CompFile1.cmp","user.directorya/file.txt",value,2,0);
*value=0x00;
setxattr("CompFile1.cmp","user.directorya/directoryb.txt",value,2,0);
getxattr("./CompFile1.cmp","user.directorya",value,sizeof(off_t));
printf("%li\n",*value);
*value=0x32F;
setxattr("./CompFile2.cmp","user.file1.txt",value,2,0);
*value=0x383;
setxattr("./CompFile2.cmp","user.file2.txt",value,2,0);
*value=0x00;
/* getxattr("./CompFile1.cmp","user.filea.txt",value,sizeof(off_t));
printf("%li\n",*value);
getxattr("CompFile1.cmp","user.fileb.txt",value,sizeof(off_t));
printf("%li\n",*value);
getxattr("CompFile1.cmp","user.filec.txt",value,sizeof(off_t));
printf("%li\n",*value);
getxattr("CompFile1.cmp","user.filed",value,sizeof(off_t));
printf("%li\n",*value);
*/
delete(value);
char buffer[BUFFER_SIZE];
char name[20], val[20]; //Should also be re-write in const variable format to achieve better global control
int length = listxattr("CompFile1.cmp", buffer, BUFFER_SIZE); //Add some error check here
//Now the buffer contains a list of attribute names, separated by a single empty character '/0'
cout<<"length="<<length<<endl; //Length is the length of the attribute name list
// if succeed, break it to each attribute
/* int pos = 0;
for (int i = 0; i < length; i++) {
name[pos++] = buffer[i];
if (buffer[i] == '\0') {
pos = 0; //Set to zero, so following chacters will be stored in another name, overridding
cout<<name<<endl; //Add getxattr function to get the value to the corresponding name
}
}
*/
return 0;
}