-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxattrfs.c
115 lines (107 loc) · 3.18 KB
/
xattrfs.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
#include <limits.h>
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <strings.h>
#include <fuse.h>
#include "callbacks.h"
enum {
KEY_HELP
};
static struct fuse_opt xattrfs_opts[] = {
FUSE_OPT_KEY("-h", KEY_HELP),
FUSE_OPT_KEY("--help", KEY_HELP),
FUSE_OPT_END
};
struct fuse_operations callback_operations = {
.getattr = getattr_cb,
.readlink = readlink_cb,
// .getdir is depricated,
.mknod = mknod_cb,
.mkdir = mkdir_cb,
.unlink = unlink_cb,
.rmdir = rmdir_cb,
.symlink = symlink_cb,
.rename = rename_cb,
.link = link_cb,
.chmod = chmod_cb,
.chown = chown_cb,
.truncate = truncate_cb,
.utimens = utimens_cb,
.open = open_cb,
.read = read_cb,
.write = write_cb,
.statfs = statfs_cb,
.flush = flush_cb,
.release = release_cb,
.fsync = fsync_cb,
.setxattr = setxattr_cb,
.getxattr = getxattr_cb,
.listxattr = listxattr_cb,
.removexattr = removexattr_cb,
.opendir = opendir_cb,
.readdir = readdir_cb,
.releasedir = releasedir_cb,
.access = access_cb,
.init = init_cb,
.destroy = destroy_cb
};
static int xattrfs_parse_opt(void *data, const char *arg, int key,
struct fuse_args *outargs)
{
switch(key) {
case FUSE_OPT_KEY_OPT:
return 1;
case FUSE_OPT_KEY_NONOPT:
// 1st non-fuse arg is the source dir
if (source_dir[0] == '\0') {
// get the absolute path of the source dir
if (realpath(arg, source_dir) == NULL) {
perror("mount failed");
exit(1);
}
else { // ok
return 0;
}
}
else
{ // this is the mountpoint, nothing to do here
return 1;
}
case KEY_HELP:
fprintf(stdout,
"Utility for adding extended file attributes(xattr) support for any file system\n"
"without this feature. Utility bind any directory to a new mountpoint. xattr data\n"
"stores in hidden file\n"
"Usage:\nxattrfs source_dir mountpoint [-o FUSE arguments]\n"
"See list of FUSE arguments in general mount options section of 'man mount.fuse'\n"
"Example:\n"
"xattrfs /src /dest -o allow_other\n");
exit(0);
default:
fprintf(stderr, "Unknown argument %s\n", outargs->argv[0]);
exit(1);
}
return 1;
}
int main(int argc, char *argv[]) {
struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
int res;
// do not limit our permission bits
umask(0);
res = fuse_opt_parse(&args, &source_dir, xattrfs_opts, xattrfs_parse_opt);
if(res != 0) {
fprintf(stderr, "Invalid arguments\n");
exit(1);
}
if(source_dir == NULL) {
fprintf(stderr, "Missing source_dir\n");
exit(1);
}
if(source_dir[strlen(source_dir) - 1] == '/') {
source_dir[strlen(source_dir) - 1] = 0;
}
fuse_main(args.argc, args.argv, &callback_operations, NULL);
return 0;
}