Diff for /freem/src/global_bltin.c between versions 1.9 and 1.13

version 1.9, 2025/04/08 16:46:11 version 1.13, 2025/04/09 14:34:30
Line 24 Line 24
  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.   *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
  *   *
  *   $Log$   *   $Log$
    *   Revision 1.13  2025/04/09 14:34:30  snw
    *   Further work on global_bltin.c refactor
    *
    *   Revision 1.12  2025/04/09 00:43:07  snw
    *   Exit with fatal error if a header mismatch found
    *
    *   Revision 1.11  2025/04/08 21:41:13  snw
    *   Make insert, update, and splitp global handler functions take a ptr to a global_handle instead of a file descriptor
    *
    *   Revision 1.10  2025/04/08 20:00:56  snw
    *   Global handler now uses a header file and maintains the last journaling transaction ID
    *
  *   Revision 1.9  2025/04/08 16:46:11  snw   *   Revision 1.9  2025/04/08 16:46:11  snw
  *   Add global file header and offsets   *   Add global file header and offsets
  *   *
Line 56 Line 68
 #include <errno.h>  #include <errno.h>
   
 #include "mpsdef.h"  #include "mpsdef.h"
   #include "journal.h"
 #include "global_bltin.h"  #include "global_bltin.h"
   
 global_handle *global_handles_head;  global_handle *global_handles_head;
   unsigned long gbl_cache_misses = 0;
   unsigned long gbl_cache_hits = 0;
   
 static void b_free (short filedes, unsigned long blknbr);  static void b_free (short filedes, unsigned long blknbr);
 static void splitp (short filedes, char *block, long *addr, long *offs, unsigned long *blknbr);  static void splitp (global_handle *g, char *block, long *addr, long *offs, unsigned long *blknbr);
 static void update (short filedes, char *ins_key, long keyl);  static void update (global_handle *g, char *ins_key, long keyl);
 static void insert (int filedes, char *ins_key, long key_len, unsigned long blknbr);  static void insert (global_handle *g, char *ins_key, long key_len, unsigned long blknbr);
 static void scanpblk (char *block, long *adr, long *fnd);  static void scanpblk (char *block, long *adr, long *fnd);
 static void scandblk (char *block, long *adr, long *fnd);  static void scandblk (char *block, long *adr, long *fnd);
 static void getnewblk (int filedes, unsigned long *blknbr);  static void getnewblk (int filedes, unsigned long *blknbr);
Line 202  nextpath: Line 217  nextpath:
     return i;      return i;
 } /* gbl_path() */  } /* gbl_path() */
   
   void gbl_cache_hit(global_handle *g)
   {
       g->cache_hits++;
       gbl_cache_hits++;
   } /* gbl_cache_hit() */
   
   void gbl_cache_miss(global_handle *g)
   {
       g->fast_path = 0;
       g->cache_misses++;
       gbl_cache_misses++;
   } /* gbl_cache_miss() */
   
 int gbl_lock(global_handle *g, int type)  int gbl_lock(global_handle *g, int type)
 {  {
     if (g->locked == TRUE || lonelyflag == TRUE) {      if (g->locked == TRUE || lonelyflag == TRUE) {
Line 244  void gbl_close_all(void) Line 272  void gbl_close_all(void)
     }      }
 } /* gbl_close_all() */  } /* gbl_close_all() */
   
 int gbl_write_header(global_handle *g)  int gbl_write_initial_header(global_handle *g)
 {  {
     global_header hdr;      global_header hdr;
     unsigned long old_position;      unsigned long old_position;
Line 268  int gbl_write_header(global_handle *g) Line 296  int gbl_write_header(global_handle *g)
     lseek (g->fd, 0, SEEK_SET);      lseek (g->fd, 0, SEEK_SET);
   
     if (write (g->fd, &hdr, sizeof (global_header)) == -1) {      if (write (g->fd, &hdr, sizeof (global_header)) == -1) {
         snprintf (msg, 256, "error %d writing global header for %s", errno, g->global_name);          snprintf (msg, sizeof (msg), "error %d writing global header for %s", errno, g->global_name);
         m_fatal (msg);          m_fatal (msg);
     }      }
           
Line 276  int gbl_write_header(global_handle *g) Line 304  int gbl_write_header(global_handle *g)
     gbl_unlock (g);      gbl_unlock (g);
   
     return TRUE;      return TRUE;
   } /* gbl_write_initial_header() */
   
   
   int gbl_write_header(global_handle *g, global_header *hdr)
   {
       unsigned long old_position;
       char msg[256];
       
       if (g->opened == FALSE) {
           return FALSE;
       }
       
       gbl_lock (g, 1);
       old_position = lseek (g->fd, 0, SEEK_CUR);
       lseek (g->fd, 0, SEEK_SET);
   
       if (write (g->fd, hdr, sizeof (global_header)) == -1) {
           snprintf (msg, sizeof (msg), "error %d writing global header for %s", errno, g->global_name);
           m_fatal (msg);
       }
   
       lseek (g->fd, old_position, SEEK_SET);
       gbl_unlock (g);
   
       gbl_read_header (g, &g->header);
       
       return TRUE;    
 } /* gbl_write_header() */  } /* gbl_write_header() */
   
   int gbl_read_header(global_handle *g, global_header *h)
   {
       unsigned long old_position;
       char m[5] = GBL_MAGIC;
   
       
       if (g->opened == FALSE) {
           return GBL_HDR_NOTOPEN;
       }
   
       gbl_lock (g, 1);
       old_position = lseek (g->fd, 0, SEEK_CUR);
       lseek (g->fd, 0, SEEK_SET);
   
       read (g->fd, h, sizeof (global_header));
   
       lseek (g->fd, old_position, SEEK_SET);
       gbl_unlock (g);
   
       if (strncmp (h->magic, m, 5) != 0) {
           return GBL_HDR_BADMAGIC;
       }
       if (h->format_version != GBL_FORMAT_VERSION) {
           return GBL_HDR_BADVERSION;
       }
       if (h->block_size != BLOCKLEN) {
           return GBL_HDR_BADBLOCKSIZE;
       }
   
       return GBL_HDR_OK;                          
   } /* gbl_read_header() */
   
   int gbl_update_tid(global_handle *g)
   {
       global_header h;
   
       if (gbl_read_header (g, &h) != GBL_HDR_OK) {
           return FALSE;
       }
   
       h.last_transaction_id = jnl_tran_id;
   
       return gbl_write_header (g, &h);        
   } /* gbl_update_tid() */
   
 int gbl_create(global_handle *g)  int gbl_create(global_handle *g)
 {  {
     while (1) {      while (1) {
Line 297  int gbl_create(global_handle *g) Line 397  int gbl_create(global_handle *g)
     g->age = time (0L);      g->age = time (0L);
     g->last_block = 0;      g->last_block = 0;
     g->use_count = 1;      g->use_count = 1;
       g->fast_path = 0;
     gbl_write_header (g);      
       gbl_write_initial_header (g);
           
     return OK;      return OK;
 } /* gbl_create() */  } /* gbl_create() */
   
 short gbl_open(global_handle *g, short action)  short gbl_open(global_handle *g, short action)
 {  {
       int result;
       
     if (g->opened == FALSE) {      if (g->opened == FALSE) {
           gbl_cache_miss (g);
         while (1) {          while (1) {
             errno = 0;              errno = 0;
             g->fd = open (g->global_path, 2);              g->fd = open (g->global_path, 2);
Line 318  short gbl_open(global_handle *g, short a Line 422  short gbl_open(global_handle *g, short a
                                           
                 case EMFILE:                  case EMFILE:
                 case ENFILE:                  case ENFILE:
                     close_all_globals ();                      gbl_close_all ();
                     continue;                      continue;
             }              }
                           
Line 334  short gbl_open(global_handle *g, short a Line 438  short gbl_open(global_handle *g, short a
         }          }
         else {          else {
             g->opened = TRUE;              g->opened = TRUE;
               result = gbl_read_header (g, &g->header);
               
               if (result == GBL_HDR_OK) {
                   g->opened = TRUE;
               }
               else {                
                   gbl_close (g);
                   set_io (UNIX);
                   
                   switch (result) {
                       
                       case GBL_HDR_BADMAGIC:
                           fprintf (stderr, "gbl_open:  bad magic value in %s [FATAL]\n", g->global_name);
                           exit (1);
                           break;
   
                       case GBL_HDR_BADVERSION:
                           fprintf (stderr, "gbl_open:  global version is %d in %s (must be %d) [FATAL]\n", g->header.format_version, g->global_name, GBL_FORMAT_VERSION);
                           exit (1);
                           break;
   
                   }
                           
                   return FALSE;
               }
         }          }
     }      }
   
Line 388  global_handle *gbl_handle(char *key) Line 517  global_handle *gbl_handle(char *key)
     g->opened = FALSE;      g->opened = FALSE;
     g->fd = 0;      g->fd = 0;
     g->fast_path = -1;      g->fast_path = -1;
       g->cache_misses = 0;
       g->cache_hits = 0;
           
     strcpy (g->global_name, global_name);          strcpy (g->global_name, global_name);    
     gbl_path (key, g->global_path);      gbl_path (key, g->global_path);
Line 939  lock: Line 1070  lock:
   
 tfast0:  tfast0:
         gbl_lock (g, 3);          gbl_lock (g, 3);
         if (tryfast) goto tfast1;               /* try again last block */          
           if (g->fast_path > 0) goto tfast1;              /* try again last block */
                   
         blknbr = g->last_block = ROOT;          /* start with ROOT block */          blknbr = g->last_block = ROOT;          /* start with ROOT block */
                   
Line 970  tfast2: Line 1102  tfast2:
                 j = UNSIGN (block[i++]);        /* length of key - offset */                  j = UNSIGN (block[i++]);        /* length of key - offset */
                 k = UNSIGN (block[i++]);        /* offset into previous entry */                  k = UNSIGN (block[i++]);        /* offset into previous entry */
   
 #ifdef VERSNEW  
   
                 stcpy0 (&key0[k], &block[i], j);  
                 i += j;  
                 j += k;  
   
 #else  
   
                 j += k;                  j += k;
                           
                 while (k < j) key1[k++] = block[i++];           /* get key */                  while (k < j) key1[k++] = block[i++];           /* get key */
   
 #endif /* VERSNEW */  
   
                 if (j != ch) {  /* keys have different length */                  if (j != ch) {  /* keys have different length */
                                           
                     i += UNSIGN (block[i]);                      i += UNSIGN (block[i]);
Line 1017  tfast2: Line 1139  tfast2:
   
             /* fast access failed. try normal path */              /* fast access failed. try normal path */
             if (tryfast) {              if (tryfast) {
                 tryfast = FALSE;                  gbl_cache_miss (g);
                 goto tfast0;                  goto tfast0;
             }              }
   
Line 1028  tfast2: Line 1150  tfast2:
         }           } 
         else {          else {
                   
             if (tryfast) {              if (g->fast_path > 0) {
                 tryfast = FALSE;                  gbl_cache_miss (g);
                 goto tfast0;                  goto tfast0;
             }              }
   
Line 1059  tfast2: Line 1181  tfast2:
   
         addr += PLEN;           /* skip data */          addr += PLEN;           /* skip data */
         g->last_block = blknbr;          g->last_block = blknbr;
           g->fast_path = 1;
                   
         if (merr () == INRPT) goto quit;          if (merr () == INRPT) goto quit;
   
Line 1137  k_again:    /* entry point for repeated Line 1260  k_again:    /* entry point for repeated
   
         addr += PLEN;                   /* skip data */          addr += PLEN;                   /* skip data */
         g->last_block = blknbr;          g->last_block = blknbr;
           g->fast_path = 1;
     }      }
   
     traceadr[trx] = addr;      traceadr[trx] = addr;
Line 1274  s10:            { Line 1398  s10:            {
                 lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                  lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);
                 write (g->fd, block, BLOCKLEN);                  write (g->fd, block, BLOCKLEN);
   
                 if (traceadr[trx] == 0) update (g->fd, compactkey, keyl);                  if (traceadr[trx] == 0) update (g, compactkey, keyl);
   
                 break;                  break;
             }              }
Line 1360  s20: Line 1484  s20:
             stcpy0 (&block[++addr], data, (long) datal);              stcpy0 (&block[++addr], data, (long) datal);
             lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);              lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);
             write (g->fd, block, BLOCKLEN);              write (g->fd, block, BLOCKLEN);
   
               gbl_update_tid (g);
               
             break;              break;
   
   
Line 2082  p_empty:  /* entry if pointer block goes Line 2209  p_empty:  /* entry if pointer block goes
                         if (addr == 0) {        /* update of pointer */                          if (addr == 0) {        /* update of pointer */
                             traceadr[trx] = 0;                              traceadr[trx] = 0;
                                                           
                             update (g->fd, &block[2], (long) UNSIGN (block[0]));                              update (g, &block[2], (long) UNSIGN (block[0]));
                         }                          }
   
                         trx = trxsav;                          trx = trxsav;
Line 2128  p_empty:  /* entry if pointer block goes Line 2255  p_empty:  /* entry if pointer block goes
                 write (g->fd, block, BLOCKLEN);                  write (g->fd, block, BLOCKLEN);
                 if (addr < 3) {         /* update of pointer */                  if (addr < 3) {         /* update of pointer */
                 traceadr[trx] = 0;                  traceadr[trx] = 0;
                 update (g->fd, &block[2], (long) UNSIGN (block[0]));                  update (g, &block[2], (long) UNSIGN (block[0]));
                 }                  }
             }              }
   
Line 2491  splitd:    /* split data block in two se Line 2618  splitd:    /* split data block in two se
         addr = 0;          addr = 0;
         blknbr = newblk;          blknbr = newblk;
                   
         insert (g->fd, compactkey, keyl, newblk);          insert (g, compactkey, keyl, newblk);
                   
         /* up-date LL-PTR of RL-block */          /* up-date LL-PTR of RL-block */
         if ((other = right * 65536 + right1 * 256 + right2)) {          if ((other = right * 65536 + right1 * 256 + right2)) {
Line 2537  splitd:    /* split data block in two se Line 2664  splitd:    /* split data block in two se
         blknbr = newblk;          blknbr = newblk;
         traceadr[trx] = (-1);           /* inhibit second update of pointers */          traceadr[trx] = (-1);           /* inhibit second update of pointers */
                   
         insert (g->fd, compactkey, keyl, newblk);          insert (g, compactkey, keyl, newblk);
                   
         if (addr < 3) {                 /* update of pointer */          if (addr < 3) {                 /* update of pointer */
             traceadr[trx] = 0;              traceadr[trx] = 0;
                           
             update (g->fd, compactkey, keyl);              update (g, compactkey, keyl);
         }          }
   
         /* other is ***always*** zero !!!          /* other is ***always*** zero !!!
Line 2656  splitd:    /* split data block in two se Line 2783  splitd:    /* split data block in two se
             offset = limit;              offset = limit;
             /* insert new block in pointer structure */              /* insert new block in pointer structure */
                   
             insert (g->fd, &block0[2], (long) UNSIGN (block0[0]), newblk);              insert (g, &block0[2], (long) UNSIGN (block0[0]), newblk);
                   
             /* up-date LL-PTR of RL-block */              /* up-date LL-PTR of RL-block */
             if (other != 0) {              if (other != 0) {
Line 2698  splitd:    /* split data block in two se Line 2825  splitd:    /* split data block in two se
             traceblk[trx] = (blknbr = newblk);              traceblk[trx] = (blknbr = newblk);
                           
             /* insert new block in pointer structure */              /* insert new block in pointer structure */
             insert (g->fd, &block0[2], (long) UNSIGN (block0[0]), newblk);              insert (g, &block0[2], (long) UNSIGN (block0[0]), newblk);
                           
             /* up-date LL-PTR of RL-block */              /* up-date LL-PTR of RL-block */
             if (other != 0) {              if (other != 0) {
Line 2738  spltex: Line 2865  spltex:
  *   'addr' there I would like to insert, if possible (which is not)   *   'addr' there I would like to insert, if possible (which is not)
  *   'offset' filled up to this limit   *   'offset' filled up to this limit
  */   */
 static void splitp (short filedes, char *block, long *addr, long *offs, unsigned long *blknbr)    static void splitp (global_handle *g, char *block, long *addr, long *offs, unsigned long *blknbr)       
 {  {
   
     char block0[BLOCKLEN];      char block0[BLOCKLEN];
Line 2751  static void splitp (short filedes, char Line 2878  static void splitp (short filedes, char
   
     hdr_offset = sizeof (global_header);      hdr_offset = sizeof (global_header);
           
     getnewblk (filedes, &newblk);       /* get a new block */      getnewblk (g->fd, &newblk); /* get a new block */
           
     if (*blknbr == ROOT) {              /* ROOT overflow is special */      if (*blknbr == ROOT) {              /* ROOT overflow is special */
   
Line 2786  static void splitp (short filedes, char Line 2913  static void splitp (short filedes, char
         block0[NRBLK + 2] = i % 256;          block0[NRBLK + 2] = i % 256;
         block0[BTYP] = POINTER;          block0[BTYP] = POINTER;
                   
         lseek (filedes, hdr_offset + ROOT, SEEK_SET);          lseek (g->fd, hdr_offset + ROOT, SEEK_SET);
         write (filedes, block0, BLOCKLEN);          write (g->fd, block0, BLOCKLEN);
                   
         /* shift trace_stack */          /* shift trace_stack */
         j = trx++;          j = trx++;
Line 2804  static void splitp (short filedes, char Line 2931  static void splitp (short filedes, char
         traceblk[1] = newblk;          traceblk[1] = newblk;
         *blknbr = newblk;          *blknbr = newblk;
                   
         getnewblk (filedes, &newblk);   /* get a new block */          getnewblk (g->fd, &newblk);     /* get a new block */
   
     }      }
   
Line 2858  static void splitp (short filedes, char Line 2985  static void splitp (short filedes, char
         block0[LLPTR + 1] = (*blknbr) % 65536 / 256;          block0[LLPTR + 1] = (*blknbr) % 65536 / 256;
         block0[LLPTR + 2] = (*blknbr) % 256;          block0[LLPTR + 2] = (*blknbr) % 256;
   
         lseek (filedes, hdr_offset + ((long) (newblk) * (long) (BLOCKLEN)), SEEK_SET);          lseek (g->fd, hdr_offset + ((long) (newblk) * (long) (BLOCKLEN)), SEEK_SET);
         write (filedes, block0, BLOCKLEN);          write (g->fd, block0, BLOCKLEN);
   
         (*offs) = limit;          (*offs) = limit;
                   
         insert (filedes, &block0[2], (long) UNSIGN (block0[0]), newblk);          insert (g, &block0[2], (long) UNSIGN (block0[0]), newblk);
                   
         /* up-date LL-PTR of RL-block */          /* up-date LL-PTR of RL-block */
         if (other != 0) {          if (other != 0) {
   
             lseek (filedes, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);              lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);
             read (filedes, block0, BLOCKLEN);              read (g->fd, block0, BLOCKLEN);
                           
             block0[LLPTR] = newblk / 65536;              block0[LLPTR] = newblk / 65536;
             block0[LLPTR + 1] = newblk % 65536 / 256;              block0[LLPTR + 1] = newblk % 65536 / 256;
             block0[LLPTR + 2] = newblk % 256;              block0[LLPTR + 2] = newblk % 256;
                           
             lseek (filedes, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);              lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);
             write (filedes, block0, BLOCKLEN);              write (g->fd, block0, BLOCKLEN);
   
         }          }
   
Line 2901  static void splitp (short filedes, char Line 3028  static void splitp (short filedes, char
         (*addr) -= limit;          (*addr) -= limit;
         (*offs) -= limit;          (*offs) -= limit;
                   
         lseek (filedes, hdr_offset + ((long) (*blknbr) * (long) (BLOCKLEN)), SEEK_SET);          lseek (g->fd, hdr_offset + ((long) (*blknbr) * (long) (BLOCKLEN)), SEEK_SET);
         write (filedes, block, BLOCKLEN);          write (g->fd, block, BLOCKLEN);
         stcpy0 (block, block0, (long) BLOCKLEN);          stcpy0 (block, block0, (long) BLOCKLEN);
                   
         (*blknbr) = newblk;          (*blknbr) = newblk;
                   
         insert (filedes, &block0[2], (long) UNSIGN (block0[0]), newblk);          insert (g, &block0[2], (long) UNSIGN (block0[0]), newblk);
                   
         /* up-date LL-PTR of RL-block */          /* up-date LL-PTR of RL-block */
         if (other != 0) {          if (other != 0) {
   
             lseek (filedes, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);              lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);
             read (filedes, block0, BLOCKLEN);              read (g->fd, block0, BLOCKLEN);
                           
             block0[LLPTR] = newblk / 65536;              block0[LLPTR] = newblk / 65536;
             block0[LLPTR + 1] = newblk % 65536 / 256;              block0[LLPTR + 1] = newblk % 65536 / 256;
             block0[LLPTR + 2] = newblk % 256;              block0[LLPTR + 2] = newblk % 256;
                           
             lseek (filedes, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);              lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);
             write (filedes, block0, BLOCKLEN);              write (g->fd, block0, BLOCKLEN);
   
         }          }
   
Line 2935  static void splitp (short filedes, char Line 3062  static void splitp (short filedes, char
  *  ins_key:    key to be inserted   *  ins_key:    key to be inserted
  *  keyl:       length of that key   *  keyl:       length of that key
  */   */
 static void update (short filedes, char *ins_key, long keyl)  static void update (global_handle *g, char *ins_key, long keyl)
 {  {
     long offset;      long offset;
     long addr;      long addr;
Line 2953  static void update (short filedes, char Line 3080  static void update (short filedes, char
         blknbr = traceblk[trx];          blknbr = traceblk[trx];
         addr = traceadr[trx];          addr = traceadr[trx];
                   
         lseek (filedes, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);          lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);
         read (filedes, block, BLOCKLEN);          read (g->fd, block, BLOCKLEN);
                   
         {          {
             long    oldkeyl;              long    oldkeyl;
Line 2981  static void update (short filedes, char Line 3108  static void update (short filedes, char
             else if (j < 0) {           /* we need more space */              else if (j < 0) {           /* we need more space */
                           
                 /* block too small */                  /* block too small */
                 if ((offset - j) > DATALIM) splitp (filedes, block, &addr, &offset, &blknbr);                  if ((offset - j) > DATALIM) splitp (g, block, &addr, &offset, &blknbr);
                                   
                 i = offset;                  i = offset;
                 offset -= j;                  offset -= j;
Line 3004  static void update (short filedes, char Line 3131  static void update (short filedes, char
             while (i < keyl) block[j++] = ins_key[i++];              while (i < keyl) block[j++] = ins_key[i++];
                           
             /* block pointed to remains the same */              /* block pointed to remains the same */
             lseek (filedes, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);              lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);
             write (filedes, block, BLOCKLEN);              write (g->fd, block, BLOCKLEN);
   
         }          }
                   
         lseek (filedes, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);          lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);
         read (filedes, block, BLOCKLEN);          read (g->fd, block, BLOCKLEN);
   
     }      }
   
Line 3025  static void update (short filedes, char Line 3152  static void update (short filedes, char
  *  key_len:    length of that key   *  key_len:    length of that key
  *  blknbr:     key points to this block   *  blknbr:     key points to this block
  */   */
 static void insert (int filedes, char *ins_key, long key_len, unsigned long blknbr)     /* insert pointer */  static void insert (global_handle *g, char *ins_key, long key_len, unsigned long blknbr)        /* insert pointer */
 {  {
     unsigned long blk;      unsigned long blk;
     char block[BLOCKLEN];      char block[BLOCKLEN];
Line 3042  static void insert (int filedes, char *i Line 3169  static void insert (int filedes, char *i
     blk = traceblk[trx];      blk = traceblk[trx];
     addr = traceadr[trx];      addr = traceadr[trx];
   
     lseek (filedes, hdr_offset + ((long) (blk) * (long) (BLOCKLEN)), SEEK_SET);      lseek (g->fd, hdr_offset + ((long) (blk) * (long) (BLOCKLEN)), SEEK_SET);
     read (filedes, block, BLOCKLEN);      read (g->fd, block, BLOCKLEN);
           
     offset = UNSIGN (block[OFFS]) * 256 +      offset = UNSIGN (block[OFFS]) * 256 +
     UNSIGN (block[OFFS + 1]);      UNSIGN (block[OFFS + 1]);
Line 3055  static void insert (int filedes, char *i Line 3182  static void insert (int filedes, char *i
   
     needed = key_len + 2 + PLEN;      needed = key_len + 2 + PLEN;
           
     if ((offset + needed) > DATALIM) splitp (filedes, block, &addr, &offset, &blk);      if ((offset + needed) > DATALIM) splitp (g, block, &addr, &offset, &blk);
           
     /*  insert key */      /*  insert key */
     i = (offset += needed);      i = (offset += needed);
Line 3079  static void insert (int filedes, char *i Line 3206  static void insert (int filedes, char *i
     block[i++] = blknbr % 65536 / 256;      block[i++] = blknbr % 65536 / 256;
     block[i] = blknbr % 256;      block[i] = blknbr % 256;
   
     lseek (filedes, hdr_offset + ((long) (blk) * (long) (BLOCKLEN)), SEEK_SET);      lseek (g->fd, hdr_offset + ((long) (blk) * (long) (BLOCKLEN)), SEEK_SET);
     write (filedes, block, BLOCKLEN);      write (g->fd, block, BLOCKLEN);
           
     trx = trxsav;      trx = trxsav;
           
Line 3584  short g_numeric (char *str) Line 3711  short g_numeric (char *str)
   
 }                                       /* end g_numeric() */  }                                       /* end g_numeric() */
   
   
   /* DEPRECATED: use gbl_close_all() instead */
 void close_all_globals (void)  void close_all_globals (void)
 {                                         {                                       
     register int i;      gbl_close_all ();
       
     for (i = 0; i < NO_GLOBLS; i++) {  
           
         if (oldfil[i][0] != NUL) {  
               
             close (olddes[i]);  
               
             usage[i] = 0;  
             olddes[i] = 0;  
             oldfil[i][0] = NUL;  
   
         }  
   
     }  
   
     return;      return;
   
 }                                       /* end close_all_globals() */  }                                       /* end close_all_globals() */
   
 static void panic (void)  static void panic (void)
Line 3630  static void panic (void) Line 3744  static void panic (void)
 void gbl_dump_stat(void)  void gbl_dump_stat(void)
 {  {
     global_handle *g;      global_handle *g;
       int ct;
       int miss_pct;
       int hit_pct;
       unsigned long access_total;   
       unsigned long hit_total;
           
     printf ("FreeM Global Statistics [PID %d]\r\n", pid);      printf ("\r\nFreeM Global Statistics [PID %d]\r\n\r\n", pid);
   
     printf ("%-20s%-10s%-20s%-10s%s\r\n", "GLOBAL", "USECT", "AGE", "LAST BLK", "FILE");      printf ("%-20s%-10s%-12s%-20s%-10s%s\r\n", "GLOBAL", "USECT", "SLOW PTHCT", "AGE", "LAST BLK", "FILE");
     printf ("%-20s%-10s%-20s%-10s%s\r\n", "======", "=====", "===", "========", "====");      printf ("%-20s%-10s%-12s%-20s%-10s%s\r\n", "======", "=====", "==========", "===", "========", "====");
       
       access_total = 0;
       ct = 0;
     for (g = global_handles_head; g != NULL; g = g->next) {      for (g = global_handles_head; g != NULL; g = g->next) {
         printf ("%-20s%-10d%-20d%-10d%s\r\n", g->global_name, g->use_count, g->age, g->last_block, g->global_path);          printf ("%-20s%-10d%-12d%-20d%-10d%s\r\n",
     }                  g->global_name,
                       g->use_count,
                   g->cache_misses,
                   g->age,
                   g->last_block,
                   g->global_path);
           ct++;
           access_total += g->use_count;      
       }
       if (!ct) printf ("<no globals opened in this pid>\r\n");
   
       hit_total = access_total - gbl_cache_misses;
       miss_pct = (gbl_cache_misses * 100) / access_total;
       hit_pct = (hit_total * 100) / access_total;
       
       printf ("\r\nTotal accesses:      %ld\r\n", access_total);
       printf ("Fast path hits       %ld\t(%d%%)\r\n", hit_total, hit_pct);
       printf ("Fast path misses:    %ld\t(%d%%)\r\n", gbl_cache_misses, miss_pct);    
 }  }

Removed from v.1.9  
changed lines
  Added in v.1.13


FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>