Changeset 25 for tarfs

Show
Ignore:
Timestamp:
11/04/07 00:19:11 (1 year ago)
Author:
nlawren2
Message:

Wrote some more code, did some homework, and got TarFS to accept command line arguments

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • tarfs/tarfs.c

    r20 r25  
    1010 
    1111#include <fuse.h> 
    12  
    13 #include "zlib.h" 
    14 #include "bzlib.h" 
    1512 
    1613#include "tar.h" 
     
    196193 
    197194        /* Create a root directory of the tree */ 
    198         new=file_tree=create_dir(NULL); 
     195        file_tree=create_dir(NULL); 
    199196 
    200197        while(true){ 
     
    238235                        else 
    239236                                return NULL; 
    240                  
    241                 /* Add inode attributes */ 
    242                 int name_size=strlen(result); 
    243                 memmove(new->file_name, result, name_size); 
    244                 new->file_name[name_size]='\0'; 
     237        /* Add inode attributes */ int name_size=strlen(result); memmove(new->file_name, result, name_size); new->file_name[name_size]='\0'; 
    245238                 
    246239                switch(header.typeflag){ 
     
    264257                /* Jump to the next header */    
    265258                fseek(file, new->block_length, SEEK_CUR); 
     259 
    266260        } 
    267261        fflush(file); 
     
    313307int main(int argc, char **argv){ 
    314308        /* Parse filepath and initialize the file tree */ 
    315         /* 
    316         int c; 
    317         while( (c=getopt(argc, argv, "f:")) != -1 ){ 
    318                 switch(c){ 
    319                 case 'f': 
    320                 { 
    321                         tar_file = fopen(optarg, "r"); 
    322                         if( !tar_file ){ 
    323                                 eprintf("Invalid filename: %s\n", optarg); 
    324                                 return 1; 
    325                         } 
    326                         file_tree=tarfs_init(tar_file); 
    327                         if( !file_tree ){ 
    328                                 eprintf("Invalid file: %s\n", optarg); 
    329                                 return 1; 
    330                         } 
    331                         break; 
    332                 } 
    333                 case '?': 
    334                 default: 
    335                         break; 
    336                 } 
    337         } 
    338          
     309        if( argc != 3 ){ 
     310                eprintf("Use: %s directory filepath\n", argv[0]); 
     311                return 1; 
     312        } 
     313 
     314        tar_file = fopen(argv[2], "r"); 
     315        if( !tar_file ){ 
     316                eprintf("Invalid filename: %s\n", argv[2]); 
     317                return 1; 
     318        } 
     319         
     320        file_tree=tarfs_init(tar_file); 
    339321        if( !file_tree ){ 
    340                 eprintf("Use: %s -f filepath\n", argv[0]); 
     322                eprintf("Invalid filetype: %s\n", argv[2]); 
    341323                return 1; 
    342         }*/ 
    343         tar_file = fopen("./contrib.tar", "r"); 
    344          
    345         file_tree=tarfs_init(tar_file); 
    346          
    347         if( !file_tree ){ 
    348                 eprintf("A fatal error occoured...\n"); 
    349                 return 1; 
    350         } 
    351         else{ 
    352                 return fuse_main(argc, argv, &tarfs_oper); 
    353         } 
    354 
     324        } 
     325         
     326        return fuse_main(argc-1, argv, &tarfs_oper); 
     327