"Fossies" - the Fresh Open Source Software Archive 
Member "giis_4.6.2/src/searchnupdate.c" (6 Nov 2012, 22576 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/searchnupdate.c - This file performs search and update operations on files.
3 *
4 * Copyright (C) 2005,2006,2007,2008,2009,2010,2011,2012 Lakshmipathi.G <lakshmipathi.g@giis.co.in>.
5 * This file may be redistributed under the terms of the GNU Public License.
6 *
7 */
8
9 #include"giis.h"
10
11 /*
12 * search4dir() - This function is used to record all entries of Directory into
13 * corresponding info_files.
14 * Modification for giis2:
15 * First we record directories and avoid any duplication with the help avoid_dups()
16 * After recording all directories then record files by setting install_file.And
17 * make a recursive call to search4dir().
18 * Modification for giis2.1:
19 * Use of update_dir variable
20 */
21
22
23 int search4dir ()
24 {
25 int i, fp, level_count = 0;
26
27 if(install == 0){
28
29 //get dir.list from config file
30 read_config_file2();
31 read_conf_file_inum();
32
33 }
34 while (level_count < level_value)
35 {
36
37 fp = open (DIR_INFO_FILE, 0);
38 if (fp == -1)
39 {
40 perror ("open");
41 return -1;
42 }
43
44 i = read (fp, giis_d.buffer, GIIS_DSIZE);
45 if (i == -1)
46 {
47 perror ("");
48 printf ("Error Number:%d", errno);
49 return -1;
50 }
51
52
53 while (i > 0)
54 {
55 if (giis_d.info.search_flag == 1)
56 {
57
58 fs.inode_number = giis_d.info.inode_number;
59 i = find_inode_offset ();
60 if (i == -1)
61 {
62 perror ("");
63 printf ("Error Number:%d", errno);
64 return -1;
65 }
66 i = read_inode ();
67 if (i == -1)
68 {
69 perror ("");
70 printf ("Error Number:%d", errno);
71 return -1;
72 }
73 i = set_content_offset ();
74 if (i == -1)
75 {
76 perror ("");
77 printf ("Error Number:%d", errno);
78 return -1;
79 }
80 if (dir)
81 {
82
83 i = read_dir ();
84 if (i == -1)
85 {
86 perror ("");
87 printf ("Error Number:%d", errno);
88 return -1;
89 }
90 i = show_dir ();
91 if (i == -1)
92 {
93 perror ("");
94 printf ("Error Number:%d", errno);
95 return -1;
96 }
97 }
98
99 }
100 i = read (fp, giis_d.buffer, GIIS_DSIZE);
101 if (i == -1)
102 {
103 perror ("");
104 printf ("Error Number:%d", errno);
105 return -1;
106 }
107 }
108 if(new_dir_added){
109 install == 1;
110 install_file == 0;
111 }
112 if ((install == 1 && install_file == 0))
113 {
114 i = update_dir_info_file (level_count);
115 if (i == -1)
116 {
117 perror ("");
118 printf ("Error Number:%d", errno);
119 return -1;
120 }
121 i = avoid_dups ();
122 if (i == -1)
123 {
124 perror ("");
125 printf ("Error Number:%d", errno);
126 return -1;
127 }
128 }
129 /* First update all directories above and now update files */
130 if (update_dir == 1)
131 {
132 close (fp);
133 update_dir = 0;
134 i = search4dir (); /* Update files */
135 if (i == 444)
136 {
137 close (fp);
138 //Set device name :
139 search4fs();
140
141 get_sample_data ();
142 printf ("\n\n\t\t giis updated...");
143 return 1;
144
145 }
146
147
148 }
149
150 if (install_file == 1 || update_file == 1) /* Because we want record files only once . */
151 return 444;
152
153 level_count++;
154 close (fp);
155 }
156
157
158
159 /* During installation we need to record fiels so now store
160 only those files from DIR file */
161
162 if (install == 1 && install_file == 0)
163 {
164 install_file = 1;
165 search4dir (); /* Recursive */
166 }
167
168 return 1;
169 }
170
171
172 /*
173 * update_dir_info_file()-After entries are recorded directories search_flags are set.
174 * This is called during installation.
175 * This update_dir_info_file() ironically will not be called during updates.
176 */
177
178 int update_dir_info_file (int level_count)
179 {
180 int fp, i, flag, count = 0;
181
182
183 fp = open (DIR_INFO_FILE, 2);
184 if (fp == -1)
185 {
186 perror ("open");
187 return -1;
188 }
189 i = read (fp, giis_d.buffer, GIIS_DSIZE);
190 if (i == -1)
191 {
192 perror ("");
193 printf ("Error Number:%d", errno);
194 return -1;
195 }
196
197 /* Set flags of newly found entries */
198
199 while (i > 0)
200 {
201 if ((giis_d.info.search_flag == 0) && (giis_d.info.parent_inode_number != 2))
202 {
203 flag = get_parent_inode_flag (giis_d.info.parent_inode_number);
204 if (flag == -1)
205 break;
206 if (flag == 1)
207 { /* Parent is set so set sub-directory flag */
208 lseek (fp, count * GIIS_DSIZE, 0);
209 i = read (fp, giis_d.buffer, GIIS_DSIZE);
210 if (i != GIIS_DSIZE)
211 {
212 perror ("read");
213 return -1;
214 }
215 giis_d.info.search_flag = 1;
216 lseek (fp, -GIIS_DSIZE, 1);
217 i = write (fp, giis_d.buffer, GIIS_DSIZE);
218 if (i != GIIS_DSIZE)
219 {
220 perror ("write");
221 return -1;
222 }
223
224 }
225 }
226 i = read (fp, giis_d.buffer, GIIS_DSIZE);
227 /* if end of file just quits loop */
228 count++;
229
230 }
231
232 printf ("\n\t Files at Directory Level %d are updated......", level_count + 1);
233 close (fp);
234 return 1;
235 }
236
237 /*
238 * get_parent_inode_flag() is a helper function to update_dir_file_info().
239 * It returns parent inode flag.
240 */
241
242 int get_parent_inode_flag (unsigned long parent)
243 {
244 int fp, i;
245
246 fp = open (DIR_INFO_FILE, 0);
247 if (fp == -1)
248 {
249 perror ("open");
250 return -1;
251 }
252
253 i = read (fp, giis_d.buffer, GIIS_DSIZE);
254 if (i == -1)
255 {
256 perror ("");
257 printf ("Error Number:%d", errno);
258 return -1;
259 }
260
261 while (i > 0)
262 {
263 if (giis_d.info.inode_number == parent)
264 {
265 close (fp);
266 return 1;
267 }
268 i = read (fp, giis_d.buffer, GIIS_DSIZE);
269 if (i == -1)
270 {
271 perror ("");
272 printf ("Error Number:%d", errno);
273 return -1;
274 }
275
276 }
277
278 close (fp);
279 return -1;
280 }
281
282 /*
283 * search4sequence12()
284 * In giis1 holes concept used:
285 * If we have holes less than five then store it in member d/sindirect_block_hole[]
286 * Since if store it in a files which uses fixed record size of 1024 unsigned long.
287 * If we have 4 records then remaining 1020 are wasted.
288 * To avoid this we used s/dindirect_block_hole.-Thus saves space when holes<5
289 * And hole=100 we use file though still there will be 924 are wasted.
290 * Lot of space still wasted.
291 *
292 * Modified for giis.2
293 * Get rid of that holes concept since we use variable size records instead of fixed size
294 * record.Now with variable records which doesnot waste space.We do not need holes at all.
295 *
296 * In giis2 we have following flags,
297 * sfragment_flag=0 files not uses single indirect at all.
298 * sfragment_flag=1 file uses single indirect but it's already in sequence.
299 * sfragment_flag=2 file uses single indirect with SIND FILE .
300 */
301
302
303 int search4sequence12 ()
304 {
305 unsigned long indirect_block[1024], prev;
306 int i, hole, fp, count;
307 count = hole = 0;
308 lseek64 (fd, (unsigned long long) giis_f.info.data_block[12] * fs.block_size, 0);
309 read (fd, indirect_block, fs.block_size);
310
311 /* Check 4 holes */
312 if (indirect_block[0] - giis_f.info.data_block[12] != 1)
313 {
314 idata_block[count++] = giis_f.info.data_block[12];
315 idata_block[count++] = indirect_block[0];
316 hole++;
317 }
318
319 prev = indirect_block[0];
320
321 for (i = 1; i < 1024 && indirect_block[i]; i++)
322 {
323
324 if (indirect_block[i] - prev == 1)
325 {
326 prev = indirect_block[i];
327 continue;
328 }
329
330 else
331 { /* Hole uses {this_block,that_block} format */
332 idata_block[count++] = prev;
333 idata_block[count++] = indirect_block[i];
334 hole++;
335 prev = indirect_block[i];
336 }
337
338 }
339
340 /* Update is_offset and sfragment_flag and last_data_block */
341
342 if ((i == 1024 || indirect_block[i] == 0) && (hole == 0))
343 {
344 giis_f.info.is_offset = 0;
345 giis_f.info.sfragment_flag = 1;
346 giis_f.info.last_data_block = indirect_block[i - 1];
347 return (hole);
348 }
349
350 if ((i == 1024 || indirect_block[i] == 0) && hole)
351 {
352 giis_f.info.is_offset = count;
353 giis_f.info.sfragment_flag = 2;
354 giis_f.info.last_data_block = indirect_block[i - 1];
355
356
357 /* Write into file */
358 fp = open (SIND_INFO_FILE, 1);
359 if (fp == -1)
360 {
361 perror ("Open:");
362 printf ("Error no :%d", errno);
363 return -1;
364 }
365 lseek (fp, 0, 2);
366 i = write (fp, idata_block, count * sizeof (unsigned long));
367 if (i != count * sizeof (unsigned long))
368 {
369 perror ("write");
370 printf ("Error no :%d", errno);
371 return -1;
372 }
373 close (fp);
374 return 1;
375 }
376
377 return 1;
378 }
379
380 /*
381 * search4sequence13() Exactly sames as above but it deals with double indirect blocks
382 * Modified for giis.2
383 * Get rid of that holes.variable size records used instead of fixed size records.
384 *
385 * In giis2 we have following flags,
386 * dfragment_flag=0 files not uses double indirect at all.
387 * dfragment_flag=1 file uses double indirect but it's already in sequence.
388 * dfragment_flag=2 file uses double indirect with DIND FILE .
389 *
390 * Here files greater than 8.04MB are also recorded with an recursive call to
391 * search4sequence13() untill all blocks are scanned.
392 *
393 */
394
395 int search4sequence13 ()
396 {
397 unsigned long indirect_block[1024];
398 int i, fp, count, err, ret;
399 static unsigned long prev;
400 count = 0, ret = 0;
401
402 /*
403 Consider the following cases,
404 1) When all block number of file is less than 1048575 there is no problem.
405 2) When all block number of file is greater than 1048575 still no problem.
406 3) When there is a file with block numbers that switches from less to
407 greater than 1048575 we come acroess some problem.
408
409 When we use block numbers more than 1048575 we make shift beyond range of
410 unsigned long (i.e)4294967295.But for some reasons-Which i don't know- it throws up raw data. So in these cases where we make a shift from blocks
411 less then greater we tend the skip the second lseek().
412
413 *Since I'm not sure what's the problem is? I'm unsure about this solution
414 too.
415 */
416
417 if (gi_round == 0)
418 {
419 count = hole = 0; /* Counts holes */
420 lseek64 (fd, (unsigned long long) giis_f.info.data_block[13] * fs.block_size, 0);
421 read (fd, indirect_block, fs.block_size);
422
423 lseek64 (fd, (unsigned long long) indirect_block[0] * fs.block_size, 0);
424 read (fd, indirect_block, fs.block_size);
425 prev = giis_f.info.data_block[13];
426
427 }
428 else
429 {
430 lseek64 (fd, (unsigned long long) prev * 4096, 0);
431 read (fd, indirect_block, fs.block_size);
432 lseek64 (fd, (unsigned long long) indirect_block[0] * 4096, 0);
433 read (fd, indirect_block, fs.block_size);
434 }
435
436 if (indirect_block[0] - prev != 2)
437 {
438
439 idata_block[count++] = prev;
440 idata_block[count++] = indirect_block[0];
441 hole++;
442 }
443
444 prev = indirect_block[0];
445
446 for (i = 1; i < 1024 && indirect_block[i]; i++)
447 {
448
449 if (indirect_block[i] - prev == 1)
450 {
451 prev = indirect_block[i];
452 continue;
453 }
454
455 else
456 {
457 idata_block[count++] = prev;
458 idata_block[count++] = indirect_block[i];
459 hole++;
460 prev = indirect_block[i];
461 }
462
463
464 }
465
466 /* Update id_offset and dfragment_flag and last_data_block */
467
468 if ((indirect_block[i] == 0) && (hole == 0))
469 {
470 giis_f.info.id_offset = 0;
471 giis_f.info.dfragment_flag = 1;
472 giis_f.info.last_data_block = indirect_block[i - 1];
473
474 return 444;
475 }
476
477 if ((i == 1024 || indirect_block[i] == 0) && hole)
478 {
479 giis_f.info.id_offset += count;
480 giis_f.info.dfragment_flag = 2;
481 giis_f.info.last_data_block = indirect_block[i - 1];
482
483 /* Write into file */
484
485 fp = open (DIND_INFO_FILE, 1);
486 if (fp == -1)
487 {
488 perror ("Open:");
489 printf ("Error no :%d", errno);
490 return -1;
491 }
492 lseek (fp, 0, 2);
493 err = write (fp, idata_block, count * sizeof (unsigned long));
494 if (err != count * sizeof (unsigned long))
495 {
496 perror ("write");
497 printf ("Error no :%d", errno);
498 return -1;
499 }
500 close (fp);
501 }
502
503 if (i == 1024 && indirect_block[1023] != 0)
504 {
505 prev = indirect_block[1023];
506 gi_round++;
507 ret = search4sequence13 ();
508 if (ret == 444)
509 return 1;
510
511 }
512
513
514 return 444; /* Will be caught by recursive function */
515 }
516
517 /*
518 * Introduced for giis2:
519 * avoid_dups():Called Only during installtion
520 * This is used to figureout whether we have any duplication of directory entry.
521 * call2remove() if found.
522 */
523
524 int avoid_dups ()
525 {
526 int fp1, fp2, i, record_no, bity;
527 unsigned long temp, end;
528
529 fp1 = open (DIR_INFO_FILE, 0);
530 if (fp1 == -1)
531 {
532 perror ("open:");
533 printf ("\nError No:%d", errno);
534 close (fp1);
535 return -1;
536 }
537 fp2 = open (DIR_INFO_FILE, 0);
538 if (fp2 == -1)
539 {
540 perror ("open:");
541 printf ("\nError No:%d", errno);
542 close (fp2);
543 return -1;
544 }
545
546 /* Not so elegant code/method to check 4 repeatation
547 but i think...it's different */
548
549
550
551 end = lseek (fp1, 0, 2); /* EOF */
552 lseek (fp1, 0, 0);
553 temp = bity = 0;
554
555 while (temp < (end - (int)GIIS_DSIZE))
556 {
557 i = read (fp1, giis_d.buffer, GIIS_DSIZE);
558 if (i != GIIS_DSIZE)
559 {
560 perror ("read1()");
561 printf ("\nError No:%d \t fp=%d", errno, fp1);
562 close (fp1);
563 close (fp2);
564 if(i==0){
565 printf("\n Fatal Error in %s",DIR_INFO_FILE);
566 exit(0);
567 }
568 return -1;
569 }
570 temp += GIIS_DSIZE;
571
572 /* Read next record in fp2 from current record of fp1 */
573
574 lseek (fp2, lseek (fp1, 0, 1), 0);
575
576 while (i > 0)
577 {
578 i = read (fp2, giis_dt.buffer, GIIS_DSIZE);
579
580 if ((giis_d.info.inode_number == giis_dt.info.inode_number)
581 && (giis_dt.info.search_flag == 1))
582 {
583
584 /* Get the duplicate record number */
585
586 record_no = lseek (fp2, 0, 1) / GIIS_DSIZE;
587 call2remove (record_no);
588 }
589 }
590 }
591 close (fp1);
592 close (fp2);
593 return 1;
594 }
595
596 /*
597 * Introduced for giis2:
598 * call2remove()- This removes a directory entry from future processing by just resetting its
599 * search flag to zero.
600 * This is helper funtion to avoid_dups().
601 */
602
603 int call2remove (int record_no)
604 {
605 int fdes, i;
606 fdes = open (DIR_INFO_FILE, 2);
607 if (fdes == -1)
608 {
609 perror ("open");
610 return -1;
611 }
612
613 lseek (fdes, (record_no - 1) * GIIS_DSIZE, 0);
614 i = read (fdes, giis_dt.buffer, GIIS_DSIZE);
615 if (i != GIIS_DSIZE)
616 {
617 perror ("read1()");
618 printf ("\nError No:%d \t fp=%d", errno, fdes);
619 close (fdes);
620 return -1;
621 }
622
623
624 giis_dt.info.search_flag = 0;
625 lseek (fdes, -GIIS_DSIZE, 1);
626 i = write (fdes, giis_dt.buffer, GIIS_DSIZE);
627
628 if (i != GIIS_DSIZE)
629 {
630 perror ("read1()");
631 printf ("\nError No:%d \t fp=%d", errno, fdes);
632 close (fdes);
633 return -1;
634 }
635
636
637 close (fdes);
638 return 1;
639
640 }
641
642 /*
643 * Introduced for giis2.1:
644 * check4file_dups() : Checks whether a file is a valid entry or not.
645 */
646 int check4file_dups (unsigned long parent)
647 {
648 int i, fp;
649
650 fp = open (FILE_INFO_FILE, 0);
651 if (fp == -1)
652 {
653 perror ("check4file_dups:open");
654 return -1;
655 }
656 if (lseek (fp, 0, 0) == lseek (fp, 0, 2))
657 { /* Empty file */
658 close (fp);
659 return 1;
660 }
661 lseek (fp, 0, 0); /* Reset */
662
663 i = read (fp, giis_f.buffer, GIIS_FSIZE);
664 while (i > 0)
665 {
666 if ((giis_f.info.inode_number == ide.de.inode)
667 && (giis_f.info.parent_inode_number == parent)
668 && (giis_f.info.file_size == iin.in.i_size))
669 {
670 close (fp);
671 return 0;
672 }
673 i = read (fp, giis_f.buffer, GIIS_FSIZE);
674 if (i == -1)
675 {
676 perror ("");
677 printf ("searchnupdate.c:check4file_dups()-read:Error Number:%d", errno);
678 return -1;
679 }
680 }
681 close (fp);
682 return 1;
683 }
684
685 /*
686 * Introduced for giis2.1:
687 * check4dir_dups() : Checks whether a directory is a valid entry or not.
688 */
689 int check4dir_dups (unsigned long parent)
690 {
691 int i, fp;
692
693 if (ide.de.inode == ROOT_INODE)
694 return 0;
695 if (ide.de.name[0] == '.')
696 return 0;
697 fp = open (DIR_INFO_FILE, 0);
698 if (fp == -1)
699 {
700 perror ("open");
701 return -1;
702 }
703 if (lseek (fp, 0, 0) == lseek (fp, 0, 2))
704 { /* Empty file */
705 close (fp);
706 return 1;
707 }
708 lseek (fp, 0, 0); /* Reset */
709
710 i = read (fp, giis_d.buffer, GIIS_DSIZE);
711 while (i > 0)
712 {
713 if (giis_d.info.inode_number == ide.de.inode)
714 { /* We already have it */
715 close (fp);
716 return 0;
717 }
718 i = read (fp, giis_d.buffer, GIIS_DSIZE);
719 if (i == -1)
720 {
721 perror ("");
722 printf ("Error Number:%d", errno);
723 return -1;
724 }
725 }
726 close (fp);
727 dir_level = 1;
728 i = dir_depth (parent);
729 if (i == -1)
730 {
731 perror ("");
732 printf ("searchnupdate.c:check4dir_dups()-Error Number:%d", errno);
733 return -1;
734 }
735 if ((i == 444) && (dir_level < level_value))
736 return 1; /* Record this new entry */
737
738 if ((i == 444) && (dir_level > level_value))
739 return 0; /* Don't record since out of range of LEVEL_VALUE */
740
741 return 0;
742 }
743
744 /*
745 * Introduced for giis2.1:
746 * dir_depth() : Returns level_value of newly found dir.
747 */
748 int dir_depth (unsigned long inode)
749 {
750 int i, fp;
751
752 if (inode == ROOT_INODE) /* We reached the depth */
753 return 444;
754 fp = open (DIR_INFO_FILE, 0);
755 if (fp == -1)
756 {
757 perror ("open");
758 return -1;
759 }
760
761 i = read (fp, giis_d.buffer, GIIS_DSIZE);
762
763 while (i > 0)
764 {
765 if (inode == ROOT_INODE)
766 return 444;
767
768 if (giis_d.info.inode_number == inode)
769 { /* When parent and grandparent is same */
770 close (fp);
771 dir_level++;
772 i = dir_depth (giis_d.info.parent_inode_number);
773 if (i == 444)
774 return i;
775 else
776 return 0;
777 }
778 i = read (fp, giis_d.buffer, GIIS_DSIZE);
779 if (i == -1)
780 {
781 perror ("");
782 printf ("searchnupdate.c:dir_depth()Error Number:%d", errno);
783 return -1;
784 }
785 }
786 close (fp);
787 return 0;
788 }
789
790 /*
791 * Introduced for giis3.0:
792 * get_sample_data() : Get content of each file and store them.
793 */
794 int get_sample_data ()
795 {
796 int sfp, ffp, dfp, i, ret;
797 unsigned long device_block_number;
798 char sample[32];
799
800 //Open sample file
801 sfp = open (SAMPLE_DATA_FILE, O_RDWR);
802 if (sfp == -1)
803 {
804 printf ("\nFile Not found %s", SAMPLE_DATA_FILE);
805 return -1;
806 }
807 //Open the device
808 dfp = open (device_name, 0);
809 if (dfp == -1)
810 {
811 perror ("open");
812 {
813 perror ("");
814 printf ("Searchnupdate:device_name:open:Error Number:%d", errno);
815 return -1;
816 }
817 }
818
819 //Open the FILE informations file
820 ffp = open (FILE_INFO_FILE, 0);
821 if (ffp == -1)
822 {
823 perror ("Searchupdate:FILE_INFO_FILE:open");
824 return -1;
825 }
826 //Now read each file records
827 i = read (ffp, giis_f.buffer, GIIS_FSIZE);
828
829 while (i > 0)
830 {
831
832 /* Check whether the inode alread available in SAMPLE FILE */
833 /* During installtion this check won't be needed install = 0; */
834 if(install == 0)
835 ret = check4samplefile_dups (giis_f.info.inode_number);
836
837 if (ret)
838 {
839 fs.block_number = giis_f.info.data_block[0];
840 if (fs.block_number != 0)
841
842 {
843
844 i = eye_on_gd ();
845 if (i == -1)
846 {
847 //giis 4.2 warn disbaled.
848 // printf ("\n\t Warning : Abnormal block number: Group Descriptor not found ");
849 close (ffp);
850 close (dfp);
851 close (sfp);
852 return -1;
853 }
854 device_block_number =
855 ((fs.block_number - 1) % fs.blocks_per_group) +
856 fs.group_number * fs.blocks_per_group;
857 device_block_number += fs.first_data_block;
858 fs.content_offset =
859 (unsigned long long) device_block_number *(unsigned long long) fs.block_size;
860 fs.content_offset += fs.block_size;
861 //set device file to appropriate location
862 lseek64 (dfp, fs.content_offset, 0);
863 //Empty the buffer - sample
864 for (i = 0; i < 32; i++)
865 {
866 giis_s.info.sdata[i] = '\0';
867 }
868 //read data from disk
869 i = read (dfp, sample, 32); //0-31
870 if (i != 32)
871 {
872 perror ("read():get_sample_data()");
873 printf ("\nError No:%d", errno);
874 close (ffp);
875 close (dfp);
876 close (sfp);
877 return -1;
878 }
879 sample[31] = '\0'; //32 is
880 strcpy (giis_s.info.sdata, sample);
881 giis_s.info.inode_number = giis_f.info.inode_number;
882
883
884 //Inode and sample data is in struct now write into sample file
885 i = write (sfp, giis_s.buffer, GIIS_SSIZE);
886 if (i != GIIS_SSIZE)
887 {
888 perror (" write():");
889 printf ("\nError No:%d", errno);
890 close (ffp);
891 close (dfp);
892 close (sfp);
893 return -1;
894
895 }
896 }
897 }
898 //Next record
899 i = read (ffp, giis_f.buffer, GIIS_FSIZE);
900 if (i == -1)
901 {
902 perror ("");
903 printf ("Error Number:%d", errno);
904 return -1;
905 }
906 }
907 close (ffp);
908 close (dfp);
909 close (sfp);
910 return 0;
911 }
912
913 /*
914 * Introduced for giis4.1:
915 * check4samplefile_dups() : Checks whether a file's data should be retireved or not ..
916 */
917 int check4samplefile_dups (unsigned long temp_inode_number)
918 {
919 int i, fp;
920 fp = open (SAMPLE_DATA_FILE, 0);
921 if (fp == -1)
922 {
923 perror ("open");
924 return -1;
925 }
926 if (lseek (fp, 0, 0) == lseek (fp, 0, 2))
927 { /* Empty file */
928 close (fp);
929 return 1;
930 }
931 lseek (fp, 0, 0); /* Reset */
932
933 i = read (fp, giis_s.buffer, GIIS_SSIZE);
934 while (i > 0)
935 {
936 if (giis_s.info.inode_number == temp_inode_number)
937 {
938 close (fp);
939 return 0; //already exists
940 }
941 i = read (fp, giis_s.buffer, GIIS_SSIZE);
942 if (i == -1)
943 {
944 perror ("");
945 printf ("Error Number:%d", errno);
946 return -1;
947 }
948 }
949 close (fp);
950 return 1;
951 }