Beispiel #1
0
int fskit_fuse_fgetattr(const char *path, struct stat *statbuf, struct fuse_file_info *fi) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_FGETATTR) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("fgetattr(%s, %p, %p)\n", path, statbuf, fi );

   struct fskit_fuse_file_info* ffi = NULL;

   ffi = (struct fskit_fuse_file_info*)((uintptr_t)fi->fh);

   int rc = 0;

   if( ffi->type == FSKIT_ENTRY_TYPE_FILE ) {
      rc = fskit_fstat( state->core, fskit_file_handle_get_path( ffi->handle.fh ), fskit_file_handle_get_entry( ffi->handle.fh ), statbuf );
   }
   else {
      rc = fskit_fstat( state->core, fskit_dir_handle_get_path( ffi->handle.dh ), fskit_dir_handle_get_entry( ffi->handle.dh ), statbuf );
   }

   fskit_debug("fgetattr(%s, %p, %p) rc = %d\n", path, statbuf, fi, rc );

   return rc;
}
Beispiel #2
0
int fskit_fuse_fsyncdir(const char *path, int datasync, struct fuse_file_info *fi) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_FSYNCDIR) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("fsyncdir(%s, %d, %p)\n", path, datasync, fi);


   // not addressed by fskit

   fskit_debug("fsyncdir(%s, %d, %p) rc = %d\n", path, datasync, fi, 0);
   return 0;
}
Beispiel #3
0
int fskit_fuse_fsync(const char *path, int datasync, struct fuse_file_info *fi) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_FSYNC) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("fsync(%s, %d, %p)\n", path, datasync, fi );

   struct fskit_fuse_file_info* ffi = (struct fskit_fuse_file_info*)((uintptr_t)fi->fh);

   int rc = fskit_fsync( state->core, ffi->handle.fh );

   fskit_debug("fsync(%s, %d, %p) rc = %d\n", path, datasync, fi, rc );
   return rc;
}
Beispiel #4
0
int fskit_fuse_removexattr(const char *path, const char *name) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_REMOVEXATTR) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("removexattr(%s, %s)\n", path, name );

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   int rc = fskit_removexattr( state->core, path, uid, gid, name );

   fskit_debug("removexattr(%s, %s) rc = %d\n", path, name, rc );
   return rc;
}
Beispiel #5
0
int fskit_fuse_listxattr(const char *path, char *list, size_t size) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_LISTXATTR) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("listxattr(%s, %p, %zu)\n", path, list, size );

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   int rc = fskit_listxattr( state->core, path, uid, gid, list, size );

   fskit_debug("listxattr(%s, %p, %zu) rc = %d\n", path, list, size, rc );
   return rc;
}
Beispiel #6
0
int fskit_fuse_setxattr(const char *path, const char *name, const char *value, size_t size, int flags) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_SETXATTR) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("setxattr(%s, %s, %p, %zu, %X)\n", path, name, value, size, flags );

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   int rc = fskit_setxattr( state->core, path, uid, gid, name, value, size, flags );

   fskit_debug("setxattr(%s, %s, %p, %zu, %X) rc = %d\n", path, name, value, size, flags, rc );
   return rc;
}
Beispiel #7
0
int fskit_fuse_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_WRITE) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("write(%s, %p, %zu, %jd, %p)\n", path, buf, size, offset, fi);

   struct fskit_fuse_file_info* ffi = (struct fskit_fuse_file_info*)((uintptr_t)fi->fh);
   ssize_t num_written = 0;

   num_written = fskit_write( state->core, ffi->handle.fh, buf, size, offset );

   fskit_debug("write(%s, %p, %zu, %jd, %p) rc = %zd\n", path, buf, size, offset, fi, num_written);

   return (int)num_written;
}
Beispiel #8
0
int fskit_fuse_utime(const char *path, struct utimbuf *ubuf) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_UTIME) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("utime(%s, %ld.%ld)\n", path, ubuf->actime, ubuf->modtime );

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   int rc = fskit_utime( state->core, path, uid, gid, ubuf );

   fskit_debug("utime(%s, %ld.%ld) rc = %d\n", path, ubuf->actime, ubuf->modtime, rc );

   return rc;
}
Beispiel #9
0
int fskit_fuse_truncate(const char *path, off_t newsize) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_TRUNCATE) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("truncate(%s, %jd)\n", path, newsize );

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   int rc = fskit_trunc( state->core, path, uid, gid, newsize );

   fskit_debug("truncate(%s, %jd) rc = %d\n", path, newsize, rc );

   return rc;
}
Beispiel #10
0
int fskit_fuse_chmod(const char *path, mode_t mode) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_CHMOD) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("chmod(%s, %o)\n", path, mode );

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   int rc = fskit_chmod( state->core, path, uid, gid, mode );

   fskit_debug("chmod(%s, %o) rc = %d\n", path, mode, rc );

   return rc;
}
Beispiel #11
0
int fskit_fuse_link(const char *path, const char *newpath) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_LINK) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("link(%s, %s)\n", path, newpath );

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   int rc = fskit_link( state->core, path, newpath, uid, gid );

   fskit_debug("link(%s, %s) rc = %d\n", path, newpath, rc );

   return 0;
}
Beispiel #12
0
int fskit_fuse_symlink(const char *target, const char *linkpath) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_SYMLINK) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("symlink(%s, %s)\n", target, linkpath );

   int rc = 0;
   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   rc = fskit_symlink( state->core, target, linkpath, uid, gid );

   fskit_debug("symlink(%s, %s) rc = %d\n", target, linkpath, rc );
   return rc;
}
Beispiel #13
0
int fskit_fuse_rmdir(const char *path) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_RMDIR) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("rmdir(%s)\n", path );

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   int rc = fskit_rmdir( state->core, path, uid, gid );

   fskit_debug("rmdir(%s) rc = %d\n", path, rc );

   return rc;
}
Beispiel #14
0
int fskit_fuse_mknod(const char *path, mode_t mode, dev_t dev) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_MKNOD) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("mknod(%s, %o, %d, %d)\n", path, mode, major(dev), minor(dev) );

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   int rc = fskit_mknod( state->core, path, mode, dev, uid, gid );

   fskit_debug("mknod(%s, %o, %d, %d) rc = %d\n", path, mode, major(dev), minor(dev), rc );

   return rc;
}
Beispiel #15
0
int fskit_fuse_access(const char *path, int mask) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_ACCESS) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("access(%s, %X)\n", path, mask );

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   int rc = fskit_access( state->core, path, uid, gid, mask );

   fskit_debug("access(%s, %X) rc = %d\n", path, mask, rc );

   return rc;
}
Beispiel #16
0
int fskit_fuse_getattr(const char *path, struct stat *statbuf) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_GETATTR) == 0 ) {
      return -ENOSYS;
   }

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   fskit_debug("getattr(%s, %p, %d, %d)\n", path, statbuf, uid, gid );

   int rc = fskit_stat( state->core, path, uid, gid, statbuf );

   fskit_debug("getattr(%s, %p, %d, %d) rc = %d\n", path, statbuf, uid, gid, rc );

   return rc;
}
Beispiel #17
0
int fskit_fuse_chown(const char *path, uid_t new_uid, gid_t new_gid) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_CHOWN) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("chown(%s, %d, %d)\n", path, new_uid, new_gid );

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   int rc = fskit_chown( state->core, path, uid, gid, new_uid, new_gid );

   fskit_debug("chown(%s, %d, %d) rc = %d\n", path, new_uid, new_gid, rc );

   return rc;
}
Beispiel #18
0
int fskit_fuse_statfs(const char *path, struct statvfs *statv) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_STATFS) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("statfs(%s, %p)\n", path, statv );

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   int rc = fskit_statvfs( state->core, path, uid, gid, statv );

   fskit_debug("statfs(%s, %p) rc = %d\n", path, statv, rc );

   return rc;
}
Beispiel #19
0
int fskit_fuse_ftruncate(const char *path, off_t new_size, struct fuse_file_info *fi) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_FTRUNCATE) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("ftruncate(%s, %jd, %p)\n", path, new_size, fi );

   struct fskit_fuse_file_info* ffi = NULL;

   ffi = (struct fskit_fuse_file_info*)((uintptr_t)fi->fh);

   int rc = fskit_ftrunc( state->core, ffi->handle.fh, new_size );

   fskit_debug("ftruncate(%s, %jd, %p) rc = %d\n", path, new_size, fi, rc );

   return rc;
}
Beispiel #20
0
int fskit_fuse_create(const char *path, mode_t mode, struct fuse_file_info *fi) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_CREATE) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("create(%s, %o, %p)\n", path, mode, fi );

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );
   struct fskit_fuse_file_info* ffi = NULL;
   int rc = 0;

   struct fskit_file_handle* fh = fskit_create( state->core, path, uid, gid, mode, &rc );

   if( rc != 0 ) {

      fskit_debug("create(%s, %o, %p) rc = %d\n", path, mode, fi, rc );

      return rc;
   }

   ffi = fskit_fuse_make_file_handle( fh );
   if( ffi == NULL ) {

      fskit_close( state->core, fh );

      fskit_debug("create(%s, %o, %p) rc = %d\n", path, mode, fi, -ENOMEM );

      return -ENOMEM;
   }

   fi->fh = (uintptr_t)ffi;

   // NOTE: fskit_read() and fskit_write() return a negative error code on error,
   // so set direct_io to allow this error code to be propagated.
   fi->direct_io = 1;

   fskit_debug("create(%s, %o, %p) rc = %d\n", path, mode, fi, rc );

   return rc;
}
Beispiel #21
0
int fskit_fuse_readdir(const char *path, void *buf, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_READDIR) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("readdir(%s, %jd, %p, %p)\n", path, offset, buf, fi );

   struct fskit_dir_handle* fdh = NULL;
   struct fskit_fuse_file_info* ffi = NULL;
   int rc = 0;
   uint64_t num_read = 0;

   ffi = (struct fskit_fuse_file_info*)((uintptr_t)fi->fh);
   fdh = ffi->handle.dh;

   struct fskit_dir_entry** dirents = fskit_listdir( state->core, fdh, &num_read, &rc );

   if( dirents == NULL || rc != 0 ) {
      fskit_debug("readdir(%s, %jd, %p, %p) rc = %d\n", path, offset, buf, fi, rc );
      return rc;
   }

   for( uint64_t i = 0; i < num_read; i++ ) {

      rc = filler( buf, dirents[i]->name, NULL, 0 );
      if( rc != 0 ) {
         rc = -ENOMEM;
         break;
      }
   }

   fskit_dir_entry_free_list( dirents );

   if( rc > 0 ) {
      rc = 0;
   }

   fskit_debug("readdir(%s, %jd, %p, %p) rc = %d\n", path, offset, buf, fi, rc );
   return rc;
}
Beispiel #22
0
int fskit_fuse_release(const char *path, struct fuse_file_info *fi) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_RELEASE) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("release(%s, %p)\n", path, fi);

   struct fskit_fuse_file_info* ffi = (struct fskit_fuse_file_info*)((uintptr_t)fi->fh);

   int rc = fskit_close( state->core, ffi->handle.fh );

   if( rc == 0 ) {
      free( ffi );
   }

   fskit_debug("release(%s, %p) rc = %d\n", path, fi, rc);
   return rc;
}
Beispiel #23
0
int fskit_fuse_flush(const char *path, struct fuse_file_info *fi) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_FLUSH) == 0 ) {
      return -ENOSYS;
   }
   
   int rc = 0;
   fskit_debug("flush(%s, %p)\n", path, fi);
  
   // if this is a file, then fsync it
   struct fskit_fuse_file_info* ffi = (struct fskit_fuse_file_info*)((uintptr_t)fi->fh);
   if( ffi->type == FSKIT_ENTRY_TYPE_FILE ) {

       // same as fsync 
       rc = fskit_fsync( state->core, ffi->handle.fh );
   }

   fskit_debug("flush(%s, %p) rc = %d\n", path, fi, rc);
   return rc;
}
Beispiel #24
0
int main( int argc, char** argv ) {

   struct fskit_core* core = NULL;
   int rc;
   char name_buf[10];
   struct fskit_file_handle* fh = NULL;
   void* output;

   rc = fskit_test_begin( &core, NULL );
   if( rc != 0 ) {
      exit(1);
   }

   for( int i = 0; i < 256; i++ ) {

      sprintf(name_buf, "/%d", i );

      fh = fskit_create( core, name_buf, 0, i, 0644, &rc );

      if( fh == NULL ) {
         fskit_error("fskit_create('%s') rc = %d\n", name_buf, rc );
         exit(1);
      }

      fskit_close( core, fh );
   }

   for( int i = 0; i < 256; i++ ) {

      sprintf(name_buf, "/%d", i );

      struct stat sb;
      memset( &sb, 0xFF, sizeof(struct stat) );

      rc = fskit_stat( core, name_buf, 0, i, &sb );

      if( rc != 0 ) {
         fskit_error("fskit_stat('%s') rc = %d\n", name_buf, rc );
         exit(1);
      }

      fskit_debug("%s: stat(st_dev=%lX st_ino=%lX st_mode=%o st_nlink=%lu st_uid=%d st_gid=%d st_rdev=%lX st_size=%jd st_blksize=%ld st_blocks=%ld)\n",
               name_buf, sb.st_dev, sb.st_ino, sb.st_mode, sb.st_nlink, sb.st_uid, sb.st_gid, sb.st_rdev, sb.st_size, sb.st_blksize, sb.st_blocks );
   }

   fskit_print_tree( stdout, fskit_core_get_root( core ) );

   fskit_test_end( core, &output );

   return 0;
}
Beispiel #25
0
int fskit_fuse_readlink(const char *path, char *link, size_t size) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_READLINK) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("readlink(%s, %zu)\n", path, size );

   ssize_t rc = 0;
   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );

   rc = fskit_readlink( state->core, path, uid, gid, link, size );

   if( rc >= 0 ) {
      rc = 0;
   }

   fskit_debug("readlink(%s, %zu) rc = %zd\n", path, size, rc );

   return (int)rc;
}
Beispiel #26
0
int fskit_fuse_opendir(const char *path, struct fuse_file_info *fi) {

   struct fskit_fuse_state* state = fskit_fuse_get_state();
   if( (state->callbacks & FSKIT_FUSE_OPENDIR) == 0 ) {
      return -ENOSYS;
   }

   fskit_debug("opendir(%s, %p)\n", path, fi );

   uid_t uid = fskit_fuse_get_uid( state );
   gid_t gid = fskit_fuse_get_gid( state );
   struct fskit_fuse_file_info* ffi = NULL;
   int rc = 0;

   struct fskit_dir_handle* dh = fskit_opendir( state->core, path, uid, gid, &rc );

   if( rc != 0 ) {

      fskit_debug("opendir(%s, %p) rc = %d\n", path, fi, rc );
      return rc;
   }

   ffi = fskit_fuse_make_dir_handle( dh );

   if( ffi == NULL ) {
      fskit_closedir( state->core, dh );

      fskit_debug("opendir(%s, %p) rc = %d\n", path, fi, -ENOMEM );
      return -ENOMEM;
   }

   fi->fh = (uintptr_t)ffi;

   fskit_debug("opendir(%s, %p) rc = %d\n", path, fi, 0 );
   return 0;
}
Beispiel #27
0
int fskit_test_mkdir_LR_recursive( struct fskit_core* core, char const* path, int depth ) {

   if( depth <= 0 ) {
      return 0;
   }

   fskit_debug("mkdir('%s')\n", path );
   
   int rc = fskit_mkdir( core, path, 0755, 0, 0 );
   if( rc != 0 ) {
      fskit_error("fskit_mkdir('%s') rc = %d\n", path, rc );
      return rc;
   }

   char* new_path_1 = fskit_fullpath( path, "L", NULL );
   char* new_path_2 = fskit_fullpath( path, "R", NULL );

   rc = fskit_test_mkdir_LR_recursive( core, new_path_1, depth - 1 );
   if( rc != 0 ) {
      fskit_error("fskit_test_mkdir_LR_recursive('%s') rc = %d\n", new_path_1, rc );

      free( new_path_1 );
      free( new_path_2 );
      return rc;
   }

   rc = fskit_test_mkdir_LR_recursive( core, new_path_2, depth - 1 );
   if( rc != 0 ) {
      fskit_error("fskit_test_mkdir_LR_recursive('%s') rc = %d\n", new_path_2, rc );

      free( new_path_1 );
      free( new_path_2 );
      return rc;
   }

   free( new_path_1 );
   free( new_path_2 );

   return 0;
}
Beispiel #28
0
// verify that a given process created the given file
// return 0 if not equal 
// return 1 if equal 
// return negative on error
int runfs_inode_is_created_by_proc( struct runfs_inode* inode, struct pstat* proc_stat, int verify_discipline ) {
   
   int flags = 0;
   
   if( verify_discipline & RUNFS_VERIFY_HASH ) {
      flags |= PSTAT_HASH;
   }
   
   if( !proc_stat->running ) {
   
      fskit_debug("PID %d is not running\n", proc_stat->pid );
      return 0;
   }
   
   if( proc_stat->pid != inode->ps.pid ) {
      
      fskit_debug("PID mismatch: %d != %d\n", inode->ps.pid, proc_stat->pid );
      return 0;
   }
   
   if( verify_discipline & RUNFS_VERIFY_INODE ) {
      if( proc_stat->deleted || inode->ps.bin_stat.st_ino != proc_stat->bin_stat.st_ino ) {
         
         fskit_debug("%d: Inode mismatch: %ld != %ld\n", inode->ps.pid, inode->ps.bin_stat.st_ino, proc_stat->bin_stat.st_ino );
         return 0;
      }
   }
   
   if( verify_discipline & RUNFS_VERIFY_SIZE ) {
      if( proc_stat->deleted || inode->ps.bin_stat.st_size != proc_stat->bin_stat.st_size ) {
         
         fskit_debug("%d: Size mismatch: %jd != %jd\n", inode->ps.pid, inode->ps.bin_stat.st_size, proc_stat->bin_stat.st_size );
         return 0;
      }
   }
   
   if( verify_discipline & RUNFS_VERIFY_MTIME ) {
      if( proc_stat->deleted || inode->ps.bin_stat.st_mtim.tv_sec != proc_stat->bin_stat.st_mtim.tv_sec || inode->ps.bin_stat.st_mtim.tv_nsec != proc_stat->bin_stat.st_mtim.tv_nsec ) {
         
         fskit_debug("%d: Modtime mismatch: %ld.%d != %ld.%d\n", inode->ps.pid, inode->ps.bin_stat.st_mtim.tv_sec, inode->ps.bin_stat.st_mtim.tv_nsec, proc_stat->bin_stat.st_mtim.tv_sec, proc_stat->bin_stat.st_mtim.tv_nsec );
         return 0;
      }
   }
   
   if( verify_discipline & RUNFS_VERIFY_PATH ) {
      if( proc_stat->deleted || strcmp(proc_stat->path, inode->ps.path) != 0 ) {
         
         fskit_debug("%d: Path mismatch: %s != %s\n", inode->ps.pid, inode->ps.path, proc_stat->path );
         return 0;
      }
   }
   
   if( verify_discipline & RUNFS_VERIFY_HASH ) {
      if( proc_stat->deleted || memcmp( proc_stat->sha256, inode->ps.sha256, SHA256_DIGEST_LENGTH ) != 0 ) {
         
         fskit_debug("%d: Hash mismatch\n", inode->ps.pid );
         return 0;
      }
   }
   
   return 1;
}
Beispiel #29
0
// run fskit with fuse
int fskit_fuse_main( struct fskit_fuse_state* state, int argc, char** argv ) {

   int rc = 0;

   // set up FUSE
   struct fuse_args args = FUSE_ARGS_INIT(argc, argv);
   struct fuse_chan* ch = NULL;
   struct fuse* fs = NULL;
   int multithreaded = 1;
   int foreground = 0;
   char* mountpoint = NULL;

   // parse command-line...
   rc = fuse_parse_cmdline( &args, &mountpoint, &multithreaded, &foreground );
   if( rc < 0 ) {

      fskit_error("fuse_parse_cmdline rc = %d\n", rc );
      fuse_opt_free_args(&args);

      return rc;
   }

   if( mountpoint == NULL ) {

      fskit_error("%s", "No mountpoint given\n");
      fuse_opt_free_args(&args);

      return rc;
   }

   state->mountpoint = strdup( mountpoint );

   // mount
   ch = fuse_mount( mountpoint, &args );
   if( ch == NULL ) {

      rc = -errno;
      fskit_error("fuse_mount failed, errno = %d\n", rc );

      fuse_opt_free_args(&args);

      if( rc == 0 ) {
          rc = -EPERM;
      }

      return rc;
   }

   // create the filesystem
   fs = fuse_new( ch, &args, &state->ops, sizeof(state->ops), state );
   fuse_opt_free_args(&args);

   if( fs == NULL ) {

      // failed
      rc = -errno;
      fskit_error("fuse_new failed, errno = %d\n", rc );

      fuse_unmount( mountpoint, ch );

      if( rc == 0 ) {
          rc = -EPERM;
      }

      return rc;
   }

   // daemonize if running in the background
   fskit_debug("FUSE daemonize: foreground=%d\n", foreground);
   rc = fuse_daemonize( foreground );
   if( rc != 0 ) {

      // failed
      fskit_error("fuse_daemonize(%d) rc = %d\n", foreground, rc );

      fuse_unmount( mountpoint, ch );
      fuse_destroy( fs );

      return rc;
   }

   // set up FUSE signal handlers
   rc = fuse_set_signal_handlers( fuse_get_session(fs) );
   if( rc < 0 ) {

      // failed
      fskit_error("fuse_set_signal_handlers rc = %d\n", rc );

      fuse_unmount( mountpoint, ch );
      fuse_destroy( fs );
      return rc;
   }

   // if we have a post-mount callback, call it now, since FUSE is ready to receive requests
   if( state->postmount != NULL ) {

      rc = (*state->postmount)( state, state->postmount_cls );
      if( rc != 0 ) {

         fskit_error("fskit postmount callback rc = %d\n", rc );

         fuse_unmount( mountpoint, ch );
         fuse_destroy( fs );

         return rc;
      }
   }

   // run the filesystem--start processing requests
   fskit_debug("%s", "FUSE main loop entered\n");
   if( multithreaded ) {
      rc = fuse_loop_mt( fs );
   }
   else {
      rc = fuse_loop( fs );
   }

   fskit_debug("%s", "FUSE main loop finished\n");
   fuse_teardown( fs, mountpoint );

   return rc;
}