Changeset 9

Show
Ignore:
Timestamp:
10/28/07 17:19:29 (1 year ago)
Author:
nlawren2
Message:

Added read support

Files:

Legend:

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

    r8 r9  
    7070 
    7171static int tarfs_read(const char *file_path, void *buffer, size_t size, off_t offset, struct fuse_file_info *fi); 
    72 //(FILE *file, inode *file_tree, char *file_path){ 
    73         char buffer[BLOCK_SIZE]; 
    7472        char *result; 
    7573        char delims[]="/"; 
    7674        inode *i=file_tree, *node; 
    77         int size; 
    78          
    79          
     75        size_t len; 
     76 
    8077        /* Traverse the file tree */ 
    8178        result=strtok(file_path, delims); 
     
    8986                                else{ 
    9087                                        node=i; 
    91                                         goto print
     88                                        goto read
    9289                                } 
    9390                        } 
     
    9794        } 
    9895 
    99         return NULL; 
    100  
    101 print: 
    102         /* Print out the file */ 
    103         size=node->file_length; 
    104         fseek(file, node->block_offset, SEEK_SET); 
    105         for(; size > BLOCK_SIZE; size -=BLOCK_SIZE){ 
    106                 fread(buffer, sizeof(char), BLOCK_SIZE, file); 
    107                 fwrite(buffer, sizeof(char), BLOCK_SIZE, stdout); // <<< 
    108         } 
    109  
    110         fread(buffer, sizeof(char), size, file); 
    111         fwrite(buffer, sizeof(char), size, stdout); // <<< 
     96        return -ENOENT; 
     97 
     98read: 
     99        /* Get the file length */ 
     100        len=node->file_length; 
     101 
     102        if (offset < len) { 
     103                /* Seek to the position of the file in the tar */ 
     104                fseek(file, node->block_offset, SEEK_SET); 
     105 
     106                /* Seek to the requested offset */ 
     107                fseek(file, offset, SEEK_CUR); 
     108 
     109                /* Do the actual read */ 
     110                size = fread(buffer, sizeof(char), len, file); 
     111        } else 
     112                size = 0; 
    112113 
    113114        fflush(file); 
    114         fflush(stdout); 
    115         return node;     
     115        return size;     
    116116} 
    117117