Skip to content

Commit 46bb425

Browse files
committed
The lock position is asked about rather than assumed
⚠️⚠️ AN ENVIRONMENT MAY EXPORT A NAME AND NOT IMPLEMENT WHAT IT NAMES. This system locks a byte range, and the three continuous-integration rows that run ON it measure that it does. A fourth row cross-builds and runs the result under an EMULATOR of this system, which exports `NtLockFile' and answers `STATUS_NOT_IMPLEMENTED' when it is called. ⭐ SO THE PROPERTY IS NOT A PROPERTY OF THE VOLUME, NOR OF THE FORMAT. It is a property of what is beneath the program at the moment it asks. A word that claimed the position regardless would be describing the INTERFACE rather than the environment --- and the whole purpose of a capability word is that a caller may ask before it calls and be told the truth about where it is. ⚠️ THE ENQUIRY IS MADE ON A DIRECTORY, WHICH IS NOT A THING THIS SYSTEM LOCKS, and that is what makes it answerable without disturbing anything. A system that implements the operation refuses a directory as a wrong request; one that has not implemented it says so with a different value, and that difference is the whole of the question. Nothing is locked either way, and it is asked once. Measured under that emulator, through the C library above: a lock now reports `ENOSYS' --- which is true there --- rather than the suite reporting four observations that did not hold. On the three rows that run on the system itself, nothing changes and the observations hold.
1 parent b9db125 commit 46bb425

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

src/fs.cpp

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,11 +657,59 @@ int kal_fs_list_next(kal_dir, kal_uintptr* iter,
657657
// guessed: names on the volume this system is ordinarily installed on are
658658
// compared without regard to case, and a volume attached to the same machine
659659
// may be otherwise --- and a word per implementation could state neither.
660+
// Whether the environment beneath actually performs a lock.
661+
//
662+
// ⚠️ ASKED ON A DIRECTORY, WHICH IS NOT A THING THIS SYSTEM LOCKS --- and that is
663+
// what makes the question answerable without disturbing anything. A system that
664+
// implements the operation refuses a directory as a wrong request; one that has
665+
// not implemented it says so with a different value, and that difference is the
666+
// whole of the enquiry. Nothing is locked either way.
667+
//
668+
// Answered once. It is a property of what is beneath this program rather than of
669+
// a volume, so it does not vary between the directories one program holds.
670+
static bool locking_available() {
671+
static int cached = -1;
672+
if (cached >= 0) return cached != 0;
673+
const kal_uintptr count = kal_fs_preopen_count();
674+
cached = 1;
675+
if (count > 0) {
676+
kal_dir probe{};
677+
char name[8]; kal_uintptr len = 0;
678+
if (kal_fs_preopen(0, &probe, name, sizeof name, &len) == kal_ok) {
679+
void* h = dir_handle(probe);
680+
if (h) {
681+
okw::io_status_block iosb{};
682+
okw_i64 off = 0, len2 = 1;
683+
const long r = okw::NtLockFile(h, nullptr, nullptr, nullptr, &iosb,
684+
&off, &len2, 0, 1, 1);
685+
if (okw::ok(r)) okw::NtUnlockFile(h, &iosb, &off, &len2, 0);
686+
else if (r == okw::status_not_implemented) cached = 0;
687+
}
688+
}
689+
}
690+
return cached != 0;
691+
}
692+
660693
kal_uintptr kal_fs_props(kal_dir d) {
661694
void* h = dir_handle(d);
695+
// ⚠️⚠️ LOCKING IS ASKED ABOUT RATHER THAN ASSUMED, AND THE REASON IS NOT
696+
// THE VOLUME.
697+
//
698+
// This system locks a byte range, and the three continuous-integration rows
699+
// that run on it measure that it does. A FOURTH row cross-builds and runs
700+
// the result under an emulator of this system --- which EXPORTS the call and
701+
// answers `STATUS_NOT_IMPLEMENTED' when it is made.
702+
//
703+
// ⭐ So the property is not a property of the volume here, nor of the
704+
// format: it is a property of what is beneath the program at the moment it
705+
// asks. A word that claimed the position regardless would be describing the
706+
// INTERFACE rather than the environment --- and the whole purpose of a
707+
// capability word is that a caller may ask before it calls and be told the
708+
// truth about where it is.
709+
const kal_uintptr lockable = locking_available() ? KAL_FS_PROP_LOCKS : 0;
662710
const kal_uintptr conservative =
663711
KAL_FS_PROP_MODIFIED_TIME | KAL_FS_PROP_ATOMIC_RENAME
664-
| KAL_FS_PROP_LOCKS | KAL_FS_PROP_CAPACITY;
712+
| lockable | KAL_FS_PROP_CAPACITY;
665713
if (!h) return 0;
666714

667715
okw::io_status_block s{};

src/win.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,13 @@ inline bool ok(long status) { return status >= 0; }
245245
// reported to have the same identity.
246246
inline constexpr long status_buffer_overflow = static_cast<long>(0x80000005ul);
247247

248+
// ⚠️ AN ENVIRONMENT MAY EXPORT A NAME AND NOT IMPLEMENT WHAT IT NAMES, and the
249+
// two are distinguishable only by this value. It is what a capability word has
250+
// to consult before claiming a position: an operation whose export resolves and
251+
// whose call answers this cannot be performed here, and a word claiming it would
252+
// be describing the interface rather than the environment.
253+
inline constexpr long status_not_implemented = static_cast<long>(0xC0000002ul);
254+
248255
// --- translation -------------------------------------------------------------
249256
//
250257
// The environment's error values are mapped onto the closed set the

0 commit comments

Comments
 (0)