home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 1999 March B / SCO_CASTOR4RRT.iso / uccs / root.14 / udk / usr / ccs / lib / fur / blocklog.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-08-19  |  2.4 KB  |  105 lines

  1. /*
  2.  * Copyright (c) 1998 The Santa Cruz Operation, Inc.. All Rights Reserved. 
  3.  *                                                                         
  4.  *        THIS IS UNPUBLISHED PROPRIETARY SOURCE CODE OF THE               
  5.  *                   SANTA CRUZ OPERATION INC.                             
  6.  *                                                                         
  7.  *   The copyright notice above does not evidence any actual or intended   
  8.  *   publication of such source code.                                      
  9.  */
  10.  
  11. #ident    "@(#)fur:common/cmd/fur/blocklog.c    1.1.1.1"
  12. #ifdef KERNEL
  13. #define _KERNEL
  14. #endif
  15. #include <stdio.h>
  16. #include <fcntl.h>
  17. #include <sys/types.h>
  18. #include <sys/mman.h>
  19. #ifndef KERNEL
  20. #include <limits.h>
  21. #endif
  22. #include "log.h"
  23.  
  24. static ulong Cursource = ULONG_MAX;
  25.  
  26. #define MY_BUFSIZE 4096
  27. #define BLOCK_BUFSIZE 40960
  28.  
  29. static char Outfile[] = BLOCKLOGPREFIX ".XX";
  30.  
  31. #ifdef libc
  32. #define open _rtopen
  33. #define mmap _rtmmap
  34. #define write _rtwrite
  35. #endif
  36.  
  37. #ifndef KERNEL
  38. static int
  39. outfile()
  40. {
  41.     int i;
  42.     int fd;
  43.  
  44.     for (i = 0; i < 99; i++) {
  45.         Outfile[sizeof(Outfile) - 3] = '0' + i / 10;
  46.         Outfile[sizeof(Outfile) - 2] = '0' + i % 10;
  47.         if ((fd = open(Outfile, O_EXCL|O_RDWR|O_CREAT, 0666)) >= 0)
  48.             return(fd);
  49.     }
  50. }
  51.  
  52. struct blockcount *BlockCount;
  53.  
  54. void
  55. blockinit()
  56. {
  57.     int fd;
  58.     int i;
  59.     char buf[MY_BUFSIZE];
  60.  
  61.     for (i = 0; i < MY_BUFSIZE / sizeof(long); i++)
  62.         ((long *) buf)[i] = 0;
  63.     if ((fd = outfile()) < 0)
  64.         exit(1);
  65.     for (i = 0; i < (NBLOCKS * sizeof(struct blockcount)) / MY_BUFSIZE; i++)
  66.         write(fd, buf, MY_BUFSIZE);
  67.     if ((NBLOCKS * sizeof(struct blockcount)) % MY_BUFSIZE)
  68.         write(fd, buf, (NBLOCKS * sizeof(struct blockcount)) % MY_BUFSIZE);
  69.     if ((BlockCount = (struct blockcount *) mmap(NULL, NBLOCKS * sizeof(struct blockcount), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0)) == (struct blockcount *) -1)
  70.         exit(1);
  71.     close(fd);
  72. }
  73. #else
  74.  
  75. unsigned long BlockSize = NBLOCKS * sizeof(struct blockcount);
  76. struct blockcount BlockCount[NBLOCKS];
  77.  
  78. #endif
  79.  
  80. #ifndef FLOW
  81. blocklog(unsigned long blockno)
  82. {
  83.     static int in_here = 0;
  84.  
  85.     if (in_here)
  86.         return;
  87.     in_here = 1;
  88. #ifndef KERNEL
  89.     if (!BlockCount)
  90.         blockinit();
  91. #endif
  92.     BlockCount[blockno].callcount++;
  93.     if (Cursource != ULONG_MAX) {
  94.         if (!BlockCount[Cursource].firstcount)
  95.             BlockCount[Cursource].firstblock = blockno;
  96.         if (BlockCount[Cursource].firstblock == blockno)
  97.             BlockCount[Cursource].firstcount++;
  98.         else
  99.             BlockCount[Cursource].secondcount++;
  100.     }
  101.     Cursource = blockno;
  102.     in_here = 0;
  103. }
  104. #endif
  105.