File:  [Coherent Logic Development] / freem / src / global_bltin.h
Revision 1.8: download - view: text, annotated - select for diffs
Wed Apr 9 00:43:07 2025 UTC (11 months, 3 weeks ago) by snw
Branches: MAIN
CVS tags: HEAD
Exit with fatal error if a header mismatch found

    1: /*
    2:  *   $Id: global_bltin.h,v 1.8 2025/04/09 00:43:07 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.8  2025/04/09 00:43:07  snw
   28:  *   Exit with fatal error if a header mismatch found
   29:  *
   30:  *   Revision 1.7  2025/04/08 21:41:13  snw
   31:  *   Make insert, update, and splitp global handler functions take a ptr to a global_handle instead of a file descriptor
   32:  *
   33:  *   Revision 1.6  2025/04/08 20:00:56  snw
   34:  *   Global handler now uses a header file and maintains the last journaling transaction ID
   35:  *
   36:  *   Revision 1.5  2025/04/08 16:46:11  snw
   37:  *   Add global file header and offsets
   38:  *
   39:  *   Revision 1.4  2025/04/08 14:39:21  snw
   40:  *   Initial work on global handler refactor
   41:  *
   42:  *   Revision 1.3  2025/03/09 19:14:25  snw
   43:  *   First phase of REUSE compliance and header reformat
   44:  *
   45:  *
   46:  * SPDX-FileCopyrightText:  (C) 2025 Coherent Logic Development LLC
   47:  * SPDX-License-Identifier: AGPL-3.0-or-later
   48:  **/
   49: 
   50: #if !defined(__FREEM_GLOBAL_BLTIN_H)
   51: # define __FREEM_GLOBAL_BLTIN_H
   52: 
   53: #include "version.h"
   54: 
   55: #define GBL_FORMAT_VERSION 2
   56: #define GBL_MAGIC "FRMGL"
   57: 
   58: #define GBL_HDR_OK 0
   59: #define GBL_HDR_NOTOPEN 1
   60: #define GBL_HDR_BADMAGIC 2
   61: #define GBL_HDR_BADVERSION 3
   62: #define GBL_HDR_BADBLOCKSIZE 4
   63: 
   64: typedef struct global_header {
   65:     
   66:     char magic[5]; /* FRMGL */
   67:     int format_version;
   68:     char host_triplet[40];
   69:     char host_id[256];
   70:     
   71:     unsigned long block_size;
   72:     unsigned long last_transaction_id;
   73: 
   74:     long created;
   75:     long last_backup;
   76:     
   77: } global_header;
   78: 
   79: typedef struct global_handle {
   80: 
   81:     int fd; /* file descriptor */
   82: 
   83:     global_header header;
   84:     long use_count; /* how many times has it been accessed? */
   85:     long age;
   86:     short opened;
   87:     short locked;
   88:     unsigned long last_block;
   89:     
   90:     short fast_path;
   91:     
   92:     char global_name[256];
   93:     char global_path[4096];
   94: 
   95:     
   96:     struct global_handle *next;   
   97:     
   98: } global_handle;
   99: 
  100: extern global_handle *global_handles_head;
  101: 
  102: 
  103: extern inline long gbl_path(char *key, char *buf);
  104: extern int gbl_lock(global_handle *g, int type);
  105: extern int gbl_unlock(global_handle *g);
  106: extern void gbl_close(global_handle *g);
  107: extern void gbl_close_all(void);
  108: extern int gbl_write_initial_header(global_handle *g);
  109: extern int gbl_write_header(global_handle *g, global_header *hdr);
  110: extern int gbl_read_header(global_handle *g, global_header *h);
  111: extern int gbl_update_tid(global_handle *g);
  112: extern int gbl_create(global_handle *g);
  113: extern short gbl_open(global_handle *g, short action);
  114: extern global_handle *gbl_handle(char *key);
  115: 
  116: #endif

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