/
main.c
177 lines (168 loc) · 3.42 KB
/
main.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
165
166
167
168
169
170
171
172
173
174
175
176
177
#define FUSE_USE_VERSION 26
#define _XOPEN_SOURCE 500
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <fuse.h>
#include <fcntl.h>
#include <stddef.h>
#include <fuse_opt.h>
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
char name1[10] = "/file";
char name2[10];
static int savefd;
char* intToChar(char* bufer, int numb);
static struct fuse_session* se;
struct mbr_data
{
int fd;
uint8_t ro;
char *filename;
// struct mbr_partition *primary;
};
static inline char* fixpath(const char* path)
{
char* fixed=(char*)calloc(strlen(path)+2,sizeof(char));
strcpy(fixed,".");
strcat(fixed,path);
return fixed;
}
static int pr_getattr(const char* path,struct stat* st_buf) //get attributes about file/directory
{
int res = 0; //temporary result
char* tmp_path;
int lenght = strlen(path) - 1;
memset(st_buf,0,sizeof(struct stat));
tmp_path = (char*)calloc(strlen(path)+1,sizeof(char));
//path = fixpath(path);
res = stat(path,st_buf);
fprintf(2,"saasd12");
return res;
}
static int pr_fgetattr(const char* path, struct stat* st_buf)
{
int res;
res = lstat(path,st_buf);
if(res == -1)
return -errno;
return 0;
}
static int pr_access(const char *path, int mask)
{
int res;
res = access(path, mask);
if (res == -1)
return -errno;
return 0;
}
static int xmp_readlink(const char *path, char *buf, size_t size)
{
int res;
res = readlink(path, buf, size - 1);
if (res == -1)
return -errno;
buf[res] = '\0';
return 0;
}
static inline DIR *get_dirp(struct fuse_file_info *fi) //return directory pointer
{
return (DIR *) (uintptr_t) fi->fh;
}
int pr_opendir(const char *path, struct fuse_file_info *fi)
{
DIR* dp;
//path = fixpath(path);
dp = opendir(path);
if(dp = NULL)
{
printf("errr");
return -errno;
}
fi->fh = (unsigned long) dp;
return 0;
}
static int pr_readdir(const char* path, void* buf, fuse_fill_dir_t filler,off_t offset,struct fuse_file_info* fi)
{
int res = 0;
struct stat st;
struct dirent* de;
DIR* dp = get_dirp(fi);
(void)path;
seekdir(dp,offset);
while((de = readdir(dp)) != NULL)
{
struct stat st;
memset(&st,0,sizeof(st));
st.st_ino = de->d_ino;
st.st_mode = de->d_type << 12;
if(filler(buf,de->d_name,&st,telldir(dp)))
break;
}
return res;
}
static struct fuse_operations pr_operations = {
.getattr = pr_getattr,
.readlink = xmp_readlink,
//.fgetattr = pr_fgetattr,
//.readdir = pr_readdir,
//.open = pr_opendir,
//.access = pr_access,
};
int main(int argc,char* argv[])
{
DIR* dp;
int ret;
umask(0);
struct fuse_args args;
//args = (const struct fuse_args) FUSE_ARGS_INIT (argc,argv);
//se = fuse_lowlevel_new (&args,&pr_operations,sizeof(pr_operations),NULL);
ret = fuse_main(argc,argv,&pr_operations,NULL);
printf("%d",ret);
return ret;
}
char* intToChar(char* bufer, int numb)
{
char tmp[20];
int buf;
int lenght = 0;
int i = 0;
int j;
if(numb >= 10)
{
do
{
buf = numb%10;
tmp[i] = buf + '0';
i++;
numb /=10;
} while (numb >= 10);
tmp[i] = numb + '0';
}else
{
tmp[i] = numb + '0';
};
lenght = i;
for (j = 0; j <= lenght; j++)
{
bufer[j] = tmp[i--];
}
bufer[j] = NULL;
return bufer;
}