"Fossies" - the Fresh Open Source Software Archive

Member "giis_4.6.2/src/file.c" (6 Nov 2012, 26474 Bytes) of package /linux/misc/old/giis_4.6.2.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2 * /giis/file.c This file contains procedures to read data block and displays conents
    3 * of giis_files.
    4 *
    5 * Copyright (C) 2005,2006,2007,2008,2009,2010,2011,2012 Lakshmipathi.G <lakshmipathi.g@giis.co.in>.
    6 * This file may be redistributed  under the terms of the GNU Public License.
    7 *
    8 */
    9 
   10 #include "giis.h"
   11 
   12 /*
   13 * read_show_file() -  Reads data from given block and stores into a files.
   14 * size is global variable used to specify the remaining file size after every read.
   15 * Before recording the compare data with sample data if same continue else 
   16 * don't hack ;-)
   17 * Modification for giis4:
   18 * Implementation giis dump option.
   19 */
   20 
   21 int read_show_file (int fd, int fp)
   22 {
   23   int i, count = 0;
   24   char buffer[4096], a;         /* buffer_size=fs.block_size */
   25   char sbuf[32];
   26   int firstread = 0;
   27   int giis_dump = 0;
   28 
   29   if (size == giis_f.info.file_size)
   30     firstread = 1;
   31   else
   32     firstread = 0;
   33 
   34   if (firstread)
   35   {
   36     /* Get Sample Data for this inode and compare -Compare for each file only once  */
   37     i = read_sample_info_file (giis_f.info.inode_number);
   38     /* get data from disk */
   39     i = read (fd, &sbuf, 32);   //0-31
   40     if (i != 32)
   41     {
   42       perror ("read():read_sample_info_file()");
   43       printf ("\nError No:%d", errno);
   44       close (fd);
   45       return -1;
   46     }
   47     sbuf[31] = '\0';            // since 31 is 32 in array 
   48     if (strcmp (giis_s.info.sdata, sbuf) != 0)
   49     {
   50       printf ("\n\t\t ****** giis dump ******");
   51       printf ("\n\t %s : File Data Modified/Overwritten\n\n", giis_f.info.name);
   52       printf ("\n\t File older Data   :");
   53       printf ("\n\t ===================");
   54       show_data (giis_s.info.sdata);
   55       printf ("\n\t Current Disk Data :");
   56       printf ("\n\t ===================");
   57       //where to look from 4h byte for this ...and first byte for sample file ...
   58       startbyte = 4;
   59       show_data (sbuf);
   60       startbyte = 0;
   61       printf ("\n\tDo You wanna dump the Current Disk data?\n\tPress 1:yes \tPress 0:No");
   62       printf ("\nEnter :");
   63       scanf ("%d", &giis_dump);
   64       if (giis_dump != 1)
   65       {
   66         fileoverwritten = 444;
   67         return JSJ_NO_RETURN;
   68       }
   69       else
   70         fileoverwritten = 0;
   71     }
   72     //Else Content is same -or giis dump used -Reset the device pointer
   73     lseek64 (fd, fs.content_offset, 0);
   74   }
   75 
   76   while ((count < fs.block_size) && (size > 0))
   77   {
   78 
   79     /*Reading char by char */
   80 
   81     if (size < sizeof (buffer) && size > 0)
   82     {
   83       i = read (fd, &a, 1);
   84       while (size && count < fs.block_size)
   85       {
   86 
   87         i = write (fp, &a, 1);
   88         if (i != 1)
   89         {
   90           perror ("");
   91           printf ("Error Number:%d", errno);
   92           return -1;
   93         }
   94         size--;
   95         err_size++;
   96         count++;
   97         i = read (fd, &a, 1);
   98       }
   99     }
  100 
  101     /*Read block by block */
  102 
  103     if (size >= sizeof (buffer) && (count == 0))
  104     {
  105       i = read (fd, buffer, sizeof (buffer));
  106       if (i != sizeof (buffer))
  107       {
  108         perror ("");
  109         printf ("Error Number:%d", errno);
  110         return -1;
  111       }
  112       i = write (fp, buffer, sizeof (buffer));
  113       if (i != sizeof (buffer))
  114       {
  115         perror ("");
  116         printf ("Error Number:%d", errno);
  117         return -1;
  118       }
  119       size -= sizeof (buffer);
  120       err_size += sizeof (buffer);
  121       count = fs.block_size;
  122 
  123     }
  124   }
  125   return (size);
  126 }
  127 
  128 /*
  129 * read_dir_info_file() read data from dir_info_file and displays. 
  130 */
  131 
  132 int read_dir_info_file ()
  133 {
  134   int i, count = 0,tfd;
  135   char dname[50];
  136 
  137 
  138   tfd = open (DIR_INFO_FILE, 0);
  139   if (tfd == -1)
  140   {
  141     perror ("open");
  142     return -1;
  143   }
  144   printf ("Enter dir:");
  145   scanf ("%s", dname);
  146   printf ("\n\tName\tinode\tParent-inode\tSearchFlag\n");
  147   i = read (tfd, giis_d.buffer, GIIS_DSIZE);
  148 
  149   while (i > 0)
  150   {
  151     if (giis_d.info.search_flag == 1 )
  152     {
  153       printf ("\n\t%s\t%lu\t", giis_d.info.name, giis_d.info.inode_number);
  154       printf ("%lu\t%d", giis_d.info.parent_inode_number, giis_d.info.search_flag);
  155 
  156       count++;
  157     }
  158     if (strcmp (dname, giis_d.info.name) == 0)
  159       return 1;
  160 
  161 
  162 
  163     i = read (tfd, giis_d.buffer, GIIS_DSIZE);
  164     if (i == -1)
  165     {
  166       perror ("");
  167       printf ("Error Number:%d", errno);
  168       return -1;
  169     }
  170   }
  171 
  172   printf ("\n Total No.of Dir : %d", count);
  173   close (tfd);
  174   return 1;
  175 }
  176 
  177 /*
  178 * read_file_info_file() read data from file_info_file and displays. 
  179 * Modification for giis2:
  180 * New members like id_offset and is_offset used to keep trace of no.of blocks entry of
  181 * particular files in sind and dind files.
  182 * Where as s_offy and d_offy used for set offset in sind and dind files.
  183 */
  184 
  185 int read_file_info_file ()
  186 {
  187   int i, fd, count = 0, choice;
  188 //int index,hole,num;
  189 //unsigned long indirect_block;
  190   char fname[50];
  191 
  192   fd = open (FILE_INFO_FILE, 0);
  193   if (fd == -1)
  194   {
  195     perror ("open");
  196     return -1;
  197   }
  198   printf ("\n\t\tPress 1: All files");
  199   printf ("\n\t\tPress 2: Specific file");
  200   printf ("\n\t\tType in:");
  201   scanf ("%d", &choice);
  202   if (choice == 2)
  203   {
  204     printf ("\n\t\t Enter filename :");
  205     scanf ("%s", fname);
  206   }
  207   else
  208     choice = 1;
  209 
  210 
  211   i = read (fd, giis_f.buffer, GIIS_FSIZE);
  212   while (i > 0)
  213   {
  214     count++;
  215     printf ("\n ============================================");
  216     printf ("\nFile name   :%s", giis_f.info.name);
  217     printf ("\tInode :%lu", giis_f.info.inode_number);
  218     printf ("  sfragment_flags:%d ", giis_f.info.sfragment_flag);
  219     printf ("  dfragment_flags:%d ", giis_f.info.dfragment_flag);
  220     printf ("  is_offset %lu ", giis_f.info.is_offset);
  221     printf ("  id_offset %lu ", giis_f.info.id_offset);
  222 
  223     printf ("\nRecorded on :%s", giis_f.info.date_time);
  224     printf ("\t\tFile name   :%s", giis_f.info.name);
  225     printf ("\nInode :%lu", giis_f.info.inode_number);
  226     printf ("\tParent :%lu", giis_f.info.parent_inode_number);
  227     printf ("\tSearch Flag: %d", giis_f.info.search_flag);
  228     printf ("\tMode:%d", giis_f.info.mode);
  229     printf ("\nOwner: %d", giis_f.info.owner);
  230     printf ("\tBlocks count:%lu", giis_f.info.file_blocks_count);
  231     printf ("\tSize: %lu", giis_f.info.file_size);
  232 
  233     printf ("\nData blocks :");
  234     for (i = 0; i < EXT3_N_BLOCKS; i++)
  235       printf ("\n[%d]=%lu", i, giis_f.info.data_block[i]);
  236     printf ("\nsingles");
  237     printf ("\nis_offset=%lu\n id=%lu", giis_f.info.is_offset, giis_f.info.id_offset);
  238     printf ("\ns_offy=%lu \t d_offy=%lu", s_offy, d_offy);
  239     printf ("Sample Data :");
  240     read_sample_info_file (giis_f.info.inode_number);
  241 
  242 
  243 
  244     if (giis_f.info.is_offset)
  245     {
  246       read_sind_info_file ();
  247       s_offy += giis_f.info.is_offset;
  248     }
  249 
  250     if (giis_f.info.id_offset)
  251     {
  252       read_dind_info_file ();
  253       d_offy += giis_f.info.id_offset;
  254     }
  255     printf ("\nis_offset=%lu\n id=%lu", giis_f.info.is_offset, giis_f.info.id_offset);
  256     printf ("\ns_offy=%lu \t d_offy=%lu", s_offy, d_offy);
  257     printf ("\nLast :%lu", giis_f.info.last_data_block);
  258 
  259     if (strcmp (fname, giis_f.info.name) == 0 && choice == 2)
  260     {
  261       printf ("\n\t\tPress 0:Try next file\n\t\tPress 1:Exit  \n\t\tType in:");
  262       scanf ("%d", &i);
  263       if (i != 0)
  264         return 1;
  265 
  266     }
  267     if (choice == 1)
  268     {
  269       printf ("\n\t\tPress 0:Continue\n\t\tPress 1 : Stop ");
  270       printf ("\n\t\tEnter your choice:");
  271       scanf ("%d", &i);
  272       if (i == 1)
  273         return 1;
  274     }
  275 
  276 
  277     i = read (fd, giis_f.buffer, GIIS_FSIZE);
  278     if (i == -1)
  279     {
  280       perror ("");
  281       printf ("Error Number:%d", errno);
  282       return -1;
  283     }
  284   }
  285   printf ("\n Total No.of Files : %d", count);
  286   close (fd);
  287   return 1;
  288 }
  289 
  290 
  291 /*
  292 * read_sind_info_file() read data from sind and displays. 
  293 * introduced for giis2.
  294 * s_offy specifies offset at sind file.
  295 * is_offset gives total no.of entries of this record.
  296 */
  297 
  298 int read_sind_info_file ()
  299 {
  300   int i, fp;
  301   unsigned long iblock[1024];
  302 
  303   fp = open (SIND_INFO_FILE, 0);
  304   if (fp == -1)
  305   {
  306     perror ("open");
  307     close (fp);
  308     return -1;
  309   }
  310   lseek (fp, s_offy * sizeof (unsigned long), 0);
  311   i = (int) read (fp, iblock, giis_f.info.is_offset * sizeof (unsigned long));
  312   if (i == -1)
  313   {
  314     perror ("");
  315     printf ("Error Number:%d", errno);
  316     return -1;
  317   }
  318   i = 0;
  319   while (i < giis_f.info.is_offset)
  320   {
  321 
  322     //printf("\n%d==>%u",i,iblock[i]);
  323     i++;
  324 
  325   }
  326   printf ("\n SIND No.of records :%d", i);
  327   close (fp);
  328   return 1;
  329 }
  330 
  331 /*
  332 * read_dind_info_file() read data from dind and displays. 
  333 * introduced for giis2.
  334 * d_offy specifies offset at dind file.
  335 * id_offset gives total no.of entries of this record.
  336 */
  337 
  338 int read_dind_info_file ()
  339 {
  340   int i, fp;
  341   unsigned long iblock[1024];
  342 
  343   fp = open (DIND_INFO_FILE, 0);
  344   if (fp == -1)
  345   {
  346     perror ("open");
  347     close (fp);
  348     return -1;
  349   }
  350   lseek (fp, d_offy * sizeof (unsigned long), 0);
  351   i = (int) read (fp, iblock, giis_f.info.id_offset * sizeof (unsigned long));
  352   if (i == -1)
  353   {
  354     perror ("");
  355     printf ("Error Number:%d", errno);
  356     return -1;
  357   }
  358   i = 0;
  359 
  360   while (i < giis_f.info.id_offset)
  361   {
  362     //printf("\n%d==>%u",i,iblock[i]);
  363     i++;
  364 
  365   }
  366 
  367   printf ("\n DIND No.of records :%d", i);
  368   close (fp);
  369   return 1;
  370 }
  371 
  372 /*
  373 * introduced for giis3
  374 * read_sample_info_file() reads sample  file.  
  375 */
  376 
  377 int read_sample_info_file (unsigned long inode_number)
  378 {
  379   int i, sfp;
  380 
  381   sfp = open (SAMPLE_DATA_FILE, 0);
  382   if (sfp == -1)
  383   {
  384     perror ("open");
  385     close (sfp);
  386     return -1;
  387   }
  388   i = read (sfp, giis_s.buffer, GIIS_SSIZE);
  389   while (i > 0)
  390   {
  391     if (giis_s.info.inode_number == inode_number)
  392     {
  393       show_data (giis_s.info.sdata);
  394       close (sfp);
  395       return 1;
  396     }
  397     i = read (sfp, giis_s.buffer, GIIS_SSIZE);
  398     if (i == -1)
  399     {
  400       perror ("");
  401       printf ("Error Number:%d", errno);
  402       return -1;
  403     }
  404   }
  405   close (sfp);
  406   return 1;
  407 }
  408 
  409 /*
  410 * Introduced for giis4
  411 * show_data()- displays data meaningful to read.
  412 * Updates for giis4.1 :
  413 * giis analyser is include to detect the file formats and inform users :-)
  414 */
  415 void show_data (char buffer[32])
  416 {
  417   int i;
  418   int yes = 0;
  419   printf ("\n\t\t-------------- giis analyser : Begins -------------------");
  420 /*Uncomment to Debug
  421         for(i=0;i<32;i++){
  422         printf("[%d]=%x %c %d\n",i,buffer[i],buffer[i],buffer[i]);
  423         }
  424 */
  425 
  426 
  427 /* Graphics Files */
  428 
  429 
  430   if ((buffer[startbyte] == 0xffffffff && buffer[startbyte + 1] == 0xffffffd8 &&
  431        buffer[startbyte + 2] == 0xffffffff && buffer[startbyte + 3] == 0xffffffe0))
  432   {
  433     printf ("\n\t\t giis : It's Jpeg");
  434     yes = 444;
  435   }
  436 
  437   if (buffer[startbyte] == 0x47 && buffer[startbyte + 1] == 0x49
  438       && buffer[startbyte + 2] == 0x46 && buffer[startbyte + 3] == 0x38)
  439   {
  440     printf ("fname,giis_f.info.name\n\t\t giis : It's GIF");
  441     yes = 444;
  442   }
  443   if (buffer[startbyte] == 0xffffff89 && buffer[startbyte + 1] == 0x50
  444       && buffer[startbyte + 2] == 0x4e && buffer[startbyte + 3] == 0x47)
  445   {
  446     printf ("\n\t\t giis : It's PNG");
  447     yes = 444;
  448   }
  449   if (buffer[startbyte] == 0x49 && buffer[startbyte + 1] == 0x49
  450       && buffer[startbyte + 2] == 0x2a && buffer[startbyte + 3] == 0x00)
  451   {
  452     printf ("\n\t\t giis : It's TIF");
  453     yes = 444;
  454   }
  455   if (buffer[startbyte] == 'B' && buffer[startbyte + 1] == 'M'
  456       && buffer[startbyte + 2] == '?' && buffer[startbyte + 3] == '?'
  457       && buffer[startbyte + 4] == 0x00)
  458   {
  459     printf ("\n\t\t giis : It's BMP ");
  460     yes = 444;
  461   }
  462 
  463 
  464 /*Video - Animated files */
  465 
  466   if (buffer[startbyte] == 'R' && buffer[startbyte + 1] == 'I'
  467       && buffer[startbyte + 2] == 'F' && buffer[startbyte + 3] == 'F'
  468       && buffer[startbyte + 4] == '?' && buffer[startbyte + 5] == '?'
  469       && buffer[startbyte + 6] == '?' && buffer[startbyte + 7] == '?'
  470       && buffer[startbyte + 8] == 'A' && buffer[startbyte + 9] == 'V'
  471       && buffer[startbyte + 10] == 'I')
  472   {
  473     printf ("\n\t\t giis : It's AVI ");
  474     yes = 444;
  475   }
  476 
  477 
  478   if (buffer[startbyte] == '?' && buffer[startbyte + 1] == '?'
  479       && buffer[startbyte + 2] == '?' && buffer[startbyte + 3] == '?'
  480       && buffer[startbyte + 4] == '?' && buffer[startbyte + 5] == '?'
  481       && buffer[startbyte + 6] == '?' && buffer[startbyte + 7] == '?'
  482       && buffer[startbyte + 8] == 0x6d)
  483   {
  484     printf ("\n\t\t giis : It's Apple Quicktime ");
  485     yes = 444;
  486   }
  487 
  488   if ((buffer[startbyte] == 0x00 && buffer[startbyte + 1] == 0x00
  489        && buffer[startbyte + 2] == 0x01 && buffer[startbyte + 3] == 0xffffffba)
  490       || (buffer[startbyte] == 0x00 && buffer[startbyte + 1] == 0x00
  491           && buffer[startbyte + 2] == 0x01 && buffer[startbyte + 3] == 0xffffffb3))
  492   {
  493     printf ("\n\t\t giis : It's MPEG");
  494     yes = 444;
  495   }
  496 
  497   if (buffer[startbyte] == 'm' && buffer[startbyte + 1] == 'p'
  498       && buffer[startbyte + 2] == 'g')
  499   {
  500     printf ("\n\t\t giis : It's MPEG");
  501     yes = 444;
  502   }
  503 
  504   if (buffer[startbyte] == 'F' && buffer[startbyte + 1] == 'W'
  505       && buffer[startbyte + 2] == 'S')
  506   {
  507     printf ("\n\t\t giis : It's Flash Files");
  508     yes = 444;
  509   }
  510 
  511 
  512 /* */
  513 
  514   if (buffer[startbyte] == 0x1f && buffer[startbyte + 1] == 0xffffff8b)
  515   {
  516     printf ("\n\t\t giis : It's GZip");
  517     yes = 444;
  518   }
  519   if (buffer[startbyte] == 0x7f && buffer[startbyte + 1] == 0x45
  520       && buffer[startbyte + 2] == 0x4c && buffer[startbyte + 3] == 0x46)
  521   {
  522     printf ("\n\t\t giis : It's Unix ELF");
  523     yes = 444;
  524   }
  525   if (buffer[startbyte] == 0x50 && buffer[startbyte + 1] == 0x4b
  526       && buffer[startbyte + 2] == 0x03 && buffer[startbyte + 3] == 0x04)
  527   {
  528     printf ("\n\t\t giis : It's Zip");
  529     yes = 444;
  530   }
  531   if (buffer[startbyte] == 0xffffffd0 && buffer[startbyte + 1] == 0xffffffcf
  532       && buffer[startbyte + 2] == 0x11 && buffer[startbyte + 3] == 0xffffffe0
  533       && buffer[startbyte + 4] == 0xffffffa1 && buffer[startbyte + 5] == 0xffffffb1)
  534   {
  535     printf ("\n\t\t giis : It's DOC");
  536     yes = 444;
  537   }
  538 
  539   if ((buffer[startbyte] == 0x2e && buffer[startbyte + 1] == 0x72
  540        && buffer[startbyte + 2] == 0x61 && buffer[startbyte + 3] == 0xfffffffd)
  541       || (buffer[startbyte] == '.' && buffer[startbyte + 1] == 'R'
  542           && buffer[startbyte + 2] == 'M' && buffer[startbyte + 3] == 'F'))
  543   {
  544     printf ("\n\t\t giis : It's Real Audio Files");
  545     yes = 444;
  546   }
  547 
  548   if ( buffer[startbyte] == 0x30 && buffer[startbyte + 1] == 0x26
  549       && buffer[startbyte + 2] == 0xB2 && buffer[startbyte + 3] == 0x75 )
  550   {
  551     printf ("\n\t\t giis : It's WMA Files");
  552     yes = 444;
  553   }
  554 
  555 
  556   if ((buffer[startbyte] == 0xffffffff && buffer[startbyte + 1] == 0xfffffffb
  557        && buffer[startbyte + 2] == 0xffffff90 && buffer[startbyte + 3] == 0x44)
  558       || (buffer[startbyte] == 0xffffffff && buffer[startbyte + 1] == 0xfffffffb
  559           && buffer[startbyte + 2] == 0xffffff90 && buffer[startbyte + 3] == 0x00)
  560       || (buffer[startbyte] == 0x57 && buffer[startbyte + 1] == 0x41
  561           && buffer[startbyte + 2] == 0x56 && buffer[startbyte + 3] == 0x45)
  562       || (buffer[startbyte] == 0xffffffff && buffer[startbyte + 1] == 0xfffffffb
  563           && buffer[startbyte + 2] == 0xffffffD0) || (buffer[startbyte] == 0x49
  564                                                       && buffer[startbyte + 1] == 0x44
  565                                                       && buffer[startbyte + 2] == 0x33)
  566       || (buffer[startbyte] == 0x4C && buffer[startbyte + 1] == 0x41
  567           && buffer[startbyte + 2] == 0x4D && buffer[startbyte + 3] == 0x45))
  568   {
  569     printf ("\n\t\t giis : It's Mp3");
  570     yes = 444;
  571   }
  572 
  573   if (buffer[startbyte] == '%' && buffer[startbyte + 1] == 'P'
  574       && buffer[startbyte + 2] == 'D' && buffer[startbyte + 3] == 'F')
  575   {
  576     printf ("\n\t\t giis : It's a PDF File");
  577     yes = 444;
  578   }
  579 
  580   if (buffer[startbyte] == 0xED && buffer[startbyte + 1] == 0xAB)
  581   {
  582     printf ("\n\t\t giis : It's a Linux rpm File");
  583     yes = 444;
  584   }
  585 
  586 
  587   if (buffer[startbyte] == 'R' && buffer[startbyte + 1] == 'I'
  588       && buffer[startbyte + 2] == 'F' && buffer[startbyte + 3] == 'F'
  589       && buffer[startbyte + 4] == '?' && buffer[startbyte + 5] == '?'
  590       && buffer[startbyte + 6] == '?' && buffer[startbyte + 7] == '?'
  591       && buffer[startbyte + 8] == 'W' && buffer[startbyte + 9] == 'A'
  592       && buffer[startbyte + 10] == 'V' && buffer[startbyte + 11] == 'E')
  593   {
  594     printf ("\n\t\t giis : It's WAV files ");
  595     yes = 444;
  596   }
  597   if (buffer[startbyte] == 0x30 && buffer[startbyte + 1] == 0x26
  598       && buffer[startbyte + 2] == 0xB2 && buffer[startbyte + 3] == 0x75
  599       && buffer[startbyte + 4] == 0x8E && buffer[startbyte + 5] == 0x66
  600       && buffer[startbyte + 6] == 0xCF && buffer[startbyte + 7] == 0x11
  601       && buffer[startbyte + 8] == 0xA6 && buffer[startbyte + 9] == 0xD9
  602       && buffer[startbyte + 10] == 0x00 && buffer[startbyte + 11] == 0xAA
  603       && buffer[startbyte + 12] == 0x00 && buffer[startbyte + 13] == 0x62
  604       && buffer[startbyte + 14] == 0xCE)
  605   {
  606 
  607     printf ("\n\t\t giis : It's WMV files ");
  608     yes = 444;
  609   }
  610   if (buffer[startbyte] == 'R' && buffer[startbyte + 1] == 'a'
  611       && buffer[startbyte + 2] == 'r' && buffer[startbyte + 3] == '!')
  612   {
  613     printf ("\n\t\t giis : It's a Rar File");
  614     yes = 444;
  615   }
  616 
  617   if (buffer[startbyte] == 0xCA && buffer[startbyte + 1] == 0xFE
  618       && buffer[startbyte + 2] == 0xBA && buffer[startbyte + 3] == 0xBE)
  619   {
  620     printf ("\n\t\t giis : It's a Java File");
  621     yes = 444;
  622   }
  623   if (buffer[startbyte] == '<' && buffer[startbyte + 1] == 'h'
  624       && buffer[startbyte + 2] == 't' && buffer[startbyte + 3] == 'm'
  625       && buffer[startbyte + 1] == 'l')
  626   {
  627     printf ("\n\t\t giis : It's a html File");
  628     yes = 444;
  629   }
  630 
  631   if (yes == 0)
  632   {
  633     printf ("\n\t\t Unable to Detect File Type - Found Data : \n\t\t");
  634     for (i = 0; i < 32; i++)
  635     {
  636       if ((buffer[i] >= 32) && (buffer[i] < 128))
  637       {
  638         if (buffer[i] != 10)
  639           printf ("%c", buffer[i]);
  640         else
  641           printf ("%x", buffer[i]);
  642       }
  643     }
  644 
  645   }
  646   printf ("\n\t\t--------------Ends --------------\n\n");
  647 
  648 }
  649 
  650 /*
  651 * Introduced in giis v.4.1:
  652 * file_repeated() : It returns number of times this file entry is available in giis system 
  653 * files. 
  654 */
  655 int file_repeated (char fname[50])
  656 {
  657   int i, fd, exists = 0;
  658   union u_file_recover_info temp_giis_f;
  659 
  660   fd = open (FILE_INFO_FILE, 0);
  661   if (fd == -1)
  662   {
  663     perror ("open");
  664     return -1;
  665   }
  666   i = read (fd, temp_giis_f.buffer, GIIS_FSIZE);
  667   while (i > 0)
  668   {
  669     if (strcmp (fname, temp_giis_f.info.name) == 0)
  670     {
  671       exists++;
  672     }
  673     i = read (fd, temp_giis_f.buffer, GIIS_FSIZE);
  674     if (i == -1)
  675     {
  676       perror ("");
  677       printf ("Error Number:%d", errno);
  678       return -1;
  679     }
  680   }
  681 //printf("\n Total No.of Times Files repeated : %d",exists);
  682   close (fd);
  683   return exists;
  684 }
  685 /*
  686 Introduced to giis 4.3
  687 display_deleted_files:Displays deleted files and status
  688 */
  689 int display_deleted_files(){
  690 
  691  int i, fd, total=0,count = 0, deleted,temp=0;
  692  extern union u_s_rere_info giis_r;
  693 
  694   fd = open (FILE_INFO_FILE, 0);
  695   if (fd == -1)
  696   {
  697     perror ("open");
  698     return -1;
  699   }
  700  
  701   i = read (fd, giis_f.buffer, GIIS_FSIZE);
  702   printf("\n\t\tList of Deleted files :");
  703  printf("\n\t\t======================");
  704   
  705 
  706   while (i > 0)
  707   {
  708  
  709     deleted=0;
  710     
  711     //is it deleted?
  712     deleted = verify_inode (giis_f.info.inode_number);
  713 
  714     if(deleted){
  715     count++;
  716     for(i=0;i<count;i++)
  717         {//if already exists -path is already generated so skip this
  718         if(giis_r.info.list_of_deleted_inodes[i]==giis_f.info.inode_number){
  719         goto next; //first goto in giis :-)
  720         }
  721         }
  722     
  723     printf ("\n\n\t\t%s", giis_f.info.name);
  724     total++;
  725 
  726 
  727     giis_r.info.list_of_deleted_inodes[total-1]=giis_f.info.inode_number;
  728     
  729     //memset -clear 
  730     memset(pathname,'\0',150);
  731     strcat(pathname,"/");
  732     parent_found=0;
  733     lookup(giis_f.info.parent_inode_number);
  734     //place restore path 
  735     temp=total-1;
  736     strcpy(giis_r.info.list_of_restorepaths[temp],pathname);
  737     next:
  738     ;
  739         }
  740     
  741    i = read (fd, giis_f.buffer, GIIS_FSIZE);
  742    }
  743 
  744 printf("\n\t\t======================");
  745 printf("\n\nTotal files:%d",total);
  746 printf("\n\nNote:If required deleted file is not listed here,\nthen try \"force giis - giis dump\" option.\n\n");
  747 
  748 return total;
  749 }
  750 
  751 /* Introduced for giis.4.3
  752 lookup:Get parent name of given inode and construct absolute path name 
  753 */
  754 int lookup (unsigned long parent)
  755 {
  756   int fp, i;
  757   extern int parent_found;
  758   extern char pathname[150];
  759 
  760  
  761   giis_d.info.inode_number=0;
  762   fp = open (DIR_INFO_FILE, 0);
  763   if (fp == -1)
  764   {
  765     perror ("open");
  766     return -1;
  767   }
  768 
  769   i = read (fp, giis_d.buffer, GIIS_DSIZE);
  770   if (i == -1)
  771   {
  772     perror ("");
  773     printf ("Error Number:%d", errno);
  774     return -1;
  775   }
  776 
  777   while (i > 0)
  778   {
  779     if (giis_d.info.inode_number == parent)
  780     {
  781     if(parent_found==1)
  782     {
  783     strcat(pathname,"\/");
  784     strcat(pathname,giis_d.info.name);
  785     return 1;
  786     }
  787 
  788     
  789 
  790     if((parent_found==0) && (giis_d.info.parent_inode_number!=ROOT_INODE))
  791         {
  792         lookup(giis_d.info.parent_inode_number);
  793         }
  794     else{
  795       close (fp);
  796       strcat(pathname,giis_d.info.name);
  797       parent_found=1;
  798           return 1;
  799     }
  800     }
  801     i = read (fp, giis_d.buffer, GIIS_DSIZE);
  802     if (i == -1)
  803     {
  804       perror ("");
  805       printf ("Error Number:%d", errno);
  806       return -1;
  807     }
  808 
  809   }
  810 
  811   close (fp);
  812   return -1;
  813 }
  814 
  815 /*
  816 Introduced in giis 4.4:
  817 read_config_file: Reads Configuration file details
  818 giis 4.5:
  819 added : get TIME value from config file.
  820 */
  821 
  822 int read_config_file(char file[100]){
  823 
  824 char b[]="$DIR = ";
  825 char buf[4096];
  826 char directory[100][100];
  827 char d[]="$DEVICE = ";
  828 char e[]="$TIME = ";
  829 char f[]="$LEVEL_VALUE = ";
  830 int i,j,k,tfp;
  831 int row,col,c=0;
  832 i=0;
  833 
  834 //printf("\n passed file~~~~~~>%s",file);
  835 tfp=open(GIIS_CONF_FILE,0);
  836 if(tfp ==  -1)
  837 {
  838 printf("\n Unable to load config file");
  839 exit(0);
  840 }
  841 //read the file
  842 i=read(tfp,buf,4096);
  843 close(tfp);
  844 //Search for device name 
  845 if(strcmp(d,file)==0){
  846 //printf("\n Checking Device name.. ");
  847 memset(device_name,'\0',100);
  848 
  849 //printf("\n First Device Name:%s\n",device_name);
  850 i=0;c=0;
  851 while(buf[i]!='\0'){
  852 j=0;
  853 k=i;
  854 
  855     while((d[j]==buf[k]) && (d[j]!='\0')){
  856         j++;
  857         k++;
  858         }
  859     
  860     if(d[j]=='\0'){
  861         while(buf[k]!='$'){
  862             device_name[c++] = buf[k++];
  863             }
  864     device_name[c] = '\0';
  865     return 1;
  866     i=k;
  867     //directory[row][col]='\0';
  868     //row++;col=0;
  869     }else
  870     i++;
  871     
  872 }
  873 if(strcmp(d,file)==0)
  874 return -1;
  875 
  876 }
  877 //Search Ends
  878 
  879 //Search for Time 
  880 if(strcmp(e,file)==0){
  881 //printf("\n Checking Time.. ");
  882 memset(auto_time,'\0',5);
  883 
  884 i=0;c=0;
  885 while(buf[i]!='\0'){
  886 j=0;
  887 k=i;
  888 
  889     while((e[j]==buf[k]) && (e[j]!='\0')){
  890         j++;
  891         k++;
  892         }
  893     
  894     if(e[j]=='\0'){
  895         while(buf[k]!='$'){
  896             auto_time[c++] = buf[k++];
  897             }
  898     auto_time[c] = '\0';
  899     return 1;
  900     i=k;
  901     }else
  902     i++;
  903     
  904 }
  905 }
  906 //Search for time ends
  907 
  908 
  909 //Search for Level-value 
  910 if(strcmp(f,file)==0){
  911 //printf("\n Checking Level-value.. ");
  912 memset(s_level_value,'\0',5);
  913 
  914 i=0;c=0;
  915 while(buf[i]!='\0'){
  916 j=0;
  917 k=i;
  918 
  919     while((f[j]==buf[k]) && (f[j]!='\0')){
  920         j++;
  921         k++;
  922         }
  923     
  924     if(f[j]=='\0'){
  925         while(buf[k]!='$'){
  926             s_level_value[c++] = buf[k++];
  927             }
  928     s_level_value[c] = '\0';
  929     return 1;
  930     i=k;
  931     }else
  932     i++;
  933     
  934 }
  935 }
  936 //Search for Level-value ends
  937 
  938 row=0;
  939 col=0;
  940 i=0;
  941 while(buf[i]!='\0'){
  942 j=0;
  943 k=i;
  944 
  945     while((b[j]==buf[k]) && (b[j]!='\0')){
  946         j++;
  947         k++;
  948         }
  949     
  950     if(b[j]=='\0'){
  951 //  printf("\nPattern exists");
  952     
  953         while(buf[k]!='$'){
  954             directory[row][col++]=buf[k++];
  955             //printf("\n%d %d==>%c",row,col-1,directory[row][col-1]);
  956                 }
  957     i=k;
  958     directory[row][col]='\0';
  959     row++;col=0;
  960     }else
  961     i++;
  962     
  963 }
  964 if(row == 0)
  965 //printf("\n pattern  not exists");
  966 ;
  967 else
  968 for(i=0,col=0;i<row;i++){
  969 //printf("\n=====>%s",directory[i]);
  970 //chk given name exists or not.
  971 if(strcmp(directory[i],file)==0)
  972 //printf("\n======*>%d %s ",i,file);
  973 return 444;
  974 
  975 }
  976 return 1;
  977 }
  978 
  979 /*
  980 Introduced in giis 4.4:
  981 read_config_file2: Reads Configuration file details
  982 returns directory names 
  983 */
  984 
  985 int read_config_file2(){
  986 
  987 char b[]="$DIR = ";
  988 char buf[4096];
  989 extern char g_directory[100][100];
  990 int i,j,k,tfp,col;
  991 extern int g_row;
  992 i=0;
  993 
  994 //printf("\n passed file~~~~~~>%s",file);
  995 tfp=open(GIIS_CONF_FILE,0);
  996 if(tfp ==  -1)
  997 {
  998 printf("\n Unable to load config file");
  999 exit(0);
 1000 }
 1001 //read the file
 1002 i=read(tfp,buf,4096);
 1003 close(tfp);
 1004 
 1005 g_row=0;
 1006 col=0;
 1007 i=0;
 1008 while(buf[i]!='\0'){
 1009 j=0;
 1010 k=i;
 1011 
 1012     while((b[j]==buf[k]) && (b[j]!='\0')){
 1013         j++;
 1014         k++;
 1015         }
 1016     
 1017     if(b[j]=='\0'){
 1018 //  printf("\nPattern exists");
 1019     
 1020         while(buf[k]!='$'){
 1021             g_directory[g_row][col++]=buf[k++];
 1022             //printf("\n%d %d==>%c",row,col-1,directory[row][col-1]);
 1023                 }
 1024     i=k;
 1025     g_directory[g_row][col]='\0';
 1026     g_row++;col=0;
 1027     }else
 1028     i++;
 1029     
 1030 }
 1031 return 1;
 1032 }
 1033 
 1034 
 1035 
 1036 /*
 1037 * read_conf_file_inum(): read data from dir_info_file and return inode number
 1038 input:directory from giis.conf
 1039 output:inode number
 1040 */
 1041 
 1042 int read_conf_file_inum ()
 1043 {
 1044   int i, count = 0;
 1045   int j,tfd;    
 1046   extern new_dir_added;
 1047   new_dir_added=0;
 1048 
 1049   tfd = open (DIR_INFO_FILE, 2);
 1050   if (tfd == -1)
 1051   {
 1052     perror ("open");
 1053     return -1;
 1054   }
 1055   //printf ("\n\tName\tinode\tParent-inode\tSearchFlag\n");
 1056   i = read (tfd, giis_d.buffer, GIIS_DSIZE);
 1057   while (i > 0)
 1058   {
 1059       count++;
 1060     if(giis_d.info.parent_inode_number==2){
 1061     for(j=0;j<g_row;j++){
 1062     if ((strcmp(giis_d.info.name,g_directory[j])==0)&&(giis_d.info.search_flag==0))
 1063         {
 1064         //printf ("\n\t%s\t%lu\t", giis_d.info.name, giis_d.info.inode_number);
 1065          // printf ("%lu\t%d", giis_d.info.parent_inode_number, giis_d.info.search_flag);
 1066     //reset the flag here.
 1067     //printf("\n count:%d",count);
 1068     lseek(tfd,-(GIIS_DSIZE),1);
 1069     giis_d.info.search_flag=1;
 1070     //new directory is included in giis sys
 1071     new_dir_added=1;
 1072     write (tfd, giis_d.buffer, GIIS_DSIZE);goto out;
 1073      }
 1074     }
 1075     }
 1076     out:
 1077     i = read (tfd, giis_d.buffer, GIIS_DSIZE);
 1078     if (i == -1)
 1079     {
 1080       perror ("");
 1081       printf ("Error Number:%d", errno);
 1082       return -1;
 1083     }
 1084   }
 1085 
 1086   //printf ("\n Total No.of Dir : %d", count);
 1087   close (tfd);
 1088   return 1;
 1089 }