示例#1
0
int fskit_fuse_mkdir(const char *path, mode_t mode) {

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

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

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

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

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

   return rc;
}
示例#2
0
文件: common.cpp 项目: jaromil/fskit
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;
}
示例#3
0
int main( int argc, char** argv ) {

   struct fskit_core core;
   int rc;
   void* output;
   struct fskit_path_iterator* itr = NULL;
   struct fskit_file_handle* fh = NULL;

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

   rc = fskit_test_mkdir_LR_recursive( &core, "/root", 7 );
   if( rc != 0 ) {
      fskit_error("fskit_test_mkdir_LR_recursive('/root') rc = %d\n", rc );
      exit(1);
   }
   
   fh = fskit_create( &core, "/root/L/R/L/R/L/R/.foo", 0, 0, 0777, &rc );
   if( fh == NULL ) {
      fskit_error("fskit_create('/root/L/R/L/R/L/R/.foo') rc = %d\n", rc );
      exit(1);
   }
   
   fskit_close( &core, fh );
   
   fh = fskit_create( &core, "/bar.f", 0, 0, 0777, &rc );
   if( fh == NULL ) {
      fskit_error("fskit_create('/bar.f') rc = %d\n", rc );
      exit(1);
   }
   
   fskit_close( &core, fh );
   
   rc = fskit_mkdir( &core, "/bar.d", 0755, 0, 0 );
   if( rc < 0 ) {
      fskit_error("fskit_mkdir('/bar.d') rc = %d\n", rc );
      exit(1);  
   }
   
   /////////////////////////////////////////////////////////////////////////////////////
   printf("\n\nIterate succeeds...\n\n");
   
   for( itr = fskit_path_begin( &core, "/root/L/R/L/R/L/R/.foo", true ); !fskit_path_end( itr ); fskit_path_next( itr ) ) {
      
      struct fskit_entry* cur = fskit_path_iterator_entry( itr );
      char* cur_path = fskit_path_iterator_path( itr );
      
      printf("Entry %016" PRIX64 " (%p): %c %s\n", fskit_entry_get_file_id( cur ), cur, fskit_entry_get_type( cur ) == FSKIT_ENTRY_TYPE_FILE ? 'F' : 'D', cur_path );
      
      free( cur_path );
   }
   
   printf("Iterator error: %d\n", fskit_path_iterator_error( itr ) );
   
   fskit_path_iterator_release( itr );
   
   
   printf("\n\n");
   
   
   for( itr = fskit_path_begin( &core, "/bar.f", true ); !fskit_path_end( itr ); fskit_path_next( itr ) ) {
      
      struct fskit_entry* cur = fskit_path_iterator_entry( itr );
      char* cur_path = fskit_path_iterator_path( itr );
      
      printf("Entry %016" PRIX64 " (%p): %c %s\n", fskit_entry_get_file_id( cur ), cur, fskit_entry_get_type( cur ) == FSKIT_ENTRY_TYPE_FILE ? 'F' : 'D', cur_path );
      
      free( cur_path );
   }
   
   printf("Iterator error: %d\n", fskit_path_iterator_error( itr ) );
   
   fskit_path_iterator_release( itr );
   
   
   printf("\n\n");
   
   
   for( itr = fskit_path_begin( &core, "/bar.d", true ); !fskit_path_end( itr ); fskit_path_next( itr ) ) {
      
      struct fskit_entry* cur = fskit_path_iterator_entry( itr );
      char* cur_path = fskit_path_iterator_path( itr );
      
      printf("Entry %016" PRIX64 " (%p): %c %s\n", fskit_entry_get_file_id( cur ), cur, fskit_entry_get_type( cur ) == FSKIT_ENTRY_TYPE_FILE ? 'F' : 'D', cur_path );
      
      free( cur_path );
   }
   
   printf("Iterator error: %d\n", fskit_path_iterator_error( itr ) );
   
   fskit_path_iterator_release( itr );
   
   
   /////////////////////////////////////////////////////////////////////////////////////
   printf("\n\nIterate succeeds on path with duplicate . and /...\n\n");
   
   for( itr = fskit_path_begin( &core, "././root/L/R//L//././/R/L//.///R", true ); !fskit_path_end( itr ); fskit_path_next( itr ) ) {
      
      struct fskit_entry* cur = fskit_path_iterator_entry( itr );
      char* cur_path = fskit_path_iterator_path( itr );
      
      printf("Entry %016" PRIX64 " (%p): %c %s\n", fskit_entry_get_file_id( cur ), cur, fskit_entry_get_type( cur ) == FSKIT_ENTRY_TYPE_FILE ? 'F' : 'D', cur_path );
      
      free( cur_path );
   }

   printf("Iterator error: %d\n", fskit_path_iterator_error( itr ) );

   fskit_path_iterator_release( itr );
      
   printf("\n\n");
   
   for( itr = fskit_path_begin( &core, "/././root///././/.//.", true ); !fskit_path_end( itr ); fskit_path_next( itr ) ) {
      
      struct fskit_entry* cur = fskit_path_iterator_entry( itr );
      char* cur_path = fskit_path_iterator_path( itr );
      
      printf("Entry %016" PRIX64 " (%p): %c %s\n", fskit_entry_get_file_id( cur ), cur, fskit_entry_get_type( cur ) == FSKIT_ENTRY_TYPE_FILE ? 'F' : 'D', cur_path );
      
      free( cur_path );
   }

   printf("Iterator error: %d\n", fskit_path_iterator_error( itr ) );

   fskit_path_iterator_release( itr );
      
   /////////////////////////////////////////////////////////////////////////////////////
   printf("\n\nIterate fails (path too long)...\n\n");
   
   for( itr = fskit_path_begin( &core, "/root/L/R/L/R/L/R/L/R/L/R/L/R/L/R/L/R", true ); !fskit_path_end( itr ); fskit_path_next( itr ) ) {
      
      struct fskit_entry* cur = fskit_path_iterator_entry( itr );
      char* cur_path = fskit_path_iterator_path( itr );
      
      printf("Entry %016" PRIX64 " (%p): %c %s\n", fskit_entry_get_file_id( cur ), cur, fskit_entry_get_type( cur ) == FSKIT_ENTRY_TYPE_FILE ? 'F' : 'D', cur_path );
      
      free( cur_path );
   }
   
   printf("Iterator error: %d\n", fskit_path_iterator_error( itr ) );
   
   fskit_path_iterator_release( itr );
   
   /////////////////////////////////////////////////////////////////////////////////////
   printf("\n\nIterate fails (path does not exist)...\n\n");
   
   for( itr = fskit_path_begin( &core, "/root/L/R/L/foo/L/R", true ); !fskit_path_end( itr ); fskit_path_next( itr ) ) {
      
      struct fskit_entry* cur = fskit_path_iterator_entry( itr );
      char* cur_path = fskit_path_iterator_path( itr );
      
      printf("Entry %016" PRIX64 " (%p): %c %s\n", fskit_entry_get_file_id( cur ), cur, fskit_entry_get_type( cur ) == FSKIT_ENTRY_TYPE_FILE ? 'F' : 'D', cur_path );
      
      free( cur_path );
   }
   
   printf("Iterator error: %d\n\n\n", fskit_path_iterator_error( itr ) );
   
   fskit_path_iterator_release( itr );
   
   fskit_test_end( &core, &output );

   return 0;
}
示例#4
0
int main( int argc, char** argv ) {

   struct fskit_core core;
   int rc;
   char name_buf[10];
   char name_buf2[10];

   struct fskit_file_handle* fh = NULL;
   void* output;

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

   // setup
   for( int i = 0; i < 10; i++ ) {

      // create /a$i

      memset(name_buf, 0, 10 );
      sprintf(name_buf, "/a%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 );

      // mkdir /d$i

      memset(name_buf, 0, 10 );
      sprintf(name_buf, "/d%d", i );

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

   printf("Initial tree:\n");
   fskit_print_tree( stdout, &core.root );

   // rename in the same directory
   // rename /a$i to /b$i
   for( int i = 0; i < 10; i++ ) {

      memset(name_buf, 0, 10 );
      memset(name_buf2, 0, 10 );

      sprintf(name_buf, "/a%d", i );
      sprintf(name_buf2, "/b%d", i );

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

   printf("Rename /a$i to /b$i");
   fskit_print_tree( stdout, &core.root );

   // rename into a deeper directory
   // rename /b$i to /d$i/a$i
   for( int i = 0; i < 10; i++ ) {

      memset(name_buf, 0, 10 );
      memset(name_buf2, 0, 10 );

      sprintf(name_buf, "/b%d", i );
      sprintf(name_buf2, "/d%d/a%d", i, i );

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


   printf("Rename /b$i to /d$i/a$i");
   fskit_print_tree( stdout, &core.root );

   // rename into a shallower directory
   // rename /d$i/a$i to /a$i
   for( int i = 0; i < 10; i++ ) {

      memset(name_buf, 0, 10 );
      memset(name_buf2, 0, 10 );

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

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

   printf("Rename /d/a$i to /a$i");
   fskit_print_tree( stdout, &core.root );

   fskit_test_end( &core, &output );

   return 0;
}