📄 zfsdelete.c
字号:
/*
* File : ZFSDelete.c
* Description: This file contains the implementation of ZFSDelete APIs
* 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: ZFSDelete
//Description: This API deletes a file
ZFS_STATUS_t ZFSDelete( IN INT8 *file_name )
{
UINT last_fd_off = 0 ;
UINT off = 0 ;
UINT len = 0 ;
UINT idx ;
PZFS_DIR_LIST_t pdir_node, pcwd_dir_node ;
PZFS_VOL_INFO_t pvol_info ;
PZFS_FIR_t pfir ;
PZFS_SEC_HDR_t cur_sec ;
PZFS_SEC_HDR_t prev_sec_addr ;
ZFS_FIR_t fir_hdr ;
ZFS_SEC_HDR_t sec_hdr ;
UINT8 status ;
ZFS_STATUS_t ret_status = ZFSERR_SUCCESS ;
// if ZFS is not initialized, return error
if( !IsZFSInited() )
return ZFSERR_NOT_INITIALIZED ;
// now check the validity of the dir path given in the argument
if( !ValidatePath( file_name ) )
return ZFSERR_INVALID_FILEDIR_PATH ;
last_fd_off = GetLastFileDirNameOff( file_name ) ;
len = strlen( ( const INT8 * ) file_name ) ;
// disable preemption
RZKAcquireSemaphore(hSem_FS,INFINITE_SUSPEND);
// preempt_status = DisablePreemption() ;
if( GetCwdInfoForCurThread( &pvol_info, &pcwd_dir_node ) != ZFS_TRUE )
{
ret_status = ZFSERR_INVALID_VOLUME ;
goto err_label_ZFSDelete ;
}
// now validated, disable preemption, find the absolute path with reduced length
status = IsAbsPath( file_name, &pvol_info, &off, &pdir_node) ;
if( status != ZFS_TRUE )
{
ret_status = ZFSERR_INVALID_FILEDIR_PATH ;
goto err_label_ZFSDelete ;
}
if( !IsVolumeValid(pvol_info) )
{
ret_status = ZFSERR_INVALID_VOLUME ;
goto err_label_ZFSDelete ;
}
if( pdir_node == NULL )
{
// get the CWD_INFO table
pdir_node = pcwd_dir_node ;
}
// this is relative path, get the directory node of the relative path with reduced length
// i.e till last directory.
if( off != last_fd_off )
{
// the file is not present in the root directory
pdir_node = GetNodeForPath( pdir_node, file_name + off, (last_fd_off - off ) ) ;
if( pdir_node == NULL )
{
ret_status = ZFSERR_INVALID_FILEDIR_PATH ;
goto err_label_ZFSDelete ;
}
}
// now again check whether the last name is a directory or not. If directory, return error.
if( GetNodeForPath( pdir_node, file_name + last_fd_off, (len - last_fd_off ) ) )
{
ret_status = ZFSERR_INVALID_FILEDIR_PATH ;
goto err_label_ZFSDelete ;
}
// Now every thing is valid, just check whether the file is in use or not.
// search the FIT for the file name
pfir = SearchFIR( pvol_info,
( PZFS_FIT_HDR_t ) pdir_node->sec_num,
( file_name + last_fd_off ),
( len - last_fd_off ) ) ;
if( pfir == NULL )
{
// file is not found, return error
ret_status = ZFSERR_FILE_DIR_DOES_NOT_EXIST ;
goto err_label_ZFSDelete ;
}
// read the FIR from the device.
pvol_info->pcfg->pfn_drv_read( pfir, &fir_hdr, sizeof( ZFS_FIR_t ) ) ;
// Now file is found, just check out whether the file is opened by any thread or not
for( idx = 0 ; idx < g_max_or_entries ; idx ++ )
{
if( ( g_zfs_or[ idx ].first_secnum == fir_hdr.sec_datanum ) && g_zfs_or[idx].status == ZFS_OR_MAGIC_NUM )
{
// file is opened by a thread, just return error
ret_status = ZFSERR_FILE_DIR_IN_USE ;
goto err_label_ZFSDelete ;
}
}
// Now file is not opened, just carry out the deletion of sectors and then the FIR entry in the FIT.
for( cur_sec = ( PZFS_SEC_HDR_t ) fir_hdr.sec_datanum ; cur_sec != ( PZFS_SEC_HDR_t ) FREE_SECTOR ; )
{
prev_sec_addr = ( PZFS_SEC_HDR_t ) GetSecAddr( pvol_info, cur_sec ) ;
FreeSector( pvol_info, cur_sec ) ; // No need to check for an error
// read the FIR contents
pvol_info->pcfg->pfn_drv_read( prev_sec_addr, &sec_hdr, sizeof( ZFS_SEC_HDR_t ) ) ;
cur_sec = ( PZFS_SEC_HDR_t ) sec_hdr.nxtsecnum ;
}
// now free up the FIR allocated,
FreeFIR( pvol_info, pfir ) ; // No need to check for an error
// reduce the dir count in the parent directory
pdir_node->fd_cnt-- ;
// Finished every thing, just return
err_label_ZFSDelete:
RZKReleaseSemaphore(hSem_FS);
// EnablePreemption( preempt_status ) ;
return ret_status ;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -