Changeset 25

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
  • vowfs/db.hxx

    r24 r25  
    1 #include "common.hxx" 
     1#ifndef _VoWFS_Database_Header 
     2#define _VoWFS_Database_Header 
     3 
     4#include <postgresql/postgres.hxx> 
     5#include "vowfs.hxx" 
     6 
     7/* TODO: Implement all get-er functions 
     8 *       It isn't too difficult, but we  
     9 *       need all of the SQL queries for 
     10 *       them. 
     11 */ 
    212 
    313namespace VoWFS{ 
    414        class Database{ 
    515        private: 
     16                PQconn *connection; 
    617 
    718        public: 
    8                 Database(); 
    9  
    1019                Database(string host, int port, string db_name, string user, string password); 
     20                ~Database(); 
    1121 
    1222                // File Handling Functions 
     
    1727                File getFile(int file_id, int revision); 
    1828 
     29 
    1930                // Directory Handling Functions 
    2031                int getDirId(string dir_path); 
     
    2435                Dir getDir(int dir_id, int revision); 
    2536 
     37 
    2638                // Modular Command for SQL Queries 
    2739                list<File> getFiles(string sql_command); 
     
    2941                list<Dir>  getDirs(string sql_command); 
    3042 
    31  
    3243        }; 
    3344}; 
     45 
     46#endif 
     47 
  • vowfs/dir.hxx

    r23 r25  
    1 #include "common.hxx" 
     1#ifndef _VoWFS_Directory_Header_ 
     2#define _VoWFS_Directory_Header_ 
     3 
     4#include "vowfs.hxx" 
    25 
    36namespace VoWFS{ 
     
    710 
    811        private: 
    9                 // The connection to the databse 
    1012                static int Database db; 
    1113 
     
    2830 
    2931        public: 
     32                Dir(); 
     33                Dir(Databse db); 
     34 
     35                // TODO: Fill dir 
     36                Dir(PQresult *pqdata, int row); 
     37 
    3038                int revisionId(){ 
    3139                        return revision_id; 
     
    5664                } 
    5765 
    58                 // TODO Query the databse, get the data, and return it 
    59                 list<File> listFileContents(); 
     66                list<File> listFileContents(){ 
     67                        // TODO: What is the Query for Files 
     68                        return file_list=db.getFiles(""); 
     69                } 
     70                         
    6071                 
    61                 // TODO Query the databse, get the data, and return it 
    62                 list<File> listDirContents(); 
     72                list<File> listDirContents(){ 
     73                        // TODO: What is the Query for Directories 
     74                        return dir_list=db.getDirs(""); 
     75                } 
    6376        }; 
    6477}; 
     78 
     79#endif 
     80 
  • vowfs/file.hxx

    r22 r25  
    1 #include "common.hxx" 
     1#ifndef _VoWFS_File_Header_ 
     2#define _VoWFS_File_Header_ 
     3 
     4#include "vowfs.hxx" 
    25 
    36namespace VoWFS{ 
    47        class File{ 
    5  
    6         friend class Database; 
    7  
    88        private: 
    9                 // The connection to the databse 
    109                static int Database db; 
     10                 
     11                static int XDelta diff; 
    1112 
    1213                int revision_id; 
     
    1516                int parent_dir_id; 
    1617 
    17                 /* file_size should also be stored in the databse so that 
    18                  * the data does not need to be requested for a file that we 
    19                  * only need the size of (i.e. for a directory listing).  It 
    20                  * also provides a mechanism for error checking 
     18                /* file_size should also be stored in the databse because the 
     19                 * size of the diff is different than the size of the expanded 
     20                 * file. 
    2121                 */ 
    2222                int file_size; 
     
    3838 
    3939        public: 
     40                File(); 
     41 
     42                File(Databse db, XDelta diff); 
     43 
     44                // TODO: Fill file 
     45                File(PQresult *pqdata, int row); 
     46 
    4047                int revisionId(){ 
    4148                        return revision_id; 
     
    7885                } 
    7986 
    80                 // TODO Query the databse, get the data, and return it 
    81                 char *fileData(); 
     87                char *readData(); 
    8288        }; 
    8389}; 
     90 
     91#endif 
     92