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

📄 fsbinary.c

📁 一个免费的SMART CARD OS系统。
💻 C
字号:
/* ============================================================================   Project Name : jayaCard   Module Name  : proto/bios/fs/fsbinary.c   Version : $Id: fsbinary.c,v 1.21 2004/04/23 20:29:14 dgil Exp $	Description: Binary management    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   050803 dgil	wrote it from scratch   ============================================================================*/#include "precomp.h"#ifdef JAYA_FILESYSTEM_BINARY/* ============================================================================    Imports from fstools.c   ========================================================================= */void __manage_update_once(void);/* ============================================================================	__fs_check_binary_EF()	Assume:		- current_EF must be a binary file		- file must be of a standard type	Secure: use the global semaphore   ========================================================================= */void __fs_check_binary_EF(void){	gGlobalSem = JSEC_OK;	/* check we have a current EF */	if (current_EF_addr==NO_CURRENT_FILE) {		BIOS_SETERR(ERR_NO_EF_SELECTED);		return;	}	gGlobalSem++;	/* check it is a binary exportable content __r XXX: Life vs InternalEF */	if ((current_EF.fdesc&(FDESC_TYPE_MASK|FDESC_INTERNAL_EF))!=(FDESC_TYPE_BINARY)) {		BIOS_SETERR(ERR_INVALID_FILE_TYPE);		return;	}	gGlobalSem--;	if ((current_EF.sfi&FDESC2_MASK)!=FDESC2_STANDARD) {		BIOS_SETERR(ERR_INVALID_FILE_TYPE);		return;	}	/* ok, all seems perfect */	gGlobalSem++;}/* ============================================================================	__fs_read_binary_EF()	Parameters:		ofs		offset in the file		len		number of bytes to read	Use:		streamSrc	to read the file from the EEPROM		streamDest	to output the bytes	Assume:		- current_EF must be a binary file		- current_EF is not an internal EF   ========================================================================= */void __fs_read_binary_EF(jword ofs,jbyte len){	LOG2("FS","__fs_read_binary_EF() - current_EF ofs=%.4X len=%d !",ofs,len);	/* check the binary file */	gGlobalSem = JSEC_FAIL;	__fs_check_binary_EF();	if (lasterr!=SUCCESS) return;	gGlobalSem++;	/* initialize the streams */	BIOS_INIT_STREAM_FROM_CURRENT_EF(&streamSrc);	if (lasterr != SUCCESS) {        LOG1("RECORD","__fs_read_binary_EF() - BIOS_INIT_STREAM_FROM_CURRENT_EF reports error %d !",lasterr);		return;	}	if ((streamSrc.m_flags & READ_STREAM) != READ_STREAM) {		/* Read access not allowed */		BIOS_SETERR(ERR_ACCESS_DENIED);		return;	}	streamDest.m_flags = WRITE_STREAM|IO_STREAM;	/* __x XXX |CIPHER_STREAM if SM */	streamDest.m_flags2 = INS_IND_STREAM;	/* update the source stream with the offset */	streamSrc.m_pos += ofs;	/* check security */	if (gGlobalSem!=JSEC_SEM) {		LOG("FS","__fs_read_binary_EF() - check security failure !");		HAL_HALT();		return;	}	/* stream to stream */	(void)BIOS_STREAM2STREAM(&streamDest,&streamSrc,len);}/* ============================================================================	__fs_update_binary_EF()	Parameters:		ofs		offset in the file		len		number of bytes to update	Use:		streamSrc	to get the input bytes		streamDest	to update the bytes in the EEPROM	Assume:		- current_EF must be a binary file		- current_EF is not an internal EF   ========================================================================= */void __fs_update_binary_EF(jword ofs,jbyte len){	/* check the binary file */	gGlobalSem = JSEC_FAIL;	__fs_check_binary_EF();	if (lasterr!=SUCCESS) return;	gGlobalSem++;	/* initialize the stream */	BIOS_INIT_STREAM_FROM_CURRENT_EF(&streamDest);	if (lasterr != SUCCESS) {        LOG1("RECORD","__fs_update_binary_EF() - BIOS_INIT_STREAM_FROM_CURRENT_EF reports error %d !",lasterr);		return;	}	if ((streamDest.m_flags & WRITE_STREAM) != WRITE_STREAM) {		/* write access not allowed */		BIOS_SETERR(ERR_ACCESS_DENIED);		return;	}	streamSrc.m_flags = READ_STREAM|IO_STREAM;	/* __x XXX |CIPHER_STREAM if SM */	streamSrc.m_flags2 = 0x00;	/* update the destination stream with the offset */	streamDest.m_pos += ofs;	streamDest.m_flags2 |= INS_IND_STREAM;	/* check security */	if (gGlobalSem!=JSEC_SEM) {		LOG("FS","__fs_update_binary_EF() - check security failure !");		HAL_HALT();		return;	}	/* stream to stream */	(void)BIOS_STREAM2STREAM(&streamDest,&streamSrc,len);    __manage_update_once();}/* ============================================================================	__fs_erase_binary_EF()	Parameters:		ofs		offset in the file	Use:        streamDest  to erase the bytes in the EEPROM	Assume:		- current_EF must be a binary file		- current_EF is not an internal EF   ========================================================================= */void __fs_erase_binary_EF(jword ofs){	LOCAL(jword,len);	/* check the binary file */	gGlobalSem = JSEC_FAIL;	__fs_check_binary_EF();	if (lasterr!=SUCCESS) return;	gGlobalSem++;	/* initialize the stream */	BIOS_INIT_STREAM_FROM_CURRENT_EF(&streamDest);	if (lasterr != SUCCESS) {        LOG1("RECORD","__fs_erase_binary_EF() - BIOS_INIT_STREAM_FROM_CURRENT_EF reports error %d !",lasterr);		return;	}    if ((streamDest.m_flags2 & ERASE_STREAM) != ERASE_STREAM) {        /* erase access not allowed */        BIOS_SETERR(ERR_ACCESS_DENIED);        return;    }	/* update the destination stream position with the given offset */	streamDest.m_pos += ofs;	len = streamDest.m_pos - streamDest.m_start;	if ( len >= streamDest.m_size) {			/* fix bug#65 */		BIOS_SETERR(ERR_INVALID_OFFSET);		return;	}	len = streamDest.m_size - len;	LOG2("FS","__fs_erase_binary_EF() pos=%.4X len=%d",streamDest.m_pos,len);	/* check the size of operation ! */	if (BIOS_TEST_STREAM(&streamDest,len)==JSEC_FAIL) return;	/* check security */	if (gGlobalSem!=JSEC_SEM) {		LOG("ATTACK","__fs_erase_binary_EF() #1 - check security failure !");		HAL_HALT();		return;	}    /* erase */    gGlobalSem = JSEC_FAIL;    while (len>255) {        BIOS_ERASE_STREAM(&streamDest,255);        len = len - 255;    }    BIOS_ERASE_STREAM(&streamDest,(jbyte)len);    /* check security */    if (gGlobalSem!=JSEC_SEM) {        LOG1("ATTACK","__fs_erase_binary_EF() #3 - check security failure gGlobalSem=%.2X !",gGlobalSem);        HAL_HALT();        return;    }    __manage_update_once();}/* =========================================================================	That's all folks !   ========================================================================= */#endif/* JAYA_FILESYSTEM_BINARY */

⌨️ 快捷键说明

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