79 #define FUSE_USE_VERSION 34 
   81 #include <fuse_lowlevel.h> 
   92 #define MAX_STR_LEN 128 
   93 static char file_name[MAX_STR_LEN];
 
   95 static int lookup_cnt = 0;
 
  104 static struct options options = {
 
  107     .update_interval = 1,
 
  111 #define OPTION(t, p)                           \ 
  112     { t, offsetof(struct options, p), 1 } 
  113 static const struct fuse_opt option_spec[] = {
 
  114     OPTION(
"--no-notify", no_notify),
 
  115     OPTION(
"--update-interval=%d", update_interval),
 
  116     OPTION(
"--timeout=%f", timeout),
 
  117     OPTION(
"--only-expire", only_expire),
 
  121 static int tfs_stat(
fuse_ino_t ino, 
struct stat *stbuf) {
 
  124         stbuf->st_mode = S_IFDIR | 0755;
 
  128     else if (ino == file_ino) {
 
  129         stbuf->st_mode = S_IFREG | 0000;
 
  143     memset(&e, 0, 
sizeof(e));
 
  147     else if (strcmp(name, file_name) == 0) {
 
  153     e.attr_timeout = options.timeout;
 
  154     e.entry_timeout = options.timeout;
 
  155     if (tfs_stat(e.ino, &e.attr) != 0)
 
  168         lookup_cnt -= nlookup;
 
  180     memset(&stbuf, 0, 
sizeof(stbuf));
 
  181     if (tfs_stat(ino, &stbuf) != 0)
 
  192 static void dirbuf_add(
fuse_req_t req, 
struct dirbuf *b, 
const char *name,
 
  195     size_t oldsize = b->size;
 
  197     b->p = (
char *) realloc(b->p, b->size);
 
  198     memset(&stbuf, 0, 
sizeof(stbuf));
 
  204 #define min(x, y) ((x) < (y) ? (x) : (y)) 
  206 static int reply_buf_limited(
fuse_req_t req, 
const char *buf, 
size_t bufsize,
 
  207                              off_t off, 
size_t maxsize) {
 
  210                               min(bufsize - off, maxsize));
 
  224         memset(&b, 0, 
sizeof(b));
 
  225         dirbuf_add(req, &b, file_name, file_ino);
 
  226         reply_buf_limited(req, b.p, b.size, off, size);
 
  233     .getattr    = tfs_getattr,
 
  234     .readdir    = tfs_readdir,
 
  235     .forget     = tfs_forget,
 
  238 static void update_fs(
void) {
 
  247     ret = strftime(file_name, MAX_STR_LEN,
 
  248                    "Time_is_%Hh_%Mm_%Ss", now);
 
  252 static void* update_fs_loop(
void *data) {
 
  253     struct fuse_session *se = (
struct fuse_session*) data;
 
  257         old_name = strdup(file_name);
 
  259         if (!options.no_notify && lookup_cnt) {
 
  260             if(options.only_expire) {
 
  262                    (se, 
FUSE_ROOT_ID, old_name, strlen(old_name), FUSE_LL_EXPIRE_ONLY) == 0);
 
  269         sleep(options.update_interval);
 
  274 static void show_help(
const char *progname)
 
  276     printf(
"usage: %s [options] <mountpoint>\n\n", progname);
 
  277     printf(
"File-system specific options:\n" 
  278                "    --timeout=<secs>       Timeout for kernel caches\n" 
  279                "    --update-interval=<secs>  Update-rate of file system contents\n" 
  280                "    --no-notify            Disable kernel notifications\n" 
  281                "    --only-expire            Expire entries instead of invalidating them\n" 
  285 int main(
int argc, 
char *argv[]) {
 
  287     struct fuse_session *se;
 
  296     if (fuse_parse_cmdline(&args, &opts) != 0)
 
  298     if (opts.show_help) {
 
  304     } 
else if (opts.show_version) {
 
  315                           sizeof(tfs_oper), NULL);
 
  328     ret = pthread_create(&updater, NULL, update_fs_loop, (
void *)se);
 
  330         fprintf(stderr, 
"pthread_create failed with %s\n",
 
  336     if (opts.singlethread)
 
  339         config.clone_fd = opts.clone_fd;
 
  340         config.max_idle_threads = opts.max_idle_threads;
 
  341         ret = fuse_session_loop_mt(se, &config);
 
  350     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)
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_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)
void fuse_lowlevel_help(void)
struct fuse_session * fuse_session_new(struct fuse_args *args, const struct fuse_lowlevel_ops *op, size_t op_size, void *userdata)
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
int fuse_lowlevel_notify_expire_entry(struct fuse_session *se, fuse_ino_t parent, const char *name, size_t namelen, enum fuse_expire_flags flags)
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)