Skip to content

43B CloseFile

Validated   MON 43B (35 decimal) · Mnemonic CLOSE · Group: File Operations (manual section 2.4)

Available from: All programs (manual compatibility box)

Emulation source: src/handlers/mon_43B_CloseFile.c

Description

Closes one or more files. Files must be opened before they are accessed. Afterwards they should be closed.

  • CloseFile also resets peripheral files. This is similar to DeviceControl with control flag -1.
  • For non-RT programs, files are closed when your program terminates.

Notes

  • Version history: in the N-version, MON CLOSE (MON 43) used from an RT-program to close a file that was not opened by the program itself now reports the closing of the RT-open file to be logged by the ERS/SINTRAN III Watchdog (ND-860230-8-EN SINTRAN III - Release Information - N-version.md:962, 1406).

Parameters

Name Type Direction Description
FileNumber INTEGER In File number returned when the file was opened.
-1 = close all files not permanently open
-2 = close all files including scratch and permanently open files

Direction: In = the program supplies the value, Out = the call returns it, In/Out = both.

See also

OpenFile, CloseSpoolingFile, BackupClose, and @CLOSE-FILE

Compatibility

Machines Users Programs
ND-100 and ND-500 All users All programs

The manual's compatibility box for this call, word for word.

Yes/no fields from the YAML extraction (not in the manual's words):

ND-100 ND-500 User programs RT programs System programs
Yes Yes No No No

Examples

From the manual (OCR text, not corrected).

INTEGER : FileNumber
...
ON ROUTINEERROR DO
   IF ErrCode > 0 THEN ...
ENDON
Monitor_Call('Closefile', FileNumber)
INTEGER FileNumber
...
Monitor_Call('CloseFile', FileNumber)
IF (ErrCode .NE. 0) THEN ...
FileNumber : INTEGER2;
...
CloseFile(FileNumber);
IF ErrCode <> 0 THEN ...
01 FileNumber COMP.
01 ErrCode COMP.
...
MONITOR-CALL "CloseFile" USING FileNumber.
CALL "CbError" USING ErrCode.
IF ErrCode NOT = 0 GO ...
FileNumber : W BLOCK 1
ErrCode : W BLOCK 1
CloseFile : EQU 37B9 + 43B
...
CALLG CloseFile, 1, FileNumber
IF K GO ERROR
...
ERROR : W1 =: ErrCode          %ErrorCode in W1 register.
LDT  FILNO                 %Load register T with file number.
MON  43                   %Monitor call Closefile.
JMP  ERROR                %Error return from monitor call.
...                        %Normal return.
ERROR, ...                 %Error number in register A.
...
FILNO, ...

ndmonlib implementation

Validated Registered MON_STATUS_VALIDATED in src/core/mon_registry.c: implemented, tested and working.

Handler mon_43B_CloseFile
Code lines 61 (non-blank, non-comment lines in the file)

Notes from the handler source

src/handlers/mon_43B_CloseFile.c line 42

Handle special case: -1 means close all files not permanently open.
Must write back any still connected as a segment first - same reason
as the single-file path below, just applied to every open file.

src/handlers/mon_43B_CloseFile.c line 68

If the file is still connected as a segment, flush it back to disk first.
Closing a connected file implicitly disconnects it (SINTRAN: "The file is
disconnected when it is closed"), and a connected file is MAPPED rather
than copied - the program writes the FILE through memory accesses to the
segment. Without this, everything built in the mapping is lost at CLOSE.
See the 413B handler for the same flush on an explicit disconnect.

Emulation research

Source

This section comes from the emulation: block of the call's YAML file in the NDInsight repo. It records what was learned while implementing the call in nd500x; its status is nd500x's, not ndmonlib's.

Status (nd500x) implemented
nd500x handler nd500x/src/libmon/handlers/mon_43B_CloseFile.c
Last updated 2026-07-17

Supporting code

nd500x/src/libmon/mon_file_table.c

Parameter notes

1. FileNumber

Field Value
Note Read as a SIGNED 32-bit word. The negative special values the manual documents (-1, -2) only work if the parameter is sign-interpreted; read unsigned they become huge file numbers and fail the range check.
Verified Yes

Return contract

  • Success: K flag cleared.
  • Errors

    Code Octal Meaning
    87 127B File number out of range (not 64-127 decimal / 0100-0177 octal)
    90 132B No file opened with this number
    111 157B Missing parameter

Verified

1. CLOSE is where a deferred 73B SMAX length is physically applied.

Field Value
Evidence 73B SMAX only RECORDS the logical max-byte length (carve: the physical length is applied at CLOSE, not by SMAX). nd500x sets a max_bytes_set flag in 73B and ftruncates to bytes_in_file here, and only when that flag is set and the file is not a scratch file about to be unlinked. mon_file_table.c mon_close_file. Commit 2618145 + the SMAX/CLOSE deferral described in nd500x/docs/MON_CSHARP_SYNC_HANDOFF.md.

2. FileNumber -1 and -2 close all files (per the manual field).

Field Value
Evidence Implemented as a full file-table reset for both values. This satisfies the manual text but does not distinguish permanently-open files - see unverified.

Unverified

  • The carve does NOT byte-prove the SMAX -> CLOSE link. "SMAX records, CLOSE applies" is the consistent model we adopted after the immediate-ftruncate was proven harmful (it shortened NC's scratch file under its feet); it is INFERRED, not read from the carve.
  • -1 and -2 are implemented identically (reset everything). The manual distinguishes them: -1 = all files NOT permanently open, -2 = all including scratch and permanently open. nd500x has no permanently-open model (236B SetPermanentOpen), so the distinction is currently unmodelled.
  • The manual note "CloseFile also resets peripheral files (similar to DeviceControl with -1)" is NOT implemented - closing a file performs no device reset.
  • "Releases any reservation on the file" is not implemented; CLOSE does not interact with 122B/123B reservation state.

Emulator specific

1. SCRATCH files are UNLINKED on close by default. Set the environment variable ND500X_KEEP_SCRATCH=1 to keep them - the VDM/C pipeline needs the scratch (SCRATCHnn:DATA, file 0100 octal = 64) to survive NC's close so the CAT-500 back-end can read the CAT intermediate out of it. This is an emulator affordance, NOT SINTRAN behaviour.

Field Value
Evidence commit f353a40; mon_file_table.c mon_close_file.

Sources

Doc Note Commit
SINTRAN III Monitor Calls (ND-860228.2 EN) The manual page this YAML was extracted from.
nd500x/docs/MON_CSHARP_SYNC_HANDOFF.md Section "73B SMAX + 43B CLOSE - truncation deferral".
2618145 (nd500x) - SMAX records, CLOSE applies
f353a40 (nd500x) - ND500X_KEEP_SCRATCH

Source

SINTRAN III Monitor Calls (ND-860228.2 EN), page 117.