Changeset 7
- Timestamp:
- 10/28/07 16:45:16 (1 year ago)
- Files:
-
- tarfs/tarfs.c (modified) (9 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
tarfs/tarfs.c
r6 r7 3 3 #include <string.h> 4 4 5 //#include <fuse/fuse.h>6 //#include <fuse.h>5 #include <fuse/fuse.h> 6 #include <fuse.h> 7 7 8 8 #include "tar.h" … … 33 33 bool special; // if . or .. 34 34 }; 35 36 FILE *tar_file; 37 inode *file_tree; 35 38 36 39 inode *create_dir(inode *parent){ … … 53 56 } 54 57 55 inode *read_file(FILE *file, inode *file_tree, char *file_path){ 58 static int tarfs_open(const char *file_path, struct fuse_file_info *fi); 59 60 static int tarfs_readdir(const char *file_path, void *buffer, fuse_fill_dir_t filler, off_t offset, struct fuse_file_info *fi); 61 62 static int tarfs_getattr(const char*, struct stat*); 63 64 static int tarfs_read(const char *file_path, void *buffer, size_t size, off_t offset, struct fuse_file_info *fi); 65 //(FILE *file, inode *file_tree, char *file_path){ 56 66 char buffer[BLOCK_SIZE]; 57 67 char *result; 58 char delims[]="/ \n";68 char delims[]="/"; 59 69 inode *i=file_tree, *node; 60 70 int size; … … 88 98 for(; size > BLOCK_SIZE; size -=BLOCK_SIZE){ 89 99 fread(buffer, sizeof(char), BLOCK_SIZE, file); 90 fwrite(buffer, sizeof(char), BLOCK_SIZE, stdout); 100 fwrite(buffer, sizeof(char), BLOCK_SIZE, stdout); // <<< 91 101 } 92 102 93 103 fread(buffer, sizeof(char), size, file); 94 fwrite(buffer, sizeof(char), size, stdout); 104 fwrite(buffer, sizeof(char), size, stdout); // <<< 95 105 96 106 fflush(file); … … 99 109 } 100 110 101 inode * create_file_tree(FILE *file){111 inode *tarfs_init(FILE *file){ 102 112 char buffer[BLOCK_SIZE]; 103 113 char *result; … … 170 180 } 171 181 172 void destroy_file_tree(inode *file_tree){182 void tarfs_destroy(inode *file_tree){ 173 183 inode *i=file_tree, *j; 174 184 … … 184 194 185 195 186 void print_tree(inode *file_tree, int tab){196 void tarfs_print(inode *file_tree, int tab){ 187 197 inode *i=file_tree; 188 198 … … 202 212 203 213 int main(int argc, char **argv){ 204 FILE *tar_file; 214 // Getopts to parse -f filepath 215 205 216 char filepath[NAME_SIZE]; 206 inode *file_tree;207 217 if(argc < 2){ 208 218 eprintf("Use %s filename", argv[0]); … … 222 232 } 223 233 224 print_tree(file_tree,0);225 226 printf("Please enter the name of the file you would like to read:");227 fgets(filepath,NAME_SIZE,stdin);228 229 234 inode *i=read_file(tar_file, file_tree, filepath); 235 230 236 if( i == NULL ){ 231 237 eprintf("Invalid filename: %s", filepath); 232 238 return 1; 233 239 } 240 241 // fuse_main 234 242 235 243 destroy_file_tree(file_tree);
