?? RIGHT := 110 ??
?? NEWTITLE := 'NOS/VE File Management : Tape Label Attributes Retrieval' ??
MODULE fmm$get_tape_label_attributes;

{ PURPOSE:
{   This module contains the procedures that will either get the tape label
{   attributes of the last ansi file accessed or those that will be applied to
{   the next ansi file.

?? NEWTITLE := 'Global Declarations Referenced by This Module', EJECT ??
?? PUSH (LISTEXT := ON) ??
*copyc ame$device_class_validation
*copyc ame$tape_program_actions
*copyc fme$file_management_errors
*copyc fst$ansi_eof1_label
*copyc fst$ansi_hdr1_label
*copyc fst$ansi_hdr2_label
*copyc fst$ansi_vol1_label
*copyc fst$attachment_options
*copyc fst$evaluated_file_reference
*copyc fst$tape_attribute_source
*copyc fst$tla_returned_attributes
*copyc ost$status
?? POP ??

*copyc bap$after_trailer_labels
*copyc bap$merge_tape_attributes
*copyc bap$next_position_is_bos
*copyc bap$set_evaluated_file_abnormal
*copyc clp$convert_file_ref_to_string
*copyc clp$convert_integer_to_rjstring
*copyc clp$convert_string_to_integer
*copyc fmp$adjust_file_set_pos_values
*copyc fmp$locate_cycle_description
*copyc fmp$lock_path_table
*copyc fmp$unlock_path_table
*copyc fsp$default_tape_label_attrib
*copyc fsp$expand_file_label
*copyc fsp$file_trailer_labels
*copyc fsp$locate_tape_label
*copyc fsp$path_element
*copyc fsp$version_two_tape_label
*copyc fsp$ve_wrote_ansi_file
*copyc i#move
*copyc osp$set_status_abnormal
*copyc pmp$get_user_identification

?? TITLE := 'fmp$get_tape_label_attributes', EJECT ??

  PROCEDURE [XDCL, #GATE] fmp$get_tape_label_attributes
    (    evaluated_file_reference: fst$evaluated_file_reference;
         source: fst$tape_attribute_source;
         rma_or_ring_privileged: boolean;
     VAR attributes {input, output} : fst$attachment_options;
     VAR returned_attributes: fst$tla_returned_attributes;
     VAR status: ost$status);

?? NEWTITLE := '  get_last_access_labels', EJECT ??

    PROCEDURE [INLINE] get_last_access_labels
      (VAR header_labels: ^SEQ ( * );
       VAR trailer_labels: ^SEQ ( * );
       VAR vol1_p: ^fst$ansi_vol1_label;
       VAR hdr1_p: ^fst$ansi_hdr1_label;
       VAR hdr2_p: ^fst$ansi_hdr2_label);

      VAR
        label_identifier: fst$tape_label_identifier,
        label_locator: fst$tape_label_locator;

      IF rma_or_ring_privileged THEN
        header_labels := tape_descriptor_p^.last_accessed.unsecured_header_labels;
        trailer_labels := tape_descriptor_p^.last_accessed.unsecured_trailer_labels;
      ELSE
        header_labels := tape_descriptor_p^.last_accessed.secured_header_labels;
        trailer_labels := tape_descriptor_p^.last_accessed.secured_trailer_labels;
      IFEND;

      IF header_labels = NIL THEN
        vol1_p := NIL;
        hdr1_p := NIL;
        hdr2_p := NIL;
        RETURN;
      IFEND;

      label_identifier.location_method := fsc$tape_label_locate_by_kind;
      label_identifier.label_kind := fsc$ansi_vol1_label_kind;
      fsp$locate_tape_label (header_labels, label_identifier, label_locator);
      IF label_locator.label_found THEN
        NEXT vol1_p IN label_locator.label_block;
      ELSE
        vol1_p := NIL;
      IFEND;

      label_identifier.label_kind := fsc$ansi_hdr1_label_kind;
      fsp$locate_tape_label (header_labels, label_identifier, label_locator);
      IF label_locator.label_found THEN
        NEXT hdr1_p IN label_locator.label_block;
      ELSE
        hdr1_p := NIL;
      IFEND;

      label_identifier.label_kind := fsc$ansi_hdr2_label_kind;
      fsp$locate_tape_label (header_labels, label_identifier, label_locator);
      IF label_locator.label_found THEN
        NEXT hdr2_p IN label_locator.label_block;
      ELSE
        hdr2_p := NIL;
      IFEND;

    PROCEND get_last_access_labels;
?? OLDTITLE ??
?? NEWTITLE := '  get_next_position_labels', EJECT ??

    PROCEDURE get_next_position_labels
      (VAR header_labels: ^SEQ ( * );
       VAR trailer_labels: ^SEQ ( * );
       VAR vol1_p: ^fst$ansi_vol1_label;
       VAR hdr1_p: ^fst$ansi_hdr1_label;
       VAR hdr2_p: ^fst$ansi_hdr2_label;
       VAR status: ost$status);

?? NEWTITLE := '    build_hdr1_block', EJECT ??

      PROCEDURE [INLINE] build_hdr1_block
        (VAR hdr1_p: ^fst$ansi_hdr1_label;
         VAR status: ost$status);

        VAR
          next_position_fsn: 0 .. 9999;

        NEXT hdr1_p IN header_labels;

        IF merged_attributes.file_identifier_source <> fsc$tape_label_attr_default THEN
          hdr1_p^.file_identifier := merged_attributes.file_identifier;
        ELSEIF (NOT bap$next_position_is_bos (merged_attributes.file_set_position, tape_descriptor_p,
              last_accessed_file_identifier, last_accessed_generation_number.value)) AND
              (last_accessed_file_identifier <> ' ') THEN
          hdr1_p^.file_identifier := last_accessed_file_identifier;
        ELSE
          hdr1_p^.file_identifier := fsp$path_element (^evaluated_file_reference,
                evaluated_file_reference.number_of_path_elements) ^;
        IFEND;

        IF bap$next_position_is_bos (merged_attributes.file_set_position, tape_descriptor_p,
              last_accessed_file_identifier, last_accessed_generation_number.value) THEN
          IF merged_attributes.file_set_identifier_source <> fsc$tape_label_attr_default THEN
            hdr1_p^.file_set_identifier := merged_attributes.file_set_identifier;
          ELSEIF initial_vol1_p <> NIL THEN
            IF (tape_descriptor_p^.next_position.file_section_number > 1) THEN
              IF initial_hdr1_p <> NIL THEN
                hdr1_p^.file_set_identifier := initial_hdr1_p^.file_set_identifier;
              IFEND;
            ELSE
              hdr1_p^.file_set_identifier := initial_vol1_p^.volume_identifier;
            IFEND;
          IFEND;
        ELSEIF initial_hdr1_p <> NIL THEN
          hdr1_p^.file_set_identifier := initial_hdr1_p^.file_set_identifier;
        IFEND;

        clp$convert_integer_to_rjstring (tape_descriptor_p^.next_position.file_section_number, 10, FALSE, '0',
              hdr1_p^.file_section_number, status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;

        next_position_fsn := 0;
        IF cycle_description^.global_file_information^.open_count <> 0 THEN
          next_position_fsn := tape_descriptor_p^.next_position.file_sequence_number;
        ELSEIF (merged_attributes.file_set_position.position = fsc$tape_beginning_of_set) OR
              (last_accessed_hdr1_p = NIL) THEN
          next_position_fsn := 1;
        ELSE
          CASE merged_attributes.file_set_position.position OF
          = fsc$tape_end_of_set =
            IF tape_descriptor_p^.labeled_volume_position = bac$lvp_end_of_file_set THEN
              next_position_fsn := tape_descriptor_p^.next_position.file_sequence_number;
            IFEND;
          = fsc$tape_current_file =
            IF bap$after_trailer_labels (tape_descriptor_p^.labeled_volume_position) THEN
              next_position_fsn := tape_descriptor_p^.next_position.file_sequence_number - 1;
            ELSE
              next_position_fsn := tape_descriptor_p^.next_position.file_sequence_number;
            IFEND;
          = fsc$tape_file_sequence_pos =
            IF (bap$after_trailer_labels (tape_descriptor_p^.labeled_volume_position) AND
                  ((tape_descriptor_p^.next_position.file_sequence_number - 1) =
                  merged_attributes.file_set_position.file_sequence_number)) OR
                  (tape_descriptor_p^.next_position.file_sequence_number =
                  merged_attributes.file_set_position.file_sequence_number) THEN
              next_position_fsn := merged_attributes.file_set_position.file_sequence_number;
            IFEND;
          = fsc$tape_next_file =
            IF bap$after_trailer_labels (tape_descriptor_p^.labeled_volume_position) THEN
              next_position_fsn := tape_descriptor_p^.next_position.file_sequence_number;
            ELSE
              next_position_fsn := tape_descriptor_p^.next_position.file_sequence_number + 1;
            IFEND;
          = fsc$tape_file_identifier_pos =
            IF (merged_attributes.file_set_position.file_identifier =
                  last_accessed_file_identifier) AND (merged_attributes.file_set_position.
                  generation_number = last_accessed_generation_number.value) THEN
              IF bap$after_trailer_labels (tape_descriptor_p^.labeled_volume_position) THEN
                next_position_fsn := tape_descriptor_p^.next_position.file_sequence_number - 1;
              ELSE
                next_position_fsn := tape_descriptor_p^.next_position.file_sequence_number;
              IFEND;
            IFEND;
          ELSE
          CASEND;
        IFEND;
        IF next_position_fsn = 0 THEN
          hdr1_p^.file_sequence_number := ' ';
        ELSE
          clp$convert_integer_to_rjstring (next_position_fsn, 10, FALSE, '0', hdr1_p^.file_sequence_number,
                status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        IFEND;

        IF merged_attributes.generation_number_source <> fsc$tape_label_attr_default THEN
          clp$convert_integer_to_rjstring (merged_attributes.generation_number, 10, FALSE, '0',
                hdr1_p^.generation_number, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        ELSEIF (NOT bap$next_position_is_bos (merged_attributes.file_set_position, tape_descriptor_p,
              last_accessed_file_identifier, last_accessed_generation_number.value)) AND
              (last_accessed_hdr1_p <> NIL) THEN
          hdr1_p^.generation_number := last_accessed_hdr1_p^.generation_number;
        IFEND;

        IF merged_attributes.generation_version_num_source <> fsc$tape_label_attr_default THEN
          clp$convert_integer_to_rjstring (merged_attributes.generation_version_number, 10, FALSE, '0',
                hdr1_p^.generation_version_number, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        ELSEIF (NOT bap$next_position_is_bos (merged_attributes.file_set_position, tape_descriptor_p,
              last_accessed_file_identifier, last_accessed_generation_number.value)) AND
              (last_accessed_hdr1_p <> NIL) THEN
          hdr1_p^.generation_version_number := last_accessed_hdr1_p^.generation_version_number;
        IFEND;

        IF merged_attributes.creation_date_source <> fsc$tape_label_attr_default THEN
          IF merged_attributes.creation_date (1, 1) = '2' THEN
            hdr1_p^.creation_date (1, 1) := merged_attributes.creation_date (2, 1);
          IFEND;
          hdr1_p^.creation_date (2, 5) := merged_attributes.creation_date (3, 5);
        IFEND;

        IF merged_attributes.expiration_date_source <> fsc$tape_label_attr_default THEN
          IF merged_attributes.expiration_date (1, 1) = '2' THEN
            hdr1_p^.expiration_date (1, 1) := merged_attributes.expiration_date (2, 1);
          IFEND;
          hdr1_p^.expiration_date (2, 5) := merged_attributes.expiration_date (3, 5);
        IFEND;

        IF rma_or_ring_privileged THEN
          IF (merged_attributes.file_accessibility_source <> fsc$tape_label_attr_default) AND
                bap$next_position_is_bos (merged_attributes.file_set_position, tape_descriptor_p,
                last_accessed_file_identifier, last_accessed_generation_number.value) AND
                ((initial_hdr1_p = NIL) OR (initial_hdr1_p^.accessibility = ' ')) THEN
            hdr1_p^.accessibility := merged_attributes.file_accessibility;
          ELSEIF initial_hdr1_p <> NIL THEN
            hdr1_p^.accessibility := initial_hdr1_p^.accessibility;
          IFEND;
        ELSE
          hdr1_p^.accessibility := ' ';
        IFEND;

        IF (initial_hdr1_p <> NIL) AND fsp$ve_wrote_ansi_file (initial_hdr1_p^.system_code) THEN
          hdr1_p^.system_code := initial_hdr1_p^.system_code;
        IFEND;

      PROCEND build_hdr1_block;
?? OLDTITLE ??
?? NEWTITLE := '    build_hdr2_block', EJECT ??

      PROCEDURE [INLINE] build_hdr2_block
        (VAR hdr2_p: ^fst$ansi_hdr2_label;
         VAR status: ost$status);

        VAR
          block_length: string (8),
          initial_hdr2_p: ^fst$ansi_hdr2_label,
          initial_sequence_header_p: ^fst$tape_label_sequence_header,
          last_accessed_hdr2_p: ^fst$ansi_hdr2_label,
          record_length: string (8);

        NEXT hdr2_p IN header_labels;

        label_identifier.location_method := fsc$tape_label_locate_by_kind;
        label_identifier.label_kind := fsc$ansi_hdr2_label_kind;
        fsp$locate_tape_label (last_accessed_labels, label_identifier, label_locator);
        IF label_locator.label_found THEN
          NEXT last_accessed_hdr2_p IN label_locator.label_block;
        ELSE
          last_accessed_hdr2_p := NIL;
        IFEND;
        fsp$locate_tape_label (tape_descriptor_p^.initial_volume.header_labels, label_identifier,
              label_locator);
        IF label_locator.label_found THEN
          NEXT initial_hdr2_p IN label_locator.label_block;
        ELSE
          initial_hdr2_p := NIL;
        IFEND;

        CASE merged_attributes.record_type OF
        = amc$ansi_fixed =
          hdr2_p^.record_format := 'F';
        = amc$ansi_spanned =
          hdr2_p^.record_format := 'S';
        = amc$ansi_variable =
          hdr2_p^.record_format := 'D';
        ELSE
        CASEND;

        clp$convert_integer_to_rjstring (merged_attributes.max_block_length, 10, FALSE, '0', block_length,
              status);
        IF NOT status.normal THEN
          RETURN;
        IFEND;
        hdr2_p^.block_length := block_length (4, 5);
        hdr2_p^.ve_block_length_ext := block_length (1, 3);

        IF hdr2_p^.record_format = 'D' THEN
          hdr2_p^.record_length := '99999';
          hdr2_p^.ve_record_length_ext := '000';
        ELSEIF hdr2_p^.record_format = 'S' THEN
          hdr2_p^.record_length := '00000';
          hdr2_p^.ve_record_length_ext := '000';
        ELSE
          clp$convert_integer_to_rjstring (merged_attributes.max_record_length, 10, FALSE, '0', record_length,
                status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
          hdr2_p^.record_length := record_length (4, 5);
          hdr2_p^.ve_record_length_ext := record_length (1, 3);
        IFEND;

        IF merged_attributes.block_type = amc$system_specified THEN
          hdr2_p^.ve_block_type := 'SS';
        ELSE
          hdr2_p^.ve_block_type := 'US';
        IFEND;

        CASE merged_attributes.record_type OF
        = amc$variable =
          hdr2_p^.ve_record_type := 'V';
        = amc$undefined =
          hdr2_p^.ve_record_type := 'U';
        = amc$ansi_fixed =
          hdr2_p^.ve_record_type := 'F';
        = amc$ansi_spanned =
          hdr2_p^.ve_record_type := 'S';
        = amc$ansi_variable =
          hdr2_p^.ve_record_type := 'D';
        ELSE
        CASEND;

        hdr2_p^.ve_padding_character := merged_attributes.padding_character;

        IF (bap$next_position_is_bos (merged_attributes.file_set_position, tape_descriptor_p,
              last_accessed_file_identifier, last_accessed_generation_number.value) OR
              (tape_descriptor_p^.file_label_type = amc$unlabeled)) AND
              (merged_attributes.character_set_source <> fsc$tape_label_attr_default) THEN
          header_labels_seq_hdr^.character_set := merged_attributes.character_set;
        ELSEIF tape_descriptor_p^.initial_volume.header_labels <> NIL THEN
          RESET tape_descriptor_p^.initial_volume.header_labels;
          NEXT initial_sequence_header_p IN tape_descriptor_p^.initial_volume.header_labels;
          header_labels_seq_hdr^.character_set := initial_sequence_header_p^.character_set;
        IFEND;
        IF header_labels_seq_hdr^.character_set = amc$ascii THEN
          hdr2_p^.ve_character_set := 'A';
        ELSE
          hdr2_p^.ve_character_set := 'E';
        IFEND;

        IF merged_attributes.character_conversion THEN
          hdr2_p^.ve_character_conversion := 'T';
        ELSE
          hdr2_p^.ve_character_conversion := 'F';
        IFEND;

      PROCEND build_hdr2_block;
?? OLDTITLE ??
?? NEWTITLE := '    build_vol1_block', EJECT ??

      PROCEDURE [INLINE] build_vol1_block
        (VAR vol1_p: ^fst$ansi_vol1_label;
         VAR status: ost$status);

        VAR
          last_accessed_vol1_p: ^fst$ansi_vol1_label;

        NEXT vol1_p IN header_labels;
        IF initial_vol1_p <> NIL THEN
          vol1_p^ := initial_vol1_p^;
          label_identifier.location_method := fsc$tape_label_locate_by_kind;
          label_identifier.label_kind := fsc$ansi_vol1_label_kind;
          fsp$locate_tape_label (last_accessed_labels, label_identifier, label_locator);
          IF label_locator.label_found THEN
            NEXT last_accessed_vol1_p IN label_locator.label_block;
            vol1_p^.volume_identifier := last_accessed_vol1_p^.volume_identifier;
          IFEND;

          IF rma_or_ring_privileged THEN
            pmp$get_user_identification (user_id, status);
            IF NOT status.normal THEN
              RETURN;
            IFEND;
            IF bap$next_position_is_bos (merged_attributes.file_set_position, tape_descriptor_p,
                  last_accessed_file_identifier, last_accessed_generation_number.value) AND
                  (initial_vol1_p^.accessibility = ' ') THEN
              IF merged_attributes.volume_accessibility_source = fsc$tape_label_attr_default THEN
                IF ((initial_hdr1_p <> NIL) AND (fsp$version_two_tape_label (initial_hdr1_p^.system_code) OR
                      (NOT fsp$ve_wrote_ansi_file (initial_hdr1_p^.system_code) AND
                      tape_descriptor_p^.initial_volume.classification.labeled.blank))) OR
                      ((initial_hdr1_p = NIL) AND (tape_descriptor_p^.initial_volume.classification.labeled.
                      blank OR fsp$version_two_tape_label (initial_vol1_p^.implementation_identifier))) THEN
                  IF (initial_vol1_p^.owner_identifier = ' ') OR (initial_vol1_p^.owner_identifier =
                        user_id.user (1, 14)) THEN
                    vol1_p^.accessibility := 'A';
                  IFEND;
                IFEND;
              ELSE
                vol1_p^.accessibility := merged_attributes.volume_accessibility;
              IFEND;
            IFEND;

            IF bap$next_position_is_bos (merged_attributes.file_set_position, tape_descriptor_p,
                  last_accessed_file_identifier, last_accessed_generation_number.value) AND
                  (initial_vol1_p^.owner_identifier = ' ') THEN
              IF ((initial_hdr1_p <> NIL) AND (vol1_p^.accessibility = 'A') AND
                    (fsp$version_two_tape_label (initial_hdr1_p^.system_code) OR
                    (NOT fsp$ve_wrote_ansi_file (initial_hdr1_p^.system_code) AND
                    tape_descriptor_p^.initial_volume.classification.labeled.blank))) OR
                    ((initial_hdr1_p = NIL) AND (tape_descriptor_p^.initial_volume.classification.labeled.
                    blank OR fsp$version_two_tape_label (initial_vol1_p^.implementation_identifier))) THEN
                IF merged_attributes.removable_media_group_source <> fsc$tape_label_attr_default THEN
                  vol1_p^.owner_identifier (1, 1) := '&';
                  vol1_p^.owner_identifier (2, 13) := merged_attributes.removable_media_group;
                ELSE
                  vol1_p^.owner_identifier := user_id.user (1, 14);
                IFEND;
              ELSEIF merged_attributes.owner_identifier_source <> fsc$tape_label_attr_default THEN
                vol1_p^.owner_identifier := merged_attributes.owner_identifier;
              IFEND;
            IFEND;
          ELSE { not rma_or_ring_privileged }
            vol1_p^.accessibility := ' ';
            vol1_p^.owner_identifier := ' ';
          IFEND;
        ELSE { tape labels have not yet been read }
          IF rma_or_ring_privileged THEN
            IF merged_attributes.volume_accessibility_source <> fsc$tape_label_attr_default THEN
              vol1_p^.accessibility := merged_attributes.volume_accessibility;
            IFEND;
            IF merged_attributes.owner_identifier_source <> fsc$tape_label_attr_default THEN
              vol1_p^.owner_identifier := merged_attributes.owner_identifier;
            ELSEIF merged_attributes.removable_media_group_source <> fsc$tape_label_attr_default THEN
              vol1_p^.owner_identifier (1, 1) := '&';
              vol1_p^.owner_identifier (2, 13) := merged_attributes.removable_media_group;
            IFEND;
          ELSE { not rma_or_ring_privileged }
            vol1_p^.accessibility := ' ';
          IFEND;

          IF merged_attributes.system_code_source <> fsc$tape_label_attr_default THEN
            vol1_p^.label_standard_version := merged_attributes.label_standard_version;
          IFEND;
        IFEND;

      PROCEND build_vol1_block;
?? OLDTITLE, EJECT ??

      VAR
        block_descriptor: ^fst$tape_label_block_descriptor,
        block_number: fst$tape_label_count,
        eof1_p: ^fst$ansi_eof1_label,
        eof2_p: ^fst$ansi_eof2_label,
        header_labels_seq_hdr: ^fst$tape_label_sequence_header,
        initial_hdr1_p: ^fst$ansi_hdr1_label,
        initial_vol1_p: ^fst$ansi_vol1_label,
        label_identifier: fst$tape_label_identifier,
        label_locator: fst$tape_label_locator,
        last_accessed_file_identifier: string (17),
        last_accessed_generation_number: clt$integer,
        last_accessed_hdr1_p: ^fst$ansi_hdr1_label,
        last_accessed_hdr2_p: ^fst$ansi_hdr2_label,
        last_accessed_labels: ^SEQ ( * ),
        trailer_labels_seq_hdr: ^fst$tape_label_sequence_header,
        user_id: ost$user_identification;

      RESET header_labels;
      NEXT header_labels_seq_hdr IN header_labels;

      IF rma_or_ring_privileged THEN
        last_accessed_labels := tape_descriptor_p^.last_accessed.unsecured_header_labels;
      ELSE
        last_accessed_labels := tape_descriptor_p^.last_accessed.secured_header_labels;
      IFEND;

{ Build header labels

      label_identifier.location_method := fsc$tape_label_locate_by_kind;
      label_identifier.label_kind := fsc$ansi_vol1_label_kind;
      fsp$locate_tape_label (tape_descriptor_p^.initial_volume.header_labels, label_identifier,
            label_locator);
      IF label_locator.label_found THEN
        NEXT initial_vol1_p IN label_locator.label_block;
      ELSE
        initial_vol1_p := NIL;
      IFEND;

      label_identifier.label_kind := fsc$ansi_hdr1_label_kind;
      fsp$locate_tape_label (tape_descriptor_p^.initial_volume.header_labels, label_identifier,
            label_locator);
      IF label_locator.label_found THEN
        NEXT initial_hdr1_p IN label_locator.label_block;
      ELSE
        initial_hdr1_p := NIL;
      IFEND;

      label_identifier.location_method := fsc$tape_label_locate_by_kind;
      label_identifier.label_kind := fsc$ansi_hdr1_label_kind;
      fsp$locate_tape_label (last_accessed_labels, label_identifier, label_locator);
      IF label_locator.label_found THEN
        NEXT last_accessed_hdr1_p IN label_locator.label_block;
        last_accessed_file_identifier := last_accessed_hdr1_p^.file_identifier;
        IF last_accessed_hdr1_p^.generation_number <> ' ' THEN
          clp$convert_string_to_integer (last_accessed_hdr1_p^.generation_number,
                last_accessed_generation_number, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        ELSE
          last_accessed_generation_number.value := 1;
        IFEND;
      ELSE
        last_accessed_hdr1_p := NIL;
        last_accessed_file_identifier := ' ';
        last_accessed_generation_number.value := 1;
      IFEND;

      fmp$adjust_file_set_pos_values (merged_attributes);

{ Adjust max block length value

      IF merged_attributes.block_type = amc$system_specified THEN
        IF tape_descriptor_p^.requested_density = rmc$38000 THEN
          merged_attributes.max_block_length := 32640;
        ELSE
          merged_attributes.max_block_length := 4128;
        IFEND;
      IFEND;

{ It is assumed that the header labels returned by fsp$default_tape_label_attrib includes a
{ VOL1, HDR1, HDR2, and a single tapemark, in sequence.

      FOR block_number := 1 TO header_labels_seq_hdr^.label_count - 1 DO
        NEXT block_descriptor IN header_labels;
        CASE block_descriptor^.normal_label_kind OF
        = fsc$ansi_vol1_label_kind =
          build_vol1_block (vol1_p, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        = fsc$ansi_hdr1_label_kind =
          build_hdr1_block (hdr1_p, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        = fsc$ansi_hdr2_label_kind =
          build_hdr2_block (hdr2_p, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;
        ELSE
        CASEND;
      FOREND;

{ Build trailer labels

      RESET trailer_labels;
      NEXT trailer_labels_seq_hdr IN trailer_labels;
      trailer_labels_seq_hdr^.character_set := header_labels_seq_hdr^.character_set;

      label_identifier.location_method := fsc$tape_label_locate_by_kind;
      label_identifier.label_kind := fsc$ansi_eof1_label_kind;
      fsp$locate_tape_label (trailer_labels, label_identifier, label_locator);
      IF label_locator.label_found THEN
        NEXT eof1_p IN label_locator.label_block;
      IFEND;

      label_identifier.label_kind := fsc$ansi_eof2_label_kind;
      fsp$locate_tape_label (trailer_labels, label_identifier, label_locator);
      IF label_locator.label_found THEN
        NEXT eof2_p IN label_locator.label_block;
      IFEND;

      eof1_p^ := hdr1_p^;
      eof2_p^ := hdr2_p^;
      IF cycle_description^.global_file_information^.open_count <> 0 THEN
        IF last_accessed_hdr1_p <> NIL THEN
          eof1_p^ := last_accessed_hdr1_p^;
        IFEND;

        label_identifier.label_kind := fsc$ansi_hdr2_label_kind;
        fsp$locate_tape_label (last_accessed_labels, label_identifier, label_locator);
        IF label_locator.label_found THEN
          NEXT last_accessed_hdr2_p IN label_locator.label_block;
          eof2_p^ := last_accessed_hdr2_p^;
        IFEND;
      IFEND;

      eof1_p^.label_identifier := 'EOF';
      eof2_p^.label_identifier := 'EOF';

    PROCEND get_next_position_labels;
?? OLDTITLE, EJECT ??

    VAR
      attachment_option: fst$file_attachment_choices,
      cycle_description: ^fmt$cycle_description,
      default_attributes: array [1 .. 2] of fst$attachment_option,
      eof1_eov1_p: ^fst$ansi_eof1_label,
      hdr1_p: ^fst$ansi_hdr1_label,
      hdr2_p: ^fst$ansi_hdr2_label,
      ignore_file_previously_opened: boolean,
      int: clt$integer,
      header_labels: ^SEQ ( * ),
      label_identifier: fst$tape_label_identifier,
      label_locator: fst$tape_label_locator,
      last_accessed_hdr1_p: ^fst$ansi_hdr1_label, {used by get_next_position_labels and figuring by_name fsn}
      length: string (8),
      local_evaluated_file_reference: fst$evaluated_file_reference,
      merged_attributes: fst$tape_attachment_information,
      path_table_locked: boolean,
      returned_default_attributes: fst$tla_returned_attributes,
      sequence_header: ^fst$tape_label_sequence_header,
      setfa_attributes: bat$static_label_attributes,
      tape_descriptor_p: ^bat$tape_descriptor,
      trailer_labels: ^SEQ ( * ),
      use_hdr1_fsn: boolean,
      vol1_p: ^fst$ansi_vol1_label;

    status.normal := TRUE;
    local_evaluated_file_reference := evaluated_file_reference;
    fmp$locate_cycle_description (local_evaluated_file_reference, cycle_description, status);

    path_table_locked := status.normal;
    IF NOT status.normal THEN
      IF status.condition = fme$no_cycle_description THEN
        cycle_description := NIL;
        status.normal := TRUE;
      ELSE
        RETURN;
      IFEND;
    IFEND;

  /get_attributes/
    BEGIN
      IF (cycle_description = NIL) OR NOT cycle_description^.attached_file THEN
        bap$set_evaluated_file_abnormal (evaluated_file_reference, ame$file_attachment_required,
              'FSP$GET_TAPE_LABEL_ATTRIBUTES', '', status);
        EXIT /get_attributes/;
      IFEND;

      IF cycle_description^.device_class <> rmc$magnetic_tape_device THEN
        bap$set_evaluated_file_abnormal (evaluated_file_reference, ame$improper_device_class,
              'FSP$GET_TAPE_LABEL_ATTRIBUTES', 'MASS_STORAGE/NULL/TERMINAL', status);
        EXIT /get_attributes/;
      IFEND;

      returned_attributes := $fst$tla_returned_attributes [];

      IF cycle_description^.global_file_information^.device_dependent_info.tape_descriptor <> NIL THEN
        RESET cycle_description^.global_file_information^.device_dependent_info.tape_descriptor;
        NEXT tape_descriptor_p IN cycle_description^.global_file_information^.device_dependent_info.
              tape_descriptor;
        IF tape_descriptor_p = NIL THEN
          osp$set_status_abnormal ('FM', fme$system_error, ' NIL tape_descriptor IN fmp$get_attributes',
                status);
          EXIT /get_attributes/;
        IFEND;

        IF cycle_description^.global_file_information^.open_count = 0 THEN
          merged_attributes := tape_descriptor_p^.tape_label_attr_command_info;
          IF cycle_description^.static_setfa_entries <> NIL THEN
            fsp$expand_file_label (cycle_description^.static_setfa_entries, setfa_attributes,
                  ignore_file_previously_opened, status);
            IF NOT status.normal THEN
              EXIT /get_attributes/;
            IFEND;
            bap$merge_tape_attributes (NIL, NIL, merged_attributes, setfa_attributes);
          IFEND;
        ELSE
          merged_attributes := tape_descriptor_p^.tape_attachment_information;
        IFEND;

        IF source = fsc$tla_last_ansi_file_accessed THEN
          get_last_access_labels (header_labels, trailer_labels, vol1_p, hdr1_p, hdr2_p);
          IF (header_labels = NIL) AND (trailer_labels = NIL) THEN
            EXIT /get_attributes/;
          IFEND;
        ELSE { fsc$tla_next_position }
          default_attributes [1].selector := fsc$tape_attachment;
          default_attributes [1].tape_attachment.selector := fsc$tape_header_labels;
          PUSH default_attributes [1].tape_attachment.tape_header_labels:
                [[REP 1 OF fst$tape_label_sequence_header, REP 4 OF fst$tape_label_block_descriptor,
                REP 1 OF fst$ansi_vol1_label, REP 1 OF fst$ansi_hdr1_label, REP 1 OF fst$ansi_hdr2_label]];
          default_attributes [2].selector := fsc$tape_attachment;
          default_attributes [2].tape_attachment.selector := fsc$tape_trailer_labels;
          PUSH default_attributes [2].tape_attachment.tape_trailer_labels:
                [[REP 1 OF fst$tape_label_sequence_header, REP 4 OF fst$tape_label_block_descriptor,
                REP 1 OF fst$ansi_eof1_label, REP 1 OF fst$ansi_eof2_label]];
          fsp$default_tape_label_attrib (fsc$tla_system_default, default_attributes,
                returned_default_attributes, status);
          IF NOT status.normal THEN
            RETURN;
          IFEND;

          header_labels := default_attributes [1].tape_attachment.tape_header_labels;
          trailer_labels := default_attributes [2].tape_attachment.tape_trailer_labels;

          get_next_position_labels (header_labels, trailer_labels, vol1_p, hdr1_p, hdr2_p, status);
          IF NOT status.normal THEN
            EXIT /get_attributes/;
          IFEND;
        IFEND;

        FOR attachment_option := 1 TO UPPERBOUND (attributes) DO
          IF attributes [attachment_option].selector = fsc$tape_attachment THEN
            CASE attributes [attachment_option].tape_attachment.selector OF
            = fsc$tape_block_count =
              IF trailer_labels <> NIL THEN
                RESET trailer_labels;
                NEXT sequence_header IN trailer_labels;
                label_identifier.location_method := fsc$tape_label_locate_by_kind;
                IF fsp$file_trailer_labels (sequence_header^.label_kinds) THEN
                  label_identifier.label_kind := fsc$ansi_eof1_label_kind;
                ELSE
                  label_identifier.label_kind := fsc$ansi_eov1_label_kind;
                IFEND;
                fsp$locate_tape_label (trailer_labels, label_identifier, label_locator);
                IF label_locator.label_found THEN
                  NEXT eof1_eov1_p IN label_locator.label_block;
                  IF eof1_eov1_p^.block_count <> ' ' THEN
                    clp$convert_string_to_integer (eof1_eov1_p^.block_count, int, status);
                    IF NOT status.normal THEN
                      EXIT /get_attributes/;
                    IFEND;
                    attributes [attachment_option].tape_attachment.tape_block_count := int.value;
                    returned_attributes := returned_attributes + $fst$tla_returned_attributes
                          [attributes [attachment_option].tape_attachment.selector];
                  IFEND;
                IFEND;
              IFEND;

            = fsc$tape_block_type =
              IF hdr1_p <> NIL THEN
                IF fsp$ve_wrote_ansi_file (hdr1_p^.system_code) THEN
                  IF (hdr2_p <> NIL) AND (hdr2_p^.ve_block_type <> ' ') THEN
                    IF hdr2_p^.ve_block_type = 'SS' THEN
                      attributes [attachment_option].tape_attachment.tape_block_type := amc$system_specified;
                    ELSE { US }
                      attributes [attachment_option].tape_attachment.tape_block_type := amc$user_specified;
                    IFEND;
                    returned_attributes := returned_attributes + $fst$tla_returned_attributes
                          [attributes [attachment_option].tape_attachment.selector];
                  IFEND;
                ELSE
                  attributes [attachment_option].tape_attachment.tape_block_type := amc$user_specified;
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                IFEND;
              ELSEIF hdr2_p <> NIL THEN
                attributes [attachment_option].tape_attachment.tape_block_type := amc$user_specified;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;
              IF NOT (fsc$tape_block_type IN returned_attributes) AND
                    (source = fsc$tla_last_ansi_file_accessed) AND
                    (cycle_description^.global_file_information^.open_count > 0) THEN
                attributes [attachment_option].tape_attachment.tape_block_type :=
                      merged_attributes.block_type;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_buffer_offset =
              IF (hdr2_p <> NIL) AND (hdr2_p^.buffer_offset_length <> ' ') THEN
                clp$convert_string_to_integer (hdr2_p^.buffer_offset_length, int, status);
                IF NOT status.normal THEN
                  EXIT /get_attributes/;
                IFEND;
                attributes [attachment_option].tape_attachment.tape_buffer_offset := int.value;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_character_conversion =
              IF (hdr1_p <> NIL) AND fsp$ve_wrote_ansi_file (hdr1_p^.system_code) AND (hdr2_p <> NIL) AND
                    (hdr2_p^.ve_character_conversion <> ' ') THEN
                attributes [attachment_option].tape_attachment.tape_character_conversion :=
                      hdr2_p^.ve_character_conversion = 'T';
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              ELSEIF (source = fsc$tla_last_ansi_file_accessed) AND
                    (cycle_description^.global_file_information^.open_count > 0) THEN
                attributes [attachment_option].tape_attachment.tape_character_conversion :=
                      merged_attributes.character_conversion;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_character_set =
              IF (hdr2_p <> NIL) AND (hdr2_p^.ve_character_set <> ' ') THEN
                IF hdr2_p^.ve_character_set = 'A' THEN
                  attributes [attachment_option].tape_attachment.tape_character_set := amc$ascii;
                ELSE
                  attributes [attachment_option].tape_attachment.tape_character_set := amc$ebcdic;
                IFEND;
              ELSE
                NEXT sequence_header IN header_labels;
                attributes [attachment_option].tape_attachment.tape_character_set :=
                      sequence_header^.character_set;
              IFEND;
              returned_attributes := returned_attributes + $fst$tla_returned_attributes
                    [attributes [attachment_option].tape_attachment.selector];

            = fsc$tape_creation_date =
              IF (hdr1_p <> NIL) AND (hdr1_p^.creation_date <> ' ') THEN
                IF hdr1_p^.creation_date (1, 1) = ' ' THEN
                  attributes [attachment_option].tape_attachment.tape_creation_date (1, 2) := '19';
                ELSE
                  attributes [attachment_option].tape_attachment.tape_creation_date (1, 1) := '2';
                  attributes [attachment_option].tape_attachment.tape_creation_date (2, 1) :=
                        hdr1_p^.creation_date (1, 1);
                IFEND;
                attributes [attachment_option].tape_attachment.tape_creation_date (3, 5) :=
                      hdr1_p^.creation_date (2, 5);
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_expiration_date =
              IF (hdr1_p <> NIL) AND (hdr1_p^.expiration_date <> ' ') THEN
                IF hdr1_p^.expiration_date (1, 1) = ' ' THEN
                  IF hdr1_p^.expiration_date (2, 5) = '00000' THEN
                    attributes [attachment_option].tape_attachment.tape_expiration_date (1, 2) := '  ';
                  ELSE
                    attributes [attachment_option].tape_attachment.tape_expiration_date (1, 2) := '19';
                  IFEND;
                  attributes [attachment_option].tape_attachment.tape_expiration_date (3, 5) :=
                        hdr1_p^.expiration_date (2, 5);
                ELSE
                  attributes [attachment_option].tape_attachment.tape_expiration_date (1, 1) := '2';
                  attributes [attachment_option].tape_attachment.tape_expiration_date (2, 6) :=
                        hdr1_p^.expiration_date (1, 6);
                IFEND;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_file_accessibility =
              IF rma_or_ring_privileged THEN
                IF hdr1_p <> NIL THEN
                  attributes [attachment_option].tape_attachment.tape_file_accessibility :=
                        hdr1_p^.accessibility;
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                IFEND;
              ELSE
                bap$set_evaluated_file_abnormal (evaluated_file_reference, ame$security_conflict, '',
                      'FILE_ACCESSIBILITY', status);
                EXIT /get_attributes/;
              IFEND;

            = fsc$tape_file_identifier =
              IF hdr1_p <> NIL THEN
                attributes [attachment_option].tape_attachment.tape_file_identifier :=
                      hdr1_p^.file_identifier;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_file_section_number =
              IF hdr1_p <> NIL THEN
                clp$convert_string_to_integer (hdr1_p^.file_section_number, int, status);
                IF NOT status.normal THEN
                  EXIT /get_attributes/;
                IFEND;
                attributes [attachment_option].tape_attachment.tape_file_section_number := int.value;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_file_sequence_number =
              IF source = fsc$tla_last_ansi_file_accessed THEN
                IF hdr1_p <> NIL THEN
                  IF hdr1_p^.file_sequence_number <> ' ' THEN
                    clp$convert_string_to_integer (hdr1_p^.file_sequence_number, int, status);
                    IF NOT status.normal THEN
                      EXIT /get_attributes/;
                    IFEND;
                    use_hdr1_fsn := (tape_descriptor_p^.next_position.file_sequence_number - int.value) <= 1;
                  ELSE
                    use_hdr1_fsn := FALSE;
                  IFEND;
                  IF use_hdr1_fsn THEN
                    attributes [attachment_option].tape_attachment.tape_file_sequence_number := int.value;
                  ELSEIF bap$after_trailer_labels (tape_descriptor_p^.labeled_volume_position) AND
                        (tape_descriptor_p^.next_position.file_sequence_number > 1) THEN
                    attributes [attachment_option].tape_attachment.tape_file_sequence_number :=
                          tape_descriptor_p^.next_position.file_sequence_number - 1;
                  ELSE
                    attributes [attachment_option].tape_attachment.tape_file_sequence_number :=
                          tape_descriptor_p^.next_position.file_sequence_number;
                  IFEND;
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                IFEND;
              ELSE { next_position }
                IF hdr1_p^.file_sequence_number <> ' ' THEN
                  clp$convert_string_to_integer (hdr1_p^.file_sequence_number, int, status);
                  IF NOT status.normal THEN
                    EXIT /get_attributes/;
                  IFEND;
                  attributes [attachment_option].tape_attachment.tape_file_sequence_number := int.value;
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                IFEND;
              IFEND;

            = fsc$tape_file_set_identifier =
              IF hdr1_p <> NIL THEN
                attributes [attachment_option].tape_attachment.tape_file_set_identifier :=
                      hdr1_p^.file_set_identifier;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_file_set_position =
              IF source = fsc$tla_next_position THEN
                attributes [attachment_option].tape_attachment.tape_file_set_position :=
                      merged_attributes.file_set_position;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_generation_number =
              IF (hdr1_p <> NIL) AND (hdr1_p^.generation_number <> ' ') THEN
                clp$convert_string_to_integer (hdr1_p^.generation_number, int, status);
                IF NOT status.normal THEN
                  EXIT /get_attributes/;
                IFEND;
                attributes [attachment_option].tape_attachment.tape_generation_number := int.value;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_generation_version_num =
              IF (hdr1_p <> NIL) AND (hdr1_p^.generation_version_number <> ' ') THEN
                clp$convert_string_to_integer (hdr1_p^.generation_version_number, int, status);
                IF NOT status.normal THEN
                  EXIT /get_attributes/;
                IFEND;
                attributes [attachment_option].tape_attachment.tape_generation_version_num := int.value;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_header_labels =
              IF (attributes [attachment_option].tape_attachment.tape_header_labels <> NIL) AND
                    (header_labels <> NIL) THEN
                IF #SIZE (attributes [attachment_option].tape_attachment.tape_header_labels^) >=
                      #SIZE (header_labels^) THEN
                  i#move (header_labels, attributes [attachment_option].tape_attachment.
                        tape_header_labels, #SIZE (header_labels^));
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                ELSEIF #SIZE (attributes [attachment_option].tape_attachment.tape_header_labels^) >=
                      #SIZE (fst$tape_label_sequence_header) THEN
                  i#move (header_labels, attributes [attachment_option].tape_attachment.
                        tape_header_labels, #SIZE (fst$tape_label_sequence_header));
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                  bap$set_evaluated_file_abnormal (evaluated_file_reference, ame$only_seq_header_returned,
                        'FSP$GET_TAPE_LABEL_ATTRIBUTES', 'HEADER', status);
                ELSE
                  bap$set_evaluated_file_abnormal (evaluated_file_reference, ame$label_sequence_too_small,
                        'FSP$GET_TAPE_LABEL_ATTRIBUTES', 'HEADER', status);
                IFEND;
              IFEND;

            = fsc$tape_implementation_id =
              IF hdr1_p <> NIL THEN
                attributes [attachment_option].tape_attachment.tape_implementation_id := hdr1_p^.system_code;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_label_standard_version =
              IF (vol1_p <> NIL) AND (vol1_p^.label_standard_version <> ' ') THEN
                clp$convert_string_to_integer (vol1_p^.label_standard_version, int, status);
                IF NOT status.normal THEN
                  EXIT /get_attributes/;
                IFEND;
                attributes [attachment_option].tape_attachment.tape_label_standard_version := int.value;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_max_block_length =
              IF (hdr1_p <> NIL) AND (hdr2_p <> NIL) THEN
                IF fsp$ve_wrote_ansi_file (hdr1_p^.system_code) AND (hdr2_p^.ve_block_length_ext <> ' ') THEN
                  length (1, 3) := hdr2_p^.ve_block_length_ext;
                  length (4, 5) := hdr2_p^.block_length;
                  clp$convert_string_to_integer (length, int, status);
                  IF NOT status.normal THEN
                    EXIT /get_attributes/;
                  IFEND;
                  IF int.value <> 0 THEN
                    attributes [attachment_option].tape_attachment.tape_max_block_length := int.value;
                    returned_attributes := returned_attributes + $fst$tla_returned_attributes
                          [attributes [attachment_option].tape_attachment.selector];
                  IFEND;
                ELSEIF (hdr2_p^.block_length <> ' ') AND (hdr2_p^.block_length <> '00000') THEN
                  clp$convert_string_to_integer (hdr2_p^.block_length, int, status);
                  IF NOT status.normal THEN
                    EXIT /get_attributes/;
                  IFEND;
                  attributes [attachment_option].tape_attachment.tape_max_block_length := int.value;
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                IFEND;
              IFEND;
              IF NOT (fsc$tape_max_block_length IN returned_attributes) AND
                    (source = fsc$tla_last_ansi_file_accessed) AND
                    (cycle_description^.global_file_information^.open_count > 0) THEN
                attributes [attachment_option].tape_attachment.tape_max_block_length :=
                      merged_attributes.max_block_length;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_max_record_length =
              IF (hdr1_p <> NIL) AND (hdr2_p <> NIL) THEN
                IF fsp$ve_wrote_ansi_file (hdr1_p^.system_code) AND (hdr2_p^.ve_record_length_ext <> ' ') THEN
                  length (1, 3) := hdr2_p^.ve_record_length_ext;
                  length (4, 5) := hdr2_p^.record_length;
                  clp$convert_string_to_integer (length, int, status);
                  IF NOT status.normal THEN
                    EXIT /get_attributes/;
                  IFEND;
                  attributes [attachment_option].tape_attachment.tape_max_record_length := int.value;
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                ELSEIF hdr2_p^.record_length <> ' ' THEN
                  clp$convert_string_to_integer (hdr2_p^.record_length, int, status);
                  IF NOT status.normal THEN
                    EXIT /get_attributes/;
                  IFEND;
                  attributes [attachment_option].tape_attachment.tape_max_record_length := int.value;
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                IFEND;
              IFEND;
              IF NOT (fsc$tape_max_record_length IN returned_attributes) AND
                    (source = fsc$tla_last_ansi_file_accessed) AND
                    (cycle_description^.global_file_information^.open_count > 0) THEN
                attributes [attachment_option].tape_attachment.tape_max_record_length :=
                      merged_attributes.max_record_length;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_null_attachment_option =
              ;

            = fsc$tape_owner_identification =
              IF rma_or_ring_privileged THEN
                IF (vol1_p <> NIL) AND ((hdr1_p = NIL) OR (NOT fsp$ve_wrote_ansi_file
                      (hdr1_p^.system_code)) OR (vol1_p^.accessibility <> 'A') OR
                      (vol1_p^.owner_identifier (1, 1) <> '&')) THEN
                  attributes [attachment_option].tape_attachment.tape_owner_identification :=
                        vol1_p^.owner_identifier;
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                IFEND;
              ELSE
                bap$set_evaluated_file_abnormal (evaluated_file_reference, ame$security_conflict, '',
                      'OWNER_IDENTIFICATION', status);
                EXIT /get_attributes/;
              IFEND;

            = fsc$tape_padding_character =
              IF (hdr1_p <> NIL) AND fsp$ve_wrote_ansi_file (hdr1_p^.system_code) AND (hdr2_p <> NIL) THEN
                attributes [attachment_option].tape_attachment.tape_padding_character :=
                      hdr2_p^.ve_padding_character (1);
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              ELSEIF (source = fsc$tla_last_ansi_file_accessed) AND
                    (cycle_description^.global_file_information^.open_count > 0) THEN
                attributes [attachment_option].tape_attachment.tape_padding_character :=
                      merged_attributes.padding_character;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_record_type =
              IF (hdr1_p <> NIL) AND fsp$ve_wrote_ansi_file (hdr1_p^.system_code) THEN
                IF (hdr2_p <> NIL) AND (hdr2_p^.ve_record_type <> ' ') THEN
                  IF hdr2_p^.ve_record_type = 'V' THEN
                    attributes [attachment_option].tape_attachment.tape_record_type := amc$variable;
                  ELSEIF hdr2_p^.ve_record_type = 'U' THEN
                    attributes [attachment_option].tape_attachment.tape_record_type := amc$undefined;
                  ELSEIF hdr2_p^.ve_record_type = 'F' THEN
                    attributes [attachment_option].tape_attachment.tape_record_type := amc$ansi_fixed;
                  ELSEIF hdr2_p^.ve_record_type = 'S' THEN
                    attributes [attachment_option].tape_attachment.tape_record_type := amc$ansi_spanned;
                  ELSEIF hdr2_p^.ve_record_type = 'D' THEN
                    attributes [attachment_option].tape_attachment.tape_record_type := amc$ansi_variable;
                  IFEND;
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                IFEND;
              ELSEIF (hdr2_p <> NIL) AND (hdr2_p^.record_format <> ' ') THEN
                IF hdr2_p^.record_format = 'F' THEN
                  attributes [attachment_option].tape_attachment.tape_record_type := amc$ansi_fixed;
                ELSEIF hdr2_p^.record_format = 'S' THEN
                  attributes [attachment_option].tape_attachment.tape_record_type := amc$ansi_spanned;
                ELSEIF hdr2_p^.record_format = 'D' THEN
                  attributes [attachment_option].tape_attachment.tape_record_type := amc$ansi_variable;
                ELSE
                  attributes [attachment_option].tape_attachment.tape_record_type := amc$undefined;
                IFEND;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;
              IF NOT (fsc$tape_record_type IN returned_attributes) AND
                    (source = fsc$tla_last_ansi_file_accessed) AND
                    (cycle_description^.global_file_information^.open_count > 0) THEN
                attributes [attachment_option].tape_attachment.tape_record_type :=
                      merged_attributes.record_type;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_removable_media_group =
              IF rma_or_ring_privileged THEN
                IF (vol1_p <> NIL) AND (hdr1_p <> NIL) AND fsp$ve_wrote_ansi_file (hdr1_p^.system_code) AND
                      (vol1_p^.accessibility = 'A') AND (vol1_p^.owner_identifier (1, 1) = '&') THEN
                  attributes [attachment_option].tape_attachment.tape_removable_media_group :=
                        vol1_p^.owner_identifier (2, * );
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                IFEND;
              ELSE
                bap$set_evaluated_file_abnormal (evaluated_file_reference, ame$security_conflict, '',
                      'REMOVABLE_MEDIA_GROUP', status);
                EXIT /get_attributes/;
              IFEND;

            = fsc$tape_rewrite_labels =
              IF source = fsc$tla_next_position THEN
                attributes [attachment_option].tape_attachment.tape_rewrite_labels :=
                      merged_attributes.rewrite_labels;
                returned_attributes := returned_attributes + $fst$tla_returned_attributes
                      [attributes [attachment_option].tape_attachment.selector];
              IFEND;

            = fsc$tape_trailer_labels =
              IF (attributes [attachment_option].tape_attachment.tape_trailer_labels <> NIL) AND
                    (trailer_labels <> NIL) THEN
                IF #SIZE (attributes [attachment_option].tape_attachment.tape_trailer_labels^) >=
                      #SIZE (trailer_labels^) THEN
                  i#move (trailer_labels, attributes [attachment_option].tape_attachment.
                        tape_trailer_labels, #SIZE (trailer_labels^));
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                ELSEIF #SIZE (attributes [attachment_option].tape_attachment.tape_trailer_labels^) >=
                      #SIZE (fst$tape_label_sequence_header) THEN
                  i#move (trailer_labels, attributes [attachment_option].tape_attachment.
                        tape_trailer_labels, #SIZE (fst$tape_label_sequence_header));
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                  bap$set_evaluated_file_abnormal (evaluated_file_reference, ame$only_seq_header_returned,
                        'FSP$GET_TAPE_LABEL_ATTRIBUTES', 'TRAILER', status);
                ELSE
                  bap$set_evaluated_file_abnormal (evaluated_file_reference, ame$label_sequence_too_small,
                        'FSP$GET_TAPE_LABEL_ATTRIBUTES', 'TRAILER', status);
                IFEND;
              IFEND;

            = fsc$tape_volume_accessibility =
              IF rma_or_ring_privileged THEN
                IF vol1_p <> NIL THEN
                  attributes [attachment_option].tape_attachment.tape_volume_accessibility :=
                        vol1_p^.accessibility;
                  returned_attributes := returned_attributes + $fst$tla_returned_attributes
                        [attributes [attachment_option].tape_attachment.selector];
                IFEND;
              ELSE
                bap$set_evaluated_file_abnormal (evaluated_file_reference, ame$security_conflict, '',
                      'VOLUME_ACCESSIBILITY', status);
                EXIT /get_attributes/;
              IFEND;

            ELSE
              ;
            CASEND;

          IFEND;
        FOREND;
      IFEND; { tape_descriptor <> NIL }

    END /get_attributes/;

    IF path_table_locked THEN
      fmp$unlock_path_table;
    IFEND;

  PROCEND fmp$get_tape_label_attributes;
MODEND fmm$get_tape_label_attributes;
