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

version 1.10, 2025/04/08 20:00:56 version 1.25, 2025/05/02 16:30:16
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.10  2025/04/08 20:00:56  snw   *   Revision 1.25  2025/05/02 16:30:16  snw
  *   Global handler now uses a header file and maintains the last journaling transaction ID   *   Fix broken build due to time issues
  *   *
  *   Revision 1.9  2025/04/08 16:46:11  snw   *   Revision 1.24  2025/04/28 14:52:54  snw
  *   Add global file header and offsets   *   Temporarily revert global handler refactor and fix reference regression in xecline
  *  
  *   Revision 1.8  2025/04/08 14:39:21  snw  
  *   Initial work on global handler refactor  
  *   *
  *   Revision 1.7  2025/03/24 04:13:11  snw   *   Revision 1.7  2025/03/24 04:13:11  snw
  *   Replace action macro dat with fra_dat to avoid symbol conflict on OS/2   *   Replace action macro dat with fra_dat to avoid symbol conflict on OS/2
Line 55 Line 52
 #include <fcntl.h>  #include <fcntl.h>
 #include <unistd.h>  #include <unistd.h>
 #include <string.h>  #include <string.h>
 #include <stdlib.h>  #if defined(USE_SYS_TIME_H) && !defined(MSDOS) && !defined(__osf__)
   # include <sys/time.h>
   #else
   # include <time.h> 
   #endif
   
 #include <errno.h>  #include <errno.h>
   
 #include "mpsdef.h"  
 #include "journal.h"  
 #include "global_bltin.h"  
   
 global_handle *global_handles_head;  #include "mpsdef.h"
   
 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 (short filedes, char *block, long *addr, long *offs, unsigned long *blknbr);
Line 116  static void panic (void); Line 115  static void panic (void);
 #define BOTTOM   6  #define BOTTOM   6
 #define DATA     8  #define DATA     8
   
 #if !defined(__OpenBSD__) && !defined(_AIX) && !defined(__osf__) && !defined(MSDOS) && !defined(__vax__) && !defined(__OS2__)  #if !defined(__OpenBSD__) && !defined(_AIX) && !defined(__osf__) && !defined(MSDOS) && !defined(__vax__) && !defined(__OS2__) && !defined(__linux__)
  long time ();   long time ();
 #endif  #endif
   
 inline long gbl_path(char *key, char *buf)  
 {  
     long savj;  
     long savch;                 /* saved j and ch for multiple pathes */  
   
     register long int i;  
     register long int j;  
     register long int k;  
     register long int ch;  
     long pathscan;                      /* flag for repeated scan of pathlist setting an undef global */  
      
     /* construct full UNIX filename */  
     savj = 0;  
     savch = ch = EOL;  
     pathscan = TRUE;  
 nextpath:  
     k = 0;  
     j = savj;  
   
     if (key[1] == '%' || key[1] == '$') {               /* %-globals and SSVN backing storage, no explicit path */  
           
         if (gloplib[0] != EOL) {  
               
             /* append % global access path */  
             while ((ch = buf[k++] = gloplib[j++]) != ':' && ch != EOL);   
   
         }   
   
     }  
     else if (key[1] != '/') {           /* no explicit path specified */  
           
         if (glopath[0] != EOL) {  
   
             /* append global access path */  
             while ((ch = buf[k++] = glopath[j++]) != ':' && ch != EOL);  
   
         }  
   
     }  
   
     if (savj == 0 && ch == EOL) pathscan = FALSE;               /* one path only: inhibit search */  
       
     if (k > 0) {  
   
         if (k == 1 || (k == 2 && buf[0] == '.')) {  
             k = 0;  
         }  
         else {  
             buf[k - 1] = '/';  
         }  
   
     }  
   
     savch = ch;  
     savj = j;  
     i = 0;  
     j = 0;  
   
     while (key[i] != EOL) {  
   
         if ((buf[k] = key[i]) == DELIM) break;  
           
         if (buf[k] == '/') {  
               
             j = i;  
   
             if (k > i) {  
                 i = 0;  
                 j = 0;  
                 k = 0;  
   
                 continue;  
             }  
   
         }  
   
         i++;  
         k++;  
       
     }  
   
     buf[k] = NUL;                       /* NUL not EOL !!! */  
   
     return i;  
 } /* gbl_path() */  
   
 int gbl_lock(global_handle *g, int type)  
 {  
     if (g->locked == TRUE || lonelyflag == TRUE) {  
         return TRUE;  
     }  
   
     locking (g->fd, type, 0L);  
     g->locked = TRUE;  
 } /* gbl_lock() */  
   
 int gbl_unlock(global_handle *g)  
 {  
     if (g->locked == FALSE || lonelyflag == TRUE) {  
         return TRUE;  
     }  
   
     locking (g->fd, 0, 0L);  
     g->locked = FALSE;  
 } /* gbl_unlock() */  
   
 void gbl_close(global_handle *g)  
 {  
     if (g->opened == TRUE) {  
         close (g->fd);  
   
         g->use_count = 0;  
         g->age = 0;  
         g->last_block = 0;  
         g->locked = FALSE;  
         g->opened = FALSE;  
     }  
 } /* gbl_close() */  
   
 void gbl_close_all(void)  
 {  
     global_handle *g;  
   
     for (g = global_handles_head; g != NULL; g = g->next) {  
         gbl_close (g);  
     }  
 } /* gbl_close_all() */  
   
 int gbl_write_initial_header(global_handle *g)  
 {  
     global_header hdr;  
     unsigned long old_position;  
     char m[5] = GBL_MAGIC;  
     char msg[256];  
       
     if (g->opened == FALSE) {  
         return FALSE;  
     }  
   
     memcpy (hdr.magic, m, 5);  
     hdr.format_version = GBL_FORMAT_VERSION;  
     strncpy (hdr.host_triplet, HOST, 40);  
     hdr.block_size = BLOCKLEN;  
     hdr.last_transaction_id = 0;  
     hdr.created = time (0L);  
     hdr.last_backup = -1;  
       
     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);  
   
     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);  
       
     return TRUE;      
 } /* 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)  
 {  
     while (1) {  
         errno = 0;  
   
         if ((g->fd = creat (g->global_path, 0666)) != -1) break;  
   
         if (errno == EMFILE || errno == ENFILE) {  
             gbl_close_all ();  
             continue;  
         }  
   
         return PROTECT;  
     }  
   
     g->opened = TRUE;  
     g->age = time (0L);  
     g->last_block = 0;  
     g->use_count = 1;  
   
     gbl_write_initial_header (g);  
       
     return OK;  
 } /* gbl_create() */  
   
 short gbl_open(global_handle *g, short action)  
 {  
     int result;  
     global_header h;  
       
     if (g->opened == FALSE) {  
         while (1) {  
             errno = 0;  
             g->fd = open (g->global_path, 2);  
               
             if (g->fd != -1) break;  
               
             switch (errno) {              
                 case EINTR:  
                     continue;  
                       
                 case EMFILE:  
                 case ENFILE:  
                     gbl_close_all ();  
                     continue;  
             }  
               
             break;  
         }  
           
         if (g->fd == -1) {  
             g->use_count = 0;  
             g->age = 0;  
             g->last_block = 0;  
             g->locked = FALSE;  
             g->opened = FALSE;  
         }  
         else {  
             g->opened = TRUE;  
             result = gbl_read_header (g, &h);  
   
             if (result == GBL_HDR_OK) {  
                 g->opened = TRUE;  
             }  
             else {  
                 gbl_close (g);                  
                 return FALSE;  
             }  
         }  
     }  
   
     return g->opened;  
       
 } /* gbl_open() */  
   
 global_handle *gbl_handle(char *key)  
 {  
     global_handle *g;  
     char global_name[256];  
     int i;  
     long path_len;  
     char block[BLOCKLEN];  
     struct stat dinf;              
       
     i = 0;  
     while (key[i] != EOL) {  
         if ((global_name[i] = key[i]) == DELIM) break;  
   
         i++;  
     }  
     global_name[i] = NUL;  
   
       
     for (g = global_handles_head; g != NULL; g = g->next) {  
         if (strncmp (g->global_name, global_name, 256) == 0) {  
             g->use_count++;  
             if (!lonelyflag) {  
                 g->fast_path = 0;  
             }  
   
             fstat (g->fd, &dinf);  
             if (g->age > dinf.st_mtime) {  
                 g->fast_path = 2;  
                 return g;  
             }  
   
             g->age = time (0L);  
             g->fast_path = 0;  
               
             return g;  
         }  
     }  
     g = (global_handle *) malloc (sizeof (global_handle));  
     NULLPTRCHK(g,"gbl_open");  
   
     g->use_count = 1;  
     g->locked = FALSE;  
     g->age = time (0L);  
     g->last_block = 0;  
     g->opened = FALSE;  
     g->fd = 0;  
     g->fast_path = -1;  
       
     strcpy (g->global_name, global_name);      
     gbl_path (key, g->global_path);  
       
     g->next = global_handles_head;  
     global_handles_head = g;  
   
     return g;      
 } /* gbl_handle() */  
   
   
 /* globals management */  /* globals management */
           
 /* 0 = set_sym      1 = get_sym */  /* 0 = set_sym      1 = get_sym */
Line 559  global_handle *gbl_handle(char *key) Line 193  global_handle *gbl_handle(char *key)
  * the file is *not* closed on return. since access is regulated by the   * the file is *not* closed on return. since access is regulated by the
  * locking mechanism, that will not spell trouble.   * locking mechanism, that will not spell trouble.
  */   */
    
 void global_bltin (short action, char *key, char *data)  void global_bltin (short action, char *key, char *data)
 {  {
   
     global_handle *g;  
   
     unsigned long hdr_offset;  
       
     /* these must be static variables */      /* these must be static variables */
   
     static short filedes;               /* filedescr for global access */      static short filedes;               /* filedescr for global access */
     static char filnam[256];            /* name of global/unix file */      static char filnam[256];            /* name of global/unix file */
   
     /* the following vars may be */      /* the following vars may be */
     /* static or dynamic */      /* static or dynamic */
   
     static unsigned long blknbr;        /* block number */      static unsigned long blknbr;        /* block number */
       static unsigned long oldblk;
     static unsigned long newblk;      static unsigned long newblk;
     static unsigned long other;      static unsigned long other;
     static long j1;      static long j1;
     static long limit;      static long limit;
     static short typ;                   /* block type */      static short typ;                   /* block type */
     static long keyl;                   /* length of compacted key */      static long keyl,                   /* length of compacted key */
     static long datal;                  /* length of data */                  datal,                  /* length of data */
     static long olddatal;                  olddatal,
     static long offset;                  offset,
     static long found;                  found,
     static long addr;                   /* address of key in 'block' */                  addr,                   /* address of key in 'block' */
     static long needed;                 /* new bytes needed to ins. stuff */                  needed,                 /* new bytes needed to ins. stuff */
     static long ret_to;                 /* return code */                  ret_to,                 /* return code */
     static long kill_again;                  kill_again;
     static char key1[256];      static char key1[256];
     static char tmp1[256];              /* intermediate storage for op= */      static char tmp1[256];              /* intermediate storage for op= */
     static char block[BLOCKLEN];      static char block[BLOCKLEN];
Line 595  void global_bltin (short action, char *k Line 228  void global_bltin (short action, char *k
     static int tryfast;                 /* try fast access if get_sym on    */      static int tryfast;                 /* try fast access if get_sym on    */
                                 /* previous global */                                  /* previous global */
   
     int iresult;  
       
     struct stat dinf;                   /* get modification date */      struct stat dinf;                   /* get modification date */
   
     long savj;      long    savj,
     long savch;                 /* saved j and ch for multiple pathes */      savch;                      /* saved j and ch for multiple pathes */
     register long int i;      register long int i,
     register long int j;      j,
     register long int k;      k,
     register long int ch;      ch;
     long pathscan;                      /* flag for repeated scan of pathlist setting an undef global */      long    pathscan;                   /* flag for repeated scan of pathlist setting an undef global */
   
   
     hdr_offset = sizeof (global_header);  
       
     /* process optional limitations */      /* process optional limitations */
     if (glvnflag.all && key[0] >= '%' && key[0] <= 'z') {      if (glvnflag.all && key[0] >= '%' && key[0] <= 'z') {
   
Line 685  void global_bltin (short action, char *k Line 315  void global_bltin (short action, char *k
         }          }
     }      }
   
   
     if (action == getnext) {      if (action == getnext) {
   
         getnflag = TRUE;          getnflag = TRUE;
         varnam[0] = EOL;          varnam[0] = EOL;
                   
Line 760  void global_bltin (short action, char *k Line 390  void global_bltin (short action, char *k
         }          }
     }      }
   
     g = gbl_handle (key);          /* construct full UNIX filename */
     i = gbl_path (key, filnam);      savj = 0;
       savch = ch = EOL;
       pathscan = TRUE;
       nextpath:
       k = 0;
       j = savj;
   
       if (key[1] == '%' || key[1] == '$') {               /* %-globals and SSVN backing storage, no explicit path */
           
           if (gloplib[0] != EOL) {
               
               /* append % global access path */
               while ((ch = filnam[k++] = gloplib[j++]) != ':' && ch != EOL); 
   
           } 
   
       }
       else if (key[1] != '/') {           /* no explicit path specified */
                   
           if (glopath[0] != EOL) {
   
               /* append global access path */
               while ((ch = filnam[k++] = glopath[j++]) != ':' && ch != EOL);
   
           }
   
       }
   
       if (savj == 0 && ch == EOL) pathscan = FALSE;               /* one path only: inhibit search */
       
       if (k > 0) {
   
           if (k == 1 || (k == 2 && filnam[0] == '.')) {
               k = 0;
           }
           else {
               filnam[k - 1] = '/';
           }
   
       }
   
       savch = ch;
       savj = j;
       i = 0;
       j = 0;
   
       while (key[i] != EOL) {
   
           if ((filnam[k] = key[i]) == DELIM) break;
           
           if (filnam[k] == '/') {
               
               j = i;
   
               if (k > i) {
                   i = 0;
                   j = 0;
                   k = 0;
   
                   continue;
               }
   
           }
   
           i++;
           k++;
       
       }
   
       filnam[k] = NUL;                    /* NUL not EOL !!! */
   
       /* if a unix directory is specified, reposition '^' */
       /* '^/usr/test' becomes '/usr/^test'                */
       if (j > 0) {
   
           for (k = 0; k < j; k++) {
               filnam[k] = filnam[k + 1];
           }
       
           filnam[j] = '^';
   
       }
   
     /* compact key to internal format: characters are shifted left */      /* compact key to internal format: characters are shifted left */
     /* delimiters become LSB of previous character                 */      /* delimiters become LSB of previous character                 */
     /* test subscripts for being numeric or not                    */      /* test subscripts for being numeric or not                    */
Line 898  void global_bltin (short action, char *k Line 609  void global_bltin (short action, char *k
   
     compactkey[k] = g_EOL;      compactkey[k] = g_EOL;
   
       /* look whether file is already open */
       tryfast = FALSE;
       ch = usage[i = j = inuse];
       
       while (i < NO_GLOBLS) {
           
           k = 0;
           
           while (filnam[k] == oldfil[i][k]) {
   
               if (filnam[k++] == NUL) {
   
                   filedes = olddes[i];
   
                   if (inuse == i && action == get_sym) {
                       
                       tryfast = TRUE;
                       
                       if (usage[i] != (-1)) usage[i]++;
                       if (lonelyflag) goto tfast2;
                       
                       fstat (filedes, &dinf);
                       
                       if (g_ages[i] > dinf.st_mtime) goto tfast2;
                       
                       g_ages[i] = time (0L);
                       
                       goto tfast0;
   
                   }
   
                   inuse = i;
   
                   if (usage[i] != (-1)) usage[i]++;
                   
                   goto lock;
               }
   
           }
   
           if (ch < 0 || (usage[i] >= 0 && usage[i] < ch)) ch = usage[j = i];
           
           if (i++ == inuse) {
               inuse = (-1);
               i = 0;
           }
   
       }
   
       inuse = j;
       usage[j] = 1;
   
       /* close previous file */
       if ((filedes = olddes[j]) > 0) {
           close (filedes);
           olddes[j] = 0;
       }
   
       strcpy (oldfil[j], filnam);         /* save current filename */
   
 reopen:  reopen:
   
     gbl_open (g, action);      for (;;) {
     if (g->fd == -1) {  
           errno = 0;
           
           if ((filedes = open (filnam, 2)) != -1) break;
           if (errno == EINTR) continue;
   
           if (errno == EMFILE || errno == ENFILE) {       /* too many open files now */
               close_all_globals ();
               
               continue;
           }
   
           break;
       }
   
       if (filedes == -1) {
   
           usage[inuse] = 0;
           oldfil[inuse][0] = NUL;
           olddes[inuse] = 0;
           g_ages[inuse] = 0;
           
           if ((pathscan || errno != ENOENT) && (savch != EOL)) goto nextpath;             /* try next access path */
           
         /* file not found */          /* file not found */
         if (action != set_sym) {          if (action != set_sym) {
                           
Line 935  reopen: Line 728  reopen:
             merr_raise (PROTECT);              merr_raise (PROTECT);
             return;              return;
         }          }
           
           if (pathscan) {
               savj = 0;
               savch = ch = EOL;
               pathscan = FALSE;
   
               goto nextpath;
           }
   
         if (setop) {          if (setop) {
                           
             tmp1[0] = EOL;              tmp1[0] = EOL;
Line 965  reopen: Line 766  reopen:
         block[NRBLK + 2] = ROOT + 1;    /* nr. of blocks */          block[NRBLK + 2] = ROOT + 1;    /* nr. of blocks */
   
         /* create file, write_lock it and initialize root block */          /* create file, write_lock it and initialize root block */
         gbl_lock (g, 1);          for (;;) {
   
               errno = 0;
               
               if ((filedes = creat (filnam, 0666)) != -1) break;
   
         if ((iresult = gbl_create (g)) != OK) {              if (errno == EMFILE || errno == ENFILE) {
             merr_raise (iresult);                  close_all_globals ();
                   continue;
               }
   
               merr_raise (PROTECT);
             return;              return;
         }                  }
   
           if (lonelyflag == FALSE) locking (filedes, 1, 0L);
                   
         for (;;) {          for (;;) {
                           
             errno = 0;              errno = 0;
                   
             lseek (g->fd, hdr_offset + (ROOT * BLOCKLEN), SEEK_SET);              lseek (filedes, ROOT * BLOCKLEN, 0);
             write (g->fd, block, BLOCKLEN);              write (filedes, block, BLOCKLEN);
                   
             if (errno == 0) break;              if (errno == 0) break;
                   
Line 998  reopen: Line 809  reopen:
         for (;;) {          for (;;) {
   
             errno = 0;              errno = 0;
             write (g->fd, block, BLOCKLEN);              write (filedes, block, BLOCKLEN);
                           
             if (errno == 0) break;              if (errno == 0) break;
                           
             lseek (g->fd, hdr_offset + ((ROOT + 1L) * BLOCKLEN), SEEK_SET);              lseek (filedes, (ROOT + 1L) * BLOCKLEN, 0);
             panic ();              panic ();
   
         }          }
   
         gbl_close (g);          close (filedes);
         gbl_unlock (g);          
         gbl_open (g, action);          if (lonelyflag == FALSE) locking (filedes, 0, 0L);      /* unlock */
           
         /* close new file, so other users can find it */          /* close new file, so other users can find it */
         return;          return;
     }      }
   
       olddes[inuse] = filedes;            /* save current filedescriptor */
   
     /* request global for exclusive use                            */      /* request global for exclusive use                            */
     /* odd numbered actions get read access (get_sym,data,fra_order) 3 */      /* odd numbered actions get read access (get_sym,data,fra_order) 3 */
     /* even ones read/write access          (set_sym,kill_sym)   1 */      /* even ones read/write access          (set_sym,kill_sym)   1 */
Line 1024  lock: Line 837  lock:
     if (action == get_sym) {      if (action == get_sym) {
   
 tfast0:  tfast0:
         gbl_lock (g, 3);  
           if (lonelyflag == FALSE) locking (filedes, 3, 0L);        
         if (tryfast) goto tfast1;               /* try again last block */          if (tryfast) goto tfast1;               /* try again last block */
                   
         blknbr = g->last_block = ROOT;          /* start with ROOT block */          blknbr = oldblk = ROOT;         /* start with ROOT block */
                   
         for (;;) {          for (;;) {
   
   
 tfast1:  tfast1:
   
             lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);              lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
             read (g->fd, block, BLOCKLEN);              read (filedes, block, BLOCKLEN);
   
   
 tfast2:  tfast2:
Line 1079  tfast2: Line 893  tfast2:
   
                 }                  }
   
                   /* key1[j]=g_EOL; */
                 j = ch;                  j = ch;
                                   
                 do {                  do {
Line 1122  tfast2: Line 937  tfast2:
             if (typ == EMPTY) {              if (typ == EMPTY) {
                                   
                 if (blknbr == ROOT) {                  if (blknbr == ROOT) {
                     //close (filedes);                      close (filedes);
                     gbl_close (g);  
                     goto reopen;                      goto reopen;
                 }                  }
   
Line 1138  tfast2: Line 952  tfast2:
   
         addr += UNSIGN (block[addr]) + 2;       /* skip key */          addr += UNSIGN (block[addr]) + 2;       /* skip key */
                   
         if ((blknbr = UNSIGN (block[addr]) * 65536 + UNSIGN (block[addr + 1]) * 256 + UNSIGN (block[addr + 2])) == g->last_block) {          if ((blknbr = UNSIGN (block[addr]) * 65536 + UNSIGN (block[addr + 1]) * 256 + UNSIGN (block[addr + 2])) == oldblk) {
             merr_raise (DBDGD);              merr_raise (DBDGD);
             goto quit;              goto quit;
         }          }
   
         addr += PLEN;           /* skip data */          addr += PLEN;           /* skip data */
         g->last_block = blknbr;          oldblk = blknbr;
                   
         if (merr () == INRPT) goto quit;          if (merr () == INRPT) goto quit;
   
         }          }
     }                                   /* end of get_sym */      }                                   /* end of get_sym */
   
     gbl_lock (g, action & 01 ? 3 : 1);  
           if (lonelyflag == FALSE) locking (filedes, (action & 01 ? 3 : 1), 0L);
   
     /* a KILL on an unsubscripted global deletes the entire file */      /* a KILL on an unsubscripted global deletes the entire file */
     if (action == kill_sym && compactkey[0] == g_EOL) {      if (action == kill_sym && compactkey[0] == g_EOL) {
                   
         lseek (g->fd, hdr_offset + ROOT, SEEK_SET);          lseek (filedes, ROOT, 0);
   
         /* note : UNIX does not tell other    */          /* note : UNIX does not tell other    */
         block[BTYP] = EMPTY;            /* jobs that a file has been unlinked */          block[BTYP] = EMPTY;            /* jobs that a file has been unlinked */
                   
         /* as long as they keep it open.      */          /* as long as they keep it open.      */
         /* so we mark this global as EMPTY    */          /* so we mark this global as EMPTY    */
         write (g->fd, block, BLOCKLEN);          write (filedes, block, BLOCKLEN);
           
         gbl_unlock (g);          if (lonelyflag == FALSE) locking (filedes, 0, 0L);      /* unlock */
         gbl_close (g);          
           close (filedes);
           
           olddes[inuse] = 0;
           oldfil[inuse][0] = NUL;
           usage[inuse] = 0;
                   
         unlink (filnam);          unlink (filnam);
                   
Line 1176  tfast2: Line 996  tfast2:
 k_again:                                /* entry point for repeated kill operations */  k_again:                                /* entry point for repeated kill operations */
   
     /* scan tree for the proper position of key */      /* scan tree for the proper position of key */
     blknbr = g->last_block = ROOT;              /* start with ROOT block */      blknbr = oldblk = ROOT;             /* start with ROOT block */
     trx = (-1);      trx = (-1);
   
     for (;;) {      for (;;) {
Line 1189  k_again:    /* entry point for repeated Line 1009  k_again:    /* entry point for repeated
         traceblk[trx] = blknbr;          traceblk[trx] = blknbr;
         traceadr[trx] = 0;          traceadr[trx] = 0;
                   
         lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);          lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
         read (g->fd, block, BLOCKLEN);          read (filedes, block, BLOCKLEN);
                   
         typ = block[BTYP];          typ = block[BTYP];
                   
Line 1202  k_again:    /* entry point for repeated Line 1022  k_again:    /* entry point for repeated
         if (typ == EMPTY) {          if (typ == EMPTY) {
   
             if (blknbr == ROOT) {              if (blknbr == ROOT) {
                 gbl_close (g);                  close (filedes);
                 goto reopen;                  goto reopen;
             }              }
   
Line 1216  k_again:    /* entry point for repeated Line 1036  k_again:    /* entry point for repeated
         addr += UNSIGN (block[addr]);          addr += UNSIGN (block[addr]);
         addr += 2;                      /* skip key */          addr += 2;                      /* skip key */
                   
         if ((blknbr = UNSIGN (block[addr]) * 65536 + UNSIGN (block[addr + 1]) * 256 + UNSIGN (block[addr + 2])) == g->last_block) {          if ((blknbr = UNSIGN (block[addr]) * 65536 + UNSIGN (block[addr + 1]) * 256 + UNSIGN (block[addr + 2])) == oldblk) {
             merr_raise (DBDGD);              merr_raise (DBDGD);
             goto quit;              goto quit;
         }          }
   
         addr += PLEN;                   /* skip data */          addr += PLEN;                   /* skip data */
         g->last_block = blknbr;          oldblk = blknbr;
     }      }
   
     traceadr[trx] = addr;      traceadr[trx] = addr;
Line 1357  s10:            { Line 1177  s10:            {
   
                 }                  }
   
                 lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                  lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
                 write (g->fd, block, BLOCKLEN);                  write (filedes, block, BLOCKLEN);
   
                 if (traceadr[trx] == 0) update (g->fd, compactkey, keyl);                  if (traceadr[trx] == 0) update (filedes, compactkey, keyl);
   
                 break;                  break;
             }              }
Line 1402  s10:            { Line 1222  s10:            {
   
                 }                   } 
                 else {                                    else {                  
                       /* if (j1<0) */
                     /* we need more space */                       /* we need more space */ 
   
                     if ((offset - j1) > DATALIM) {                      if ((offset - j1) > DATALIM) {
Line 1444  s20: Line 1265  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 (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
             write (g->fd, block, BLOCKLEN);              write (filedes, block, BLOCKLEN);
   
             gbl_update_tid (g);  
               
             break;              break;
   
   
Line 1479  s20: Line 1297  s20:
   
                     if ((blknbr = UNSIGN (block[RLPTR]) * 65536 + UNSIGN (block[RLPTR + 1]) * 256 + UNSIGN (block[RLPTR + 2]))) {                      if ((blknbr = UNSIGN (block[RLPTR]) * 65536 + UNSIGN (block[RLPTR + 1]) * 256 + UNSIGN (block[RLPTR + 2]))) {
                                           
                         lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                          lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
                         read (g->fd, block, BLOCKLEN);                          read (filedes, block, BLOCKLEN);
                         j1 = UNSIGN (block[0]);                          j1 = UNSIGN (block[0]);
                                           
                         i = 0;                          i = 0;
Line 1562  s20: Line 1380  s20:
                     goto quit;                      goto quit;
                 }       /* no next block */                  }       /* no next block */
                                   
                 lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                  lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
                 read (g->fd, block, BLOCKLEN);                  read (filedes, block, BLOCKLEN);
                 scandblk (block, &addr, &found);                  scandblk (block, &addr, &found);
   
             }               } 
Line 1719  s20: Line 1537  s20:
                         goto quit;              /* no next block */                          goto quit;              /* no next block */
                     }                      }
   
                     lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                      lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
                     read (g->fd, block, BLOCKLEN);                      read (filedes, block, BLOCKLEN);
   
                     addr = 0;                      addr = 0;
                     offset = UNSIGN (block[OFFS]) * 256 +                      offset = UNSIGN (block[OFFS]) * 256 +
Line 1743  s20: Line 1561  s20:
                     goto quit;          /* no next block */                      goto quit;          /* no next block */
                 }                  }
   
                 lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                  lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
                 read (g->fd, block, BLOCKLEN);                  read (filedes, block, BLOCKLEN);
                                   
                 addr = 0;                  addr = 0;
             }               } 
Line 1954  killo:    /* entry from killone section Line 1772  killo:    /* entry from killone section
                         other = traceblk[--trx];                          other = traceblk[--trx];
                         addr = traceadr[trx];                          addr = traceadr[trx];
                                                   
                         lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);                          lseek (filedes, (long) other * (long) (BLOCKLEN), 0);
                         read (g->fd, block, BLOCKLEN);                          read (filedes, block, BLOCKLEN);
                                                   
                         addr += UNSIGN (block[addr]);                          addr += UNSIGN (block[addr]);
                         addr += (2 + PLEN);     /* skip previous entry */                          addr += (2 + PLEN);     /* skip previous entry */
Line 1974  killo:    /* entry from killone section Line 1792  killo:    /* entry from killone section
   
                     trx = trxsav;                      trx = trxsav;
   
                     lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                      lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
                     read (g->fd, block, BLOCKLEN);                      read (filedes, block, BLOCKLEN);
   
                     offset = UNSIGN (block[OFFS]) * 256 +                      offset = UNSIGN (block[OFFS]) * 256 +
                     UNSIGN (block[OFFS + 1]);                      UNSIGN (block[OFFS + 1]);
Line 2081  p_empty:  /* entry if pointer block goes Line 1899  p_empty:  /* entry if pointer block goes
   
                     if (left) {                      if (left) {
   
                         lseek (g->fd, hdr_offset + ((long) left * (long) (BLOCKLEN)), SEEK_SET);                          lseek (filedes, (long) left * (long) (BLOCKLEN), 0);
                         read (g->fd, block0, BLOCKLEN);                          read (filedes, block0, BLOCKLEN);
                                                   
                         block0[RLPTR] = block[RLPTR];                          block0[RLPTR] = block[RLPTR];
                         block0[RLPTR + 1] = block[RLPTR + 1];                          block0[RLPTR + 1] = block[RLPTR + 1];
                         block0[RLPTR + 2] = block[RLPTR + 2];                          block0[RLPTR + 2] = block[RLPTR + 2];
                                                   
                         lseek (g->fd, hdr_offset + ((long) left * (long) (BLOCKLEN)), SEEK_SET);                          lseek (filedes, (long) left * (long) (BLOCKLEN), 0);
                         write (g->fd, block0, BLOCKLEN);                          write (filedes, block0, BLOCKLEN);
   
                     }                      }
   
                     if (right) {                      if (right) {
                                                   
                         lseek (g->fd, hdr_offset + ((long) right * (long) (BLOCKLEN)), SEEK_SET);                          lseek (filedes, (long) right * (long) (BLOCKLEN), 0);
                         read (g->fd, block0, BLOCKLEN);                          read (filedes, block0, BLOCKLEN);
                                                   
                         block0[LLPTR] = block[LLPTR];                          block0[LLPTR] = block[LLPTR];
                         block0[LLPTR + 1] = block[LLPTR + 1];                          block0[LLPTR + 1] = block[LLPTR + 1];
                         block0[LLPTR + 2] = block[LLPTR + 2];                          block0[LLPTR + 2] = block[LLPTR + 2];
                                                   
                         lseek (g->fd, hdr_offset + ((long) right * (long) (BLOCKLEN)), SEEK_SET);                          lseek (filedes, (long) right * (long) (BLOCKLEN), 0);
                         write (g->fd, block0, BLOCKLEN);                          write (filedes, block0, BLOCKLEN);
   
                     }                      }
   
                     b_free (g->fd, blknbr);     /* modify free list */                      b_free (filedes, blknbr);   /* modify free list */
                                           
                     /* delete pointer */                      /* delete pointer */
                     /**************************/                      /**************************/
Line 2120  p_empty:  /* entry if pointer block goes Line 1938  p_empty:  /* entry if pointer block goes
                         blknbr = traceblk[--trx];                          blknbr = traceblk[--trx];
                         addr = traceadr[trx];                          addr = traceadr[trx];
   
                         lseek (g->fd, hdr_offset + ((long) (blknbr) * (long) (BLOCKLEN)), SEEK_SET);                          lseek (filedes, (long) (blknbr) * (long) (BLOCKLEN), 0);
                         read (g->fd, block, BLOCKLEN);                          read (filedes, block, BLOCKLEN);
                         offset = UNSIGN (block[OFFS]) * 256 +                          offset = UNSIGN (block[OFFS]) * 256 +
                         UNSIGN (block[OFFS + 1]);                          UNSIGN (block[OFFS + 1]);
                         freecnt = UNSIGN (block[addr]) + 2 + PLEN;                          freecnt = UNSIGN (block[addr]) + 2 + PLEN;
Line 2133  p_empty:  /* entry if pointer block goes Line 1951  p_empty:  /* entry if pointer block goes
   
                             if (blknbr == ROOT) {       /* global went empty */                              if (blknbr == ROOT) {       /* global went empty */
   
                                 lseek (g->fd, hdr_offset + 0L, SEEK_SET);                                  lseek (filedes, 0L, 0);
                                                   
                                 /* note : UNIX does not tell other    */                                  /* note : UNIX does not tell other    */
                                 block[BTYP] = EMPTY;    /* jobs that a file has been unlinked */                                  block[BTYP] = EMPTY;    /* jobs that a file has been unlinked */
                                                   
                                 /* as long as they keep it open.      */                                  /* as long as they keep it open.      */
                                 /* so we mark this global as EMPTY    */                                  /* so we mark this global as EMPTY    */
                                 write (g->fd, block, BLOCKLEN);                                  write (filedes, block, BLOCKLEN);
                                 gbl_close (g);                                  close (filedes);
                                 unlink (filnam);                                  unlink (filnam);
                           
                                 gbl_unlock (g);                                  if (lonelyflag == FALSE) locking (filedes, 0, 0L);      /* unlock */
   
                                 olddes[inuse] = 0;                                  olddes[inuse] = 0;
                                 oldfil[inuse][0] = NUL;                                  oldfil[inuse][0] = NUL;
Line 2165  p_empty:  /* entry if pointer block goes Line 1983  p_empty:  /* entry if pointer block goes
                                                   
                         for (i = offset; i < offset + freecnt; block[i++] = 0);                          for (i = offset; i < offset + freecnt; block[i++] = 0);
   
                         lseek (g->fd, hdr_offset + ((long) (blknbr) * (long) (BLOCKLEN)), SEEK_SET);                          lseek (filedes, (long) (blknbr) * (long) (BLOCKLEN), 0);
                         write (g->fd, block, BLOCKLEN);                          write (filedes, block, BLOCKLEN);
   
                         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 (filedes, &block[2], (long) UNSIGN (block[0]));
                         }                          }
   
                         trx = trxsav;                          trx = trxsav;
Line 2213  p_empty:  /* entry if pointer block goes Line 2031  p_empty:  /* entry if pointer block goes
                 }                  }
                 block[OFFS] = offset / 256;                  block[OFFS] = offset / 256;
                 block[OFFS + 1] = offset % 256;                  block[OFFS + 1] = offset % 256;
                 lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                  lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
                 write (g->fd, block, BLOCKLEN);                  write (filedes, 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 (filedes, &block[2], (long) UNSIGN (block[0]));
                 }                  }
             }              }
   
Line 2240  zinv: Line 2058  zinv:
                         goto quit;                          goto quit;
                     }                   /* no previous block */                      }                   /* no previous block */
                                           
                     lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                      lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
                     read (g->fd, block, BLOCKLEN);                      read (filedes, block, BLOCKLEN);
                                           
                     addr = UNSIGN (block[OFFS]) * 256 +                      addr = UNSIGN (block[OFFS]) * 256 +
                     UNSIGN (block[OFFS + 1]);                      UNSIGN (block[OFFS + 1]);
Line 2420  zinv: Line 2238  zinv:
                             break;              /* no next block */                              break;              /* no next block */
                         }                          }
   
                         lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);                          lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
                         read (g->fd, block, BLOCKLEN);                          read (filedes, block, BLOCKLEN);
                                                   
                         addr = 0;                          addr = 0;
                         offset = UNSIGN (block[OFFS]) * 256 +                          offset = UNSIGN (block[OFFS]) * 256 +
Line 2536  quit: Line 2354  quit:
           
     /* clean things up */      /* clean things up */
   
     lseek (g->fd, hdr_offset + ROOT, SEEK_SET);      lseek (filedes, ROOT, 0);
     gbl_unlock (g);  
           if (lonelyflag == FALSE) locking (filedes, 0, 0L);  /* unlock */
   
     return;      return;
   
   
Line 2549  splitd:    /* split data block in two se Line 2368  splitd:    /* split data block in two se
     /* '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 */
   
     getnewblk (g->fd, &newblk); /* get a new block */      getnewblk (filedes, &newblk);       /* get a new block */
   
     /* if we have to insert at the begin or end of a block  */      /* if we have to insert at the begin or end of a block  */
     /* we don't split - we just start a new block           */      /* we don't split - we just start a new block           */
Line 2567  splitd:    /* split data block in two se Line 2386  splitd:    /* split data block in two se
         block[RLPTR + 1] = newblk % 65536 / 256;          block[RLPTR + 1] = newblk % 65536 / 256;
         block[RLPTR + 2] = newblk % 256;          block[RLPTR + 2] = newblk % 256;
   
         lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);          lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
         write (g->fd, block, BLOCKLEN);          write (filedes, block, BLOCKLEN);
                   
         block[RLPTR] = right;          block[RLPTR] = right;
         block[RLPTR + 1] = right1;          block[RLPTR + 1] = right1;
Line 2580  splitd:    /* split data block in two se Line 2399  splitd:    /* split data block in two se
         addr = 0;          addr = 0;
         blknbr = newblk;          blknbr = newblk;
                   
         insert (g->fd, compactkey, keyl, newblk);          insert (filedes, 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)) {
                   
             char    block0[BLOCKLEN];              char    block0[BLOCKLEN];
   
             lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);              lseek (filedes, (long) other * (long) (BLOCKLEN), 0);
             read (g->fd, block0, BLOCKLEN);              read (filedes, block0, BLOCKLEN);
                   
             block0[LLPTR] = blknbr / 65536;              block0[LLPTR] = blknbr / 65536;
             block0[LLPTR + 1] = blknbr % 65536 / 256;              block0[LLPTR + 1] = blknbr % 65536 / 256;
             block0[LLPTR + 2] = blknbr % 256;              block0[LLPTR + 2] = blknbr % 256;
                   
             lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);              lseek (filedes, (long) other * (long) (BLOCKLEN), 0);
             write (g->fd, block0, BLOCKLEN);              write (filedes, block0, BLOCKLEN);
                   
         }          }
                   
Line 2613  splitd:    /* split data block in two se Line 2432  splitd:    /* split data block in two se
         block[LLPTR + 1] = newblk % 65536 / 256;          block[LLPTR + 1] = newblk % 65536 / 256;
         block[LLPTR + 2] = newblk % 256;          block[LLPTR + 2] = newblk % 256;
   
         lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);          lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
         write (g->fd, block, BLOCKLEN);          write (filedes, block, BLOCKLEN);
                   
         block[LLPTR] = left;          block[LLPTR] = left;
         block[LLPTR + 1] = left1;          block[LLPTR + 1] = left1;
Line 2626  splitd:    /* split data block in two se Line 2445  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 (filedes, 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 (filedes, compactkey, keyl);
         }          }
   
         /* other is ***always*** zero !!!          /* other is ***always*** zero !!!
Line 2739  splitd:    /* split data block in two se Line 2558  splitd:    /* split data block in two se
             block0[LLPTR + 1] = blknbr % 65536 / 256;              block0[LLPTR + 1] = blknbr % 65536 / 256;
             block0[LLPTR + 2] = blknbr % 256;              block0[LLPTR + 2] = blknbr % 256;
   
             lseek (g->fd, hdr_offset + ((long) (newblk) * (long) (BLOCKLEN)), SEEK_SET);              lseek (filedes, (long) (newblk) * (long) (BLOCKLEN), 0);
             write (g->fd, block0, BLOCKLEN);              write (filedes, block0, BLOCKLEN);
                   
             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 (filedes, &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 (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);                  lseek (filedes, (long) other * (long) (BLOCKLEN), 0);
                 read (g->fd, block0, BLOCKLEN);                  read (filedes, 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 (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);                  lseek (filedes, (long) other * (long) (BLOCKLEN), 0);
                 write (g->fd, block0, BLOCKLEN);                  write (filedes, block0, BLOCKLEN);
   
             }              }
   
Line 2779  splitd:    /* split data block in two se Line 2598  splitd:    /* split data block in two se
             block0[LLPTR + 1] = blknbr % 65536 / 256;              block0[LLPTR + 1] = blknbr % 65536 / 256;
             block0[LLPTR + 2] = blknbr % 256;              block0[LLPTR + 2] = blknbr % 256;
   
             lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);              lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
             write (g->fd, block, BLOCKLEN);              write (filedes, block, BLOCKLEN);
             stcpy0 (block, block0, (long) BLOCKLEN);              stcpy0 (block, block0, (long) BLOCKLEN);
   
             traceadr[trx] = (addr -= limit);              traceadr[trx] = (addr -= limit);
             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 (filedes, &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 (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);                  lseek (filedes, (long) other * (long) (BLOCKLEN), 0);
                 read (g->fd, block0, BLOCKLEN);                  read (filedes, 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 (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET);                  lseek (filedes, (long) other * (long) (BLOCKLEN), 0);
                 write (g->fd, block0, BLOCKLEN);                  write (filedes, block0, BLOCKLEN);
   
             }              }
   
Line 2836  static void splitp (short filedes, char Line 2655  static void splitp (short filedes, char
     unsigned long other;      unsigned long other;
     register int i, j;      register int i, j;
   
     long hdr_offset;  
   
     hdr_offset = sizeof (global_header);  
       
     getnewblk (filedes, &newblk);       /* get a new block */      getnewblk (filedes, &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 2690  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 (filedes, ROOT, 0);
         write (filedes, block0, BLOCKLEN);          write (filedes, block0, BLOCKLEN);
                   
         /* shift trace_stack */          /* shift trace_stack */
Line 2947  static void splitp (short filedes, char Line 2762  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 (filedes, (long) (newblk) * (long) (BLOCKLEN), 0);
         write (filedes, block0, BLOCKLEN);          write (filedes, block0, BLOCKLEN);
   
         (*offs) = limit;          (*offs) = limit;
Line 2957  static void splitp (short filedes, char Line 2772  static void splitp (short filedes, char
         /* 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 (filedes, (long) other * (long) (BLOCKLEN), 0);
             read (filedes, block0, BLOCKLEN);              read (filedes, 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 (filedes, (long) other * (long) (BLOCKLEN), 0);
             write (filedes, block0, BLOCKLEN);              write (filedes, block0, BLOCKLEN);
   
         }          }
Line 2990  static void splitp (short filedes, char Line 2805  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 (filedes, (long) (*blknbr) * (long) (BLOCKLEN), 0);
         write (filedes, block, BLOCKLEN);          write (filedes, block, BLOCKLEN);
         stcpy0 (block, block0, (long) BLOCKLEN);          stcpy0 (block, block0, (long) BLOCKLEN);
                   
Line 3001  static void splitp (short filedes, char Line 2816  static void splitp (short filedes, char
         /* 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 (filedes, (long) other * (long) (BLOCKLEN), 0);
             read (filedes, block0, BLOCKLEN);              read (filedes, 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 (filedes, (long) other * (long) (BLOCKLEN), 0);
             write (filedes, block0, BLOCKLEN);              write (filedes, block0, BLOCKLEN);
   
         }          }
Line 3031  static void update (short filedes, char Line 2846  static void update (short filedes, char
     unsigned long blknbr;      unsigned long blknbr;
     char block[BLOCKLEN];      char block[BLOCKLEN];
     long i, j, k;      long i, j, k;
     long hdr_offset;  
   
     hdr_offset = sizeof (global_header);  
       
     while (traceadr[trx] == 0) {        /* update of pointer blocks necessary */      while (traceadr[trx] == 0) {        /* update of pointer blocks necessary */
   
         if (--trx < 0) break;          if (--trx < 0) break;
Line 3042  static void update (short filedes, char Line 2854  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 (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
         read (filedes, block, BLOCKLEN);          read (filedes, block, BLOCKLEN);
                   
         {          {
Line 3093  static void update (short filedes, char Line 2905  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 (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
             write (filedes, block, BLOCKLEN);              write (filedes, block, BLOCKLEN);
   
         }          }
                   
         lseek (filedes, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET);          lseek (filedes, (long) blknbr * (long) (BLOCKLEN), 0);
         read (filedes, block, BLOCKLEN);          read (filedes, block, BLOCKLEN);
   
     }      }
Line 3123  static void insert (int filedes, char *i Line 2935  static void insert (int filedes, char *i
     long needed;      long needed;
     long addr;      long addr;
     register int i, k;      register int i, k;
     long hdr_offset;  
   
     hdr_offset = sizeof (global_header);  
       
     trxsav = trx--;      trxsav = trx--;
     blk = traceblk[trx];      blk = traceblk[trx];
     addr = traceadr[trx];      addr = traceadr[trx];
   
     lseek (filedes, hdr_offset + ((long) (blk) * (long) (BLOCKLEN)), SEEK_SET);      lseek (filedes, (long) (blk) * (long) (BLOCKLEN), 0);
     read (filedes, block, BLOCKLEN);      read (filedes, block, BLOCKLEN);
           
     offset = UNSIGN (block[OFFS]) * 256 +      offset = UNSIGN (block[OFFS]) * 256 +
Line 3168  static void insert (int filedes, char *i Line 2977  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 (filedes, (long) (blk) * (long) (BLOCKLEN), 0);
     write (filedes, block, BLOCKLEN);      write (filedes, block, BLOCKLEN);
           
     trx = trxsav;      trx = trxsav;
Line 3188  static void b_free (short filedes, unsig Line 2997  static void b_free (short filedes, unsig
     unsigned long other;      unsigned long other;
     long i;      long i;
     long offset;      long offset;
     long hdr_offset;  
       
     hdr_offset = sizeof (global_header);  
       
     /* mark block as empty */      /* mark block as empty */
     lseek (filedes, hdr_offset + ((long) (blknbr) * BLOCKLEN), SEEK_SET);      lseek (filedes, (long) (blknbr) * BLOCKLEN, 0);
     read (filedes, block0, BLOCKLEN);      read (filedes, block0, BLOCKLEN);
   
     block0[BTYP] = EMPTY;      block0[BTYP] = EMPTY;
           
     lseek (filedes, hdr_offset + ((long) (blknbr) * BLOCKLEN), SEEK_SET);      lseek (filedes, (long) (blknbr) * BLOCKLEN, 0);
     write (filedes, block0, BLOCKLEN);      write (filedes, block0, BLOCKLEN);
   
     /* do we have a list of free blocks? */      /* do we have a list of free blocks? */
     lseek (filedes, hdr_offset + ROOT, SEEK_SET);      lseek (filedes, ROOT, 0);
     read (filedes, block0, BLOCKLEN);      read (filedes, block0, BLOCKLEN);
           
     if ((free = UNSIGN (block0[FREE]) * 65536 + UNSIGN (block0[FREE + 1]) * 256 + UNSIGN (block0[FREE + 2]))) {      if ((free = UNSIGN (block0[FREE]) * 65536 + UNSIGN (block0[FREE + 1]) * 256 + UNSIGN (block0[FREE + 2]))) {
                   
         for (;;) {          for (;;) {
                   
             lseek (filedes, hdr_offset + ((long) free * (long) BLOCKLEN), SEEK_SET);              lseek (filedes, (long) free * (long) BLOCKLEN, 0);
             read (filedes, block0, BLOCKLEN);              read (filedes, block0, BLOCKLEN);
   
             other = UNSIGN (block0[RLPTR]) * 65536 +              other = UNSIGN (block0[RLPTR]) * 65536 +
Line 3242  static void b_free (short filedes, unsig Line 3048  static void b_free (short filedes, unsig
             block0[RLPTR + 1] = other % 65536 / 256;              block0[RLPTR + 1] = other % 65536 / 256;
             block0[RLPTR + 2] = other % 256;              block0[RLPTR + 2] = other % 256;
                           
             lseek (filedes, hdr_offset + ((long) free * (long) BLOCKLEN), SEEK_SET);              lseek (filedes, (long) free * (long) BLOCKLEN, 0);
             write (filedes, block0, BLOCKLEN);              write (filedes, block0, BLOCKLEN);
   
             for (i = 0; i < BLOCKLEN; block0[i++] = 0); /* clear block */              for (i = 0; i < BLOCKLEN; block0[i++] = 0); /* clear block */
Line 3263  static void b_free (short filedes, unsig Line 3069  static void b_free (short filedes, unsig
         getnewblk (filedes, &free);          getnewblk (filedes, &free);
   
         /* set FBLK free blocks pointer */          /* set FBLK free blocks pointer */
         lseek (filedes, hdr_offset + ROOT, SEEK_SET);          lseek (filedes, ROOT, 0);
         read (filedes, block0, BLOCKLEN);          read (filedes, block0, BLOCKLEN);
                   
         block0[FREE] = free / 65536;          block0[FREE] = free / 65536;
         block0[FREE + 1] = free % 65536 / 256;          block0[FREE + 1] = free % 65536 / 256;
         block0[FREE + 2] = free % 256;          block0[FREE + 2] = free % 256;
                   
         lseek (filedes, hdr_offset + ROOT, SEEK_SET);          lseek (filedes, ROOT, 0);
         write (filedes, block0, BLOCKLEN);          write (filedes, block0, BLOCKLEN);
   
         for (i = 0; i < BLOCKLEN; block0[i++] = 0);     /* clear block */          for (i = 0; i < BLOCKLEN; block0[i++] = 0);     /* clear block */
Line 3286  static void b_free (short filedes, unsig Line 3092  static void b_free (short filedes, unsig
     block0[OFFS] = offset / 256;      block0[OFFS] = offset / 256;
     block0[OFFS + 1] = offset % 256;      block0[OFFS + 1] = offset % 256;
   
     lseek (filedes, hdr_offset + ((long) free * (long) BLOCKLEN), SEEK_SET);      lseek (filedes, (long) free * (long) BLOCKLEN, 0);
     write (filedes, block0, BLOCKLEN);      write (filedes, block0, BLOCKLEN);
           
     return;      return;
Line 3413  static void getnewblk (int filedes, unsi Line 3219  static void getnewblk (int filedes, unsi
     unsigned long freeblks, no_of_blks;      unsigned long freeblks, no_of_blks;
     long other;      long other;
     long offset;      long offset;
     long hdr_offset;  
   
     hdr_offset = sizeof (global_header);      lseek (filedes, ROOT, 0);
       
     lseek (filedes, hdr_offset + ROOT, SEEK_SET);  
     read (filedes, nblock, BLOCKLEN);      read (filedes, nblock, BLOCKLEN);
   
     freeblks = UNSIGN (nblock[FREE]) * 65536 + UNSIGN (nblock[FREE + 1]) * 256 + UNSIGN (nblock[FREE + 2]);      freeblks = UNSIGN (nblock[FREE]) * 65536 + UNSIGN (nblock[FREE + 1]) * 256 + UNSIGN (nblock[FREE + 2]);
Line 3425  static void getnewblk (int filedes, unsi Line 3228  static void getnewblk (int filedes, unsi
           
     if (freeblks) {      if (freeblks) {
                   
         lseek (filedes, hdr_offset + ((long) (freeblks) * BLOCKLEN), SEEK_SET);          lseek (filedes, (long) (freeblks) * BLOCKLEN, 0);
         read (filedes, nblock, BLOCKLEN);          read (filedes, nblock, BLOCKLEN);
                   
         offset = UNSIGN (nblock[OFFS]) * 256 + UNSIGN (nblock[OFFS + 1]);          offset = UNSIGN (nblock[OFFS]) * 256 + UNSIGN (nblock[OFFS + 1]);
Line 3438  static void getnewblk (int filedes, unsi Line 3241  static void getnewblk (int filedes, unsi
             /* update RL-block, if any */              /* update RL-block, if any */
             if (other) {              if (other) {
   
                 lseek (filedes, hdr_offset + ((long) (other) * BLOCKLEN), SEEK_SET);                  lseek (filedes, (long) (other) * BLOCKLEN, 0);
                 read (filedes, nblock, BLOCKLEN);                  read (filedes, nblock, BLOCKLEN);
                                   
                 nblock[LLPTR] = 0;                  nblock[LLPTR] = 0;
                 nblock[LLPTR + 1] = 0;                  nblock[LLPTR + 1] = 0;
                 nblock[LLPTR + 2] = 0;                  nblock[LLPTR + 2] = 0;
                                   
                 lseek (filedes, hdr_offset + ((long) (other) * BLOCKLEN), SEEK_SET);                  lseek (filedes, (long) (other) * BLOCKLEN, 0);
                 write (filedes, nblock, BLOCKLEN);                  write (filedes, nblock, BLOCKLEN);
   
             }              }
   
             /* update ROOT block */              /* update ROOT block */
             lseek (filedes, hdr_offset + ROOT, SEEK_SET);              lseek (filedes, ROOT, 0);
             read (filedes, nblock, BLOCKLEN);              read (filedes, nblock, BLOCKLEN);
                           
             nblock[FREE] = other / 65536;              nblock[FREE] = other / 65536;
             nblock[FREE + 1] = other % 65536 / 256;              nblock[FREE + 1] = other % 65536 / 256;
             nblock[FREE + 2] = other % 256;              nblock[FREE + 2] = other % 256;
                           
             lseek (filedes, hdr_offset + ROOT, SEEK_SET);              lseek (filedes, ROOT, 0);
             write (filedes, nblock, BLOCKLEN);              write (filedes, nblock, BLOCKLEN);
                           
             return;              return;
Line 3472  static void getnewblk (int filedes, unsi Line 3275  static void getnewblk (int filedes, unsi
         nblock[OFFS] = offset / 256;          nblock[OFFS] = offset / 256;
         nblock[OFFS + 1] = offset % 256;          nblock[OFFS + 1] = offset % 256;
                   
         lseek (filedes, hdr_offset + ((long) (freeblks) * BLOCKLEN), SEEK_SET);          lseek (filedes, (long) (freeblks) * BLOCKLEN, 0);
         write (filedes, nblock, BLOCKLEN);          write (filedes, nblock, BLOCKLEN);
                   
         return;          return;
Line 3485  static void getnewblk (int filedes, unsi Line 3288  static void getnewblk (int filedes, unsi
     nblock[NRBLK + 1] = no_of_blks % 65536 / 256;      nblock[NRBLK + 1] = no_of_blks % 65536 / 256;
     nblock[NRBLK + 2] = no_of_blks % 256;      nblock[NRBLK + 2] = no_of_blks % 256;
           
     lseek (filedes, hdr_offset + ROOT, SEEK_SET);      lseek (filedes, ROOT, 0);
     write (filedes, nblock, BLOCKLEN);      write (filedes, nblock, BLOCKLEN);
           
     *blknbr = no_of_blks;      *blknbr = no_of_blks;
Line 3494  static void getnewblk (int filedes, unsi Line 3297  static void getnewblk (int filedes, unsi
   
         errno = 0;          errno = 0;
                   
         lseek (filedes, hdr_offset + ((long) (no_of_blks) * BLOCKLEN), SEEK_SET);          lseek (filedes, (long) (no_of_blks) * BLOCKLEN, 0);
         write (filedes, nblock, BLOCKLEN);          write (filedes, nblock, BLOCKLEN);
                   
         if (errno == 0) break;          if (errno == 0) break;
Line 3673  short g_numeric (char *str) Line 3476  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)
 {                                         {                                       
     gbl_close_all ();      register int i;
       
       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)
 {  {                                       
     printf ("write failed\r\n");  
       
     printf ("\033[s\033[25H\033[5;7mwrite needs more disk space immediately\007");      printf ("\033[s\033[25H\033[5;7mwrite needs more disk space immediately\007");
     sleep (1);      sleep (1);
     printf ("\033[m\007\033[2K\033[u");      printf ("\033[m\007\033[2K\033[u");
Line 3705  static void panic (void) Line 3519  static void panic (void)
   
 void gbl_dump_stat(void)  void gbl_dump_stat(void)
 {  {
     global_handle *g;      register int i;
           
     printf ("FreeM Global Statistics [PID %d]\r\n", pid);      printf ("FreeM Global Statistics [PID %d]\r\n", pid);
   
     printf ("%-20s%-10s%-20s%-10s%s\r\n", "GLOBAL", "USECT", "AGE", "LAST BLK", "FILE");      printf ("%-10s%-20s%s\r\n", "USECT", "AGE", "FILE");
     printf ("%-20s%-10s%-20s%-10s%s\r\n", "======", "=====", "===", "========", "====");      printf ("%-10s%-20s%s\r\n", "=====", "===", "====");
           
     for (g = global_handles_head; g != NULL; g = g->next) {      for (i = 0; i < NO_GLOBLS; i++) {
         printf ("%-20s%-10d%-20d%-10d%s\r\n", g->global_name, g->use_count, g->age, g->last_block, g->global_path);          printf ("%-10d%-20ld%s\r\n", usage[i], g_ages[i], oldfil[i]);    
     }      }
           
 }  }

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


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