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

DAY_OF_WEEK and CVT_FROM_INTERNAL_TIME

In the previous article, we documented three new system services. In this article, we will begin to look at the code to implement the first two.

function DAY_OF_WEEK( Time : int64 ) : integer ;

var DOW : int64 ;

begin
    DOW := 0 ;
    LIB_DAY_OF_WEEK( int64( @Time ), int64( @DOW ) ) ;
    Result := DOW ;
end ;
This function is added to the PasStartlet unit. It provides a Pascal-friendly interface to the Starlet service.

procedure LIB_DAY_OF_WEEK( Time, Res : int64 ) ;

begin
    if( Res = 0 ) then
    begin
        exit ; // No place to write result
    end ;
    if( Time = 0 ) then
    begin
        Time := LIB_Get_Timestamp ;
    end else
    begin
        Time := pint64( Time )^ ;
        if( Time = 0 ) then
        begin
            Time := LIB_Get_Timestamp ;
        end ;
    end ;
    Time := DOW( Time ) ;
    pint64( Res )^ := Time ;
end ;
This service returns the day of week for the passed time. If no time is passed (address is 0), we use the current timestamp.

function DOW( Time : int64 ) : int64 ;

begin
    Time := Time div One_Day - 1 ; // Convert to day (-1 since day 0 is Sunday, and Monday=1 on VMS)
    Result := ( Time mod 7 ) + 1 ; // Make 1-based instead of 0-based
end ;
This function converts a timestamp to a day of week. This is a simple operation. We know that a timestamp of 0 is Sunday, so all we need to do is divide the timestamp by the number of ns in a day (since the timestamp has a 1 ns resolution). This will return the number of days since day 0. But, oddly, VMS defines Monday as day 1 and Sunday as day 7. Since our timestamps effectively define Sunday as 0 and Saturday as 7, we have to compensate by subtracting a day. Now we can do a mod division to determine which of the 7 weekdays we are talking about. This yields a 0-based day value (0 through 6), with 0 being Monday. Then we add 1 back in to make the day value 1-based like it is on VMS.

function CVT_FROM_INTERNAL_TIME( Operation, Time : int64 ) : int64 ;

begin
    LIB_CVT_FROM_INTERNAL_TIME( int64( @Result ), int64( @Operation ), int64( @Time ) ) ;
end ;
This function is yet another one added to the PasStartlet unit to provide a Pascal-friendly interface to the Starlet service.

const VMS_Julian : int64 = 586604160000000000 ;

function LIB_CVT_FROM_INTERNAL_TIME( ResultTime, Operation : int64 ; Time : int64 = 0 ) : int64 ;

var ResValue : int64 ;
    Y, Mo, D, H, M, S : word ;
    NS : longint ;
    Weekday : integer ;

begin
    Result := 0 ;
    if( Time = 0 ) then
    begin
        Time := LIB_Get_Timestamp ;
    end else
    begin
        Time := Pint64( Time )^ ;
    end ;
    Operation := pint64( Operation )^ ;
    case Operation of
        LIB_K_DELTA_WEEKS,
        LIB_K_DELTA_DAYS,
        LIB_K_DELTA_HOURS,
        LIB_K_DELTA_MINUTES,
        LIB_K_DELTA_SECONDS : ;
        else if( Time < 0 ) then // Delta time
             begin
                 Result := LIB_ABSTIMREQ ;
                 exit ;
             end ;
    end ;
    if( Time < 0 ) then
    begin
        Time := -Time ;
    end ;
    if( ResultTime = 0 ) then // No place to write result...
    begin
        exit ;
    end ;
In the Starlet function we first get the time. If none specified (address is 0), we use the current system time. Then we get the operation to perform and verify that the time is not negative - except for delta times, which can be negative. If so, we return an error. If things are okay, we make sure the time is positive, even for delta times. Finally we exit if no result address was provided.

    Parse_Sirius_Timestamp( Time, Y, Mo, D, H, M, S, NS ) ;
    Weekday := DOW( Time ) ;
    case Operation of
        LIB_K_MONTH_OF_YEAR : ResValue := M ; // 1 to 12
        LIB_K_DAY_OF_YEAR : ResValue := Julian( M, D, Y ) ; // 1 to 366
        LIB_K_HOUR_OF_YEAR : ResValue := ( Julian( M, D, Y ) - 1 ) * 24 + H ; // 1 to 8784
        LIB_K_MINUTE_OF_YEAR : ResValue := ( Julian( M, D, Y ) - 1 ) * 24 * 60 + H * 60 + M ; 
            // 1 to 527,040
        LIB_K_SECOND_OF_YEAR : ResValue := ( Julian( M, D, Y ) - 1 ) * 24 * 60 * 60 + H * 60 * 60 + 
            M * 60 + S ;
        LIB_K_DAY_OF_MONTH : ResValue := D ; // 1 to 31
        LIB_K_HOUR_OF_MONTH : ResValue := ( D - 1 ) * 24 + H ; // 1 to 744
        LIB_K_MINUTE_OF_MONTH : ResValue := ( D - 1 ) * 24 * 60 + H * 60 + M ; // 1 to 44,640
        LIB_K_SECOND_OF_MONTH : ResValue := ( D - 1 ) * 24 * 60 * 60 + H * 60 * 60 + M * 60 + S ; 
            // 1 to 2,678,400
        LIB_K_DAY_OF_WEEK : ResValue := Weekday ; // 1 to 7
        LIB_K_HOUR_OF_WEEK : ResValue := ( Weekday - 1 ) * 24 + H ; // 1 to 168
        LIB_K_MINUTE_OF_WEEK : ResValue := ( Weekday - 1 ) + 24 * 60 + H * 60 + M ; // 1 to 10,080
        LIB_K_SECOND_OF_WEEK : ResValue := ( Weekday - 1 ) + 24 * 60 * 60 + H * 60 * 60 + M * 60 + 
            S ; // 1 to 604,800
        LIB_K_HOUR_OF_DAY : ResValue := H ; // 0 to 23
        LIB_K_MINUTE_OF_DAY : ResValue := H * 60 + M ; // 0 to 1439
        LIB_K_SECOND_OF_DAY : ResValue := H * 60 + M * 60 + S ; // 0 to 86,399
        LIB_K_MINUTE_OF_HOUR : ResValue := M ; // 0 to 59
        LIB_K_SECOND_OF_HOUR : ResValue := M * 60 + S ; // 0 to 3599
        LIB_K_SECOND_OF_MINUTE : ResValue := S ; // 0 to 59
        LIB_K_NANOSECOND_OF_SECOND : ResValue := NS ;
        LIB_K_JULIAN_DATE : ResValue := ( Time - VMS_Julian ) div One_Day ; 
            // Julian date (days since 17�Nov�1858)
        LIB_K_DELTA_WEEKS : ResValue := Time div One_Week ;
        LIB_K_DELTA_DAYS : ResValue := Time div One_Day ;
        LIB_K_DELTA_HOURS : ResValue := Time div One_Hour ;
        LIB_K_DELTA_MINUTES : ResValue := Time div One_Minute ;
        LIB_K_DELTA_SECONDS : ResValue := Time div One_Second ;
        else
        begin
            Result := LIB_INVOPER ; // Invalid operation
            exit ;
        end ;
    end ;
    pint64( ResultTime )^ := ResValue ;
end ; // LIB_CVT_FROM_INTERNAL_TIME
To make the following code simpler, we parse the time into its components and determine the day of the week. Next we perform the requested operation. Most of these operations are fairly simple, but we need to talk about the different kinds of Julian dates. Technically, the Julian date is the number of days since the beginning of the Julian period. However, the value returned by the Julian() function is the number of the day of the year (eg January 1 is Julian day 1, February 1 is Julian day 32 etc). But the VMS Julian day is the number of days since November 17, 1858. Since I already calculated the timestamp for November 17, 1858 (it is 586,604,160,000,000,000 and defined by the VMS_Julian constant), we can simply subtract that value from the provided timestamp and then scale it by days. Unlike VMS whose earliest valid date is November 17, 1858, earlier dates could be specified by UOS, so it is possible to get a negative value (indicating the number of days before November 17, 1858).

Also of note is LIB_K_NANOSECOND_OF_SECOND, which is not in VMS, but included in UOS for a finer resolution on comparing times.

If the operation requested doesn't match one of the valid ones, we return an error. Otherwise, we write the result to the result address.

In the next article, we will look at the code for the SPAWN service.

 

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