| 67 | | static int tarfs_readdir(const char *file_path, void *buffer, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi); |
|---|
| 68 | | |
|---|
| 69 | | static int tarfs_getattr(const char*, struct stat*) |
|---|
| 70 | | { |
|---|
| 71 | | int res = 0; |
|---|
| 72 | | |
|---|
| 73 | | stbuf->st_mode = S_IFDIR | 0555; |
|---|
| 74 | | stbuf->st_nlink = 2; |
|---|
| 75 | | return res; |
|---|
| 76 | | } |
|---|
| 77 | | |
|---|
| 78 | | static int tarfs_read(const char *file_path, void *buffer, size_t size, off_t offset, struct fuse_file_info *fi); |
|---|
| | 70 | static int tarfs_readdir(const char *file_path, void *buffer, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi){ |
|---|
| | 71 | char buffer[BLOCK_SIZE]; |
|---|
| | 87 | return -ENOENT; |
|---|
| | 88 | } |
|---|
| | 89 | } |
|---|
| | 90 | i=i->next; |
|---|
| | 91 | } |
|---|
| | 92 | result=strtok(NULL, delims); |
|---|
| | 93 | } |
|---|
| | 94 | |
|---|
| | 95 | return -ENOENT; |
|---|
| | 96 | |
|---|
| | 97 | readdir: |
|---|
| | 98 | while(i){ |
|---|
| | 99 | filler(buffer,i->file_name,NULL,0); |
|---|
| | 100 | i=i->next; |
|---|
| | 101 | } |
|---|
| | 102 | |
|---|
| | 103 | return 0; |
|---|
| | 104 | } |
|---|
| | 105 | |
|---|
| | 106 | static int tarfs_getattr(const char*, struct stat*) |
|---|
| | 107 | { |
|---|
| | 108 | int res = 0; |
|---|
| | 109 | stbuf->st_mode = S_IFDIR | 0555; |
|---|
| | 110 | stbuf->st_nlink = 2; |
|---|
| | 111 | return res; |
|---|
| | 112 | } |
|---|
| | 113 | |
|---|
| | 114 | static int tarfs_read(const char *file_path, void *buffer, size_t size, off_t offset, struct fuse_file_info *fi); |
|---|
| | 115 | char *result; |
|---|
| | 116 | char delims[]="/"; |
|---|
| | 117 | inode *i=file_tree, *node; |
|---|
| | 118 | size_t len; |
|---|
| | 119 | |
|---|
| | 120 | /* Traverse the file tree */ |
|---|
| | 121 | result=strtok(file_path, delims); |
|---|
| | 122 | while( result != NULL ){ |
|---|
| | 123 | while(i){ |
|---|
| | 124 | if(!strcmp(result, i->file_name)){ |
|---|
| | 125 | if(i->subdir){ |
|---|
| | 126 | i=i->subdir; |
|---|
| | 127 | break; |
|---|
| | 128 | } |
|---|
| | 129 | else{ |
|---|
| 228 | | // Getopts to parse -f filepath |
|---|
| 229 | | |
|---|
| 230 | | char filepath[NAME_SIZE]; |
|---|
| 231 | | if(argc < 2){ |
|---|
| 232 | | eprintf("Use %s filename", argv[0]); |
|---|
| | 271 | int c; |
|---|
| | 272 | |
|---|
| | 273 | /* Parse filepath and initialize the file tree */ |
|---|
| | 274 | while( (c=getopt(argc, argv, "f")) != -1 ){ |
|---|
| | 275 | switch(c){ |
|---|
| | 276 | case 'f': |
|---|
| | 277 | { |
|---|
| | 278 | tar_file = fopen(optarg); |
|---|
| | 279 | if( !tar_file ){ |
|---|
| | 280 | eprintf("Invalid filename: %s\n", optarg); |
|---|
| | 281 | return 1; |
|---|
| | 282 | } |
|---|
| | 283 | file_tree=tarfs_init(tar_file); |
|---|
| | 284 | if( !file_tree ){ |
|---|
| | 285 | eprintf("Invalid file: %s\n", optarg); |
|---|
| | 286 | return 1; |
|---|
| | 287 | } |
|---|
| | 288 | break; |
|---|
| | 289 | } |
|---|
| | 290 | case '?': |
|---|
| | 291 | default: |
|---|
| | 292 | break; |
|---|
| | 293 | } |
|---|
| | 294 | } |
|---|
| | 295 | |
|---|
| | 296 | if( !file_tree ){ |
|---|
| | 297 | eprintf("Use: %s -f filepath\n", argv[0]); |
|---|
| 236 | | tar_file = fopen(argv[1],"r"); |
|---|
| 237 | | if( tar_file == NULL ){ |
|---|
| 238 | | eprintf("Invalid filename: %s", argv[1]); |
|---|
| 239 | | return 1; |
|---|
| 240 | | } |
|---|
| 241 | | |
|---|
| 242 | | file_tree=create_file_tree(tar_file); |
|---|
| 243 | | if( file_tree == NULL ){ |
|---|
| 244 | | eprintf("Invalid filetype: %s", argv[1]); |
|---|
| 245 | | return 1; |
|---|
| 246 | | } |
|---|
| 247 | | |
|---|
| 248 | | inode *i=read_file(tar_file, file_tree, filepath); |
|---|
| 249 | | |
|---|
| 250 | | if( i == NULL ){ |
|---|
| 251 | | eprintf("Invalid filename: %s", filepath); |
|---|
| 252 | | return 1; |
|---|
| 253 | | } |
|---|
| 254 | | |
|---|
| 255 | | // fuse_main |
|---|
| 256 | | |
|---|
| 257 | | destroy_file_tree(file_tree); |
|---|
| 258 | | |
|---|
| 259 | | return 0; |
|---|
| 260 | | } |
|---|
| | 301 | return fuse_main(argc, argv, tarfs_opers); |
|---|
| | 302 | } |
|---|