1 Introduction
2 Ground Rules

Building a File System
3 File Systems
4 File Content Data Structure
5 Allocation Cluster Manager
6 Exceptions and Emancipation
7 Base Classes, Testing, and More
8 File Meta Data
9 Native File Class
10 Our File System
11 Allocation Table
12 File System Support Code
13 Initializing the File System
14 Contiguous Files
15 Rebuilding the File System
16 Native File System Support Methods
17 Lookups, Wildcards, and Unicode, Oh My
18 Finishing the File System Class

The Init Program
19 Hardware Abstraction and UOS Architecture
20 Init Command Mode
21 Using Our File System
22 Hardware and Device Lists
23 Fun with Stores: Partitions
24 Fun with Stores: RAID
25 Fun with Stores: RAM Disks
26 Init wrap-up

The Executive
27 Overview of The Executive
28 Starting the Kernel
29 The Kernel
30 Making a Store Bootable
31 The MMC
32 The HMC
33 Loading the components
34 Using the File Processor
35 Symbols and the SSC
36 The File Processor and Device Management
37 The File Processor and File System Management
38 Finishing Executive Startup

Users and Security
39 Introduction to Users and Security
40 More Fun With Stores: File Heaps
41 File Heaps, part 2
42 SysUAF
43 TUser
44 SysUAF API

Terminal I/O
45 Shells and UCL
46 UOS API, the Application Side
47 UOS API, the Executive Side
48 I/O Devices
49 Streams
50 Terminal Output Filters
51 The TTerminal Class
52 Handles
53 Putting it All Together
54 Getting Terminal Input
55 QIO
56 Cooking Terminal Input
57 Putting it all together, part 2
58 Quotas and I/O

UCL
59 UCL Basics
60 Symbol Substitution
61 Command execution
62 Command execution, part 2
63 Command Abbreviation
64 ASTs
65 Expressions, Part 1
66 Expressions, Part 2: Support code
67 Expressions, part 3: Parsing
68 SYS_GETJPIW and SYS_TRNLNM
69 Expressions, part 4: Evaluation

UCL Lexical Functions
70 PROCESS_SCAN
71 PROCESS_SCAN, Part 2
72 TProcess updates
73 Unicode revisted
74 Lexical functions: F$CONTEXT
75 Lexical functions: F$PID
76 Lexical Functions: F$CUNITS
77 Lexical Functions: F$CVSI and F$CVUI
78 UOS Date and Time Formatting
79 Lexical Functions: F$CVTIME
80 LIB_CVTIME
81 Date/Time Contexts
82 SYS_GETTIM, LIB_Get_Timestamp, SYS_ASCTIM, and LIB_SYS_ASCTIM
83 Lexical Functions: F$DELTA_TIME
84 Lexical functions: F$DEVICE
85 SYS_DEVICE_SCAN
86 Lexical functions: F$DIRECTORY
87 Lexical functions: F$EDIT and F$ELEMENT
88 Lexical functions: F$ENVIRONMENT
89 SYS_GETUAI
90 Lexical functions: F$EXTRACT and F$IDENTIFIER
91 LIB_FAO and LIB_FAOL
92 LIB_FAO and LIB_FAOL, part 2
93 Lexical functions: F$FAO
94 File Processing Structures
95 Lexical functions: F$FILE_ATTRIBUTES
96 SYS_DISPLAY
97 Lexical functions: F$GETDVI
98 Parse_GetDVI
99 GetDVI
100 GetDVI, part 2
101 GetDVI, part 3
102 Lexical functions: F$GETJPI
103 GETJPI
104 Lexical functions: F$GETSYI
105 GETSYI
106 Lexical functions: F$INTEGER, F$LENGTH, F$LOCATE, and F$MATCH_WILD
107 Lexical function: F$PARSE
108 FILESCAN
109 SYS_PARSE
110 Lexical Functions: F$MODE, F$PRIVILEGE, and F$PROCESS
111 File Lookup Service
112 Lexical Functions: F$SEARCH
113 SYS_SEARCH
114 F$SETPRV and SYS_SETPRV
115 Lexical Functions: F$STRING, F$TIME, and F$TYPE
116 More on symbols
117 Lexical Functions: F$TRNLNM
118 SYS_TRNLNM, Part 2
119 Lexical functions: F$UNIQUE, F$USER, and F$VERIFY
120 Lexical functions: F$MESSAGE
121 TUOS_File_Wrapper
122 OPEN, CLOSE, and READ system services

UCL Commands
123 WRITE
124 Symbol assignment
125 The @ command
126 @ and EXIT
127 CRELNT system service
128 DELLNT system service
129 IF...THEN...ELSE
130 Comments, labels, and GOTO
131 GOSUB and RETURN
132 CALL, SUBROUTINE, and ENDSUBROUTINE
133 ON, SET {NO}ON, and error handling
134 INQUIRE
135 SYS_WRITE Service
136 OPEN
137 CLOSE
138 DELLNM system service
139 READ
140 Command Recall
141 RECALL
142 RUN
143 LIB_RUN
144 The Data Stream Interface
145 Preparing for execution
146 EOJ and LOGOUT
147 SYS_DELPROC and LIB_GET_FOREIGN

CUSPs and utilities
148 The I/O Queue
149 Timers
150 Logging in, part one
151 Logging in, part 2
152 System configuration
153 SET NODE utility
154 UUI
155 SETTERM utility
156 SETTERM utility, part 2
157 SETTERM utility, part 3
158 AUTHORIZE utility
159 AUTHORIZE utility, UI
160 AUTHORIZE utility, Access Restrictions
161 AUTHORIZE utility, Part 4
162 AUTHORIZE utility, Reporting
163 AUTHORIZE utility, Part 6
164 Authentication
165 Hashlib
166 Authenticate, Part 7
167 Logging in, part 3
168 DAY_OF_WEEK, CVT_FROM_INTERNAL_TIME, and SPAWN
169 DAY_OF_WEEK and CVT_FROM_INTERNAL_TIME
170 LIB_SPAWN
171 CREPRC
172 CREPRC, Part 2
173 COPY
174 COPY, part 2
175 COPY, part 3
176 COPY, part 4
177 LIB_Get_Default_File_Protection and LIB_Substitute_Wildcards
178 CREATESTREAM, STREAMNAME, and Set_Contiguous
179 Help Files
180 LBR Services
181 LBR Services, Part 2
182 LIBRARY utility
183 LIBRARY utility, Part 2
184 FS Services
185 FS Services, Part 2
186 Implementing Help
187 HELP
188 HELP, Part 2
189 DMG_Get_Key and LIB_Put_Formatted_Output
190 LIBRARY utility, Part 3
191 Shutting Down UOS
192 SHUTDOWN
193 WAIT
194 SETIMR
195 WAITFR and Scheduling
196 REPLY, OPCOM, and Mailboxes
197 REPLY utility
198 Mailboxes
199 BRKTHRU
200 OPCOM

Glossary/Index


Downloads

CLOSE

In the last article, we discussed the OPEN command. In this article, we cover the inverse: the CLOSE command. Note that VMS supports various options upon closing a file. UOS handles some of them now, but others will have to wait until we cover the batch and print queue facilities. We handle all of the options in UCL, but the File Processor ignores some of them for now. Here is the user documentation for CLOSE:

CLOSE

Closes a file previously opened with OPEN.

Format

CLOSE symbol{:}

Parameters

symbol
The name of the symbol used to open the file.

Description

This command closes an open file. Files opened with the OPEN command remain open until closed with CLOSE. If a command procedure terminates without closing open files, the file remains open.

Qualifiers

/DISPOSITION=option
Specifies actions to take after the file is closed. The options are:
OptionMeaning
DELETEDelete the file.
KEEP (default)Keep the file.
PRINTPrint the file.
SUBMITSubmit the command file to the batch queue.

/ERROR=label
Specify a label to jump to if there was an error when closing the file.

/{NO}LOG
/LOG is the default and indicates that if an error occurs, it is reported to the user, even if /ERROR is specified. /NOLOG means that no error message is displayed on error.

Example


$ OPEN/READ/ERROR=NoFile IN Filename
$ READ IN Line
$ CLOSE IN


                    if( Sym = 'close' ) then
                    begin
                        Process_Close ;
                    end else
This code is added to the Process routine.

procedure Process_Close ;

var Disposition, Error : string ;
    Flags, I, Index : integer ;
    Err, I64 : int64 ;
    _Log : boolean ;
    Parameters, S, Sym : string ;
    Switches : TStringList ;

begin
    // Process switches...
    Switches := Parse_Switches ;
    _Log := True ;
    Error := '' ;
    Disposition := 'k' ;
    for I := 0 to Switches.Count - 1 do
    begin
        S := lowercase( Switches[ I ] ) ;
        Parameters := '' ;
        if( Switch_Match( S, 'disposition', 1, Disposition ) ) then
        begin
            if( ( not Name_Match( Disposition, 'delete', 1 ) )
                and
                ( not Name_Match( Disposition, 'keep', 1 ) )
                and
                ( not Name_Match( Disposition, 'print', 1 ) )
                and
                ( not Name_Match( Disposition, 'submit', 1 ) )
              ) then
            begin
                Exception( UCL_IVQUAL, S ) ;
                Switches.Free ;
                exit ;
            end ;
            Disposition := copy( Disposition, 1, 1 ) ;
        end else
        if( Switch_Match( S, 'error', 1, Error ) ) then
        begin
        end else
        if( Switch_Match( S, 'log', 1, Parameters ) ) then
        begin
            _Log := True ;
            if( Parameters <> '' ) then
            begin
                Exception( UCL_NOVALU, S ) ;
                Switches.Free ;
                exit ;
            end ;
        end else
        if( Switch_Match( S, 'nolog', 3, Parameters ) ) then
        begin
            _Log := False ;
            if( Parameters <> '' ) then
            begin
                Exception( UCL_NOVALU, S ) ;
                Switches.Free ;
                exit ;
            end ;
        end else
        begin
            Exception( UCL_IVQUAL, S ) ;
            Switches.Free ;
            exit ;
        end ;
    end ;
    Switches.Free ;
This new routine handles closing files. First, we process the switches, as we did for OPEN.

    // Get symbol name...
    Sym := trim( Get_Token ) ;
    if( length( Sym ) = 0 ) then
    begin
        Sym := lowercase( Get_Prompted_Parameter( '_Log name: ' ) ) ;
        if( Sym = '' ) then
        begin
            exit ; // Aborted
        end ;
    end ;
    if( Parser.Peek = ':' ) then
    begin
        Get_Token ; // Eat the colon
    end ;
Next we get the symbol that holds the file identifier. As with OPEN, an optional colon may follow it.

    // Remove current file handle...
    S := LIB_Get_Symbol( Sym ) ;
    if( trim( S ) = '' ) then
    begin
        Exception( UCL_NULFIL ) ;
        exit ;
    end ;
    if( not Valid_Int( S, I64 ) ) then
    begin
        Exception( UCL_UNDFIL, S ) ;
        exit ;
    end ;
    Index := File_Handles.Indexof( pointer( I64 ) ) ;
    if( Index = -1 ) then // Not a file handle
    begin
        Exception( UCL_UNDFIL, S ) ;
        exit ;
    end ;
Now we read the symbol and validate that it is one of our file instances. If not, we exit with an error.

    DELLNM( '', Sym, 3 ) ;
    File_Handles.Delete( Index ) ; // Remove from handle list
    Flags := 0 ;
    if( Disposition = 'p' ) then
    begin
        Flags := FAB_V_SPL ;
    end else
    if( Disposition = 's' ) then
    begin
        Flags := FAB_V_SCF ;
    end else
    if( Disposition = 'd' ) then
    begin
        Flags := FAB_V_DLT ;
    end ;
    TCOM_File64( I64 ).Close( Flags ) ;
    TCOM_File64( I64 ).Free ; // Free previous file
    Err := LIB_Get_Exception( 0 ) ;
    if( Err <> 0 ) then
    begin
        if( _Log ) then
        begin
            Output_Line( RH_SysError, LIB_Get_Exception_Text( 0, Err ) ) ;
        end ;
        Err := LIB_Get_Exception_Code( 0, Err ) ;
    end ;
    Set_Status( Err ) ;
    if( ( Error <> '' ) and ( Err <> 0 ) ) then
    begin
        Parser.Put_Token( 'goto ' + Error ) ;
    end ;
end ; // Process_Close
Next we call DELLNM to delete the logical with the file instance value. Then we determine the proper flag for the specified options and call the file's close method with that flag. Finally we free the file instance, display any error unless the user specified /NOLOG, then jump to the error label if there was an error and /ERROR was specified. DELLNM will be covered in the next article.

procedure TUOS_File_Wrapper.Close( Flags : int64 = 0 ) ;

begin
    if( FAB.FAB_Q_HANDLE <> 0 ) then // If open
    begin
        FAB.FAB_L_FOP := FAB.FAB_L_FOP or Flags ;
        SYS_CLOSE( int64( @FAB ), 0, 0 ) ;
        FAB.FAB_Q_HANDLE := 0 ;
    end ;
end ;
Lastly, we modify the Close method of TUOS_File_Wrapper to take an optional parameter and update the FAB's file operation (FOP) code if the optional parameter was non-zero. This will pass the flags to the File Processor when the file is closed.

    if( not USC.Valid_Handle( PID, FAB.FAB_Q_Handle ) ) then
    begin
        Generate_Exception( UOSErr_Invalid_Handle ) ;
        Result := UOSErr_Invalid_Handle ;
        Call_To_User( Err ) ;
        exit ;
    end ;
    Resource := TResource( FAB.FAB_Q_Handle ) ;
    Name := '' ;
    if( Resource._File <> nil ) then
    begin
        Name := TFiP_File( Resource._File )._Name ;
        Device := TDevice( Resource._Device ) ;
    end ;
This code is added to the TUOS_FIP.File_Close method just before the handle is closed. The point of the code is to obtain the device and filename for optional close behaviors.

      if( ( FAB.FAB_L_FOP and FAB_V_DLT ) <> 0 ) then
      begin
          if( ( Name <> '' ) and ( Device.FS <> nil ) ) then
          begin
              Device.FS.Delete_File( PChar( Name ) ) ; // TODO: Handle versions, backup, etc.
          end ;
      end else
      if( ( FAB.FAB_L_FOP and FAB_V_SPL ) <> 0 ) then
      begin
          //TODO:spool file to print queue
      end else
      if( ( FAB.FAB_L_FOP and FAB_V_SCF ) <> 0 ) then
      begin
          //TODO:submit to batch queue
      end ;
This code is added later in the same routine to handle the new flags passed from UCL. As mentioned earlier, certain options aren't supported yet. But we do handle the delete-on-close option.

In the next article, we will examine the DELLNM system service.

 

Copyright © 2021 by Alan Conroy. This article may be copied in whole or in part as long as this copyright is included.