00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013 #define _LARGEFILE64_SOURCE
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
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
00043
00044 #define LEVEL_VALUE 11
00045 #define INSTALL_DIR1 "/giis"
00046 #define INSTALL_DIR2 "/giis/sys"
00047 #define INSTALL_DIR3 "/giis/got_it"
00048 #define INSTALL_DIR4 "/giis/unrecovered"
00049
00050 #define DIR_INFO_FILE "/giis/sys/dir"
00051 #define FILE_INFO_FILE "/giis/sys/file"
00052 #define SIND_INFO_FILE "/giis/sys/sind"
00053 #define DIND_INFO_FILE "/giis/sys/dind"
00054 #define SAMPLE_DATA_FILE "/giis/sys/sample"
00055 #define DEFAULT_OFFSET_OF_SUPER_BLOCK 1024
00056 #define ACCESS 0
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
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
00100 struct file_system{
00101
00102
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
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;
00115 unsigned long long root_inode_offset;
00116 unsigned long long device_offset;
00117 unsigned long long content_offset;
00118 unsigned long index_number;
00119
00120 unsigned long inodes_per_group;
00121 unsigned long blocks_per_group;
00122 int groups_count;
00123 unsigned long long inodes_count;
00124 unsigned long long blocks_count;
00125 unsigned long long fs_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
00135
00136 union u_file_recover_info{
00137 struct s_file_recover_info{
00138 char date_time[30];
00139 char name[30];
00140 unsigned long inode_number;
00141 unsigned long parent_inode_number;
00142 int search_flag;
00143 int mode;
00144 int owner;
00145 unsigned long file_blocks_count;
00146 unsigned long file_size;
00147 unsigned long file_flags;
00148 unsigned long data_block[EXT3_N_BLOCKS];
00149 unsigned long is_offset;
00150 unsigned long id_offset;
00151 int sfragment_flag;
00152 int dfragment_flag;
00153 unsigned long last_data_block;
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];
00161 char name[30];
00162 unsigned long inode_number;
00163 unsigned long parent_inode_number;
00164 int search_flag;
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;
00173 char sdata[32];
00174 }info;
00175 char buffer[sizeof(struct s_sample_file_data)];
00176 }giis_s;
00177
00178
00179 unsigned long idata_block[1024];
00180
00181 struct passwd *pwfile;
00182
00183
00184
00185
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;
00191 int entry,found;
00192 time_t result;
00193 char date_time[25];
00194 unsigned long long deleted_inode_offset;
00195 unsigned long size,err_size;
00196 unsigned long home_inode;
00197 unsigned long root_inode;
00198 unsigned long s_offy;
00199 unsigned long d_offy;
00200 int dir_level;
00201 int fileoverwritten;
00202 int search_format;
00203 int startbyte;
00204 int get_version;
00205 int repeat;
00206
00207
00208
00209
00210
00211 int set_content_offset();
00212 int read_dir();
00213 int record_dir(unsigned long);
00214 int record_file(unsigned long);
00215 int show_dir();
00216
00217
00218
00219 int read_show_file(int,int);
00220 int read_dir_info_file();
00221 int read_file_info_file();
00222 int read_sind_info_file();
00223 int read_dind_info_file();
00224 int read_sample_info_file(unsigned long);
00225 void show_data(char []);
00226 int file_repeated(char []);
00227
00228
00229
00230 int get_it();
00231 int verify_inode(unsigned long);
00232 int get_it_i_say();
00233 int get_data_from_block(int,int,unsigned long);
00234 int force_giis();
00235
00236
00237
00238 int get_group_desc();
00239 int eye_on_gd();
00240
00241
00242
00243 int search4fs();
00244 int search4super_block();
00245 void set_file_system();
00246 int search4group_desc();
00247 int init();
00248 int init_files();
00249 int fs_display();
00250
00251
00252
00253 int find_inode_offset();
00254 int read_inode();
00255 int show_inode();
00256
00257
00258
00259 int search4dir();
00260 int update_dir_info_file();
00261 int get_parent_inode_flag(unsigned long);
00262 int search4sequence12();
00263 int search4sequence13();
00264 int avoid_dups();
00265 int call2remove(int);
00266 int check4file_dups(unsigned long);
00267 int check4dir_dups(unsigned long);
00268 int dir_depth(unsigned long );
00269 int get_sample_data();
00270 int check4samplefile_dups(unsigned long);
00271
00272
00273 int remove_giis();
00274
00275
00276 #endif