interplane.Get Omega
Read in your language

omnet

aien-dev/omnet

Brought by drakestapleton

branch main Branches Tags History

omnet / om / store / store.om

217 lines · 3930 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note Linux ARM64 descriptor and snapshot framing helpers; include blake2s.om first.
3fn stget64 b view uchar 65536 p ulong to ulong
4v = ulong 0
5for i ulong 8
6v = or v shl ulong get b add p i mul i 8
7end
8ret v
9end
10
11fn stput64 b edit uchar 65536 p ulong v ulong to void
12for i ulong 8
13put b add p i uchar and shr v mul i 8 255
14end
15end
16
17fn stpath b edit uchar 65536 to void
18note Fixed ASCII snapshot.tmp; use its first eight bytes for snapshot.
19stput64 b 0 8390039475830484595
20stput64 b 8 1886221358
21end
22
23fn staddr fd int a edit uchar 65536 to int
24b = new uchar 65536 0
25if ne fstat fd b ulong 0 ulong 128 long 0
26ret 1
27end
28put a 0 1
29put a 1 0
30put a 2 0
31note sockaddr_un: fixed abstract prefix omnet.store.v1. then binary device/inode.
32stput64 a 3 8391101608174185839
33stput64 a 11 13002232582992495
34stput64 a 18 stget64 b 0
35stput64 a 26 stget64 b 8
36ret 0
37end
38
39fn stunused fd int to int
40if lt fd 3
41ret 1
42end
43b = new uchar 65536 0
44if ne fstat fd b ulong 0 ulong 128 long -9
45ret 1
46end
47ret 0
48end
49
50fn stlockmeta dirfd int lockfd int to int
51b = new uchar 65536 0
52a = new uchar 65536 0
53if ne fstat lockfd b ulong 0 ulong 128 long 0
54ret 1
55end
56if ne and stget64 b 16 61440 ulong 49152
57ret 1
58end
59if ne and stget64 b 24 4294967295 ulong geteuid
60ret 1
61end
62if ne staddr dirfd a 0
63ret 1
64end
65if ne sockname lockfd b ulong 0 ulong 65536 long 34
66ret 1
67end
68for i ulong 34
69if ne get a i get b i
70ret 1
71end
72end
73ret 0
74end
75
76note Thin native boundaries deliberately have no production fault-injection switch.
77fn stwr fd int b view uchar 65536 off ulong n ulong to long
78ret write fd b off n
79end
80fn strd fd int b edit uchar 65536 off ulong n ulong to long
81ret read fd b off n
82end
83fn stsync fd int to long
84ret fsync fd
85end
86fn strename to long
87p = new uchar 65536 0
88put p 0 2
89put p 2 12
90a = new uchar 65536 0
91stpath a
92for i ulong 12
93put p add i 4 get a i
94end
95put p 16 8
96for i ulong 8
97put p add i 18 get a i
98end
99ret renames p ulong 0 ulong 26 int 0
100end
101
102fn stwriteall fd int b view uchar 65536 n ulong to int
103p = ulong 0
104for attempt ulong 131072
105if eq p n
106ret 0
107end
108r = stwr fd b p sub n p
109if eq r long -4
110r = long 0
111else
112if le r long 0
113ret 1
114end
115p = add p ulong r
116end
117end
118ret 1
119end
120fn streadall fd int b edit uchar 65536 n ulong to int
121p = ulong 0
122for attempt ulong 131072
123if eq p n
124ret 0
125end
126r = strd fd b p sub n p
127if eq r long -4
128r = long 0
129else
130if le r long 0
131ret 1
132end
133p = add p ulong r
134end
135end
136ret 1
137end
138
139note fstat ARM64 mode16,nlink20,uid24,size48; reject special bits and hard links.
140fn stmeta fd int isdir int to int
141b = new uchar 65536 0
142if ne fstat fd b ulong 0 ulong 128 long 0
143ret 1
144end
145m = and stget64 b 16 4294967295
146u = and stget64 b 24 4294967295
147if ne u ulong geteuid
148ret 1
149end
150if eq isdir 1
151if ne m ulong 16832
152ret 1
153end
154else
155if ne m ulong 33152
156ret 1
157end
158if ne and shr stget64 b 16 32 4294967295 ulong 1
159ret 1
160end
161if gt stget64 b 48 ulong 36175944
162ret 1
163end
164end
165ret 0
166end
167
168note Digest chaining commits order, frame lengths, cumulative bytes and frame count.
169fn stchain prev view uchar 32 hash view uchar 32 n ulong total ulong count ulong out edit uchar 32 to void
170b = new uchar 65536 0
171k = new uchar 32 0
172for i ulong 32
173put b i get prev i
174put b add i 32 get hash i
175end
176stput64 b 64 n
177stput64 b 72 total
178stput64 b 80 count
179b2shash b 88 k 0 32 out
180end
181fn sthashdata b view uchar 65536 n ulong out edit uchar 32 to void
182k = new uchar 32 0
183b2shash b n k 0 32 out
184end
185fn steqhash b view uchar 65536 off ulong h view uchar 32 to int
186v = ulong 0
187for i ulong 32
188v = or v ulong xor get b add off i get h i
189end
190if ne v 0
191ret 1
192end
193ret 0
194end
195
196fn stmagic b edit uchar 65536 to void
197note Exact 16 ASCII bytes OMNETSNAP0000001.
198stput64 b 0 4705790282053864783
199stput64 b 8 3544385890265608272
200end
201fn sthead fd int to int
202b = new uchar 65536 0
203m = new uchar 65536 0
204stmagic m
205if ne fseek fd long 0 int 0 long 0
206ret 1
207end
208if ne streadall fd b 16 0
209ret 1
210end
211for i ulong 16
212if ne get b i get m i
213ret 1
214end
215end
216ret 0
217end