Sys.Info.links: how many names a file has From st_nlink, beside ino, in both Sys. For arno, which must tell a file made in its scratch dir from a hard link to one outside.
| @@ -649,28 +649,3 @@ | ||
| 649 | 649 | Met in rrem's `RremUcd`, whose tables `tools/Ucd.raz` writes: before |
| 650 | 650 | the tool's first run, each table needs a placeholder of one element, |
| 651 | 651 | which the code reading it must then not take for a real one. |
| 652 | - | |
| 653 | -## A file's link count | |
| 654 | - | |
| 655 | -`Sys.Info` names a file (`dev`, `ino`) but doesn't say how many names | |
| 656 | -it has. A program that lets a writer loose in a directory of its own | |
| 657 | -can't tell a file made there from a hard link to one somewhere else: | |
| 658 | -both are regular files inside the directory, and writing to either | |
| 659 | -writes to the one file. | |
| 660 | - | |
| 661 | -The proposal, in `Info`, beside `ino`: | |
| 662 | - | |
| 663 | -``` | |
| 664 | -links*: U64; (* how many names the file has: 1 for a file no hard link shares *) | |
| 665 | -``` | |
| 666 | - | |
| 667 | -filled in `fromStat` from `st_nlink`, which is `st[2]` on | |
| 668 | -x86_64 Linux, as `st_ino` is `st[1]`. A field more in a record breaks | |
| 669 | -only a program that builds an `Info` by a literal of all its fields, | |
| 670 | -so it could come with a thaw. | |
| 671 | - | |
| 672 | -Met in arno: a conversation's scratch directory is the model's own, | |
| 673 | -and its `edit`, `move` and `remove` there go ahead without asking. The | |
| 674 | -Pascal arno refused that freedom for a file with a second link, which | |
| 675 | -shares its contents with a name outside, perhaps one of the human's; | |
| 676 | -the raz arno can't, until `Info` says how many links a file has. |
| @@ -179,6 +179,7 @@ | ||
| 179 | 179 | symlink*: BOOL; (* the path itself is a symbolic link *) |
| 180 | 180 | ino*: U64; (* its inode, which a rename keeps and a new file doesn't *) |
| 181 | 181 | dev*: U64; (* the file system it is on; with ino, it names the file *) |
| 182 | + links*: U64; (* how many names it has: 1 for a file no hard link shares *) | |
| 182 | 183 | end; |
| 183 | 184 | Kind* = (unknown, isFile, isDir, isLink, isOther); (* what a directory says a name in it is *) |
| 184 | 185 | Dir* = record ... end; (* an open directory; its fields are the target's *) |
| @@ -357,7 +358,9 @@ | ||
| 357 | 358 | files have none. `Info.dev` is the file system the file is on: two |
| 358 | 359 | files are one only if both `dev` and `ino` agree, which is how a |
| 359 | 360 | program following links finds that one has led it back into a |
| 360 | -directory it is already in. `Info.mode` holds the nine | |
| 361 | +directory it is already in. `Info.links` is how many names the file | |
| 362 | +has: more than 1 if a hard link shares it, so that writing to it | |
| 363 | +writes to a file named elsewhere too; 0 on a target that doesn't say. `Info.mode` holds the nine | |
| 361 | 364 | bits of `rwxrwxrwx`, and `chmod` sets them, 1EDH (755) for a program, |
| 362 | 365 | 1A4H (644) for data. |
| 363 | 366 |
| @@ -41,6 +41,7 @@ | ||
| 41 | 41 | symlink*: BOOL; (* the path itself is a symbolic link *) |
| 42 | 42 | ino*: U64; (* its inode, which a rename keeps and a new file doesn't *) |
| 43 | 43 | dev*: U64; (* the file system it is on; with ino, it names the file *) |
| 44 | + links*: U64; (* how many names it has: 1 for a file no hard link shares *) | |
| 44 | 45 | end; |
| 45 | 46 | |
| 46 | 47 | (* What a directory says a name in it is, without asking the file: |
| @@ -440,6 +441,7 @@ | ||
| 440 | 441 | i.size := st[6]; (* st_size *) |
| 441 | 442 | i.dev := U64(st[0]); (* st_dev *) |
| 442 | 443 | i.ino := U64(st[1]); (* st_ino *) |
| 444 | + i.links := U64(st[2]); (* st_nlink *) | |
| 443 | 445 | i.mtime := st[11] * 1000000000 + st[12]; (* st_mtim *) |
| 444 | 446 | i.mode := st[3] & 1FFH; |
| 445 | 447 | i.dir := st[3] & 0F000H = 4000H; (* S_IFDIR *) |
| @@ -2243,7 +2245,7 @@ | ||
| 2243 | 2245 | if (entryKind(ADR(d)) # isFile) and (entryKind(ADR(d)) # unknown) then exit(2); end; |
| 2244 | 2246 | i, err := info("/tmp/raz-sys-dir/g"); |
| 2245 | 2247 | j, err := info("/tmp/raz-sys-dir"); |
| 2246 | - if (err # 0) or (i.dev # j.dev) or (i.ino = j.ino) then exit(2); end; | |
| 2248 | + if (err # 0) or (i.dev # j.dev) or (i.ino = j.ino) or (i.links # 1) then exit(2); end; | |
| 2247 | 2249 | name, ok := nextEntry(ADR(d)); |
| 2248 | 2250 | if ok then exit(2); end; |
| 2249 | 2251 | closeDir(ADR(d)); |
| @@ -60,6 +60,7 @@ | ||
| 60 | 60 | symlink*: BOOL; (* the path itself is a symbolic link *) |
| 61 | 61 | ino*: U64; (* its inode, which a rename keeps and a new file doesn't *) |
| 62 | 62 | dev*: U64; (* the file system it is on; with ino, it names the file *) |
| 63 | + links*: U64; (* how many names it has: 1 for a file no hard link shares *) | |
| 63 | 64 | end; |
| 64 | 65 | |
| 65 | 66 | (* What a directory says a name in it is, without asking the file: |
| @@ -507,6 +508,7 @@ | ||
| 507 | 508 | i.size := st[6]; (* st_size *) |
| 508 | 509 | i.dev := U64(st[0]); (* st_dev *) |
| 509 | 510 | i.ino := U64(st[1]); (* st_ino *) |
| 511 | + i.links := U64(st[2]); (* st_nlink *) | |
| 510 | 512 | i.mtime := st[11] * 1000000000 + st[12]; (* st_mtim *) |
| 511 | 513 | i.mode := st[3] & 1FFH; |
| 512 | 514 | i.dir := st[3] & 0F000H = 4000H; (* S_IFDIR *) |
| @@ -2064,7 +2066,7 @@ | ||
| 2064 | 2066 | if (entryKind(ADR(d)) # isFile) and (entryKind(ADR(d)) # unknown) then exit(2); end; |
| 2065 | 2067 | i, err := info("/tmp/raz-sys-dir/g"); |
| 2066 | 2068 | j, err := info("/tmp/raz-sys-dir"); |
| 2067 | - if (err # 0) or (i.dev # j.dev) or (i.ino = j.ino) then exit(2); end; | |
| 2069 | + if (err # 0) or (i.dev # j.dev) or (i.ino = j.ino) or (i.links # 1) then exit(2); end; | |
| 2068 | 2070 | name, ok := nextEntry(ADR(d)); |
| 2069 | 2071 | if ok then exit(2); end; |
| 2070 | 2072 | closeDir(ADR(d)); |