Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/omega-mv/blob/main/seed/authority/store.om # omega-mv Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance. Brought by drakestapleton Sign in to star 1 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `omega-mv / seed / authority / store.om` 184 lines ยท 3348 bytes Raw Blame History 1 note SPDX-License-Identifier: AGPL-3.0-only 2 note Durable 32-word authority record store. Caller supplies the record and generation. 3 note Writes a temporary 256-byte file, fsyncs it, then atomically renames it into place. 4 note Reads require exactly 256 bytes; a short or torn file is refused. Store calls do not lock; the 5 note dispatcher holds lock.om around its read-check-persist window. 6 text recp "build/authority-store/rec" 7 text tmpp "build/authority-store/tmp" 8 text genp "build/authority-store/gen" 9 global sb uchar 256 10 global stail uchar 1 11 global spkt uchar 256 12 global sn ulong 1 13 global spath uchar 128 14 global splen ulong 1 15 global sgerr ulong 1 16 fn put16 v ulong to void 17 put spkt get sn 0 uchar and v 255 18 put spkt add get sn 0 1 uchar shr v 8 19 put sn 0 add get sn 0 2 20 end 21 fn setrec to void 22 put splen 0 len recp 23 for i ulong len recp 24 put spath i get recp i 25 end 26 end 27 fn settmp to void 28 put splen 0 len tmpp 29 for i ulong len tmpp 30 put spath i get tmpp i 31 end 32 end 33 fn setgen to void 34 put splen 0 len genp 35 for i ulong len genp 36 put spath i get genp i 37 end 38 end 39 fn pack2 to ulong 40 put sn 0 0 41 put16 2 42 put16 len tmpp 43 for i ulong len tmpp 44 put spkt add get sn 0 i get tmpp i 45 end 46 put sn 0 add get sn 0 len tmpp 47 put16 len recp 48 for i ulong len recp 49 put spkt add get sn 0 i get recp i 50 end 51 put sn 0 add get sn 0 len recp 52 ret get sn 0 53 end 54 fn enc r view ulong 32 to void 55 for i ulong 32 56 v = get r i 57 for j ulong 8 58 put sb add mul i 8 j uchar and shr v mul j 8 255 59 end 60 end 61 end 62 fn dec r edit ulong 32 to void 63 for i ulong 32 64 v = ulong 0 65 for j ulong 8 66 v = or v shl ulong get sb add mul i 8 j mul j 8 67 end 68 put r i v 69 end 70 end 71 note p10 effect 72 fn writerec r view ulong 32 to ulong 73 enc r 74 settmp 75 fd = fopen spath 0 get splen 0 577 384 76 if lt fd 0 77 ret 10 78 end 79 n = write int fd sb 0 256 80 if ne n 256 81 note p10 allow E1 primary write error wins over cleanup close error 82 cleanup = fclose int fd 83 ret 11 84 end 85 if ne fsync int fd 0 86 note p10 allow E1 primary sync error wins over cleanup close error 87 cleanup = fclose int fd 88 ret 12 89 end 90 if ne fclose int fd 0 91 ret 13 92 end 93 pn = pack2 94 rr = renames spkt 0 pn 0 95 if lt rr 0 96 ret 14 97 end 98 ret 0 99 end 100 note p10 effect 101 fn readrec r edit ulong 32 to ulong 102 setrec 103 fd = fopen spath 0 get splen 0 0 0 104 if lt fd 0 105 ret 20 106 end 107 n = read int fd sb 0 256 108 extra = long -1 109 if eq n 256 110 extra = read int fd stail 0 1 111 end 112 if ne fclose int fd 0 113 ret 21 114 end 115 if or ne n 256 ne extra 0 116 ret 22 117 end 118 dec r 119 ret 0 120 end 121 note p10 effect 122 fn readgen to ulong 123 put sgerr 0 0 124 setgen 125 fd = fopen spath 0 get splen 0 0 0 126 if lt fd 0 127 put sgerr 0 30 128 ret 0 129 end 130 n = read int fd sb 0 8 131 extra = long -1 132 if eq n 8 133 extra = read int fd stail 0 1 134 end 135 if ne fclose int fd 0 136 put sgerr 0 31 137 ret 0 138 end 139 if or ne n 8 ne extra 0 140 put sgerr 0 32 141 ret 0 142 end 143 v = ulong 0 144 for j ulong 8 145 v = or v shl ulong get sb j mul j 8 146 end 147 ret v 148 end 149 note p10 effect 150 fn writegen v ulong to ulong 151 setgen 152 fd = fopen spath 0 get splen 0 577 384 153 if lt fd 0 154 ret 40 155 end 156 for j ulong 8 157 put sb j uchar and shr v mul j 8 255 158 end 159 n = write int fd sb 0 8 160 if ne n 8 161 note p10 allow E1 primary write error wins over cleanup close error 162 cleanup = fclose int fd 163 ret 41 164 end 165 if ne fsync int fd 0 166 note p10 allow E1 primary sync error wins over cleanup close error 167 cleanup = fclose int fd 168 ret 42 169 end 170 if ne fclose int fd 0 171 ret 43 172 end 173 ret 0 174 end 175 note p10 pure 176 fn storevalid r view ulong 32 g ulong to ulong 177 if ne get r 0 1 178 ret 51 179 end 180 if ne get r 4 g 181 ret 52 182 end 183 ret 0 184 end