home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / misc / volume07 / frag < prev    next >
Encoding:
Internet Message Format  |  1991-08-27  |  2.9 KB

  1. From decwrl!purdue!ames!xanth!ginosko!uunet!allbery Thu Aug  3 08:48:06 PDT 1989
  2. Article 953 of comp.sources.misc:
  3. Path: decwrl!purdue!ames!xanth!ginosko!uunet!allbery
  4. From: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  5. Newsgroups: comp.sources.misc
  6. Subject: v07i061: Fragmentation Check
  7. Message-ID: <729@mitisft.Convergent.COM>
  8. Date: 9 Jul 89 00:25:15 GMT
  9. Sender: allbery@uunet.UU.NET
  10. Reply-To: dold@mitisft.convergent.com (Clarence Dold)
  11. Distribution: usa
  12. Organization: Convergent Technologies, San Jose, CA
  13. Lines: 92
  14. Approved: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
  15.  
  16. Posting-number: Volume 7, Issue 61
  17. Submitted-by: dold@mitisft.convergent.com (Clarence Dold)
  18. Archive-name: frag
  19.  
  20. This turned out to be so short, I should have done it quite some time ago.
  21. A really short, non-error checking tool that accepts one file name,
  22. finds it's inode and invokes a pipe from bcheck to scan the assigned block
  23. numbers.
  24. These block numbers are examined to make sure they are contiguous, else it
  25. prints some info.
  26.  
  27. Do I really need a makefile?
  28. all:    frag
  29.  
  30. frag: frag.o
  31.  
  32. frag.o:
  33.     cc -o frag frag.c
  34.  
  35. ---------------------------------------snip----------------------
  36. /* program to check for fragmentation of one file.
  37.  * Arbitrarily chose 3 block gap as acceptable, to allow for
  38.  * necessary inode gaps in large files.
  39.  * Super User Usage: frag filename
  40.  * CADold - dold@Convergent.COM - Fri Jun  9 19:02:38 PDT 1989
  41.  */
  42. #include <stdio.h>
  43. #include <sys/types.h>
  44. #include <sys/stat.h>
  45. #include <sys/gdisk.h>
  46.  
  47. #ifndef AUTHOR
  48. #define AUTHOR
  49. static char *Author=" dold@Convergent.COM";
  50. #endif        /* If there is no author specified, stick my name in the code */
  51.  
  52. char cmd[80] ="/usr/local/bin/bcheck -i ";
  53. main(argc, argv)
  54. int argc;
  55. char **argv;
  56. {
  57. struct stat statbuf;
  58. int stat(), cont, drive, slice;
  59. FILE *pipe;
  60. char line[BUFSIZ];
  61. long this, last, contig;
  62. long jumps=0L, blocks=0L, restart=0L;
  63.  
  64.  
  65. if (argc != 2){
  66.     printf("Usage: %s filename\n", argv[0]);
  67.     exit(1);
  68. }
  69.  
  70. stat (argv[1], &statbuf);
  71. slice = statbuf.st_dev % GDMAXSLICE;
  72. drive = ((statbuf.st_dev % (GDMAXSLICE * DRIVES)) - slice)/GDMAXSLICE;
  73. cont = statbuf.st_dev / (GDMAXSLICE * DRIVES);
  74.  
  75. sprintf(line, "%d /dev/rdsk/c%dd%ds%d", statbuf.st_ino, cont, drive, slice);
  76. strcat(cmd, line);
  77. if ((pipe = popen(cmd, "r")) != NULL){
  78.     fgets(line,BUFSIZ-1,pipe);
  79.     last = atol(line);
  80.     blocks++;
  81.  
  82.     while (fgets(line,BUFSIZ-1,pipe) != NULL ) {
  83.         this = atol(line);
  84.         if  ( (this -3 > last) || (this < last)  ){
  85.             jumps++;
  86.             contig = blocks - restart;
  87.             restart = blocks;
  88.             printf("Block jump from %ld to %ld, after %ld contiguous blocks\n",
  89.                 last, this, contig);
  90.         }
  91.         blocks++;
  92.         last = this;
  93.     }
  94. } else {
  95.     exit(1);
  96. }
  97. pclose(pipe);
  98. printf("%ld jumps in %ld blocks\n", jumps, blocks);
  99. return(0);
  100. }
  101.  
  102. ---------------------------------------snip----------------------
  103. -- 
  104. ---
  105. Clarence A Dold - dold@tsmiti.Convergent.COM        (408) 434-5293
  106.         ...pyramid!ctnews!tsmiti!dold
  107.         P.O.Box 6685, San Jose, CA 95150-6685    MS#10-007
  108.  
  109.  
  110.