raz / commit b27fd91f

commit
b27fd91f8a97e57e3941ed7be9c1755b39551833
author
Luis <42945842+ldiaz94@users.noreply.github.com>
date
parent
5406a156
PROPOSALS: what a version control system needs of Sys

linkInfo, Info.ino, openMode, lock and syncAll, met in porting sauce;
each breaks no program.

patch · log

1 file changed, +71 -0

PROPOSALS.md modified +71 -0

@@ -81,3 +81,74 @@
8181 a failed check in it is still told at its line; 60 to 100 lines of
8282 the budget; and, across modules, the imported module's
8383 text kept to be read again, which is to be checked.
84+
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}))`.