25 #define FUSE_USE_VERSION 31    37 #define FIOC_NAME       "fioc"    45 static void *fioc_buf;
    46 static size_t fioc_size;
    48 static 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);
    68 static int fioc_expand(
size_t new_size)
    70         if (new_size > fioc_size)
    71                 return fioc_resize(new_size);
    75 static int fioc_file_type(
const char *path)
    77         if (strcmp(path, 
"/") == 0)
    79         if (strcmp(path, 
"/" FIOC_NAME) == 0)
    84 static 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)
   118 static 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);
   131 static 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);
   142 static 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);
   152 static 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);
   163 static int fioc_truncate(
const char *path, off_t size,
   167         if (fioc_file_type(path) != FIOC_FILE)
   170         return fioc_resize(size);
   173 static int fioc_readdir(
const char *path, 
void *buf, 
fuse_fill_dir_t filler,
   181         if (fioc_file_type(path) != FIOC_ROOT)
   184         filler(buf, 
".", NULL, 0, 0);
   185         filler(buf, 
"..", NULL, 0, 0);
   186         filler(buf, FIOC_NAME, NULL, 0, 0);
   191 static 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,
   227 int main(
int argc, 
char *argv[])
   229         return fuse_main(argc, argv, &fioc_oper, NULL);
 
#define FUSE_IOCTL_COMPAT
#define fuse_main(argc, argv, op, private_data)
int(* getattr)(const char *, struct stat *, struct fuse_file_info *fi)
int(* fuse_fill_dir_t)(void *buf, const char *name, const struct stat *stbuf, off_t off, enum fuse_fill_dir_flags flags)