Fx_mbie.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:14k
源码类别:

DVD

开发平台:

Others

  1. /**************************************************************************/ 
  2. /*                                                                        */ 
  3. /*            Copyright (c) 1996-2002 by Express Logic Inc.               */ 
  4. /*                                                                        */ 
  5. /*  This software is copyrighted by and is the sole property of Express   */ 
  6. /*  Logic, Inc.  All rights, title, ownership, or other interests         */ 
  7. /*  in the software remain the property of Express Logic, Inc.  This      */ 
  8. /*  software may only be used in accordance with the corresponding        */ 
  9. /*  license agreement.  Any unauthorized use, duplication, transmission,  */ 
  10. /*  distribution, or disclosure of this software is expressly forbidden.  */ 
  11. /*                                                                        */
  12. /*  This Copyright notice may not be removed or modified without prior    */ 
  13. /*  written consent of Express Logic, Inc.                                */ 
  14. /*                                                                        */ 
  15. /*  Express Logic, Inc. reserves the right to modify this software        */ 
  16. /*  without notice.                                                       */ 
  17. /*                                                                        */ 
  18. /*  Express Logic, Inc.                     info@expresslogic.com         */
  19. /*  11423 West Bernardo Court               http://www.expresslogic.com   */
  20. /*  San Diego, CA  92127                                                  */
  21. /*                                                                        */
  22. /**************************************************************************/
  23. /**************************************************************************/
  24. /**************************************************************************/
  25. /**                                                                       */ 
  26. /** FileX Component                                                       */ 
  27. /**                                                                       */
  28. /**   Media (MED)                                                         */
  29. /**                                                                       */
  30. /**************************************************************************/
  31. /**************************************************************************/
  32. #include "Config.h" // Global Configuration - do not remove!
  33. #ifdef ENABLE_FILEX
  34. #ifdef _DEBUG
  35. #undef IFTRACE
  36. #define IFTRACE if (gTraceFileSys)
  37. #include "DebugDbgMain.h"
  38. #endif //_DEBUG
  39. #define FX_SOURCE_CODE
  40. /* Include necessary system files.  */
  41. #include "PlaycoreFileSysFileXfx_api.h"
  42. #include "PlaycoreFileSysFileXfx_sys.h"
  43. #include "PlaycoreFileSysFileXfx_med.h"
  44. #include "PlaycoreFileSysFileXfx_uti.h"
  45. /**************************************************************************/ 
  46. /*                                                                        */ 
  47. /*  FUNCTION                                               RELEASE        */ 
  48. /*                                                                        */ 
  49. /*    _fx_media_boot_info_extract                         PORTABLE C      */ 
  50. /*                                                           3.0          */ 
  51. /*  AUTHOR                                                                */ 
  52. /*                                                                        */ 
  53. /*    William E. Lamie, Express Logic, Inc.                               */ 
  54. /*                                                                        */ 
  55. /*  DESCRIPTION                                                           */ 
  56. /*                                                                        */ 
  57. /*    This function extracts and validates the information from the boot  */ 
  58. /*    record found in the memory buffer.  If the boot record is invalid,  */ 
  59. /*    an FX_MEDIA_INVALID status is returned to the caller.               */ 
  60. /*                                                                        */ 
  61. /*    The MS-DOS boot sector (512 bytes) that is operated on by this      */ 
  62. /*    function must look like the following:                              */ 
  63. /*                                                                        */ 
  64. /*          Byte Offset         Meaning             Size                  */ 
  65. /*                                                                        */ 
  66. /*            0x000         Jump Instructions        3                    */ 
  67. /*            0x003         OEM Name                 8                    */ 
  68. /*            0x00B        *Bytes per Sector         2                    */ 
  69. /*            0x00D        *Sectors per Cluster      1                    */ 
  70. /*            0x00E        *Reserved Sectors         2                    */ 
  71. /*            0x010        *Number of FATs           1                    */ 
  72. /*            0x011        *Max Root Dir Entries     2                    */ 
  73. /*            0x013        *Number of Sectors        2                    */ 
  74. /*            0x015         Media Type               1                    */ 
  75. /*            0x016        *Sectors per FAT          2                    */ 
  76. /*            0x018        *Sectors per Track        2                    */ 
  77. /*            0x01A        *Number of Heads          2                    */ 
  78. /*            0x01C        *Hidden Sectors           4                    */ 
  79. /*            0x020        *Huge Sectors             4                    */ 
  80. /*            0x024         Drive Number             1                    */ 
  81. /*            0x025         Reserved                 1                    */ 
  82. /*            0x026         Boot Signature           1                    */ 
  83. /*            0x027         Volume ID                4                    */ 
  84. /*            0x02B         Volume Label             11                   */ 
  85. /*            0x036         File System Type         8                    */ 
  86. /*             ...              ...                 ...                   */ 
  87. /*            0x1FE       **Signature (0x55aa)       2                    */ 
  88. /*                                                                        */ 
  89. /*            * Denotes which elements of the boot record                 */ 
  90. /*              FileX uses.                                               */ 
  91. /*                                                                        */ 
  92. /*            **Denotes the element is checked by the I/O                 */ 
  93. /*              driver.  This eliminates the need for a minimum           */ 
  94. /*              512-byte buffer for FileX.                                */ 
  95. /*                                                                        */ 
  96. /*  Note: All values above are in little endian format, i.e. the LSB is   */ 
  97. /*        in the lowest address.                                          */ 
  98. /*                                                                        */ 
  99. /*  INPUT                                                                 */ 
  100. /*                                                                        */ 
  101. /*    media_ptr                             Media control block pointer   */ 
  102. /*                                                                        */ 
  103. /*  OUTPUT                                                                */ 
  104. /*                                                                        */ 
  105. /*    return status                                                       */ 
  106. /*                                                                        */ 
  107. /*  CALLS                                                                 */ 
  108. /*                                                                        */ 
  109. /*    _fx_utility_16_unsigned_read          Read a UINT from buffer       */ 
  110. /*    _fx_utility_32_unsigned_read          Read a ULONG from buffer      */ 
  111. /*                                                                        */ 
  112. /*  CALLED BY                                                             */ 
  113. /*                                                                        */ 
  114. /*    _fx_media_open                        Media open function           */ 
  115. /*                                                                        */ 
  116. /*  RELEASE HISTORY                                                       */ 
  117. /*                                                                        */ 
  118. /*    DATE              NAME                      DESCRIPTION             */ 
  119. /*                                                                        */ 
  120. /*  01-01-1999     William E. Lamie         Initial Version 1.0           */ 
  121. /*  03-01-2000     William E. Lamie         Modified comment(s),          */ 
  122. /*                                            resulting in version 1.0b.  */ 
  123. /*  01-28-2001     William E. Lamie         Modified comment(s),          */ 
  124. /*                                            resulting in version 2.0.   */ 
  125. /*  03-01-2002     Mohammad N. Minhaz       Modified comment(s), and      */ 
  126. /*                                            added logic to read FAT32   */ 
  127. /*                                            boot record, resulting in   */ 
  128. /*                                            version 3.0.                */ 
  129. /*                                                                        */ 
  130. /**************************************************************************/ 
  131. UINT  _fx_media_boot_info_extract(FX_MEDIA *media_ptr, UCHAR_PTR boot_sector)
  132. {
  133.     /* Extract the number of bytes per sector.  */
  134.     media_ptr -> fx_media_bytes_per_sector =    _fx_utility_16_unsigned_read(&boot_sector[FX_BYTES_SECTOR]);
  135. if (media_ptr -> fx_media_bytes_per_sector == 0)
  136. return(FX_IO_ERROR);
  137.     /* Extract the number of sectors per track.  */
  138.     media_ptr -> fx_media_sectors_per_track =   _fx_utility_16_unsigned_read(&boot_sector[FX_SECTORS_PER_TRK]);
  139.     /* Extract the number of heads.  */
  140.     media_ptr -> fx_media_heads =               _fx_utility_16_unsigned_read(&boot_sector[FX_HEADS]);
  141.     /* Extract the total number of sectors.  */
  142.     media_ptr -> fx_media_total_sectors =       _fx_utility_16_unsigned_read(&boot_sector[FX_SECTORS]);
  143.     if (media_ptr -> fx_media_total_sectors == 0)
  144.         media_ptr -> fx_media_total_sectors = _fx_utility_32_unsigned_read(&boot_sector[FX_HUGE_SECTORS]);
  145.     if (media_ptr -> fx_media_total_sectors == 0)
  146.         return(FX_IO_ERROR);
  147.     /* Extract the number of reserved sectors before the first FAT.  */
  148.     media_ptr -> fx_media_reserved_sectors =    _fx_utility_16_unsigned_read(&boot_sector[FX_RESERVED_SECTORS]);
  149.     /* Extract the number of sectors per cluster.  */
  150.     media_ptr -> fx_media_sectors_per_cluster = ((UINT) boot_sector[FX_SECTORS_CLUSTER] & 0xFF);
  151.     if (media_ptr -> fx_media_sectors_per_cluster == 0)
  152.         return(FX_IO_ERROR);
  153.     /* Extract media type */
  154.     media_ptr -> fx_media_type = boot_sector[FX_MEDIA_TYPE];
  155.     /* Extract the number of sectors per FAT.  */
  156.     media_ptr -> fx_media_sectors_per_FAT =     _fx_utility_16_unsigned_read(&boot_sector[FX_SECTORS_PER_FAT]);
  157.     if (media_ptr -> fx_media_sectors_per_FAT == 0)
  158.         media_ptr -> fx_media_sectors_per_FAT = _fx_utility_32_unsigned_read(&boot_sector[FX_SECTORS_PER_FAT_32]);
  159.     if (media_ptr -> fx_media_sectors_per_FAT == 0)
  160.         return(FX_IO_ERROR);
  161.     /* Extract the number of FATs.  */
  162.     media_ptr -> fx_media_number_of_FATs =      ((UINT) boot_sector[FX_NUMBER_OF_FATS] & 0xFF);
  163.     if (media_ptr -> fx_media_number_of_FATs == 0)
  164.         return(FX_IO_ERROR);
  165.     /* Extract the number of hidden sectors.  */
  166.     media_ptr -> fx_media_hidden_sectors =      _fx_utility_32_unsigned_read(&boot_sector[FX_HIDDEN_SECTORS]);
  167.     /* Extract the number of root directory entries.  */
  168.     media_ptr -> fx_media_root_directory_entries =  _fx_utility_16_unsigned_read(&boot_sector[FX_ROOT_DIR_ENTRIES]);
  169.     /* Extract root directory starting cluster (32 bit only) and compute start sector */
  170.     media_ptr -> fx_media_root_clus_32 = _fx_utility_32_unsigned_read(&boot_sector[FX_ROOT_CLUS_32]);
  171.     /* root_sector_start has been computed */
  172.     media_ptr -> fx_media_root_sector_start =  media_ptr -> fx_media_reserved_sectors +
  173. (media_ptr -> fx_media_number_of_FATs *
  174. media_ptr -> fx_media_sectors_per_FAT);
  175.     /* Calculate the number of directory sectors.  */
  176.     media_ptr -> fx_media_root_sectors =  
  177. ((media_ptr -> fx_media_root_directory_entries * FX_DIR_ENTRY_SIZE) +
  178. media_ptr -> fx_media_bytes_per_sector - 1)/
  179. media_ptr -> fx_media_bytes_per_sector;
  180.     /* Calculate the starting data sector.  */
  181.     media_ptr -> fx_media_data_sector_start =  media_ptr -> fx_media_root_sector_start +
  182. media_ptr -> fx_media_root_sectors;
  183.     /* Calculate the total number of clusters.  */
  184.     if (media_ptr -> fx_media_total_sectors)
  185.     {
  186.         /* Calculate from 16-bit total sectors.  */
  187.         media_ptr -> fx_media_total_clusters =   (media_ptr -> fx_media_total_sectors -
  188. media_ptr -> fx_media_data_sector_start)/
  189. media_ptr -> fx_media_sectors_per_cluster;
  190.     }
  191.     /* Determine if a 12-bit FAT is in use.  */
  192.     if (media_ptr -> fx_media_total_clusters < FX_12_BIT_FAT_SIZE)
  193.     {
  194.         /* No, 16-bit FAT is present.  Set flag accordingly.  */
  195.         media_ptr -> fx_media_12_bit_FAT = FX_TRUE;
  196.         media_ptr -> fx_media_32_bit_FAT = FX_FALSE;
  197.     } else if (media_ptr -> fx_media_total_clusters < FX_16_BIT_FAT_SIZE)
  198.     {
  199.         /* Yes, a 12-bit FAT is present.  Set flag accordingly.  */
  200.         media_ptr -> fx_media_12_bit_FAT =  FX_FALSE;
  201.         media_ptr -> fx_media_32_bit_FAT =  FX_FALSE;
  202.     } else 
  203.     {
  204.         media_ptr -> fx_media_12_bit_FAT =  FX_FALSE;
  205.         media_ptr -> fx_media_32_bit_FAT =  FX_TRUE;
  206.     }
  207.     /* Return a successful status.  */
  208.     return(FX_SUCCESS);
  209. }
  210. #endif