⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zfsgetcwd.c

📁 zilog的实时操作系统RZK,可以移植到多种处理器上
💻 C
字号:
/*
 * File       : ZFSGetCwd.c
 * Description: This file contains the implementation of ZFSGetCwd 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: ZFSGetCwd
//Description: This API gets the current working directory for the thread
ZFS_STATUS_t ZFSGetCwd( IN_OUT INT8 *pcwd_path )
{
	// get the cwd node, and traverse in reverse to get the directory name and store the same in the 
	// the pointer provided by the user.
	INT8 *pstr ;
	PZFS_DIR_LIST_t pdir_node, pcwd_dir_node ;
	PZFS_VOL_INFO_t pvol_info ;
	UINT off = 0 ;
	ZFS_STATUS_t status ;

	// if ZFS is not initialized, return error
	if( !IsZFSInited() )
		return ZFSERR_NOT_INITIALIZED ;

	if( pcwd_path == NULL )
		return ZFSERR_INVALID_ARGUMENTS ;


	pstr = GetCwdPathForHandle( GetCurrentThread() ) ;

//	preempt_status = DisablePreemption() ;
	RZKAcquireSemaphore(hSem_FS,INFINITE_SUSPEND);

	// check whether the CWD is valid or not: it may happen that 
	// cwd in this thread may have an invalid volume:
	if( GetCwdInfoForCurThread( &pvol_info, &pcwd_dir_node )  != ZFS_TRUE )
		{
		RZKReleaseSemaphore(hSem_FS);
//		EnablePreemption( preempt_status ) ;
		return ZFSERR_INVALID_VOLUME ;
		}

	// now validated, disable preemption, find the absolute path with reduced length
	status = IsAbsPath( pstr, &pvol_info, &off, &pdir_node) ;
	if( status != ZFS_TRUE )
		{
		RZKReleaseSemaphore(hSem_FS);
//		EnablePreemption( preempt_status ) ;
		return ZFSERR_INTERNAL ;
		}

	if( !IsVolumeValid(pvol_info) )
		{
		*pcwd_path = '\0' ;
		RZKReleaseSemaphore(hSem_FS);
//		EnablePreemption( preempt_status ) ;
		return ZFSERR_INVALID_VOLUME ;
		}


	RZKReleaseSemaphore(hSem_FS);
//	EnablePreemption( preempt_status ) ;
	strcpy( (INT8 *)pcwd_path, (const INT8 *)pstr ) ;
	
	return ZFSERR_SUCCESS ;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -