📄 findrec.c
字号:
/* From the current record */ rcb = fd->crcb; } else if ( cmdPara->mode > 0 ) { /* From the start record */ rcb = FirstRCB(ofcb); } else { /* From the end record */ rcb = EndRCB(ofcb); } /* Move the record. */ err = seekRecord(&rcb, cmdPara->offset, ofcb); if ( err < E_OK ) { goto err_ret; } /* Return the record number to recnum. */ err = setRecnum(cmdPara->recnum, rcb, ofcb); if ( err < E_OK ) { goto err_ret; } /* Move the current record. */ fmpMoveCurRecord(fd, rcb); pkt->cmd.ret = E_OK; return;err_ret: DEBUG_PRINT(("fmpSeekRecord err = %d\n", err)); pkt->cmd.ret = err; return;}/* * Record retrieval */EXPORT void fmpFindRecord( FmCmdPkt *pkt ){ FM_FND_REC_PARA *cmdPara = (FM_FND_REC_PARA*)pkt->cmd.para; FD *fd; OFCB *ofcb; RCB *rcb; W fwd; ER err; /* Obtain FD and OFCB. */ fd = getFDp(cmdPara->fd); ofcb = fd->ofcb; /* Start record */ rcb = fd->crcb; fwd = startRecord(&rcb, cmdPara->mode, ofcb); if ( fwd < E_OK ) { err = (ER)fwd; goto err_ret; } /* Record retrieval */ err = findRecord(&rcb, fwd, cmdPara->typemask, cmdPara->subtype, ofcb); if ( err < E_OK ) { goto err_ret; } /* Return the record number to recnum. */ err = setRecnum(cmdPara->recnum, rcb, ofcb); if ( err < E_OK ) { goto err_ret; } /* Move the current record. */ fmpMoveCurRecord(fd, rcb); pkt->cmd.ret = (W)rcb->rtype; return;err_ret: DEBUG_PRINT(("fmpFindRecord err = %d\n", err)); pkt->cmd.ret = err; return;}/* * Link record retrieval */EXPORT void fmpFindLinkRecord( FmCmdPkt *pkt ){ FM_FND_LNK_PARA *cmdPara = (FM_FND_LNK_PARA*)pkt->cmd.para; FD *fd; OFCB *ofcb; RCB *rcb; W fwd; ER err; /* Obtain FD and OFCB. */ fd = getFDp(cmdPara->fd); ofcb = fd->ofcb; /* lnk check */ if ( ((UW)cmdPara->mode & ~TSD_FFR_MSK_0XF) != 0U ) { err = CheckSpaceR(cmdPara->lnk, sizeof(LINK)); if ( err < E_OK ) { goto err_ret; } } /* Start record */ rcb = fd->crcb; fwd = startRecord(&rcb, (UW)cmdPara->mode & TSD_FFR_MSK_0XF, ofcb); if ( fwd < E_OK ) { err = (ER)fwd; goto err_ret; } /* Link record retrieval */ err = findLinkRecord(&rcb, fwd, (UW)cmdPara->mode & ~TSD_FFR_MSK_0XF, cmdPara->lnk, cmdPara->subtype, ofcb); if ( err < E_OK ) { goto err_ret; } /* Return the record number to recnum. */ err = setRecnum(cmdPara->recnum, rcb, ofcb); if ( err < E_OK ) { goto err_ret; } /* Move the current record. */ fmpMoveCurRecord(fd, rcb); pkt->cmd.ret = E_OK; return;err_ret: DEBUG_PRINT(("fmpFindLinkRecord err = %d\n", err)); pkt->cmd.ret = err; return;}/* ------------------------------------------------------------------------ *//* * Link record retrieval (For opened files) * When fid >= 0, * Find a link record that refers to the file of file ID (fid). * When fname != NULL, * Find a link record that refers to the file of file name (fname). * The location of n th link record is defined as the current location of ri. * Return the corresponding RCB to *rcb. * If not found, return E_NOEXS. */LOCAL ER searchLinkRecord_O( RIdx *ri, W fid, FileName fname, W n, RCB **rcb, OFCB *ofcb ){ FsInfo *fsinfo = ofcb->fsinfo; BOOL match = FALSE; SFN sfn; DfRecordIndex *ridx; FID id; RCB *p; ER err; if ( fname != NULL ) { /* Prepare to retrieve the file name. */ err = fmpOpenSFN(&sfn, fname, fsinfo); if ( err < E_OK ) { goto err_ret1; } } for ( p = FirstRCB(ofcb); p != EndRCB(ofcb); p = nextRCB(p) ) { /* Make valid the contents of RCB. */ err = fmpSetRCB(p, ofcb); if ( err < E_OK ) { goto err_ret2; } if ( isLinkRecord(p->rtype) != 0 ) { /* Obtain the record index. */ err = fmpSeekRIdx(ri, &p->idxadr); if ( err < E_OK ) { goto err_ret2; } ridx = fmpGetRIdx(ri); if ( ridx == NULL ) { goto err_ret3; } id = fmpConvEndianH(ridx->l.fid, fsinfo); if ( fid >= 0 ) { /* File ID matched? */ match = ( fid == id ); } if ( fname != NULL ) { /* File name matched? */ err = fmpMatchSFN(&sfn, id, NULL); if ( err < E_OK ) { goto err_ret2; } match = (BOOL)err; } if ( match && (--n <= 0) ) { break; } match = FALSE; } } if ( fname != NULL ) { err = fmpCloseSFN(&sfn); if ( err < E_OK ) { goto err_ret1; } } *rcb = p; return ( match != 0 )? E_OK: E_NOEXS;err_ret3: err = fmpGetRIdxError(ri);err_ret2: if ( fname != NULL ) { (void)fmpCloseSFN(&sfn); }err_ret1: DEBUG_PRINT(("searchLinkRecord_O err = %d\n", err)); return err;}/* * Link record retrieval (For files not opened) * When fid >= 0, * Find a link record that refers to the file of file ID (fid). * When fname != NULL, * Find a link record that refers to the file of file name (fname) * The location of n th link record is defined as the current location of ri. * If not found, return E_NOEXS. */LOCAL ER searchLinkRecord_C( RIdx *ri, W fid, FileName fname, W n, OFCB *ofcb ){ FsInfo *fsinfo = ofcb->fsinfo; BOOL match = FALSE; SFN sfn; DfRecordIndex *ridx; FID id; W i; ER err; if ( fname != NULL ) { /* Prepare to retrieve the file name. */ err = fmpOpenSFN(&sfn, fname, fsinfo); if ( err < E_OK ) { goto err_ret1; } } for ( i = 0; i < ofcb->nrec; ++i ) { /* Obtain the record index. */ ridx = fmpGetRecordRIdx(ri); if ( ridx == NULL ) { goto err_ret2; } if ( ridx->type[1] == TSD_SLR_VAL_0X80 ) { id = fmpConvEndianH(ridx->l.fid, fsinfo); if ( fid >= 0 ) { /* File ID matched? */ match = ( fid == id ); } if ( fname != NULL ) { /* File name matched? */ err = fmpMatchSFN(&sfn, id, NULL); if ( err < E_OK ) { goto err_ret2; } match = (BOOL)err; } if ( match && (--n <= 0) ) { break; } match = FALSE; } } if ( fname != NULL ) { err = fmpCloseSFN(&sfn); if ( err < E_OK ) { goto err_ret1; } } return ( match != 0 )? E_OK: E_NOEXS;err_ret2: if ( fname != NULL ) { (void)fmpCloseSFN(&sfn); }err_ret1: err = fmpGetRIdxError(ri); DEBUG_PRINT(("searchLinkRecord_C err = %d\n", err)); return err;}/* * Retrieve the link record for internal use. * Retrieve the link record that refers to the file of fid from the file of ofcb, * and return the address of the record index of the record to *iadr. * When ofcb is opened, return the RCB corresponding to *iadr to *rcb. * If not opened, *rcb = NULL. * If the link record is not found, return E_NOEXS. */EXPORT ER fmpISearchLinkRecord( OFCB *ofcb, FID fid, IdxAdr *iadr, RCB **rcb ){ RIdx ri; ER err; /* Prepare to read the record index. */ err = fmpOpenRIdx(&ri, FIRST_RIdx, ofcb); if ( err < E_OK ) { goto err_ret1; } if ( ofcb->ref > 0 ) { /* Opened. */ err = searchLinkRecord_O(&ri, (W)fid, NULL, 1, rcb, ofcb); if ( err < E_OK ) { goto err_ret2; } } else { /* Not opened. */ err = searchLinkRecord_C(&ri, (W)fid, NULL, 1, ofcb); if ( err < E_OK ) { goto err_ret2; } *rcb = NULL; } *iadr = fmpGetIdxAdr(&ri); err = fmpCloseRIdx(&ri); if ( err < E_OK ) { goto err_ret1; } return E_OK;err_ret2: (void)fmpCloseRIdx(&ri);err_ret1: DEBUG_PRINT(("fmpISearchLinkRecord err = %d\n", err)); return err;}/* * Record retrieval for internal use * Retrieve the link record that refers to the file of fname from the file of ofcb. * Return the contents of n th link record to lnk. * If the target link record is not found, return E_NOEXS. */EXPORT ER fmpISearchFile( OFCB *ofcb, FileName fname, W n, LINK *lnk ){ RIdx ri; DfRecordIndex *ridx; W cp; RCB *rcb; ER err; /* Prepare to read the record index. */ err = fmpOpenRIdx(&ri, FIRST_RIdx, ofcb); if ( err < E_OK ) { goto err_ret1; } if ( ofcb->ref > 0 ) { /* Opened. */ err = searchLinkRecord_O(&ri, TSD_FIS_VAL_M1, fname, n, &rcb, ofcb); if ( err < E_OK ) { goto err_ret2; } } else { /* Not opened. */ err = searchLinkRecord_C(&ri, TSD_FIS_VAL_M1, fname, n, ofcb); if ( err < E_OK ) { goto err_ret2; } } /* Obtain LINK */ ridx = fmpGetMapAdr(&ri, &cp); fmpLIdxToLINK(lnk, &ridx->l, ofcb->fsinfo); err = fmpCloseRIdx(&ri); if ( err < E_OK ) { goto err_ret1; } return E_OK;err_ret2: (void)fmpCloseRIdx(&ri);err_ret1: DEBUG_PRINT(("fmpISearchFile err = %d\n", err)); return err;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -