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

Lexical functions - F$UNIQUE, F$USER, and F$VERIFY

The F$UNIQUE lexical function generates a unique string. Here is the definition:

F$UNIQUE generates a string that is suitable to be a file name and is guaranteed to be unique across the cluster. Unique file names can be used when creating temporary files. Note that this function guarantees a unique name for each time it is called, no matter which process or node is making the call. However, it does not guarantee that the name is not already in use on the system.

Format
F$UNIQUE()

Return Value
A unique character string.

Arguments
none

Example
$ A = F$UNIQUE()
This call will set the symbol A to a unique string which can be used as a filename.

        Function_UNIQUE : begin
                              if( Missing_Parentheses( '(' ) ) then
                              begin
                                  exit ;
                              end ;
                              if( Process_Unique( Err, Context ) ) then
                              begin
                                  exit ;
                              end ;
                              if( Missing_Parentheses( ')' ) ) then
                              begin
                                  exit ;
                              end ;
                              S := Context ;
                          end ;
This code is added to the Function_Reference function.

function Process_Unique( var Err : integer ; var Context : string ) : boolean ;

var I : integer ;
    L : int64 ;
    N, S : string ;

begin
    // Setup...
    Result := False ; // Assume no problems

    setlength( S, sizeof( int64 ) ) ;
    L := LIB_Get_Timestamp ;
    move( L, PChar( S )[ 0 ], sizeof( int64 ) ) ;
    S := S + Get_SYI( SYI_NODENAME, '', 0 ) ;
    N := '' ;
    for I := length( S ) downto 1 do
    begin
        N := N + Hex( ord( S[ I ] ) ) ;
    end ;
    Context := N ;
end ;
This function constructs a unique filename. The idea here is that the system clock interval is fast enough that no two processes will request the current time at the same time. In actuality, that is quite possible, given the low resolution of most hardware clocks used in computers these days. However, the UOS rule is that each request for a timestamp from the HAL must return a different value. In our simulated HAL, we do this by remembering the last time a request was made and, if the time is the same as that, we add an internal nanosecond offset, and increment that offset. In essence, multiple requests within the minimum resolution of the hardware will result in values indicting the current time, plus 1 nanosecond for each subsequent call. Thus, the timestamp we get will be a unique value. We can use this to generate a unique name. Note: Just so you know, this still holds for multi-processor systems since reading the timestamp is a serialized feature (only one access at a time).

While this approach yields a guaranteed unique value for each call on a given computer, there is no guarantee that the same value cannot be obtained from two or more different computers in a cluster. Because the value has to be unique within the cluster, we need to take this situation into account. Since each node in a cluster must be unique, we'll use the node name as a prefix for the timestamp. Problem solved.

We use a string in this case as a binary buffer. We move the timestamp into the string, then prepend the node name. Next we iterate through the buffer, converting each byte to a hexadecimal value, and building the result string from that.


The F$USER lexical function returns the username of the user running the script. Here is the definition.

F$USER returns the current user name as a string. The function takes no arguments, but must be followed by parentheses.

Format
F$USER()

Return Value
A character string containing the current user's username.

Arguments
none

Example
$ A = F$USER()
This call will set the symbol A to the user name of the user running the script.

function Process_User( var Err : integer ; var Context : string ) : boolean ;

begin
    Result := False ; // Assume no problems

    Context := Get_JPI( 0, JPI_USERNAME ) ;
end ;
This function simply makes a GETJPI system service call and returns the user name.


UCL (and DCL) has a means of logging the input file to the terminal when a script is run. Normally, the script is not echoed to the terminal. There are two aspects of what is in a command file: commands and data. UCL has two flags that indicate whether or not to echo those items. When a command procedure is started, these flags are set to False, but the F$VERIFY lexical function can be used to change their state. Here is the definition:

F$VERIFY returns an integer value indicating whether the procedure verification flag is currently on or off. If arguments are provided, the procedure and/or image verification can be changed. The parentheses must follow the function name even if no arguments are provided.

Format
F$VERIFY({proc} {,image})

Return Value
The function returns 0 if procedure verification is off, or 1 if it is on.

Arguments
proc

Specifies 1 to turn procedure verification on, or 0 to turn it off. If omitted, the current procedure verification setting is left unchanged. Note that the function returns the procedure verification state prior to making any change to it.

image

Specifies 1 to turn image verification on, or 0 to turn it off. If omitted, the current image verification setting is left unchanged.

Examples
$ A = F$VERIFY()
This code will set the symbol A to the current procedure verification flag. No other processing occurs.

$ A = F$VERIFY(,1)
This code will set the symbol A to the current procedure verification flag. The procedure verification is left unaltered, and the image verification is enabled.

$ A = F$VERIFY(0)
This code will set the symbol A to the current procedure verification flag and then turns procedure verification off.

$ A = F$VERIFY(1,0)
This call will set the symbol A to the current procedure verification flag and then turns procedure verification on and image verification off.

var Verify_Procedure : boolean = False ; // True to verify procedure
var Verify_Image : boolean = False ; // True to echo
These are the flags that control verification.

        Function_VERIFY : begin
                              if( Missing_Parentheses( '(' ) ) then
                              begin
                                  exit ;
                              end ;
                              if( Process_Verify( Err, Context ) ) then
                              begin
                                  exit ;
                              end ;
                              if( Missing_Parentheses( ')' ) ) then
                              begin
                                  exit ;
                              end ;
                              S := Context ;
                          end ;
This code is added to the Function_Reference function.

function Process_Verify( var Err : integer ; var Context : string ) : boolean ;

var P, Image, Res : string ;

begin
    // Setup...
    Result := False ; // Assume no problems

    // Set result...
    if( Verify_Procedure ) then
    begin
        Res := '1' ;
    end else
    begin
        Res := '0' ;
    end ;

    // Get parameters...
    P := uppercase( Get_Parameter( Err, Context, True ) ) ;
    if( Err <> 0 ) then
    begin
        exit ;
    end ;
    Image := '' ;
    if( Parser.Peek = ',' ) then
    begin
        Image := uppercase( Get_Parameter( Err, Context, True ) ) ;
        if( Err <> 0 ) then
        begin
            exit ;
        end ;
    end ;
This function first saves the state of the procedure verification flag. Then we get the parameters.

    // Alter flags...
    if( P <> '' ) then
    begin
        if( UCL_Strtoint( P ) = '0' ) then
        begin
            Verify_Procedure := False ;
        end else
        begin
            Verify_Procedure := True ;
        end ;
    end ;
    if( Image <> '' ) then
    begin
        if( UCL_Strtoint( Image ) = '0' ) then
        begin
            Verify_Image := False ;
        end else
        begin
            Verify_Image := True ;
        end ;
    end ;
    Context := Res ;
end ; // Process_Verify
We set the procedure verification flag appropriately, if the argument was provided. Likewise the image verification flag. Then we return the original procedure verification state.

    if( S = 'verify_image' ) then
    begin
        Context := TrueFalse( Verify_Image ) ;
    end else
    if( S = 'verify_procedure' ) then
    begin
        Context := TrueFalse( Verify_Procedure ) ;
    end else
This code in the Parse_Environment function is modified to handle the verify flags.

function TrueFalse( Value : boolean ) : string ;

begin
   if( Value ) then
   begin
       Result := 'TRUE' ;
   end else
   begin
       Result := 'FALSE' ;
   end ;
end ;
This new function is used by the above code.

In the next few articles, we will examine the last lexical function and delve more deeply into file I/O.

 

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