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