src/backend/utils/sort/logtape.c
/*
 * Rewind logical tape and switch from reading to writing.
 *
 * NOTE: we assume the caller has read the tape to the end; otherwise
 * untouched data and indirect blocks will not have been freed. We
 * could add more code to free any unread blocks, but in current usage
 * of this module it'd be useless code.
 */
Rewind logical tape and switch from reading to writing.
NOTE: we assume the caller has read the tape to the end; otherwise
untouched data and indirect blocks will not have been freed. We
could add more code to free any unread blocks, but in current usage
of this module it'd be useless code.
Rewind logical tape and switch from reading to writing . NOTE : we assume the caller has read the tape to the end ; otherwise untouched data and indirect blocks will not have been freed . We could add more code to free any unread blocks but in current usage of this module it ' d be useless code .
void
LogicalTapeRewindForWrite(LogicalTapeSet *lts, int tapenum)
{
	LogicalTape *lt;
	IndirectBlock *ib,
			   *nextib;
	Assert(tapenum >= 0 && tapenum < lts->nTapes);
	lt = &lts->tapes[tapenum];
	Assert(!lt->writing && !lt->frozen);
	if (lt->indirect)
	{
		for (ib = lt->indirect->nextup; ib != NULL; ib = nextib)
		{
			nextib = ib->nextup;
			pfree(ib);
		}
		lt->indirect->nextSlot = 0;
		lt->indirect->nextup = NULL;
	}
	lt->writing = true;
	lt->dirty = false;
	lt->numFullBlocks = 0L;
	lt->lastBlockBytes = 0;
	lt->curBlockNumber = 0L;
	lt->pos = 0;
	lt->nbytes = 0;
	if (lt->buffer)
	{
		pfree(lt->buffer);
		lt->buffer = NULL;
		lt->buffer_size = 0;
	}
}
void LogicalTapeRewindForWrite ( LogicalTapeSet * lts , int tapenum ) { LogicalTape * lt ; IndirectBlock * ib , * nextib ; Assert ( tapenum >= 0 && tapenum < lts -> nTapes ) ; lt = & lts -> tapes [ tapenum ] ; Assert ( ! lt -> writing && ! lt -> frozen ) ; if ( lt -> indirect ) { for ( ib = lt -> indirect -> nextup ; ib != NULL ; ib = nextib ) { nextib = ib -> nextup ; pfree ( ib ) ; } lt -> indirect -> nextSlot = 0 ; lt -> indirect -> nextup = NULL ; } lt -> writing = true ; lt -> dirty = false ; lt -> numFullBlocks = 0L ; lt -> lastBlockBytes = 0 ; lt -> curBlockNumber = 0L ; lt -> pos = 0 ; lt -> nbytes = 0 ; if ( lt -> buffer ) { pfree ( lt -> buffer ) ; lt -> buffer = NULL ; lt -> buffer_size = 0 ; } }
Rewind logical tape and switch from reading to writing.
Rewind logical tape and switch from reading to writing .
/* Must truncate the indirect-block hierarchy down to one level. */