
{ The purpose of this request is to issue a tape_bm_advance_volume request.
{ The two possible results of this request are:
{   1) The volume was advanced and the volume position = amc$bov.
{   2) There are no more volumes in the volume list and the volume_position
{      = amc$eov, and an abnormal status is returned.

  PROCEDURE bai$advance_volume
    (    file_identifier: amt$file_identifier;
     VAR volume_position: amt$volume_position;
     VAR status: ost$status);

?? PUSH (LISTEXT := ON) ??

    VAR
      blocks_currently_buffered: bat$tape_block_buffer_count,
      error_action: bat$error_actions,
      tape_failure_modes: amt$tape_failure_modes,
      request_status: ost$status;


    PROCEDURE bai$advance_vol_blk_xt_hndlr
      (    condition: pmt$condition;
           p_condition_info: ^pmt$condition_information;
           p_stack: ^ost$stack_frame_save_area;
       VAR condition_status: ost$status);

{ The purpose of this condition handler is to handle all block
{ exit occurances that may occur while trying to advance to
{ another volume.  The assumptions is that appropriate actions
{ for the various conditions occur elsewhere.  If a block exit
{ is attempted at this level, the necessary action is to close
{ the file and get out.
{

      VAR
        ignore_status: ost$status;

      condition_status.normal := TRUE;
      sl_tape_abnormal_termination (file_identifier);
      bap$close (file_identifier, ignore_status);

    PROCEND bai$advance_vol_blk_xt_hndlr;

    bap$tape_bm_unwritten_blk_count (file_identifier,
          blocks_currently_buffered, request_status);
    tape_failure_modes := $amt$tape_failure_modes [];
    bai$process_request_status (file_identifier, amc$max_operation,
          request_status, tape_failure_modes, error_action, status);
    IF NOT status.normal THEN
      RETURN; {----->
    IFEND;

    osp$establish_block_exit_hndlr (^bai$advance_vol_blk_xt_hndlr);

  /main_program/
    BEGIN
      bap$tape_bm_advance_volume (file_identifier, tape_failure_modes,
            request_status);
      bai$process_request_status (file_identifier, operation, request_status,
            tape_failure_modes, error_action, status);
      IF NOT status.normal THEN
        volume_position := amc$eov;
        EXIT /main_program/; {----->
      ELSEIF NOT request_status.normal AND
            (request_status.condition = dme$volume_list_exhausted) THEN
        volume_position := amc$eov;
        EXIT /main_program/; {----->
      ELSE
        volume_position := amc$bov;
        tape_descriptor^.volume_number := tape_descriptor^.volume_number + 1;
        tape_descriptor^.initial_volume.initial_read_labels_attempt := TRUE;
        block_info^.block_number := max (blocks_currently_buffered,
              LOWERVALUE (block_info^.block_number));
      IFEND;
    END /main_program/;
    osp$disestablish_cond_handler;

    IF NOT status.normal AND (status.condition <> ame$tape_end_of_volume_list)
          THEN
      sl_tape_abnormal_termination (file_identifier);
    IFEND;

  PROCEND bai$advance_volume;

  FUNCTION [INLINE] max
    (    n1: integer;
         n2: integer): integer;

    IF n1 < n2 THEN
      max := n2;
    ELSE
      max := n1;
    IFEND;

  FUNCEND max;

*copyc bap$tape_bm_advance_volume
*copyc bap$tape_bm_unwritten_blk_count
*copyc bai$label_type
*copyc osp$establish_block_exit_hndlr
*copyc osp$disestablish_cond_handler
*copyc dme$tape_errors
?? POP ??

