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

DVD

开发平台:

Others

  1. /**************************************************************************/ 
  2. /*                                                                        */ 
  3. /*            Copyright (c) 2003 by Zoran                                 */ 
  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 Zoran  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 Zoran                                              */ 
  14. /*                                                                        */ 
  15. /*  Zoran reserves the right to modify this software         */ 
  16. /*  without notice.                                                       */ 
  17. /*                                                                        */ 
  18. /*                                                                        */
  19. /**************************************************************************/
  20. /**************************************************************************/
  21. /**************************************************************************/
  22. /**                                                                       */ 
  23. /** FileX Component                                                       */ 
  24. /**                                                                       */
  25. /**   Directory (DIR)                                                     */
  26. /**                                                                       */
  27. /**************************************************************************/
  28. /**************************************************************************/
  29. #include "Config.h" // Global Configuration - do not remove!
  30. #ifdef ENABLE_FILEX
  31. #ifdef _DEBUG
  32. #undef IFTRACE
  33. #define IFTRACE if (gTraceFileSys)
  34. #include "DebugDbgMain.h"
  35. #endif //_DEBUG
  36. #define FX_SOURCE_CODE
  37. /* Include necessary system files.  */
  38. #include "PlaycoreFileSysFileXfx_api.h"
  39. #include "PlaycoreFileSysFileXfx_dir.h"
  40. #include "PlaycoreFileSysFileXfx_uti.h"
  41. #ifndef TX_NO_LOCAL_PATH
  42. extern TX_THREAD *_tx_thread_current_ptr;
  43. #endif
  44. /**************************************************************************/ 
  45. /*                                                                        */ 
  46. /*  FUNCTION                                               RELEASE        */ 
  47. /*                                                                        */ 
  48. /*    _fx_directory_next_entry_find_new                   PORTABLE C      */ 
  49. /*                                                           3.0          */ 
  50. /*  AUTHOR                                                                */ 
  51. /*                                                                        */ 
  52. /*    Brizguine Alexei, Zoran                                              */ 
  53. /*                                                                        */ 
  54. /*  DESCRIPTION                                                           */ 
  55. /*                                                                        */ 
  56. /*    This function returns the name of the next entry in the current     */ 
  57. /*    working directory.  The function that returns the first name in the */ 
  58. /*    current directory must be called prior to this function.            */ 
  59. /*                                                                        */ 
  60. /*  INPUT                                                                 */ 
  61. /*                                                                        */ 
  62. /*    media_ptr                             Media control block pointer   */ 
  63. /*    dir_ptr                               Destination for directory     */ 
  64. /*                                            parameters                  */ 
  65. /*                                                                        */ 
  66. /*  OUTPUT                                                                */ 
  67. /*                                                                        */ 
  68. /*    return status                                                       */ 
  69. /*                                                                        */ 
  70. /*  CALLS                                                                 */ 
  71. /*                                                                        */ 
  72. /*    _fx_directory_entry_read              Read entries from root dir    */ 
  73. /*    _fx_utlity_FAT_entry_read             Read FAT entries to calculate */ 
  74. /*                                            the sub-directory size      */ 
  75. /*                                                                        */ 
  76. /*  CALLED BY                                                             */ 
  77. /*                                                                        */ 
  78. /*    Application Code and                                                */ 
  79. /*    FileX System Functions                                              */ 
  80. /*                                                                        */ 
  81. /*  RELEASE HISTORY                                                       */ 
  82. /*                                                                        */ 
  83. /*    DATE              NAME                      DESCRIPTION             */ 
  84. /*                                                                        */ 
  85. /*  29-05-2003     Brizguine Alexei         Modified comment(s),          */ 
  86. /*                                            changed to 32 bit variables,*/ 
  87. /*                                            fixed possible infinite loop*/ 
  88. /*                                            caused by FAT corruption,   */ 
  89. /*                                            and fixed status corruption,*/ 
  90. /*                                            resulting in version 3.0.   */ 
  91. /*                                                                        */ 
  92. /**************************************************************************/ 
  93. UINT   _fx_directory_next_entry_find_new(FX_MEDIA *media_ptr, FX_DIR_ENTRY* entry)
  94. {
  95. ULONG           i;
  96. UINT            status;
  97. UINT            temp_status;
  98. ULONG           cluster, next_cluster;
  99. ULONG           directory_size;
  100. //FX_DIR_ENTRY    entry;
  101. FX_DIR_ENTRY    *search_dir_ptr;
  102. FX_PATH         *path_ptr;
  103. ULONG           fat_reserved;
  104.     /* Check the media to make sure it is open.  */
  105.     if (media_ptr -> fx_media_id != FX_MEDIA_ID)
  106.     {
  107.         /* Return the media not opened error.  */
  108.         return(FX_MEDIA_NOT_OPEN);
  109.     }
  110.     /* Determine the type of FAT and setup variables accordingly.  */
  111.     if (media_ptr -> fx_media_32_bit_FAT) fat_reserved = FX_RESERVED_1_32;
  112.     else fat_reserved = FX_RESERVED_1;
  113.     /* Protect against other threads accessing the media.  */
  114.     FX_PROTECT
  115.     /* First check for a local path pointer stored in the thread control block.  This
  116.        is only available in ThreadX Version 4 and above.  */
  117. #ifndef FX_NO_LOCAL_PATH
  118.     if (_tx_thread_current_ptr -> tx_filex_ptr)
  119.     {
  120.         /* Setup the default path pointer.  */
  121.         path_ptr =  (FX_PATH *) _tx_thread_current_ptr -> tx_filex_ptr;
  122.         /* Determine if we are at the root directory.  */
  123.         if (path_ptr -> fx_path_directory.fx_dir_entry_name[0])
  124.         {
  125.             /* No, we are not at the root directory.  */
  126.             
  127.             /* Set the internal pointer to the search directory as well.  */
  128.             search_dir_ptr =  &path_ptr -> fx_path_directory;
  129.         }
  130.         else
  131.         {
  132.             /* The current default directory is the root so just set the
  133.                search directory pointer to NULL.  */
  134.             search_dir_ptr =  FX_NULL;
  135.         }
  136.     } else
  137. #endif
  138.     /* Set the initial search directory to the current working 
  139.        directory - if there is one.  */
  140.     if (media_ptr -> fx_media_default_path.fx_path_directory.fx_dir_entry_name[0])
  141.     {
  142.         
  143.         /* Setup the path pointer to the global media path.  */
  144.         path_ptr =  &media_ptr -> fx_media_default_path;
  145.             
  146.         /* Set the internal pointer to the search directory as well.  */
  147.         search_dir_ptr =  &path_ptr -> fx_path_directory;
  148.     }
  149.     else
  150.     {
  151.         /* Setup the path pointer to the global media path.  */
  152.         path_ptr =  &media_ptr -> fx_media_default_path;
  153.         /* The current default directory is the root so just set the
  154.            search directory pointer to NULL.  */
  155.         search_dir_ptr =  FX_NULL;
  156.     }
  157.     /* Calculate the directory size.  */
  158.     if (search_dir_ptr)
  159.     {
  160.         /* Calculate the directory size by counting the allocated
  161.            clusters for it.  */
  162.         if (media_ptr -> fx_media_default_path.fx_path_current_entry !=  0)
  163.             directory_size = search_dir_ptr->fx_dir_entry_file_size ;
  164.         else
  165.         {
  166.             i =        0;
  167.             cluster =  search_dir_ptr -> fx_dir_entry_cluster;
  168.             while ((cluster >= FX_FAT_ENTRY_START) && (cluster < fat_reserved))
  169.             {
  170.                 /* Increment the cluster count.  */
  171.                 i++;
  172.                 /* Read the next FAT entry.  */
  173.                 status =  _fx_utility_FAT_entry_read(media_ptr, cluster, &next_cluster);
  174.                 /* Check the return status.  */
  175.                 if (status != FX_SUCCESS)
  176.                 {
  177.                     /* Release media protection.  */
  178.                     FX_UNPROTECT
  179.                     /* Return the bad status.  */
  180.                     return(status);
  181.                 }                
  182.                 if ((cluster == next_cluster) || (i > media_ptr -> fx_media_total_clusters)) 
  183.                 {
  184.                     /* Release media protection.  */
  185.                     FX_UNPROTECT
  186.                     /* Return the bad status.  */
  187.                     return(FX_FAT_READ_ERROR);
  188.                 }
  189.                 cluster = next_cluster;
  190.             }
  191.             /* Now we can calculate the directory size.  */
  192.             directory_size =  (((ULONG) media_ptr -> fx_media_bytes_per_sector) *
  193.                                    ((ULONG) media_ptr -> fx_media_sectors_per_cluster) * i)
  194.                                     / (ULONG) FX_DIR_ENTRY_SIZE;
  195.             search_dir_ptr->fx_dir_entry_file_size = directory_size ;
  196.         }
  197.     }
  198.     else
  199.     {
  200.         /* Directory size is the number of entries in the root directory.  */
  201.         directory_size =  (ULONG) media_ptr -> fx_media_root_directory_entries;
  202.     }
  203.     /* Preset status with an error return.  */
  204.     status =  FX_NO_MORE_ENTRIES;
  205.     /* Determine if the current entry is inside of the directory's range.  */
  206.     while (path_ptr -> fx_path_current_entry < directory_size)
  207.     {
  208.         /* Read an entry from the directory.  */
  209.         temp_status =  _fx_directory_entry_read(media_ptr, search_dir_ptr, 
  210.                                     &(path_ptr -> fx_path_current_entry), entry);
  211.         /* Check for error status.  */
  212.         if (temp_status != FX_SUCCESS)
  213.         {
  214.             /* Release media protection.  */
  215.             FX_UNPROTECT
  216.             /* Return error status.  */
  217.             return(status);
  218.         }
  219.         /* Check to see if the entry has something in it.  */
  220.         if (entry->fx_dir_entry_name[0] == (CHAR) FX_DIR_ENTRY_FREE)
  221.         {
  222.             /* Current entry is free, skip to next entry and continue the loop.  */
  223.             path_ptr -> fx_path_current_entry++;
  224.             continue;
  225.         }
  226. //JERRYC_2004AUG25        else if (entry->fx_dir_entry_name[0] != (CHAR) FX_DIR_ENTRY_DONE)
  227.         else if (entry->fx_dir_entry_name[0] != (CHAR) FX_DIR_ENTRY_DONE || 0 == path_ptr -> fx_path_current_entry)
  228.         {
  229.             /* A valid directory entry is present.  */
  230.             /* Copy the name into the destination.  */
  231. /*            for (i = 0; entry.fx_dir_entry_name[i]; i++)
  232.             {
  233.                 
  234.                 *directory_name = entry.fx_dir_entry_name[i];
  235.                 directory_name++;
  236.             }
  237.             *directory_name =  (CHAR) 0;
  238. */
  239.             /* Increment the current entry for the media.  */
  240.             path_ptr -> fx_path_current_entry++;
  241.             /* Set return status to success.  */
  242.             status =  FX_SUCCESS;
  243.             /* Get out of the loop.  */
  244.             break;
  245.         }
  246.         else 
  247.         {
  248.             /* Set the error code.  */
  249.             status =  FX_NO_MORE_ENTRIES;
  250.             /* Get out of the loop.  */
  251.             break;
  252.         }
  253.     }
  254.     /* Release media protection.  */
  255.     FX_UNPROTECT
  256.     /* Return status to the caller.  */
  257.     return(status);
  258. }
  259. #endif