Fx_mbie.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 */
- /** */
- /** Media (MED) */
- /** */
- /**************************************************************************/
- /**************************************************************************/
- #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_med.h"
- #include "PlaycoreFileSysFileXfx_uti.h"
- /**************************************************************************/
- /* */
- /* FUNCTION RELEASE */
- /* */
- /* _fx_media_boot_info_extract PORTABLE C */
- /* 3.0 */
- /* AUTHOR */
- /* */
- /* William E. Lamie, Express Logic, Inc. */
- /* */
- /* DESCRIPTION */
- /* */
- /* This function extracts and validates the information from the boot */
- /* record found in the memory buffer. If the boot record is invalid, */
- /* an FX_MEDIA_INVALID status is returned to the caller. */
- /* */
- /* The MS-DOS boot sector (512 bytes) that is operated on by this */
- /* function must look like the following: */
- /* */
- /* Byte Offset Meaning Size */
- /* */
- /* 0x000 Jump Instructions 3 */
- /* 0x003 OEM Name 8 */
- /* 0x00B *Bytes per Sector 2 */
- /* 0x00D *Sectors per Cluster 1 */
- /* 0x00E *Reserved Sectors 2 */
- /* 0x010 *Number of FATs 1 */
- /* 0x011 *Max Root Dir Entries 2 */
- /* 0x013 *Number of Sectors 2 */
- /* 0x015 Media Type 1 */
- /* 0x016 *Sectors per FAT 2 */
- /* 0x018 *Sectors per Track 2 */
- /* 0x01A *Number of Heads 2 */
- /* 0x01C *Hidden Sectors 4 */
- /* 0x020 *Huge Sectors 4 */
- /* 0x024 Drive Number 1 */
- /* 0x025 Reserved 1 */
- /* 0x026 Boot Signature 1 */
- /* 0x027 Volume ID 4 */
- /* 0x02B Volume Label 11 */
- /* 0x036 File System Type 8 */
- /* ... ... ... */
- /* 0x1FE **Signature (0x55aa) 2 */
- /* */
- /* * Denotes which elements of the boot record */
- /* FileX uses. */
- /* */
- /* **Denotes the element is checked by the I/O */
- /* driver. This eliminates the need for a minimum */
- /* 512-byte buffer for FileX. */
- /* */
- /* Note: All values above are in little endian format, i.e. the LSB is */
- /* in the lowest address. */
- /* */
- /* INPUT */
- /* */
- /* media_ptr Media control block pointer */
- /* */
- /* OUTPUT */
- /* */
- /* return status */
- /* */
- /* CALLS */
- /* */
- /* _fx_utility_16_unsigned_read Read a UINT from buffer */
- /* _fx_utility_32_unsigned_read Read a ULONG from buffer */
- /* */
- /* CALLED BY */
- /* */
- /* _fx_media_open Media open function */
- /* */
- /* RELEASE HISTORY */
- /* */
- /* DATE NAME DESCRIPTION */
- /* */
- /* 01-01-1999 William E. Lamie Initial Version 1.0 */
- /* 03-01-2000 William E. Lamie Modified comment(s), */
- /* 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 to read FAT32 */
- /* boot record, resulting in */
- /* version 3.0. */
- /* */
- /**************************************************************************/
- UINT _fx_media_boot_info_extract(FX_MEDIA *media_ptr, UCHAR_PTR boot_sector)
- {
- /* Extract the number of bytes per sector. */
- media_ptr -> fx_media_bytes_per_sector = _fx_utility_16_unsigned_read(&boot_sector[FX_BYTES_SECTOR]);
- if (media_ptr -> fx_media_bytes_per_sector == 0)
- return(FX_IO_ERROR);
-
- /* Extract the number of sectors per track. */
- media_ptr -> fx_media_sectors_per_track = _fx_utility_16_unsigned_read(&boot_sector[FX_SECTORS_PER_TRK]);
-
- /* Extract the number of heads. */
- media_ptr -> fx_media_heads = _fx_utility_16_unsigned_read(&boot_sector[FX_HEADS]);
- /* Extract the total number of sectors. */
- media_ptr -> fx_media_total_sectors = _fx_utility_16_unsigned_read(&boot_sector[FX_SECTORS]);
- if (media_ptr -> fx_media_total_sectors == 0)
- media_ptr -> fx_media_total_sectors = _fx_utility_32_unsigned_read(&boot_sector[FX_HUGE_SECTORS]);
- if (media_ptr -> fx_media_total_sectors == 0)
- return(FX_IO_ERROR);
- /* Extract the number of reserved sectors before the first FAT. */
- media_ptr -> fx_media_reserved_sectors = _fx_utility_16_unsigned_read(&boot_sector[FX_RESERVED_SECTORS]);
- /* Extract the number of sectors per cluster. */
- media_ptr -> fx_media_sectors_per_cluster = ((UINT) boot_sector[FX_SECTORS_CLUSTER] & 0xFF);
- if (media_ptr -> fx_media_sectors_per_cluster == 0)
- return(FX_IO_ERROR);
- /* Extract media type */
- media_ptr -> fx_media_type = boot_sector[FX_MEDIA_TYPE];
- /* Extract the number of sectors per FAT. */
- media_ptr -> fx_media_sectors_per_FAT = _fx_utility_16_unsigned_read(&boot_sector[FX_SECTORS_PER_FAT]);
- if (media_ptr -> fx_media_sectors_per_FAT == 0)
- media_ptr -> fx_media_sectors_per_FAT = _fx_utility_32_unsigned_read(&boot_sector[FX_SECTORS_PER_FAT_32]);
- if (media_ptr -> fx_media_sectors_per_FAT == 0)
- return(FX_IO_ERROR);
- /* Extract the number of FATs. */
- media_ptr -> fx_media_number_of_FATs = ((UINT) boot_sector[FX_NUMBER_OF_FATS] & 0xFF);
- if (media_ptr -> fx_media_number_of_FATs == 0)
- return(FX_IO_ERROR);
- /* Extract the number of hidden sectors. */
- media_ptr -> fx_media_hidden_sectors = _fx_utility_32_unsigned_read(&boot_sector[FX_HIDDEN_SECTORS]);
- /* Extract the number of root directory entries. */
- media_ptr -> fx_media_root_directory_entries = _fx_utility_16_unsigned_read(&boot_sector[FX_ROOT_DIR_ENTRIES]);
- /* Extract root directory starting cluster (32 bit only) and compute start sector */
- media_ptr -> fx_media_root_clus_32 = _fx_utility_32_unsigned_read(&boot_sector[FX_ROOT_CLUS_32]);
- /* root_sector_start has been computed */
- media_ptr -> fx_media_root_sector_start = media_ptr -> fx_media_reserved_sectors +
- (media_ptr -> fx_media_number_of_FATs *
- media_ptr -> fx_media_sectors_per_FAT);
- /* Calculate the number of directory sectors. */
- media_ptr -> fx_media_root_sectors =
- ((media_ptr -> fx_media_root_directory_entries * FX_DIR_ENTRY_SIZE) +
- media_ptr -> fx_media_bytes_per_sector - 1)/
- media_ptr -> fx_media_bytes_per_sector;
- /* Calculate the starting data sector. */
- media_ptr -> fx_media_data_sector_start = media_ptr -> fx_media_root_sector_start +
- media_ptr -> fx_media_root_sectors;
-
- /* Calculate the total number of clusters. */
- if (media_ptr -> fx_media_total_sectors)
- {
- /* Calculate from 16-bit total sectors. */
- media_ptr -> fx_media_total_clusters = (media_ptr -> fx_media_total_sectors -
- media_ptr -> fx_media_data_sector_start)/
- media_ptr -> fx_media_sectors_per_cluster;
- }
-
- /* Determine if a 12-bit FAT is in use. */
- if (media_ptr -> fx_media_total_clusters < FX_12_BIT_FAT_SIZE)
- {
- /* No, 16-bit FAT is present. Set flag accordingly. */
- media_ptr -> fx_media_12_bit_FAT = FX_TRUE;
- media_ptr -> fx_media_32_bit_FAT = FX_FALSE;
- } else if (media_ptr -> fx_media_total_clusters < FX_16_BIT_FAT_SIZE)
- {
- /* Yes, a 12-bit FAT is present. Set flag accordingly. */
- media_ptr -> fx_media_12_bit_FAT = FX_FALSE;
- media_ptr -> fx_media_32_bit_FAT = FX_FALSE;
- } else
- {
- media_ptr -> fx_media_12_bit_FAT = FX_FALSE;
- media_ptr -> fx_media_32_bit_FAT = FX_TRUE;
- }
- /* Return a successful status. */
- return(FX_SUCCESS);
- }
- #endif