/*static char *SCCSID = "@(#)closeup.c  6.1 90/11/17";*/
/*static char *SCCSID = "@(#)closeup.c  13.3 90/01/25";*/
// @75229 - move to _BTXT
#define _BTXT _BTXT

#include <os2def.h>
#include "api.h"
#include "const.h"
#include "misc.h"
#include "chain.h"
#include "buf.h"
#include "dir.h"
#include "storage.h"
#include "fnode.h"
#include "volume.h"
#include "tables.h"
#include "pb_ifs.h"
#include "superb.h"
#include "lw.h"
#include "frame.h"
#include "fsdata.h"
#include "assert.h"

#include "pr_DEL.h"
#include "pr_MISC.h"


/***    Closeup - Close up Directory Block
 *
 *      Closeup is called to remove a record from a directory block.
 *      The remaining parts of the block are moved up to overlay
 *      the removed record.
 *
 *      The DIRBLK values are updated to represent the closure.
 *
 *      Closeup only manipulates the DIRBLK fields, it doesn't
 *      deal with down pointers or otherwise maintain the
 *      BTREE structure.
 *
 *      Closeup also doesn't set the dirty bits.  It does flag
 *      the directory block changed.
 *
 *      ENTRY   pdb = address of dir block
 *              pde = address of entry
 *
 *      HISTORY
 *          03-Oct-1988 08:08 by Bill McJohn [t-billm]
 *                              Xlated from 9/28/88 assembly code
 */

void far
Closeup (pdb, pde)
PDIRBLK pdb;    /* ptr to DIRBLK from which the DIRENT will be deleted  */
PDIRENT pde;    /* ptr to DIRENT which is to be deleted  */
{
        USHORT cbToCopy;

        ASSERT_DB (pdb);
        ASSERT_DE (pde);

        /*  Determine the number of bytes to copy  */
#ifdef DEBUG
        if (pdb->offulFirstFree > DIRBLKS) {
                INTERR ("Closeup: pdb->offulFirstFree too big");
        }
#endif
        cbToCopy = (USHORT) (pdb->offulFirstFree - ((PBYTE)pde - (PBYTE)pdb) -
                        pde->cchThisEntry);

#ifdef DEBUG
            if (cbToCopy % 4)
                INTERR ("CLOSEUP:  size of DIRENT is not a multiple of four.");
            if (cbToCopy > 0x1000)
                INTERR ("CLOSEUP:  size of DIRENT is greater than 0x1000.");
#endif

        /*  Update the DIRBLK First Free field before the
         *  doomed pde gets wiped out.
         */
        pdb->offulFirstFree -= pde->cchThisEntry;

        /*  Since BYTE_COPY low-to-high, and we are copying from
         *  higher to lower, there is no problem with overlapping.
         */
        BYTE_COPY (NEXT_ENTRY (pde), pde, cbToCopy);

        pdb->culChange += 2;
}
