Fx_ufer.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:14k
- /**************************************************************************/
- /* */
- /* Copyright (c) 1996-2002 by Express Logic Inc. */
- /* */
- /* This software is copyrighted by and is the sole property of Express */
- /* Logic, Inc. All rights, title, ownership, or other interests */
- /* in the software remain the property of Express Logic, Inc. This */
- /* software may only be used in accordance with the corresponding */
- /* license agreement. Any unauthorized use, duplication, transmission, */
- /* distribution, or disclosure of this software is expressly forbidden. */
- /* */
- /* This Copyright notice may not be removed or modified without prior */
- /* written consent of Express Logic, Inc. */
- /* */
- /* Express Logic, Inc. reserves the right to modify this software */
- /* without notice. */
- /* */
- /* Express Logic, Inc. info@expresslogic.com */
- /* 11423 West Bernardo Court http://www.expresslogic.com */
- /* San Diego, CA 92127 */
- /* */
- /**************************************************************************/
- /**************************************************************************/
- /**************************************************************************/
- /** */
- /** FileX Component */
- /** */
- /** Utility (UTI) */
- /** */
- /**************************************************************************/
- /**************************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef ENABLE_FILEX
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceFileSys)
- #include "DebugDbgMain.h"
- #endif //_DEBUG
- #define FX_SOURCE_CODE
- /* Include necessary system files. */
- #include "PlaycoreFileSysFileXfx_api.h"
- #include "PlaycoreFileSysFileXfx_sys.h"
- #include "PlaycoreFileSysFileXfx_uti.h"
- /**************************************************************************/
- /* */
- /* FUNCTION RELEASE */
- /* */
- /* _fx_utility_FAT_entry_read PORTABLE C */
- /* 3.0 */
- /* AUTHOR */
- /* */
- /* William E. Lamie, Express Logic, Inc. */
- /* */
- /* DESCRIPTION */
- /* */
- /* This function reads the supplied FAT entry from the first FAT of */
- /* the media. Both 12-bit and 16-bit FAT reading is supported, while */
- /* only 16-bit information is returned. */
- /* */
- /* INPUT */
- /* */
- /* media_ptr Media control block pointer */
- /* cluster Cluster entry number */
- /* entry_ptr Pointer to destination for */
- /* the FAT entry */
- /* */
- /* OUTPUT */
- /* */
- /* return status */
- /* */
- /* CALLS */
- /* */
- /* _fx_utility_16_unsigned_read Read a UINT from FAT buffer */
- /* _fx_utility_log_sector_read Read FAT sector into memory */
- /* */
- /* CALLED BY */
- /* */
- /* FileX System Functions */
- /* */
- /* RELEASE HISTORY */
- /* */
- /* DATE NAME DESCRIPTION */
- /* */
- /* 01-01-1999 William E. Lamie Initial Version 1.0 */
- /* 03-01-2000 William E. Lamie Modified comment(s), modified */
- /* 12-bit sign extension, and */
- /* modified byte offsets for */
- /* 16-bit FAT entries, */
- /* resulting in version 1.0b. */
- /* 01-28-2001 William E. Lamie Modified comment(s), */
- /* resulting in version 2.0. */
- /* 03-01-2002 Mohammad N. Minhaz Modified comment(s), and */
- /* added logic for reading */
- /* FAT32 entries, resulting in */
- /* version 3.0. */
- /* */
- /**************************************************************************/
- UINT _fx_utility_FAT_entry_read(FX_MEDIA *media_ptr, ULONG cluster, ULONG *entry_ptr)
- {
- ULONG FAT_sector;
- ULONG byte_offset, entry32;
- UCHAR_PTR FAT_ptr;
- UINT entry;
- UINT status;
- /* Determine which type of FAT is present. */
- if (media_ptr -> fx_media_12_bit_FAT)
- {
- /* Calculate the byte offset to the cluster entry. */
- byte_offset = (((ULONG) cluster << 1) + cluster) >> 1;
- /* Calculate the FAT sector the requested FAT entry resides in. */
- FAT_sector = (byte_offset / media_ptr -> fx_media_bytes_per_sector) +
- (ULONG) media_ptr -> fx_media_reserved_sectors;
- /* Read the sector in. */
- status = _fx_utility_log_sector_read(media_ptr, (ULONG) FAT_sector,
- media_ptr -> fx_media_memory_buffer, (ULONG) 1);
- /* Determine if an error occurred. */
- if (status != FX_SUCCESS)
- {
- /* Return the error status. */
- return(status);
- }
- /* Now calculate the byte offset into this FAT sector. */
- byte_offset = byte_offset -
- ((FAT_sector - (ULONG) media_ptr -> fx_media_reserved_sectors) *
- media_ptr -> fx_media_bytes_per_sector);
- /* Setup a pointer into the buffer. */
- FAT_ptr = (UCHAR_PTR) media_ptr -> fx_media_memory_buffer + (UINT) byte_offset;
- /* Determine if the cluster entry is odd or even. */
- if (cluster & 1)
- {
- /* Odd cluster number. */
- /* Pickup the lower nibble of the FAT entry. */
- entry = (((UINT) *FAT_ptr) & 0xF0) >> 4;
-
- /* Move to the next byte of the FAT entry. */
- FAT_ptr++;
- /* Determine if we are now past the end of the FAT buffer in memory. */
- if (byte_offset == (ULONG) (media_ptr -> fx_media_bytes_per_sector - 1))
- {
- /* Yes, we need to read the next sector. */
- FAT_sector++;
- status = _fx_utility_log_sector_read(media_ptr, (ULONG) FAT_sector,
- media_ptr -> fx_media_memory_buffer, (ULONG) 1);
- /* Determine if an error occurred. */
- if (status != FX_SUCCESS)
- {
- /* Return the error status. */
- return(status);
- }
- /* Setup a pointer into the buffer. */
- FAT_ptr = (UCHAR_PTR) media_ptr -> fx_media_memory_buffer;
- }
- /* Pickup the upper 8 bits of the FAT entry. */
- entry = entry | (((UINT) *FAT_ptr) << 4);
- }
- else
- {
-
- /* Even cluster number. */
- /* Pickup the lower byte of the FAT entry. */
- entry = (UINT) (((UINT) *FAT_ptr) & 0xFF);
-
- /* Move to the next nibble of the FAT entry. */
- FAT_ptr++;
- /* Determine if we are now past the end of the FAT buffer in memory. */
- if (byte_offset == (ULONG) (media_ptr -> fx_media_bytes_per_sector - 1))
- {
- /* Yes, we need to read the next sector. */
- FAT_sector++;
- status = _fx_utility_log_sector_read(media_ptr, (ULONG) FAT_sector,
- media_ptr -> fx_media_memory_buffer, (ULONG) 1);
- /* Determine if an error occurred. */
- if (status != FX_SUCCESS)
- return(status);
- /* Setup a pointer into the buffer. */
- FAT_ptr = (UCHAR_PTR) media_ptr -> fx_media_memory_buffer;
- }
- /* Pickup the upper 4 bits of the FAT entry. */
- entry = entry | ((((UINT) *FAT_ptr) & 0x0F) << 8);
- }
- /* Determine if we need to do sign extension on the 12-bit eof value. */
- if (entry >= FX_MAX_12BIT_CLUST)
- {
- /* Yes, we need to sign extend. */
- entry = entry | FX_SIGN_EXTEND;
- }
- *entry_ptr = entry;
- }
- else if (! media_ptr -> fx_media_32_bit_FAT)
- {
- /* 16-bit FAT is present. */
- /* Calculate the byte offset to the cluster entry. */
- byte_offset = (((ULONG) cluster) * 2);
- /* Calculate the FAT sector the requested FAT entry resides in. */
- FAT_sector = (byte_offset / media_ptr -> fx_media_bytes_per_sector) +
- (ULONG) media_ptr -> fx_media_reserved_sectors;
- /* Read the FAT sector. */
- status = _fx_utility_log_sector_read(media_ptr, (ULONG) FAT_sector,
- media_ptr -> fx_media_memory_buffer, (ULONG) 1);
- /* Determine if an error occurred. */
- if (status != FX_SUCCESS)
- {
-
- /* Return the error code. */
- return(status);
- }
- /* Now calculate the byte offset into this FAT sector. */
- byte_offset = byte_offset -
- ((FAT_sector - (ULONG) media_ptr -> fx_media_reserved_sectors) *
- media_ptr -> fx_media_bytes_per_sector);
- /* Setup a pointer into the buffer. */
- FAT_ptr = (UCHAR_PTR) media_ptr -> fx_media_memory_buffer + (UINT) byte_offset;
- /* Pickup the FAT entry. */
- entry = _fx_utility_16_unsigned_read(FAT_ptr);
- *entry_ptr = entry;
- }
- else
- {
- /* 32 bit FAT present */
- byte_offset = (((ULONG) cluster) * 4);
- /* Calculate the FAT sector the requested FAT entry resides in. */
- FAT_sector = (byte_offset / media_ptr -> fx_media_bytes_per_sector) +
- (ULONG) media_ptr -> fx_media_reserved_sectors;
- byte_offset %= media_ptr -> fx_media_bytes_per_sector;
- status = _fx_utility_log_sector_read(media_ptr, (ULONG) FAT_sector,
- media_ptr -> fx_media_memory_buffer, (ULONG) 1);
- /* Determine if an error occurred. */
- if (status != FX_SUCCESS)
- {
-
- /* Return the error code. */
- return(status);
- }
- /* Setup a pointer into the buffer. */
- FAT_ptr = (UCHAR_PTR) media_ptr -> fx_media_memory_buffer + byte_offset;
- /* Pickup the FAT entry. */
- entry32 = _fx_utility_32_unsigned_read(FAT_ptr);
- entry32 &= 0x0FFFFFFFUL;
- *entry_ptr = entry32;
- }
-
- /* Return success to the caller. */
- return(FX_SUCCESS);
- }
- #endif