FX_DDS.C
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:16k
- /**************************************************************************/
- /* */
- /* Copyright (c) 1996-2002 by Express Logic Inc. */
- /* */
- /* This software is copyrighted by and is the sole property of Express */
- /* Logic, Inc. All rights, title, ownership, or other interests */
- /* in the software remain the property of Express Logic, Inc. This */
- /* software may only be used in accordance with the corresponding */
- /* license agreement. Any unauthorized use, duplication, transmission, */
- /* distribution, or disclosure of this software is expressly forbidden. */
- /* */
- /* This Copyright notice may not be removed or modified without prior */
- /* written consent of Express Logic, Inc. */
- /* */
- /* Express Logic, Inc. reserves the right to modify this software */
- /* without notice. */
- /* */
- /* Express Logic, Inc. info@expresslogic.com */
- /* 11423 West Bernardo Court http://www.expresslogic.com */
- /* San Diego, CA 92127 */
- /* */
- /**************************************************************************/
- /**************************************************************************/
- /**************************************************************************/
- /** */
- /** FileX Component */
- /** */
- /** Directory (DIR) */
- /** */
- /**************************************************************************/
- /**************************************************************************/
- #include "Config.h" // Global Configuration - do not remove!
- #ifdef ENABLE_FILEX
- #ifdef _DEBUG
- #undef IFTRACE
- #define IFTRACE if (gTraceFileSys)
- #include "DebugDbgMain.h"
- #endif //_DEBUG
- #define FX_SOURCE_CODE
- /* Include necessary system files. */
- #include "PlaycoreFileSysFileXfx_api.h"
- #include "PlaycoreFileSysFileXfx_sys.h"
- #include "PlaycoreFileSysFileXfx_fil.h"
- #include "PlaycoreFileSysFileXfx_uti.h"
- #include "PlaycoreFileSysFileXfx_dir.h"
- #ifndef FX_NO_LOCAL_PATH
- extern TX_THREAD *_tx_thread_current_ptr;
- #endif
- /**************************************************************************/
- /* */
- /* FUNCTION RELEASE */
- /* */
- /* _fx_directory_default_set PORTABLE C */
- /* 3.0 */
- /* AUTHOR */
- /* */
- /* William E. Lamie, Express Logic, Inc. */
- /* */
- /* DESCRIPTION */
- /* */
- /* This function sets the default directory of the media to the path */
- /* specified by the caller. If this path is not found, an error code */
- /* is returned. */
- /* */
- /* INPUT */
- /* */
- /* media_ptr Media control block pointer */
- /* new_path_name New path to set current */
- /* working directory to */
- /* */
- /* OUTPUT */
- /* */
- /* return status */
- /* */
- /* CALLS */
- /* */
- /* _fx_directory_search Search for the directory name */
- /* in the directory structure */
- /* */
- /* CALLED BY */
- /* */
- /* Application Code */
- /* */
- /* RELEASE HISTORY */
- /* */
- /* DATE NAME DESCRIPTION */
- /* */
- /* 01-01-1999 William E. Lamie Initial Version 1.0 */
- /* 03-01-2000 William E. Lamie Modified comment(s), and */
- /* added logic to save the */
- /* current path internally in */
- /* ASCII string format, */
- /* resulting in version 1.0b. */
- /* 01-28-2001 William E. Lamie Modified comment(s) and added */
- /* logic to use new internal */
- /* path structure, resulting */
- /* in version 2.0. */
- /* 03-01-2002 William E. Lamie Modified comment(s), */
- /* resulting in version 3.0. */
- /* */
- /**************************************************************************/
- UINT _fx_directory_default_set(FX_MEDIA *media_ptr, CHAR *new_path_name)
- {
- UINT status;
- FX_DIR_ENTRY dir_entry;
- CHAR *path_string_ptr;
- UINT path_string_capacity;
- FX_PATH *path_ptr;
- /* Check the media to make sure it is open. */
- if (media_ptr -> fx_media_id != FX_MEDIA_ID)
- {
- /* Return the media not opened error. */
- return(FX_MEDIA_NOT_OPEN);
- }
- /* Protect against other threads accessing the media. */
- FX_PROTECT
- /* Look for a root directory selection. */
- if ((!new_path_name) || ((new_path_name[0] == '\') && (new_path_name[1] == (CHAR) 0)))
- {
- /* Set the media current working directory to the root. */
- media_ptr -> fx_media_default_path.fx_path_directory.fx_dir_entry_name[0] = (CHAR) 0;
- media_ptr -> fx_media_default_path.fx_path_string[0] = (CHAR) 0;
- media_ptr -> fx_media_default_path.fx_path_string[FX_MAXIMUM_PATH-2] = (CHAR) 0;
- }
- else
- {
- /* Search the system for the supplied path and directory name. */
- status = _fx_directory_search(media_ptr, new_path_name, &dir_entry, FX_NULL, FX_NULL);
- /* Determine if the search failed or if the entry found is not a
- directory. */
- if ((status != FX_SUCCESS) || (!(dir_entry.fx_dir_entry_attributes & FX_DIRECTORY)))
- {
- /* Release media protection. */
- FX_UNPROTECT
- /* Invalid Path - Return the error code. */
- return(FX_INVALID_PATH);
- }
- /* Now update the current path string. */
- /* Setup the path string pointer to the start of the current path. */
- path_string_ptr = &(media_ptr -> fx_media_default_path.fx_path_string[0]);
- /* Setup the path string's capacity. */
- path_string_capacity = FX_MAXIMUM_PATH - 1;
- /* Determine if the new path is relative from the current path. */
- if (new_path_name[0] != '\')
- {
- /* Yes, a relative path was found. */
-
- /* First check for a local path pointer stored in the thread control block.
- This is only available in ThreadX Version 4 and above. */
- #ifndef FX_NO_LOCAL_PATH
- if (_tx_thread_current_ptr -> tx_filex_ptr)
- {
- /* Setup the default path pointer to the local path. */
- path_ptr = (FX_PATH *) _tx_thread_current_ptr -> tx_filex_ptr;
- }
- else
- {
- /* Setup the default path to the global media path. */
- path_ptr = &media_ptr -> fx_media_default_path;
- }
- #else
- /* Setup the default path to the global media path. */
- path_ptr = &media_ptr -> fx_media_default_path;
- #endif
- /* First, check the current path for string overflow. If this is set,
- don't attempt to update the current path with relative information.
- The path won't be valid again until a complete path is given. */
- if (path_ptr -> fx_path_string[FX_MAXIMUM_PATH-2] == '*')
- {
- /* Yes, don't update the string, just finish the path set processing. */
- /* Determine if we are at the root directory. */
- if (!dir_entry.fx_dir_entry_cluster)
- {
- /* Set the current directory back to the root directory. */
- dir_entry.fx_dir_entry_name[0] = (CHAR) 0;
- /* Clear the current path string. */
- path_ptr -> fx_path_string[0] = (CHAR) 0;
- /* Clear the overflow flag in the current path string... just in
- case! */
- path_ptr -> fx_path_string[FX_MAXIMUM_PATH-2] = (CHAR) 0;
- }
- /* Copy the new directory entry into the media control block. */
- path_ptr -> fx_path_directory = dir_entry;
- /* Release media protection. */
- FX_UNPROTECT
- /* Default directory set is complete, return status. */
- return(FX_SUCCESS);
- }
- /* Move the current path starting pointer to the end of the current
- path string. */
- while ((*path_string_ptr != FX_NULL) && (path_string_capacity))
- {
- path_string_ptr++;
- path_string_capacity--;
- }
- /* If room, place the character in the path string. */
- if (path_string_capacity)
- {
- /* There is room, place the directory marker in the string. */
- *path_string_ptr++ = '\';
- path_string_capacity--;
- }
- }
- else
- {
- /* Setup the default path pointer. */
- /* First check for a local path pointer stored in the thread control block.
- This is only available in ThreadX Version 4 and above. */
- #ifndef FX_NO_LOCAL_PATH
- if (_tx_thread_current_ptr -> tx_filex_ptr)
- {
- /* Setup the default path pointer to the local path. */
- path_ptr = (FX_PATH *) _tx_thread_current_ptr -> tx_filex_ptr;
- }
- else
- {
- /* Setup the default path to the global media path. */
- path_ptr = &media_ptr -> fx_media_default_path;
- }
- #else
- /* Setup the default path to the global media path. */
- path_ptr = &media_ptr -> fx_media_default_path;
- #endif
- /* Complete path name given. Check to see if we need to clear an
- overflow character from a previous current path string update. */
- if (path_ptr -> fx_path_string[FX_MAXIMUM_PATH-2] == '*')
- path_ptr -> fx_path_string[FX_MAXIMUM_PATH-2] = (CHAR) 0;
- }
- /* Copy what we can into the current path. */
- while (*new_path_name)
- {
- /* Determine if there is a ".." character sequence that specifies the
- previous path. */
- if ((*new_path_name == '.') && (*(new_path_name+1) == '.'))
- {
- /* Yes, a backward path is found. The current path pointer
- must be moved back to just after the previous character. */
- /* Skip the current