62 #define FUSE_USE_VERSION 31    77 #define NO_TIMEOUT 500000    81 #define ACCESS_MASK (O_RDONLY | O_WRONLY | O_RDWR)    83 #define MAX_STR_LEN 128    85 #define FILE_NAME "current_time"    86 static char file_contents[MAX_STR_LEN];
    87 static int lookup_cnt = 0;
    88 static size_t file_size;
    95 static struct options options = {
   100 #define OPTION(t, p)                           \   101     { t, offsetof(struct options, p), 1 }   102 static const struct fuse_opt option_spec[] = {
   103     OPTION(
"--no-notify", no_notify),
   104     OPTION(
"--update-interval=%d", update_interval),
   108 static int tfs_stat(
fuse_ino_t ino, 
struct stat *stbuf) {
   111         stbuf->st_mode = S_IFDIR | 0755;
   115     else if (ino == FILE_INO) {
   116         stbuf->st_mode = S_IFREG | 0444;
   118         stbuf->st_size = file_size;
   130     memset(&e, 0, 
sizeof(e));
   134     else if (strcmp(name, FILE_NAME) == 0) {
   140     e.attr_timeout = NO_TIMEOUT;
   141     e.entry_timeout = NO_TIMEOUT;
   142     if (tfs_stat(e.ino, &e.attr) != 0)
   155         lookup_cnt -= nlookup;
   167     memset(&stbuf, 0, 
sizeof(stbuf));
   168     if (tfs_stat(ino, &stbuf) != 0)
   179 static void dirbuf_add(
fuse_req_t req, 
struct dirbuf *b, 
const char *name,
   182     size_t oldsize = b->size;
   184     b->p = (
char *) realloc(b->p, b->size);
   185     memset(&stbuf, 0, 
sizeof(stbuf));
   191 #define min(x, y) ((x) < (y) ? (x) : (y))   193 static int reply_buf_limited(
fuse_req_t req, 
const char *buf, 
size_t bufsize,
   194                              off_t off, 
size_t maxsize) {
   197                               min(bufsize - off, maxsize));
   211         memset(&b, 0, 
sizeof(b));
   212         dirbuf_add(req, &b, FILE_NAME, FILE_INO);
   213         reply_buf_limited(req, b.p, b.size, off, size);
   227     else if ((fi->
flags & ACCESS_MASK) != O_RDONLY)
   229     else if (ino == FILE_INO)
   233         fprintf(stderr, 
"Got open for non-existing inode!\n");
   242     assert(ino == FILE_INO);
   243     reply_buf_limited(req, file_contents, file_size, off, size);
   248     .getattr    = tfs_getattr,
   249     .readdir    = tfs_readdir,
   252     .forget     = tfs_forget,
   255 static void update_fs(
void) {
   262     file_size = strftime(file_contents, MAX_STR_LEN,
   263                          "The current time is %H:%M:%S\n", now);
   264     assert(file_size != 0);
   267 static void* update_fs_loop(
void *data) {
   268     struct fuse_session *se = (
struct fuse_session*) data;
   272         if (!options.no_notify && lookup_cnt) {
   276                    (se, FILE_INO, 0, 0) == 0);
   278         sleep(options.update_interval);
   283 static void show_help(
const char *progname)
   285     printf(
"usage: %s [options] <mountpoint>\n\n", progname);
   286     printf(
"File-system specific options:\n"   287                "    --update-interval=<secs>  Update-rate of file system contents\n"   288                "    --no-notify            Disable kernel notifications\n"   292 int main(
int argc, 
char *argv[]) {
   294     struct fuse_session *se;
   295     struct fuse_cmdline_opts opts;
   307     if (opts.show_help) {
   313     } 
else if (opts.show_version) {
   324                           sizeof(tfs_oper), NULL);
   337     ret = pthread_create(&updater, NULL, update_fs_loop, (
void *)se);
   339         fprintf(stderr, 
"pthread_create failed with %s\n",
   345     if (opts.singlethread)
   348         ret = fuse_session_loop_mt(se, opts.clone_fd);
   357     free(opts.mountpoint);
 void fuse_session_destroy(struct fuse_session *se)
int fuse_reply_err(fuse_req_t req, int err)
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_loop(struct fuse_session *se)
void fuse_lowlevel_help(void)
int fuse_daemonize(int foreground)
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc)
struct fuse_req * fuse_req_t
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_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino, off_t off, off_t len)
int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts)
void fuse_cmdline_help(void)
int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
int fuse_set_signal_handlers(struct fuse_session *se)
void fuse_remove_signal_handlers(struct fuse_session *se)
void fuse_lowlevel_version(void)
void fuse_reply_none(fuse_req_t req)
void fuse_opt_free_args(struct fuse_args *args)
int fuse_reply_attr(fuse_req_t req, const struct stat *attr, double attr_timeout)
void fuse_session_unmount(struct fuse_session *se)
void(* lookup)(fuse_req_t req, fuse_ino_t parent, const char *name)
int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi)
const char * fuse_pkgversion(void)
#define FUSE_ARGS_INIT(argc, argv)
int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size)