.ad 8
.bm 8
.fm 4
.bt $Copyright by SAP AG, 2003$$Page %$
.tm 12
.hm 6
.hs 3
.tt 1 $SQL$Project Distributed Database System$VBD01$
.tt 2 $$$$
.tt 3 $JuergenP$filesysteminterface_1$$$$$2000-11-10$
***********************************************************
.nf
 
 
    ========== licence begin  GPL
    Copyright (C) 2000 SAP AG
 
    This program is free software; you can redistribute it and/or
    modify it under the terms of the GNU General Public License
    as published by the Free Software Foundation; either version 2
    of the License, or (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    ========== licence end
 
.fo
.nf
.sp
Module  : filesysteminterface_1
=========
.sp
Purpose : base layer operations :
            - routines for system administration
            - general file operations
            - I/O routines for the restart/logging area
.CM *-END-* purpose -------------------------------------
.sp
.cp 3
Define  :
 
        VAR
              b01bad_index_cnt  : tsp00_Int4;
              b01downfilesystem : boolean;
              b01keyrange       : tgg00_KeyRangeRecord;
              b01blankfilename  : tsp00_VFilename;
              b01zerokey        : tsp00_Key;
              b01fullkey        : tsp00_Key;
 
        PROCEDURE
              b01b_check_bytestr (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b01bcreate_bytestr (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b01change_filetype (VAR t : tgg00_TransContext;
                    VAR file_id  : tgg00_FileId;
                    new_filetype : tgg00_FiletypeSet);
 
        PROCEDURE
              b01check_table (VAR t : tgg00_TransContext;
                    VAR file_id          : tgg00_FileId;
                    long_col_cnt         : tsp00_Int2;
                    new_long_col_cnt     : tsp00_Int2;
                    check_long_existence : boolean);
 
        FUNCTION
              b01connect_allowed : boolean;
 
        PROCEDURE
              b01create_filesystem (
                    VAR t       : tgg00_TransContext;
                    VAR DBIdent : tsp00_Line );
 
        FUNCTION
              b01db_full( taskId : tsp00_TaskId ) : boolean;
 
        PROCEDURE
              b01dbspace_statistic (VAR t : tgg00_TransContext;
                    VAR info : tgg00_DbSpaceInfo);
 
        PROCEDURE
              b01del_event_dw_compr;
 
        PROCEDURE
              b01del_event_dw_displ;
 
        PROCEDURE
              b01del_event_savepoint;
 
        PROCEDURE
              b01destroy_file (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b01empty_file (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b01end_read_only (VAR t : tgg00_TransContext);
 
        PROCEDURE
              b01fcreate_file (VAR t : tgg00_TransContext;
                    VAR file_id    : tgg00_FileId;
                    stringcol_cnt  : tsp00_Int2;
                    varcol_cnt_off : tsp00_Int2;
                    no_tree_index  : boolean);
 
        PROCEDURE
              b01filestate (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b01fn_new_and_unload (VAR t : tgg00_TransContext;
                    VAR orig_id : tgg00_FileId;
                    VAR new_id  : tgg00_FileId);
 
        PROCEDURE
              b01fset_write_state (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId;
                    on          : boolean);
 
        FUNCTION
              b01get_bad_index_cnt (pid : tsp00_TaskId) : tsp00_Int4;
 
        PROCEDURE
              b01get_bad_indexid (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b01get_data_cache_workload (VAR t : tgg00_TransContext;
                    VAR DataCacheSize      : tsp00_Int4;
                    VAR OmsHistoryPageCnt  : tsp00_Int4;
                    VAR OmsDataPageCnt     : tsp00_Int4;
                    VAR SqlDataPageCnt     : tsp00_Int4);
 
        PROCEDURE
              b01lg_create_log_file (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b01ldestroy_long_file (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b01move_filecontent (VAR t : tgg00_TransContext;
                    VAR source_id : tgg00_FileId;
                    VAR target_id : tgg00_FileId);
 
        PROCEDURE
              b01next_fdir_entry (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        FUNCTION
              b01no_of_data_devs : tsp00_Int4;
 
        FUNCTION
              b01no_of_log_devs : tsp00_Int4;
 
        PROCEDURE
              b01pdestroy_perm_file (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b01prefix_destroy_files (VAR t : tgg00_TransContext;
                    VAR prefix_fn : tgg00_Filename;
                    prefix_len    : integer);
 
        PROCEDURE
              b01psclear_save_pages_psm (VAR t : tgg00_TransContext);
 
        PROCEDURE
              b01pverify_participant (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId;
                    is_cold     : boolean);
 
        FUNCTION
              b01rec_align (len : tsp00_Int4): tsp00_Int4;
 
        PROCEDURE
              b01reload_file (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b01rename_file (VAR t : tgg00_TransContext;
                    VAR old_id : tgg00_FileId;
                    VAR new_id : tgg00_FileId);
 
        PROCEDURE
              b01reset_monitor (part : tgg00_MonitorPart);
 
        PROCEDURE
              b01restart_filesystem (VAR t : tgg00_TransContext;
                    IncrementConvVersion : boolean);
 
        PROCEDURE
              b01set_fileversion (VAR t : tgg00_TransContext;
                    VAR file_id     : tgg00_FileId;
                    new_fileversion : tgg91_FileVersion;
                    new_long_cnt    : tsp00_Int2);
 
        PROCEDURE
              b01show_treelocklist (VAR t : tgg00_TransContext;
                    VAR file_id   : tgg00_FileId;
                    VAR rec_count : tsp00_Int4);
 
        PROCEDURE
              b01treeleafnodes (VAR t     : tgg00_TransContext;
                    VAR file_id           : tgg00_FileId;
                    m_type                : tgg00_MessType;
                    VAR old_treeleafnodes : tsp00_Int4);
 
        PROCEDURE
              b01setto_zero_full_and_null;
 
        PROCEDURE
              b01sfile_statistic (
                    VAR t              : tgg00_TransContext;
                    VAR file_id        : tgg00_FileId;
                    with_shortcol_file : boolean;
                    VAR info           : tgg00_SampleInfo);
 
        PROCEDURE
              b01show_monitor (
                    TaskId   : tsp00_TaskId;
                    VAR info : tgg00_ReferenceInfo);
 
        PROCEDURE
              b01shutdown_filesystem (VAR t : tgg00_TransContext);
 
        PROCEDURE
              b01tcreate_file (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b01tdestroy_loc_temp_files (VAR t : tgg00_TransContext;
                    site : tgg00_ServerdbNo);
 
        PROCEDURE
              b01tinit_temp_cache (VAR t : tgg00_TransContext;
                    buffers            : tsp00_Int4;
                    is_control_session : boolean);
 
        FUNCTION
              b01tmp_cache_size (VAR t : tgg00_TransContext) : tsp00_Int4;
 
        PROCEDURE
              b01tnext_temp_statistic (
                    VAR Trans        : tgg00_TransContext;
                    VAR FileId       : tgg00_FileId;
                    VAR TotalPageCnt : tsp00_Int4);
 
        PROCEDURE
              b01trelease_temp_cache (VAR t : tgg00_TransContext);
 
        PROCEDURE
              b01treset_file (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b01unload_file (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b01verify_database (
                    VAR t                 : tgg00_TransContext;
                    bWithUpdate           : boolean;
                    bWithIndexes          : boolean;
                    VAR NumPermPages      : tsp00_Int4;
                    VAR NumReleasedBlocks : tsp00_Int4;
                    VAR bad_index_cnt     : tsp00_Int4;
                    VAR total_bad_cnt     : tsp00_Int4);
 
        PROCEDURE
              b01vstate_fileversion (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              bd01AddInvToFileDirectory (
                    VAR Trans        : tgg00_TransContext;
                    VAR FileId       : tgg00_FileId;
                    SetNotAccessible : boolean);
 
        PROCEDURE
              bd01DataCacheSize (
                    VAR TotalPages : tsp00_Int4;
                    VAR UnMapPages : tsp00_Int4);
 
        FUNCTION
              bd01ConverterSize : tsp00_Int4;
 
        PROCEDURE
              bd01CreateCoordinator (VAR t : tgg00_TransContext;
                    VAR FileId : tgg00_FileId;
                    MessType   : tgg00_MessType);
 
        PROCEDURE
              bd01EmergencyShutdown (TaskId : tsp00_TaskId);
 
        PROCEDURE
              bd01SetToNilCurrent( VAR Current : tbd_current_tree );
 
        PROCEDURE
              bd01StartCoordinator (t : tgg00_TransContext;
                    VAR FileId : tgg00_FileId;
                    MessType   : tgg00_MessType);
 
        FUNCTION
              bd01UsableServerForParallelExecution (
                    TaskId   : tsp00_TaskId;
                    MessType : tgg00_MessType;
                    InRegion : boolean) : integer;
 
        PROCEDURE
              bd01CalculateRecordsAndLeaves(
                    VAR Trans           : tgg00_TransContext;
                    VAR FileId          : tgg00_FileId;
                    VAR NumberOfLeaves  : tsp00_Int4;
                    VAR NumberOfRecords : tsp00_Int4 );
 
        PROCEDURE
              bd01SampleRecordsAndLeaves(
                    VAR Trans            : tgg00_TransContext;
                    VAR FileId           : tgg00_FileId;
                    NumberOfSampleLeaves : tsp00_Int4;
                    VAR NumberOfLeaves   : tsp00_Int4;
                    VAR NumberOfRecords  : tsp00_Int4 );
 
        PROCEDURE
              bd01ExtractForeignKey(
                    VAR MessBlock : tgg00_MessBlock;
                    VAR AuxFileId : tgg00_FileId);
 
        PROCEDURE
              bd01MultiColumnStatistic(
                    VAR MessBlock        : tgg00_MessBlock;
                    VAR AuxFileId        : tgg00_FileId;
                    bCalculate           : boolean;
                    NumberOfSampleLeaves : tsp00_Int4;
                    VAR NumberOfLeaves   : tsp00_Int4;
                    VAR NumberOfRecords  : tsp00_Int4;
                    VAR DistinctValues   : tgg00_ColumnDistinctValues);
 
        PROCEDURE
              bd01MigrateDataBase(
                    TaskId      : tsp00_TaskId;
                    VAR TrError : tgg00_BasisError);
              (*ptocExport hbd01_2.h*)
 
        FUNCTION
              b01devsize (dev_type : tsp2_dev_type;
                    devno : tsp00_Int4) : tsp00_Int4;
 
        PROCEDURE
              b01get_devname (dev_type : tsp2_dev_type;
                    devno       : tsp00_Int4;
                    VAR devname : tsp2_devname);
 
        PROCEDURE
              b01next_bad_dev (pid : tsp00_TaskId;
                    VAR dev_type   : tsp2_dev_type;
                    VAR devno      : tsp00_Int4;
                    VAR devname    : tsp2_devname;
                    VAR really_bad : boolean);
 
        PROCEDURE
              b01next_dev_info (
                    TaskId              : tsp00_TaskId;
                    VAR dev_no          : tsp00_Int4;
                    VAR dev_type        : tsp2_dev_type;
                    VAR dev_name        : tsp2_devname;
                    VAR dev_size        : tsp00_Int4;
                    VAR dev_used_blocks : tsp00_Int4;
                    VAR dev_online      : boolean;
                    VAR dev_state       : tsp00_C18);
              (*ptocExport hbd01_3.h*)
 
        PROCEDURE
              b01del_event (EventId : tsp31_event_ident;
                    Threshold : integer);
 
        PROCEDURE
              b01get_events (VAR ShortEventDesc : tsp31_short_event_desc);
 
        PROCEDURE
              b01set_event (EventId   : tsp31_event_ident;
                    Threshold : integer;
                    Priority  : tsp31_event_prio);
 
        PROCEDURE
              b01set_event_dw_compr(priority_of_event : tsp31_event_prio);
 
        PROCEDURE
              b01set_event_dw_displ(priority_of_event : tsp31_event_prio);
 
        PROCEDURE
              b01set_event_savepoint(priority_of_event : tsp31_event_prio);
              (*ptocExport hbd01_1.h*)
 
        VAR
              b01nilcurrent : tbd_current_tree;
              b01niltree_id : tgg00_FileId;
 
.CM *-END-* define --------------------------------------
.sp;.cp 3
Use     :
 
        FROM
              filesysteminterface_2 : VBD02;
 
        PROCEDURE
              b02calculate_page_count (VAR t : tgg00_TransContext;
                    VAR file_id      : tgg00_FileId;
                    VAR startkey     : tgg00_Lkey;
                    VAR stopkey      : tgg00_Lkey;
                    VAR page_count   : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              filesysteminterface_3 : VBD03;
 
        PROCEDURE
              bd03ReleaseInvTree (VAR Trans  : tgg00_TransContext;
                    VAR FiledId              : tgg00_FileId);
 
        PROCEDURE
              bd03VerifyInvTree (VAR Trans : tgg00_TransContext;
                    VAR FiledId            : tgg00_FileId;
                    IsCold                 : boolean;
                    VAR NumPages           : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              error_text_handling : VBD06;
 
        PROCEDURE
              b06init_errtxt;
 
        PROCEDURE
              b06write_filename_and_root (VAR file_id : tgg00_FileId);
 
      ------------------------------ 
 
        FROM
              pagestore : VBD10;
 
        FUNCTION
              bd10IsConnectAllowed : boolean;
 
        FUNCTION
              bd10IsDbFull( TaskId : tsp00_TaskId ) : boolean;
 
        FUNCTION
              bd10ConverterSize : tsp00_Int4;
 
        PROCEDURE
              b10create_converter (
                    TaskId      : tsp00_TaskId;
                    NumAllPages : tsp00_Int4);
 
        PROCEDURE
              bd10dbspace_statistic (VAR t : tgg00_TransContext;
                    VAR info : tgg00_DbSpaceInfo);
 
        PROCEDURE
              bd10EndColdVerify (
                    TaskId                : tsp00_TaskId;
                    VAR NumPermPages      : tsp00_Int4;
                    VAR NumReleasedBlocks : tsp00_Int4);
 
        PROCEDURE
              bd10EndFailedColdVerify (TaskId : tsp00_TaskId);
 
        PROCEDURE
              bd10FlushConverterSerial (VAR Trans : tgg00_TransContext;
                    VAR ConverterVersion           : tsp00_Int4;
                    VAR MaxStaticPageNo            : tsp00_PageNo;
                    VAR MaxDynamicPageNo           : tsp00_PageNo;
                    VAR PackedConvRootBlockAddress : tsp00_Int4);
 
        PROCEDURE
              bd10BeginColdVerify;
 
        PROCEDURE
              b10rc_restart_converter (
                    VAR t                  : tgg00_TransContext;
                    ConverterVersion       : tsp00_Int4;
                    NumAllPages            : tsp00_Int4;
                    IncrementConvVersion   : boolean;
                    LastSaveDataSuccessful : boolean;
                    VAR RestartParam       : tgg00_ConfigRestartParam);
 
        PROCEDURE
              bd10ShutdownConverter (TaskId : tsp00_TaskId);
 
        PROCEDURE
              bd10GetDBFillingEventSet (VAR ShortEventDesc : tsp31_short_event_desc;
                    bGetOverflowEvents : boolean);
 
        PROCEDURE
              bd10AddDBFillingEvent (
                    EventId        :  tsp31_event_ident;
                    EventThreshold :  tsp00_Int4;
                    EventPrio      :  tsp31_event_prio
                    );
 
        PROCEDURE
              bd10DelDBFillingEvent (
                    EventId        :  tsp31_event_ident;
                    EventThreshold :  tsp00_Int4
                    );
 
      ------------------------------ 
 
        FROM
              free_block_management : VBD11;
 
        PROCEDURE
              b11_init;
 
        FUNCTION
              b11_blocks_used (dev_no : tsp00_Int2) : tsp00_Int4;
 
      ------------------------------ 
 
        FROM
              Trace : VBD120;
 
        PROCEDURE
              b120InsertTrace (VAR t   : tgg00_TransContext;
                    trace_layer  : tgg00_Debug;
                    trace_object : tgg00_VtraceType;
                    body_len     : tsp00_Int2;
                    trace_body   : tgg11_VtraceBodyPtr);
 
      ------------------------------ 
 
        FROM
              nodehandling : VBD13;
 
        PROCEDURE
              b13pfree_pno (pno : tsp00_PageNo;
                    VAR current : tbd_current_tree);
 
      ------------------------------ 
 
        FROM
              filedirectory : VBD17;
 
        VAR
              b17permfdir_current   : tbd_current_tree;
              b17tempfdir_current   : tbd_current_tree;
              b17strcolfdir_current : tbd_current_tree;
 
        PROCEDURE
              b17create_fdir (VAR t : tgg00_TransContext);
 
        PROCEDURE
              b17restart_fdir (
                    VAR t       : tgg00_TransContext;
                    fdir_1_root : tsp00_PageNo;
                    fdir_2_root : tsp00_PageNo);
 
        FUNCTION
              bd17GetFdirRoot : tsp00_PageNo;
 
        PROCEDURE
              b17add_fdir (VAR fn : tgg00_Filename;
                    VAR fi : tbd_fileinfo;
                    VAR t  : tgg00_TransContext);
 
        PROCEDURE
              b17repl_fdir (VAR fn : tgg00_Filename;
                    VAR fi      : tbd_fileinfo;
                    shared_file : boolean;
                    VAR t       : tgg00_TransContext);
 
        PROCEDURE
              b17del_fdir (VAR fn   : tgg00_Filename;
                    VAR fi          : tbd_fileinfo;
                    shared_file     : boolean;
                    VAR t           : tgg00_TransContext);
 
        PROCEDURE
              b17unload_fdir (VAR fn : tgg00_Filename;
                    VAR fi          : tbd_fileinfo;
                    shared_file     : boolean;
                    VAR t           : tgg00_TransContext);
 
        PROCEDURE
              b17get_fdir (VAR fn   : tgg00_Filename;
                    VAR fi          : tbd_fileinfo;
                    shared_file     : boolean;
                    VAR t           : tgg00_TransContext);
 
        PROCEDURE
              b17next_del_fdir (VAR prefix : tgg00_Filename;
                    prefix_len      : integer;
                    VAR fn          : tgg00_Filename;
                    VAR fi          : tbd_fileinfo;
                    shared_file     : boolean;
                    VAR t           : tgg00_TransContext);
 
        PROCEDURE
              b17succ_fdir (VAR fn, next_fn : tgg00_Filename;
                    VAR fi          : tbd_fileinfo;
                    shared_file     : boolean;
                    VAR t           : tgg00_TransContext;
                    include_strcols : boolean);
 
        PROCEDURE
              b17state_fdir (VAR fn : tgg00_Filename;
                    VAR fi      : tbd_fileinfo;
                    shared_file : boolean;
                    VAR t       : tgg00_TransContext);
 
        PROCEDURE
              b17set_filestate (VAR fn : tgg00_Filename;
                    VAR t      : tgg00_TransContext;
                    new_fstate : tbd_file_state_set;
                    reset      : boolean);
 
        PROCEDURE
              b17reset_read_only (VAR t : tgg00_TransContext);
 
        PROCEDURE
              b17tnext_temp_fdir (VAR fn, next_fn : tgg00_Filename;
                    VAR fi      : tbd_fileinfo;
                    shared_file : boolean;
                    VAR t       : tgg00_TransContext);
 
      ------------------------------ 
 
        FROM
              diskfiledirectory : VBD18;
 
        PROCEDURE
              b18lcreate_lcl_tfdir ( VAR t : tgg00_TransContext);
 
      ------------------------------ 
 
        FROM
              systembufferinterface : VBD20;
 
        PROCEDURE
              bd20InitDataCache (
                    TaskId          : tsp00_TaskId;
                    VAR TrError     : tgg00_BasisError;
                    TotalFreeFrames : tsp00_Int4;
                    TotalDataPages  : tsp00_Int4);
 
        PROCEDURE
              bd20GetCacheSize (
                    VAR TotalPages : tsp00_Int4;
                    VAR UnMapPages : tsp00_Int4);
 
        PROCEDURE
              bd20GetWorkloadCounter (
                    VAR DataCacheSize      : tsp00_Int4;
                    VAR OmsHistoryPageCnt  : tsp00_Int4;
                    VAR OmsDataPageCnt     : tsp00_Int4;
                    VAR SqlDataPageCnt     : tsp00_Int4);
 
        PROCEDURE
              bd20FlushDataCache (VAR t : tgg00_TransContext);
 
        PROCEDURE
              bd20ShutdownDataCache (
                    TaskId             : tsp00_TaskId;
                    emergency_shutdown : boolean);
 
      ------------------------------ 
 
        FROM
              task_temp_data_cache : VBD21;
 
        PROCEDURE
              b21init_temp_cache (pid  : tsp00_TaskId;
                    buffers            : tsp00_Int4;
                    allocate_monitor   : boolean;
                    is_control_session : boolean;
                    VAR temp_cache_ptr : tgg00_TempDataCachePtr;
                    VAR e              : tgg00_BasisError);
 
        PROCEDURE
              b21temp_cache_release (pid : tsp00_TaskId;
                    temp_cache_ptr : tgg00_TempDataCachePtr);
 
        FUNCTION
              b21tmp_cache_size (temp_cache_ptr : tgg00_TempDataCachePtr) : tsp00_Int4;
 
        PROCEDURE
              b21lcl_tfdir_root (temp_cache_ptr : tgg00_TempDataCachePtr;
                    is_set  : boolean;
                    VAR pno : tsp00_PageNo);
 
        PROCEDURE
              b21m_init_monitor_rec;
 
      ------------------------------ 
 
        FROM
              treehandling : VBD30;
 
        PROCEDURE
              b30add_filestate (VAR current : tbd_current_tree;
                    new_filestate : tbd_file_state_set);
 
        PROCEDURE
              b30check_tree (
                    VAR current          : tbd_current_tree;
                    long_col_cnt         : tsp00_Int2;
                    new_long_col_cnt     : tsp00_Int2;
                    check_long_existence : boolean);
 
        PROCEDURE
              b30cinit_current (VAR t : tgg00_TransContext;
                    VAR current : tbd_current_tree);
 
        PROCEDURE
              b30current (VAR t : tgg00_TransContext;
                    VAR file_id : tgg00_FileId;
                    m_type      : tgg00_MessType;
                    VAR current : tbd_current_tree);
 
        PROCEDURE
              b30database_verify (VAR t : tgg00_TransContext;
                    VAR bad_index_cnt : tsp00_Int4;
                    VAR total_bad_cnt : tsp00_Int4;
                    VAR verify_error  : tgg00_BasisError;
                    bWithUpdate       : boolean;
                    bWithIndexes      : boolean;
                    max_server        : integer);
 
        PROCEDURE
              b30fdir_to_treeid (VAR fi : tbd_fileinfo;
                    VAR file_id : tgg00_FileId);
 
        PROCEDURE
              b30new_tree (VAR fi : tbd_fileinfo;
                    VAR current   : tbd_current_tree);
 
        PROCEDURE
              b30release_tree (VAR current : tbd_current_tree;
                    stringcol_cnt  : integer;
                    varcol_cnt_off : integer;
                    only_empty     : boolean);
 
        PROCEDURE
              b30set_fileversion (VAR current : tbd_current_tree;
                    new_fileversion : tgg91_FileVersion);
 
        PROCEDURE
              b30treeleafnodes (VAR current : tbd_current_tree;
                    node_req          : tbd_node_request;
                    VAR old_leafnodes : tsp00_Int4);
 
        PROCEDURE
              b30sub_filestate (VAR current : tbd_current_tree;
                    filestate : tbd_file_state_set);
 
        PROCEDURE
              b30verify_tree (VAR current : tbd_current_tree;
                    is_cold          : boolean;
                    VAR NumPages     : tsp00_Int4);
 
        PROCEDURE
              bd30CreateCoordinator (VAR t : tgg00_TransContext;
                    VAR FileId : tgg00_FileId;
                    MessType   : tgg00_MessType);
 
        PROCEDURE
              bd30OmsReadAheadCoordinator (VAR t : tgg00_TransContext;
                    ReadAheadServer : integer);
 
        PROCEDURE
              bd30ObjFileCoordinator (VAR t : tgg00_TransContext;
                    mtype           : tgg_message_type;    (* PTS 1113635 FF 25-Jan-2002 *)
                    NumVerifyServer : integer);
 
      ------------------------------ 
 
        FROM
              indexhandling : VBD50;
 
        PROCEDURE
              b50change_treeroot (subroot : tsp00_PageNo;
                    new_root    : tsp00_PageNo;
                    VAR current : tbd_current_tree);
 
        PROCEDURE
              bd50ExtractForeignKey (
                    VAR m            : tgg00_MessBlock;
                    VAR current      : tbd_current_tree;
                    VAR temp_current : tbd_current_tree);
 
      ------------------------------ 
 
        FROM
              bytestring_handling : VBD60;
 
        PROCEDURE
              b60check_bytestr (VAR current : tbd_current_tree);
 
        PROCEDURE
              b60new_bytestr (VAR current : tbd_current_tree);
 
        PROCEDURE
              b60release_bytestr (VAR current : tbd_current_tree);
 
        PROCEDURE
              b60verify_bytestr (VAR current : tbd_current_tree;
                    psm_update   : boolean;
                    VAR NumPages : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              concurrency : VBD75;
 
        PROCEDURE
              b75init_tree_locklist (pid : tsp00_TaskId;
                    VAR e : tgg00_BasisError);
 
        PROCEDURE
              b75show_treelocklist (VAR current : tbd_current_tree;
                    VAR rec_count : tsp00_Int4);
 
        PROCEDURE
              b75tldelete_lock_tree (VAR current : tbd_current_tree;
                    ignore_svp     : boolean;
                    suspend_reason : tsp00_Int2);
 
        PROCEDURE
              b75tlread_lock_tree (VAR current : tbd_current_tree;
                    suspend_reason : tsp00_Int2);
 
        PROCEDURE
              b75turead_unlock_tree (VAR current : tbd_current_tree);
 
        PROCEDURE
              b75tudelete_unlock_tree (VAR current : tbd_current_tree);
 
        PROCEDURE
              b75rdelete_lock_requests (pid : tsp00_TaskId);
 
      ------------------------------ 
 
        FROM
              tree_locklist : VBD77;
 
        PROCEDURE
              b77set_not_generated;
 
      ------------------------------ 
 
        FROM
              filestatistic : VBD72;
 
        PROCEDURE
              bd72MultiColumnStatistic(
                    VAR MessBlock        : tgg00_MessBlock;
                    VAR Current          : tbd_current_tree;
                    VAR TempCurrent      : tbd_current_tree;
                    bCalculate           : boolean;
                    NumberOfSampleLeaves : tsp00_Int4;
                    VAR NumberOfLeaves   : tsp00_Int4;
                    VAR NumberOfRecords  : tsp00_Int4;
                    VAR DistinctValues   : tgg00_ColumnDistinctValues);
 
      ------------------------------ 
 
        FROM
              ref_statistic :   VBD73;
 
        PROCEDURE
              b73init_ref_statistic (part : tgg00_MonitorPart);
 
        PROCEDURE
              b73show_ref_statistic (
                    TaskId   : tsp00_TaskId;
                    VAR info : tgg00_ReferenceInfo);
 
      ------------------------------ 
 
        FROM
              object_garbage_collection : VBD91;
 
        PROCEDURE
              bd91InitObjFileDir (VAR Trans : tgg00_TransContext);
 
        FUNCTION              (* PTS 1113635 FF *)
              bd91MigrationNeeded( VAR version : tsp00_Version ) : tsp00_Int4;
 
        PROCEDURE
              bd91RemoveObjFilesMarkedForDelete (VAR Trans : tgg00_TransContext);
 
        PROCEDURE
              bd91StartOMSGarbageCollectionAfterSpecialOp (TaskId : tsp00_TaskId);
 
      ------------------------------ 
 
        FROM
              service_routines_for_oms : VBD92;
 
        PROCEDURE
              bd92VerifyObjFile ( VAR current : tbd_current_tree;
                    bConverterUpdate : boolean);
 
      ------------------------------ 
 
        FROM
              eventing : VBD700;
 
        PROCEDURE
              bd700SetSystemDefinedEvents;
 
      ------------------------------ 
 
        FROM
              BD_Wrapper : VBD999;
 
        PROCEDURE
              bd999AttachAllDevices( VAR Trans : tgg00_TransContext );
 
        PROCEDURE
              bd999CreateAllLogDevices(
                    TaskId        : tsp00_TaskId;
                    pDBIdentifier : tsp00_BytePtr;
                    VAR TrError   : tgg00_BasisError);
 
        PROCEDURE
              bd999CreateAllDataDevices(
                    TaskId        : tsp00_TaskId;
                    pDBIdentifier : tsp00_BytePtr;
                    VAR TrError   : tgg00_BasisError);
 
        PROCEDURE
              bd999DetachAllDevices( TaskId : tsp00_TaskId );
 
        FUNCTION
              bd999DataDevSpaceSize( DevNo : tsp00_Int2 ) : tsp00_Int4;
 
        FUNCTION
              bd999LogDevSpaceSize( DevNo : tsp00_Int2) : tsp00_Int4;
 
        FUNCTION
              bd999FramesAvailable : tsp00_Int4;
 
        PROCEDURE
              bd999GetDataDevName(
                    DevNo        : tsp00_Int2;
                    VAR  DevName : tsp00_VFilename);
 
        PROCEDURE
              bd999GetLogDevName(
                    DevNo        : tsp00_Int2;
                    VAR  DevName : tsp00_VFilename);
 
        PROCEDURE
              bd999MigrateDataBase(
                    TaskId      : tsp00_TaskId;
                    VAR TrError : tgg00_BasisError);
 
        FUNCTION
              bd999NoOfDataDevices : tsp00_Int4;
 
        FUNCTION
              bd999NoOfLogDevices : tsp00_Int4;
 
        FUNCTION
              bd999TotalDataPages : tsp00_Int4;
 
        PROCEDURE
              bd999EnableDataWriter (
                    TaskId   : tsp00_TaskId);
 
        PROCEDURE
              bd999CalculateColumnStatistic(
                    VAR Trans           : tgg00_TransContext;
                    VAR Current         : tbd_current_tree;
                    VAR TempCurrent     : tbd_current_tree;
                    ColumnCount         : tsp00_Int2;
                    columnFirstPosition : tsp00_Int2;
                    columnLastPosition  : tsp00_Int2;
                    pColumnDescription  : tgg00_StackListPtr;
                    VAR NumberOfLeaves  : tsp00_Int4;
                    VAR NumberOfRecords : tsp00_Int4;
                    VAR DistinctValues  : tgg00_ColumnDistinctValues );
 
        PROCEDURE
              bd999SampleColumnStatistic(
                    VAR Trans            : tgg00_TransContext;
                    VAR Current          : tbd_current_tree;
                    VAR TempCurrent      : tbd_current_tree;
                    NumberOfSampleLeaves : tsp00_Int4;
                    ColumnCount          : tsp00_Int2;
                    columnFirstPosition  : tsp00_Int2;
                    columnLastPosition   : tsp00_Int2;
                    pColumnDescription   : tgg00_StackListPtr;
                    VAR NumberOfLeaves   : tsp00_Int4;
                    VAR NumberOfRecords  : tsp00_Int4;
                    VAR DistinctValues   : tgg00_ColumnDistinctValues );
 
        PROCEDURE
              bd999CalculateRecordsAndLeaves(
                    VAR Trans           : tgg00_TransContext;
                    VAR Current         : tbd_current_tree;
                    VAR NumberOfLeaves  : tsp00_Int4;
                    VAR NumberOfRecords : tsp00_Int4 );
 
        PROCEDURE
              bd999SampleRecordsAndLeaves(
                    VAR Trans            : tgg00_TransContext;
                    VAR Current          : tbd_current_tree;
                    NumberOfSampleLeaves : tsp00_Int4;
                    VAR NumberOfLeaves   : tsp00_Int4;
                    VAR NumberOfRecords  : tsp00_Int4 );
 
        PROCEDURE
              bd999CalculateTableStatistic(
                    VAR Trans             : tgg00_TransContext;
                    VAR Current           : tbd_current_tree;
                    VAR ShortCurrent      : tbd_current_tree;
                    bShortColumnFileExist : boolean;
                    NumberOfLongColumns   : tsp00_Int4;
                    VAR TableStatistic    : tgg00_TableStatInfo);
 
        PROCEDURE
              bd999CheckSpace(
                    VAR Trans         : tgg00_TransContext;
                    NumPagesRequestes : tsp00_Int4);
 
      ------------------------------ 
 
        FROM
              KB_Logging : VKB560;
 
        PROCEDURE
              kb560CheckKernelVersionForMigration (VAR version : tsp00_Version);
 
        PROCEDURE
              kb560CreateHistoryManager (VAR Trans : tgg00_TransContext);
 
        FUNCTION
              kb560VerifyOpenTransAndHistory (VAR Trans : tgg00_TransContext;
                    isCold : boolean) : boolean;
 
      ------------------------------ 
 
        FROM
              KB_restart_record : VKB57;
 
        VAR
              k57restartrec : tkb00_PagePtr;
 
        PROCEDURE
              k57init_restartrec_handling (VAR t : tgg00_TransContext);
 
        PROCEDURE
              k57save_restartrecord (TaskId : tsp00_TaskId);
 
        FUNCTION
              kb57AnyOpenTransactionsExist : boolean;
 
        FUNCTION
              kb57GetFdir : tsp00_PageNo;
 
        FUNCTION
              kb57GetLongFdir : tsp00_PageNo;
 
      ------------------------------ 
 
        FROM
              KB_sender_receiver : VKB90;
 
        FUNCTION
              k90free_requests (pid : tsp_process_id;
                    mtype           : tgg_message_type;
                    in_region       : boolean) : tsp_int4;
 
      ------------------------------ 
 
        FROM
              Configuration_Parameter : VGG01;
 
        VAR
              g01localsite  : tgg_serverdb_no;
              g01vtrace     : tgg_vtrace_state;
              g01newupdstat : boolean;
 
        FUNCTION
              g01is_livecache : boolean;
 
        PROCEDURE
              g01opmsg (msg_prio : tsp3_priority;
                    msg_type  : tsp3_msg_type;
                    msg_no    : tsp_int4;
                    msg_label : tsp_c8;
                    msg_text  : tsp_c24;
                    msg_value : tsp_int4);
 
        PROCEDURE
              g01optextmsg (msg_prio : tsp3_priority;
                    msg_type  : tsp3_msg_type;
                    msg_no    : tsp_int4;
                    msg_label : tsp_c8;
                    msg_text  : tsp_c40);
 
      ------------------------------ 
 
        FROM
              Select_Help_Procedures : VGG04;
 
        FUNCTION
              g04inv_tfn (tfn : tgg00_Tfn) : boolean;
 
      ------------------------------ 
 
        FROM
              GG_cpp_auxiliary_functions : vgg06;
 
        PROCEDURE
              gg06SetNilRef (VAR PageRef : tgg91_PageRef);
&       ifdef TRACE
 
      ------------------------------ 
 
        FROM
              Test_Procedures : VTA01;
 
        PROCEDURE
              t01basis_error (debug : tgg00_Debug;
                    nam   : tsp00_Sname;
                    b_err : tgg00_BasisError);
 
        PROCEDURE
              t01bool (debug : tgg00_Debug;
                    nam      : tsp00_Sname;
                    curr_bool: boolean);
 
        PROCEDURE
              t01vffn (
                    debug : tgg00_Debug;
                    nam   : tsp00_Sname;
                    fn    : tsp00_VFilename);
 
        PROCEDURE
              t01filename (debug : tgg00_Debug;
                    fn : tgg00_Filename);
 
        PROCEDURE
              t01filetype (debug : tgg00_Debug;
                    nam : tsp00_Sname;
                    s   : tgg00_FiletypeSet);
 
        PROCEDURE
              ta01FileVers (debug : tgg00_Debug;
                    nam           : tsp00_Sname;
                    VAR FileVers  : tgg91_FileVersion);
 
        PROCEDURE
              t01int4 (debug : tgg00_Debug;
                    nam      : tsp00_Sname;
                    int4     : tsp00_Int4);
 
        PROCEDURE
              t01messtype (debug : tgg00_Debug;
                    nam          : tsp00_Sname;
                    mess_type    : tgg00_MessType);
 
        PROCEDURE
              t01name (debug : tgg00_Debug;
                    nam  : tsp00_Name);
 
        PROCEDURE
              t01p2int4 (debug : tgg00_Debug;
                    nam_1 : tsp00_Sname;
                    int_1 : tsp00_Int4;
                    nam_2 : tsp00_Sname;
                    int_2 : tsp00_Int4);
 
        PROCEDURE
              t01site (debug : tgg00_Debug;
                    nam      : tsp00_Sname;
                    site     : tgg00_ServerdbNo);
 
        PROCEDURE
              t01sname (debug : tgg00_Debug;
                    nam : tsp00_Sname);
 
        PROCEDURE
              t01str30 (layer : tgg00_Debug;
                    str30 : tsp00_C30);
 
        FUNCTION
              t01trace (debug : tgg00_Debug) : boolean;
 
        PROCEDURE
              t01treeid (debug : tgg00_Debug;
                    nam        : tsp00_Sname;
                    VAR treeid : tgg00_FileId);
&       endif
 
.CM *-END-* use -----------------------------------------
.sp;.cp 3
Synonym :
 
        PROCEDURE
              bd999CalculateColumnStatistic;
 
              tgg00_StEntryAddr tgg00_StackListPtr
 
        PROCEDURE
              bd999SampleColumnStatistic;
 
              tgg00_StEntryAddr tgg00_StackListPtr
 
        PROCEDURE
              bd999GetDataDevName;
 
              tsp00_VFilename tsp2_devname
 
        PROCEDURE
              bd999GetLogDevName;
 
              tsp00_VFilename tsp2_devname
&             ifdef TRACE
&             endif
 
.CM *-END-* synonym -------------------------------------
.sp;.cp 3
Author  : JuergenP
.sp
.cp 3
Created : 1979-09-05
.sp
.cp 3
.sp
.cp 3
Release :      Date : 2000-11-10
.sp
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Specification:
 
.sp 2;.cp 4
.oc _/1;1._Base_Layer_Files
.sp 4;.cp 6
The base layer makes available operations for file management and
processing.
.br
A file must be explicitly created before it can be processed and
normally exists until it is explicitly deleted.  Every (existing)
file has an unambiguous name, a 'filename', and consists of a
sequenced set of entries.  The entries are (Pascal) strings of
variable length and each contains an unambiguous key as a
substring.
.sp 2;.cp 10
   a) Key :
.sp 2;.nf
        1       n bytes
      ------------------------------
      | kl |    keyvalue           |   (kl) = n
      ------------------------------
.sp 3;.cp 4
.fo
File entries are arranged according to their key values,
from lowest to highest.
The binary codes of the individual characters form the
alphabet, the keys form words via this alphabet and the
words are arranged in alphabetical order.
.br
The type of file (fileType_gg00) that is created can either
be temporary or permanent (perm, temp).  At each system
startup, all temporary files that are still in existence are
implicitly deleted and all permanent files are retained.
In addition, the user alone is responsible for the
unambiguousness of the file name for temporary files.
The internal handling of temporary files differs in some
respects from the handling of permanent files, in order to
reduce access time -- at the expense of data protection.
.br
With regard to processing possibilities, a distinction is
made between primary files and inversions of primary files.
.sp
The procedure parameter procid supplies the system-internal
identification  of the process that calls the procedure.
It is required for synchronizing operations on
B* trees.
.sp 4;.cp 6
.oc _/1;2._General_File_Management_Routines
.sp 3
b01fcreate_file (t,fn,ft,stringcol_cnt,varcol_cnt_off,
.br
                 act_tree_id,e)
.sp
Generates a new, empty file with the name fn and file
type ft.  The unambiguousness of the file name is
constantly verified.
.br
The parameter with_stringcol indicates whether the table
assigned to this file contains columns of the 'LONG' type.
If this column type is present (stringcol_cnt > 0),
the number of such columns is supplied to 'stringcol_cnt'. Furthermore
(in the latter case) the offset to skip the fixed part of each record
(relative to the end of the record key) is supplied
to 'varcol_cnt_off'.
.br
In act_tree_id, the caller is supplied with the tree
identification for the file.
.br;.cp 5
One of the following messages, among others, is sent to e:
   - e_ok
   - b_duplicate_filename
   - b_shutdown
   - b_disk_not_accessible
.sp 3;.cp 6
b01tcreate_file (t,file_id,e)
.sp
Generates a new, temporary file with the file identification 'file_id'
supplies the relevant file parameters to file_id.
The unambiguousness of the file name is constantly verified.
.br;.cp 5
One of the following messages, among others, is sent to e:
   - e_ok
   - b_duplicate_filename
   - b_shutdown
   - b_disk_not_accessible
.sp 3;.cp 6
b01open_file (t,fn,act_tree_id,e)
.sp
Opens file with the name fn for further processing.
The relevant file information is supplied to act_tree_id.
.br;.cp 6
One of the following messages is sent to e:
   - e_ok
   - b_file_not_found
   - b_file_unloaded
   - b_shutdown
   - b_disk_not_accessible
.sp 3;.cp 6
b01bcreate_bytestr (t,fn,e)
.sp
Generates a new, empty byte-string file with the name fn.
The unambiguousness of the file name is constantly verified.
.br;.cp 5
One of the following messages, among others, is sent to e:
   - e_ok
   - b_duplicate_filename
   - b_shutdown
   - b_disk_not_accessible
.sp 3;.cp 6
b01vstate_fileversion (t,fn,e)
.sp
Checks whether the version number for the file fn in the file
directory matches the version number that was supplied by the
calling procedure via trans_no t.
.br;.cp 6
One of the following messages, among others, is sent to e:
   - e_ok
   - b_old_fileversion
   - b_file_not_found
   - b_shutdown
   - b_disk_not_accessible
.sp 3;.cp 6
b01set_fileversion (t, file_id, new_fileversion, new_long_cnt)
.sp
A new version number is entered in the file directory for the
file fn.
.br;.cp 5
One of the following messages, among others, is sent to e:
   - e_ok
   - b_file_not_found
   - b_shutdown
   - b_disk_not_accessible
.sp 3;.cp 6
b01treeleafnodes (t, file_id, m_fetch/m_update, old_treeleafnodes)
.sp
Case m_fetch a number of tree leaf nodes is fetched from the root node
page of the primary tree file_id into old_treeleafnodes.
Case m_update a new number of tree leaf nodes is entered from
file_id.treeleafnodes in the root node page of the primary tree file_id.
.br;.cp 5
One of the following messages, among others, is sent to e:
   - e_ok
   - b_file_not_found
   - b_shutdown
   - b_disk_not_accessible
.sp 3;.cp 6
b01fset_write_state (t,fn, on, e)
.sp
An entry is made in the file directory indicating that file fn can
be read-accessed only or if the parameter 'on' is set to TRUE
is write accessible again.
.br;.cp 5
One of the following error messages, among others, is sent to e:
   - e_ok
   - b_file_not_found
   - b_shutdown
   - b_disk_not_accessible
.sp 3;.cp 6
b01end_read_only (t,e)
.sp
An entry is made in the file directory cancelling
the read-only restriction for all files that were, up until
this point, read-only.
.br;.cp 5
One of the following error messages, among others, is sent to e:
   - e_ok
   - b_file_not_found
   - b_shutdown
   - b_disk_not_accessible
.sp 3;.cp 6
b01unload_file (t,fn,e)
.sp
If the file with the name fn is present in the file directory,
it is labelled as 'unloaded'.  The user is responsible for
ensuring that the file has already been unloaded onto another
storage medium.  The file contents are deleted, i.e. the
B* tree is deleted.
.br;.cp 6
One of the following error messages, among others, is sent to e:
   - e_ok
   - b_file_unloaded
   - b_file_not_found
   - b_shutdown
   - b_disk_not_accessible
.sp 3;.cp 6
b01reload_file (t,fn,e)
.sp
If the file with the name fn is present in the file directory, it is
labelled as 'not unloaded'.  It is also assigned a new root.
.br;.cp 6
One of the following error messages, among others, is sent to e:
   - e_ok
   - b_file_not_found
   - b_no_more_space
   - b_shutdown
   - b_disk_not_accessible
.sp 3;.cp 6
b01destroy_file (t,fn,e)
.sp
If the file with the name fn is present, it is deleted, i.e.
all file records are destroyed and the name of the file is
not retained.
.br;.cp 5
One of the following messages, among others, is sent to e:
   - e_ok
   - b_file_not_found
   - b_shutdown
   - b_disk_not_accessible
.sp 3;.cp 6
b01empty_file (t,file_id,e)
.sp
The temporary file with the identifier 'file_id' is emptied;
i.e. all file records are destroyed.  However, the file directory
for this file is retained along with the root of the associated
tree.
.br;.cp 5
One of the following messages, among others, is sent to e:
   - e_ok
   - b_shutdown
   - b_disk_not_accessible
.sp 3;.cp 6
b01treset_file (t,file_id,e)
.sp
If the temporary file with the identifier 'file_id' exists
then this file is emptied;
i.e. all file records are destroyed.
However, the file directory
for this file is retained along with the root of the associated
tree.
.br
Otherwise a new temporary file is created.
.br;.cp 5
One of the following messages, among others, is sent to e:
   - e_ok
   - b_shutdown
   - b_disk_not_accessible
.sp 3;.cp 6
b01prefix_destroy_files (t,prefix_fn,prefix_len,e)
.sp
All files that contain the prefix prefix_fn of the length
prefix_len in their file name are deleted, i.e. all file records
are destroyed and the file names are not retained.
.br;.cp 5
One of the following messages, among others, is sent to e:
   - e_ok
   - b_file_not_found
   - b_shutdown
   - b_disk_not_accessible
.sp 2;.cp 6
b01filestate (t,fn,ft,e)
.sp
Checks whether a file with the name fn exists.  If yes, the
file type defined for this file is shown in ft.  One of the
purposes of this routine is to check the unambiguousness
of a file name that is to be assigned to a temporary file.
.br;.cp 7
One of the following messages, among others, is sent to e:
   - e_ok
   - b_file_read_only
   - b_bad_file
   - b_file_unloaded
   - b_file_not_found
   - b_shutdown
   - b_disk_not_accessible
.sp 2;.cp 6
bd01invfile_state (t,fn,ft,e)
.sp
Checks whether a file with the name fn exists.  If yes, the
file type defined for this file is shown in ft.  One of the
purposes of this routine is to check the unambiguousness
of a file name that is to be assigned to a temporary file.
.br;.cp 6
One of the following messages, among others, is sent to e:
   - e_ok
   - b_bad_invfile
   - b_file_unloaded
   - b_file_not_found
   - b_shutdown
   - b_disk_not_accessible
.sp 2;.cp 6
b01rename_file (t,old,new,e)
.sp
If there is a file with the name "old" and no file with the name
"new", "old" is renamed "new".  For temporary files, external
measures must be taken to ensure that no file with the name "new"
already exists.
.br;.cp 6
One of the following messages, among others, is sent to e:
   - e_ok
   - b_file_not_found
   - b_duplicate_filename
   - b_shutdown
   - b_disk_not_accessible
.sp 2;.cp 6
b01sfile_statistic (t,fn,info,e)
.sp
Generates statistics on static memory utilization by the
file fn.  The result is sent to the buffer "info".
.br;.cp 6
One of the following messages, among others, is sent to e:
   - e_ok
   - b_file_unloaded
   - b_file_not_found
   - b_shutdown
   - b_disk_not_accessible
.sp 4;.cp 12
.oc _/1;3._System_Management
.sp 3
The following is an introduction to the routines for creating,
explicitly shutting down and restarting the base-layer
file management system.
.sp 3;.cp 4
b01create_filesystem (t,conf_desc,conf_pageptr,e)
.sp
This routine must be called during system generation.
It formats the secondary storage and initializes all data
structures used by the file management system (in the main memory
and secondary storage) in such a way that there are not yet any
files in existence and a maximum of free storage space is
available.  The prerequisite is that the number of free storage
management pages chosen is appropriately high.  The trans_no of
the calling transaction is sent to t; a description of the system
configuration must be entered in conf_desc.
.br;.cp 5
One of the following messages, among others, is sent to e:
   - e_ok
   - b_no_more_space
   - b_sysbuf_storage_exceeded
   - b_disk_not_accessible
.sp 3;.cp 4
b01shutdown_filesystem (t,log_active,e)
.sp
This routine brings about the normal shutdown of the file
management system.  Until the system is restarted, all base-layer
calls result in the acknowledgement 'b_shutdown' in parameter e.
.br;.cp 3
One of the following messages, among others, is sent to e:
   - e_ok
   - b_disk_not_accessible
.sp 3;.cp 4
b01restart_filesystem (t,fn,conf_desc,conf_pageptr,e)
.sp
This routine must be called to restart the system following a
normal shutdown or following a system failure due to an
irrecoverable error.  At this time, all temporary files that
are still present are implicitly deleted whereas permanent files
are retained unchanged. The name of the
file from which the configuration description must be read must
be entered in fn.  This description is sent to conf_desc.
.br;.cp 5
One of the following messages, among others, is sent to e:
   - e_ok
   - b_init_missing
   - b_sysbuf_storage_exceeded
   - b_disk_not_accessible
.sp 3;.cp 6
 
bd01tcheck_tree (t,root,rk,e)
.sp
This routine checks the tree structure of the tree with the root
identified as "root".  If "root" is a negative number, the absolute
value of "root" identifies a tree containing an inversion.
If the length of the key "rk" is greater than zero, the tree
structure is checked only in the immediate area of this key.
.br;.cp 6
One of the following messages, among others, is sent to e:
.br
   - e_ok
   - b_invalid_index_structure
   - b_invalid_leaves_structure
   - b_disk_not_accessible
.sp 3;.cp 6
b01verify_database (t,is_cold,NumPermPages,repair_trees,bad_file)
.sp
When this routine is called, the pages of all permanent files in
the previously deleted free storage manager that are present
in the database are labelled as used.  In this way, pages that were
labelled as used but did not belong to a file (did not belong to a
tree) are labelled as unused.
.br
The number of pages that are labelled as used following the "verify"
routine is indicated in the parameter "NumPermPages".
If, when traversing a tree, a structural error is discovered,
an attempt is made to reconstruct the correct structure.
The number of successful repair attempts is sent to "repair_trees".
.br;.cp 6
One of the following messages, among others, is sent to e:
.br
   - e_ok
   - b_shutdown
   - b_invalid_index_structure
   - b_invalid_leaves_structure
   - b_disk_not_accessible
.sp 4;.cp 12
.oc _/1;4._I/O-Routines
.sp 3
Using the following procedures, it is possible to read
from or write to individual pages in the restart and
logging areas.
.sp 2;.cp 9
 
.CM *-END-* specification -------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.fo
.oc _/1
Description:
 
A global variable 'database_state' indicates by means of
'e_ok' that the file system has been generated and is
not shut down; otherwise it contains the message 'b_shutdown'.
The existence of a file can generally be detected by accessing
the file directory.  In addition, the 'add' and 'repl' operations
are used to determine whether enough space is still available
in the secondary storage.
.sp
When a new file is being created, a tree root is requested and an
entry identifying the file is included in the file directory.
.sp
Entries in a file are stored in the leaves of a B* tree.
File routines are thus referred back to the appropriate
tree routine.  Before each tree routine is called, the operation
b30adjust_tree identifies which tree is being processed;
this means that, later on, certain information does not always
have to be carried along as a parameter.
.sp
When a checkpoint is set, only the system buffer (as necessary)
is written to the secondary storage.
.sp
If a file routine sends the message b_disk_not_accessible
to e, the physical integrity of the file system is no
longer secure!
.CM *-END-* description ---------------------------------
.sp 2
***********************************************************
.sp
.cp 10
.nf
.oc _/1
Structure:
 
.CM *-END-* structure -----------------------------------
.sp 2
**********************************************************
.sp
.cp 10
.nf
.oc _/1
.CM -lll-
Code    :
 
 
CONST
      c_nil_stringcol_cnt      = 0;
      c_concurrent             = true;
      c_ignore_svp             = true;
      c_include_strcols        = true;
      c_in_region              = true;
      c_no_tree_index          = true;
      c_only_empty             = true;
      c_conv_update            = true;
      c_set_not_get_pno        = true;
      c_emergency_shutdown     = true;
      (* *)
      MSG_STOP_CHECK_OKAY      = 'Check data finished successfully        ';
      MSG_STOP_CHECK_WITH_ERR  = 'Check data finished unsuccessfully      ';
 
 
(*------------------------------*) 
 
PROCEDURE
      b01b_check_bytestr (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
VAR
      current : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name   (bi, '====> check bytest');
t01treeid (bi, 'treeid      ', file_id);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    t.trError_gg00 := e_ok;
(*ENDIF*) 
IF  t.trError_gg00 = e_ok
THEN
    WITH current DO
        BEGIN
        t.trError_gg00 := e_ok;
        file_id.fileRoot_gg00 := NIL_PAGE_NO_GG00;
        b30current (t, file_id, m_verify, current);
        IF  t.trError_gg00 = e_ok
        THEN
            b60check_bytestr (current);
        (*ENDIF*) 
        IF  t.trError_gg00 = e_ok
        THEN
            file_id := current.curr_tree_id;
        (*ENDIF*) 
        IF  curr_lockstate = r_lock_tree
        THEN
            b75turead_unlock_tree (current);
        (*ENDIF*) 
        END;
    (*ENDWITH*) 
&ifdef TRACE
(*ENDIF*) 
t01basis_error (bi, 'check byt e ', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01bcreate_bytestr (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
VAR
      fi         : tbd_fileinfo;
      current    : tbd_current_tree;
      fn_trace   : tgg11_BdFilenameTrace;
      root_trace : tgg11_BdRootTrace;
 
BEGIN
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    fn_trace.bdfTrType_gg11 := bdtrFilename_egg11;
    fn_trace.bdfFn_gg11     := file_id.fileName_gg00;
    b120InsertTrace (t, bd, b01b_create, sizeof (fn_trace), @fn_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01name   (bi, '====> bd create by');
t01treeid (bi, 'treeid req  ', file_id);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    WITH fi DO
        BEGIN
        fi_type    := [ftsByteStr_egg00, ftsConcurrent_egg00];
        fi_state   := [];
        fi_fill1   := false;
        fi_descr   := [];
        fi_root    := NIL_PAGE_NO_GG00;
        fi_vers    := file_id.fileVersion_gg00;
        fi_col_cnt := 0;
        gg06SetNilRef (fi_user_ref)
        END;
    (*ENDWITH*) 
    b30fdir_to_treeid (fi, file_id);
    current.curr_tree_id := file_id;
    bd999CheckSpace (t, 1);
    IF  t.trError_gg00 = e_ok
    THEN
        b60new_bytestr (current);
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        fi.fi_root := current.curr_tree_id.fileRoot_gg00;
        b17add_fdir (file_id.fileName_gg00, fi, t)
        END;
    (*ENDIF*) 
    IF  t.trError_gg00 = e_duplicate_filename
    THEN
        BEGIN
        t.trError_gg00 := e_ok;
        b13pfree_pno (current.curr_tree_id.fileRoot_gg00, current);
        IF  t.trError_gg00 = e_ok
        THEN
            t.trError_gg00 := e_duplicate_filename
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        file_id := current.curr_tree_id
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    root_trace.bdrTrType_gg11 := bdtrRoot_egg11;
    root_trace.bdrRoot_gg11   := file_id.fileRoot_gg00;
    root_trace.bdrError_gg11  := t.trError_gg00;
    b120InsertTrace (t, bd, b01b_create, sizeof (root_trace), @root_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01treeid      (bi, 'new treeid  ', file_id);
t01basis_error (bi, 'create byt e', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01change_filetype (VAR t : tgg00_TransContext;
            VAR file_id  : tgg00_FileId;
            new_filetype : tgg00_FiletypeSet);
 
VAR
      fi      : tbd_fileinfo;
      current : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name     (bi, '====> change filet');
t01treeid   (bi, 'treeid      ', file_id);
t01filetype (bi, 'new filetype', new_filetype);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    b17state_fdir (file_id.fileName_gg00, fi, ftsShared_egg00 in file_id.fileType_gg00, t);
    IF  t.trError_gg00 = e_file_unloaded
    THEN
        t.trError_gg00 := e_ok;
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        b30fdir_to_treeid (fi, file_id);
        current.curr_tree_id := file_id;
        IF  ftsConcurrent_egg00 in current.curr_tree_id.fileType_gg00
        THEN
            b75tldelete_lock_tree (current, ftsTemp_egg00 in current.curr_tree_id.fileType_gg00, 10);
        (*ENDIF*) 
        WITH fi DO
            BEGIN
            fi_type := new_filetype;
            b17repl_fdir (file_id.fileName_gg00, fi, ftsShared_egg00 in file_id.fileType_gg00, t)
            END;
        (*ENDWITH*) 
        IF  current.curr_lockstate = d_lock_tree
        THEN
            b75tudelete_unlock_tree (current)
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        file_id := current.curr_tree_id;
        file_id.fileType_gg00 := new_filetype
        END;
    (*ENDIF*) 
    END;
(*ENDIF*) 
&ifdef TRACE
t01basis_error (bi, 'change ft e ', t.trError_gg00);
&endif
END;
 
(* PTS 1109905 E.Z. everything with newlong *)
(*------------------------------*) 
 
PROCEDURE
      b01check_table (VAR t : tgg00_TransContext;
            VAR file_id          : tgg00_FileId;
            long_col_cnt         : tsp00_Int2;
            new_long_col_cnt     : tsp00_Int2;
            check_long_existence : boolean);
 
VAR
      aux_err       : tgg00_BasisError;
      shcol_file_id : tgg00_FileId;
      current       : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name   (bi, '====> check table ');
t01treeid (bi, 'treeid      ', file_id);
t01int4   (bi, 'long_col_cnt', long_col_cnt);
t01int4   (bi, 'new_long_col', new_long_col_cnt);
t01bool   (bi, 'long_exist  ', check_long_existence);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    t.trError_gg00 := e_ok;
(*ENDIF*) 
IF  t.trError_gg00 = e_ok
THEN
    WITH current DO
        BEGIN
        file_id.fileRoot_gg00 := NIL_PAGE_NO_GG00;
        b30current (t, file_id, m_verify, current);
        IF  t.trError_gg00 = e_ok
        THEN
            b30check_tree (current, long_col_cnt, new_long_col_cnt,
                  check_long_existence);
        (*ENDIF*) 
        IF  t.trError_gg00 = e_ok
        THEN
            file_id := current.curr_tree_id;
        (*ENDIF*) 
        IF  curr_lockstate = r_lock_tree
        THEN
            b75turead_unlock_tree (current);
        (*ENDIF*) 
        IF  (long_col_cnt > 0) AND
            (long_col_cnt > new_long_col_cnt) AND
            (t.trError_gg00 <> e_disk_not_accessible) AND
            (t.trError_gg00 <> e_shutdown           )
        THEN
            BEGIN
            aux_err       := t.trError_gg00;
            t.trError_gg00      := e_ok;
            shcol_file_id := file_id;
            WITH shcol_file_id DO
                BEGIN
                fileTfn_gg00              := tfnShortScol_egg00;
                fileRoot_gg00             := NIL_PAGE_NO_GG00;
                fileVersion_gg00.ci2_gg00 := cgg_dummy_file_version;
                END;
            (*ENDWITH*) 
            b30current (t, shcol_file_id, m_verify, current);
            IF  t.trError_gg00 = e_ok
            THEN
                b30check_tree (current, 0, 0, check_long_existence);
            (*ENDIF*) 
            IF  curr_lockstate = r_lock_tree
            THEN
                b75turead_unlock_tree (current);
            (*ENDIF*) 
            IF  t.trError_gg00 = e_ok
            THEN
                t.trError_gg00 := aux_err
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        END;
    (*ENDWITH*) 
&ifdef TRACE
(*ENDIF*) 
t01basis_error (bi, 'check tab e ', t.trError_gg00)
&     endif
END;
 
(*------------------------------*) 
 
FUNCTION
      b01connect_allowed : boolean;
 
BEGIN
b01connect_allowed := bd10IsConnectAllowed;
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01create_filesystem (
            VAR t       : tgg00_TransContext;
            VAR DBIdent : tsp00_Line );
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd init     ');
&endif
t.trError_gg00    := e_ok;
b01bad_index_cnt  := 0;
b01downfilesystem := false;
b06init_errtxt;
(* *)
bd999CreateAllLogDevices( t.trTaskId_gg00, @DBIdent, t.trError_gg00 );
IF  t.trError_gg00 = e_ok
THEN
    bd999CreateAllDataDevices( t.trTaskId_gg00, @DBIdent, t.trError_gg00 );
(*ENDIF*) 
IF  t.trError_gg00 = e_ok
THEN
    b10create_converter (t.trTaskId_gg00, bd999TotalDataPages);
(*ENDIF*) 
IF  t.trError_gg00 = e_ok
THEN
    bd20InitDataCache (t.trTaskId_gg00, t.trError_gg00, bd999FramesAvailable, bd999TotalDataPages);
(*ENDIF*) 
IF  t.trError_gg00 = e_ok
THEN
    b75init_tree_locklist (t.trTaskId_gg00, t.trError_gg00);
(*ENDIF*) 
IF  t.trError_gg00 = e_ok
THEN
    b17create_fdir (t);
(*ENDIF*) 
IF  (t.trError_gg00 = e_ok) AND g01is_livecache
THEN
    bd91InitObjFileDir (t);
(*ENDIF*) 
IF  t.trError_gg00 <> e_ok
THEN
    bd999DetachAllDevices (t.trTaskId_gg00);
&ifdef TRACE
(*ENDIF*) 
t01basis_error (bi, 'init error  ', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
FUNCTION
      b01db_full( taskId : tsp00_TaskId ) : boolean;
 
BEGIN
b01db_full := bd10IsDbFull( taskId );
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01dbspace_statistic (VAR t : tgg00_TransContext;
            VAR info : tgg00_DbSpaceInfo);
 
BEGIN
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown;
(*ENDIF*) 
BEGIN
t.trError_gg00 := e_ok;
bd10dbspace_statistic (t, info)
END;
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01del_event (EventId   : tsp31_event_ident;
            Threshold : integer);
 
BEGIN
(* CRS 1103110 Alexander Kley 20/07/99 *)
bd10DelDBFillingEvent (EventId, Threshold * 100);
&ifdef TRACE
IF  t01trace (bi)
THEN
    BEGIN
    t01name(bi,'====> bd del event');
    t01int4(bi,'   EventId  ',ord(EventId));
    t01int4(bi,'   Threshold',Threshold);
    END;
&endif
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01del_event_dw_compr;
 
BEGIN
(*b12del_event_dw_compr;*)
&ifdef TRACE
IF  t01trace (bi)
THEN
    BEGIN
    t01name(bi,'====> bd del event');
    t01name(bi,'== dw compress  ==');
    END;
&endif
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01del_event_dw_displ;
 
BEGIN
(* b12del_event_dw_displ; *)
&ifdef TRACE
IF  t01trace (bi)
THEN
    BEGIN
    t01name(bi,'====> bd del event');
    t01name(bi,'== dw displace  ==');
    END;
&endif
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01del_event_savepoint;
 
BEGIN
(* b12del_event_savepoint;*)
&ifdef TRACE
IF  t01trace (bi)
THEN
    BEGIN
    t01name(bi,'====> bd del event');
    t01name(bi,'== savepoint off==');
    END;
&endif
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01destroy_file (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
VAR
      fn_trace   : tgg11_BdFilenameTrace;
      root_trace : tgg11_BdRootTrace;
 
      filetype : RECORD
            CASE integer OF
                1:
                    (tfn_as_set : tgg00_FiletypeSet);
                2:
                    (tfn_as_char : tsp00_C1);
                END;
            (*ENDCASE*) 
 
 
BEGIN
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    fn_trace.bdfTrType_gg11 := bdtrFilename_egg11;
    fn_trace.bdfFn_gg11     := file_id.fileName_gg00;
    b120InsertTrace (t, bd, b01destroy, sizeof (fn_trace), @fn_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01name   (bi, '====> bd destroy f');
t01treeid (bi, 'treeid      ', file_id);
&endif
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    IF  ftsTemp_egg00 in file_id.fileType_gg00
    THEN
        bd01destroy_file (t, file_id, root_trace.bdrRoot_gg11)
    ELSE
        BEGIN
        filetype.tfn_as_set := file_id.fileType_gg00;
        g01opmsg (sp3p_console, sp3m_error, csp3_b01_1_invalid_filetype,
              csp3_n_btree, 'NOT ftsTemp IN filetype '
              ,ord(filetype.tfn_as_char[1]));
        b06write_filename_and_root (file_id);
        t.trError_gg00 := e_invalid_filetype
        END;
    (*ENDIF*) 
(*ENDIF*) 
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    root_trace.bdrTrType_gg11 := bdtrRoot_egg11;
    root_trace.bdrError_gg11  := t.trError_gg00;
    b120InsertTrace (t, bd, b01destroy, sizeof (root_trace), @root_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01basis_error (bi, 'destroy err ', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
FUNCTION
      b01devsize (dev_type : tsp2_dev_type;
            devno : tsp00_Int4) : tsp00_Int4;
 
VAR
      devsize : tsp00_Int4;
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd devsize  ');
t01int4 (bi, 'dev_type    ', ord (dev_type));
t01int4 (bi, 'devno       ', devno);
&endif
CASE dev_type OF
    sp2dt_data:
        devsize := bd999DataDevSpaceSize( devno );
    sp2dt_log:
        devsize :=  bd999LogDevSpaceSize( devno );
    OTHERWISE
        devsize :=  0;
    END;
(*ENDCASE*) 
b01devsize := devsize;
&ifdef TRACE
t01int4 (bi, 'devsize     ', devsize);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01empty_file (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
VAR
      fi         : tbd_fileinfo;
      current    : tbd_current_tree;
      fn_trace   : tgg11_BdFilenameTrace;
      root_trace : tgg11_BdRootTrace;
 
BEGIN
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    fn_trace.bdfTrType_gg11 := bdtrFilename_egg11;
    fn_trace.bdfFn_gg11     := file_id.fileName_gg00;
    b120InsertTrace (t, bd, b01empty, sizeof (fn_trace), @fn_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01name (bi, '====> bd empty f  ');
t01int4 (bi, 'root        ', file_id.fileRoot_gg00);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    b17state_fdir (file_id.fileName_gg00, fi, ftsShared_egg00 in file_id.fileType_gg00, t);
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        b30fdir_to_treeid (fi, file_id);
        current.curr_tree_id := file_id;
        IF  ftsConcurrent_egg00 in current.curr_tree_id.fileType_gg00
        THEN
            b75tldelete_lock_tree (current, ftsTemp_egg00 in current.curr_tree_id.fileType_gg00, 23);
        (*ENDIF*) 
        b30release_tree (current, 0, cgg_nil_varcol_cnt_off,
              c_only_empty);
        IF  t.trError_gg00 = e_ok
        THEN
            file_id := current.curr_tree_id;
        (*ENDIF*) 
        IF  current.curr_lockstate = d_lock_tree
        THEN
            b75tudelete_unlock_tree (current)
        (*ENDIF*) 
        END
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    root_trace.bdrTrType_gg11 := bdtrRoot_egg11;
    root_trace.bdrRoot_gg11   := file_id.fileRoot_gg00;
    root_trace.bdrError_gg11  := t.trError_gg00;
    b120InsertTrace (t, bd, b01empty, sizeof (root_trace), @root_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01basis_error (bi, 'empty error ', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01end_read_only (VAR t : tgg00_TransContext);
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd end ronly');
&endif
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    b17reset_read_only (t)
    END;
(*ENDIF*) 
&ifdef TRACE
t01basis_error (bi, 'end readonly', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01fcreate_file (VAR t : tgg00_TransContext;
            VAR file_id    : tgg00_FileId;
            stringcol_cnt  : tsp00_Int2;
            varcol_cnt_off : tsp00_Int2;
            no_tree_index  : boolean);
 
BEGIN
&ifdef TRACE
t01name   (bi, '====> bd create fi');
t01treeid (bi, 'treeid req  ', file_id);
t01p2int4 (bi, 'scol count  ', stringcol_cnt
      ,        'varcol cnt o', varcol_cnt_off);
t01bool   (bi, 'no tree indx', no_tree_index);
&endif
bd01create_file (t, file_id, stringcol_cnt, varcol_cnt_off, no_tree_index)
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01filestate (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
VAR
      fi : tbd_fileinfo;
 
BEGIN
&ifdef TRACE
t01name   (bi, '====> bd state fil');
t01treeid (bi, 'treeid bef  ', file_id);
&endif
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    b17state_fdir (file_id.fileName_gg00, fi, ftsShared_egg00 IN file_id.fileType_gg00, t);
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        IF  (f_write_off IN fi.fi_state)
            OR
            (
            (f_read_only IN fi.fi_state) AND
            (NOT (hsNoLog_egg00 in file_id.fileHandling_gg00))
            )
        THEN
            t.trError_gg00 := e_file_read_only
        ELSE
            BEGIN
            IF  f_bad IN fi.fi_state
            THEN
                BEGIN
                t.trError_gg00         := e_bad_file;
                file_id.fileType_gg00 := fi.fi_type
                END
            ELSE
                IF  f_not_accessible IN fi.fi_state
                THEN
                    t.trError_gg00 := e_file_not_accessible
                (*ENDIF*) 
            (*ENDIF*) 
            END
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  (t.trError_gg00 = e_ok) OR (t.trError_gg00 = e_file_read_only)
    THEN
        b30fdir_to_treeid (fi, file_id)
    (*ENDIF*) 
    END;
(*ENDIF*) 
&ifdef TRACE
t01treeid      (bi, 'treeid after', file_id);
t01basis_error (bi, 'state err   ', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01fn_new_and_unload (VAR t : tgg00_TransContext;
            VAR orig_id : tgg00_FileId;
            VAR new_id  : tgg00_FileId);
 
VAR
      fi : tbd_fileinfo;
 
BEGIN
&ifdef TRACE
t01name   (bi, '====> fn new and u');
t01treeid (bi, 'orig treeid ', orig_id);
t01treeid (bi, 'new treeid b', new_id);
&endif
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    b17state_fdir (orig_id.fileName_gg00, fi, ftsShared_egg00 in orig_id.fileType_gg00,t);
    IF  t.trError_gg00 = e_file_unloaded
    THEN
        t.trError_gg00 := e_ok;
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        WITH fi DO
            BEGIN
            fi_root   := NIL_PAGE_NO_GG00;
            fi_state  := fi_state + [f_unloaded];
            fi_vers   := new_id.fileVersion_gg00
            END;
        (*ENDWITH*) 
        new_id.fileType_gg00 := orig_id.fileType_gg00;
        new_id.fileRoot_gg00 := NIL_PAGE_NO_GG00;
        b17add_fdir (new_id.fileName_gg00, fi, t);
        END
    (*ENDIF*) 
    END;
(*ENDIF*) 
&ifdef TRACE
t01treeid      (bi, 'new treeid a', new_id);
t01basis_error (bi, 'fn new error', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01fset_write_state (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId;
            on          : boolean);
 
VAR
      fi      : tbd_fileinfo;
      current : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name   (bi, '====> bd fset_stat');
t01bool   (bi, 'write on    ', on);
t01treeid (bi, 'treeid      ', file_id);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    b17state_fdir (file_id.fileName_gg00, fi, ftsShared_egg00 in file_id.fileType_gg00, t);
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        b30fdir_to_treeid (fi, file_id);
        current.curr_tree_id := file_id;
        IF  t.trError_gg00 = e_ok
        THEN
            BEGIN
            IF  ftsConcurrent_egg00 in current.curr_tree_id.fileType_gg00
            THEN
                b75tldelete_lock_tree (current, c_ignore_svp, 11); (* PTS 1106058 TS 2000-03-28 *)
            (*ENDIF*) 
            IF  on
            THEN
                b30sub_filestate (current, [f_write_off])
            ELSE
                b30add_filestate (current, [f_write_off]);
            (*ENDIF*) 
            IF  t.trError_gg00 = e_ok
            THEN
                b17set_filestate (file_id.fileName_gg00, t, [f_write_off], on);
            (*ENDIF*) 
            IF  current.curr_lockstate = d_lock_tree
            THEN
                b75tudelete_unlock_tree (current)
            (*ENDIF*) 
            END
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    END;
(*ENDIF*) 
&ifdef TRACE
t01basis_error (bi, 'fset_state e', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
FUNCTION
      b01get_bad_index_cnt (pid : tsp00_TaskId) : tsp00_Int4;
 
BEGIN
b01get_bad_index_cnt := b01bad_index_cnt;
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01get_bad_indexid (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
VAR
      fi : tbd_fileinfo;
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd get bad i');
&endif
REPEAT
    IF  b01downfilesystem
    THEN
        t.trError_gg00 := e_shutdown
    ELSE
        BEGIN
        t.trError_gg00 := e_ok;
        b17succ_fdir (file_id.fileName_gg00, file_id.fileName_gg00, fi, c_concurrent,
              t, NOT c_include_strcols);
        END;
    (*ENDIF*) 
UNTIL
    (t.trError_gg00 <> e_ok) OR (f_not_accessible in fi.fi_state);
(*ENDREPEAT*) 
IF  t.trError_gg00 = e_file_not_found
THEN
    t.trError_gg00 := e_no_next_record;
&ifdef TRACE
(*ENDIF*) 
t01treeid      (bi, 'bad treeid  ', file_id);
t01basis_error (bi, 'get bad inde',t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01get_data_cache_workload (VAR t : tgg00_TransContext;
            VAR DataCacheSize      : tsp00_Int4;
            VAR OmsHistoryPageCnt  : tsp00_Int4;
            VAR OmsDataPageCnt     : tsp00_Int4;
            VAR SqlDataPageCnt     : tsp00_Int4);
 
BEGIN
&ifdef TRACE
t01name (bi, '===> bd cache stat');
&endif
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    (* PTS 1111572 E.Z. *)
    bd20GetWorkloadCounter (DataCacheSize, OmsHistoryPageCnt,
          OmsDataPageCnt, SqlDataPageCnt);
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01get_devname (
            dev_type    : tsp2_dev_type;
            devno       : tsp00_Int4;
            VAR devname : tsp2_devname);
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd get devna');
t01int4 (bi, 'dev_type    ', ord (dev_type));
t01int4 (bi, 'devno       ', devno);
&endif
CASE dev_type OF
    sp2dt_data:
        bd999GetDataDevName( devno, devname );
    sp2dt_log:
        bd999GetLogDevName( devno, devname );
    OTHERWISE
        devname := b01blankfilename
    END;
(*ENDCASE*) 
&ifdef TRACE
t01vffn (bi, 'devname     ', devname);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01get_events (VAR ShortEventDesc : tsp31_short_event_desc);
 
CONST
      cGetOverFlowEvents  = true;
      cGetUnderFlowEvents = false;
 
BEGIN
CASE ShortEventDesc.sp31sed_ident OF
    sp31ei_db_filling_above_limit:
        bd10GetDBFillingEventSet (ShortEventDesc, cGetOverFlowEvents);
    sp31ei_db_filling_below_limit:
        bd10GetDBFillingEventSet (ShortEventDesc, cGetUnderFlowEvents);
    sp31ei_dw_compr :
        ;
    (* b12get_event_dw_compr (ShortEventDesc); *)
    sp31ei_dw_displ :
        ;
    (* b12get_event_dw_displ (ShortEventDesc); *)
    sp31ei_savepoint :
        ;
    (* b12get_event_savepoint (ShortEventDesc); *)
    END
(*ENDCASE*) 
END;
 
(* PTS 1107952 E.Z. *)
(*------------------------------*) 
 
PROCEDURE
      b01lg_create_log_file (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
BEGIN
&ifdef TRACE
t01name  (bi, '====> bd lg create');
&endif
bd01create_file (t, file_id, c_nil_stringcol_cnt, cgg_nil_varcol_cnt_off, c_no_tree_index);
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01ldestroy_long_file (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
VAR
      fn_trace   : tgg11_BdFilenameTrace;
      root_trace : tgg11_BdRootTrace;
 
      filetype: RECORD
            CASE integer OF
                1:
                    (tfn_as_set : tgg00_FiletypeSet);
                2:
                    (tfn_as_char : tsp00_C1);
                END;
            (*ENDCASE*) 
 
 
BEGIN
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    fn_trace.bdfTrType_gg11 := bdtrFilename_egg11;
    fn_trace.bdfFn_gg11     := file_id.fileName_gg00;
    b120InsertTrace (t, bd, b01destroy, sizeof (fn_trace), @fn_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01name   (bi, '====> bd ldestr lf');
t01treeid (bi, 'treeid      ', file_id);
&endif
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    IF  (ftsPerm_egg00 in file_id.fileType_gg00) OR
        (ftsByteStr_egg00 in file_id.fileType_gg00)
    THEN
        bd01destroy_file (t, file_id, root_trace.bdrRoot_gg11)
    ELSE
        BEGIN
        filetype.tfn_as_set := file_id.fileType_gg00;
        g01opmsg (sp3p_console, sp3m_error, csp3_b01_2_invalid_filetype,
              csp3_n_btree,  'ftsTemp IN filetype     '
              ,ord(filetype.tfn_as_char[1]));
        b06write_filename_and_root (file_id);
        t.trError_gg00 := e_invalid_filetype
        END;
    (*ENDIF*) 
(*ENDIF*) 
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    root_trace.bdrTrType_gg11 := bdtrRoot_egg11;
    root_trace.bdrError_gg11  := t.trError_gg00;
    b120InsertTrace (t, bd, b01destroy, sizeof (root_trace), @root_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01basis_error (bi, 'ldestroy err', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01move_filecontent (VAR t : tgg00_TransContext;
            VAR source_id : tgg00_FileId;
            VAR target_id : tgg00_FileId);
 
VAR
      fi        : tbd_fileinfo;
      current   : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name   (bi, '====> bd move file');
t01treeid (bi, 'source file ', source_id);
t01treeid (bi, 'target file ', target_id);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    b17state_fdir (target_id.fileName_gg00, fi, ftsShared_egg00 in target_id.fileType_gg00, t);
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        IF  target_id.fileRoot_gg00 = NIL_PAGE_NO_GG00
        THEN
            b30fdir_to_treeid (fi, target_id);
        (*ENDIF*) 
        IF  source_id.fileRoot_gg00 = NIL_PAGE_NO_GG00
        THEN
            BEGIN
            b17state_fdir (source_id.fileName_gg00, fi, ftsShared_egg00 in
                  source_id.fileType_gg00, t);
            IF  t.trError_gg00 = e_ok
            THEN
                b30fdir_to_treeid (fi, source_id)
            (*ENDIF*) 
            END
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        current.curr_tree_id := target_id;
        b30release_tree (current, 0, cgg_nil_varcol_cnt_off,
              c_only_empty);
        IF  t.trError_gg00 = e_ok
        THEN
            BEGIN
            b30cinit_current (t, current);
            current.curr_tree_id := source_id;
            b50change_treeroot (source_id.fileRoot_gg00, target_id.fileRoot_gg00,
                  current)
            END
        (*ENDIF*) 
        END
    (*ENDIF*) 
    END;
(*ENDIF*) 
&ifdef TRACE
t01basis_error (bi, 'move error  ', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01next_bad_dev (pid : tsp00_TaskId;
            VAR dev_type   : tsp2_dev_type;
            VAR devno      : tsp00_Int4;
            VAR devname    : tsp2_devname;
            VAR really_bad : boolean);
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd next_badd');
&endif
really_bad  := true;
devname     := b01blankfilename;
dev_type    := sp2dt_trace;
devno       := 1;
&ifdef TRACE
t01int4  (bi, 'dev_type    ', ord (dev_type));
t01vffn  (bi, 'devname     ', devname);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01next_dev_info (
            TaskId              : tsp00_TaskId;
            VAR dev_no          : tsp00_Int4;
            VAR dev_type        : tsp2_dev_type;
            VAR dev_name        : tsp2_devname;
            VAR dev_size        : tsp00_Int4;
            VAR dev_used_blocks : tsp00_Int4;
            VAR dev_online      : boolean;
            VAR dev_state       : tsp00_C18);
 
VAR
      found : boolean;
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd next_dinf');
&endif
dev_name        := b01blankfilename;
dev_size        := 0;
dev_used_blocks := 0;
IF  dev_no < 0
THEN
    BEGIN
    dev_no   := 1;
    dev_type := sp2dt_data
    END
ELSE
    dev_no := dev_no + 1;
(*ENDIF*) 
found := false;
WHILE (NOT found) AND (dev_type <> sp2dt_trace) DO
    CASE dev_type OF
        sp2dt_data :
            IF  dev_no <= bd999NoOfDataDevices
            THEN
                BEGIN
                bd999GetDataDevName (dev_no, dev_name);
                dev_size        := bd999DataDevSpaceSize (dev_no);
                dev_used_blocks := b11_blocks_used (dev_no);
                dev_state       := 'NotMirrored       ';
                dev_online      := true;
                found           := true
                END
            ELSE
                BEGIN
                dev_no   := 1;
                dev_type := sp2dt_log;
                found    := false
                END;
            (*ENDIF*) 
        sp2dt_log :
            IF  dev_no <= bd999NoOfLogDevices
            THEN
                BEGIN
                bd999GetLogDevName (dev_no, dev_name);
                dev_size     := bd999LogDevSpaceSize (dev_no);
                dev_state    := 'NotMirrored       ';
                dev_online   := true;
                found        := true
                END
            ELSE
                BEGIN
                dev_no   := 1;
                dev_type := sp2dt_trace;
                found    := false
                END;
            (*ENDIF*) 
        OTHERWISE
            dev_type := sp2dt_trace;
        END;
    (*ENDCASE*) 
(*ENDWHILE*) 
IF  NOT found
THEN
    dev_no := -1;
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01next_fdir_entry (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
VAR
      found : boolean;
      fi    : tbd_fileinfo;
 
BEGIN
&ifdef TRACE
t01name     (bi, '====> bd next fdir');
t01filename (bi, file_id.fileName_gg00);
&endif
found := false;
REPEAT
    IF  b01downfilesystem
    THEN
        t.trError_gg00 := e_shutdown
    ELSE
        BEGIN
        t.trError_gg00 := e_ok;
        b17succ_fdir (file_id.fileName_gg00, file_id.fileName_gg00, fi, c_concurrent,
              t, c_include_strcols);
        IF  t.trError_gg00 = e_ok
        THEN
            BEGIN
            found := true;
            b30fdir_to_treeid (fi, file_id);
            END
        ELSE
            IF  (t.trError_gg00             = e_file_not_found) AND
                (file_id.fileTfn_gg00 = tfnColumn_egg00 )
            THEN
                BEGIN
                file_id.fileName_gg00 := cgg_zero_fn;
                file_id.fileTfn_gg00  := tfnTempInv_egg00;
                t.trError_gg00        := e_ok;
                END
            (*ENDIF*) 
        (*ENDIF*) 
        END;
    (*ENDIF*) 
UNTIL
    (t.trError_gg00 <> e_ok) OR found;
(*ENDREPEAT*) 
IF  t.trError_gg00 = e_file_not_found
THEN
    t.trError_gg00 := e_no_next_record;
&ifdef TRACE
(*ENDIF*) 
t01treeid      (bi, 'next treeid ', file_id);
t01basis_error (bi, 'next fdir er',t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
FUNCTION
      b01no_of_data_devs : tsp00_Int4;
 
VAR
      no_of_devs : tsp00_Int4;
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd no data d');
&endif
no_of_devs         := bd999NoOfDataDevices;
b01no_of_data_devs := no_of_devs;
&ifdef TRACE
t01int4 (bi, 'no data devs', no_of_devs);
&endif
END;
 
(*------------------------------*) 
 
FUNCTION
      b01no_of_log_devs : tsp00_Int4;
 
VAR
      no_of_devs : tsp00_Int4;
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd no log de');
&endif
no_of_devs := bd999NoOfLogDevices;
b01no_of_log_devs := no_of_devs;
&ifdef TRACE
t01int4 (bi, 'no log devs ', no_of_devs);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01pdestroy_perm_file (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
VAR
      fn_trace   : tgg11_BdFilenameTrace;
      root_trace : tgg11_BdRootTrace;
 
      filetype : RECORD
            CASE integer OF
                1:
                    (tfn_as_set : tgg00_FiletypeSet);
                2:
                    (tfn_as_char : tsp00_C1);
                END;
            (*ENDCASE*) 
 
 
BEGIN
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    fn_trace.bdfTrType_gg11 := bdtrFilename_egg11;
    fn_trace.bdfFn_gg11     := file_id.fileName_gg00;
    b120InsertTrace (t, bd, b01destroy, sizeof (fn_trace), @fn_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01name   (bi, '====> bd pdestro f');
t01treeid (bi, 'treeid      ', file_id);
&endif
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    IF  (ftsPerm_egg00 in file_id.fileType_gg00   ) OR
        (ftsByteStr_egg00 in file_id.fileType_gg00) OR
        (ftsObject_egg00 in file_id.fileType_gg00 )
    THEN
        bd01destroy_file (t, file_id, root_trace.bdrRoot_gg11)
    ELSE
        BEGIN
        filetype.tfn_as_set := file_id.fileType_gg00;
        g01opmsg (sp3p_console, sp3m_error, csp3_b01_3_invalid_filetype,
              csp3_n_btree, 'ftsTemp IN filetype     '
              ,ord(filetype.tfn_as_char[1]));
        b06write_filename_and_root (file_id);
        t.trError_gg00 := e_invalid_filetype
        END;
    (*ENDIF*) 
(*ENDIF*) 
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    IF  t.trError_gg00 = e_file_not_found
    THEN
        root_trace.bdrRoot_gg11 := NIL_PAGE_NO_GG00;
    (*ENDIF*) 
    root_trace.bdrTrType_gg11 := bdtrRoot_egg11;
    root_trace.bdrError_gg11  := t.trError_gg00;
    b120InsertTrace (t, bd, b01destroy, sizeof (root_trace), @root_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01basis_error (bi, 'pdestroy err', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01prefix_destroy_files (VAR t : tgg00_TransContext;
            VAR prefix_fn : tgg00_Filename;
            prefix_len    : integer);
 
VAR
      first        : boolean;
      shared_phase : boolean;
      aux_file_was_inv : boolean;
      fi           : tbd_fileinfo;
      prefix       : tgg00_Filename;
      file_id      : tgg00_FileId;
      current      : tbd_current_tree;
      fn_trace     : tgg11_BdFilenameTrace;
      root_trace   : tgg11_BdRootTrace;
 
BEGIN
&ifdef TRACE
t01name     (bi, '====> bd prefix de');
t01filename (bi, prefix_fn);
t01int4     (bi, 'prefix len  ', prefix_len);
&endif
shared_phase := true;
prefix       := prefix_fn;
first        := true;
file_id      := b01niltree_id;
REPEAT
    b30cinit_current (t, current);
    IF  b01downfilesystem
    THEN
        t.trError_gg00 := e_shutdown
    ELSE
        BEGIN
        t.trError_gg00 := e_ok;
        current.curr_tree_id.fileBdUse_gg00 :=
              current.curr_tree_id.fileBdUse_gg00 + [bd_release_acc];
        current.curr_action := m_drop;
        IF  first
        THEN
            BEGIN
            first := false;
            file_id.fileName_gg00 := prefix;
            b17del_fdir (prefix_fn, fi, shared_phase, t);
            IF  t.trError_gg00 = e_file_not_found
            THEN
                b17next_del_fdir (prefix, prefix_len, file_id.fileName_gg00,
                      fi, shared_phase, t)
            (*ENDIF*) 
            END
        ELSE
            b17next_del_fdir (prefix, prefix_len, file_id.fileName_gg00,
                  fi, shared_phase, t);
        (*ENDIF*) 
        IF  (t.trError_gg00 = e_ok)
            AND
            (g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00)
        THEN
            BEGIN
            fn_trace.bdfTrType_gg11 := bdtrFilename_egg11;
            fn_trace.bdfFn_gg11     := file_id.fileName_gg00;
            b120InsertTrace (t, bd, b01p_destroy, sizeof (fn_trace), @fn_trace)
            END;
&       ifdef TRACE
        (*ENDIF*) 
        IF  t.trError_gg00 = e_ok
        THEN
            BEGIN
            t01sname    (bi, 'destroyed:  ');
            t01filename (bi, file_id.fileName_gg00)
            END;
&       endif
        (*ENDIF*) 
        IF  (t.trError_gg00 = e_ok)
            AND
            (fi.fi_root <> NIL_PAGE_NO_GG00)
        THEN
            BEGIN
            b30fdir_to_treeid (fi, file_id);
            current.curr_tree_id := file_id;
            aux_file_was_inv     :=
                  (file_id.fileTfn_gg00 = tfnAux_egg00 ) AND
                  (g04inv_tfn (file_id.fileOldTfn_gg00));
            IF  (ftsConcurrent_egg00 in fi.fi_type)
                AND
                NOT aux_file_was_inv
            THEN
                b75tldelete_lock_tree (current, c_ignore_svp, 12);
            (*ENDIF*) 
            IF  aux_file_was_inv
            THEN
                bd03ReleaseInvTree (current.curr_trans^, current.curr_tree_id)
            ELSE
                IF  ftsByteStr_egg00 in fi.fi_type
                THEN
                    b60release_bytestr (current)
                ELSE
                    BEGIN
&                   ifdef TRACE
                    t01int4 (bi, 'scol count  ', fi.fi_col_cnt);
&                   endif
                    IF  (fi.fi_col_cnt > 0) AND
                        (current.curr_tree_id.fileAuxCnt_gg00 < 0)
                    THEN
                        (* is set when executing m_change, mm_key *)
                        b30release_tree (current, 0, cgg_nil_varcol_cnt_off,
                              NOT c_only_empty)
                    ELSE
                        IF  fid_new_long_col in fi.fi_descr
                        THEN
                            b30release_tree (current, fi.fi_col_cnt,
                                  fi.fi_var_col_cnt_pos, NOT c_only_empty)
                        ELSE
                            b30release_tree (current, fi.fi_col_cnt,
                                  cgg_nil_varcol_cnt_off, NOT c_only_empty);
                        (*ENDIF*) 
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
            (*ENDIF*) 
            IF  t.trError_gg00 = e_bad_datapage
            THEN
                t.trError_gg00 := e_ok;
            (*ENDIF*) 
            IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
            THEN
                BEGIN
                root_trace.bdrTrType_gg11 := bdtrRoot_egg11;
                root_trace.bdrRoot_gg11   := file_id.fileRoot_gg00;
                root_trace.bdrError_gg11  := t.trError_gg00;
                b120InsertTrace (t, bd, b01p_destroy, sizeof (root_trace), @root_trace)
                END
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        IF  t.trError_gg00 = e_file_unloaded
        THEN
            t.trError_gg00 := e_ok;
        (*ENDIF*) 
        current.curr_tree_id.fileBdUse_gg00 :=
              current.curr_tree_id.fileBdUse_gg00 - [bd_release_acc];
        IF  current.curr_lockstate = d_lock_tree
        THEN
            b75tudelete_unlock_tree (current)
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  shared_phase AND (t.trError_gg00 = e_file_not_found)
    THEN
        BEGIN
        t.trError_gg00     := e_ok;
        shared_phase := false;
        prefix       := prefix_fn;
        first        := true;
        file_id      := b01niltree_id;
        END;
    (*ENDIF*) 
UNTIL
    (t.trError_gg00 <> e_ok);
(*ENDREPEAT*) 
IF  t.trError_gg00 = e_file_not_found
THEN
    t.trError_gg00 := e_ok;
&ifdef TRACE
(*ENDIF*) 
t01basis_error (bi, 'prefix destr', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01psclear_save_pages_psm (VAR t : tgg00_TransContext);
 
BEGIN
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    t.trError_gg00 := e_ok;
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01pverify_participant (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId;
            is_cold     : boolean);
 
VAR
      NumPages    : tsp00_Int4;
      fi          : tbd_fileinfo;
      current     : tbd_current_tree;
      VerifyTrace : tgg11_BdVerifyTrace;
 
BEGIN
&ifdef TRACE
t01bool   (bi, 'verify cold ', is_cold);
t01treeid (bi, 'treeid      ', file_id);
&endif
NumPages := 0;
b30cinit_current (t, current);
WITH t DO
    BEGIN
    IF  g04inv_tfn (file_id.fileTfn_gg00)
    THEN
        bd03VerifyInvTree (t, file_id, is_cold, NumPages)
    ELSE
        BEGIN
        IF  b01downfilesystem
        THEN
            trError_gg00 := e_shutdown
        ELSE
            BEGIN
            trError_gg00 := e_ok;
            b17state_fdir (file_id.fileName_gg00, fi, ftsShared_egg00 IN file_id.fileType_gg00, t);
            IF  trError_gg00 <> e_ok
            THEN
                BEGIN
                IF  trError_gg00 = e_file_not_found
                THEN
                    trError_gg00 := e_ok
                (*ENDIF*) 
                END
            ELSE
                WITH current DO
                    BEGIN
                    b30fdir_to_treeid (fi, file_id);
                    curr_tree_id := file_id;
                    curr_action  := m_verify;
                    IF  (NOT is_cold                                 ) AND
                        (ftsConcurrent_egg00 IN file_id.fileType_gg00)
                    THEN
                        b75tlread_lock_tree (current, 25);
                    (*ENDIF*) 
                    IF  ftsByteStr_egg00 in fi.fi_type
                    THEN
                        b60verify_bytestr (current, is_cold, NumPages)
                    ELSE
                        BEGIN
                        IF  file_id.fileTfn_gg00 = tfnObj_egg00
                        THEN
                            bd92VerifyObjFile (current, is_cold)
                        ELSE
                            IF  file_id.fileTfn_gg00 <> tfnContObj_egg00
                            THEN
                                BEGIN
                                (* nothing needs to be done for object continuation files  *)
                                (* since they get already checked when the verify routine  *)
                                (* is called for the corresponding primary file of type    *)
                                (* tfnObj_egg00                                            *)
                                b30verify_tree (current, is_cold, NumPages);
                                END;
                            (*ENDIF*) 
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                    IF  (NOT is_cold                 ) AND
                        (curr_lockstate = r_lock_tree)
                    THEN
                        b75turead_unlock_tree (current)
                    (*ENDIF*) 
                    END
                (*ENDWITH*) 
            (*ENDIF*) 
            END
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  (trError_gg00 <> e_ok) OR (g01vtrace.vtrAll_gg00)
    THEN
        BEGIN
        VerifyTrace.bdvRootTrace_gg11.bdrTrType_gg11 := bdtrVerify_egg11;
        VerifyTrace.bdvRootTrace_gg11.bdrError_gg11  := trError_gg00;
        VerifyTrace.bdvRootTrace_gg11.bdrRoot_gg11   := file_id.fileRoot_gg00;
        VerifyTrace.bdvNumPages_gg11                 := NumPages;
        VerifyTrace.bdvFn_gg11                       := file_id.fileName_gg00;
        b120InsertTrace (t, bd, b01verify, sizeof (VerifyTrace), @VerifyTrace)
        END
    (*ENDIF*) 
    END;
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
FUNCTION
      b01rec_align (len : tsp00_Int4): tsp00_Int4;
 
BEGIN
b01rec_align := ((len + REC_ALIGN_BD00 - 1) DIV REC_ALIGN_BD00) * REC_ALIGN_BD00
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01reload_file (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
VAR
      fi      : tbd_fileinfo;
      current : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name   (bi, '====> bd reload fi');
t01treeid (bi, 'treeid bef  ', file_id);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    b17state_fdir (file_id.fileName_gg00, fi, ftsShared_egg00 in file_id.fileType_gg00,t);
    IF  t.trError_gg00 = e_file_unloaded
    THEN
        BEGIN
        t.trError_gg00 := e_ok;
        b30fdir_to_treeid (fi, file_id);
        file_id.fileVersion_gg00 := fi.fi_vers;
        current.curr_tree_id     := file_id;
        bd999CheckSpace (t, 1);
        IF  t.trError_gg00 = e_ok
        THEN
            BEGIN
            IF  ftsByteStr_egg00 in fi.fi_type
            THEN
                BEGIN
                b60new_bytestr (current);
                IF  t.trError_gg00 = e_ok
                THEN
                    fi.fi_root := current.curr_tree_id.fileRoot_gg00
                (*ENDIF*) 
                END
            ELSE
                b30new_tree (fi, current)
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        IF  t.trError_gg00 = e_ok
        THEN
            BEGIN
            IF  ftsConcurrent_egg00 in current.curr_tree_id.fileType_gg00
            THEN
                b75tldelete_lock_tree (current, ftsTemp_egg00 in current.curr_tree_id.fileType_gg00, 13);
            (*ENDIF*) 
            fi.fi_state := fi.fi_state - [f_unloaded];
            b17repl_fdir (file_id.fileName_gg00, fi,
                  ftsShared_egg00 in file_id.fileType_gg00, t);
            IF  (t.trError_gg00 = e_ok) AND (f_read_only in fi.fi_state)
            THEN
                b30add_filestate (current, [f_read_only]);
            (*ENDIF*) 
            IF  current.curr_lockstate = d_lock_tree
            THEN
                b75tudelete_unlock_tree (current)
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        IF  t.trError_gg00 = e_ok
        THEN
            file_id := current.curr_tree_id
        (*ENDIF*) 
        END
    (*ENDIF*) 
    END;
(*ENDIF*) 
&ifdef TRACE
t01treeid      (bi, 'treeid after', file_id);
t01basis_error (bi, 'reload err  ', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01rename_file (VAR t : tgg00_TransContext;
            VAR old_id : tgg00_FileId;
            VAR new_id : tgg00_FileId);
 
VAR
      old_root     : tsp00_PageNo;
      fi           : tbd_fileinfo;
      new_fi       : tbd_fileinfo;
      rename_trace : tgg11_BdRenameTrace;
      root_trace   : tgg11_BdRootTrace;
 
BEGIN
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    rename_trace.bdrnTrType_gg11 := bdtrRename_egg11;
    rename_trace.bdrnOldFn_gg11  := old_id.fileName_gg00;
    rename_trace.bdrnNewFn_gg11  := new_id.fileName_gg00;
    b120InsertTrace (t, bd, b01rename, sizeof (rename_trace), @rename_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01name   (bi, '====> bd rename fi');
t01treeid (bi, 'old treeid  ', old_id);
t01treeid (bi, 'new treeid b', new_id);
&endif
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    IF  old_id.fileName_gg00 <> new_id.fileName_gg00
    THEN
        BEGIN
        b17state_fdir (old_id.fileName_gg00, fi, ftsShared_egg00 in old_id.fileType_gg00, t);
        IF  t.trError_gg00 = e_file_unloaded
        THEN
            t.trError_gg00 := e_ok;
        (*ENDIF*) 
        IF  t.trError_gg00 = e_ok
        THEN
            BEGIN
            old_root := fi.fi_root;
            new_fi   := fi;
            b17state_fdir (new_id.fileName_gg00, fi, ftsShared_egg00 in
                  new_id.fileType_gg00, t);
            IF  t.trError_gg00 = e_file_unloaded
            THEN
                t.trError_gg00 := e_ok;
            (*ENDIF*) 
            IF  t.trError_gg00 = e_ok
            THEN
                BEGIN
                IF  fi.fi_root = old_root
                THEN
                    (* old was already renamed before *)
                    BEGIN
                    new_id.fileRoot_gg00 := old_root;
                    new_id.fileType_gg00 := old_id.fileType_gg00;
                    b17del_fdir (old_id.fileName_gg00, fi,
                          ftsShared_egg00 in old_id.fileType_gg00, t);
                    IF  t.trError_gg00 = e_file_unloaded
                    THEN
                        t.trError_gg00 := e_ok
                    (*ENDIF*) 
                    END
                ELSE
                    t.trError_gg00 := e_duplicate_filename
                (*ENDIF*) 
                END
            ELSE
                BEGIN
                IF  t.trError_gg00 = e_file_not_found
                THEN
                    BEGIN
                    b17add_fdir (new_id.fileName_gg00, new_fi, t);
                    IF  t.trError_gg00 = e_ok
                    THEN
                        BEGIN
                        new_id.fileRoot_gg00 := old_root;
                        new_id.fileType_gg00 := old_id.fileType_gg00;
                        b17del_fdir (old_id.fileName_gg00, fi,
                              ftsShared_egg00 in old_id.fileType_gg00, t);
                        IF  t.trError_gg00 = e_file_unloaded
                        THEN
                            t.trError_gg00 := e_ok
                        (*ENDIF*) 
                        END
                    (*ENDIF*) 
                    END
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            IF  (t.trError_gg00 = e_ok) AND (f_not_accessible IN fi.fi_state)
            THEN
                BEGIN
                IF  (old_id.fileTfn_gg00 = tfnAux_egg00) AND
                    (g04inv_tfn (new_id.fileTfn_gg00)  )
                THEN
                    BEGIN
                    b01bad_index_cnt := succ (b01bad_index_cnt);
                    END
                ELSE
                    IF  g04inv_tfn (old_id.fileTfn_gg00    ) AND
                        (new_id.fileTfn_gg00 = tfnAux_egg00)
                    THEN
                        BEGIN
                        b01bad_index_cnt := pred (b01bad_index_cnt);
                        IF  b01bad_index_cnt < 0
                        THEN
                            b01bad_index_cnt := 0;
                        (*ENDIF*) 
                        END
                    (*ENDIF*) 
                (*ENDIF*) 
                END
            (*ENDIF*) 
            END
        (*ENDIF*) 
        END
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    root_trace.bdrTrType_gg11 := bdtrRoot_egg11;
    root_trace.bdrRoot_gg11   := new_id.fileRoot_gg00;
    root_trace.bdrError_gg11  := t.trError_gg00;
    b120InsertTrace (t, bd, b01rename, sizeof (root_trace), @root_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01treeid      (bi, 'new treeid a', new_id);
t01basis_error (bi, 'rename err  ', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01reset_monitor (part : tgg00_MonitorPart);
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd reset mon');
&endif
b73init_ref_statistic (part);
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01restart_filesystem (VAR t : tgg00_TransContext;
            IncrementConvVersion : boolean);
 
VAR
      NumVerifyServer : tsp00_Int4;
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd restart  ');
&endif
t.trError_gg00     := e_ok;
b01bad_index_cnt   := 0;
b01downfilesystem  := false;
b06init_errtxt;
IF  t.trError_gg00 = e_ok
THEN
    BEGIN
    bd999AttachAllDevices( t );
    IF  t.trError_gg00 <> e_ok
    THEN
        BEGIN
        bd999DetachAllDevices (t.trTaskId_gg00);
        b01downfilesystem := true
        END
    (*ENDIF*) 
    END
ELSE
    BEGIN
    b01downfilesystem := true
    END;
(*ENDIF*) 
IF  t.trError_gg00 = e_ok
THEN
    BEGIN
    k57init_restartrec_handling (t);
    IF  t.trError_gg00 = e_ok
    THEN
        b10rc_restart_converter(t,
              k57restartrec^.rstConverterVersion_kb00,
              bd999TotalDataPages,
              IncrementConvVersion,
              k57restartrec^.rstLastSaveDataSuccessful_kb00,
              k57restartrec^.rstConfigParam_kb00);
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        bd20InitDataCache (t.trTaskId_gg00, t.trError_gg00, bd999FramesAvailable, bd999TotalDataPages);
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        b75init_tree_locklist (t.trTaskId_gg00, t.trError_gg00);
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        b17restart_fdir (t, kb57GetFdir, kb57GetLongFdir);
    (*ENDIF*) 
    IF  t.trError_gg00 <> e_ok
    THEN
        BEGIN
        bd999DetachAllDevices (t.trTaskId_gg00);
        b01downfilesystem := true
        END
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  t.trError_gg00 = e_ok
THEN
    BEGIN
    bd01tcheck_tree (t, bd17GetFdirRoot );
    IF  (t.trError_gg00 = e_ok) AND IncrementConvVersion
    THEN
        bd01calc_bad_index_cnt (t);
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok (* PTS 1111179 TS 2001-07-30 *)
    THEN
        BEGIN
        bd999EnableDataWriter (t.trTaskId_gg00);
        END;
    (* PTS 1114877 UH 2002-03-18 *)
    (*ENDIF*) 
    kb560CheckKernelVersionForMigration (k57restartrec^.rstReleaseVersion_kb00);
    IF  g01is_livecache AND (t.trError_gg00 = e_ok)
    THEN
        BEGIN
        kb560CreateHistoryManager (t);
        IF  t.trError_gg00 = e_ok
        THEN
            bd91InitObjFileDir (t);
        (* PTS 1113635 FF migration because of new lock protocol needed *)
        (*ENDIF*) 
        IF  (t.trError_gg00 = e_ok) AND IncrementConvVersion AND
            (0 < bd91MigrationNeeded( k57restartrec^.rstReleaseVersion_kb00 ))
        THEN
            BEGIN
            NumVerifyServer :=
                  bd01UsableServerForParallelExecution (
                  t.trTaskId_gg00, m_migrate_obj_files, NOT c_in_region);
            bd30ObjFileCoordinator (t, m_migrate_obj_files, NumVerifyServer);
            END;
        (* END PTS 1113635 FF *)
&       ifdef QUICK
        (*ENDIF*) 
        IF  (t.trError_gg00 = e_ok) AND
            IncrementConvVersion    AND
            kb57AnyOpenTransactionsExist (* PTS 1113089 TS 2001-12-12 *)
        THEN
            BEGIN
            NumVerifyServer := bd01UsableServerForParallelExecution (
                  t.trTaskId_gg00, m_verify, NOT c_in_region);
            bd30ObjFileCoordinator (t, m_verify, NumVerifyServer);
            END;
&       endif
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  t.trError_gg00 <> e_ok
    THEN
        BEGIN
        bd999DetachAllDevices (t.trTaskId_gg00);
        b01downfilesystem := true
        END
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  (t.trError_gg00 = e_ok) AND g01is_livecache AND IncrementConvVersion
THEN
    BEGIN
    bd91StartOMSGarbageCollectionAfterSpecialOp( t.trTaskId_gg00 );
    bd91RemoveObjFilesMarkedForDelete (t);
    END;
&ifdef TRACE
(*ENDIF*) 
t01basis_error (bi, 'restart err ', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01set_event (
            EventId   : tsp31_event_ident;
            Threshold : integer;
            Priority  : tsp31_event_prio);
 
BEGIN
(* CRS 1103110 Alexander Kley 20/07/99 *)
bd10AddDBFillingEvent (EventId, Threshold * 100, Priority);
&ifdef TRACE
IF  t01trace (bi)
THEN
    BEGIN
    t01name(bi,'====> bd set event');
    t01int4(bi,'   EventId  ',ord(EventId));
    t01int4(bi,'   Threshold',Threshold);
    t01int4(bi,'   Priority ',ord(Priority));
    END;
&endif
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01set_event_dw_compr(priority_of_event : tsp31_event_prio);
 
BEGIN
(* b12set_event_dw_compr(priority_of_event); *)
&ifdef TRACE
IF  t01trace (bi)
THEN
    BEGIN
    t01name(bi,'====> bd set event');
    t01int4(bi,'dw compress ',ord(priority_of_event));
    END;
&endif
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01set_event_dw_displ(priority_of_event : tsp31_event_prio);
 
BEGIN
(* b12set_event_dw_displ(priority_of_event);*)
&ifdef TRACE
IF  t01trace (bi)
THEN
    BEGIN
    t01name(bi,'====> bd set event');
    t01int4(bi,'dw displace ',ord(priority_of_event));
    END;
&endif
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01set_event_savepoint(priority_of_event : tsp31_event_prio);
 
BEGIN
(* b12set_event_savepoint(priority_of_event); *)
&ifdef TRACE
IF  t01trace (bi)
THEN
    BEGIN
    t01name(bi,'====> bd set event');
    t01name(bi,'== savepoint on ==');
    END;
&endif
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01set_fileversion (VAR t : tgg00_TransContext;
            VAR file_id     : tgg00_FileId;
            new_fileversion : tgg91_FileVersion;
            new_long_cnt    : tsp00_Int2);
 
CONST
      c_dummy_new_long_cnt = -1;
 
VAR
      fi      : tbd_fileinfo;
      current : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name      (bi, '====> set filevers');
t01treeid    (bi, 'treeid      ', file_id);
ta01FileVers (bi, 'new filevers', new_fileversion);
t01int4      (bi, 'new long cnt', new_long_cnt);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    b17state_fdir (file_id.fileName_gg00, fi, ftsShared_egg00 in file_id.fileType_gg00,t);
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        b30fdir_to_treeid (fi, file_id);
        current.curr_tree_id := file_id;
        IF  ftsConcurrent_egg00 in current.curr_tree_id.fileType_gg00
        THEN
            b75tldelete_lock_tree (current, ftsTemp_egg00 in current.curr_tree_id.fileType_gg00, 16);
        (*ENDIF*) 
        b30set_fileversion (current, new_fileversion);
        IF  current.curr_lockstate = d_lock_tree
        THEN
            b75tudelete_unlock_tree (current)
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  t.trError_gg00 = e_file_unloaded
    THEN
        t.trError_gg00 := e_ok;
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        WITH fi DO
            BEGIN
            fi_vers := new_fileversion;
            IF  new_long_cnt <> c_dummy_new_long_cnt
            THEN
                fi.fi_col_cnt := new_long_cnt;
            (*ENDIF*) 
            b17repl_fdir (file_id.fileName_gg00, fi,
                  ftsShared_egg00 in file_id.fileType_gg00, t)
            END;
        (*ENDWITH*) 
    (*ENDIF*) 
    END;
(*ENDIF*) 
&ifdef TRACE
t01basis_error (bi, 'set filev e ', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01treeleafnodes (VAR t     : tgg00_TransContext;
            VAR file_id           : tgg00_FileId;
            m_type                : tgg00_MessType;
            VAR old_treeleafnodes : tsp00_Int4);
 
VAR
      fi      : tbd_fileinfo;
      current : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name     (bi, '====> treeleafnode');
t01treeid   (bi, 'treeid      ', file_id);
t01messtype (bi, 'fetch/update', m_type);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    b17state_fdir (file_id.fileName_gg00, fi, ftsShared_egg00 in file_id.fileType_gg00, t);
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        b30fdir_to_treeid (fi, file_id);
        current.curr_tree_id := file_id;
        IF  ftsConcurrent_egg00 in current.curr_tree_id.fileType_gg00
        THEN
            BEGIN
            CASE m_type OF
                m_fetch:
                    b75tlread_lock_tree (current, 17);
                m_update:
                    b75tldelete_lock_tree (current, ftsTemp_egg00 in current.curr_tree_id.fileType_gg00, 18);
                OTHERWISE
                    ;
                END;
            (*ENDCASE*) 
            END;
        (*ENDIF*) 
        CASE m_type OF
            m_fetch:
                BEGIN
                current.curr_tree_id.fileLeafNodes_gg00 := cgg_nil_leafnodes;
                b30treeleafnodes (current, nr_for_read, old_treeleafnodes);
                IF  current.curr_lockstate = r_lock_tree
                THEN
                    b75turead_unlock_tree (current)
                (*ENDIF*) 
                END;
            m_update:
                BEGIN
                b30treeleafnodes (current, nr_for_update,
                      old_treeleafnodes);
                IF  current.curr_lockstate = d_lock_tree
                THEN
                    b75tudelete_unlock_tree (current)
                (*ENDIF*) 
                END;
            OTHERWISE
                BEGIN
                g01opmsg (sp3p_console, sp3m_error,
                      csp3_b01_1_illegal_mess_type,
                      csp3_n_btree, 'illegal mess type       ',
                      ord (m_type));
                t.trError_gg00 := e_not_implemented
                END
            END
        (*ENDCASE*) 
        END
    (*ENDIF*) 
    END;
(*ENDIF*) 
&ifdef TRACE
t01basis_error (bi, 'set treel e ', t.trError_gg00);
t01int4        (bi, 'old leafnode', old_treeleafnodes);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01setto_zero_full_and_null;
 
VAR
      i : integer;
 
BEGIN
b11_init;
b21m_init_monitor_rec;
b77set_not_generated;
b01downfilesystem := true;
FOR i := 1 TO sizeof (tsp00_Key) DO
    b01zerokey [i] := chr (0);
(*ENDFOR*) 
FOR i := 1 TO sizeof (tsp00_Key) DO
    b01fullkey [i] := chr (255);
(*ENDFOR*) 
FOR i := 1 TO cgg_range_entries DO
    b01keyrange.key_ranges [i] := false;
(*ENDFOR*) 
FOR i := 1 TO sizeof (tsp00_VFilename) DO
    b01blankfilename [i] := ' ';
(*ENDFOR*) 
WITH b01niltree_id DO
    BEGIN
    fileRootCheck_gg00        := ROOT_CHECK_GG00;
    fileLeafNodes_gg00        := cgg_nil_leafnodes;
    fileHandling_gg00         := [hsWithoutLock_egg00];
    fileBdUse_gg00            := [];
    fileRoot_gg00             := NIL_PAGE_NO_GG00;
    fileVersion_gg00.ci2_gg00 := cgg_dummy_file_version;
    fileType_gg00             := [ftsTemp_egg00];
    fileName_gg00             := cgg_zero_fn;
    gg06SetNilRef (fileUserRef_gg00);
    END;
(*ENDWITH*) 
WITH b01nilcurrent DO
    BEGIN
    curr_node_locked              := NIL_PAGE_NO_GG00;
    curr_lvl_1_pno                := NIL_PAGE_NO_GG00;
    curr_lvl_1_locked             := NIL_PAGE_NO_GG00;
    curr_left_bound               := NIL_PAGE_NO_GG00;
    curr_right_bound              := NIL_PAGE_NO_GG00;
    curr_tree_id                  := b01niltree_id;
    curr_lockstate                := no_bd_lock;
    currFiller0_bd00              := false;
    currUnlockAllowed_bd00        := false;
    curr_action                   := m_nil;
    currFreeQueue_bd00.fqTop_bd00 := 1;
    currNumLeaves_bd00            := 1;
    currRootNptrs_bd00.np_ptr     := NIL;
    currRootNptrs_bd00.np_cbptr   := NIL;
    currIndexNptrs_bd00.np_ptr    := NIL;
    currIndexNptrs_bd00.np_cbptr  := NIL;
    currRootUpdated_bd00          := false;
    currIndexUpdated_bd00         := false;
    currCounter_bd00              := 0;
    END;
(*ENDWITH*) 
b06init_errtxt;
bd700SetSystemDefinedEvents;
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01sfile_statistic (
            VAR t              : tgg00_TransContext;
            VAR file_id        : tgg00_FileId;
            with_shortcol_file : boolean;
            VAR info           : tgg00_SampleInfo);
 
VAR
      fi           : tbd_fileinfo;
      scol_file_id : tgg00_FileId;
      current      : tbd_current_tree;
      scol_current : tbd_current_tree;
      tableStat    : tgg00_TableStatInfo;
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd statistic');
t01treeid (bi, 'treeid      ', file_id);
&endif
b30cinit_current (t, current);
b30cinit_current (t, scol_current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    WITH current DO
        BEGIN
        t.trError_gg00 := e_ok;
        b17get_fdir (file_id.fileName_gg00, fi, ftsShared_egg00 in file_id.fileType_gg00, t);
        IF  t.trError_gg00 = e_ok
        THEN
            BEGIN
            b30fdir_to_treeid (fi, file_id);
            curr_tree_id := file_id;
            IF  ftsConcurrent_egg00 in fi.fi_type
            THEN
                BEGIN
                b75tlread_lock_tree (current, 19);
                IF  (file_id.fileVersion_gg00.ci2_gg00 <> cgg_dummy_file_version)
                    AND
                    (fi.fi_vers <> file_id.fileVersion_gg00)
                THEN
                    t.trError_gg00 := e_old_fileversion
                ELSE
                    IF  f_bad in fi.fi_state
                    THEN
                        t.trError_gg00 := e_bad_file
                    (*ENDIF*) 
                (*ENDIF*) 
                END
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        IF  t.trError_gg00 = e_ok
        THEN
            BEGIN
            IF  ((fi.fi_col_cnt > 0) AND (with_shortcol_file))
            THEN
                BEGIN
                WITH scol_file_id DO
                    BEGIN
                    scol_file_id              := current.curr_tree_id;
                    fileType_gg00             := [ftsPerm_egg00, ftsConcurrent_egg00];
                    fileTfn_gg00              := tfnShortScol_egg00;
                    fileRoot_gg00             := NIL_PAGE_NO_GG00;
                    fileVersion_gg00.ci2_gg00 := cgg_dummy_file_version;
                    END;
                (*ENDWITH*) 
                b30current (t, scol_file_id, m_column, scol_current);
                END;
            (*ENDIF*) 
            IF  t.trError_gg00 = e_ok
            THEN
                bd999CalculateTableStatistic (t, current, scol_current, with_shortcol_file,
                      fi.fi_col_cnt, tableStat);
            (*ENDIF*) 
            IF  t.trError_gg00 = e_ok
            THEN
                WITH info DO (* temporary solution as long as tgg00_SampleInfo is given *)
                    BEGIN
                    leafnodes           := tableStat.TabStatLeafnodes_gg00;
                    sec_key_cnt         := 0;
                    prim_key_cnt        := 0;
                    avg_prim_per_list   := 0;
                    records             := tableStat.TabStatRecords_gg00;
                    all_stringcol_pages := tableStat.TabStatAllStringColPages_gg00;
                    nodes               := tableStat.TabStatNodes_gg00;
                    null_value_cnt      := 0;
                    min_sec_key_len     := 0;
                    max_sec_key_len     := 0;
                    avg_sec_key_len     := 0;
                    treecov             := tableStat.TabStatTreeCov_gg00;
                    rootcov             := tableStat.TabStatRootCov_gg00;
                    indexcov            := tableStat.TabStatIndexCov_gg00;
                    min_indexcov        := tableStat.TabStatMinIndexCov_gg00;
                    max_indexcov        := tableStat.TabStatMaxIndexCov_gg00;
                    leafcov             := tableStat.TabStatLeafCov_gg00;
                    min_leafcov         := tableStat.TabStatMinLeafCov_gg00;
                    max_leafcov         := tableStat.TabStatMaxLeafCov_gg00;
                    rec_per_page        := tableStat.TabStatRecsPerPage_gg00;
                    ave_rec_length      := tableStat.TabStatAveRecLength_gg00;
                    min_rec_length      := tableStat.TabStatMinRecLength_gg00;
                    max_rec_length      := tableStat.TabStatMaxRecLength_gg00;
                    ave_key_length      := tableStat.TabStatAveKeyLength_gg00;
                    indexnodes          := tableStat.TabStatIndexNodes_gg00;
                    ave_sep_length      := tableStat.TabStatAveSepLength_gg00;
                    min_key_length      := tableStat.TabStatMinKeyLength_gg00;
                    max_key_length      := tableStat.TabStatMaxKeyLength_gg00;
                    min_sep_length      := tableStat.TabStatMinSepLength_gg00;
                    max_sep_length      := tableStat.TabStatMaxSepLength_gg00;
                    min_rec_per_page    := tableStat.TabStatMinRecsPerPage_gg00;
                    max_rec_per_page    := tableStat.TabStatMaxRecsPerPage_gg00;
                    rootsegm            := curr_tree_id.fileRoot_gg00;
                    smplFileType_gg00   := curr_tree_id.fileType_gg00;
                    pcs_dummy           : = false;
                    hight               := tableStat.TabStatRootLevel_gg00;
                    defined_stringcols  := tableStat.TabStatDefinedStringCols_gg00;
                    min_len_stringcol   := tableStat.TabStatMinLenStringCol_gg00;
                    max_len_stringcol   := tableStat.TabStatMaxLenStringCol_gg00;
                    ave_len_stringcol   := tableStat.TabStatAveLenStringCol_gg00;
                    min_stringcol_pages := tableStat.TabStatMinStringColPages_gg00;
                    max_stringcol_pages := tableStat.TabStatMaxStringColPages_gg00;
                    ave_stringcol_pages := tableStat.TabStatAveStringColPages_gg00;
                    invsel_1            := 0;
                    invsel_5            := 0;
                    invsel_10           := 0;
                    invsel_25           := 0;
                    invsel_notsel       := 0;
                    min_prim_per_list   := 0;
                    max_prim_per_list   := 0;
                    END;
                (*ENDWITH*) 
            (*ENDIF*) 
            IF  (t.trError_gg00 = e_ok) OR (t.trError_gg00 = e_bad_datapage)
            THEN
                file_id := curr_tree_id;
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        IF  scol_current.curr_lockstate = r_lock_tree
        THEN
            b75turead_unlock_tree (scol_current);
        (*ENDIF*) 
        IF  curr_lockstate = r_lock_tree
        THEN
            b75turead_unlock_tree (current);
        (*ENDIF*) 
        END;
    (*ENDWITH*) 
(*ENDIF*) 
&ifdef TRACE
t01basis_error (bi, 'statistic er', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01show_treelocklist (VAR t : tgg00_TransContext;
            VAR file_id   : tgg00_FileId;
            VAR rec_count : tsp00_Int4);
 
VAR
      current     : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd show lock');
t01treeid (bi, 'treeid      ', file_id);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    b01treset_file (t, file_id);
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        current.curr_tree_id := file_id;
        b75show_treelocklist (current, rec_count)
        END
    (*ENDIF*) 
    END;
(*ENDIF*) 
&ifdef TRACE
IF  t.trError_gg00 = e_ok
THEN
    t01int4 (bi, 'rec_count   ', rec_count);
(*ENDIF*) 
t01basis_error (bi, 'show lock er', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01show_monitor (
            TaskId   : tsp00_TaskId;
            VAR info : tgg00_ReferenceInfo);
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd show mon ');
&endif
b73show_ref_statistic (TaskId, info);
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01shutdown_filesystem (VAR t : tgg00_TransContext);
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd shutdown ');
&endif
t.trError_gg00 := e_ok;
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    b01downfilesystem := true;
    bd20ShutdownDataCache (t.trTaskId_gg00, NOT c_emergency_shutdown);
    bd10ShutdownConverter (t.trTaskId_gg00);
    b75rdelete_lock_requests (t.trTaskId_gg00);
    bd999DetachAllDevices (t.trTaskId_gg00)
    END;
(*ENDIF*) 
&ifdef TRACE
t01basis_error (bi, 'shutdown err', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd01tcheck_tree (VAR t : tgg00_TransContext;
            root : tsp00_PageNo);
 
VAR
      Dummy    : tsp00_Int4;
      current  : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd checktree');
t01int4 (bi, 'treeroot    ', root);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    WITH current DO
        BEGIN
        t.trError_gg00             := e_ok;
        curr_tree_id               := b01niltree_id;
        curr_tree_id.fileRoot_gg00 := root;
        curr_tree_id.fileType_gg00 := [ftsPerm_egg00];
        END;
    (*ENDWITH*) 
    b30verify_tree (current, NOT c_conv_update, Dummy)
    END;
(*ENDIF*) 
&ifdef TRACE
t01basis_error (bi, 'check tree e', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01tcreate_file (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
VAR
      fi         : tbd_fileinfo;
      current    : tbd_current_tree;
      fn_trace   : tgg11_BdFilenameTrace;
      root_trace : tgg11_BdRootTrace;
 
BEGIN
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    fn_trace.bdfTrType_gg11 := bdtrFilename_egg11;
    fn_trace.bdfFn_gg11     := file_id.fileName_gg00;
    b120InsertTrace (t, bd, b01t_create, sizeof (fn_trace), @fn_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01name   (bi, '====> bd tcreate f');
t01treeid (bi, 'treeid req  ', file_id);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    file_id.fileResultSite_gg00 := g01localsite;
    WITH fi DO
        BEGIN
        t.trError_gg00   := e_ok;
        fi_type          := file_id.fileType_gg00;
        fi_state         := [];
        fi_fill1         := false;
        fi_descr         := [];
        fi_root          := NIL_PAGE_NO_GG00;
        fi_vers.ci2_gg00 := cgg_dummy_file_version;
        fi_col_cnt       := 0;
        gg06SetNilRef (fi_user_ref)
        END;
    (*ENDWITH*) 
    b30fdir_to_treeid (fi, file_id);
    current.curr_tree_id := file_id;
    bd999CheckSpace (t, 1);
    IF  t.trError_gg00 = e_ok
    THEN
        b30new_tree (fi, current);
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        b17add_fdir (file_id.fileName_gg00, fi, t);
    (*ENDIF*) 
    IF  t.trError_gg00 = e_duplicate_filename
    THEN
        BEGIN
        t.trError_gg00 := e_ok;
        b13pfree_pno (current.curr_tree_id.fileRoot_gg00, current);
        IF  t.trError_gg00 = e_ok
        THEN
            t.trError_gg00 := e_duplicate_filename
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        file_id := current.curr_tree_id;
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    root_trace.bdrTrType_gg11 := bdtrRoot_egg11;
    root_trace.bdrRoot_gg11   := file_id.fileRoot_gg00;
    root_trace.bdrError_gg11  := t.trError_gg00;
    b120InsertTrace (t, bd, b01t_create, sizeof (root_trace), @root_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01treeid      (bi, 'new treeid  ', file_id);
t01basis_error (bi, 'tcreate err ', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01tdestroy_loc_temp_files (VAR t : tgg00_TransContext;
            site : tgg00_ServerdbNo);
 
VAR
      fi       : tbd_fileinfo;
      file_id  : tgg00_FileId;
      current  : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name (bi, '===> bd dest tsite');
t01site (bi, 'site        ', site);
&endif
file_id              := b01niltree_id;
file_id.fileName_gg00           := cgg_zero_fn;
file_id.fileTfn_gg00 := tfnTemp_egg00;
IF  site <> g01localsite
THEN
    REPEAT
        b30cinit_current (t, current);
        IF  b01downfilesystem
        THEN
            t.trError_gg00 := e_shutdown
        ELSE
            BEGIN
            t.trError_gg00 := e_ok;
            b17succ_fdir (file_id.fileName_gg00, file_id.fileName_gg00, fi,
                  ftsShared_egg00 in file_id.fileType_gg00, t,
                  NOT c_include_strcols);
            IF  t.trError_gg00 = e_ok
            THEN
                IF  site = g01localsite (* file_id.fileSite_gg00 = site *)
                THEN
                    BEGIN
                    b30fdir_to_treeid (fi, file_id);
                    current.curr_tree_id := file_id;
                    b17del_fdir (file_id.fileName_gg00, fi,
                          ftsShared_egg00 in file_id.fileType_gg00, t);
&                   ifdef TRACE
                    IF  t.trError_gg00 = e_ok
                    THEN
                        BEGIN
                        t01sname (bi, 'destroyed:  ');
                        t01filename (bi, file_id.fileName_gg00)
                        END;
&                   endif
                    (*ENDIF*) 
                    IF  (t.trError_gg00 = e_ok)
                        AND (fi.fi_root <> NIL_PAGE_NO_GG00)
                    THEN
                        BEGIN
                        IF  fid_new_long_col in fi.fi_descr
                        THEN
                            b30release_tree (current, fi.fi_col_cnt,
                                  fi.fi_var_col_cnt_pos,
                                  NOT c_only_empty)
                        ELSE
                            b30release_tree (current, fi.fi_col_cnt,
                                  cgg_nil_varcol_cnt_off,
                                  NOT c_only_empty)
                        (*ENDIF*) 
                        END;
                    (*ENDIF*) 
                    IF  t.trError_gg00 = e_bad_datapage
                    THEN
                        t.trError_gg00 := e_ok
                    (*ENDIF*) 
                    END;
                (*ENDIF*) 
            (*ENDIF*) 
            END
        (*ENDIF*) 
    UNTIL
        (t.trError_gg00 <> e_ok);
    (*ENDREPEAT*) 
(*ENDIF*) 
IF  t.trError_gg00 = e_file_not_found
THEN
    t.trError_gg00 := e_ok;
&ifdef TRACE
(*ENDIF*) 
t01basis_error (bi, 'tdestroy l e', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01tinit_temp_cache (VAR t : tgg00_TransContext;
            buffers            : tsp00_Int4;
            is_control_session : boolean);
 
CONST
      c_alloc_monitor = true;
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd tinit tc ');
t01int4 (bi, 'tca buffers ', buffers);
t01bool (bi, 'is control s', is_control_session);
&endif
t.trError_gg00 := e_ok;
IF  is_control_session OR bd10IsConnectAllowed
THEN
    b21init_temp_cache (t.trTaskId_gg00, buffers,
          c_alloc_monitor, is_control_session,
          t.trBdTcachePtr_gg00, t.trError_gg00)
ELSE
    t.trError_gg00 := e_no_more_temp_space;
(*ENDIF*) 
IF  t.trError_gg00 = e_ok
THEN
    b18lcreate_lcl_tfdir (t);
(*ENDIF*) 
IF  (t.trError_gg00 <> e_ok) AND (t.trError_gg00 <> e_no_more_temp_space)
THEN
    t.trBdTcachePtr_gg00 := NIL;
&ifdef TRACE
(*ENDIF*) 
t01basis_error (bi, 'tinit tc err', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
FUNCTION
      b01tmp_cache_size (VAR t : tgg00_TransContext) : tsp00_Int4;
 
BEGIN
b01tmp_cache_size := b21tmp_cache_size (t.trBdTcachePtr_gg00)
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01tnext_temp_statistic (
            VAR Trans        : tgg00_TransContext;
            VAR FileId       : tgg00_FileId;
            VAR TotalPageCnt : tsp00_Int4);
 
VAR
      FileInfo  : tbd_fileinfo;
      PageCnt   : tsp00_Int4;
      StartKey  : tgg00_Lkey;
      StopKey   : tgg00_Lkey;
 
BEGIN
&ifdef TRACE
t01name   (bi, '====> bd tnext sta');
t01treeid (bi, 'FileId      ', FileId);
&endif
IF  b01downfilesystem
THEN
    Trans.trError_gg00 := e_shutdown
ELSE
    BEGIN
    TotalPageCnt       := 0;
    PageCnt            := 0;
    Trans.trError_gg00 := e_ok;
    b17tnext_temp_fdir (FileId.fileName_gg00, FileId.fileName_gg00, FileInfo,
          ftsShared_egg00 IN FileId.fileType_gg00, Trans);
    IF  Trans.trError_gg00 = e_ok
    THEN
        BEGIN
        b30fdir_to_treeid( FileInfo, FileId );
        IF  NOT g04inv_tfn (FileId.fileTfn_gg00)
        THEN
            BEGIN
            StartKey.keyLen_gg00 := 0;
            StartKey.keyVal_gg00 := b01zerokey;
            StopKey.keyLen_gg00  := MAX_KEYLEN_GG00;
            StopKey.keyVal_gg00  := b01fullkey;
            b02calculate_page_count( Trans, FileId, StartKey, StopKey, PageCnt );
            TotalPageCnt := TotalPageCnt + PageCnt
            END
        (*ENDIF*) 
        END
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  Trans.trError_gg00 = e_file_not_found
THEN
    Trans.trError_gg00 := e_no_next_record;
&ifdef TRACE
(*ENDIF*) 
t01treeid      (bi, 'FileId      ', FileId);
t01int4        (bi, 'PageCount   ', TotalPageCnt);
t01basis_error (bi, 'BaseError   ', Trans.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01trelease_temp_cache (VAR t : tgg00_TransContext);
 
VAR
      aux_err : tgg00_BasisError;
      aux_pno : tsp00_PageNo;
      file_id : tgg00_FileId;
      fi      : tbd_fileinfo;
      current : tbd_current_tree;
 
BEGIN
aux_err := e_ok;
&ifdef TRACE
t01name (bi, '====> bd trele tc ');
&endif
t.trError_gg00 := e_ok;
(*===== release all private temp files =====*)
file_id     := b01niltree_id;
file_id.fileName_gg00  := cgg_zero_fn;
(*===== be aware of tgg_tfn_type =====*)
file_id.fileTfn_gg00 := tfnTempAux_egg00;
(*===== actually the lowest temp tfn =*)
REPEAT
    b30cinit_current (t, current);
    IF  b01downfilesystem
    THEN
        t.trError_gg00 := e_shutdown
    ELSE
        BEGIN
        t.trError_gg00 := e_ok;
        b17succ_fdir (file_id.fileName_gg00, file_id.fileName_gg00, fi,
              NOT c_concurrent, t, NOT c_include_strcols);
        IF  (t.trError_gg00 = e_ok) AND (ftsTemp_egg00 in fi.fi_type)
            AND (NOT (ftsShared_egg00 in fi.fi_type))
        THEN
            BEGIN
            b30fdir_to_treeid (fi, file_id);
            current.curr_tree_id := file_id;
            b17del_fdir (file_id.fileName_gg00, fi, NOT c_concurrent, t);
&           ifdef TRACE
            IF  t.trError_gg00 = e_ok
            THEN
                BEGIN
                t01sname (bi, 'destroyed:  ');
                t01filename (bi, file_id.fileName_gg00)
                END;
&           endif
            (*ENDIF*) 
            IF  (t.trError_gg00 = e_ok)
                AND (fi.fi_root <> NIL_PAGE_NO_GG00)
            THEN
                BEGIN
                IF  fid_new_long_col in fi.fi_descr
                THEN
                    b30release_tree (current, fi.fi_col_cnt,
                          fi.fi_var_col_cnt_pos, NOT c_only_empty)
                ELSE
                    b30release_tree (current, fi.fi_col_cnt,
                          cgg_nil_varcol_cnt_off, NOT c_only_empty)
                (*ENDIF*) 
                END;
            (*ENDIF*) 
            IF  t.trError_gg00 = e_bad_datapage
            THEN
                t.trError_gg00 := e_ok
            (*ENDIF*) 
            END
        (*ENDIF*) 
        END
    (*ENDIF*) 
UNTIL
    (t.trError_gg00 <> e_ok);
(*ENDREPEAT*) 
IF  t.trError_gg00 = e_file_not_found
THEN
    t.trError_gg00 := e_ok
ELSE
    BEGIN
    aux_err := t.trError_gg00;
    t.trError_gg00 := e_ok
    END;
(*ENDIF*) 
(*========================================*)
IF  NOT b01downfilesystem
THEN
    BEGIN
    current            := b17tempfdir_current;
    current.curr_trans := @t;
    b21lcl_tfdir_root (t.trBdTcachePtr_gg00, NOT c_set_not_get_pno,
          current.curr_tree_id.fileRoot_gg00);
    current.curr_tree_id.fileType_gg00 := current.curr_tree_id.fileType_gg00 -
          [ftsConcurrent_egg00,ftsShared_egg00];
    b30release_tree (current, 0, cgg_nil_varcol_cnt_off, NOT c_only_empty);
    IF  t.trError_gg00 = e_ok
    THEN
        t.trError_gg00 := aux_err;
    (*ENDIF*) 
    END;
(*ENDIF*) 
aux_pno := NIL_PAGE_NO_GG00;
b21lcl_tfdir_root (t.trBdTcachePtr_gg00, c_set_not_get_pno, aux_pno);
b21temp_cache_release (t.trTaskId_gg00, t.trBdTcachePtr_gg00);
t.trBdTcachePtr_gg00 := NIL;
&ifdef TRACE
t01basis_error (bi, 'trele tc err', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01treset_file (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
VAR
      fi         : tbd_fileinfo;
      current    : tbd_current_tree;
      fn_trace   : tgg11_BdFilenameTrace;
      root_trace : tgg11_BdRootTrace;
 
BEGIN
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    fn_trace.bdfTrType_gg11 := bdtrFilename_egg11;
    fn_trace.bdfFn_gg11     := file_id.fileName_gg00;
    b120InsertTrace (t, bd, b01t_reset, sizeof (fn_trace), @fn_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01name   (bi, '====> bd treset f ');
t01treeid (bi, 'treeid req  ', file_id);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    b17state_fdir (file_id.fileName_gg00, fi, ftsShared_egg00 in file_id.fileType_gg00, t);
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        b30fdir_to_treeid (fi, file_id);
        current.curr_tree_id := file_id;
        IF  ftsConcurrent_egg00 in current.curr_tree_id.fileType_gg00
        THEN
            b75tldelete_lock_tree (current, ftsTemp_egg00 in current.curr_tree_id.fileType_gg00, 21);
        (*ENDIF*) 
        b30release_tree (current, 0, cgg_nil_varcol_cnt_off, c_only_empty);
        IF  current.curr_lockstate = d_lock_tree
        THEN
            b75tudelete_unlock_tree (current)
        (*ENDIF*) 
        END
    ELSE
        IF  t.trError_gg00 = e_file_not_found
        THEN
            BEGIN
            WITH fi DO
                BEGIN
                t.trError_gg00   := e_ok;
                fi_type          := file_id.fileType_gg00;
                fi_state         := [];
                fi_fill1         := false;
                fi_descr         := [];
                fi_root          := NIL_PAGE_NO_GG00;
                fi_vers.ci2_gg00 := cgg_dummy_file_version;
                fi_col_cnt       := 0;
                gg06SetNilRef (fi_user_ref)
                END;
            (*ENDWITH*) 
            b30fdir_to_treeid (fi, file_id);
            current.curr_tree_id := file_id;
            bd999CheckSpace (t, 1);
            IF  t.trError_gg00 = e_ok
            THEN
                b30new_tree (fi, current);
            (*ENDIF*) 
            IF  t.trError_gg00 = e_ok
            THEN
                b17add_fdir (file_id.fileName_gg00, fi, t)
            (*ENDIF*) 
            END;
        (*ENDIF*) 
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        file_id := current.curr_tree_id;
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    root_trace.bdrTrType_gg11 := bdtrRoot_egg11;
    root_trace.bdrRoot_gg11   := file_id.fileRoot_gg00;
    root_trace.bdrError_gg11  := t.trError_gg00;
    b120InsertTrace (t, bd, b01t_reset, sizeof (root_trace), @root_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01treeid      (bi, 'new treeid  ', file_id);
t01basis_error (bi, 'treset error', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01unload_file (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
VAR
      fi      : tbd_fileinfo;
      current : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd unload fi');
t01treeid (bi, 'treeid      ', file_id);
&endif
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    b17unload_fdir (file_id.fileName_gg00, fi, ftsShared_egg00 in file_id.fileType_gg00, t);
    IF  (t.trError_gg00 = e_ok) AND (fi.fi_root <> NIL_PAGE_NO_GG00)
    THEN
        BEGIN
        b30fdir_to_treeid (fi, file_id);
        current.curr_tree_id := file_id;
        IF  ftsConcurrent_egg00 in fi.fi_type
        THEN
            b75tldelete_lock_tree (current, ftsTemp_egg00 in fi.fi_type, 22);
&       ifdef TRACE
        (*ENDIF*) 
        t01int4 (bi, 'scol count  ', fi.fi_col_cnt);
&       endif
        IF  fid_new_long_col in fi.fi_descr
        THEN
            b30release_tree (current, fi.fi_col_cnt,
                  fi.fi_var_col_cnt_pos, NOT c_only_empty)
        ELSE
            b30release_tree (current, fi.fi_col_cnt,
                  cgg_nil_varcol_cnt_off, NOT c_only_empty);
        (*ENDIF*) 
        IF  t.trError_gg00 = e_bad_datapage
        THEN
            t.trError_gg00 := e_ok;
        (*ENDIF*) 
        IF  t.trError_gg00 = e_ok
        THEN
            file_id := current.curr_tree_id;
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  current.curr_lockstate = d_lock_tree
    THEN
        b75tudelete_unlock_tree (current)
    (*ENDIF*) 
    END;
(*ENDIF*) 
&ifdef TRACE
t01basis_error (bi, 'unload err  ', t.trError_gg00);
&endif
END;
 
(* PTS 1107952 E.Z. *)
(*------------------------------*) 
 
PROCEDURE
      b01verify_database (
            VAR t                 : tgg00_TransContext;
            bWithUpdate           : boolean;
            bWithIndexes          : boolean;
            VAR NumPermPages      : tsp00_Int4;
            VAR NumReleasedBlocks : tsp00_Int4;
            VAR bad_index_cnt     : tsp00_Int4;
            VAR total_bad_cnt     : tsp00_Int4);
 
VAR
      verify_error                : tgg00_BasisError;
      MaxServer                   : integer;
      Dummy                       : tsp00_Int4;
      current                     : tbd_current_tree;
      ConverterVersion            : tsp00_Int4;
      MaxStaticPageNo             : tsp00_PageNo;
      MaxDynamicPageNo            : tsp00_PageNo;
      PackedConvRootBlockAddress  : tsp00_Int4;
      OpenTransOrHistoryFilesOkay : boolean;
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd verify   ');
&endif
verify_error      := e_ok;
bad_index_cnt     := 0;
NumPermPages      := 0;
NumReleasedBlocks := 0;
total_bad_cnt     := 0;
WITH t DO
    BEGIN
    IF  b01downfilesystem
    THEN
        trError_gg00 := e_shutdown
    ELSE
        BEGIN
        trError_gg00 := e_ok;
        IF  bWithUpdate
        THEN
            bd10BeginColdVerify;
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  trError_gg00 = e_ok
    THEN
        BEGIN
        current            := b17permfdir_current;
        current.curr_trans := @t;
        IF  NOT bWithUpdate
        THEN
            BEGIN
            b75tlread_lock_tree (current, 91);
            END;
        (*ENDIF*) 
        b30verify_tree (current, bWithUpdate, Dummy);
        IF  (NOT bWithUpdate) AND (current.curr_lockstate = r_lock_tree)
        THEN
            b75turead_unlock_tree (current);
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  trError_gg00 = e_ok
    THEN
        BEGIN
        current            := b17strcolfdir_current;
        current.curr_trans := @t;
        IF  NOT bWithUpdate
        THEN
            BEGIN
            b75tlread_lock_tree (current, 92);
            END;        (*ENDIF*)
        (*ENDIF*) 
        b30verify_tree (current, bWithUpdate, Dummy);
        IF  (NOT bWithUpdate) AND (current.curr_lockstate = r_lock_tree)
        THEN
            b75turead_unlock_tree (current);
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  trError_gg00 = e_ok
    THEN
        BEGIN
        OpenTransOrHistoryFilesOkay := kb560VerifyOpenTransAndHistory (t, bWithUpdate);
        IF  trError_gg00 <> e_ok
        THEN
            BEGIN
            verify_error := trError_gg00;
            trError_gg00 := e_ok;
            END;
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  trError_gg00 = e_ok
    THEN
        BEGIN
        MaxServer := bd01UsableServerForParallelExecution (
              trTaskId_gg00, m_verify, NOT c_in_region);
        b30database_verify (t, bad_index_cnt, total_bad_cnt,
              verify_error, bWithUpdate, bWithIndexes, MaxServer)
        END;
    (*ENDIF*) 
    IF  (total_bad_cnt > 0)
        OR
        NOT OpenTransOrHistoryFilesOkay
    THEN
        BEGIN
        IF  verify_error = e_ok
        THEN
            trError_gg00 := e_file_not_accessible
        ELSE
            trError_gg00 := verify_error;
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  trError_gg00 = e_file_not_found
    THEN
        BEGIN
        trError_gg00 := e_ok;
        IF  bWithUpdate
        THEN
            BEGIN
            bd20FlushDataCache (t);
            IF  trError_gg00 = e_ok
            THEN
                bd10EndColdVerify (trTaskId_gg00, NumPermPages, NumReleasedBlocks);
            (*ENDIF*) 
            IF  t.trError_gg00 = e_ok
            THEN
                bd10FlushConverterSerial (t, ConverterVersion ,MaxStaticPageNo,
                      MaxDynamicPageNo, PackedConvRootBlockAddress);
            (*ENDIF*) 
            IF  trError_gg00 = e_ok
            THEN
                WITH k57restartrec^, rstConfigParam_kb00 DO
                    BEGIN
                    rstConverterVersion_kb00 := ConverterVersion;
                    crMaxDynamicPno_gg00     := MaxDynamicPageNo;
                    crMaxStaticPno_gg00      := MaxStaticPageNo;
                    crConvRootBlockAddr_gg00 := PackedConvRootBlockAddress;
                    k57save_restartrecord (t.trTaskId_gg00);
                    END;
                (*ENDWITH*) 
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        g01optextmsg (sp3p_knldiag, sp3m_info, csp3_bd_msg,
              csp3_n_check, MSG_STOP_CHECK_OKAY)
        END
    ELSE
        BEGIN
        IF  bWithUpdate
        THEN
            bd10EndFailedColdVerify(t.trTaskId_gg00);
        (*ENDIF*) 
        g01optextmsg (sp3p_knldiag, sp3m_error, csp3_bd_msg,
              csp3_n_check, MSG_STOP_CHECK_WITH_ERR);
        END;
    (*ENDIF*) 
&   ifdef TRACE
    IF  bWithUpdate
    THEN
        BEGIN
        t01p2int4 (bi, 'bad_index_cn', bad_index_cnt
              ,        'total_bad_cn', total_bad_cnt)
        END;
    (*ENDIF*) 
    t01basis_error (bi, 'verify error',trError_gg00);
&   endif
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      b01vstate_fileversion (VAR t : tgg00_TransContext;
            VAR file_id : tgg00_FileId);
 
VAR
      fi : tbd_fileinfo;
 
BEGIN
&ifdef TRACE
t01name   (bi, '====> state filev ');
t01treeid (bi, 'treeid      ', file_id);
&endif
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    b17state_fdir (file_id.fileName_gg00, fi, ftsShared_egg00 in file_id.fileType_gg00, t);
    IF  t.trError_gg00 = e_file_unloaded
    THEN
        t.trError_gg00 := e_ok;
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        b30fdir_to_treeid (fi, file_id);
        IF  fi.fi_vers <> file_id.fileVersion_gg00
        THEN
            BEGIN
            file_id.fileVersion_gg00 := fi.fi_vers;
            t.trError_gg00 := e_old_fileversion
            END
        (*ENDIF*) 
        END
    (*ENDIF*) 
    END;
(*ENDIF*) 
&ifdef TRACE
ta01FileVers   (bi, 'fdir fvers  ', fi.fi_vers);
t01basis_error (bi, 'state fv  e ', t.trError_gg00);
&endif
END;
 
(* PTS 1105274 TS 1999-12-21 *)
(*------------------------------*) 
 
PROCEDURE
      bd01AddInvToFileDirectory (
            VAR Trans        : tgg00_TransContext;
            VAR FileId       : tgg00_FileId;
            SetNotAccessible : boolean);
 
VAR
      FileInfo : tbd_fileinfo;
 
BEGIN
IF  b01downfilesystem
THEN
    Trans.trError_gg00 := e_shutdown
ELSE
    BEGIN
    Trans.trError_gg00 := e_ok;
    WITH FileInfo DO
        BEGIN
        IF  SetNotAccessible
        THEN
            fi_state := [f_not_accessible]
        ELSE
            fi_state := [];
        (*ENDIF*) 
        fi_type            := FileId.fileType_gg00;
        fi_type            := fi_type + [ftsConcurrent_egg00];
        fi_descr           := [];
        fi_root            := FileId.fileRoot_gg00;
        fi_vers            := FileId.fileVersion_gg00;
        fi_col_cnt         := 0;
        fi_var_col_cnt_pos := cgg_nil_varcol_cnt_off;
        gg06SetNilRef (fi_user_ref)
        END;
    (*ENDWITH*) 
    b17add_fdir (FileId.fileName_gg00, FileInfo, Trans);
    END;
(*ENDIF*) 
(* PTS 1105022 *)
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd01DataCacheSize (
            VAR TotalPages : tsp00_Int4;
            VAR UnMapPages : tsp00_Int4);
 
BEGIN
bd20GetCacheSize( TotalPages, UnMapPages );
END;
 
(*------------------------------*) 
 
FUNCTION
      bd01ConverterSize : tsp00_Int4;
 
BEGIN
bd01ConverterSize := bd10ConverterSize;
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd01CreateCoordinator (VAR t : tgg00_TransContext;
            VAR FileId : tgg00_FileId;
            MessType   : tgg00_MessType);
 
BEGIN
bd30CreateCoordinator (t, FileId, MessType)
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd01EmergencyShutdown (TaskId : tsp00_TaskId);
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd shutdown ');
&endif
IF  NOT b01downfilesystem
THEN
    BEGIN
    b01downfilesystem := true;
    bd20ShutdownDataCache (TaskId, c_emergency_shutdown);
    b75rdelete_lock_requests (TaskId);
    END
(*ENDIF*) 
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd01SetToNilCurrent( VAR Current : tbd_current_tree );
 
BEGIN
Current := b01nilcurrent;
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd01StartCoordinator (t : tgg00_TransContext;
            VAR FileId : tgg00_FileId;
            MessType   : tgg00_MessType);
 
VAR
      ReadAheadServer : integer;
 
BEGIN
&ifdef TRACE
t01str30  (bi, '===> bd coordinator read ahead');
&endif
WITH t DO
    BEGIN
    IF  b01downfilesystem
    THEN
        trError_gg00 := e_shutdown
    ELSE
        BEGIN
        trError_gg00    := e_ok;
        ReadAheadServer := bd01UsableServerForParallelExecution (
              trTaskId_gg00, MessType, NOT c_in_region);
        CASE MessType OF
            m_get_object :
                bd30OmsReadAheadCoordinator (t, ReadAheadServer);
            OTHERWISE :
                ;
            END
        (*ENDCASE*) 
        END;
    (*ENDIF*) 
    IF  trError_gg00 <> e_ok
    THEN
        trError_gg00 := e_ok; (* ignore errors *)
&   ifdef TRACE
    (*ENDIF*) 
    t01basis_error (bi, 'coordin read', trError_gg00);
&   endif
    END
(*ENDWITH*) 
END;
 
(*------------------------------*) 
 
FUNCTION
      bd01UsableServerForParallelExecution (TaskId : tsp00_TaskId;
            MessType : tgg00_MessType;
            InRegion : boolean) : integer;
 
VAR
      ReadAheadServer : integer;
      ServerAvailable : integer;
 
BEGIN
ServerAvailable := k90free_requests (TaskId, MessType, InRegion);
ReadAheadServer := b01no_of_data_devs;
IF  ReadAheadServer = 1
THEN
    ReadAheadServer := ReadAheadServer + 1;
(*ENDIF*) 
IF  (ReadAheadServer > (ServerAvailable DIV 2))
THEN
    ReadAheadServer := (ServerAvailable DIV 2);
(*ENDIF*) 
bd01UsableServerForParallelExecution := ReadAheadServer
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd01CalculateRecordsAndLeaves(
            VAR Trans           : tgg00_TransContext;
            VAR FileId          : tgg00_FileId;
            VAR NumberOfLeaves  : tsp00_Int4;
            VAR NumberOfRecords : tsp00_Int4 );
 
VAR
      Current : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name   (bi, '====> bd calc rec ');
t01treeid (bi, 'FileId      ', FileId);
&endif
WITH Current, Trans DO
    BEGIN
    Trans.trError_gg00 := e_ok;
    b30cinit_current (Trans, Current);
    IF  b01downfilesystem
    THEN
        trError_gg00 := e_shutdown
    ELSE
        BEGIN
        b30current (Trans, FileId, m_select, Current);
        IF  trError_gg00 = e_ok
        THEN
            bd999CalculateRecordsAndLeaves (Trans, Current,
                  NumberOfLeaves, NumberOfRecords);
        (*ENDIF*) 
        IF  curr_lockstate = r_lock_tree
        THEN
            b75turead_unlock_tree (Current);
        (*ENDIF*) 
        END
    (*ENDIF*) 
    END;
(*ENDWITH*) 
&ifdef TRACE
IF  Trans.trError_gg00 = e_ok
THEN
    BEGIN
    t01int4 (bi, 'record count', NumberOfRecords);
    t01int4 (bi, 'leaf count  ', NumberOfLeaves);
    END;
(*ENDIF*) 
t01basis_error (bi, 'calc rec err', Trans.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd01SampleRecordsAndLeaves(
            VAR Trans            : tgg00_TransContext;
            VAR FileId           : tgg00_FileId;
            NumberOfSampleLeaves : tsp00_Int4;
            VAR NumberOfLeaves   : tsp00_Int4;
            VAR NumberOfRecords  : tsp00_Int4 );
 
VAR
      Current : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name   (bi, '====> bd esti rec ');
t01treeid (bi, 'FileId      ', FileId);
t01int4   (bi, 'sample leave', NumberOfSampleLeaves);
&endif
WITH Current, Trans DO
    BEGIN
    Trans.trError_gg00 := e_ok;
    b30cinit_current (Trans, Current);
    IF  b01downfilesystem
    THEN
        trError_gg00 := e_shutdown
    ELSE
        BEGIN
        b30current (Trans, FileId, m_select, Current);
        IF  trError_gg00 = e_ok
        THEN
            bd999SampleRecordsAndLeaves (Trans, Current,
                  NumberOfSampleLeaves, NumberOfLeaves, NumberOfRecords);
        (*ENDIF*) 
        IF  curr_lockstate = r_lock_tree
        THEN
            b75turead_unlock_tree (Current);
        (*ENDIF*) 
        END
    (*ENDIF*) 
    END;
(*ENDWITH*) 
&ifdef TRACE
IF  Trans.trError_gg00 = e_ok
THEN
    BEGIN
    t01int4 (bi, 'record count', NumberOfRecords);
    t01int4 (bi, 'leaf count  ', NumberOfLeaves);
    END;
(*ENDIF*) 
t01basis_error (bi, 'esti rec err', Trans.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd01ExtractForeignKey(
            VAR MessBlock : tgg00_MessBlock;
            VAR AuxFileId : tgg00_FileId);
 
VAR
      Current     : tbd_current_tree;
      TempCurrent : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name   (bi, '====> bd extract  ');
t01treeid (bi, 'FileId      ', MessBlock.mb_qual^.mtree);
t01treeid (bi, 'AuxFileId   ', AuxFileId);
&endif
WITH Current, MessBlock, mb_trns^ DO
    BEGIN
    b30cinit_current (mb_trns^, Current);
    b30cinit_current (mb_trns^, TempCurrent);
    IF  b01downfilesystem
    THEN
        trError_gg00 := e_shutdown
    ELSE
        BEGIN
        trError_gg00 := e_ok;
        b30current (mb_trns^, mb_qual^.mtree, m_select, Current);
        IF  trError_gg00 = e_ok
        THEN
            b30current (mb_trns^, AuxFileId, m_nil, TempCurrent);
        (*ENDIF*) 
        IF  trError_gg00 = e_ok
        THEN
            bd50ExtractForeignKey (MessBlock, Current, TempCurrent);
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  curr_lockstate = r_lock_tree
    THEN
        b75turead_unlock_tree (Current);
    (*ENDIF*) 
    END;
(*ENDWITH*) 
&ifdef TRACE
t01basis_error (bi, 'extract err ', MessBlock.mb_trns^.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd01MultiColumnStatistic(
            VAR MessBlock        : tgg00_MessBlock;
            VAR AuxFileId        : tgg00_FileId;
            bCalculate           : boolean;
            NumberOfSampleLeaves : tsp00_Int4;
            VAR NumberOfLeaves   : tsp00_Int4;
            VAR NumberOfRecords  : tsp00_Int4;
            VAR DistinctValues   : tgg00_ColumnDistinctValues);
 
VAR
      AuxError    : tgg00_BasisError;
      Current     : tbd_current_tree;
      TempCurrent : tbd_current_tree;
 
BEGIN
&ifdef TRACE
t01name   (bi, '====> bd statistic');
t01treeid (bi, 'FileId      ', MessBlock.mb_qual^.mtree);
t01treeid (bi, 'AuxFileId   ', AuxFileId);
&endif
WITH Current, MessBlock, mb_trns^ DO
    BEGIN
    b30cinit_current (mb_trns^, Current);
    b30cinit_current (mb_trns^, TempCurrent);
    IF  b01downfilesystem
    THEN
        trError_gg00 := e_shutdown
    ELSE
        BEGIN
        trError_gg00 := e_ok;
        b30current (mb_trns^, MessBlock.mb_qual^.mtree, m_select, Current);
        IF  trError_gg00 = e_ok
        THEN
            b30current (mb_trns^, AuxFileId, m_nil, TempCurrent);
        (*ENDIF*) 
        IF  trError_gg00 = e_ok
        THEN
            BEGIN
            IF  g01newupdstat (* PTS 1118179 *)
            THEN
                BEGIN
                IF  bCalculate
                THEN
                    WITH MessBlock.mb_qual^ DO
                        bd999CalculateColumnStatistic( mb_trns^, Current, TempCurrent,
                              mcol_cnt, mcol_pos, (mcol_pos + mcol_cnt -1), MessBlock.mb_st,
                              NumberOfLeaves, NumberOfRecords, DistinctValues)
                    (*ENDWITH*) 
                ELSE
                    WITH MessBlock.mb_qual^ DO
                        bd999SampleColumnStatistic( mb_trns^, Current, TempCurrent, NumberOfSampleLeaves,
                              mcol_cnt, mcol_pos, (mcol_pos + mcol_cnt -1), MessBlock.mb_st,
                              NumberOfLeaves, NumberOfRecords, DistinctValues);
                    (*ENDWITH*) 
                (*ENDIF*) 
                END
            ELSE
                bd72MultiColumnStatistic (MessBlock, Current, TempCurrent, bCalculate,
                      NumberOfSampleLeaves, NumberOfLeaves, NumberOfRecords, DistinctValues);
            (*ENDIF*) 
            END;
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  curr_lockstate = r_lock_tree
    THEN
        b75turead_unlock_tree (Current);
    (*ENDIF*) 
    AuxError     := trError_gg00;
    trError_gg00 := e_ok;
    IF  TempCurrent.curr_tree_id.fileRoot_gg00 <> NIL_PAGE_NO_GG00
    THEN
        b30release_tree (TempCurrent, 0, cgg_nil_varcol_cnt_off, c_only_empty);
    (*ENDIF*) 
    IF  trError_gg00 = e_ok
    THEN
        trError_gg00 := AuxError
    (*ENDIF*) 
    END;
(*ENDWITH*) 
&ifdef TRACE
t01basis_error (bi, 'col stat err', MessBlock.mb_trns^.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd01MigrateDataBase(
            TaskId      : tsp00_TaskId;
            VAR TrError : tgg00_BasisError);
 
BEGIN
bd999MigrateDataBase( TaskId, TrError );
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd01calc_bad_index_cnt (VAR t : tgg00_TransContext);
 
VAR
      fi : tbd_fileinfo;
      fn : tgg00_Filename;
 
BEGIN
&ifdef TRACE
t01name (bi, '====> bd get bad i');
&endif
b01bad_index_cnt := 0;
fn := cgg_zero_fn;
REPEAT
    IF  b01downfilesystem
    THEN
        t.trError_gg00 := e_shutdown
    ELSE
        BEGIN
        t.trError_gg00 := e_ok;
&       ifdef TRACE
        t01filename (bi, fn);
&       endif
        b17succ_fdir (fn, fn, fi, c_concurrent,
              t, NOT c_include_strcols);
        IF  t.trError_gg00 = e_ok
        THEN
            IF  (f_not_accessible IN fi.fi_state) AND
                (fn [1] <> chr (ord (tfnAux_egg00)))
            THEN
                b01bad_index_cnt := succ (b01bad_index_cnt)
            (*ENDIF*) 
        (*ENDIF*) 
        END
    (*ENDIF*) 
UNTIL
    t.trError_gg00 <> e_ok;
(*ENDREPEAT*) 
IF  t.trError_gg00 = e_file_not_found
THEN
    t.trError_gg00 := e_ok;
(*ENDIF*) 
IF  (t.trError_gg00 = e_ok) AND (b01bad_index_cnt > 0)
THEN
    (* PTS 1104961 TS 2000-01-05 *)
    g01opmsg (sp3p_console, sp3m_warning, csp3_b01_bad_index_cnt,
          csp3_n_btree, 'bad index count         ', b01bad_index_cnt);
(* PTS 1104961 TS 2000-01-05 *)
&ifdef TRACE
(*ENDIF*) 
t01basis_error (bi, 'get bad inde',t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd01create_file (VAR t : tgg00_TransContext;
            VAR file_id      : tgg00_FileId;
            stringcol_cnt    : tsp00_Int2;
            varcol_cnt_off   : tsp00_Int2;
            no_tree_index    : boolean);
 
VAR
      aux_error  : tgg00_BasisError;
      fi         : tbd_fileinfo;
      current    : tbd_current_tree;
      fn_trace   : tgg11_BdFilenameTrace;
      root_trace : tgg11_BdRootTrace;
 
BEGIN
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    fn_trace.bdfTrType_gg11 := bdtrFilename_egg11;
    fn_trace.bdfFn_gg11     := file_id.fileName_gg00;
    b120InsertTrace (t, bd, b01create, sizeof (fn_trace), @fn_trace)
    END;
(*ENDIF*) 
b30cinit_current (t, current);
IF  b01downfilesystem
THEN
    t.trError_gg00 := e_shutdown
ELSE
    BEGIN
    t.trError_gg00 := e_ok;
    WITH fi DO
        BEGIN
        fi_type := file_id.fileType_gg00;
        IF  no_tree_index
        THEN
            fi_state := [f_no_tree_index]
        ELSE
            fi_state := [];
        (*ENDIF*) 
        IF  (ftsPerm_egg00 in fi_type   ) OR
            (ftsByteStr_egg00 in fi_type)
        THEN
            fi_type := fi_type + [ftsConcurrent_egg00];
        (*ENDIF*) 
        file_id.fileType_gg00 := fi_type;
        fi_descr              := [];
        fi_root               := NIL_PAGE_NO_GG00;
        fi_vers               := file_id.fileVersion_gg00;
        IF  stringcol_cnt > 0
        THEN
            BEGIN
            fi_col_cnt         := stringcol_cnt;
            fi_var_col_cnt_pos := varcol_cnt_off;
            IF  fi_var_col_cnt_pos <> cgg_nil_varcol_cnt_off
            THEN
                fi_descr := [fid_new_long_col]
            (*ENDIF*) 
            END
        ELSE
            BEGIN
            fi_col_cnt         := 0;
            fi_var_col_cnt_pos := cgg_nil_varcol_cnt_off
            END;
        (*ENDIF*) 
        gg06SetNilRef (fi_user_ref)
        END;
    (*ENDWITH*) 
    b30fdir_to_treeid (fi, file_id);
    current.curr_tree_id := file_id;
    bd999CheckSpace (t, 1);
    IF  t.trError_gg00 = e_ok
    THEN
        b30new_tree (fi, current);
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        b17add_fdir (file_id.fileName_gg00, fi, t);
    (*ENDIF*) 
    IF  (t.trError_gg00 = e_duplicate_filename)
    THEN
        BEGIN
        aux_error      := t.trError_gg00;
        t.trError_gg00 := e_ok;
        b13pfree_pno (current.curr_tree_id.fileRoot_gg00, current);
        IF  t.trError_gg00 = e_ok
        THEN
            t.trError_gg00 := aux_error
        (*ENDIF*) 
        END;
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        file_id := current.curr_tree_id
    (*ENDIF*) 
    END;
(*ENDIF*) 
IF  g01vtrace.vtrAll_gg00 OR g01vtrace.vtrBdPrim_gg00
THEN
    BEGIN
    root_trace.bdrTrType_gg11 := bdtrRoot_egg11;
    root_trace.bdrRoot_gg11   := file_id.fileRoot_gg00;
    root_trace.bdrError_gg11  := t.trError_gg00;
    b120InsertTrace (t, bd, b01create, sizeof (root_trace), @root_trace)
    END;
&ifdef TRACE
(*ENDIF*) 
t01treeid      (bi, 'new treeid  ', file_id);
t01basis_error (bi, 'create err  ', t.trError_gg00);
&endif
END;
 
(*------------------------------*) 
 
PROCEDURE
      bd01destroy_file (VAR t : tgg00_TransContext;
            VAR file_id       : tgg00_FileId;
            VAR trace_root    : tsp00_PageNo);
 
VAR
      IsInvTree : boolean;
      fi        : tbd_fileinfo;
      current   : tbd_current_tree;
 
BEGIN
t.trError_gg00         := e_ok;
file_id.fileBdUse_gg00 := file_id.fileBdUse_gg00 + [bd_release_acc];
b30cinit_current (t, current);
b17del_fdir (file_id.fileName_gg00, fi, ftsShared_egg00 in file_id.fileType_gg00, t);
IF  (t.trError_gg00 = e_ok) AND (fi.fi_root <> NIL_PAGE_NO_GG00)
THEN
    BEGIN
    b30fdir_to_treeid (fi, file_id);
    current.curr_tree_id := file_id;
    IsInvTree            := g04inv_tfn (file_id.fileTfn_gg00);
    IF  (ftsConcurrent_egg00 in fi.fi_type) AND NOT IsInvTree
        AND NOT (ftsObject_egg00 in fi.fi_type)
    THEN
        b75tldelete_lock_tree (current, c_ignore_svp, 26);
    (*ENDIF*) 
    current.curr_action := m_drop;
    trace_root          := file_id.fileRoot_gg00;
    IF  IsInvTree
    THEN
        bd03ReleaseInvTree (current.curr_trans^, current.curr_tree_id)
    ELSE
        IF  ftsByteStr_egg00 in fi.fi_type
        THEN
            b60release_bytestr (current)
        ELSE
            BEGIN
&           ifdef TRACE
            t01int4 (bi, 'scol count  ', fi.fi_col_cnt);
&           endif
            IF  fid_new_long_col in fi.fi_descr
            THEN
                b30release_tree (current, fi.fi_col_cnt,
                      fi.fi_var_col_cnt_pos, NOT c_only_empty)
            ELSE
                b30release_tree (current, fi.fi_col_cnt,
                      cgg_nil_varcol_cnt_off, NOT c_only_empty);
            (*ENDIF*) 
            END;
        (*ENDIF*) 
    (*ENDIF*) 
    IF  t.trError_gg00 = e_bad_datapage
    THEN
        t.trError_gg00 := e_ok;
    (*ENDIF*) 
    IF  t.trError_gg00 = e_ok
    THEN
        BEGIN
        IF  f_not_accessible IN fi.fi_state
        THEN
            BEGIN
            b01bad_index_cnt := pred (b01bad_index_cnt);
            IF  b01bad_index_cnt < 0
            THEN
                b01bad_index_cnt := 0;
&           ifdef TRACE
            (*ENDIF*) 
            t01int4        (bi, 'destroy idx ', b01bad_index_cnt);
&           endif
            END;
        (*ENDIF*) 
        file_id               := current.curr_tree_id;
        file_id.fileRoot_gg00 := NIL_PAGE_NO_GG00
        END
    (*ENDIF*) 
    END;
(*ENDIF*) 
file_id.fileBdUse_gg00 := file_id.fileBdUse_gg00 - [bd_release_acc];
IF  t.trError_gg00 = e_file_unloaded
THEN
    t.trError_gg00 := e_ok;
(*ENDIF*) 
IF  current.curr_lockstate = d_lock_tree
THEN
    b75tudelete_unlock_tree (current)
(*ENDIF*) 
END;
 
.CM *-END-* code ----------------------------------------
.SP 2 
***********************************************************
.PA 
