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

📄 port.c

📁 T-kernel 的extension源代码
💻 C
字号:
/* *---------------------------------------------------------------------- *    T-Kernel / Standard Extension * *    Copyright (C) 2006 by Ken Sakamura. All rights reserved. *    T-Kernel / Standard Extension is distributed  *      under the T-License for T-Kernel / Standard Extension. *---------------------------------------------------------------------- * *    Version:   1.00.00 *    Released by T-Engine Forum(http://www.t-engine.org) at 2006/8/11. * *---------------------------------------------------------------------- *//* *	port.c (file) * *	File management *	Sending and forwarding, etc. of commands by the rendezvous port */#include "fminfo.h"#include "filesys.h"LOCAL	ER	fmpEnterSyncExec( void );LOCAL	ER	fmpExitSyncExec( void );LOCAL	ER	fmpCallMgrTask( FmCmdPkt *pkt, SyscallPattern ptn );/* ------------------------------------------------------------------------ *//* *	When calling other file system task from one file system task synchronously, if the tasks *	call each other simultaneously,a deadlock occurs. In order to avoid the problem, we have *	prepared the synchronous execution flag to perform control so that only one synchronous *	call can be executed at a time. Overlapped synchronous executions result in EFM_RETRY *	error and reexecution is reserved. (See fstask.c:fmpFsTask() ) *//* * Start the synchronous execution. */LOCAL ER fmpEnterSyncExec( void ){	ER	err;#ifdef DEBUG	if ( GetFsInfo(TSK_SELF) == NULL ) {		err = E_SYS;		goto err_ret;	}#endif	err = tk_wai_sem(fmInfo.syncExecFlag, 1, SyncExecWait);	if ( err != E_OK ) {		err = ( err == E_TMOUT )? EFM_RETRY: ERtoERR(err);		goto err_ret;	}	return E_OK;err_ret:	DEBUG_PRINT(("fmpEnterSyncExec err = %d\n", err));	return err;}/* * End the synchronous execution. */LOCAL ER fmpExitSyncExec( void ){	ER	err;	err = tk_sig_sem(fmInfo.syncExecFlag, 1);	if ( err != E_OK ) {		DEBUG_PRINT(("fmpExitSyncExec er = %d\n", err));		return ERtoERR(err);	}	return E_OK;}/* ------------------------------------------------------------------------ *//* * Call the file management common section. *	(For call from the extended SVC section) */EXPORT ER fmCallMgrTask( FmCmdPkt *pkt, SyscallPattern ptn ){	INT	rmsgsz;	rmsgsz = tk_cal_por(fmInfo.entryPort, ptn, &pkt, (W)sizeof(VP), TMO_FEVR);	if ( rmsgsz < E_OK ) {		DEBUG_PRINT(("fmCallMgrTask er = %d\n", rmsgsz));		return ERtoERR(rmsgsz);	}	return E_OK;}/* * Call the file management common section. *	(For call from the file system task) */LOCAL ER fmpCallMgrTask( FmCmdPkt *pkt, SyscallPattern ptn ){	INT	rmsgsz;	ER	err;	/* Start the synchronous execution */	err = fmpEnterSyncExec();	if ( err < E_OK ) {		goto err_ret;	}	/* Call the file management common section. */	rmsgsz = tk_cal_por(fmInfo.entryPort, ptn, &pkt, (W)sizeof(VP), TMO_FEVR);	/* End the synchronous execution. */	err = fmpExitSyncExec();	if ( err < E_OK ) {		goto err_ret;	}	if ( rmsgsz < E_OK ) {		err = ERtoERR(rmsgsz);		goto err_ret;	}	return E_OK;err_ret:	DEBUG_PRINT(("fmpCallMgrTask err = %d\n", err));	return err;}/* * Forward to the file management common section. */EXPORT ER fmForwardMgrTask( RNO rdvno, FmCmdPkt *pkt ){	ER	err;	err = tk_fwd_por(fmInfo.entryPort, Syscall_OWN, rdvno,					&pkt, sizeof(VP));	if ( err != E_OK ) {		DEBUG_PRINT(("fmForwardMgrTask er = %d\n", err));		return ERtoERR(err);	}	return E_OK;}/* * Call the file system section. *	(It can be called only from the manager task.) */EXPORT ER fmcCallFsTask( ID port, FmCmdPkt *pkt ){	INT	rmsgsz;	Unlock(&fmInfo.lock);	rmsgsz = tk_cal_por(port, Syscall_OWN, &pkt, sizeof(VP), TMO_FEVR);	Lock(&fmInfo.lock);	if ( rmsgsz < E_OK ) {		DEBUG_PRINT(("fmCallFsTask er = %d\n", rmsgsz));		return ERtoERR(rmsgsz);	}	return E_OK;}/* * Forward to the file system section. */EXPORT ER fmForwardFsTask( ID port, RNO rdvno, FmCmdPkt *pkt ){	ER	err;	err = tk_fwd_por(port, Syscall_OWN, rdvno, &pkt, sizeof(VP));	if ( err != E_OK ) {		DEBUG_PRINT(("fmForwardFsTask er = %d\n", err));		return ERtoERR(err);	}	return E_OK;}/* ======================================================================== *//* *	Service command between file systems for internal use *	Entry for call *//* * Obtain the file information. *	(It can be called only from the file system task.) */EXPORT ER fmIGetFileInfo( LINK *lnk, FileName fname,				STIME *ctime, FileAccMode *amode ){	FMI_GetFileInfo_PARA	para;	FmCmdPkt	pkt = NIL;	ER		err;	/* Set the packet. */	pkt.cmd.fno.w = FMI_GetFileInfo_FN;	pkt.cmd.para  = &para;	para.lnk   = lnk;	para.fname = fname;	para.ctime = ctime;	para.amode = amode;	/* Call the rendezvous. */	err = fmpCallMgrTask(&pkt, Syscall_OWN);	if ( err < E_OK ) {		goto err_ret;	}	return pkt.cmd.ret;err_ret:	DEBUG_PRINT(("fmIGetFileInfo err = %d\n", err));	return err;}/* * Change the link file name. *	(It can be called only from the file system task.) */EXPORT ER fmIChangeLinkFileName( LINK *lnk, FileName fname ){	FMI_ChangeLinkFileName_PARA	para;	FmCmdPkt	pkt = NIL;	ER		err;	/* Set the packet. */	pkt.cmd.fno.w = FMI_ChangeLinkFileName_FN;	pkt.cmd.para  = &para;	para.lnk   = lnk;	para.fname = fname;	/* Call the rendezvous. */	err = fmpCallMgrTask(&pkt, Syscall_OWN);	if ( err < E_OK ) {		goto err_ret;	}	return pkt.cmd.ret;err_ret:	DEBUG_PRINT(("fmIChangeLinkFileName err = %d\n", err));	return err;}/* * Set the work file. (at startup) */EXPORT ER fmISetWorkFile( LINK *lnk, PINFO *pinfo ){	FMI_SetWorkFile_PARA	para;	FmCmdPkt	pkt = NIL;	ER		err;	/* Set the packet */	pkt.cmd.fno.w = FMI_SetWorkFile_FN;	pkt.cmd.para  = &para;	para.lnk   = lnk;	para.pinfo = pinfo;	/* Call the rendezvous. */	err = fmCallMgrTask(&pkt, Syscall_OWN);	if ( err < E_OK ) {		goto err_ret;	}	return pkt.cmd.ret;err_ret:	DEBUG_PRINT(("fmISetWorkFile err = %d\n", err));	return err;}/* * File close (at internal call of cls_fil/cleanup) *	(It can be called only from the manager task.) */EXPORT ER fmcICloseFile( FD *fd ){	FM_CLS_FIL_PARA	para;	FmCmdPkt	pkt = NIL;	FsInfo		*fs;	ER		err;	fs = fd->fs;	if ( fs == NULL ) {		err = E_FD;		goto err_ret;	}	/* Set the packet. */	pkt.cmd.fno.w = FM_CLS_FIL_FN;	pkt.cmd.para  = &para;	pkt.wrk.pinfo = fd->pinfo;	para.fd = getFDno(fd);	/* Call the rendezvous. */	err = fmcCallFsTask(fs->port, &pkt);	if ( err < E_OK ) {		goto err_ret;	}	return pkt.cmd.ret;err_ret:	DEBUG_PRINT(("fmcICloseFile err = %d\n", err));	return err;}

⌨️ 快捷键说明

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