-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcgrpfs_main_puffs.c
119 lines (99 loc) · 2.62 KB
/
cgrpfs_main_puffs.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
#define _KERNTYPES
#include <sys/types.h>
#include <puffs.h>
/* these must come first */
#include <sys/event.h>
#include <assert.h>
#include <err.h>
#include <errno.h>
#include <getopt.h>
#include <mntopts.h>
#include <paths.h>
#include <stdlib.h>
#include "cgrpfs.h"
cgmgr_t cgmgr;
static struct puffs_usermount *pu;
static void
usage()
{
errx(EXIT_FAILURE, "usage: %s [-o mntopt] [-o puffsopt] /mountpoint",
getprogname());
}
int
main(int argc, char *argv[])
{
extern char *optarg;
extern int optind;
struct puffs_pathobj *po_root;
struct puffs_ops *pops;
struct timespec ts;
const char *typename;
char *rtstr;
mntoptparse_t mp;
int pflags = 0, detach = 0, mntflags = 0;
int ch;
while ((ch = getopt(argc, argv, "do:")) != -1) {
switch (ch) {
case 'd':
pflags |= PUFFS_FLAG_OPDUMP;
break;
case 'o':
mp = getmntopts(optarg, puffsmopts, &mntflags, &pflags);
if (mp == NULL)
err(1, "getmntopts");
freemntopts(mp);
break;
default:
usage();
}
}
argc -= optind;
argv += optind;
if (argc != 1)
usage();
puffs_unmountonsignal(SIGINT, 1);
cgmgr_init();
PUFFSOP_INIT(pops);
puffs_null_setops(pops);
PUFFSOP_SETFSNOP(pops, sync);
PUFFSOP_SETFSNOP(pops, statvfs);
PUFFSOP_SET(pops, cgrpfs, node, lookup);
PUFFSOP_SET(pops, cgrpfs, node, open);
PUFFSOP_SET(pops, cgrpfs, node, open2);
PUFFSOP_SET(pops, cgrpfs, node, mkdir);
PUFFSOP_SET(pops, cgrpfs, node, rmdir);
PUFFSOP_SET(pops, cgrpfs, node, access);
PUFFSOP_SET(pops, cgrpfs, node, getattr);
PUFFSOP_SET(pops, cgrpfs, node, setattr);
PUFFSOP_SET(pops, cgrpfs, node, poll);
PUFFSOP_SET(pops, cgrpfs, node, readdir);
PUFFSOP_SET(pops, cgrpfs, node, rename);
PUFFSOP_SET(pops, cgrpfs, node, read);
PUFFSOP_SET(pops, cgrpfs, node, write);
PUFFSOP_SET(pops, cgrpfs, node, inactive);
PUFFSOP_SET(pops, cgrpfs, node, reclaim);
if ((pu = puffs_init(pops, _PATH_PUFFS, "cgrpfs", NULL, pflags)) ==
NULL)
err(1, "init");
/*
* The framebuf interface is useless to us as it tries to add a write
* event filter, which doesn't work on kernel queues.
* We could maybe have a separate thread wait for the KQ FD to become
* ready then sent a byte along a pipe instead, but that can be done
* another time.
*/
#if 0
puffs_framev_init(pu, kq_fdread_fn, NULL, NULL, NULL, NULL);
if (puffs_framev_addfd(pu, cgmgr.kq, PUFFS_FBIO_READ) < 0)
err(1, "framebuf addfd kq");
#endif
puffs_set_errnotify(pu, puffs_kernerr_abort);
if (detach)
if (puffs_daemon(pu, 1, 1) == -1)
err(1, "puffs_daemon");
if (puffs_mount(pu, *argv, mntflags, cgmgr.rootnode) == -1)
err(1, "mount");
if (puffs_mainloop(pu) == -1)
err(1, "mainloop");
return 0;
}