Fx_ufer.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. /**   Utility (UTI)                                                       */
  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_uti.h"
  44. /**************************************************************************/ 
  45. /*                                                                        */ 
  46. /*  FUNCTION                                               RELEASE        */ 
  47. /*                                                                        */ 
  48. /*    _fx_utility_FAT_entry_read                          PORTABLE C      */ 
  49. /*                                                           3.0          */ 
  50. /*  AUTHOR                                                                */ 
  51. /*                                                                        */ 
  52. /*    William E. Lamie, Express Logic, Inc.                               */ 
  53. /*                                                                        */ 
  54. /*  DESCRIPTION                                                           */ 
  55. /*                                                                        */ 
  56. /*    This function reads the supplied FAT entry from the first FAT of    */ 
  57. /*    the media.  Both 12-bit and 16-bit FAT reading is supported, while  */ 
  58. /*    only 16-bit information is returned.                                */ 
  59. /*                                                                        */ 
  60. /*  INPUT                                                                 */ 
  61. /*                                                                        */ 
  62. /*    media_ptr                             Media control block pointer   */ 
  63. /*    cluster                               Cluster entry number          */ 
  64. /*    entry_ptr                             Pointer to destination for    */ 
  65. /*                                            the FAT entry               */ 
  66. /*                                                                        */ 
  67. /*  OUTPUT                                                                */ 
  68. /*                                                                        */ 
  69. /*    return status                                                       */ 
  70. /*                                                                        */ 
  71. /*  CALLS                                                                 */ 
  72. /*                                                                        */ 
  73. /*    _fx_utility_16_unsigned_read          Read a UINT from FAT buffer   */ 
  74. /*    _fx_utility_log_sector_read           Read FAT sector into memory   */ 
  75. /*                                                                        */ 
  76. /*  CALLED BY                                                             */ 
  77. /*                                                                        */ 
  78. /*    FileX System Functions                                              */ 
  79. /*                                                                        */ 
  80. /*  RELEASE HISTORY                                                       */ 
  81. /*                                                                        */ 
  82. /*    DATE              NAME                      DESCRIPTION             */ 
  83. /*                                                                        */ 
  84. /*  01-01-1999     William E. Lamie         Initial Version 1.0           */ 
  85. /*  03-01-2000     William E. Lamie         Modified comment(s), modified */ 
  86. /*                                            12-bit sign extension, and  */ 
  87. /*                                            modified byte offsets for   */ 
  88. /*                                            16-bit FAT entries,         */ 
  89. /*                                            resulting in version 1.0b.  */ 
  90. /*  01-28-2001     William E. Lamie         Modified comment(s),          */ 
  91. /*                                            resulting in version 2.0.   */
  92. /*  03-01-2002     Mohammad N. Minhaz       Modified comment(s), and      */ 
  93. /*                                            added logic for reading     */ 
  94. /*                                            FAT32 entries, resulting in */ 
  95. /*                                            version 3.0.                */ 
  96. /*                                                                        */ 
  97. /**************************************************************************/ 
  98. UINT  _fx_utility_FAT_entry_read(FX_MEDIA *media_ptr, ULONG cluster, ULONG *entry_ptr)
  99. {
  100. ULONG       FAT_sector;
  101. ULONG       byte_offset, entry32;
  102. UCHAR_PTR   FAT_ptr;
  103. UINT        entry;
  104. UINT        status;
  105.     /* Determine which type of FAT is present.  */
  106.     if (media_ptr -> fx_media_12_bit_FAT)
  107.     {
  108.         /* Calculate the byte offset to the cluster entry.  */
  109.         byte_offset =  (((ULONG) cluster << 1) + cluster) >> 1;
  110.         /* Calculate the FAT sector the requested FAT entry resides in.  */
  111.         FAT_sector =  (byte_offset / media_ptr -> fx_media_bytes_per_sector) +
  112.                         (ULONG) media_ptr -> fx_media_reserved_sectors;
  113.         /* Read the sector in.  */
  114.         status =  _fx_utility_log_sector_read(media_ptr, (ULONG) FAT_sector, 
  115.                                         media_ptr -> fx_media_memory_buffer, (ULONG) 1);
  116.         /* Determine if an error occurred.  */
  117.         if (status != FX_SUCCESS)
  118.         {
  119.             /* Return the error status.  */
  120.             return(status);
  121.         }
  122.         /* Now calculate the byte offset into this FAT sector.  */
  123.         byte_offset =  byte_offset -  
  124.                     ((FAT_sector - (ULONG) media_ptr -> fx_media_reserved_sectors) *
  125.                         media_ptr -> fx_media_bytes_per_sector); 
  126.         /* Setup a pointer into the buffer.  */
  127.         FAT_ptr =  (UCHAR_PTR) media_ptr -> fx_media_memory_buffer + (UINT) byte_offset;
  128.         /* Determine if the cluster entry is odd or even.  */
  129.         if (cluster & 1)
  130.         {
  131.             /* Odd cluster number.  */
  132.             /* Pickup the lower nibble of the FAT entry.  */
  133.             entry =  (((UINT) *FAT_ptr) & 0xF0) >> 4;
  134.             
  135.             /* Move to the next byte of the FAT entry.  */
  136.             FAT_ptr++;
  137.             /* Determine if we are now past the end of the FAT buffer in memory.  */
  138.             if (byte_offset == (ULONG) (media_ptr -> fx_media_bytes_per_sector - 1))
  139.             {
  140.                 /* Yes, we need to read the next sector.  */
  141.                 FAT_sector++;
  142.                 status =  _fx_utility_log_sector_read(media_ptr, (ULONG) FAT_sector, 
  143.                                         media_ptr -> fx_media_memory_buffer, (ULONG) 1);
  144.                 /* Determine if an error occurred.  */
  145.                 if (status != FX_SUCCESS)
  146.                 {
  147.                     /* Return the error status.  */
  148.                     return(status);
  149.                 }
  150.                 /* Setup a pointer into the buffer.  */
  151.                 FAT_ptr =  (UCHAR_PTR) media_ptr -> fx_media_memory_buffer;
  152.             }
  153.             /* Pickup the upper 8 bits of the FAT entry.  */
  154.             entry =  entry | (((UINT) *FAT_ptr) << 4);
  155.         }
  156.         else
  157.         {
  158.           
  159.             /* Even cluster number.  */
  160.             /* Pickup the lower byte of the FAT entry.  */
  161.             entry =  (UINT) (((UINT) *FAT_ptr) & 0xFF);
  162.             
  163.             /* Move to the next nibble of the FAT entry.  */
  164.             FAT_ptr++;
  165.             /* Determine if we are now past the end of the FAT buffer in memory.  */
  166.             if (byte_offset == (ULONG) (media_ptr -> fx_media_bytes_per_sector - 1))
  167.             {
  168.                 /* Yes, we need to read the next sector.  */
  169.                 FAT_sector++;
  170.                 status =  _fx_utility_log_sector_read(media_ptr, (ULONG) FAT_sector, 
  171.                                         media_ptr -> fx_media_memory_buffer, (ULONG) 1);
  172.                 /* Determine if an error occurred.  */
  173.                 if (status != FX_SUCCESS)
  174.                     return(status);
  175.                 /* Setup a pointer into the buffer.  */
  176.                 FAT_ptr =  (UCHAR_PTR) media_ptr -> fx_media_memory_buffer;
  177.             }
  178.             /* Pickup the upper 4 bits of the FAT entry.  */
  179.             entry =  entry | ((((UINT) *FAT_ptr) & 0x0F) << 8);
  180.         }
  181.         /* Determine if we need to do sign extension on the 12-bit eof value.  */
  182.         if (entry >= FX_MAX_12BIT_CLUST)
  183.         {
  184.             /* Yes, we need to sign extend.  */
  185.             entry =  entry | FX_SIGN_EXTEND;
  186.         }
  187.         *entry_ptr =  entry;
  188.     }
  189.     else if (! media_ptr -> fx_media_32_bit_FAT)
  190.     {
  191.         /* 16-bit FAT is present.  */
  192.         /* Calculate the byte offset to the cluster entry.  */
  193.         byte_offset =  (((ULONG) cluster) * 2); 
  194.         /* Calculate the FAT sector the requested FAT entry resides in.  */
  195.         FAT_sector =  (byte_offset / media_ptr -> fx_media_bytes_per_sector) +
  196.                         (ULONG) media_ptr -> fx_media_reserved_sectors;
  197.         /* Read the FAT sector.  */
  198.         status =  _fx_utility_log_sector_read(media_ptr, (ULONG) FAT_sector, 
  199.                                         media_ptr -> fx_media_memory_buffer, (ULONG) 1);
  200.         /* Determine if an error occurred.  */
  201.         if (status != FX_SUCCESS)
  202.         {
  203.     
  204.             /* Return the error code.  */
  205.             return(status);
  206.         }
  207.         /* Now calculate the byte offset into this FAT sector.  */
  208.         byte_offset =  byte_offset -  
  209.                     ((FAT_sector - (ULONG) media_ptr -> fx_media_reserved_sectors) *
  210.                         media_ptr -> fx_media_bytes_per_sector); 
  211.         /* Setup a pointer into the buffer.  */
  212.         FAT_ptr =  (UCHAR_PTR) media_ptr -> fx_media_memory_buffer + (UINT) byte_offset;
  213.         /* Pickup the FAT entry.  */
  214.         entry =  _fx_utility_16_unsigned_read(FAT_ptr);
  215.         *entry_ptr =  entry;
  216.     }
  217.     else
  218.     {
  219.         /* 32 bit FAT present */
  220.         byte_offset =  (((ULONG) cluster) * 4); 
  221.         /* Calculate the FAT sector the requested FAT entry resides in.  */
  222.         FAT_sector =  (byte_offset / media_ptr -> fx_media_bytes_per_sector) +
  223.                         (ULONG) media_ptr -> fx_media_reserved_sectors;
  224.         byte_offset %= media_ptr -> fx_media_bytes_per_sector;
  225.         status =  _fx_utility_log_sector_read(media_ptr, (ULONG) FAT_sector, 
  226.                                         media_ptr -> fx_media_memory_buffer, (ULONG) 1);
  227.         /* Determine if an error occurred.  */
  228.         if (status != FX_SUCCESS)
  229.         {
  230.     
  231.             /* Return the error code.  */
  232.             return(status);
  233.         }
  234.         /* Setup a pointer into the buffer.  */
  235.         FAT_ptr =  (UCHAR_PTR) media_ptr -> fx_media_memory_buffer + byte_offset;
  236.         /* Pickup the FAT entry.  */
  237.         entry32 =  _fx_utility_32_unsigned_read(FAT_ptr);
  238.         entry32 &= 0x0FFFFFFFUL;
  239.         *entry_ptr =  entry32;
  240.     }
  241.     
  242.     /* Return success to the caller.  */
  243.     return(FX_SUCCESS);
  244. }
  245. #endif