📄 fdi_file.c
字号:
/* ###########################################################################
### Intel Confidential
### Copyright (c) Intel Corporation 1995-2002
### All Rights Reserved.
### -------------------------------------------------------------------------
### Project: Flash Data Integrator
###
### Module: FDI_FILE.C - The file support API shall exist as a software layer
### that utilizes the standard FDI API functions. The
### file API shall be implemented with an ANSI stdio
### interface. The file API provides file information
### associated with each file. The application shall be
### responsible for sorting the file info.
### Functions:
### FDI_fopen opens the file whose name is the string pointed to
### by filename and associates a stream with it
### FDI_fwrite writes from the array buffer, up to count elements
### whose size is element_size, to a specified stream
### FDI_fread reads into the array buffer, up to count elements of
### size element_size, from a specified stream
### FDI_fclose flushes a stream specified by stream and closes file
### FDI_fseek sets the file position indicator for a stream
### specified
### FDI_findfirst begins search for files specified by wildcards
### FDI_findnext fetches subsequent files that match the filename
### given in FDI_findfirst
### FDI_remove deletes the file specified by filename
### FDI_rename changes the name of a file from oldname to newname
### FDI_fileinit initial files after successful FDI_Init
### FDI_feof EOF detected while reading from input stream
### FDI_ferror error has occurred while reading from or writing to
### the stream
### FDI_clearerr resets error and end-of-file indicators on stream
### FDI_chmod change file permissions
### FDI_fchmod change open stream permissions
### FDI_stat get file permissions
### FDI_fstat get open stream permissions
### FDI_ftell get the file pointer
### FDI_fileterminate deallocates resources
###
### FileNameSearch searches the file info structures for matching file
### FileNameMatch compares one name to another including wildcards
### FileDelete deletes file info and data info for a file
### FileNameValid determines if filename's size and chars are valid
### FilesOnFlashValid determines if files on flash are valid
### DeletePLRFile deletes file indicated by plr_id field of file info
### RestoreFile restores file to plr_size in file info
### GetNextFreeFLTIndex returns the next free index into FLT
###
### FileGetTime returns a default time value
### FileGetDate returns a default date value
### FileGetGID returns a default group id
### FileGetUID returns a default user id
###
### $Archive: /FDI/SRC/fm_enh/fdi_file.c $
### $Revision: 1.1 $
### $Date: 2002/11/21 00:48:53 $
### $Author: wavis $
### $NoKeywords $
########################################################################### */
/****************************************************************************
INTEL OEM SOFTWARE LICENSE AGREEMENT (LICENSE.TXT)
BY USING THIS SOFTWARE, YOU ("You" or "Licensee") ARE AGREEING TO BE
BOUND BY THE TERMS OF THIS AGREEMENT. DO NOT USE THE SOFTWARE UNTIL
YOU HAVE CAREFULLY READ AND AGREED TO THE FOLLOWING TERMS AND
CONDITIONS. IF YOU DO NOT AGREE TO THE TERMS OF THIS AGREEMENT,
PROMPTLY RETURN THE SOFTWARE, PACKAGING, AND ANY ACCOMPANYING ITEMS.
YOU MUST BE AN ORIGINAL EQUIPMENT MANUFACTURER ("OEM") SYSTEM DEVELOPER
TO ACQUIRE ANY RIGHTS IN THE SOFTWARE UNDER THIS LICENSE AGREEMENT.
"Source Code" means source code that you receive from Intel under this
Agreement. "Derived Object Code" means executable code derived from
Intel Source Code. "Software" means the Intel Source Code and object
code (unmodified by you) and related documentation that You receive
from Intel under this Agreement.
LICENSE: Intel Corporation ("Intel") grants You the non-exclusive,
nontransferable, royalty free right under Intel copyright to:
1. Reproduce and modify the Software, only for your own development
and maintenance, provided that You may not modify the Software for
use with flash products other than Intel Flash memory products;
2. Install, use, reproduce and distribute Derived Object Code
internally, only for Your own development and maintenance purposes;
3. Allow authorized contractors ("Subcontractors") engaged by You for
the sole purpose of product development work to have access to the
Software and any modified Source Code solely for that purpose.
Subcontractors do NOT acquire any of Your rights to the Software or
any modified Source Code provided in this Agreement;
4. Distribute Derived Object Code externally to Your bona fide customers
("Customers"), provided that You may not distribute Derived Object
Code for use with flash products other than Intel Flash memory
products; and
5. Copy the Software for Your support, backup or archival purposes.
RESTRICTIONS:
YOU ARE NOT ALLOWED TO:
1. Use, copy, modify, rent, sell, license, transfer, disclose or
distribute the Software, in whole or in part, except as provided for
in this Agreement;
2. Remove or modify the "Compatibility" module, if any, in the Software
or in any Derived Object Code;
3. Decompile or reverse engineer any Software delivered in object code
form.
THIS ROYALTY FREE LICENSE ALLOWS YOU TO USE THE SOFTWARE WITH INTEL FLASH
PRODUCTS ONLY. YOUR USE OF THE SOFTWARE WITH ANY OTHER FLASH PRODUCTS IS
EXPRESSLY PROHIBITED UNLESS AND UNTIL YOU APPLY FOR, AND ARE GRANTED IN
INTEL'S SOLE DISCRETION, A SEPARATE WRITTEN SOFTWARE LICENSE FROM INTEL
LICENSING ANY SUCH USE
YOU MUST execute the "Compatibility" module if provided with the Software.
TRANSFER: Except as provided above, You may not transfer or disclose the
Software to any other party.
OWNERSHIP AND COPYRIGHT OF SOFTWARE: Title to the Software and all copies
thereof remain with Intel. The Software is copyrighted and is protected
by United States and international copyright laws. You will not remove
the copyright notice from the Software. You agree to prevent the
unauthorized copying of the Software. You are not required to provide
Intel with a copy of any modified Source Code or Derived Object Code
created by You. Title to modified Source Code, other than the portion(s)
of the modified code consisting of any portion of the Software, shall
remain with You.
Your sale or distribution of Derived Object Code is at Your own risk and
expense.
CONFIDENTIALITY. Source Code may include trade secrets of Intel. You will
not disclose or otherwise make any part of Source Code (whether or not
modified by You) available, in any form, to any person other than Your
employees whose job performance requires such access. You agree to
instruct all such employees on these obligations with respect to use,
copying, protection, and confidentiality of Source Code. Even after this
Agreement terminates, the obligations of this section shall remain in
effect until the Source Code rightfully becomes publicly known. You may
not disclose the terms or existence of this Agreement or use Intel's name
in any publications, advertisements, or other announcements without Intel's
prior written consent. You do not have any rights to use Intel's trademarks.
Any Subcontractors to whom You disclose the Source Code must sign a written
confidentiality agreement which contains terms regarding the Software no
less restrictive than those set forth in this Agreement.
NO WARRANTY. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS". INTEL SPECIFICALLY DISCLAIMS ANY OTHER
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WARRANTIES OF MERCHANTABILITY,
NONINFRINGEMENT OR FITNESS FOR ANY PARTICULAR PURPOSE.
LIMITATION OF LIABILITY. INTEL SHALL NOT BE LIABLE FOR ANY INDIRECT,
SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGE, NOR ANY LOSS OF PROFITS, LOSS
OF USE, LOSS OF DATA, INTERRUPTION OF BUSINESS, OF ANY KIND, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGES.
TERMINATION OF THIS LICENSE. You may terminate this Agreement and the
license granted herein at any time by notifying Intel in writing. Intel
reserves the right to conduct or have conducted audits to verify Your
compliance with this Agreement. Intel may terminate this Agreement at any
time if You are in breach of any of its terms and conditions. If this
Agreement is terminated for any reason, You will cease distribution of
Derived Object Code and, at Intel's option and within thirty (30) days
following termination, either return to Intel or destroy the original and
all copies of the Software and undistributed copies of Derived Object Code,
and certify to Intel that they have been destroyed.
U.S. GOVERNMENT RESTRICTED RIGHTS. The Software and documentation were
developed at private expense and are provided with "RESTRICTED RIGHTS".
If You distribute Derived Object Code to the U.S. Government or contractor
You must include the following legend on the distributed copy(ies): "Use,
duplication, and disclosure by the Government is subject to restrictions
set forth in FAR 52.227-14, DFARS 252.227-7013 or their successors."
EXPORT LAWS. Source Code and Derived Object Code may be controlled for
export purposes by the U.S. Government. You will not export, either
directly or indirectly, any Derived Object Code without first obtaining
any required license or other approval from the U.S. Department of
Commerce or any other agency or department of the United States
Government as required.
ENTIRE AGREEMENT. This is the entire agreement between You and Intel
relating to this subject matter, and no amendments will be effective
unless in a writing signed by both parties.
APPLICABLE LAW. This Agreement is governed by the laws of the State of
Delaware and the United States, including patent and copyright laws.
Any claim arising out of this Agreement will be brought in Delaware.
AGREEMENT ACCEPTANCE AND FILE PASSWORD ACCESS: The archive file that
contains the code included with this license agreement is encrypted and
password protected. In entering the password I_AGREE and by opening the
archive file You indicate Your acceptance of the terms of the above
agreement. Please see the accompanying "read me" (READxxxx.TXT) file
for detailed instructions on how to use the password.
PRODUCT REGISTRATION
To register your product, please print out this document, fill out the
following and return the entire document to Intel as indicated below.
Intel Flash Software_________________________________
(fill in software type, PSM, FDI, etc.)
Version___________________
(fill in version number)
LICENSEE
__________________________________________________
Company Name
__________________________________________________
Printed Name
__________________________________________________
Signature
__________________________________________________
Title
__________________________________________________
Date
__________________________________________________
Address
__________________________________________________
City
__________________________________________________
State/province
ZIP/postal code___________________________________
Country___________________________________________
EMAIL _________________________
Phone __________________________ Ext______
(Please include your area code or country/city code as
appropriate)
FAX _________________________
Application Details (please tell us about your product,
the flash use, and software use):
_______________________________________________________
_______________________________________________________
_______________________________________________________
Please return COMPLETELY filled out to:
Intel Corporation FAX: 916-356-2803
Intel Flash Software Marketing
FM3-163
1900 Prairie City Road
Folsom, CA 95630
Atten: Flash S/W License
Intel reserves the right to use and/or include Your name in
public relations activities and marketing material and may
request You to submit endorsements for the Software. If You
wish to discuss participation in this program, please send a
fax to 916-356-2803 attn: "Software Marketing" with contact
information and an Intel representative will contact You.
Revised: 02/16/01
***************************************************************************/
#define CURRENT_FILE_BEING_COMPILED FDI_FM
/* ### Include Files
* ################################# */
#include <string.h> /* added by jjs */
#include <ctype.h> /* added by jjs */
#include <stdio.h> /* added by jjs */
#include "fdi_ext.h"
#include "fdi_mutx.h"
#include "fdi_file.h"
/*#include <string.h>*/ /* commented by jjs */
/*#include <ctype.h>*/ /* commented by jjs */
/*#include <stdio.h>*/ /* commented by jjs */
#if (FILE_MANAGER == TRUE)
/* ### Local Declarations
* ################################# */
/* mode_flag bit masks */
#define FILE_MUST_EXIST 0x01
#define FILE_CONTENT_LOST 0x02
#define READ_PERMITTED 0x04
#define WRITE_PERMITTED 0x08
#define WRITE_END_ONLY 0x10
#define MODE_INVALID 0x00
#define FILE_INVALID 0xFFFF /* invalid identifier value */
#define FILE_NULL 0x00 /* File Manager NULL value */
#define FILE_NOERR 0x00 /* API no error return value */
#define FILE_NOEOF 0x00 /* indicates no EOF */
#define FILE_EOS '\0' /* null character marks EOS */
#define INIT_BYTE 0x00 /* MemorySet init byte value */
/* define macros to initialize structures */
#define INIT_FILE_INFO(fi_ptr) \
MemorySet((BYTE_PTR)(fi_ptr), INIT_BYTE, sizeof(FILE_INFO)); \
((FILE_INFO *)(fi_ptr))->data_id = FILE_INVALID; \
((FILE_INFO *)(fi_ptr))->plr_id = FILE_INVALID
#define INIT_STREAM_INFO(si_ptr) \
MemorySet((BYTE_PTR)(si_ptr), INIT_BYTE, sizeof(STREAM_INFO)); \
((STREAM_INFO *)(si_ptr))->open_file_info.data_id = FILE_INVALID; \
((STREAM_INFO *)(si_ptr))->open_file_info.plr_id = FILE_INVALID; \
((STREAM_INFO *)(si_ptr))->file_info_id = FILE_INVALID
#define INIT_FILE_LOOKUP(fl_ptr) \
MemorySet((BYTE_PTR)(fl_ptr), INIT_BYTE, sizeof(FILE_LOOKUP)); \
((FILE_LOOKUP *)(fl_ptr))->file_info_id = FILE_INVALID
/*
* local structure contains the open stream information much like an
* operating system's FILE pointer structure
*/
typedef struct tag_stream_info
{
DWORD file_pointer; /* offset into the open file */
FILE_INFO open_file_info; /* file information */
FILE_ID file_info_id; /* file info parameter's identifier */
int read_eof; /* track read accesses past EOF */
ERR_CODE ferrno; /* track errors found in this stream */
char mode_flag; /* bit 0 named file must already exist
* bit 1 existing file's contents lost
* bit 2 read from stream permitted
* bit 3 write to stream permitted
* bit 4 write permitted only at end
* of stream */
} STREAM_INFO;
/* StreamInfoTable is the STREAM_INFO structure array used
* by API's to keep track of opened files
* index 0 is reserved for search info
*/
static STREAM_INFO StreamInfoTable[NUM_OPEN_FILES + 1];
/* the search info structure is at index 0 in StreamInfoTable so
* FDI_fopen can't return 0 since it is reserved for error
*/
static STREAM_INFO *const SearchInfoPtr = StreamInfoTable;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -