79#define FUSE_USE_VERSION FUSE_MAKE_VERSION(3, 12) 
   81#include <fuse_lowlevel.h> 
   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) {
 
  126    if (ino == FUSE_ROOT_ID) {
 
  127        stbuf->st_mode = S_IFDIR | 0755;
 
  131    else if (ino == file_ino) {
 
  132        stbuf->st_mode = S_IFREG | 0000;
 
  143static void tfs_init(
void *userdata, 
struct fuse_conn_info *conn) {
 
  153    memset(&e, 0, 
sizeof(e));
 
  157    else if (strcmp(name, file_name) == 0) {
 
  163    e.attr_timeout = options.timeout;
 
  164    e.entry_timeout = options.timeout;
 
  165    if (tfs_stat(e.ino, &e.attr) != 0)
 
  178        lookup_cnt -= nlookup;
 
  190    memset(&stbuf, 0, 
sizeof(stbuf));
 
  191    if (tfs_stat(ino, &stbuf) != 0)
 
  202static void dirbuf_add(
fuse_req_t req, 
struct dirbuf *b, 
const char *name,
 
  205    size_t oldsize = b->size;
 
  207    b->p = (
char *) realloc(b->p, b->size);
 
  208    memset(&stbuf, 0, 
sizeof(stbuf));
 
  214#define min(x, y) ((x) < (y) ? (x) : (y)) 
  216static int reply_buf_limited(
fuse_req_t req, 
const char *buf, 
size_t bufsize,
 
  217                             off_t off, 
size_t maxsize) {
 
  220                              min(bufsize - off, maxsize));
 
  229    if (ino != FUSE_ROOT_ID)
 
  234        memset(&b, 0, 
sizeof(b));
 
  235        dirbuf_add(req, &b, file_name, file_ino);
 
  236        reply_buf_limited(req, b.p, b.size, off, size);
 
  243    .lookup     = tfs_lookup,
 
  244    .getattr    = tfs_getattr,
 
  245    .readdir    = tfs_readdir,
 
  246    .forget     = tfs_forget,
 
  249static void update_fs(
void) {
 
  258    ret = strftime(file_name, MAX_STR_LEN,
 
  259                   "Time_is_%Hh_%Mm_%Ss", now);
 
  263static void* update_fs_loop(
void *data) {
 
  264    struct fuse_session *se = (
struct fuse_session*) data;
 
  269        old_name = strdup(file_name);
 
  272        if (!options.no_notify && lookup_cnt) {
 
  273            if(options.only_expire) { 
 
  275                   (se, FUSE_ROOT_ID, old_name, strlen(old_name));
 
  278                if (ret == -ENOSYS) {
 
  279                    printf(
"fuse_lowlevel_notify_expire_entry not supported by kernel\n");
 
  280                    printf(
"Exiting...\n");
 
  284                    pthread_kill(main_thread, SIGPIPE);
 
  291                assert(ret == 0 || ret == -ENOENT);
 
  294                      (se, FUSE_ROOT_ID, old_name, strlen(old_name)) == 0);
 
  298        sleep(options.update_interval);
 
  303static void show_help(
const char *progname)
 
  305    printf(
"usage: %s [options] <mountpoint>\n\n", progname);
 
  306    printf(
"File-system specific options:\n" 
  307               "    --timeout=<secs>       Timeout for kernel caches\n" 
  308               "    --update-interval=<secs>  Update-rate of file system contents\n" 
  309               "    --no-notify            Disable kernel notifications\n" 
  310               "    --only-expire            Expire entries instead of invalidating them\n" 
  314int main(
int argc, 
char *argv[]) {
 
  316    struct fuse_session *se;
 
  325    if (fuse_parse_cmdline(&args, &opts) != 0)
 
  327    if (opts.show_help) {
 
  333    } 
else if (opts.show_version) {
 
  343    se = fuse_session_new(&args, &tfs_oper,
 
  344                          sizeof(tfs_oper), &se);
 
  359    main_thread = pthread_self();
 
  362    ret = pthread_create(&updater, NULL, update_fs_loop, (
void *)se);
 
  364        fprintf(stderr, 
"pthread_create failed with %s\n",
 
  370    if (opts.singlethread) {
 
  373                config = fuse_loop_cfg_create();
 
  374                fuse_loop_cfg_set_clone_fd(config, opts.clone_fd);
 
  375                fuse_loop_cfg_set_max_threads(config, opts.max_threads);
 
  376                ret = fuse_session_loop_mt(se, config);
 
  377                fuse_loop_cfg_destroy(config);
 
  387    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)
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(* init)(void *userdata, struct fuse_conn_info *conn)