📄 _fs_setfpos.c
字号:
/*----------------------------------------------------------------------------
* R T L - F l a s h F i l e S y s t e m
*----------------------------------------------------------------------------
* Name: _FS_SETFPOS.C
* Purpose: Low level Set File Position Indicator Function
* Rev.: V3.22
*----------------------------------------------------------------------------
* This code is part of the RealView Run-Time Library.
* Copyright (c) 2004-2008 KEIL - An ARM Company. All rights reserved.
*---------------------------------------------------------------------------*/
#include "File_Config.h"
/*--------------------------- __setfpos -------------------------------------*/
int __setfpos (int handle, U32 pos) {
/* Low level Set file position pointer function. */
FALLOC fa;
IOB *fcb;
U32 bl,adr,fidx,prev;
U32 i,fpos;
fcb = &_iob[handle];
if (fcb->drive == DRV_MCARD) {
if (fat_set_fpos (fcb, pos) == __TRUE) {
/* File Position indicator changed. */
return (0);
}
return (-1);
}
if (fcb->flags & _IOWRT) {
if ((fcb->flags & _IOAPPEND) && (fcb->fsize == pos)) {
if (fs_AllocBlock (fcb) == __TRUE) {
return (0);
}
}
return (-1);
}
fidx = 0;
fpos = 0;
bl = fcb->_fblock;
nextbl:
for (i = 0; i < fcb->NumSect; i++) {
/* Search for file blocks identified with identification 'fileID' */
adr = fs_adr_sig (bl, fcb);
adr = fs_rd_sig (adr, &fa.end);
if (fa.end != fcb->InitVal) {
for (prev = 0; ; prev = fa.end) {
adr = fs_rd_alloc (adr, &fa);
if (fa.fileID == fcb->fileID && fa.index == fidx) {
/* All file blocks are 4-byte aligned. */
prev = (prev + 3) & ~3;
fidx++;
if (fpos + (fa.end - prev) < pos) {
/* Go and try next File Block */
fpos += (fa.end - prev);
goto nextbl;
}
/* OK, the right File Block Index is found */
fcb->_fblock = bl;
fcb->_fidx = fidx;
/* File opened for read. */
fcb->_fbot = prev + pos - fpos;
fcb->_ftop = fa.end;
return (0);
}
if (fa.end == fcb->InitVal) break;
}
}
if (++bl == fcb->NumSect) {
bl = 0;
}
}
return (-1);
}
/*----------------------------------------------------------------------------
* end of file
*---------------------------------------------------------------------------*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -