10#define FUSE_USE_VERSION 30 
   15#include <fuse_config.h> 
   16#include <fuse_lowlevel.h> 
   30#include <linux/limits.h> 
   34#define FILE_NAME "truncate_me" 
   37static mode_t file_mode = S_IFREG | 0644;
 
   39static int tfs_stat(
fuse_ino_t ino, 
struct stat *stbuf) {
 
   41    if (ino == FUSE_ROOT_ID) {
 
   42        stbuf->st_mode = S_IFDIR | 0755;
 
   46    else if (ino == FILE_INO) {
 
   47        stbuf->st_mode = file_mode;
 
   61    memset(&e, 0, 
sizeof(e));
 
   65    else if (strcmp(name, FILE_NAME) == 0)
 
   70    if (tfs_stat(e.ino, &e.attr) != 0)
 
   85    memset(&stbuf, 0, 
sizeof(stbuf));
 
   86    if (tfs_stat(ino, &stbuf) != 0)
 
   94    if (ino == FUSE_ROOT_ID)
 
   97        assert(ino == FILE_INO);
 
  105    if(ino != FILE_INO ||
 
  106       !(to_set & FUSE_SET_ATTR_MODE)) {
 
  112        fprintf(stderr, 
"setattr with fi == NULL\n");
 
  113    else if (fi->
fh != FILE_INO)
 
  114        fprintf(stderr, 
"setattr with wrong fi->fh\n");
 
  116        fprintf(stderr, 
"setattr ok\n");
 
  118        file_mode = attr->st_mode;
 
  121    tfs_getattr(req, ino, fi);
 
  126    .getattr    = tfs_getattr,
 
  128    .setattr    = tfs_setattr,
 
  131static void* run_fs(
void *data) {
 
  132    struct fuse_session *se = (
struct fuse_session*) data;
 
  137static void test_fs(
char *mountpoint) {
 
  138    char fname[PATH_MAX];
 
  141    assert(snprintf(fname, PATH_MAX, 
"%s/" FILE_NAME,
 
  143    fd = open(fname, O_WRONLY);
 
  149    assert(fchmod(fd, 0600) == 0);
 
  153int main(
int argc, 
char *argv[]) {
 
  155    struct fuse_session *se;
 
  159    assert(fuse_parse_cmdline(&args, &fuse_opts) == 0);
 
  163    se = fuse_session_new(&args, &tfs_oper,
 
  164                          sizeof(tfs_oper), NULL);
 
  170    assert(pthread_create(&fs_thread, NULL, run_fs, (
void *)se) == 0);
 
  173    test_fs(fuse_opts.mountpoint);
 
  176    assert(pthread_cancel(fs_thread) == 0);
 
  183    printf(
"Test completed successfully.\n");
 
int fuse_set_signal_handlers(struct fuse_session *se)
void fuse_remove_signal_handlers(struct fuse_session *se)
void fuse_session_destroy(struct fuse_session *se)
int fuse_reply_open(fuse_req_t req, const struct fuse_file_info *fi)
int fuse_reply_err(fuse_req_t req, int err)
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)
int fuse_session_mount(struct fuse_session *se, const char *mountpoint)
int fuse_reply_attr(fuse_req_t req, const struct stat *attr, double attr_timeout)
int fuse_opt_add_arg(struct fuse_args *args, const char *arg)
#define FUSE_ARGS_INIT(argc, argv)
void(* lookup)(fuse_req_t req, fuse_ino_t parent, const char *name)