" All PRODUCT_FILES have been loaded to the $LOCAL catalog with file names
" which match their tape file identifiers.  The ring attributes of each file
" is (3, 13, 13).  If a file's BLOCK_TYPE=SYSTEM_SPECIFIED and RECORD_TYPE=
" UNKNOWN, the file was assumed to be an object library and the load process
" set the FILE_CONTENT to OBJECT and FILE_STRUCTURE to LIBRARY.

VAR
  rav$attach_status  : status
  rav$ignore_status  : status
  rav$local_file     : file
  rav$permanent_file : file
VAREND

*IF $variable(rav$proc_doc,declared)<>'UNKNOWN'
"
" During the deadstart process, the builtin library, operator library
" and sou library were copied from the deadstart file to $LOCAL.
"
" The following code loads the builtin library, operator library and
" sou library from $LOCAL to their permanent locations.
" The load is performed unconditionally.
" The assumption is made that the version of these files on the deadstart file
" is the version which should be used in production.
"
" Each file is attached.  If the attach is successful, the load can be performed.
" If the attach is not successful, all known file cycles are deleted, and the
" load is performed.
"
" If the attach was successful (ie. permanent file cycles already exist), it
" is important that they not be deleted before the load.  This is to allow
" recovering jobs which have previously attached these files to re-access
" them using the path handle name assigned on the attach.  Deleting these
" files will remove the path handle name from the path handle table.
"
" The load will be made to cycle 999 of each file.
"
" During an initial deadstart, no file cycles will be found, and the attach
" will fail.  However, the ignore status on the delete command makes an
" attempted delete acceptable.
"
" If the file or disk is corrupted, an attempt is made to delete all
" known cycles prior to loading the files to their permanent locations.
"
*IFEND

" Install $LOCAL.BUILTIN_LIBRARY to $SYSTEM.OSF$BUILTIN_LIBRARY.999.

rav$local_file = $local.builtin_library
rav$permanent_file = $system.osf$builtin_library

$system.attach_file f=rav$permanent_file am=all sm=none status=rav$attach_status
IF NOT rav$attach_status.normal THEN
  TASK ring=3
    REPEAT
      $system.delete_file f=rav$permanent_file status=rav$ignore_status
    UNTIL NOT rav$ignore_status.normal
  TASKEND
  request_mass_storage file=rav$permanent_file.999 file_class=q
IFEND

$system.copy_file i=rav$local_file o=rav$permanent_file.999
$system.detach_file f=rav$local_file

$system.change_file_attributes f=rav$permanent_file.999 ra=(3 13 13)
$system.create_file_permit f=rav$permanent_file.999 g=public
$system.detach_file f=rav$permanent_file.999

" Install $LOCAL.OPERATOR_LIBRARY to $SYSTEM.OSF$OPERATOR_LIBRARY.999

rav$local_file = $local.operator_library
rav$permanent_file = $system.osf$operator_library

$system.attach_file f=rav$permanent_file am=all sm=none status=rav$attach_status
IF NOT rav$attach_status.normal THEN
  TASK ring=3
    REPEAT
      $system.delete_file f=rav$permanent_file status=rav$ignore_status
    UNTIL NOT rav$ignore_status.normal
  TASKEND
  request_mass_storage file=rav$permanent_file.999 file_class=q
IFEND

$system.copy_file i=rav$local_file o=rav$permanent_file.999
$system.detach_file f=rav$local_file

$system.change_file_attributes f=rav$permanent_file.999 ra=(3 13 13)
$system.detach_file f=rav$permanent_file.999

" Install $LOCAL.SOU_LIBRARY to $SYSTEM.OSF$SOU_LIBRARY.999.

rav$local_file = $local.sou_library
rav$permanent_file = $system.osf$sou_library

$system.attach_file f=rav$permanent_file am=all sm=none status=rav$attach_status
IF NOT rav$attach_status.normal THEN
  TASK ring=3
    REPEAT
      $system.delete_file f=rav$permanent_file status=rav$ignore_status
    UNTIL NOT rav$ignore_status.normal
  TASKEND
  request_mass_storage file=rav$permanent_file.999 file_class=q
IFEND

$system.copy_file i=rav$local_file o=rav$permanent_file.999
$system.detach_file f=rav$local_file

$system.change_file_attributes f=rav$permanent_file.999 ra=(3 13 13)
$system.create_file_permit f=rav$permanent_file.999 g=public
$system.detach_file f=rav$permanent_file.999

$system.delete_variable n=rav$ignore_status
$system.delete_variable n=rav$attach_status
$system.delete_variable n=rav$local_file
$system.delete_variable n=rav$permanent_file
