⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 insrec.c

📁 T-kernel 的extension源代码
💻 C
📖 第 1 页 / 共 2 页
字号:
	if ( err < E_OK ) {		goto err_ret;	}	pkt->cmd.ret = error;	setSyncAtExit(SAE_OPENF, ofcb->fsinfo);	return;err_ret:	DEBUG_PRINT(("fmpInsertRecord err = %d\n", err));	pkt->cmd.ret = err;	setSyncAtExit(SAE_OPENF, ofcb->fsinfo);	return;}/* * Add the record. */EXPORT void fmpAppendRecord( FmCmdPkt *pkt ){	FM_APD_REC_PARA	*cmdPara = (FM_APD_REC_PARA*)pkt->cmd.para;	FD		*fd;	OFCB		*ofcb;	RCB		*rcb;	ER		err, error = E_OK;	/* Obtain FD and OFCB */	fd = getFDp(cmdPara->fd);	ofcb = fd->ofcb;	/* Check the open mode. */	err = fmpCheckFileOpenMode(fd, F_WRITE);	if ( err < E_OK ) {		goto err_ret;	}	/* Parameter check */	if ( !((cmdPara->type >= 0) && (cmdPara->type < TSD_FPR_VAL_32))	   || (cmdPara->size < 0) ) {		err = E_PAR;		goto err_ret;	}	if ( isLinkRecord(cmdPara->type) != 0 ) {		/* Check when the link record is added. */		if ( ((UW)cmdPara->size != sizeof(LINK))		  || (cmdPara->buf == NULL) ) {			err = E_PAR;			goto err_ret;		}		err = CheckSpaceR(cmdPara->buf, sizeof(LINK));		if ( err < E_OK ) {			goto err_ret;		}		/* Check the contents of LINK. */		err = checkLINK((LINK*)cmdPara->buf, ofcb->fsinfo);		if ( err < E_OK ) {			goto err_ret;		}	}	/* Add the record. */	err = appendRecord(&rcb, ofcb,			cmdPara->type, cmdPara->subtype, (LINK*)cmdPara->buf);	if ( err < E_OK ) {		goto err_ret;	}	if ( isDataRecord(cmdPara->type) && (cmdPara->size > 0) ) {		/* Write the data record. */		err = fmpWriteDataRecord(rcb, ofcb,			0, cmdPara->buf, cmdPara->size, cmdPara->units);		if ( err < E_OK ) {			if ( err != E_NODSK ) {				goto err_ret;			}			error = err;		}	}	/* Update the time stamp. */	err = fmpSetTimeStamp(ofcb, F_WRITE);	if ( err < E_OK ) {		goto err_ret;	}	pkt->cmd.ret = error;	setSyncAtExit(SAE_OPENF, ofcb->fsinfo);	return;err_ret:	DEBUG_PRINT(("fmpAppendRecord err = %d\n", err));	pkt->cmd.ret = err;	setSyncAtExit(SAE_OPENF, ofcb->fsinfo);	return;}/* * Add the link record for internal use. */EXPORT ER fmpIAppendLinkRecord( OFCB *ofcb, LINK *lnk ){	RIdx		ri;	RCB		*currcb;	DfRecordIndex	*ridx;	ER		err;	if ( ofcb->ref == 0 ) {		/* The management of rcb is not required when it is not referred from others. */		currcb = NULL;	} else {		currcb = prevRCB(EndRCB(ofcb));	}	/* Up the reference count of the file (lnk). */	err = changeFileReferenceCount(lnk->f_id, (+1), ofcb->fsinfo);	if ( err < E_OK ) {		goto err_ret1;	}	/* Locate ri at the last record index. */	err = fmpOpenRIdx(&ri, LAST_RIdx, ofcb);	if ( err < E_OK ) {		goto err_ret1;	}	ridx = fmpGetRIdx(&ri);	if ( ridx == NULL ) {		goto err_ret3;	}	/* Whether the current location is an unused record index. */	if ( !((ridx->type[0] == 0) && (ridx->type[1] == 0)) ) {		/* It is used. */		/* Add the record index. */		ridx = fmpAppendRIdx(&ri, currcb);		if ( ridx == NULL ) {			goto err_ret3;		}	}	if ( currcb != NULL ) {		/* Add the new RCB just before the end record. */		err = fmpNewRCB(EndRCB(ofcb));		if ( err < E_OK ) {			goto err_ret2;		}	}	/* Set the record index. */	err = fmpSetRIdx(&ri, 0, 0, lnk);	if ( err < E_OK ) {		goto err_ret2;	}	err = fmpCloseRIdx(&ri);	if ( err < E_OK ) {		goto err_ret1;	}	/* Update the total number of records of the file header. */	err = changeRecordCount(ofcb, 0, (+1));	if ( err < E_OK ) {		goto err_ret1;	}	/* Update the time stamp. */	err = fmpSetTimeStamp(ofcb, F_WRITE);	if ( err < E_OK ) {		goto err_ret1;	}	return E_OK;err_ret3:	err = fmpGetRIdxError(&ri);err_ret2:	(void)fmpCloseRIdx(&ri);err_ret1:	DEBUG_PRINT(("fmpIAppendLinkRecord err = %d\n", err));	return err;}/* ----------------------------------------------------------------------- *//* * Decrease the file reference count by1. *	When the reference count is decreased to 0, return 1. Otherwise, return 0. */EXPORT WER fmpDecrementFileReferenceCount( DfLinkIndex *lidx, FsInfo *fsinfo ){	W		refcnt;	FID		fid;	ER		err;	fid = fmpConvEndianH(lidx->fid, fsinfo);	/* Decreased the reference count. */	refcnt = changeFileReferenceCount(fid, TSD_FRC_VAL_M1, fsinfo);	if ( refcnt < E_OK ) {		err = (ER)refcnt;		goto err_ret;	}	return ( refcnt == 0 )? 1: 0;err_ret:	DEBUG_PRINT(("fmpDecrementFileReferenceCount err = %d\n", err));	return err;}/* * Delete the record. *	Delete the record of rcb (and rcb), and change the current record of fd *	to the next record to rcb. *	When the deleted record is a link record and the reference count of the file being *	referred to become 0, return 1 to the return value. Otherwise, return 0. */LOCAL WER deleteRecord( FD *fd, RCB *rcb, OFCB *ofcb ){	RIdx		ri;	DfRecordIndex	*ridx;	W		noref;	ER		err;	/* Prepare to obtain the record index. */	err = fmpOpenRIdx(&ri, &rcb->idxadr, ofcb);	if ( err < E_OK ) {		goto err_ret1;	}	/* Obtain the record index. */	ridx = fmpGetRIdx(&ri);	if ( ridx == NULL ) {		goto err_ret3;	}	if ( isLinkRecord(rcb->rtype) != 0 ) {		/* Update the file reference count. */		noref = fmpDecrementFileReferenceCount(&ridx->l, ofcb->fsinfo);		if ( noref < E_OK ) {			err = (ER)noref;			goto err_ret2;		}	} else {		noref = 0;	}	/* Delete the record index. */	err = fmpDeleteRIdx(&ri);	if ( err < E_OK ) {		goto err_ret2;	}	err = fmpCloseRIdx(&ri);	if ( err < E_OK ) {		goto err_ret1;	}	/* Update the total number of records of the file header. */	err = changeRecordCount(ofcb, (W)rcb->rtype, TSD_DRD_VAL_M1);	if ( err < E_OK ) {		goto err_ret1;	}	/* Move the current record to the next record. */	fmpMoveCurRecord(fd, nextRCB(rcb));	/* Delete rcb, and decrease the following record numbers by 1. */	fmpDeleteRCB(rcb, ofcb);	return noref;err_ret3:	err = fmpGetRIdxError(&ri);err_ret2:	(void)fmpCloseRIdx(&ri);err_ret1:	DEBUG_PRINT(("deleteRecord err = %d\n", err));	return err;}/* * Delete the record. */EXPORT void fmpDeleteRecord( FmCmdPkt *pkt ){	FM_DEL_REC_PARA	*cmdPara = (FM_DEL_REC_PARA*)pkt->cmd.para;	FD		*fd;	OFCB		*ofcb;	RCB		*rcb;	W		noref;	ER		err;	/* Obtain FD and OFCB. */	fd = getFDp(cmdPara->fd);	ofcb = fd->ofcb;	/* Check the open mode. */	err = fmpCheckFileOpenMode(fd, F_WRITE);	if ( err < E_OK ) {		goto err_ret;	}	/* Obtain the current record. */	err = fmpSetRCB(rcb = fd->crcb, ofcb);	if ( err < E_OK ) {		goto err_ret;	}	/* Check the record lock. */	if ( isLockRecord(fd, rcb) != 0 ) {		err = E_LOCK;		goto err_ret;	}	/* Check the record map. */	if ( isMapRecord(rcb) != 0 ) {		err = E_BUSY;		goto err_ret;	}	/* Whether it is referred from others as the current record. */	if ( rcb->ref > 1 ) {		err = E_BUSY;		goto err_ret;	}	if ( isDataRecord(rcb->rtype) && (rcb->rsize > 0) ) {		/* Delete the data. */		err = fmpTruncateDataRecord(rcb, ofcb, 0);		if ( err < E_OK ) {			goto err_ret;		}	}	/* Delete the record. */	noref = deleteRecord(fd, rcb, ofcb);	if ( noref < E_OK ) {		err = (ER)noref;		goto err_ret;	}	/* Update the time stamp. */	err = fmpSetTimeStamp(ofcb, F_WRITE);	if ( err < E_OK ) {		goto err_ret;	}	pkt->cmd.ret = noref;	setSyncAtExit(SAE_OPENF, ofcb->fsinfo);	return;err_ret:	DEBUG_PRINT(("fmpDeleteRecord err = %d\n", err));	pkt->cmd.ret = err;	setSyncAtExit(SAE_OPENF, ofcb->fsinfo);	return;}/* * Delete the link record for internal use. *	Delete the link record of the record index that iadr indicates. *	rcb must correspond to the link record that iadr indicates. *	rcb is also deleted together with the link record. *	However, when rcb == NULL, the management of rcb is not performed. */EXPORT ER fmpIDeleteLinkRecord( OFCB *ofcb, IdxAdr *iadr, RCB *rcb ){	RIdx		ri;	DfRecordIndex	*ridx;	ER		err;	/* Prepare to obtain the record index. */	err = fmpOpenRIdx(&ri, iadr, ofcb);	if ( err < E_OK ) {		goto err_ret1;	}	/* Obtain the record index. */	ridx = fmpGetRIdx(&ri);	if ( ridx == NULL ) {		goto err_ret3;	}	/* Update the file reference count. */	err = fmpDecrementFileReferenceCount(&ridx->l, ofcb->fsinfo);	if ( err < E_OK ) {		goto err_ret2;	}	/* Delete the record index. */	err = fmpDeleteRIdx(&ri);	if ( err < E_OK ) {		goto err_ret2;	}	err = fmpCloseRIdx(&ri);	if ( err < E_OK ) {		goto err_ret1;	}	/* Update the total number of records of the file header. */	err = changeRecordCount(ofcb, 0, TSD_DRD_VAL_M1);	if ( err < E_OK ) {		goto err_ret1;	}	if ( rcb != NULL ) {		/* Delete rcb, and decrease the following record numbers by 1. */		fmpDeleteRCB(rcb, ofcb);	}	/* Update the time stamp. */	err = fmpSetTimeStamp(ofcb, F_WRITE);	if ( err < E_OK ) {		goto err_ret1;	}	return E_OK;err_ret3:	err = fmpGetRIdxError(&ri);err_ret2:	(void)fmpCloseRIdx(&ri);err_ret1:	DEBUG_PRINT(("fmpIDeleteLinkRecord err = %d\n", err));	return err;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -