Fx_dnefn.c
上传用户:super_houu
上传日期:2008-09-21
资源大小:4099k
文件大小:13k
- /**************************************************************************/
- /* */
- /* Copyright (c) 2003 by Zoran */
- /* */
- /* 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 Zoran 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 Zoran */
- /* */
- /* Zoran reserves the right to modify this software */
- /* without notice. */
- /* */
- /* */
- /**************************************************************************/
- /**************************************************************************/
- /**************************************************************************/
- /** */
- /** 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_dir.h"
- #include "PlaycoreFileSysFileXfx_uti.h"
- #ifndef TX_NO_LOCAL_PATH
- extern TX_THREAD *_tx_thread_current_ptr;
- #endif
- /**************************************************************************/
- /* */
- /* FUNCTION RELEASE */
- /* */
- /* _fx_directory_next_entry_find_new PORTABLE C */
- /* 3.0 */
- /* AUTHOR */
- /* */
- /* Brizguine Alexei, Zoran */
- /* */
- /* DESCRIPTION */
- /* */
- /* This function returns the name of the next entry in the current */
- /* working directory. The function that returns the first name in the */
- /* current directory must be called prior to this function. */
- /* */
- /* INPUT */
- /* */
- /* media_ptr Media control block pointer */
- /* dir_ptr Destination for directory */
- /* parameters */
- /* */
- /* OUTPUT */
- /* */
- /* return status */
- /* */
- /* CALLS */
- /* */
- /* _fx_directory_entry_read Read entries from root dir */
- /* _fx_utlity_FAT_entry_read Read FAT entries to calculate */
- /* the sub-directory size */
- /* */
- /* CALLED BY */
- /* */
- /* Application Code and */
- /* FileX System Functions */
- /* */
- /* RELEASE HISTORY */
- /* */
- /* DATE NAME DESCRIPTION */
- /* */
- /* 29-05-2003 Brizguine Alexei Modified comment(s), */
- /* changed to 32 bit variables,*/
- /* fixed possible infinite loop*/
- /* caused by FAT corruption, */
- /* and fixed status corruption,*/
- /* resulting in version 3.0. */
- /* */
- /**************************************************************************/
- UINT _fx_directory_next_entry_find_new(FX_MEDIA *media_ptr, FX_DIR_ENTRY* entry)
- {
- ULONG i;
- UINT status;
- UINT temp_status;
- ULONG cluster, next_cluster;
- ULONG directory_size;
- //FX_DIR_ENTRY entry;
- FX_DIR_ENTRY *search_dir_ptr;
- FX_PATH *path_ptr;
- ULONG fat_reserved;
- /* 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);
- }
- /* Determine the type of FAT and setup variables accordingly. */
- if (media_ptr -> fx_media_32_bit_FAT) fat_reserved = FX_RESERVED_1_32;
- else fat_reserved = FX_RESERVED_1;
- /* Protect against other threads accessing the media. */
- FX_PROTECT
- /* 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. */
- path_ptr = (FX_PATH *) _tx_thread_current_ptr -> tx_filex_ptr;
- /* Determine if we are at the root directory. */
- if (path_ptr -> fx_path_directory.fx_dir_entry_name[0])
- {
- /* No, we are not at the root directory. */
-
- /* Set the internal pointer to the search directory as well. */
- search_dir_ptr = &path_ptr -> fx_path_directory;
- }
- else
- {
- /* The current default directory is the root so just set the
- search directory pointer to NULL. */
- search_dir_ptr = FX_NULL;
- }
- } else
- #endif
- /* Set the initial search directory to the current working
- directory - if there is one. */
- if (media_ptr -> fx_media_default_path.fx_path_directory.fx_dir_entry_name[0])
- {
-
- /* Setup the path pointer to the global media path. */
- path_ptr = &media_ptr -> fx_media_default_path;
-
- /* Set the internal pointer to the search directory as well. */
- search_dir_ptr = &path_ptr -> fx_path_directory;
- }
- else
- {
- /* Setup the path pointer to the global media path. */
- path_ptr = &media_ptr -> fx_media_default_path;
- /* The current default directory is the root so just set the
- search directory pointer to NULL. */
- search_dir_ptr = FX_NULL;
- }
- /* Calculate the directory size. */
- if (search_dir_ptr)
- {
- /* Calculate the directory size by counting the allocated
- clusters for it. */
- if (media_ptr -> fx_media_default_path.fx_path_current_entry != 0)
- directory_size = search_dir_ptr->fx_dir_entry_file_size ;
- else
- {
- i = 0;
- cluster = search_dir_ptr -> fx_dir_entry_cluster;
- while ((cluster >= FX_FAT_ENTRY_START) && (cluster < fat_reserved))
- {
- /* Increment the cluster count. */
- i++;
- /* Read the next FAT entry. */
- status = _fx_utility_FAT_entry_read(media_ptr, cluster, &next_cluster);
- /* Check the return status. */
- if (status != FX_SUCCESS)
- {
- /* Release media protection. */
- FX_UNPROTECT
- /* Return the bad status. */
- return(status);
- }
- if ((cluster == next_cluster) || (i > media_ptr -> fx_media_total_clusters))
- {
- /* Release media protection. */
- FX_UNPROTECT
- /* Return the bad status. */
- return(FX_FAT_READ_ERROR);
- }
- cluster = next_cluster;
- }
- /* Now we can calculate the directory size. */
- directory_size = (((ULONG) media_ptr -> fx_media_bytes_per_sector) *
- ((ULONG) media_ptr -> fx_media_sectors_per_cluster) * i)
- / (ULONG) FX_DIR_ENTRY_SIZE;
- search_dir_ptr->fx_dir_entry_file_size = directory_size ;
- }
- }
- else
- {
- /* Directory size is the number of entries in the root directory. */
- directory_size = (ULONG) media_ptr -> fx_media_root_directory_entries;
- }
- /* Preset status with an error return. */
- status = FX_NO_MORE_ENTRIES;
- /* Determine if the current entry is inside of the directory's range. */
- while (path_ptr -> fx_path_current_entry < directory_size)
- {
- /* Read an entry from the directory. */
- temp_status = _fx_directory_entry_read(media_ptr, search_dir_ptr,
- &(path_ptr -> fx_path_current_entry), entry);
- /* Check for error status. */
- if (temp_status != FX_SUCCESS)
- {
- /* Release media protection. */
- FX_UNPROTECT
- /* Return error status. */
- return(status);
- }
- /* Check to see if the entry has something in it. */
- if (entry->fx_dir_entry_name[0] == (CHAR) FX_DIR_ENTRY_FREE)
- {
- /* Current entry is free, skip to next entry and continue the loop. */
- path_ptr -> fx_path_current_entry++;
- continue;
- }
- //JERRYC_2004AUG25 else if (entry->fx_dir_entry_name[0] != (CHAR) FX_DIR_ENTRY_DONE)
- else if (entry->fx_dir_entry_name[0] != (CHAR) FX_DIR_ENTRY_DONE || 0 == path_ptr -> fx_path_current_entry)
- {
- /* A valid directory entry is present. */
- /* Copy the name into the destination. */
- /* for (i = 0; entry.fx_dir_entry_name[i]; i++)
- {
-
- *directory_name = entry.fx_dir_entry_name[i];
- directory_name++;
- }
- *directory_name = (CHAR) 0;
- */
- /* Increment the current entry for the media. */
- path_ptr -> fx_path_current_entry++;
- /* Set return status to success. */
- status = FX_SUCCESS;
- /* Get out of the loop. */
- break;
- }
- else
- {
- /* Set the error code. */
- status = FX_NO_MORE_ENTRIES;
- /* Get out of the loop. */
- break;
- }
- }
- /* Release media protection. */
- FX_UNPROTECT
- /* Return status to the caller. */
- return(status);
- }
- #endif