--- freem/src/global_bltin.c 2025/04/09 19:52:02 1.14 +++ freem/src/global_bltin.c 2025/04/11 00:52:40 1.16 @@ -1,5 +1,5 @@ /* - * $Id: global_bltin.c,v 1.14 2025/04/09 19:52:02 snw Exp $ + * $Id: global_bltin.c,v 1.16 2025/04/11 00:52:40 snw Exp $ * freem database engine * * @@ -24,6 +24,12 @@ * along with FreeM. If not, see . * * $Log: global_bltin.c,v $ + * Revision 1.16 2025/04/11 00:52:40 snw + * Replace all lseek/read calls in global handler to use gbl_read_block function + * + * Revision 1.15 2025/04/10 01:24:38 snw + * Remove C++ style comments + * * Revision 1.14 2025/04/09 19:52:02 snw * Eliminate as many warnings as possible while building with -Wall * @@ -86,7 +92,6 @@ static void scanpblk (char *block, long static void scandblk (char *block, long *adr, long *fnd); static void getnewblk (int filedes, unsigned long *blknbr); static short int g_collate (char *t); -//static short int g_numeric (char *str); short g_numeric (char *str); void close_all_globals(void); static void panic (void); @@ -469,6 +474,26 @@ short gbl_open(global_handle *g, short a } /* gbl_open() */ +int gbl_read_block(global_handle *g, unsigned long blocknum, char *block) +{ + unsigned long hdr_offset; + hdr_offset = sizeof (global_header); + + if (g->opened == FALSE) { + return FALSE; + } + + gbl_lock (g, 1); + lseek (g->fd, hdr_offset + ((long) blocknum * (long) (g->header.block_size)), SEEK_SET); + read (g->fd, block, g->header.block_size); + g->last_block = blocknum; + g->use_count++; + g->read_ops++; + gbl_unlock (g); + + return TRUE; +} + global_handle *gbl_handle(char *key) { global_handle *g; @@ -516,6 +541,8 @@ global_handle *gbl_handle(char *key) g->fast_path = -1; g->cache_misses = 0; g->cache_hits = 0; + g->read_ops = 0; + g->write_ops = 0; strcpy (g->global_name, global_name); gbl_path (key, g->global_path); @@ -643,6 +670,8 @@ void global_bltin (short action, char *k register long int k; register long int ch; + j = 0; + hdr_offset = sizeof (global_header); /* process optional limitations */ @@ -1072,9 +1101,7 @@ tfast0: tfast1: - - lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block, BLOCKLEN); + gbl_read_block (g, blknbr, block); /* temporarily disabled tfast2: @@ -1151,7 +1178,6 @@ tfast2: if (typ == EMPTY) { if (blknbr == ROOT) { - //close (filedes); gbl_close (g); goto reopen; } @@ -1218,10 +1244,8 @@ k_again: /* entry point for repeated traceblk[trx] = blknbr; traceadr[trx] = 0; - - lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block, BLOCKLEN); - + + gbl_read_block (g, blknbr, block); typ = block[BTYP]; if (typ == DATA) { @@ -1509,9 +1533,8 @@ s20: if (addr >= offset) { 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); - read (g->fd, block, BLOCKLEN); + + gbl_read_block (g, blknbr, block); j1 = UNSIGN (block[0]); i = 0; @@ -1592,9 +1615,8 @@ s20: goto quit; } /* no next block */ - - lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block, BLOCKLEN); + + gbl_read_block (g, blknbr, block); scandblk (block, &addr, &found); } @@ -1750,8 +1772,7 @@ s20: goto quit; /* no next block */ } - lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block, BLOCKLEN); + gbl_read_block (g, blknbr, block); addr = 0; offset = UNSIGN (block[OFFS]) * 256 + @@ -1774,8 +1795,7 @@ s20: goto quit; /* no next block */ } - lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block, BLOCKLEN); + gbl_read_block (g, blknbr, block); addr = 0; } @@ -1984,9 +2004,8 @@ killo: /* entry from killone section other = traceblk[--trx]; addr = traceadr[trx]; - - lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block, BLOCKLEN); + + gbl_read_block (g, other, block); addr += UNSIGN (block[addr]); addr += (2 + PLEN); /* skip previous entry */ @@ -2005,8 +2024,7 @@ killo: /* entry from killone section trx = trxsav; - lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block, BLOCKLEN); + gbl_read_block (g, blknbr, block); offset = UNSIGN (block[OFFS]) * 256 + UNSIGN (block[OFFS + 1]); @@ -2112,8 +2130,7 @@ p_empty: /* entry if pointer block goes if (left) { - lseek (g->fd, hdr_offset + ((long) left * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block0, BLOCKLEN); + gbl_read_block (g, left, block0); block0[RLPTR] = block[RLPTR]; block0[RLPTR + 1] = block[RLPTR + 1]; @@ -2125,9 +2142,8 @@ p_empty: /* entry if pointer block goes } if (right) { - - lseek (g->fd, hdr_offset + ((long) right * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block0, BLOCKLEN); + + gbl_read_block (g, right, block0); block0[LLPTR] = block[LLPTR]; block0[LLPTR + 1] = block[LLPTR + 1]; @@ -2151,8 +2167,7 @@ p_empty: /* entry if pointer block goes blknbr = traceblk[--trx]; addr = traceadr[trx]; - lseek (g->fd, hdr_offset + ((long) (blknbr) * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block, BLOCKLEN); + gbl_read_block (g, blknbr, block); offset = UNSIGN (block[OFFS]) * 256 + UNSIGN (block[OFFS + 1]); freecnt = UNSIGN (block[addr]) + 2 + PLEN; @@ -2270,9 +2285,8 @@ zinv: data[0] = EOL1; goto quit; } /* no previous block */ - - lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block, BLOCKLEN); + + gbl_read_block (g, blknbr, block); addr = UNSIGN (block[OFFS]) * 256 + UNSIGN (block[OFFS + 1]); @@ -2451,8 +2465,7 @@ zinv: break; /* no next block */ } - lseek (g->fd, hdr_offset + ((long) blknbr * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block, BLOCKLEN); + gbl_read_block (g, blknbr, block); addr = 0; offset = UNSIGN (block[OFFS]) * 256 + @@ -2618,8 +2631,7 @@ splitd: /* split data block in two se char block0[BLOCKLEN]; - lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block0, BLOCKLEN); + gbl_read_block (g, other, block0); block0[LLPTR] = blknbr / 65536; block0[LLPTR + 1] = blknbr % 65536 / 256; @@ -2781,8 +2793,7 @@ splitd: /* split data block in two se /* up-date LL-PTR of RL-block */ if (other != 0) { - lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block0, BLOCKLEN); + gbl_read_block (g, other, block0); block0[LLPTR] = newblk / 65536; block0[LLPTR + 1] = newblk % 65536 / 256; @@ -2823,8 +2834,7 @@ splitd: /* split data block in two se /* up-date LL-PTR of RL-block */ if (other != 0) { - lseek (g->fd, hdr_offset + ((long) other * (long) (BLOCKLEN)), SEEK_SET); - read (g->fd, block0, BLOCKLEN); + gbl_read_block (g, other, block0); block0[LLPTR] = newblk / 65536; block0[LLPTR + 1] = newblk % 65536 / 256; @@ -3661,7 +3671,6 @@ static short int g_collate (char *t) /* * test whether 'str' is canonical */ -//static short int g_numeric (char *str) short g_numeric (char *str) { register int ptr = 0, ch;