📄 zfsseek.c
字号:
/*
* File : ZFSSeek.c
* Description: This file contains the implementation of ZFSSeek API
* Author : Mahadev K C
* Created on : 30-APR-2003
*
* Copyright 2004 ZiLOG Inc. ALL RIGHTS RESERVED.
*
* This file contains unpublished confidential and proprietary information
* of ZiLOG, Inc.
* NO PART OF THIS WORK MAY BE DUPLICATED, STORED, PUBLISHED OR DISCLOSED
* IN ANY FORM WITHOUT THE PRIOR WRITTEN CONSENT OF ZiLOG, INC.
* This is not a license and no use of any kind of this work is authorized
* in the absence of a written license granted by ZiLOG, Inc. in ZiLOG's
* sole discretion
*/
#include "ZSysgen.h"
#include "ZTypes.h"
#include "ZThread.h"
#include "ZSemaphore.h"
#include "glextern.h"
extern RZK_SEMAPHOREHANDLE_t hSem_FS;
//Function Name: ZFSSeek
//Description: This API will change the offset in the file
ZFS_STATUS_t ZFSSeek( IN ZFS_HANDLE_t handle, IN INT32 offset, IN INT8 origin )
{
#define handle ((PZFS_OPEN_REC_t)handle)
INT32 off ;
INT32 new_off ;
ZFS_SEC_ID_t cur_sec_id ;
INT32 loc_size = 0 ;
ZFS_SEC_HDR_t sec_hdr ;
// if ZFS is not initialized, return error
if( !IsZFSInited() )
return ZFSERR_NOT_INITIALIZED ;
if( origin != ZFS_FILE_BEGIN && origin != ZFS_FILE_END && origin != ZFS_FILE_CURRENT )
return ZFSERR_INVALID_ARGUMENTS ;
// first check whether the handle is valid or not
if( handle->status != ZFS_OR_MAGIC_NUM )
return ZFSERR_INVALID_HANDLE ;
RZKAcquireSemaphore(hSem_FS,INFINITE_SUSPEND);
// preempt_status = DisablePreemption() ;
// if mode is APPEND, return error
if( handle->mode & ZFS_APPEND )
{
RZKReleaseSemaphore(hSem_FS);
// EnablePreemption( preempt_status ) ;
return ZFSERR_INVALID_OPERATION ;
}
if( origin == ZFS_FILE_BEGIN )
off = 0 ;
else if( origin == ZFS_FILE_END )
off = handle->size ;
else if( origin == ZFS_FILE_CURRENT )
off = handle->offset ;
new_off = offset + off ;
if( ( new_off > (INT32) handle->size ) || ( new_off < 0 ) )
{
RZKReleaseSemaphore(hSem_FS);
// EnablePreemption( preempt_status ) ;
return ZFSERR_INVALID_OFFSET_RANGE ;
}
handle->offset = new_off ;
// now traverse through the nodes to find where current offset lies
for( cur_sec_id = handle->first_secnum ; cur_sec_id != (ZFS_SEC_ID_t) FREE_SECTOR ; )
{
if( ( loc_size + ZFS_SEC_DATA_SIZE ) >= new_off )
{
// this is the sec id, just store it in or
handle->cur_secnum = cur_sec_id ;
break ;
}
// go to next linked sector.
handle->pvol->pcfg->pfn_drv_read( GetSecAddr( handle->pvol, cur_sec_id), &sec_hdr, sizeof( ZFS_SEC_HDR_t) );
cur_sec_id = sec_hdr.nxtsecnum ;
loc_size += ZFS_SEC_DATA_SIZE ;
}
RZKReleaseSemaphore(hSem_FS);
// EnablePreemption( preempt_status ) ;
return ZFSERR_SUCCESS ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -