62 #define FUSE_USE_VERSION 31    64 #include <fuse_lowlevel.h>    77 #define NO_TIMEOUT 500000    79 #define MAX_STR_LEN 128    81 #define FILE_NAME "current_time"    82 static char file_contents[MAX_STR_LEN];
    83 static int lookup_cnt = 0;
    84 static size_t file_size;
    91 static struct options options = {
    96 #define OPTION(t, p)                           \    97     { t, offsetof(struct options, p), 1 }    98 static const struct fuse_opt option_spec[] = {
    99     OPTION(
"--no-notify", no_notify),
   100     OPTION(
"--update-interval=%d", update_interval),
   104 static int tfs_stat(
fuse_ino_t ino, 
struct stat *stbuf) {
   107         stbuf->st_mode = S_IFDIR | 0755;
   111     else if (ino == FILE_INO) {
   112         stbuf->st_mode = S_IFREG | 0444;
   114         stbuf->st_size = file_size;
   126     memset(&e, 0, 
sizeof(e));
   130     else if (strcmp(name, FILE_NAME) == 0) {
   136     e.attr_timeout = NO_TIMEOUT;
   137     e.entry_timeout = NO_TIMEOUT;
   138     if (tfs_stat(e.ino, &e.attr) != 0)
   151         lookup_cnt -= nlookup;
   163     memset(&stbuf, 0, 
sizeof(stbuf));
   164     if (tfs_stat(ino, &stbuf) != 0)
   175 static void dirbuf_add(
fuse_req_t req, 
struct dirbuf *b, 
const char *name,
   178     size_t oldsize = b->size;
   180     b->p = (
char *) realloc(b->p, b->size);
   181     memset(&stbuf, 0, 
sizeof(stbuf));
   187 #define min(x, y) ((x) < (y) ? (x) : (y))   189 static int reply_buf_limited(
fuse_req_t req, 
const char *buf, 
size_t bufsize,
   190                              off_t off, 
size_t maxsize) {
   193                               min(bufsize - off, maxsize));
   207         memset(&b, 0, 
sizeof(b));
   208         dirbuf_add(req, &b, FILE_NAME, FILE_INO);
   209         reply_buf_limited(req, b.p, b.size, off, size);
   223     else if ((fi->
flags & O_ACCMODE) != O_RDONLY)
   225     else if (ino == FILE_INO)
   229         fprintf(stderr, 
"Got open for non-existing inode!\n");
   238     assert(ino == FILE_INO);
   239     reply_buf_limited(req, file_contents, file_size, off, size);
   244     .getattr    = tfs_getattr,
   245     .readdir    = tfs_readdir,
   248     .forget     = tfs_forget,
   251 static void update_fs(
void) {
   258     file_size = strftime(file_contents, MAX_STR_LEN,
   259                          "The current time is %H:%M:%S\n", now);
   260     assert(file_size != 0);
   263 static void* update_fs_loop(
void *data) {
   264     struct fuse_session *se = (
struct fuse_session*) data;
   268         if (!options.no_notify && lookup_cnt) {
   272                    (se, FILE_INO, 0, 0) == 0);
   274         sleep(options.update_interval);
   279 static void show_help(
const char *progname)
   281     printf(
"usage: %s [options] <mountpoint>\n\n", progname);
   282     printf(
"File-system specific options:\n"   283                "    --update-interval=<secs>  Update-rate of file system contents\n"   284                "    --no-notify            Disable kernel notifications\n"   288 int main(
int argc, 
char *argv[]) {
   290     struct fuse_session *se;
   291     struct fuse_cmdline_opts opts;
   303     if (opts.show_help) {
   309     } 
else if (opts.show_version) {
   320                           sizeof(tfs_oper), NULL);
   333     ret = pthread_create(&updater, NULL, update_fs_loop, (
void *)se);
   335         fprintf(stderr, 
"pthread_create failed with %s\n",
   341     if (opts.singlethread)
   344         ret = fuse_session_loop_mt(se, opts.clone_fd);
   353     free(opts.mountpoint);
 void fuse_cmdline_help(void)
void(* lookup)(fuse_req_t req, fuse_ino_t parent, const char *name)
int fuse_opt_parse(struct fuse_args *args, void *data, const struct fuse_opt opts[], fuse_opt_proc_t proc)
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
struct fuse_req * fuse_req_t
int fuse_set_signal_handlers(struct fuse_session *se)
void fuse_reply_none(fuse_req_t req)
int fuse_reply_attr(fuse_req_t req, const struct stat *attr, double attr_timeout)
#define FUSE_ARGS_INIT(argc, argv)
int fuse_reply_buf(fuse_req_t req, const char *buf, size_t size)
int fuse_lowlevel_notify_inval_inode(struct fuse_session *se, fuse_ino_t ino, off_t off, off_t len)
void fuse_lowlevel_version(void)
const char * fuse_pkgversion(void)
int fuse_session_loop(struct fuse_session *se)
int fuse_parse_cmdline(struct fuse_args *args, struct fuse_cmdline_opts *opts)
struct fuse_session * fuse_session_new(struct fuse_args *args, const struct fuse_lowlevel_ops *op, size_t op_size, void *userdata)
void fuse_remove_signal_handlers(struct fuse_session *se)
void fuse_session_unmount(struct fuse_session *se)
int fuse_reply_err(fuse_req_t req, int err)
size_t fuse_add_direntry(fuse_req_t req, char *buf, size_t bufsize, const char *name, const struct stat *stbuf, off_t off)
void fuse_opt_free_args(struct fuse_args *args)
int fuse_reply_entry(fuse_req_t req, const struct fuse_entry_param *e)
int fuse_daemonize(int foreground)
void fuse_session_destroy(struct fuse_session *se)
void fuse_lowlevel_help(void)
int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi)