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