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

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_fil.h"
  44. #include "PlaycoreFileSysFileXfx_uti.h"
  45. #include "PlaycoreFileSysFileXfx_dir.h"
  46. #ifndef FX_NO_LOCAL_PATH
  47. extern TX_THREAD *_tx_thread_current_ptr;
  48. #endif
  49. /**************************************************************************/ 
  50. /*                                                                        */ 
  51. /*  FUNCTION                                               RELEASE        */ 
  52. /*                                                                        */ 
  53. /*    _fx_directory_default_set                           PORTABLE C      */ 
  54. /*                                                           3.0          */ 
  55. /*  AUTHOR                                                                */ 
  56. /*                                                                        */ 
  57. /*    William E. Lamie, Express Logic, Inc.                               */ 
  58. /*                                                                        */ 
  59. /*  DESCRIPTION                                                           */ 
  60. /*                                                                        */ 
  61. /*    This function sets the default directory of the media to the path   */ 
  62. /*    specified by the caller.  If this path is not found, an error code  */ 
  63. /*    is returned.                                                        */ 
  64. /*                                                                        */ 
  65. /*  INPUT                                                                 */ 
  66. /*                                                                        */ 
  67. /*    media_ptr                             Media control block pointer   */ 
  68. /*    new_path_name                         New path to set current       */ 
  69. /*                                            working directory to        */ 
  70. /*                                                                        */ 
  71. /*  OUTPUT                                                                */ 
  72. /*                                                                        */ 
  73. /*    return status                                                       */ 
  74. /*                                                                        */ 
  75. /*  CALLS                                                                 */ 
  76. /*                                                                        */ 
  77. /*    _fx_directory_search                  Search for the directory name */ 
  78. /*                                          in the directory structure    */ 
  79. /*                                                                        */ 
  80. /*  CALLED BY                                                             */ 
  81. /*                                                                        */ 
  82. /*    Application Code                                                    */ 
  83. /*                                                                        */ 
  84. /*  RELEASE HISTORY                                                       */ 
  85. /*                                                                        */ 
  86. /*    DATE              NAME                      DESCRIPTION             */ 
  87. /*                                                                        */ 
  88. /*  01-01-1999     William E. Lamie         Initial Version 1.0           */ 
  89. /*  03-01-2000     William E. Lamie         Modified comment(s), and      */ 
  90. /*                                            added logic to save the     */ 
  91. /*                                            current path internally in  */ 
  92. /*                                            ASCII string format,        */ 
  93. /*                                            resulting in version 1.0b.  */ 
  94. /*  01-28-2001     William E. Lamie         Modified comment(s) and added */ 
  95. /*                                            logic to use new internal   */ 
  96. /*                                            path structure, resulting   */ 
  97. /*                                            in version 2.0.             */ 
  98. /*  03-01-2002     William E. Lamie         Modified comment(s),          */ 
  99. /*                                            resulting in version 3.0.   */ 
  100. /*                                                                        */ 
  101. /**************************************************************************/ 
  102. UINT  _fx_directory_default_set(FX_MEDIA *media_ptr, CHAR *new_path_name)
  103. {
  104. UINT            status;
  105. FX_DIR_ENTRY    dir_entry;
  106. CHAR            *path_string_ptr;
  107. UINT            path_string_capacity;
  108. FX_PATH         *path_ptr;
  109.     /* Check the media to make sure it is open.  */
  110.     if (media_ptr -> fx_media_id != FX_MEDIA_ID)
  111.     {
  112.         /* Return the media not opened error.  */
  113.         return(FX_MEDIA_NOT_OPEN);
  114.     }
  115.     /* Protect against other threads accessing the media.  */
  116.     FX_PROTECT
  117.     /* Look for a root directory selection.  */
  118.     if ((!new_path_name) || ((new_path_name[0] == '\') && (new_path_name[1] == (CHAR) 0)))
  119.     {
  120.         /* Set the media current working directory to the root.  */
  121.         media_ptr -> fx_media_default_path.fx_path_directory.fx_dir_entry_name[0] =  (CHAR) 0;
  122.         media_ptr -> fx_media_default_path.fx_path_string[0] =                       (CHAR) 0;
  123.         media_ptr -> fx_media_default_path.fx_path_string[FX_MAXIMUM_PATH-2] =       (CHAR) 0;
  124.     }
  125.     else
  126.     {
  127.         /* Search the system for the supplied path and directory name.  */
  128.         status =  _fx_directory_search(media_ptr, new_path_name, &dir_entry, FX_NULL, FX_NULL);
  129.         /* Determine if the search failed or if the entry found is not a 
  130.            directory.  */
  131.         if ((status != FX_SUCCESS) || (!(dir_entry.fx_dir_entry_attributes & FX_DIRECTORY)))
  132.         {
  133.             /* Release media protection.  */
  134.             FX_UNPROTECT
  135.             /* Invalid Path - Return the error code.  */
  136.             return(FX_INVALID_PATH);
  137.         }
  138.         /* Now update the current path string.  */
  139.         /* Setup the path string pointer to the start of the current path.  */
  140.         path_string_ptr =  &(media_ptr -> fx_media_default_path.fx_path_string[0]);
  141.         /* Setup the path string's capacity.  */
  142.         path_string_capacity =  FX_MAXIMUM_PATH - 1;
  143.         /* Determine if the new path is relative from the current path.  */
  144.         if (new_path_name[0] != '\')
  145.         {
  146.             /* Yes, a relative path was found.  */
  147.            
  148.             /* First check for a local path pointer stored in the thread control block.  
  149.                This is only available in ThreadX Version 4 and above.  */
  150. #ifndef FX_NO_LOCAL_PATH
  151.             if (_tx_thread_current_ptr -> tx_filex_ptr)
  152.             {
  153.                 /* Setup the default path pointer to the local path.  */
  154.                 path_ptr =  (FX_PATH *) _tx_thread_current_ptr -> tx_filex_ptr;
  155.             } 
  156.             else
  157.             {
  158.                 /* Setup the default path to the global media path.  */
  159.                 path_ptr =  &media_ptr -> fx_media_default_path;
  160.             }
  161. #else
  162.             /* Setup the default path to the global media path.  */
  163.             path_ptr =  &media_ptr -> fx_media_default_path;
  164. #endif
  165.             /* First, check the current path for string overflow.  If this is set, 
  166.                don't attempt to update the current path with relative information.  
  167.                The path won't be valid again until a complete path is given.  */
  168.             if (path_ptr -> fx_path_string[FX_MAXIMUM_PATH-2] == '*')
  169.             {
  170.                 /* Yes, don't update the string, just finish the path set processing.  */
  171.                 /* Determine if we are at the root directory.  */
  172.                 if (!dir_entry.fx_dir_entry_cluster)
  173.                 {
  174.                     /* Set the current directory back to the root directory.  */
  175.                     dir_entry.fx_dir_entry_name[0] =  (CHAR) 0;
  176.                     /* Clear the current path string.  */
  177.                     path_ptr -> fx_path_string[0] =  (CHAR) 0;
  178.                     /* Clear the overflow flag in the current path string... just in
  179.                        case! */
  180.                     path_ptr -> fx_path_string[FX_MAXIMUM_PATH-2] =  (CHAR) 0;
  181.                 }
  182.                 /* Copy the new directory entry into the media control block.  */
  183.                 path_ptr -> fx_path_directory =  dir_entry;
  184.                 /* Release media protection.  */
  185.                 FX_UNPROTECT
  186.                 /* Default directory set is complete, return status.  */
  187.                 return(FX_SUCCESS);
  188.             }
  189.             /* Move the current path starting pointer to the end of the current 
  190.                path string.  */
  191.             while ((*path_string_ptr != FX_NULL) && (path_string_capacity))
  192.             {
  193.                 path_string_ptr++;
  194.                 path_string_capacity--;
  195.             }
  196.             /* If room, place the  character in the path string.  */
  197.             if (path_string_capacity)
  198.             {
  199.                 /* There is room, place the directory marker in the string.  */
  200.                 *path_string_ptr++ =  '\';
  201.                 path_string_capacity--;
  202.             }
  203.         }
  204.         else
  205.         {
  206.             /* Setup the default path pointer.  */
  207.             /* First check for a local path pointer stored in the thread control block.  
  208.                This is only available in ThreadX Version 4 and above.  */
  209. #ifndef FX_NO_LOCAL_PATH
  210.             if (_tx_thread_current_ptr -> tx_filex_ptr)
  211.             {
  212.                 /* Setup the default path pointer to the local path.  */
  213.                 path_ptr =  (FX_PATH *) _tx_thread_current_ptr -> tx_filex_ptr;
  214.             } 
  215.             else
  216.             {
  217.                 /* Setup the default path to the global media path.  */
  218.                 path_ptr =  &media_ptr -> fx_media_default_path;
  219.             }
  220. #else
  221.             /* Setup the default path to the global media path.  */
  222.             path_ptr =  &media_ptr -> fx_media_default_path;
  223. #endif
  224.             /* Complete path name given.  Check to see if we need to clear an 
  225.                overflow character from a previous current path string update.  */
  226.             if (path_ptr -> fx_path_string[FX_MAXIMUM_PATH-2] == '*')
  227.                 path_ptr -> fx_path_string[FX_MAXIMUM_PATH-2] = (CHAR) 0;
  228.         }
  229.         /* Copy what we can into the current path.  */
  230.         while (*new_path_name)
  231.         {
  232.             /* Determine if there is a ".." character sequence that specifies the 
  233.                previous path.  */
  234.             if ((*new_path_name == '.') && (*(new_path_name+1) == '.'))
  235.             {
  236.                 /* Yes, a backward path is found.  The current path pointer
  237.                    must be moved back to just after the previous  character.  */
  238.                 /* Skip the current  that is at the end of the current path.  */
  239.                 path_string_capacity =  path_string_capacity + 2;
  240.                 path_string_ptr =       path_string_ptr - 2;
  241.                 while (path_string_capacity <= (FX_MAXIMUM_PATH-1))
  242.                 {
  243.                     /* Move the current path pointer backwards until
  244.                        a  character is found.  */
  245.                     
  246.                     if (*path_string_ptr == '\')
  247.                     {
  248.                         /* Yes, we have successfully backed up one directory.  */
  249.                         break;
  250.                     }
  251.                     /* Backup another character.  */
  252.                     path_string_capacity++;
  253.                     path_string_ptr--;
  254.                 }
  255.                 /* Adjust the new directory pointer past the .. characters  */
  256.                 new_path_name =  new_path_name + 2;
  257.             }
  258.             else 
  259.             {
  260.                 /* Normal characters that need to be copied into the current path.  */
  261.                 if (path_string_capacity)
  262.                 {
  263.                 
  264.                     /* Copy character from the new path into the current path string.  */
  265.                     *path_string_ptr++ =  *new_path_name++;
  266.                     path_string_capacity--;
  267.                 }
  268.                 else
  269.                 {
  270.                     /* No more room in the current path string!  */
  271.                     break;
  272.                 }
  273.             }
  274.         }
  275.         /* Determine if there is still room in the current path string.  */
  276.         if (path_string_capacity)
  277.         {
  278.             /* Yes, there is still room, place a NULL character at the 
  279.                end of the path.  */
  280.             *path_string_ptr =  (CHAR) FX_NULL;
  281.         }
  282.         else
  283.         {
  284.             /* No more room.  Determine if the entire path was successfully
  285.                copied into the current path.  */
  286.             if (*new_path_name)
  287.             {
  288.                 /* No, we couldn't fit the entire path.  Place a "*" character
  289.                    at the end to indicate that we had overflow.  Note that 
  290.                    the path is kept just the the directory defaut get call, so
  291.                    the new default path is valid.  */
  292.                 path_ptr -> fx_path_string[FX_MAXIMUM_PATH-2] =  '*';
  293.             }
  294.         }
  295.         /* Determine if we are at the root directory.  */
  296.         if (!dir_entry.fx_dir_entry_cluster)
  297.         {
  298.             /* Set the current directory back to the root directory.  */
  299.             dir_entry.fx_dir_entry_name[0] =  (CHAR) 0;
  300.         }
  301.         /* Copy the new directory entry into the media control block.  */
  302.         path_ptr -> fx_path_directory =  dir_entry;
  303.     }
  304.     /* Release media protection.  */
  305.     FX_UNPROTECT
  306.     /* Default directory set is complete, return status.  */
  307.     return(FX_SUCCESS);
  308. }
  309. #endif