79#define FUSE_USE_VERSION 34
94#define MAX_STR_LEN 128
95static char file_name[MAX_STR_LEN];
97static int lookup_cnt = 0;
98static pthread_t main_thread;
107static struct options options = {
110 .update_interval = 1,
114#define OPTION(t, p) \
115 { t, offsetof(struct options, p), 1 }
116static const struct fuse_opt option_spec[] = {
117 OPTION(
"--no-notify", no_notify),
118 OPTION(
"--update-interval=%d", update_interval),
119 OPTION(
"--timeout=%f", timeout),
120 OPTION(
"--only-expire", only_expire),
124static int tfs_stat(
fuse_ino_t ino,
struct stat *stbuf) {
127 stbuf->st_mode = S_IFDIR | 0755;
131 else if (ino == file_ino) {
132 stbuf->st_mode = S_IFREG | 0000;
146 memset(&e, 0,
sizeof(e));
150 else if (strcmp(name, file_name) == 0) {
156 e.attr_timeout = options.timeout;
157 e.entry_timeout = options.timeout;
158 if (tfs_stat(e.ino, &e.attr) != 0)
171 lookup_cnt -= nlookup;
183 memset(&stbuf, 0,
sizeof(stbuf));
184 if (tfs_stat(ino, &stbuf) != 0)
195static void dirbuf_add(
fuse_req_t req,
struct dirbuf *b,
const char *name,
198 size_t oldsize = b->size;
200 b->p = (
char *) realloc(b->p, b->size);
201 memset(&stbuf, 0,
sizeof(stbuf));
207#define min(x, y) ((x) < (y) ? (x) : (y))
209static int reply_buf_limited(
fuse_req_t req,
const char *buf,
size_t bufsize,
210 off_t off,
size_t maxsize) {
213 min(bufsize - off, maxsize));
227 memset(&b, 0,
sizeof(b));
228 dirbuf_add(req, &b, file_name, file_ino);
229 reply_buf_limited(req, b.p, b.size, off, size);
236 .getattr = tfs_getattr,
237 .readdir = tfs_readdir,
238 .forget = tfs_forget,
241static void update_fs(
void) {
250 ret = strftime(file_name, MAX_STR_LEN,
251 "Time_is_%Hh_%Mm_%Ss", now);
255static void* update_fs_loop(
void *data) {
256 struct fuse_session *se = (
struct fuse_session*) data;
261 old_name = strdup(file_name);
264 if (!options.no_notify && lookup_cnt) {
265 if(options.only_expire) {
270 if (ret == -ENOSYS) {
271 printf(
"fuse_lowlevel_notify_expire_entry not supported by kernel\n");
272 printf(
"Exiting...\n");
276 pthread_kill(main_thread, SIGPIPE);
283 assert(ret == 0 || ret == -ENOENT);
290 sleep(options.update_interval);
295static void show_help(
const char *progname)
297 printf(
"usage: %s [options] <mountpoint>\n\n", progname);
298 printf(
"File-system specific options:\n"
299 " --timeout=<secs> Timeout for kernel caches\n"
300 " --update-interval=<secs> Update-rate of file system contents\n"
301 " --no-notify Disable kernel notifications\n"
302 " --only-expire Expire entries instead of invalidating them\n"
306int main(
int argc,
char *argv[]) {
308 struct fuse_session *se;
317 if (fuse_parse_cmdline(&args, &opts) != 0)
319 if (opts.show_help) {
325 }
else if (opts.show_version) {
336 sizeof(tfs_oper), &se);
351 main_thread = pthread_self();
354 ret = pthread_create(&updater, NULL, update_fs_loop, (
void *)se);
356 fprintf(stderr,
"pthread_create failed with %s\n",
362 if (opts.singlethread) {
365 config.clone_fd = opts.clone_fd;
366 config.max_idle_threads = opts.max_idle_threads;
367 ret = fuse_session_loop_mt(se, &config);
376 free(opts.mountpoint);
int fuse_set_signal_handlers(struct fuse_session *se)
const char * fuse_pkgversion(void)
void fuse_remove_signal_handlers(struct fuse_session *se)
int fuse_daemonize(int foreground)
void fuse_session_destroy(struct fuse_session *se)
void fuse_session_exit(struct fuse_session *se)
int fuse_reply_err(fuse_req_t req, int err)
int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size)
struct fuse_req * fuse_req_t
int fuse_session_exited(struct fuse_session *se)
int fuse_session_loop(struct fuse_session *se)
int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
void fuse_session_unmount(struct fuse_session *se)
void fuse_cmdline_help(void)
struct fuse_session * fuse_session_new(struct fuse_args *args, const struct fuse_lowlevel_ops *op, size_t op_size, void *userdata)
void fuse_reply_none(fuse_req_t req)
int fuse_lowlevel_notify_expire_entry(struct fuse_session *se, fuse_ino_t parent, const char *name, size_t namelen)
void fuse_lowlevel_help(void)
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
int fuse_lowlevel_notify_inval_entry(struct fuse_session *se, fuse_ino_t parent, const char *name, size_t namelen)
void fuse_lowlevel_version(void)
size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize, const char *name, const struct stat *stbuf, off_t off)
int fuse_reply_attr(fuse_req_t req, const struct stat *attr, double attr_timeout)
void fuse_opt_free_args(struct fuse_args *args)
int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc)
#define FUSE_ARGS_INIT(argc, argv)
void(* lookup)(fuse_req_t req, fuse_ino_t parent, const char *name)