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

📄 fsdelete.c

📁 一个免费的SMART CARD OS系统。
💻 C
字号:
/* ============================================================================   Project Name : jayaCard   Module Name  : proto/bios/fs/fsdelete.c   Version : $Id: fsdelete.c,v 1.20 2004/04/24 12:07:31 dgil Exp $	Description: Delete 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   040203 dgil	wrote it from scratch   ============================================================================*/#include "precomp.h"#ifdef JAYA_FILESYSTEM_DELETE/* ============================================================================	Import from fstools.c   ========================================================================= */void __fs_save_file_header(void);void __fs_load_EF_header(jword link);void __fs_save_EF_header(void);jword __fs_header_bodysize(void);void __fs_save_EF_header(void);void __fs_erase_file(void);/* ============================================================================	__fs_delete_file()	current_DF would be the parent of the deleted file	current_EF is the file under deletion.	Some error code in lasterr if any problem.   ========================================================================= */void __fs_delete_file(void){	LOCAL(jword,addr);		/* address of some header file in EEPROM */	LOCAL(jword,del_addr);	/* address of the header file in EEPROM to be deleted */	LOCAL(jbool,bWrite);    LOCAL(jbyte,res);	LOG1("FS","__fs_delete_file(): fid=0x%.4X - enter",current_EF.fid);    /* do not support deletion of DF in this version */	if ( (current_EF.fdesc&FDESC_TYPE_MASK) == FDESC_TYPE_DF) {		LOG1("FS","__fs_delete_file(): fid=0x%.4X - can't delete a DF !",current_EF.fid);		BIOS_SETERR(ERR_INVALID_FILE_TYPE);		return;	}    /* check that we are able to delete files in the DF */    gGlobalSem = JSEC_FAIL;    res = FS_CHECK_AC(ACC_CHECK_DF|ACC_DELETE_FILE);    gGlobalSem++;    if (res != JSEC_OK) {        BIOS_SETERR(ERR_ACCESS_DENIED);        return;    }    if (gGlobalSem!=JSEC_SEM) {        LOG("ATTACK","__fs_delete_file() #1 - check security failure !");        BIOS_SETERR(ERR_ACCESS_DENIED);        HAL_HALT();        return;    }    /* check that we are able to delete the file itself */    gGlobalSem = JSEC_FAIL;    res = FS_CHECK_AC(ACC_CHECK_EF|ACC_DELETE);    gGlobalSem++;    if (res != JSEC_OK) {        BIOS_SETERR(ERR_ACCESS_DENIED);        return;    }    if (gGlobalSem!=JSEC_SEM) {        LOG("ATTACK","__fs_delete_file() #2 - check security failure !");        BIOS_SETERR(ERR_ACCESS_DENIED);        HAL_HALT();        return;    }    /* save the current EF to header file */	HAL_MEMCPY((jbyte xdata*)&header_file,(jbyte xdata*)&current_EF,SIZE_HEADER_FILE);	del_addr = current_EF_addr;	LOG2("FS","__fs_delete_file(): fid=0x%.4X addr=%.4X - cut the links",header_file.fid,del_addr);	/* we need to cut the links - move through the headers and cut ! */	header_file_addr = HAL_EEPROM_READ_WORD(FREE_HEADER_FILE_ADDR);	/* begin the move at the base of headers */	addr = ADDR_HEADER_MF;	while (addr<header_file_addr) {		__fs_load_EF_header(addr);		if (lasterr!=SUCCESS) {			LOG2("FS","__fs_delete_file() error code %d moving through the headers ! (adr==%x.4X)",lasterr,addr);			return;		}		bWrite = jfalse;		if (current_EF.fid != FID_RFU) {			/* check if header_file is linked by this EF */			if (current_EF.u2.next_file == del_addr) {				/* cut the link */                LOG3("FS","__fs_delete_file(): EF_addr=%.4X next was: %.4X - next will: %.4X ",current_EF_addr,del_addr,header_file.u2.next_file);                current_EF.u2.next_file = header_file.u2.next_file;				bWrite = jtrue;			}			#ifdef JAYACFG_FILESYSTEM_ALIAS			if ((current_EF.fdesc&FDESC_ALIAS)==FDESC_ALIAS) {				/* check if header_file is linked by this alias ! */				/* if this is the case, we have to suppress also the alias ! */				/* mark the alias has bogus / next time it will be removed ! */				current_EF.fid = FID_BOGUS;				bWrite = jtrue;			} else			#endif			if ((current_EF.fdesc&FDESC_TYPE_MASK)==FDESC_TYPE_DF) {				/* check if header_file is linked by this DF/MF */				if (current_EF.u4.first_file == del_addr) {					/* cut the link */                    LOG3("FS","__fs_delete_file(): DF_addr=%.4X first was: %.4X - first will: %.4X ",current_EF_addr,del_addr,header_file.u2.next_file);                    current_EF.u4.first_file = header_file.u2.next_file;					bWrite = jtrue;				}           }		}		if (bWrite) {			/* update this file */			__fs_save_EF_header();			if (lasterr != SUCCESS) {				/* __x XXX big challenge here ! */			}		}        /* special case : current_EF is the current_DF ! need also to update it ! */        if (current_EF_addr == current_DF_addr) {            HAL_MEMCPY((jbyte xdata*)&current_DF,(jbyte xdata*)&current_EF,SIZE_HEADER_FILE);        }		/* next header */		addr += SIZE_HEADER_FILE;	}	/* then mark the header file deleted / should be re-usable by the next	   CREATE FILE. Don't touch any other field so we should be able to	   re-use also the body part.	*/	LOG2("FS","__fs_delete_file(): fid=0x%.4X - mark deleted header=%.4X",header_file.fid,del_addr);	header_file.fid = FID_RFU;	header_file_addr = del_addr;	if ((header_file.fdesc&FDESC_TYPE_LINEAR)==FDESC_TYPE_LINEAR) {		/* convert recorded body to transparent body => create will be able to		   split more easily this chunk if required		*/		header_file.u4.sizefile = __fs_header_bodysize();		header_file.fdesc = FDESC_TYPE_BINARY;	}	if ((header_file.fdesc&FDESC_TYPE_BINARY)==FDESC_TYPE_BINARY) {		/* clear the body */		FS_ERASE_FILE();		/* compact the memory */		#ifdef JAYA_FILESYSTEM_COMPACT			/* __x IMPLEMENTME */		#endif	}    /* no file after */    header_file.u2.next_file = 0x0000;	/* flush the header file to EEPROM */	__fs_save_file_header();	/* no more EF selected ! */	FS_NEW_SESSION(jfalse,jfalse);}/* =========================================================================	That's all folks !   ========================================================================= */#endif/* JAYA_FILESYSTEM */

⌨️ 快捷键说明

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