25#define FUSE_USE_VERSION 35 
   37#define FIOC_NAME       "fioc" 
   46static size_t fioc_size;
 
   48static int fioc_resize(
size_t new_size)
 
   52        if (new_size == fioc_size)
 
   55        new_buf = realloc(fioc_buf, new_size);
 
   56        if (!new_buf && new_size)
 
   59        if (new_size > fioc_size)
 
   60                memset(new_buf + fioc_size, 0, new_size - fioc_size);
 
   68static int fioc_expand(
size_t new_size)
 
   70        if (new_size > fioc_size)
 
   71                return fioc_resize(new_size);
 
   75static int fioc_file_type(
const char *path)
 
   77        if (strcmp(path, 
"/") == 0)
 
   79        if (strcmp(path, 
"/" FIOC_NAME) == 0)
 
   84static int fioc_getattr(
const char *path, 
struct stat *stbuf,
 
   88        stbuf->st_uid = getuid();
 
   89        stbuf->st_gid = getgid();
 
   90        stbuf->st_atime = stbuf->st_mtime = time(NULL);
 
   92        switch (fioc_file_type(path)) {
 
   94                stbuf->st_mode = S_IFDIR | 0755;
 
   98                stbuf->st_mode = S_IFREG | 0644;
 
  100                stbuf->st_size = fioc_size;
 
  113        if (fioc_file_type(path) != FIOC_NONE)
 
  118static int fioc_do_read(
char *buf, 
size_t size, off_t offset)
 
  120        if (offset >= fioc_size)
 
  123        if (size > fioc_size - offset)
 
  124                size = fioc_size - offset;
 
  126        memcpy(buf, fioc_buf + offset, size);
 
  131static int fioc_read(
const char *path, 
char *buf, 
size_t size,
 
  136        if (fioc_file_type(path) != FIOC_FILE)
 
  139        return fioc_do_read(buf, size, offset);
 
  142static int fioc_do_write(
const char *buf, 
size_t size, off_t offset)
 
  144        if (fioc_expand(offset + size))
 
  147        memcpy(fioc_buf + offset, buf, size);
 
  152static int fioc_write(
const char *path, 
const char *buf, 
size_t size,
 
  157        if (fioc_file_type(path) != FIOC_FILE)
 
  160        return fioc_do_write(buf, size, offset);
 
  163static int fioc_truncate(
const char *path, off_t size,
 
  167        if (fioc_file_type(path) != FIOC_FILE)
 
  170        return fioc_resize(size);
 
  173static int fioc_readdir(
const char *path, 
void *buf, 
fuse_fill_dir_t filler,
 
  181        if (fioc_file_type(path) != FIOC_ROOT)
 
  191static int fioc_ioctl(
const char *path, 
unsigned int cmd, 
void *arg,
 
  198        if (fioc_file_type(path) != FIOC_FILE)
 
  206                *(
size_t *)data = fioc_size;
 
  210                fioc_resize(*(
size_t *)data);
 
  219        .readdir        = fioc_readdir,
 
  220        .truncate       = fioc_truncate,
 
  227int main(
int argc, 
char *argv[])
 
  229        return fuse_main(argc, argv, &fioc_oper, NULL);
 
int(* fuse_fill_dir_t)(void *buf, const char *name, const struct stat *stbuf, off_t off, enum fuse_fill_dir_flags flags)
#define FUSE_IOCTL_COMPAT
int(* getattr)(const char *, struct stat *, struct fuse_file_info *fi)