src/giis.h

Go to the documentation of this file.
00001 /*
00002 * /giis/giis.h - The header file.
00003 *
00004 * gET iT i sAY-giis - EXT3/EXT2 File Undelete Tool. Version 4.1         
00005 * 
00006 * Copyright (C) 2007. G.Lakshmipathi.<lakshmipathi_g@rediffmail.com> <lakshmipathi.g@gmail.com>
00007 *
00008 *
00009 */
00010 
00011         /* List of files to be included */
00012 
00013 #define _LARGEFILE64_SOURCE                     /* lseek64()  */
00014 #define _GNU_SOURCE     
00015         
00016 #include <sys/stat.h>
00017 #include <sys/types.h>
00018 #include <fcntl.h>
00019 #include <unistd.h>
00020 #include <errno.h>
00021 #include <pwd.h>
00022 #include <stdio.h>
00023 #include <stdlib.h>
00024 #include <string.h>
00025 #include <time.h>
00026 #include <linux/ext3_fs.h>
00027 
00028 
00029 #ifndef GIIS_
00030 #define GIIS_
00031 
00032         /* Pre-defined macro */
00033         
00034 #define O_RDONLY             00
00035 #define O_WRONLY             01
00036 #define O_RDWR               02
00037 #define O_CREAT            0100 
00038 #define O_EXCL             0200 
00039 #define O_TRUNC           01000 
00040 
00041 
00042                 /* Some macro's used for reading clarity */
00043 
00044 #define LEVEL_VALUE 11   /*Supports upto 12 levels of sub-dir.(dir1/dir2/dir3.../dir12) */
00045 #define INSTALL_DIR1   "/giis"
00046 #define INSTALL_DIR2   "/giis/sys"
00047 #define INSTALL_DIR3   "/giis/got_it"                   /* Recovered files */
00048 #define INSTALL_DIR4    "/giis/unrecovered"             /* Unrecovered Files List */
00049 
00050 #define DIR_INFO_FILE  "/giis/sys/dir"                  /* Directory informations*/
00051 #define FILE_INFO_FILE "/giis/sys/file"                 /* File informations */
00052 #define SIND_INFO_FILE "/giis/sys/sind"                 /* single indirect blocks */
00053 #define DIND_INFO_FILE "/giis/sys/dind"                 /* Double indirect blocks */
00054 #define SAMPLE_DATA_FILE "/giis/sys/sample"             /* Sample Data File */
00055 #define DEFAULT_OFFSET_OF_SUPER_BLOCK 1024              /* Default offset */
00056 #define ACCESS 0                                        /* Read  only */
00057 #define SUPER_BLOCK_SIZE sizeof(struct ext3_super_block)
00058 #define INODE_SIZE sizeof(struct ext3_inode)
00059 #define GROUP_DESC_SIZE sizeof(struct ext3_group_desc)
00060 #define DIR_SIZE sizeof(struct ext3_dir_entry_2)
00061 #define GIIS_DSIZE sizeof(struct s_dir_recover_info)
00062 #define GIIS_FSIZE sizeof(struct s_file_recover_info)
00063 #define GIIS_SSIZE sizeof(struct s_sample_file_data)
00064 
00065 #define ROOT_INODE 2
00066 #define RANGE 4294967295
00067 #define CHECK   if(i==-1) \
00068                 ERROR   \
00069 
00070 
00071 #define ERROR   { \
00072                 perror(""); \
00073                 printf("Error Number:%d",errno); \
00074                 return -1;\
00075                 } \
00076 
00077 
00078         /* Buffers which will be loaded with corresponding structures */
00079 
00080 union get_ext_super_block{
00081         struct ext3_super_block sb;
00082         char buffer[sizeof(struct ext3_super_block)];
00083         }isb;
00084 
00085 union get_ext_group_desc{
00086         struct ext3_group_desc gd;
00087         char buffer[sizeof(struct ext3_group_desc)];
00088         }igd;
00089 
00090 union get_ext_inode{
00091         struct ext3_inode in;
00092         char buffer[sizeof(struct ext3_inode)];
00093         }iin;
00094 union get_ext_dir{
00095         struct ext3_dir_entry_2 de;
00096         char buffer[sizeof(struct ext3_dir_entry_2)];
00097         }ide;
00098 
00099                                 /* Contains file system Infomations */
00100 struct file_system{
00101         
00102                                         /* Group Specific */
00103 unsigned long group_number;
00104 unsigned long block_bitmap;
00105 unsigned long inode_bitmap;
00106 unsigned long inode_table;
00107 unsigned long free_blocks_count;
00108 unsigned long free_inodes_count;
00109                                          /*General info*/
00110 unsigned long inode_number;
00111 unsigned long block_number;
00112 unsigned long super_block_offset;
00113 unsigned long  group_offset;
00114 unsigned long long inode_offset;        /* Consist of current inodes offset */
00115 unsigned long long root_inode_offset;
00116 unsigned long long device_offset;
00117 unsigned long long content_offset;
00118 unsigned long index_number;             /* Index number in Inode Table of Group Descriptor */
00119                                         /*Obtained info */
00120 unsigned long inodes_per_group;
00121 unsigned long blocks_per_group;
00122 int groups_count;                       /* Total Number of Group Descriptor */
00123 unsigned long long inodes_count;        /* Total Number of inodes in Group Descriptor */
00124 unsigned long long blocks_count;        /* Total Number of blocks in Group Descriptor */
00125 unsigned long long fs_size;             /* File system size */
00126 int inode_table_size;
00127 int inodes_per_block;
00128 int  block_size;
00129 int first_data_block;
00130 int first_group_desc;
00131 
00132 }fs;
00133 
00134                                                 /* information for recovery */
00135 
00136 union u_file_recover_info{
00137 struct s_file_recover_info{
00138         char            date_time[30];            /* When this entry recorded */        
00139         char            name[30];                 /* filename */                
00140         unsigned long   inode_number;             /* inode number */
00141         unsigned long   parent_inode_number;      /* Directory inode number */
00142         int             search_flag;              /* Search flags*/     
00143         int             mode;                     /* File type */
00144         int             owner;                    /* owner's uid */     
00145         unsigned long   file_blocks_count;        /* Blocks count */
00146         unsigned long   file_size;              
00147         unsigned long   file_flags;     
00148         unsigned long   data_block[EXT3_N_BLOCKS];/* Contents pointer */
00149         unsigned long   is_offset; /* Single Indirect Block offset */   
00150         unsigned long   id_offset; /* Double indirect Block offset */
00151         int             sfragment_flag;           /* Which to use */
00152         int             dfragment_flag;
00153         unsigned long   last_data_block;/* Block number where last data remains */
00154         }info;
00155 char buffer[sizeof(struct s_file_recover_info)];
00156 }giis_f;
00157 
00158 union u_dir_recover_info{
00159 struct s_dir_recover_info{
00160         char            date_time[30];            /* When this entry recorded */        
00161         char            name[30];                 /* Directory  name */
00162         unsigned long   inode_number;             /* inode number */
00163         unsigned long   parent_inode_number;      /* Directory inode number */
00164         int             search_flag;              /* Indicates entry search or not */   
00165         }info;
00166 char buffer[sizeof(struct s_dir_recover_info)];
00167 }giis_d,giis_dt;        
00168 
00169 
00170 union u_sample_file_data{
00171 struct s_sample_file_data{
00172         unsigned long   inode_number;             /* inode number */
00173         char sdata[32];                   /* Sample content of file */
00174         }info;
00175 char buffer[sizeof(struct s_sample_file_data)];
00176 }giis_s;
00177 
00178                 /* Single or Double Indirect */
00179 unsigned long idata_block[1024];
00180 
00181 struct passwd *pwfile;                           /* Used for uid verfication */
00182 
00183 
00184 
00185                         /*Global Variables */
00186 int i_round,hole,gd;
00187 char device_name[15],user[25],search_file[30];
00188 int dir,use_uid,install,fd;
00189 int install_file;
00190 int update_file,update_dir;                     /* Required during updates */
00191 int entry,found;                                /* Used in dir.c while recording data */
00192 time_t result;                                  /* time n date  used to ? */
00193 char date_time[25];                             /* specific when entries recorded */
00194 unsigned long long deleted_inode_offset;        /* Deleted inode's offset */
00195 unsigned long size,err_size;                    /* File size used to read a file */
00196 unsigned long home_inode;                       /* inode of /home */
00197 unsigned long root_inode;                       /* inode of /root */
00198 unsigned long s_offy;                           /* SIND offset */
00199 unsigned long d_offy;                           /* DIND offset */
00200 int dir_level;                                  /* Directory depth */
00201 int fileoverwritten;                            /* File modified or overwritten */
00202 int search_format;                              /* Get files using its format */
00203 int startbyte;                                  /* Used in file.c */
00204 int get_version;                                /* version */
00205 int repeat;                             /* For check */
00206 
00207                         /* Function protocols */
00208                 
00209                                 /* dir.c */
00210                         
00211 int set_content_offset();                       /* Sets offset to content of inode */   
00212 int read_dir();                                 /* Load  dirctory  into buffer*/
00213 int record_dir(unsigned long);                  /* Writes data into DIR_INFO_FILE */
00214 int record_file(unsigned long);                 /* Writes data into FILE_INFO_FILE */
00215 int show_dir();                                 /* Display directory */
00216 
00217                                 /* file.c */
00218                         
00219 int read_show_file(int,int);                    /* Read a file  */
00220 int read_dir_info_file();                       /* Reads data from DIR_INFO FILE */
00221 int read_file_info_file();                      /* Reads data from FILE_INFO_FILE */
00222 int read_sind_info_file();                      /* Reads SIND_INFO_FILE */
00223 int read_dind_info_file();                      /* Reads DIND_INFO_FILE */
00224 int read_sample_info_file(unsigned long);       /* Reads SAMPLE_DATA_FILE */
00225 void show_data(char []);                        /* Displays Given Buffer */
00226 int file_repeated(char []);                     /* No.of times entry exists in sys file */
00227                 
00228                 
00229                         /* get_it_i_say.c */
00230 int get_it();                                   /* Search for all deleted file and recover */
00231 int verify_inode(unsigned long);                /* Verifies given inode is free or not */
00232 int get_it_i_say();                             /* Recovers the deleted  file */
00233 int get_data_from_block(int,int,unsigned long); /* Get data from block */
00234 int force_giis();                               /* Get specific file */
00235 
00236 
00237                         /* group.c */
00238 int get_group_desc();                           /* Get request Group Desccriptor */
00239 int eye_on_gd();                                /* Keep track of group */
00240                 
00241                         /* init.c */
00242                 
00243 int search4fs();                                /* Searches for root file system */
00244 int search4super_block();                       /* Searches for superblock */
00245 void set_file_system();                         /* Set file_system for processing */
00246 int search4group_desc();                        /* Searches for group descriptor */
00247 int init();                                     /* Initialize Procedure */
00248 int init_files();                               /* Creates or opens files */
00249 int fs_display();                               /* Display FS info */
00250 
00251                         /* inode.c */
00252                 
00253 int find_inode_offset();                        /* Initialize offset of inode */
00254 int read_inode();                               /* Get inode from offset*/
00255 int show_inode();                               /* Display inode*/
00256 
00257 
00258                         /* searchnupdate.c */
00259 int search4dir();                               /* searches for directory  */   
00260 int update_dir_info_file();                     /* Updates DIR_INFO_FILE */
00261 int get_parent_inode_flag(unsigned long);       /* Get Parent of given inode */
00262 int search4sequence12();                        /* Searches for continuous blocks */
00263 int search4sequence13();                        /* Searches for continuous blocks */
00264 int avoid_dups();                               /* Removes duplicates */
00265 int call2remove(int);                           /* Helper to above */
00266 int check4file_dups(unsigned long);             /* Check for duplicates */
00267 int check4dir_dups(unsigned long);              /* Check for duplicates */
00268 int dir_depth(unsigned long );                  /* Get directory depth */
00269 int get_sample_data();                          /* Get file content */  
00270 int check4samplefile_dups(unsigned long);       /* Avoids duplication of sample data */
00271 
00272                         /* uninit.c */
00273 int remove_giis();                              /* Uninstalls giis */
00274 
00275 
00276 #endif /* GIIS_*/

Generated on Wed Jul 25 20:43:33 2007 for giis by  doxygen 1.5.1