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

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. #ifndef FX_MEDIA_PART_DEFINED
  43. typedef struct FX_MEDIA_PART_STRUCT
  44. {
  45.     ULONG fx_media_part_start;    
  46.     ULONG fx_media_part_size;
  47. } FX_MEDIA_PART;
  48. #endif
  49. /**************************************************************************/ 
  50. /*                                                                        */ 
  51. /*  FUNCTION                                               RELEASE        */ 
  52. /*                                                                        */ 
  53. /*    _fx_utility_partition_get                           PORTABLE C      */ 
  54. /*                                                           3.0          */ 
  55. /*  AUTHOR                                                                */ 
  56. /*                                                                        */ 
  57. /*    Mohammad N. Minhaz, Express Logic, Inc.                             */ 
  58. /*                                                                        */ 
  59. /*  DESCRIPTION                                                           */ 
  60. /*                                                                        */ 
  61. /*    This function parses the partition sector and completes the         */ 
  62. /*    supplied partition entry structure.                                 */ 
  63. /*                                                                        */ 
  64. /*  INPUT                                                                 */ 
  65. /*                                                                        */ 
  66. /*    part_tab                              Pointer to partition table    */ 
  67. /*    count                                 Number of partitions found    */ 
  68. /*    sect                                  Base sector                   */ 
  69. /*    sect_buf                              Buffer containing partition   */ 
  70. /*                                            table                       */ 
  71. /*                                                                        */ 
  72. /*  OUTPUT                                                                */ 
  73. /*                                                                        */ 
  74. /*    return status                                                       */ 
  75. /*                                                                        */ 
  76. /*  CALLS                                                                 */ 
  77. /*                                                                        */ 
  78. /*    None                                                                */ 
  79. /*                                                                        */ 
  80. /*  CALLED BY                                                             */ 
  81. /*                                                                        */ 
  82. /*    Application Driver                                                  */ 
  83. /*                                                                        */ 
  84. /*  RELEASE HISTORY                                                       */ 
  85. /*                                                                        */ 
  86. /*    DATE              NAME                      DESCRIPTION             */ 
  87. /*                                                                        */ 
  88. /*  07-04-2002     Mohammad N. Minhaz       Initial Version 1.0           */ 
  89. /*                                                                        */ 
  90. /**************************************************************************/ 
  91. UINT  _fx_utility_partition_get(FX_MEDIA_PART *part_tab, 
  92.                                 UINT *count, ULONG sect, UCHAR *sect_buf)
  93. {
  94.     UINT i;
  95.     ULONG base_sect, val;
  96.  
  97.     base_sect = 0;
  98.     /* find out if it is a sub partition */
  99.     for(i = 0; i < *count ; i++)
  100.         if (sect == part_tab[i].fx_media_part_start){
  101.             base_sect = part_tab[i].fx_media_part_start; 
  102.             break; /* sub part */
  103.         }
  104.     for(i = 446; i <= 494; i+=16)
  105.     {
  106.         if (sect_buf[i + 4] == 0) /* no partition entry here */
  107.             continue;
  108.         val = (ULONG) sect_buf[i + 8] ; /* little endian start value */
  109.         val = (((ULONG) sect_buf[i + 9]) << 8) | val;
  110.         val = (((ULONG) sect_buf[i + 10]) << 16) | val;
  111.         val = (((ULONG) sect_buf[i + 11]) << 24) | val;
  112.         part_tab[*count].fx_media_part_start = val + base_sect;
  113.         val =(ULONG) sect_buf[i + 12] ; /* little endian size value */
  114.         val = (((ULONG) sect_buf[i + 13]) << 8) | val;
  115.         val = (((ULONG) sect_buf[i + 14]) << 16) | val;
  116.         val = (((ULONG) sect_buf[i + 15]) << 24) | val;
  117.         part_tab[*count].fx_media_part_size = val;
  118.         
  119.         (*count)++;
  120.     }
  121.     return FX_SUCCESS;
  122. }
  123. /**************************************************************************/ 
  124. /*                                                                        */ 
  125. /*  FUNCTION                                               RELEASE        */ 
  126. /*                                                                        */ 
  127. /*    _fx_partition_offset_calculate                      PORTABLE C      */ 
  128. /*                                                           3.0          */ 
  129. /*  AUTHOR                                                                */ 
  130. /*                                                                        */ 
  131. /*    Mohammad N. Minhaz, Express Logic, Inc.                             */ 
  132. /*                                                                        */ 
  133. /*  DESCRIPTION                                                           */ 
  134. /*                                                                        */ 
  135. /*    This function calculates the sector offset to the specified         */ 
  136. /*    partition.  The buffer containing the partition table is also       */ 
  137. /*    supplied to this function.  If the buffer supplied is a boot        */ 
  138. /*    record (which could be the case in non-partition systems), this     */ 
  139. /*    function returns an offset of zero and a successful status          */ 
  140. /*    indicating that the buffer supplied is the boot record.  Otherwise, */ 
  141. /*    if the partition is found, this function returns the sector offset  */ 
  142. /*    to its boot record along with a successful status.  If the          */ 
  143. /*    specified partition is not found or the buffer is not a partition   */ 
  144. /*    table or boot record, this function returns an error.               */ 
  145. /*                                                                        */ 
  146. /*  INPUT                                                                 */ 
  147. /*                                                                        */ 
  148. /*    part_sector                           Pointer to buffer containing  */ 
  149. /*                                            either the partition table  */ 
  150. /*                                            or the boot sector          */ 
  151. /*    partition                             Desired partition             */ 
  152. /*    partition_sector_offset               Pointer to destination for    */ 
  153. /*                                            returning the sector offset */ 
  154. /*                                            table                       */ 
  155. /*                                                                        */ 
  156. /*  OUTPUT                                                                */ 
  157. /*                                                                        */ 
  158. /*    return status                                                       */ 
  159. /*                                                                        */ 
  160. /*  CALLS                                                                 */ 
  161. /*                                                                        */ 
  162. /*     _fx_utility_partition_get            Actual partition parsing      */ 
  163. /*                                            routine                     */ 
  164. /*                                                                        */ 
  165. /*  CALLED BY                                                             */ 
  166. /*                                                                        */ 
  167. /*    Application Driver                                                  */ 
  168. /*                                                                        */ 
  169. /*  RELEASE HISTORY                                                       */ 
  170. /*                                                                        */ 
  171. /*    DATE              NAME                      DESCRIPTION             */ 
  172. /*                                                                        */ 
  173. /*  07-04-2002     Mohammad N. Minhaz       Initial Version 1.0           */ 
  174. /*                                                                        */ 
  175. /**************************************************************************/ 
  176. UINT _fx_partition_offset_calculate( VOID  *part_sector,
  177.                                      UINT   partition,
  178.                                      ULONG *partition_start,
  179.                                      ULONG *partition_size )
  180. {
  181.     
  182.     FX_MEDIA_PART part_tab[4];
  183.     UINT count;
  184.     UCHAR *part_sect;
  185.     part_sect = part_sector;
  186.     count = 0;
  187.     if ((part_sect[510] != 0x55) || (part_sect[511] != 0xAA))
  188.         return FX_NOT_FOUND ; /* not a valid sector to work on */
  189.     if ((part_sect[0] == 0xe9) || ((part_sect[0] == 0xeb) && (part_sect[2] == 0x90)))    
  190.     {  /* a bootable sector */
  191.             *partition_start = 0;
  192.             return FX_SUCCESS;
  193.     }
  194.     
  195.     /* not bootable, look for partition */
  196.     _fx_utility_partition_get(part_tab, &count, 0, part_sect);
  197.     if (partition >= count)
  198.           return FX_NOT_FOUND;
  199.     if ( partition_start != NULL )
  200.     {
  201.         *partition_start = part_tab[partition].fx_media_part_start;
  202.     }
  203.     if ( partition_size != NULL )
  204.     {
  205.         *partition_size  = part_tab[partition].fx_media_part_size;
  206.     }
  207.     return(FX_SUCCESS);
  208. }
  209. #endif