Diff for /freem/src/global_bltin.c between versions 1.10 and 1.11

version 1.10, 2025/04/08 20:00:56 version 1.11, 2025/04/08 21:41:13
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.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   *   Revision 1.10  2025/04/08 20:00:56  snw
  *   Global handler now uses a header file and maintains the last journaling transaction ID   *   Global handler now uses a header file and maintains the last journaling transaction ID
  *   *
Line 65 Line 68
 global_handle *global_handles_head;  global_handle *global_handles_head;
   
 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 1360  s10:            { Line 1363  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 2171  p_empty:  /* entry if pointer block goes Line 2174  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 2217  p_empty:  /* entry if pointer block goes Line 2220  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 2580  splitd:    /* split data block in two se Line 2583  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 2626  splitd:    /* split data block in two se Line 2629  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 2745  splitd:    /* split data block in two se Line 2748  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 2787  splitd:    /* split data block in two se Line 2790  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 2827  spltex: Line 2830  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 2840  static void splitp (short filedes, char Line 2843  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 2875  static void splitp (short filedes, char Line 2878  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 2893  static void splitp (short filedes, char Line 2896  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 2947  static void splitp (short filedes, char Line 2950  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 2990  static void splitp (short filedes, char Line 2993  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 3024  static void splitp (short filedes, char Line 3027  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 3042  static void update (short filedes, char Line 3045  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 3070  static void update (short filedes, char Line 3073  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 3093  static void update (short filedes, char Line 3096  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 3114  static void update (short filedes, char Line 3117  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 3131  static void insert (int filedes, char *i Line 3134  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 3144  static void insert (int filedes, char *i Line 3147  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 3168  static void insert (int filedes, char *i Line 3171  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;
           

Removed from v.1.10  
changed lines
  Added in v.1.11


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