File:  [Coherent Logic Development] / freem / src / global_bltin.h
Revision 1.13: download - view: text, annotated - select for diffs
Sun Apr 13 04:22:43 2025 UTC (3 months, 2 weeks ago) by snw
Branches: MAIN
CVS tags: HEAD
Fix snprintf calls

    1: /*
    2:  *   $Id: global_bltin.h,v 1.13 2025/04/13 04:22:43 snw Exp $
    3:  *    built-in global handler header
    4:  *
    5:  *  
    6:  *   Author: Serena Willis <snw@coherent-logic.com>
    7:  *    Copyright (C) 1998 MUG Deutschland
    8:  *    Copyright (C) 2020, 2025 Coherent Logic Development LLC
    9:  *
   10:  *
   11:  *   This file is part of FreeM.
   12:  *
   13:  *   FreeM is free software: you can redistribute it and/or modify
   14:  *   it under the terms of the GNU Affero Public License as published by
   15:  *   the Free Software Foundation, either version 3 of the License, or
   16:  *   (at your option) any later version.
   17:  *
   18:  *   FreeM is distributed in the hope that it will be useful,
   19:  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
   20:  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   21:  *   GNU Affero Public License for more details.
   22:  *
   23:  *   You should have received a copy of the GNU Affero Public License
   24:  *   along with FreeM.  If not, see <https://www.gnu.org/licenses/>.
   25:  *
   26:  *   $Log: global_bltin.h,v $
   27:  *   Revision 1.13  2025/04/13 04:22:43  snw
   28:  *   Fix snprintf calls
   29:  *
   30:  *   Revision 1.12  2025/04/11 16:23:18  snw
   31:  *   Avoid re-reading the same block consecutively when possible
   32:  *
   33:  *   Revision 1.11  2025/04/11 14:21:03  snw
   34:  *   Make all but one of the read/write calls in global_bltin use gbl_read_block or gbl_write_block
   35:  *
   36:  *   Revision 1.10  2025/04/11 00:52:40  snw
   37:  *   Replace all lseek/read calls in global handler to use gbl_read_block function
   38:  *
   39:  *   Revision 1.9  2025/04/09 14:34:30  snw
   40:  *   Further work on global_bltin.c refactor
   41:  *
   42:  *   Revision 1.8  2025/04/09 00:43:07  snw
   43:  *   Exit with fatal error if a header mismatch found
   44:  *
   45:  *   Revision 1.7  2025/04/08 21:41:13  snw
   46:  *   Make insert, update, and splitp global handler functions take a ptr to a global_handle instead of a file descriptor
   47:  *
   48:  *   Revision 1.6  2025/04/08 20:00:56  snw
   49:  *   Global handler now uses a header file and maintains the last journaling transaction ID
   50:  *
   51:  *   Revision 1.5  2025/04/08 16:46:11  snw
   52:  *   Add global file header and offsets
   53:  *
   54:  *   Revision 1.4  2025/04/08 14:39:21  snw
   55:  *   Initial work on global handler refactor
   56:  *
   57:  *   Revision 1.3  2025/03/09 19:14:25  snw
   58:  *   First phase of REUSE compliance and header reformat
   59:  *
   60:  *
   61:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
   62:  * SPDX-License-Identifier: AGPL-3.0-or-later
   63:  **/
   64: 
   65: #if !defined(__FREEM_GLOBAL_BLTIN_H)
   66: # define __FREEM_GLOBAL_BLTIN_H
   67: 
   68: #include "version.h"
   69: 
   70: #define GBL_FORMAT_VERSION 2
   71: #define GBL_MAGIC "FRMGL"
   72: 
   73: #define GBL_HDR_OK 0
   74: #define GBL_HDR_NOTOPEN 1
   75: #define GBL_HDR_BADMAGIC 2
   76: #define GBL_HDR_BADVERSION 3
   77: #define GBL_HDR_BADBLOCKSIZE 4
   78: 
   79: #define ROOT 0L
   80: 
   81: /* end of line symbol in global module is 30, which is a code not */
   82: /* otherwise used in subscripts                                   */
   83: #define g_EOL 30
   84: 
   85: #define EOL1 EOL
   86: 
   87: /* numerics (('.'<<1)&037)==28 ; (('-'<<1)&037)==26; */
   88: #define POINT 28
   89: #define MINUS 26
   90: 
   91: /* ALPHA and OMEGA are dummy subscripts in $order processing */
   92: /* ALPHA sorts before all other subscripts                   */
   93: /* OMEGA sorts after all other subscripts                    */
   94: /* e.g. ("abc") -> "abc",OMEGA ; ("abc","") -> "abc",ALPHA   */
   95: #define OMEGA 29
   96: #define ALPHA 31
   97: 
   98: /* length of blocks. status bytes defined as offset to blocklength */
   99: /*      BLOCKLEN 1024           is defined in mpsdef0 include file */
  100: #define DATALIM (BLOCKLEN-11)
  101: #define LLPTR   (BLOCKLEN-10)
  102: #define NRBLK    LLPTR
  103: #define COLLA   (BLOCKLEN- 7)
  104: #define RLPTR   (BLOCKLEN- 6)
  105: #define FREE     RLPTR
  106: #define BTYP    (BLOCKLEN- 3)
  107: #define OFFS    (BLOCKLEN- 2)
  108: 
  109: /* length of blockpointers in bytes */
  110: #define PLEN     3
  111: 
  112: #define EMPTY    0
  113: #define FBLK     1
  114: #define POINTER  2
  115: #define BOTTOM   6
  116: #define DATA     8
  117: 
  118: typedef struct global_header {
  119:     
  120:     char magic[5]; /* FRMGL */
  121:     int format_version;
  122:     char host_triplet[40];
  123:     char host_id[256];
  124:     
  125:     unsigned long block_size;
  126:     unsigned long last_transaction_id;
  127: 
  128:     long created;
  129:     long last_backup;
  130:     
  131: } global_header;
  132: 
  133: typedef struct global_handle {
  134: 
  135:     int fd; /* file descriptor */
  136: 
  137:     global_header header;
  138:    
  139:     long age;
  140:     long last_read_time;
  141:     
  142:     short opened;
  143:     short locked;
  144:     unsigned long last_block;
  145:     short have_cached_block;
  146:     unsigned long cached_block_num;
  147:     
  148:     char *last_block_accessed;
  149:     
  150:     unsigned long use_count; /* how many times has it been accessed? */
  151:     unsigned long read_ops;
  152:     unsigned long write_ops;
  153:     unsigned long memory_reads;
  154:     unsigned long splits;    
  155:     unsigned long cache_misses;
  156:     unsigned long cache_hits;
  157:     
  158:     short fast_path;
  159:     
  160:     char global_name[256];
  161:     char global_path[4096];
  162: 
  163:     
  164:     struct global_handle *next;   
  165:     
  166: } global_handle;
  167: 
  168: extern global_handle *global_handles_head;
  169: extern unsigned long gbl_cache_misses;
  170: extern unsigned long gbl_cache_hits;
  171: 
  172: extern inline long gbl_path(char *key, char *buf);
  173: extern void gbl_cache_hit(global_handle *g);
  174: extern void gbl_cache_miss(global_handle *g);
  175: extern int gbl_lock(global_handle *g, int type);
  176: extern int gbl_unlock(global_handle *g);
  177: extern void gbl_close(global_handle *g);
  178: extern void gbl_close_all(void);
  179: extern int gbl_write_initial_header(global_handle *g);
  180: extern int gbl_write_header(global_handle *g, global_header *hdr);
  181: extern int gbl_read_header(global_handle *g, global_header *h);
  182: extern int gbl_update_tid(global_handle *g);
  183: extern int gbl_create(global_handle *g);
  184: extern short gbl_open(global_handle *g, short action);
  185: extern int gbl_read_block(global_handle *g, unsigned long blocknum, char *block);
  186: extern int gbl_write_block(global_handle *g, unsigned long blocknum, char *block);
  187: extern global_handle *gbl_handle(char *key);
  188: 
  189: #endif

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