raz / commit 73d8ebbe

commit
73d8ebbe2d68aad748feea4de69ead0e2931b324
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
11573505
Sys: linkInfo, Info.ino, openMode, lock, syncAll

What sauce's Sos made by SYSCALL, now in both Sys files, from
PROPOSALS.md. Library growth that breaks no program.

- linkInfo: lstat, the link itself, dangling or not.
- Info.ino: st_ino, for a cache keyed by inode.
- openMode: open with a mode for a file it makes; open is it with 644.
- lock: flock, LOCK_EX, LOCK_NB unless wait (-11 if held).
- syncAll: syncfs; over C, POSIX sync, which flushes all.

Sys's test covers each; raz-lib.md says them.

patch · log

5 files changed, +164 -84

PROPOSALS.md modified +0 -71

@@ -82,77 +82,6 @@
8282 the budget; and, across modules, the imported module's
8383 text kept to be read again, which is to be checked.
8484
85-## What a version control system needs of `Sys`
86-
87-Met in porting sauce (`~/r/sauce`) from Free Pascal, where a module of
88-its own, `Sos`, makes these calls by `SYSCALL`. Each is library
89-growth that breaks no program, so it could come with any release, not
90-only a thaw; and each has a C call behind it, for `Sys.raz` over the C
91-library.
92-
93-**Seeing a link itself.** `info` follows a symbolic link, as it should
94-for most programs; but a program that tracks or copies a tree must see
95-the link: a dangling one is -ENOENT to `info`, and the size it gives is
96-the target's, not the link's.
97-
98-```
99-proc linkInfo*(path: []U8): (Info, INT); (* the path itself, not what a link at its end names *)
100-```
101-
102-For a link, `symlink` is true, `dir` and `file` false, and `size` the
103-length of its target, as `readLink` gives it. The C call is `lstat`.
104-
105-**The inode.** A program that keeps a cache of files, to know one
106-unchanged without reading it, keys it by inode, size and time, as git
107-and sauce do; a file replaced by a rename has a new inode and may keep
108-its size and time. `Info` gains a field:
109-
110-```
111-ino*: U64; (* the file's inode, on its file system *)
112-```
113-
114-A record literal names its fields, so no program changes. On a target
115-whose files have no inode, 0.
116-
117-**A new file's mode.** `open` with `creating` always asks for 644, so
118-a program can't make a file executable as it writes it, nor read-only:
119-it must `chmod` after, and between the two the file is there with the
120-wrong mode, and the umask is lost (sauce writes 666 or 777 less the
121-umask for the working tree, 444 for its objects).
122-
123-```
124-proc openMode*(path: []U8; how: Accesses; mode: INT): INT; (* open, a file it creates given mode, less the umask *)
125-```
126-
127-`open(path, how)` is `openMode(path, how, 1A4H)`.
128-
129-**A lock between programs.** Two programs that change the same files
130-need to take turns. A lock file made with `exclusive` works until a
131-program dies holding it, and then it is stale forever; the kernel's
132-lock on an open file goes when the program ends, however it ends.
133-
134-```
135-proc lock*(fd: INT; wait: BOOL): INT; (* an exclusive lock on the open file fd, until it is closed; -11 if another program holds one and not wait *)
136-```
137-
138-The C call is `flock`; it locks the open file, not a range of it, and
139-is enough for a program that only needs one at a time.
140-
141-**Flushing a file system.** `sync` makes one file durable. A program
142-that writes hundreds of files and then one that names them all (a
143-commit's objects, then HEAD) wants them all on the disk before the
144-last, without a `sync` of each, which is slow:
145-
146-```
147-proc syncAll*(fd: INT): INT; (* everything written to the file system holding fd, on the disk *)
148-```
149-
150-The Linux call is `syncfs`; where there is none, `sync`, which flushes
151-every file system and so does no less.
152-
153-Not needed: syncing a directory, so that a rename in it is durable, is
154-already `sync(open(dir, {reading}))`.
155-
15685 ## `Buf` when memory runs out
15786
15887 `Buf.add` and `Buf.str` call `room`, and when it fails they drop the

doc/raz-lib.md (history) modified +25 -5

@@ -11,7 +11,7 @@
1111 | Module | What |
1212 |---|---|
1313 | `Rt` | ending the program, `exit` and `atExit`; `stop`, which ends it with a message; `trace`, the calls under way; what the compiler's checks call when they fail |
14-| `Sys` | system calls: `open`, `openRead`, `create`, `read`, `write`, `seek`, `position`, `truncate`, `sync`, `close`, `mmap`, `munmap`, `isTerminal`, `yield`, `exit`; files and directories, `rename`, `remove`, `removeDir`, `makeDir`, `chmod`, `symlink`, `readLink`, `info`, `infoOf`, `openDir`, `nextEntry`, `closeDir`; the terminal, `rawMode`, `restoreMode`, `termSize`, `ready`; the environment, `env`, `workDir`, `setWorkDir`; programs, pipes and signals; time, `clock`, `now`, `sleep`; `random`; sockets, among them datagrams served and files passed; and memory shared through a file. One file per target, and `Sys.raz` over the C library for the others |
14+| `Sys` | system calls: `open`, `openMode`, `openRead`, `create`, `read`, `write`, `seek`, `position`, `truncate`, `sync`, `syncAll`, `lock`, `close`, `mmap`, `munmap`, `isTerminal`, `yield`, `exit`; files and directories, `rename`, `remove`, `removeDir`, `makeDir`, `chmod`, `symlink`, `readLink`, `info`, `linkInfo`, `infoOf`, `openDir`, `nextEntry`, `closeDir`; the terminal, `rawMode`, `restoreMode`, `termSize`, `ready`; the environment, `env`, `workDir`, `setWorkDir`; programs, pipes and signals; time, `clock`, `now`, `sleep`; `random`; sockets, among them datagrams served and files passed; and memory shared through a file. One file per target, and `Sys.raz` over the C library for the others |
1515 | `Out` | writing text and numbers to standard output, buffered; safe to call from several threads |
1616 | `C` | the parts of the C library the others use, and `printf`, `fflush`, `stdout`, `pthread_create`; a program that imports it uses C |
1717 | `Lock` | a lock for short sections, for C's threads and `Thread`'s alike |
@@ -171,6 +171,7 @@
171171 dir*: BOOL; (* a directory *)
172172 file*: BOOL; (* a regular file: not a directory, device, pipe or socket *)
173173 symlink*: BOOL; (* the path itself is a symbolic link *)
174+ ino*: U64; (* its inode, which a rename keeps and a new file doesn't *)
174175 end;
175176 Dir* = record ... end; (* an open directory; its fields are the target's *)
176177 Program* = record
@@ -190,12 +191,15 @@
190191 proc write*(fd: INT; s: []U8): INT; (* the bytes written *)
191192 proc read*(fd: INT; buf: []U8): INT; (* the bytes read; 0 at the end *)
192193 proc open*(path: []U8; how: Accesses): INT; (* its fd *)
194+proc openMode*(path: []U8; how: Accesses; mode: INT): INT; (* open, a file it makes given mode *)
193195 proc openRead*(path: []U8): INT; (* open(path, {reading}) *)
194196 proc create*(path: []U8): INT; (* open(path, {writing, creating, truncating}) *)
195197 proc seek*(fd: INT; pos: I64; fromEnd: BOOL): I64; (* the new position *)
196198 proc position*(fd: INT): I64; (* where the next read or write is *)
197199 proc truncate*(fd: INT; size: I64): INT; (* the file made size bytes long *)
198200 proc sync*(fd: INT): INT; (* what was written to it, on the disk *)
201+proc syncAll*(fd: INT): INT; (* all that was written to its file system, on the disk *)
202+proc lock*(fd: INT; wait: BOOL): INT; (* the file's lock, held until fd is closed *)
199203 proc close*(fd: INT);
200204 proc isTerminal*(fd: INT): BOOL;
201205 proc mmap*(size: INT): ^U8; (* size bytes of zeroed memory, in whole pages; or nil *)
@@ -211,6 +215,7 @@
211215 proc symlink*(target, path: []U8): INT; (* path made a link to target *)
212216 proc readLink*(path: []U8): ([]U8, INT); (* what the link names, good until the next call *)
213217 proc info*(path: []U8): (Info, INT); (* following a symbolic link *)
218+proc linkInfo*(path: []U8): (Info, INT); (* the link itself *)
214219 proc infoOf*(fd: INT): (Info, INT); (* the open file's *)
215220 proc space*(path: []U8): (I64, I64, INT); (* the bytes free and in all on path's file system *)
216221
@@ -286,15 +291,30 @@
286291 writable by its owner; with `exclusive`, failing with -17 (EEXIST) if
287292 it is there, as a program does that makes a lock or a file of its
288293 own; `truncating` it to nothing; `appending`, each write going to its
289-end, however other programs write it too. `seek` moves to `pos` from
294+end, however other programs write it too. `openMode` is `open` that
295+gives a file it makes the bits `mode`, less those the umask takes
296+away: 1EDH (755) for a program, 124H (444) for a file never to be
297+written; `open` gives 1A4H (644). `seek` moves to `pos` from
290298 the start of the file, or from its end if `fromEnd`, where a negative
291299 `pos` reads back from the end; `position` says where the file is,
292300 without moving. `truncate` makes the file `size` bytes long, cutting
293301 it or adding zeros, and leaves the position where it was. `sync`
294302 returns once what was written to the file is on the disk, as a
295-program needs before it says a file is saved. `infoOf` is `info` of
296-an open file: its size is what it holds now, however it was written. `Info.mtime` is what a program checks
297-to see whether a file changed under it; `Info.mode` holds the nine
303+program needs before it says a file is saved; `syncAll` returns once
304+everything written to the file system that holds the file is on the
305+disk, at once rather than a file at a time, and may flush other file
306+systems too. `lock` takes the file's lock, which one open file holds
307+at a time: another that asks for it waits if `wait`, and otherwise
308+fails with -11 (EAGAIN). The lock goes when the file is closed or the
309+program ends, however it ends, so it never goes stale as a file made
310+with `exclusive` does. `infoOf` is `info` of
311+an open file: its size is what it holds now, however it was written;
312+`linkInfo` is `info` of a symbolic link itself, not what it names, so
313+that `symlink` is true, `dir` and `file` false, and `size` the length
314+of what it names, which need not be there. `Info.mtime` is what a program checks
315+to see whether a file changed under it, and `Info.ino` whether it is
316+still the same file, not one renamed over it; 0 on a target whose
317+files have none. `Info.mode` holds the nine
298318 bits of `rwxrwxrwx`, and `chmod` sets them, 1EDH (755) for a program,
299319 1A4H (644) for data.
300320

lib/C.raz (history) modified +2 -0

@@ -60,6 +60,8 @@
6060 extern proc stat*(path, st: ^U8): I32;
6161 extern proc fstat*(fd: I32; st: ^U8): I32;
6262 extern proc fsync*(fd: I32): I32;
63+extern proc sync*;
64+extern proc flock*(fd, how: I32): I32;
6365 extern proc lstat*(path, st: ^U8): I32;
6466 extern proc statvfs*(path, st: ^U8): I32;
6567 extern proc symlink*(target, path: ^U8): I32;

lib/Sys.linux-x86_64.raz (history) modified +67 -4

@@ -29,6 +29,7 @@
2929 dir*: BOOL; (* a directory *)
3030 file*: BOOL; (* not a directory, device, pipe or socket *)
3131 symlink*: BOOL; (* the path itself is a symbolic link *)
32+ ino*: U64; (* its inode, which a rename keeps and a new file doesn't *)
3233 end;
3334
3435 (* An open directory: getdents64's records, read a block at a time. *)
@@ -147,15 +148,22 @@
147148 end;
148149
149150 (* The file at path, opened as how asks: its file descriptor, or minus
150- an errno. A file it creates is readable by all, writable by its
151- owner. *)
152-proc open*(path: []U8; how: Accesses): INT;
151+ an errno. A file it creates has the permission bits mode, less
152+ those the umask takes away. *)
153+proc openMode*(path: []U8; how: Accesses; mode: INT): INT;
153154 var buf: [4096]U8;
154155 begin
155156 if not cstr(path, buf) then return -36; end; (* ENAMETOOLONG *)
156- return SYSCALL(2, ADR(buf), flags(how), 1A4H); (* mode 644 *)
157+ return SYSCALL(2, ADR(buf), flags(how), mode);
157158 end;
158159
160+(* openMode with 644: a file it creates is readable by all, writable
161+ by its owner. *)
162+proc open*(path: []U8; how: Accesses): INT;
163+begin
164+ return openMode(path, how, 1A4H); (* 644 *)
165+end;
166+
159167 (* The file at path, opened for reading. *)
160168 proc openRead*(path: []U8): INT;
161169 begin
@@ -197,6 +205,24 @@
197205 return SYSCALL(74, fd); (* fsync *)
198206 end;
199207
208+(* Returns once everything written to the file system that holds fd
209+ is on the disk, as a sync of each file would, but at once: 0, or
210+ minus an errno. *)
211+proc syncAll*(fd: INT): INT;
212+begin
213+ return SYSCALL(306, fd); (* syncfs *)
214+end;
215+
216+(* Takes the lock on the open file fd, which only one program holds at
217+ a time, and which goes when fd is closed or the program ends,
218+ however it ends. If another program holds it, waits for it if wait,
219+ and otherwise returns -11 (EAGAIN). 0, or minus an errno. *)
220+proc lock*(fd: INT; wait: BOOL): INT;
221+begin
222+ if wait then return SYSCALL(73, fd, 2); end; (* flock, LOCK_EX *)
223+ return SYSCALL(73, fd, 2 | 4); (* LOCK_EX | LOCK_NB *)
224+end;
225+
200226 (* Closes the file descriptor fd. *)
201227 proc close*(fd: INT);
202228 begin
@@ -316,6 +342,7 @@
316342 var i: Info;
317343 begin
318344 i.size := st[6]; (* st_size *)
345+ i.ino := U64(st[1]); (* st_ino *)
319346 i.mtime := st[11] * 1000000000 + st[12]; (* st_mtim *)
320347 i.mode := st[3] & 1FFH;
321348 i.dir := st[3] & 0F000H = 4000H; (* S_IFDIR *)
@@ -340,6 +367,20 @@
340367 return i, 0;
341368 end;
342369
370+(* info of path itself: if it is a symbolic link, of the link, not of
371+ what it names, so that symlink is true, dir and file false, and the
372+ size the length of what it names. *)
373+proc linkInfo*(path: []U8): (Info, INT);
374+var a: [4096]U8; st: [18]INT; i: Info; r: INT;
375+begin
376+ if not cstr(path, a) then return i, -36; end;
377+ r := SYSCALL(6, ADR(a), ADR(st)); (* lstat *)
378+ if r # 0 then return i, r; end;
379+ i := fromStat(st);
380+ i.symlink := st[3] & 0F000H = 0A000H; (* S_IFLNK *)
381+ return i, 0;
382+end;
383+
343384 (* info of the file open on fd, which is never a link. *)
344385 proc infoOf*(fd: INT): (Info, INT);
345386 var st: [18]INT; i: Info; r: INT;
@@ -1319,11 +1360,19 @@
13191360 if symlink("/tmp/raz-sys-dir", "/tmp/raz-sys-link") # 0 then exit(2); end;
13201361 i, err := info("/tmp/raz-sys-link");
13211362 if (err # 0) or not i.dir or not i.symlink then exit(2); end;
1363+ i, err := linkInfo("/tmp/raz-sys-link");
1364+ if (err # 0) or i.dir or i.file or not i.symlink or (i.size # 16) then exit(2); end;
1365+ i, err := linkInfo("/tmp/raz-sys-dir");
1366+ if (err # 0) or not i.dir or i.symlink or (i.ino = 0) then exit(2); end;
13221367 name, err := readLink("/tmp/raz-sys-link");
13231368 if (err # 0) or (name # "/tmp/raz-sys-dir") then exit(2); end;
13241369 name, err := readLink("/tmp/raz-sys-dir");
13251370 if err # -22 then exit(2); end; (* EINVAL: not a link *)
13261371 _ := remove("/tmp/raz-sys-link");
1372+ if symlink("/no/such/file", "/tmp/raz-sys-link") # 0 then exit(2); end; (* dangling *)
1373+ i, err := linkInfo("/tmp/raz-sys-link");
1374+ if (err # 0) or not i.symlink or (i.size # 13) then exit(2); end;
1375+ _ := remove("/tmp/raz-sys-link");
13271376 (* open as asked, seek, the mode and the time *)
13281377 _ := remove("/tmp/raz-sys-dir/h");
13291378 fd := open("/tmp/raz-sys-dir/h", {writing, creating, exclusive});
@@ -1342,7 +1391,16 @@
13421391 if (truncate(fd, 4) # 0) or (position(fd) # 2) or (sync(fd) # 0) then exit(2); end;
13431392 i, err := infoOf(fd);
13441393 if (err # 0) or (i.size # 4) or not i.file or i.symlink then exit(2); end;
1394+ m := INT(i.ino);
1395+ i, err := info("/tmp/raz-sys-dir/h");
1396+ if (err # 0) or (INT(i.ino) # m) or (syncAll(fd) # 0) then exit(2); end;
1397+ (* the lock: one open file holds it, another can't take it until
1398+ the first is closed *)
1399+ k := openRead("/tmp/raz-sys-dir/h");
1400+ if (lock(fd, false) # 0) or (lock(k, false) # -11) then exit(2); end;
13451401 close(fd);
1402+ if lock(k, true) # 0 then exit(2); end;
1403+ close(k);
13461404 if (position(fd) # -9) or (truncate(fd, 0) # -9) or (sync(fd) # -9) then exit(2); end; (* EBADF *)
13471405 i, err := infoOf(fd);
13481406 if err # -9 then exit(2); end;
@@ -1351,6 +1409,11 @@
13511409 if chmod("/tmp/raz-sys-dir/h", 1EDH) # 0 then exit(2); end;
13521410 i, err := info("/tmp/raz-sys-dir/h");
13531411 if i.mode # 1EDH then exit(2); end;
1412+ _ := remove("/tmp/raz-sys-dir/h");
1413+ fd := openMode("/tmp/raz-sys-dir/h", {writing, creating}, 1C0H); (* rwx------ *)
1414+ close(fd);
1415+ i, err := info("/tmp/raz-sys-dir/h");
1416+ if (fd < 0) or (err # 0) or (i.mode # 1C0H) then exit(2); end;
13541417 _ := remove("/tmp/raz-sys-dir/h");
13551418 i, err := info("/no/such/file");
13561419 if err >= 0 then exit(2); end;

lib/Sys.raz (history) modified +70 -4

@@ -42,6 +42,7 @@
4242 dir*: BOOL; (* a directory *)
4343 file*: BOOL; (* not a directory, device, pipe or socket *)
4444 symlink*: BOOL; (* the path itself is a symbolic link *)
45+ ino*: U64; (* its inode, which a rename keeps and a new file doesn't *)
4546 end;
4647
4748 (* An open directory: C's DIR. *)
@@ -175,17 +176,24 @@
175176 end;
176177
177178 (* The file at path, opened as how asks: its file descriptor, or minus
178- an errno. A file it creates is readable by all, writable by its
179- owner. *)
180-proc open*(path: []U8; how: Accesses): INT;
179+ an errno. A file it creates has the permission bits mode, less
180+ those the umask takes away. *)
181+proc openMode*(path: []U8; how: Accesses; mode: INT): INT;
181182 var buf: [4096]U8; r: INT;
182183 begin
183184 if not cstr(path, buf) then return -36; end;
184- r := INT(C.open(ADR(buf[0]), flags(how), 1A4H)); (* mode 644 *)
185+ r := INT(C.open(ADR(buf[0]), flags(how), mode));
185186 if r < 0 then return failed(); end;
186187 return r;
187188 end;
188189
190+(* openMode with 644: a file it creates is readable by all, writable
191+ by its owner. *)
192+proc open*(path: []U8; how: Accesses): INT;
193+begin
194+ return openMode(path, how, 1A4H); (* 644 *)
195+end;
196+
189197 (* The file at path, opened for reading. *)
190198 proc openRead*(path: []U8): INT;
191199 begin
@@ -235,6 +243,28 @@
235243 return 0;
236244 end;
237245
246+(* Returns once everything written to the file system that holds fd
247+ is on the disk: 0, or minus an errno. POSIX has no call for one file
248+ system, so it is sync's, which flushes them all and does no less. *)
249+proc syncAll*(fd: INT): INT;
250+begin
251+ C.sync;
252+ return 0;
253+end;
254+
255+(* Takes the lock on the open file fd, which only one program holds at
256+ a time, and which goes when fd is closed or the program ends,
257+ however it ends. If another program holds it, waits for it if wait,
258+ and otherwise returns -11 (EAGAIN). 0, or minus an errno. *)
259+proc lock*(fd: INT; wait: BOOL): INT;
260+var how: I32;
261+begin
262+ how := 2; (* LOCK_EX *)
263+ if not wait then how := how | 4; end; (* LOCK_NB *)
264+ if C.flock(I32(fd), how) # 0 then return failed(); end;
265+ return 0;
266+end;
267+
238268 (* Closes the file descriptor fd. *)
239269 proc close*(fd: INT);
240270 begin
@@ -355,6 +385,7 @@
355385 var i: Info;
356386 begin
357387 i.size := st[6]; (* st_size *)
388+ i.ino := U64(st[1]); (* st_ino *)
358389 i.mtime := st[11] * 1000000000 + st[12]; (* st_mtim *)
359390 i.mode := st[3] & 1FFH;
360391 i.dir := st[3] & 0F000H = 4000H; (* S_IFDIR *)
@@ -377,6 +408,19 @@
377408 return i, 0;
378409 end;
379410
411+(* info of path itself: if it is a symbolic link, of the link, not of
412+ what it names, so that symlink is true, dir and file false, and the
413+ size the length of what it names. *)
414+proc linkInfo*(path: []U8): (Info, INT);
415+var a: [4096]U8; st: [18]INT; i: Info;
416+begin
417+ if not cstr(path, a) then return i, -36; end;
418+ if C.lstat(ADR(a[0]), ^U8(ADR(st))) # 0 then return i, failed(); end;
419+ i := fromStat(st);
420+ i.symlink := st[3] & 0F000H = 0A000H; (* S_IFLNK *)
421+ return i, 0;
422+end;
423+
380424 (* info of the file open on fd, which is never a link. *)
381425 proc infoOf*(fd: INT): (Info, INT);
382426 var st: [18]INT; i: Info;
@@ -1298,11 +1342,19 @@
12981342 if symlink("/tmp/raz-sys-dir", "/tmp/raz-sys-link") # 0 then exit(2); end;
12991343 i, err := info("/tmp/raz-sys-link");
13001344 if (err # 0) or not i.dir or not i.symlink then exit(2); end;
1345+ i, err := linkInfo("/tmp/raz-sys-link");
1346+ if (err # 0) or i.dir or i.file or not i.symlink or (i.size # 16) then exit(2); end;
1347+ i, err := linkInfo("/tmp/raz-sys-dir");
1348+ if (err # 0) or not i.dir or i.symlink or (i.ino = 0) then exit(2); end;
13011349 name, err := readLink("/tmp/raz-sys-link");
13021350 if (err # 0) or (name # "/tmp/raz-sys-dir") then exit(2); end;
13031351 name, err := readLink("/tmp/raz-sys-dir");
13041352 if err # -22 then exit(2); end; (* EINVAL: not a link *)
13051353 _ := remove("/tmp/raz-sys-link");
1354+ if symlink("/no/such/file", "/tmp/raz-sys-link") # 0 then exit(2); end; (* dangling *)
1355+ i, err := linkInfo("/tmp/raz-sys-link");
1356+ if (err # 0) or not i.symlink or (i.size # 13) then exit(2); end;
1357+ _ := remove("/tmp/raz-sys-link");
13061358 (* open as asked, seek, the mode and the time *)
13071359 _ := remove("/tmp/raz-sys-dir/h");
13081360 fd := open("/tmp/raz-sys-dir/h", {writing, creating, exclusive});
@@ -1321,7 +1373,16 @@
13211373 if (truncate(fd, 4) # 0) or (position(fd) # 2) or (sync(fd) # 0) then exit(2); end;
13221374 i, err := infoOf(fd);
13231375 if (err # 0) or (i.size # 4) or not i.file or i.symlink then exit(2); end;
1376+ m := INT(i.ino);
1377+ i, err := info("/tmp/raz-sys-dir/h");
1378+ if (err # 0) or (INT(i.ino) # m) or (syncAll(fd) # 0) then exit(2); end;
1379+ (* the lock: one open file holds it, another can't take it until
1380+ the first is closed *)
1381+ k := openRead("/tmp/raz-sys-dir/h");
1382+ if (lock(fd, false) # 0) or (lock(k, false) # -11) then exit(2); end;
13241383 close(fd);
1384+ if lock(k, true) # 0 then exit(2); end;
1385+ close(k);
13251386 if (position(fd) # -9) or (truncate(fd, 0) # -9) or (sync(fd) # -9) then exit(2); end; (* EBADF *)
13261387 i, err := infoOf(fd);
13271388 if err # -9 then exit(2); end;
@@ -1330,6 +1391,11 @@
13301391 if chmod("/tmp/raz-sys-dir/h", 1EDH) # 0 then exit(2); end;
13311392 i, err := info("/tmp/raz-sys-dir/h");
13321393 if i.mode # 1EDH then exit(2); end;
1394+ _ := remove("/tmp/raz-sys-dir/h");
1395+ fd := openMode("/tmp/raz-sys-dir/h", {writing, creating}, 1C0H); (* rwx------ *)
1396+ close(fd);
1397+ i, err := info("/tmp/raz-sys-dir/h");
1398+ if (fd < 0) or (err # 0) or (i.mode # 1C0H) then exit(2); end;
13331399 _ := remove("/tmp/raz-sys-dir/h");
13341400 i, err := info("/no/such/file");
13351401 if err >= 0 then exit(2); end;