Esempio n. 1
0
int readFileHead(VolInfo* volInfo, bk_off_t position, char* pathAndName, 
                 bool onImage, unsigned char* dest, int numBytes)
{
    int srcFile;
    bool srcFileWasOpened;
    bk_off_t origPos;
    int rc;
    
    if(onImage)
    {
        srcFile = volInfo->imageForReading;
        origPos = bkSeekTell(volInfo->imageForReading);
        bkSeekSet(volInfo->imageForReading, position, SEEK_SET);
        srcFileWasOpened = false;
    }
    else
    {
        srcFile = open(pathAndName, O_RDONLY, 0);
        if(srcFile == -1)
            return BKERROR_OPEN_READ_FAILED;
        srcFileWasOpened = true;
    }
    
    rc = bkRead(srcFile, dest, numBytes);
    
    if(srcFileWasOpened)
        bkClose(srcFile);
    else
        bkSeekSet(volInfo->imageForReading, origPos, SEEK_SET);
    
    if(rc != numBytes)
        return BKERROR_READ_GENERIC;
    
    return 1;
}
Esempio n. 2
0
/* PROGRAM: rlaiseek - read in the correct .ai file block into the
 *	current buffer
 * 
 * RETURNS: DSMVOID
 */
DSMVOID
rlaiseek(
	dsmContext_t	*pcontext,
	LONG		 aipos)
{
    dbcontext_t     *pdbcontext = pcontext->pdbcontext;
	AICTL	*paictl = pdbcontext->paictl;
	BKTBL	*pbktbl;
	AIBLK	*paiblk;

    if (aipos < 0L )
        FATAL_MSGN_CALLBACK(pcontext, rlFTL002);

    pbktbl = &(XAIBUF(pdbcontext, pdbcontext->paictl->aiqcurb)->aibk);

    paictl->ailoc  = aipos & paictl->aiblkmask;
    /* BUM - Assuming LONG(aipos & ~paictl->aiblkmask) < 2^15 */
    paictl->aiofst = (COUNT)(aipos & ~paictl->aiblkmask);
    pbktbl->bt_dbkey = (DBKEY)(aipos & paictl->aiblkmask);

    bkRead(pcontext, pbktbl);

    paiblk = XAIBLK(pdbcontext, pbktbl->bt_qbuf);
    if (paiblk->aihdr.aihdrlen == 0)
    {
        /* this is a virgin block, format it */

        if (paictl->ailoc == 0L)
	{
	    /* first block */

	    paiblk->aihdr.aihdrlen = sizeof(AIHDR) + sizeof(AIFIRST);
	    paiblk->aihdr.aiused = sizeof(AIHDR) + sizeof(AIFIRST);
	}
	else
	{
	    paiblk->aihdr.aihdrlen = sizeof(AIHDR);
	    paiblk->aihdr.aiused = sizeof(AIHDR);
	}
        /* #96-02-15-040 */
        paictl->aiofst = paiblk->aihdr.aiused;
    }
}
Esempio n. 3
0
/* PROGRAM: rlaiopn - open the	after-image (transaction-log) file
 *
 *
   Updates:
	    allocates an aictl
	    aictl.aibktbl will be setup.  If the ai is opened for output,
			  then that buffer will contain the current output
			  block of the ai file (the last block containing
			  valid data).	If the ai is opened for input,
			  then that buffer will contain the first blk of
			  the ai file.
	    aictl.aimode  will be set appropriately
	    aictl.aisize - physical EOF
	    aictl.ailoc  - input: start of file, output: logical EOF
	    aictl.aiofst - offset of ailoc within current ai block

   Some of the updates is diffrent for an off-line Transaction-log file
   which doe not use the noral AI mechanism, but is very similar to it.
									
 * NOTE: rlaiopn can be called by normal progress to open the .ai file	*
 *	 for input or output.						*
 *									*
 *	When being called for output, The caller should check		*
 *	pmstrblk->mb_ai.ainew and should not call rlaiopn if it is 0.	*
 *
 * RETURNS: 0 - on success
 *         -1 - on failure
 *          1 - only a partial ai file was detected
 */
int
rlaiopn(
	dsmContext_t	*pcontext,
	int  aimode,        /* AIINPUT or AIOUTPUT	*/
	TEXT *pname,        /* name of the .ai file	*/
	int  execmode,      /* non-zero => open for input with intent to rf */
	int  tmplog,        /* 1 for off-line TL file.   */
        int  retry)         /* 1 - retry active, 0 - retry inactive */  
{
    dbcontext_t     *pdbcontext = pcontext->pdbcontext;
    MSTRBLK *pmstr = pdbcontext->pmstrblk;
    AICTL	*paictl;
    AIBLK	*paiblk;
    BKTBL	*pbktbl;
struct  bkftbl  *pbkftbl = (struct bkftbl *)NULL;
    COUNT 	 buffmode;
    LONG	 ret;
    TEXT         timeString[TIMESIZE];
    UCOUNT       returnCode = 0;

    if (aimode == AIOUTPUT && pmstr->mb_aisync==UNBUFFERED && !tmplog)
	buffmode = UNBUFFERED;
    else buffmode = BUFFERED;

    /* allocate all buffers and control structures */
    rlaiseto (pcontext);

    /* get local pointer to global structure */
    paictl = pdbcontext->paictl;

    /* get the ai file size in bytes */
    if( pmstr->mb_aibusy_extent > (TEXT)0 )
    {
	/* using an extent, get the length of busy extent */
        paictl->aisize = rlaielen(pcontext, paictl->aiArea);
    }
    else
    {
	/* *** TODO: bkflen returns size in terms of database blocks */
	/* using a named file get the length directly */
        paictl->aisize = bkflen(pcontext, paictl->aiArea) *
            pdbcontext->pmstrblk->mb_aiblksize;
    }

    /* read the first ai block into current buffer */
    pbktbl = &(XAIBUF(pdbcontext, paictl->aiqcurb)->aibk);
    pbktbl->bt_dbkey = 0L;
    bkRead(pcontext, pbktbl);
    paiblk = XAIBLK(pdbcontext, pbktbl->bt_qbuf);

    /* Make sure we have a compatible version                */
    if (rlaiVersion(pcontext, paiblk))
    {
	/* AI file cannot be used with this database */
	MSGN_CALLBACK(pcontext, rlMSG094);
	return -1;
    }

    /* make sure blocksize matches database */
    if (rlaiblksize(pcontext, paiblk, paictl))
    {
	/* AI file cannot be used with this database */
	MSGN_CALLBACK(pcontext, rlMSG094);
	return -1;
    }

    /* Make sure the file is complete, BUG# 20000510-002 */
    if ( rlaiCompare(pcontext, paiblk, paictl) )
    {
        /* File lengths don't compare for whatever reason.
           Prohibit the ai seq num from being incremented so if the user 
           happens to find the correct, full ai file they can retry. */

        returnCode = 1;
    }

    /* setup for reading (rollforward) or writing (logging) to file */
    if (aimode == AIINPUT)
    {
	if ( execmode )
	{
         if ( retry )
            {
                /* Retry is activate - check extent status */
                if( paiblk->aifirst.aiextstate == AIEXTEMPTY )
                {
                    /* That's because this is an empty ai extent */
                    MSGN_CALLBACK(pcontext, rlMSG058);
                    return -1;
                }
                /* Ensure ai in proper sequence. */
                pmstr->mb_aiseq = pmstr->mb_aiseq ? pmstr->mb_aiseq : 1;
                if (paiblk->aifirst.aidates.aigennbr != pmstr->mb_aiseq)
                {
                    /* This ai file is not in the proper sequence for rretry. */
     /* Expected ai file number %l but file sepecified is %l in sequence. */
                    MSGN_CALLBACK(pcontext, rlMSG140, pmstr->mb_aiseq,
                                  paiblk->aifirst.aidates.aigennbr);
                    return -1;
                }
            }
            else if  (paiblk->aifirst.lstmod != pmstr->mb_lstmod )
	    {
		/* the time stamps dont match */
		if( paiblk->aifirst.aiextstate == AIEXTEMPTY )
		{
		    /* That's because this is an empty ai extent */
		    MSGN_CALLBACK(pcontext, rlMSG058);
		}
		else
		{
                    /* Ensure ai in proper sequence. */
                    pmstr->mb_aiseq = pmstr->mb_aiseq ? pmstr->mb_aiseq : 1;
                    if (paiblk->aifirst.aidates.aigennbr != pmstr->mb_aiseq)
                    {
                        /* ai file is not in the proper sequence for rollf. */
    /* "Expected ai file number %l but file sepecified is %l in sequence." */
                        MSGN_CALLBACK(pcontext, rlMSG140, pmstr->mb_aiseq,
                                      paiblk->aifirst.aidates.aigennbr);
                    }
		    MSGN_CALLBACK(pcontext, rlMSG001,
                                uttime((time_t *)&pmstr->mb_lstmod, timeString,
                                       sizeof(timeString)));
		    MSGN_CALLBACK(pcontext, rlMSG002,
		                  uttime((time_t *)&paiblk->aifirst.lstmod,
                                         timeString, sizeof(timeString)));
		    MSGN_CALLBACK(pcontext, rlMSG003);
		}
		return -1;
	    }
	}

	/* Init for reading from beginning of file */
	paictl->aiofst = paiblk->aihdr.aihdrlen;
	paictl->ailoc = pbktbl->bt_dbkey;
	paictl->aimode = AIINPUT;
    }
    else
    {
	/* file is being opened for output (logging) check the dates */
	if (paiblk->aifirst.aidates.aiopen != pmstr->mb_ai.aiopen)
        {
	    /* time stamps dont match */
            if( (pname == NULL) && 
                (pdbcontext->pmstrblk->mb_aibusy_extent > (TEXT)0) )
            {
		/* Means its an ai extent file */
		ret = bkGetAreaFtbl(pcontext, paictl->aiArea,&pbkftbl);
		pbkftbl += pdbcontext->pmstrblk->mb_aibusy_extent - 1;
                pname = XTEXT(pdbcontext, pbkftbl->ft_qname);
	    }
	    MSGN_CALLBACK(pcontext, rlMSG045, pname);
	    return -1;
	}

	/* get the current date/time and put into ai block */
	time(&paiblk->aifirst.aidates.aiopen);

	/* put time into masterblock */
	pmstr->mb_ai.aiopen = paiblk->aifirst.aidates.aiopen;

	/* write out both blocks */
	bkWrite(pcontext, pbktbl, UNBUFFERED);
	bmFlushMasterblock(pcontext);

	/* initialize ai control structure for logging */
        paictl->aiupdctr = paiblk->aifirst.aifirstctr;
        paictl->ailoc = pbktbl->bt_dbkey;
        paictl->aiofst = paiblk->aihdr.aihdrlen;
	paictl->aimode = AIOUTPUT;
    }
    /* done. ready to go */

    if ( returnCode )
    {
        /* detected partial ai file */
        return (1);
    }
    else
    {
        /* success */
        return (returnCode);
    }
}
Esempio n. 4
0
/* returns 2 if yes 1 if not
* works even if file1 == file2 */
int filesAreSame(VolInfo* volInfo, int file1, bk_off_t posFile1, 
                 int file2, bk_off_t posFile2, unsigned size)
{
    bk_off_t origPosFile1;
    bk_off_t origPosFile2;
    int numBlocks;
    int sizeLastBlock;
    int count;
    int rc;
    bool sameSoFar;
    
    if(size == 0)
        return 2;
    
    origPosFile1 = bkSeekTell(file1);
    origPosFile2 = bkSeekTell(file2);
    
    numBlocks = size / READ_WRITE_BUFFER_SIZE;
    sizeLastBlock = size % READ_WRITE_BUFFER_SIZE;
    
    sameSoFar = true;
    for(count = 0; count < numBlocks; count++)
    {
        bkSeekSet(file1, posFile1, SEEK_SET);
        rc = bkRead(file1, volInfo->readWriteBuffer, READ_WRITE_BUFFER_SIZE);
        if(rc != READ_WRITE_BUFFER_SIZE)
            return BKERROR_READ_GENERIC;
        posFile1 = bkSeekTell(file1);
        
        bkSeekSet(file2, posFile2, SEEK_SET);
        rc = bkRead(file2, volInfo->readWriteBuffer2, READ_WRITE_BUFFER_SIZE);
        if(rc != READ_WRITE_BUFFER_SIZE)
            return BKERROR_READ_GENERIC;
        posFile2 = bkSeekTell(file2);
        
        if( memcmp(volInfo->readWriteBuffer, volInfo->readWriteBuffer2, 
            READ_WRITE_BUFFER_SIZE) != 0 )
        {
            sameSoFar = false;
            break;
        }
    }
    
    if(sameSoFar && sizeLastBlock > 0)
    {
        bkSeekSet(file1, posFile1, SEEK_SET);
        rc = bkRead(file1, volInfo->readWriteBuffer, sizeLastBlock);
        if(rc != sizeLastBlock)
            return BKERROR_READ_GENERIC;
        
        bkSeekSet(file2, posFile2, SEEK_SET);
        rc = bkRead(file2, volInfo->readWriteBuffer2, sizeLastBlock);
        if(rc != sizeLastBlock)
            return BKERROR_READ_GENERIC;
        
        if(memcmp(volInfo->readWriteBuffer, volInfo->readWriteBuffer2, sizeLastBlock) != 0)
            sameSoFar = false;
    }
    
    bkSeekSet(file1, origPosFile1, SEEK_SET);
    bkSeekSet(file2, origPosFile2, SEEK_SET);
    
    if(sameSoFar)
        return 2;
    else
        return 1;
}