-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathptfs_main.cc
53 lines (41 loc) · 1.23 KB
/
ptfs_main.cc
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
#define FUSE_USE_VERSION 35
#include "ptfs.h"
#include <fuse.h>
#include <stddef.h>
#include <syslog.h>
#include <iostream>
#include "update_rlimit.h"
using std::cerr;
using std::cout;
using std::endl;
struct ptfs_config {
char* underlying_path{nullptr};
};
#define MYFS_OPT(t, p, v) \
{ t, offsetof(ptfs_config, p), v }
static struct fuse_opt ptfs_opts[] = {
MYFS_OPT("--underlying_path=%s", underlying_path, 0), FUSE_OPT_END};
#undef MYFS_OPT
int main(int argc, char** argv) {
openlog("ptfs", LOG_PERROR | LOG_PID, LOG_USER);
UpdateRlimit(); // We need more than 1024 files open.
umask(0);
struct fuse_operations o = {};
ptfs::FillFuseOperations<ptfs::PtfsHandler>(&o);
fuse_args args = FUSE_ARGS_INIT(argc, argv);
ptfs_config conf{};
fuse_opt_parse(&args, &conf, ptfs_opts, nullptr);
if (!conf.underlying_path) {
cerr << argv[0] << " [mountpoint] --underlying_path=" << endl;
return EXIT_FAILURE;
}
ptfs::PtfsHandler::premount_dirfd_ =
open(conf.underlying_path, O_PATH | O_DIRECTORY);
if (-1 == ptfs::PtfsHandler::premount_dirfd_) {
perror("open underlying_path");
return EXIT_FAILURE;
}
int ret = fuse_main(args.argc, args.argv, &o, nullptr);
fuse_opt_free_args(&args);
return ret;
}