📄 zfsgetdiskparams.c
字号:
/*
* File : ZFSGetDiskParams.c
* Description: This file contains the implementation of ZFSGetVolParams 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 <string.h>
#include "ZSysgen.h"
#include "ZTypes.h"
#include "ZThread.h"
#include "ZSemaphore.h"
#include "glextern.h"
extern RZK_SEMAPHOREHANDLE_t hSem_FS;
//Function Name: ZFSGetVolumeCount
//Description: This API returns the Number of volumes present
ZFS_STATUS_t ZFSGetVolumeCount( void )
{
// if ZFS is not initialized, return error
// if( !IsZFSInited() )
// return ZFSERR_NOT_INITIALIZED ;
return g_max_volumes ;
}
//Function Name: ZFSGetVolParams
//Description: This API returns the volume parameters for user information
ZFS_STATUS_t ZFSGetVolumeParams( IN INT8 *vol_name, ZFS_VOL_PARAMS_t *vol_params, UINT8 get_all )
{
UINT idx = 0 ;
UINT vol_idx = 0 ;
UINT cnt = 0 ;
PZFS_BLK_INFO_t pblk_info ;
PZFS_VOL_INFO_t pvol_info ;
UINT secs_in_blk ;
UINT dirty_sec_cnt ;
UINT free_sec_cnt ;
// UINT used_sec_cnt ;
// if ZFS is not initialized, return error
if( !IsZFSInited() )
return ZFSERR_NOT_INITIALIZED ;
if( vol_idx == g_max_volumes || vol_name == NULL || vol_params == NULL ||
( get_all != ZFS_FALSE && get_all != ZFS_TRUE) )
{
return ZFSERR_INVALID_ARGUMENTS ;
}
if( get_all == ZFS_FALSE )
{
// check whether the given volume name is valid or not.
for( vol_idx = 0 ; vol_idx < g_max_volumes ; vol_idx++ )
{
if( strcmp( (INT8 *)g_zfs_vol_info[ vol_idx].pcfg->vol_name, (const INT8 *)vol_name ) == 0 )
{
pvol_info = &g_zfs_vol_info[ vol_idx ] ;
break ;
}
}
}
if( vol_idx == g_max_volumes )
return ZFSERR_INVALID_ARGUMENTS ;
// now got the volume information, just traverse through the volume to find the
// space information.
// disable preemption
RZKAcquireSemaphore(hSem_FS,INFINITE_SUSPEND);
// preempt_status = DisablePreemption() ;
pvol_info = &g_zfs_vol_info[ 0 ] ;
for( cnt = 0 ; cnt < g_max_volumes ; cnt++, pvol_info++ )
{
if( cnt != vol_idx && get_all == ZFS_FALSE )
continue ;
// calculate the sectors in a block.
secs_in_blk = pvol_info->pcfg->vol_secs / pvol_info->pcfg->vol_blks ;
memset( vol_params, 0x00, sizeof( ZFS_VOL_PARAMS_t ) ) ;
for( pblk_info = pvol_info->blk_info, idx = 0 ; idx < pvol_info->pcfg->vol_blks ; pblk_info++, idx++ )
{
if( pvol_info->pcfg->vol_type != ZFS_RAM_DEV_TYPE )
{
// check each block information and fill in the structure.
if((~(pblk_info->blk_hdr.sec_hdr.sec_type) & ( ZFS_SEC_TYPE_AB | ZFS_SEC_TYPE_NEW_AB ) ) )
{
// it is an alloc blocks, just get the information.
dirty_sec_cnt = pblk_info->dirty_sec_count ;
free_sec_cnt = pblk_info->free_sec_count ;
}
else
{
dirty_sec_cnt = 0 ;
free_sec_cnt = 0 ;
}
}
else
{
// RAM stuff.
dirty_sec_cnt = 0 ;
free_sec_cnt = pblk_info->free_sec_count ;
}
vol_params->dirty_space += dirty_sec_cnt ;
vol_params->free_space += free_sec_cnt ;
vol_params->used_space += (secs_in_blk - (free_sec_cnt + dirty_sec_cnt ) ) ;
}
memcpy( &vol_params->vol_name[0], &pvol_info->pcfg->vol_name[0], ZFS_MAX_FILE_NAME_SIZE + 1 ) ;
vol_params->vol_size = pvol_info->pcfg->vol_size ;
vol_params->is_valid = pvol_info->is_valid ;
vol_params->dirty_space *= ZFS_SEC_SIZE ;
vol_params->free_space *= ZFS_SEC_SIZE ;
vol_params->used_space *= ZFS_SEC_SIZE ;
vol_params++ ;
}
// EnablePreemption( preempt_status ) ;
RZKReleaseSemaphore(hSem_FS);
return ZFSERR_SUCCESS;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -