?? TITLE := ' DF interfaces to fsp$open/close', EJECT ??
{
{ PURPOSE:
{    The purpose of this "module" is to provide simple interfaces between file
{    server procedures and fsp$open/close_file.
{

?? NEWTITLE := 'Global Declarations', EJECT ??

*copyc amp$fetch_access_information
*copyc amp$get_segment_pointer
*copyc amp$set_segment_position
*copyc cle$file_never_opened
*copyc fsp$close_file
*copyc fsp$open_file
*copyc osp$append_status_parameter
*copyc osp$set_status_abnormal

?? TITLE := '    dfp$fsp_open', EJECT ??

  PROCEDURE dfp$fsp_open
    (    local_file_name: amt$local_file_name;
         access_level: amt$access_level;
         read_not_write: boolean;
         open_for_attach: boolean;
         seq_and_free_behind: boolean;
         command_name: string ( * <= osc$max_name_size);
     VAR file_id: amt$file_identifier;
     VAR sequence_pointer: ^SEQ ( * );
     VAR sequence_size: amt$file_byte_address;
     VAR status: ost$status);

    VAR
      attribute_override: ^array [1 .. 3] of fst$file_cycle_attribute,
      fetch_access_selections: array [1 .. 1] of amt$access_info,
      file_attachment: ^array [ * ] of fst$attachment_option,
      file_creation: ^array [1 .. 1] of fst$file_cycle_attribute,
      ignore_status: ost$status,
      segment_pointer: amt$segment_pointer;

    status.normal := TRUE;

    IF open_for_attach THEN
      IF seq_and_free_behind THEN
        PUSH file_attachment: [1 .. 5];
        file_attachment^ [4].selector := fsc$sequential_access;
        file_attachment^ [4].sequential_access := TRUE;
        file_attachment^ [5].selector := fsc$free_behind;
        file_attachment^ [5].free_behind := TRUE;
      ELSE
        PUSH file_attachment: [1 .. 3];
      IFEND;

      file_attachment^ [1].selector := fsc$access_and_share_modes;
      file_attachment^ [1].access_modes.selector := fsc$specific_access_modes;
      file_attachment^ [1].share_modes.selector := fsc$specific_share_modes;
      file_attachment^ [2].selector := fsc$open_share_modes;
      IF read_not_write THEN
        file_attachment^ [1].access_modes.value :=
              $fst$file_access_options [fsc$read];
        file_attachment^ [1].share_modes.value :=
              $fst$file_access_options [fsc$read, fsc$execute];
        file_attachment^ [2].open_share_modes :=
              $fst$file_access_options [fsc$read, fsc$execute];
      ELSE
        file_attachment^ [1].access_modes.value :=
              $fst$file_access_options [fsc$read, fsc$append, fsc$shorten];
        file_attachment^ [1].share_modes.value := $fst$file_access_options [];
        file_attachment^ [2].open_share_modes :=
              $fst$file_access_options [fsc$read, fsc$execute];
      IFEND;
      file_attachment^ [3].selector := fsc$create_file;
      file_attachment^ [3].create_file := TRUE;
    ELSE
      file_attachment := NIL;
    IFEND;

    IF access_level = amc$segment THEN
      PUSH attribute_override;
      attribute_override^ [1].selector := fsc$block_type;
      attribute_override^ [1].block_type := amc$system_specified;
      attribute_override^ [2].selector := fsc$record_type;
      attribute_override^ [2].record_type := amc$undefined;
      attribute_override^ [3].selector := fsc$file_organization;
      attribute_override^ [3].file_organization := amc$sequential;
      file_creation := NIL;
    ELSE
      attribute_override := NIL;
      PUSH file_creation;
      file_creation^ [1].selector := fsc$ring_attributes;
      file_creation^ [1].ring_attributes.r1 := 11;
      file_creation^ [1].ring_attributes.r2 := 11;
      file_creation^ [1].ring_attributes.r3 := 11;
    IFEND;

    fsp$open_file (local_file_name, access_level, file_attachment,
          file_creation, {mandated_creation_attributes=} NIL,
          {attribute_vcalidation=}
          NIL, attribute_override, file_id, status);
    IF NOT status.normal THEN
      IF (status.condition = ame$new_file_requires_append) AND
            (read_not_write) THEN
        osp$set_status_abnormal ('CL', cle$file_never_opened, local_file_name,
              status);
        osp$append_status_parameter (osc$status_parameter_delimiter,
              command_name, status);
      IFEND;
      RETURN;
    IFEND;

    IF access_level = amc$segment THEN
      fetch_access_selections [1].key := amc$eoi_byte_address;
      amp$fetch_access_information (file_id, fetch_access_selections, status);
      IF NOT status.normal THEN
        fsp$close_file (file_id, ignore_status);
        RETURN;
      IFEND;
      amp$get_segment_pointer (file_id, amc$sequence_pointer, segment_pointer,
            status);
      IF status.normal THEN
        sequence_pointer := segment_pointer.sequence_pointer;
        sequence_size := fetch_access_selections [1].eoi_byte_address;
      ELSE
        fsp$close_file (file_id, ignore_status);
        RETURN;
      IFEND;
    ELSE
      sequence_pointer := NIL;
      sequence_size := 0;
    IFEND;

  PROCEND dfp$fsp_open;

?? TITLE := '    dfp$fsp_close', EJECT ??

  PROCEDURE dfp$fsp_close
    (    file_id: amt$file_identifier;
     VAR sequence_pointer: ^SEQ ( * );
     VAR status: ost$status);

    VAR
      segment_pointer: amt$segment_pointer;

    IF sequence_pointer <> NIL THEN
      segment_pointer.kind := amc$sequence_pointer;
      segment_pointer.sequence_pointer := sequence_pointer;
      amp$set_segment_position (file_id, segment_pointer, status);
    IFEND;

    fsp$close_file (file_id, status);

  PROCEND dfp$fsp_close;
?? OLDTITLE ??
?? OLDTITLE ??
?? EJECT ??

