📄 filesys.c
字号:
/************************************************** * * filesys.c * * CVS ID: $Id: * Author: Ondrej Trubac * Date: $Date: 2007/09/27 11:06:34 $ * Revision: $Revision: 1.120 $ * * Description: * * Main entry point for the controller task. * *************************************************** * * COPYRIGHT (C) ST Microelectronics 2005 * All Rights Reserved * *************************************************** * * STM CVS Log: * * $Log: filesys.c,v $ * Revision 1.120 2007/09/27 11:06:34 trubac * Configuration option for filesystem items limit * * Revision 1.119 2007/09/21 05:29:14 hara * Initial implementation for WMDRM feature into A+. * * Revision 1.118 2007/09/18 11:43:05 belardi * Removed comments * * Revision 1.117 2007/08/31 09:54:52 sedmik * fix for counter of files not stored to X_array * * Revision 1.116 2007/08/29 15:17:53 trubac * fix for adding volume to full X_array * * Revision 1.115 2007/08/28 13:07:56 trubac * Limit for 32K items in X_array * * Revision 1.114 2007/08/27 15:22:18 sedmik * fix stop CMD - apply command even no filesys FSM is running * * Revision 1.113 2007/08/07 09:34:07 trubac * host_update_file_index captures very first special file * * Revision 1.112 2007/07/31 12:00:47 belardi * Removed compiler warning * * Revision 1.111 2007/07/25 13:45:23 trubac * Special files extension testing preparation, no shrinking and extension removing is performed for special data files * * Revision 1.110 2007/07/24 15:50:21 trubac * Fix for slow FAT mounting, FatEntryCheck added * * Revision 1.109 2007/07/20 12:25:25 trubac * ItemsThrown cleared when mounting process starts * * Revision 1.108 2007/06/12 09:08:04 sedmik * fixed - if mounting is stopped during operation, remove unfinished volume * * Revision 1.107 2007/03/19 17:59:19 belardi * Integration of Optomech AAC decoder P150307 * * Revision 1.106 2007/03/15 11:44:22 trubac * directory names shrinking fixed * * Revision 1.105 2007/03/07 10:00:16 trubac * Fixed wrong X_array top when USB unplugged during mount * * Revision 1.104 2007/02/27 11:12:49 belardi * Reverted back to pre-Optomech patch (1.102) * * Revision 1.102 2007/02/21 09:35:11 trubac * File names stored without extension * * Revision 1.101 2007/02/15 15:54:51 belardi * Added configuration items for HAVE_FSHRINK * * Revision 1.100 2007/02/09 12:03:57 belardi * First integration of iPod pass-through: * - changed error define for USB * * Revision 1.99 2007/02/06 11:15:06 belardi * Added dynamic remapping of SDRAM for ESP vs. X_array * * Revision 1.98 2007/02/02 16:16:40 belardi * Changed cast in call to witeSDRAM32 to get rid of compiler warnings * * Revision 1.97 2007/01/29 14:32:00 chlapik * support for USB devices with any block size (not only 512B) * * Revision 1.96 2007/01/24 16:46:29 trubac * Filesystem supports 15000 files * String reverse page offset is in nodetype.b[1] * * Revision 1.95 2007/01/18 15:01:31 trubac * Preparation for 15000 files * * Revision 1.94 2006/12/12 19:14:25 trubac * New functions for dir numbering, should be tested * * Revision 1.93 2006/12/12 11:01:13 sedmik * vars definitions related to file update * * Revision 1.92 2006/12/01 15:39:12 sedmik * sectorbuffer size via define (in filesys.h) * * Revision 1.91 2006/11/30 11:06:14 belardi * Changed host_update_file_index to uint16 to comply with XAR_SafeIndex() * * Revision 1.90 2006/11/28 16:00:24 trubac * host_update_file_index protected by X_safe_list * * Revision 1.89 2006/11/28 09:27:43 belardi * m4a decoder alfa release from Optomech * * Revision 1.88 2006/11/27 19:45:02 belardi * Host Update protocol addition * - save index of update file in global variable for controller * * Revision 1.87 2006/11/20 15:14:02 marcucci * Modification for HAVE_UPDATE transition * * Revision 1.86 2006/11/15 13:31:22 trubac * Forced stop (EJECT) improved during UDF mounting * * Revision 1.85 2006/11/13 17:31:17 chlapik * fixed bug - stop while BitrateParser or TAG decode running * * Revision 1.84 2006/11/10 15:10:50 belardi * Changes to compile for APM: STM code uses xfile.address field for quick song numbering. * APM does not need it, so it is removed to avoid some functions from possibly using it unitinialized * * Revision 1.83 2006/11/08 13:40:42 chlapik * one more fix for USB in case of STOP - if stop is cought by USB task earlier than CTR is informed about USB unmount * * Revision 1.82 2006/11/08 12:56:05 chlapik * fixed bugs in filesys for case of stop mount: * - if GetDirItem() returns error due to stop, then don't continue with parsing of next dir, but send stop finished to CTR * - if DetectFilesystem() returns error due to stop, send stop finished to CTR * - in IO_Read() move of pending event to inevent, otherwise pending event will be processed twice by filesys (filesys still uses old event processing and also new - osal, so mix) * * Revision 1.81 2006/11/08 08:50:01 marcucci * HAVE_UPDATE form CD and USB * * Revision 1.80 2006/10/23 14:26:34 trubac * XAR_CreateSongIndexes called after new mount process * * Revision 1.79 2006/10/18 09:41:14 chlapik * force_execution added to mount params * * Revision 1.78 2006/10/17 09:58:29 trubac * mounting improvements, discid updated only when mount succesfull * * Revision 1.77 2006/10/05 07:27:58 trubac * Implementing TOC info at the end of string pool * * Revision 1.76 2006/09/27 19:50:54 belardi * Removed (global) unused variables * * Revision 1.75 2006/09/26 09:31:51 belardi * Added include to remove compiler warning * * Revision 1.74 2006/09/19 10:24:34 belardi * Removed unused variables * * Revision 1.73 2006/09/15 19:48:32 belardi * Merged the m8_cav2_cm80506_cs3563. * - renamed variables/struct fields * * ***************************************************/#include "gendef.h"#include "osal.h"#include "hwreg.h"#include "id3tag.h"#include "xfile.h"#include "filesys.h"#include "ioread.h"#include "controller.h"#include "decoder_task.h"#include "apdevsys.h"#include "isotypes.h"#include "iso9660.h"#include "FAT.h"#include "cddevice.h"#include "framebuffer.h"#include "toc.h"#if (1 == HAVE_WMA)#include "wmaudio.h"#include "wmaerr.h"#include "wmaudio_type.h"#include "wmaudio_add.h"#include "wmatag.h"#endif#if (1 == HAVE_AAC)#include "aactag.h"#endif#if (1 == HAVE_UDF)#include "UDF_getUDF.h"#endif#include <string.h> //[OK] memcpy#if (1 == HAVE_WMDRM) #include "WMDRM_Receiver.h"#endif#include "mconfig.h"#ifdef QAC_CHECK#define FS_PRINT(x)#else#define FS_PRINT(...) dprintf(__VA_ARGS__)//#define FS_PRINT(...) do{}while(0)#endif// OS20 stuffsemaphore_t sem_xfile;t_filesys_inevent filesys_inevent;t_filesys_outevent filesys_outevent;t_filesys_inevent local_filesys_inevent;t_filesys_stop_params fs_stop_params;t_filesys_mount_params fs_mount_params;t_filesys_tag_params fs_tag_params;#if (0 != HAVE_UPDATE)int16 update_file_index;#endif#if ((1 == HAVE_HOST_UPDATE) || (1 == HAVE_HOST_UPDATE_NEW))uint16 host_update_file_index;#endif#pragma arm section zidata = "filesystem_sectbuf"uint8 filesys_sectbuf[SECTORBUFFER_SIZE];#pragma arm section zidataGRESULT (*pGETDIRITEM)(SCAN_STRUCT *scans, DIR_ITEM *item, uint8 *buf);uint16 ItemsThrown = 0;uint16 ItemsAdded = 0;uint16 filesys_transition_results;int string_top;DUID cdid;FDID fsid; // [RB] can be made into local?CD_DeviceDescriptor cd_descr;FS_DESCRIPTOR fs_descriptor;SCAN_STRUCT fs_scan_struct;uint32 si_position, si_extent_position, si_extent_lba, si_extent_size;uint16 si_extent_index;extern uint8 g_FB_writeTo;t_fsm filesys_fsm_init;t_fsm filesys_fsm_stop;t_fsm filesys_fsm_mount;t_fsm filesys_fsm_tag;#if (HAVE_FSHRINK==1)#define FILE_SHRINK_MODE_STEP (module_config.data.file_shrink_step)#define FILE_SHRINK_MODE_MAX (module_config.data.file_shrink_max)#define FILE_SHRINK_MODE_MIN (module_config.data.file_shrink_min)#define DIR_SHRINK_MODE_STEP (module_config.data.dir_shrink_step)#define DIR_SHRINK_MODE_MAX (module_config.data.dir_shrink_max)#define DIR_SHRINK_MODE_MIN (module_config.data.dir_shrink_min)int16 file_shrink_mode,dir_shrink_mode;#endif//uint16 CONFIG_FS_MAX_ITEMS = 20;#define CONFIG_FS_MAX_ITEMS (module_config.data.filesystem_limit)void InitFileSystemTask(void){ semaphore_init_fifo(&sem_xfile, 1); Init_X_array();}void Init_X_array(void){ XAR_ClearXArray(); XAR_AddTOCVolume(); XAR_InitSafeList(); }void FileSystemTask(void *unused){ SYS_DeviceTableInit(); cdid = SYS_RegisterDevice(CD_DEVICE_ID, DEV_CD_ID, 0, &cd_descr); CD_SetDeviceId(cdid); // Assign device Id to CD descriptor internal attribute SYS_DeletePartitions(cdid); SYS_SetLargeBlockSize(cdid, 2048); SYS_AddPartition(cdid, 0);#if (0 != HAVE_USB) cdid = SYS_RegisterDevice(USB_DEVICE_ID, DEV_USB_ID, 0, NULL); SYS_DeletePartitions(cdid); SYS_SetLargeBlockSize(cdid, 512);#endif#if (0 != HAVE_SDC) cdid = SYS_RegisterDevice(SDC_DEVICE_ID, DEV_SDC_ID, 0, NULL); SYS_DeletePartitions(cdid); SYS_SetLargeBlockSize(cdid, 512);#endif /* HAVE_SDC */ // filesys_status_event.state = FILESYS_STATE_RESET; // fs_scan_struct.status = FS_MOUNT_STS_RESET; FSM_init(&filesys_fsm_init, "filesys_fsm_init"); FSM_init(&filesys_fsm_stop, "filesys_fsm_stop"); FSM_init(&filesys_fsm_mount, "filesys_fsm_mount"); FSM_init(&filesys_fsm_tag, "filesys_fsm_tag"); while (1) { OSAL_wait_thread(OSAL_THREAD_FilesysTask); event_disable_scheduling(); event_in_shedule(FILESYS_CMD_EVENT); event_enable_scheduling(); filesys_outevent = 0; filesys_process_preevents(); filesys_fsm(); filesys_process_postevents(); event_disable_scheduling(); event_in_clear(FILESYS_CMD_EVENT); event_out_shedule(FILESYS_TAG_EVENT); event_out_shedule(FILESYS_MOUNT_EVENT); event_out_shedule(FILESYS_STOP_EVENT); event_out_shedule(FILESYS_INIT_EVENT); event_enable_scheduling(); }}/******************************************************************************/t_filesys_cmd_event filesys_cmd_event_data[EVENT_MAX_STAGES];void * get_filesys_cmd_event_data(t_event_stage i){ // controler -> filesys return (void *)&filesys_cmd_event_data[i];}RETVAL filesys_cmd(t_filesys_cmd_event *cmd_event){ t_filesys_inevent mask = FILESYS_COMMAND_EVENT; t_filesys_cmd_event *pout_event; switch (cmd_event->command) { case FILESYS_CMD_INIT: mask = FILESYS_INIT_COMMAND_EVENT; break; case FILESYS_CMD_INIT_FOR_NEW_DISC: filesys_init_for_new_disc(); return READY; case FILESYS_CMD_STOP:#if 0 /* JS fix 27.8.2007 - apply stop CMD even no filesys FSM is running (filesys_inevent still can contain some action todo */ if ((filesys_fsm_init.state != FSM_RUN) && \ (filesys_fsm_mount.state != FSM_RUN) && \ (filesys_fsm_tag.state != FSM_RUN)) { return READY; }#endif memcpy(&fs_stop_params, &cmd_event->params.stop_params, sizeof(t_filesys_stop_params)); mask = FILESYS_STOP_COMMAND_EVENT; break; case FILESYS_CMD_MOUNT_FS: memcpy(&fs_mount_params, &cmd_event->params.mount_params, sizeof(t_filesys_mount_params)); mask = FILESYS_MOUNT_COMMAND_EVENT; break; case FILESYS_CMD_TAG_DECODE: // treat always as new command memcpy(&fs_tag_params, &cmd_event->params.tag_params, sizeof(t_filesys_tag_params)); mask = FILESYS_TAG_COMMAND_EVENT; break; case FILESYS_CMD_DATA_READY: mask = FILESYS_DATA_READY_EVENT; break; default: return READY; // UNKNOWN COMMAND } // memcpy(&new_filesys_cmd_event,cmd_event,sizeof(t_filesys_cmd_event)); filesys_inevent = mask; pout_event = (t_filesys_cmd_event *) pevent_get_out(FILESYS_CMD_EVENT); *pout_event = *cmd_event; event_set_out(FILESYS_CMD_EVENT); //priority dependent (semaphore signal immediatelly) event_out_shedule(FILESYS_CMD_EVENT); //event_cmd_set(CONTROLLER_CMD_EVENT); //independent from priorities //OSAL_wake_thread(OSAL_THREAD_FilesysTask); return BUSY;}RETVAL filesys_process_preevents(void){ // beginning of critical section // DISABLE_INTERRUPTS(); event_disable_scheduling(); local_filesys_inevent |= filesys_inevent; filesys_inevent = 0; event_enable_scheduling(); // memcpy(&local_filesys_cmd_event,&filesys_cmd_event,sizeof(t_filesys_cmd_event)); // ENABLE_INTERRUPTS(); // end of critical section // check here if some fsm has to be started // if(local_filesys_inevent & FILESYS_COMMAND_EVENT) //if (IS_FILESYS_CMD_EVENT) { // local_filesys_inevent &= ~FILESYS_COMMAND_EVENT; if (local_filesys_inevent & FILESYS_INIT_COMMAND_EVENT) { FSM_activate(&filesys_fsm_init, 0, 1); local_filesys_inevent &= ~FILESYS_INIT_COMMAND_EVENT; } // case FILESYS_CMD_INIT_FOR_NEW_DISC: // filesys_init_for_new_disc(); if (local_filesys_inevent & FILESYS_MOUNT_COMMAND_EVENT) { FSM_activate(&filesys_fsm_mount, 0, 1); local_filesys_inevent &= ~FILESYS_MOUNT_COMMAND_EVENT; //ItemsThrown = 0; } if (local_filesys_inevent & FILESYS_STOP_COMMAND_EVENT) { FSM_activate(&filesys_fsm_stop,0,1); /*if (fs_stop_params.flags & FS_STOP_MOUNT) filesys_mount_stop(); if (fs_stop_params.flags & FS_STOP_TAG) filesys_tag_decode_stop(); filesys_outevent |= FS_STOP_FINISHED; */ local_filesys_inevent &= ~FILESYS_STOP_COMMAND_EVENT; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -