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

📄 fsselect.c

📁 一个免费的SMART CARD OS系统。
💻 C
字号:
/* ============================================================================   Project Name : jayaCard   Module Name  : proto/bios/fs/fsselect.c   Version : $Id: fsselect.c,v 1.14 2004/04/23 20:29:15 dgil Exp $	Description: Select an EF or DF    The Original Code is jayaCard code.    The Initial Developer of the Original Code is Gilles Dumortier.	Portions created by the Initial Developer are Copyright (C) 2002-2004 the    Initial Developer. All Rights Reserved.    Contributor(s):    This program is free software; you can redistribute it and/or modify    it under the terms of the GNU General Public License as published by    the Free Software Foundation; either version 2 of the License, or    (at your option) any later version.    This program is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the    GNU General Public License for more details.    You should have received a copy of the GNU General Public License    along with this program; see http://www.gnu.org/licenses/gpl.html   History Rev	Description   052603 dgil	wrote it from scratch   ============================================================================*/#include "precomp.h"#ifdef JAYA_FILESYSTEM/* ============================================================================	Import from fstools.c   ========================================================================= */void __fs_move_EF_2_DF_header(void);void __fs_load_DF_header(jword link);jbool __fs_isreserved_fid(jword id);/* ============================================================================	__fs_select_file_by_fid()	select a file by its fid :		- lookup the file		- update the file header (current_EF or current_DF)        - test the INVALIDATED flag	secure: use the global semaphore to validate the EF to DF move   ========================================================================= */void __fs_select_file_by_fid(jword fid,jbyte mode){	LOCAL(jbyte,res);	LOG1("FS","__fs_select_file_by_fid(fid=0x%.4X)",fid);    /* reselect current EF or DF ? */    if (fid == FID_CURRENT) {        if (current_EF_addr == NO_CURRENT_FILE) {            if (current_DF_addr != NO_CURRENT_FILE) {                LOG2("FS","__fs_select_file_by_fid(fid=0x%.4X) reselect DF fid=0x.%4X",fid,current_DF.fid);                fid = current_DF.fid;            } else {                LOG1("FS","__fs_select_file_by_fid(fid=0x%.4X) no current EF nor DF !",fid);            }        } else {            LOG2("FS","__fs_select_file_by_fid(fid=0x%.4X) reselect EF fid=0x.%4X",fid,current_EF.fid);            fid = current_EF.fid;        }    }    /* select the MF itself ... */    if (fid == FID_MF) {        FS_NEW_SESSION(jtrue,jtrue);        if (lasterr != SUCCESS) BIOS_SETERR(ERR_FAULT);        return;    }    /* check reserved FIDs */	if (__fs_isreserved_fid(fid)) {		LOG1("FS","__fs_select_file_by_fid(): file fid=0x%.4X INVALID FID !",fid);		BIOS_SETERR(ERR_INVALID_FID);		return;	}	/* select the current file ? */	if ( fid == current_EF.fid ) {		LOG1("FS","__fs_select_file_by_fid(): file fid=0x%.4X already the current file !",fid);		return;	}	/* select the current DF file ? */	if ( fid == current_DF.fid ) {		LOG1("FS","__fs_select_file_by_fid(): file fid=0x%.4X select the current DF file !",fid);        return;    }	/* check that we have use access in the current DF */	gGlobalSem = JSEC_FAIL;    res = FS_CHECK_AC(ACC_CHECK_DF|ACC_LOOKUP);	gGlobalSem++;	if (res != JSEC_OK) {		BIOS_SETERR(ERR_ACCESS_DENIED);		return;	}	if (gGlobalSem!=JSEC_SEM) {		LOG("ATTACK","__fs_select_file_by_fid() #1 - check security failure !");		BIOS_SETERR(ERR_ACCESS_DENIED);		HAL_HALT();		return;	}	/* start a new EF session */	FS_NEW_SESSION(jfalse,jfalse);    /* lookup the file by fid */    FS_LOOKUP_FID(fid,mode);	if (lasterr!=SUCCESS) return;    /* if a DF, update the current_DF */	if ((current_EF.fdesc&FDESC_TYPE_MASK)==FDESC_TYPE_DF) {		BIOS_APPLICATION_DESELECT();        /* move EF to DF header ; note: current_EF is no file after the move */		gGlobalSem = JSEC_FAIL;		__fs_move_EF_2_DF_header();		/* check security */		if (gGlobalSem!=JSEC_SEM) {			LOG("ATTACK","__fs_select_file_by_fid() #2 - check security failure !");			HAL_HALT();			return;		}		BIOS_APPLICATION_SELECT();	}}/* ============================================================================    __fs_select_file_by_sfi()    select a file by its sfi :        - lookup the file        - update the file header (current_EF)        - test the INVALIDATED flag   ========================================================================= */void __fs_select_file_by_sfi(jbyte sfi){	/* reselect current file ? */	if (sfi == SFI_CURRENT) {		/* check we have a current EF */		if (current_EF_addr==NO_CURRENT_FILE) {			BIOS_SETERR(ERR_NO_EF_SELECTED);			return;		}        LOG("FS","__fs_select_file_by_sfi() SFI_CURRENT /  use the current file !");        return;	}    /* select the current file ? */    if (sfi == (current_EF.sfi&SFI_MASK) ) {        LOG1("FS","__fs_select_file_by_sfi() sfi=0x%.2X already the current file !",sfi);        return;    }	/* start a new EF session */	FS_NEW_SESSION(jfalse,jfalse);    /* lookup the file by sfi */    FS_LOOKUP_SFI(sfi);    if (lasterr != SUCCESS) return;    /* invalidated ? - can't select a file by SFI if invalidated - need FID */    #ifdef JAYACFG_FILESYSTEM_INVALIDATE    if ( (current_EF.fdesc&FDESC_INVALIDATED) == FDESC_INVALIDATED ) {        LOG1("FS","__fs_select_file_by_sfi() sfi=0x%.2X INVALIDATED !",sfi);        BIOS_SETERR(ERR_FILE_INVALIDATED);        FS_NEW_SESSION(jfalse,jfalse);        return;    }    #endif}/* =========================================================================	That's all folks !   ========================================================================= */#endif/* JAYA_FILESYSTEM */

⌨️ 快捷键说明

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