Changeset 12
- Timestamp:
- 10/28/07 17:40:01 (10 months ago)
- Files:
-
- tarfs/tarfs.c (modified) (11 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tarfs/tarfs.c
r11 r12 1 1 #include <stdlib.h> 2 2 #include <stdio.h> 3 4 #include <errno.h> 5 #include <fcntl.h> 3 6 4 7 #include <string.h> … … 17 20 #define false 0 18 21 #define eprintf(...) fprintf(stderr, __VA_ARGS__) 22 19 23 20 24 typedef struct posix_header posix_header; … … 69 73 70 74 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];72 75 char *result; 73 76 char delims[]="/"; 74 77 inode *i=file_tree, *node; 75 int size;76 78 77 79 /* Traverse the file tree */ … … 104 106 } 105 107 106 static int tarfs_getattr(const char *, struct stat*)108 static int tarfs_getattr(const char *file_path, struct stat *stbuf) 107 109 { 108 110 int res = 0; … … 112 114 } 113 115 114 static int tarfs_read(const char *file_path, void *buffer, size_t size, off_t offset, struct fuse_file_info *fi) ;116 static int tarfs_read(const char *file_path, void *buffer, size_t size, off_t offset, struct fuse_file_info *fi){ 115 117 char *result; 116 118 char delims[]="/"; … … 144 146 if (offset < len) { 145 147 /* Seek to the position of the file in the tar */ 146 fseek( file, node->block_offset, SEEK_SET);148 fseek(tar_file, node->block_offset, SEEK_SET); 147 149 148 150 /* Seek to the requested offset */ 149 fseek( file, offset, SEEK_CUR);151 fseek(tar_file, offset, SEEK_CUR); 150 152 151 153 /* Do the actual read */ 152 size = fread(buffer, sizeof(char), len, file);154 size = fread(buffer, sizeof(char), len, tar_file); 153 155 } else 154 156 size = 0; 155 157 156 fflush( file);157 return size; 158 fflush(tar_file); 159 return size; 158 160 } 159 161 … … 234 236 while(i){ 235 237 if(i->subdir && !i->special ) 236 destroy_file_tree(i->subdir);238 tarfs_destroy(i->subdir); 237 239 j=i; 238 240 i=i->next; … … 254 256 printf("%s%s (offset=%i, length=%i)\n",tabs,i->file_name,i->block_offset,i->file_length); 255 257 if( i->subdir && !i->special ) 256 print_tree(i->subdir, tab+3);258 tarfs_print(i->subdir, tab+3); 257 259 i=i->next; 258 260 } … … 266 268 .readdir = tarfs_readdir, 267 269 .destroy = tarfs_destroy 268 } 270 }; 269 271 270 272 int main(int argc, char **argv){ … … 276 278 case 'f': 277 279 { 278 tar_file = fopen(optarg );280 tar_file = fopen(optarg, "r"); 279 281 if( !tar_file ){ 280 282 eprintf("Invalid filename: %s\n", optarg); … … 299 301 } 300 302 301 return fuse_main(argc, argv, tarfs_opers);302 } 303 return fuse_main(argc, argv, &tarfs_oper); 304 }
