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

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. /**   File (FIL)                                                          */
  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. /**************************************************************************/ 
  47. /*                                                                        */ 
  48. /*  FUNCTION                                               RELEASE        */ 
  49. /*                                                                        */ 
  50. /*    _fx_file_close                                      PORTABLE C      */ 
  51. /*                                                           3.0          */ 
  52. /*  AUTHOR                                                                */ 
  53. /*                                                                        */ 
  54. /*    William E. Lamie, Express Logic, Inc.                               */ 
  55. /*                                                                        */ 
  56. /*  DESCRIPTION                                                           */ 
  57. /*                                                                        */ 
  58. /*    This function closes the specified file.  If the file was written   */ 
  59. /*    to this function will also write the directory entry (with the new  */ 
  60. /*    size and time/date stamp) out to disk.                              */ 
  61. /*                                                                        */ 
  62. /*  INPUT                                                                 */ 
  63. /*                                                                        */ 
  64. /*    file_ptr                              File control block pointer    */ 
  65. /*                                                                        */ 
  66. /*  OUTPUT                                                                */ 
  67. /*                                                                        */ 
  68. /*    return status                                                       */ 
  69. /*                                                                        */ 
  70. /*  CALLS                                                                 */ 
  71. /*                                                                        */ 
  72. /*    _fx_directory_entry_write             Write the directory entry     */ 
  73. /*    _fx_utility_log_sector_flush          Flush the written log sector  */ 
  74. /*                                                                        */ 
  75. /*  CALLED BY                                                             */ 
  76. /*                                                                        */ 
  77. /*    Application Code                                                    */ 
  78. /*                                                                        */ 
  79. /*  RELEASE HISTORY                                                       */ 
  80. /*                                                                        */ 
  81. /*    DATE              NAME                      DESCRIPTION             */ 
  82. /*                                                                        */ 
  83. /*  01-01-1999     William E. Lamie         Initial Version 1.0           */ 
  84. /*  03-01-2000     William E. Lamie         Modified comment(s),          */ 
  85. /*                                            resulting in version 1.0b.  */ 
  86. /*  01-28-2001     William E. Lamie         Modified comment(s),          */ 
  87. /*                                            resulting in version 2.0.   */ 
  88. /*  03-01-2002     William E. Lamie         Modified comment(s),          */ 
  89. /*                                            resulting in version 3.0.   */ 
  90. /*                                                                        */ 
  91. /**************************************************************************/ 
  92. UINT  _fx_file_close(FX_FILE *file_ptr)
  93. {
  94. UINT            status;
  95. FX_MEDIA        *media_ptr;
  96. FX_INT_SAVE_AREA
  97.     /* First, determine if the file is still open.  */
  98.     if (file_ptr -> fx_file_id != FX_FILE_ID)
  99.     {
  100.         /* Return the file not open error status.  */
  101.         return(FX_NOT_OPEN);
  102.     }
  103.     /* Setup a pointer to the associated media.  */
  104.     media_ptr =  file_ptr -> fx_file_media_ptr;
  105.     /* Protect against other threads accessing the media.  */
  106.     FX_PROTECT
  107. #if 0  // Alexei Brizguine. Never using FX_OPEN_FOR_WRITE flag
  108.     /* Check to see if this file needs to have it's directory entry written
  109.        back to the media.  */
  110.     if ((file_ptr -> fx_file_open_mode == FX_OPEN_FOR_WRITE) &&
  111.         (file_ptr -> fx_file_modified))
  112.     {
  113.         /* Lockout interrupts for time/date access.  */
  114.         FX_DISABLE_INTS
  115.         /* Set the new time and date.  */
  116.         file_ptr -> fx_file_dir_entry.fx_dir_entry_time =  _fx_system_time;
  117.         file_ptr -> fx_file_dir_entry.fx_dir_entry_date =  _fx_system_date;
  118.         /* Restore interrupts.  */
  119.         FX_RESTORE_INTS
  120.         /* Copy the new file size into the directory entry.  */
  121.         file_ptr -> fx_file_dir_entry.fx_dir_entry_file_size =
  122.                                         file_ptr -> fx_file_current_file_size;
  123.         /* Write the directory entry to the media.  */
  124.         status =  _fx_directory_entry_write(media_ptr, &(file_ptr -> fx_file_dir_entry));
  125.         /* Check for a good status.  */
  126.         if (status != FX_SUCCESS)
  127.         {
  128.             /* Release media protection.  */
  129.             FX_UNPROTECT
  130.             /* Error writing the directory.  */
  131.             return(status);
  132.         }
  133.     }
  134. #endif
  135. #if 0 // Jerry cai, don't maintain any list.
  136.     /* Remove this file from the opened list for the media.  */
  137.     /* See if the file is the only one on the open list for this media.  */
  138.     if (file_ptr == file_ptr -> fx_file_opened_next)
  139.     {
  140.         /* Only opened file, just set the opened list to NULL.  */
  141.         media_ptr -> fx_media_opened_file_list =  FX_NULL;
  142.     }
  143.     else
  144.     {
  145.         /* Otherwise, not the only opened file, link-up the neighbors.  */
  146.         (file_ptr -> fx_file_opened_next) -> fx_file_opened_previous =
  147.                                             file_ptr -> fx_file_opened_previous;
  148.         (file_ptr -> fx_file_opened_previous) -> fx_file_opened_next =
  149.                                             file_ptr -> fx_file_opened_next;
  150.         /* See if we have to update the opened list head pointer.  */
  151.         if (media_ptr -> fx_media_opened_file_list == file_ptr)
  152.             
  153.             /* Yes, move the head pointer to the next opened file. */
  154.             media_ptr -> fx_media_opened_file_list =  file_ptr -> fx_file_opened_next; 
  155.     }
  156.     /* Decrement the opened file counter.  */
  157.     media_ptr -> fx_media_opened_file_count--;
  158. #endif
  159.     /* Finally, Indicate that this file is closed.  */
  160.     file_ptr -> fx_file_id =  FX_FILE_CLOSED_ID;
  161. #if 0  // Alexei Brizguine. Never using FX_OPEN_FOR_WRITE flag
  162.     /* Flush the internal logical sector.  */
  163.     status =  _fx_utility_log_sector_flush(media_ptr);
  164. #endif
  165.     /* Release media protection.  */
  166.     FX_UNPROTECT
  167.     /* Return status to the caller.  */
  168.     return(status);
  169. }
  170. #endif