📄 filesys.c
字号:
res = filesys_next_shrink_mode(); if(res>0) goto fs_addvol; if(!res) goto fs_addvol2;#endiffs_addvol3: // abort mount operation filesys_fsm_mount.error_reason = E_INSUFFICIENT_MEMORY; filesys_fsm_mount.transition = FS_MOUNT_STATE_ERROR; return FS_TRAN_RESULT_MOUNT; // continue and terminate with error } // counter of files filtered off X_array[XAR_VolumeNode(fs_scan_struct.volume)].data.xvolume.nextfree_item = 0; // prepare scanning fs_scan_struct.fs_descriptor = &fs_descriptor; fs_scan_struct.byte0 = (fs_descriptor.attributes & ISO9660_SUPPLEM_VOL_DESCRIPTOR_FLAG) ? 1 : 0; switch (fs_scan_struct.fs_descriptor->FSType) { case FS_ISO9660_TYPE: item.dir.DirRecordLba = fs_scan_struct.fs_descriptor->PD.ISO_pd.RootRecordLba; pGETDIRITEM = ISO_GetDirItem; break;#if (HAVE_UDF) case FS_UDF_TYPE: item.dir.DirRecordLba = fs_scan_struct.fs_descriptor->PD.UDF_pd.partitionInfo.fileSet.extLocation; pGETDIRITEM = UDF_GetDirItem; break;#endif#if (HAVE_FAT) case FS_FAT_TYPE: item.dir.DirRecordLba = fs_scan_struct.fs_descriptor->PD.FAT_pd.RootRecordLba; pGETDIRITEM = FAT_GetDirItem; fs_scan_struct.IsRoot = true; break;#endif#if (HAVE_WMDRM) case FS_WMDRM_TYPE: pGETDIRITEM = WMDRM_GetDirItem; ((DRM_GETDIRITEM *) &filesys_sectbuf)->loopState = STATE_GET_OBJECTHANLDES_ROOT_DIR; break;#endif default: filesys_fsm_mount.error_reason = E_NOT_IMPLEMENTED; filesys_fsm_mount.transition = FS_MOUNT_STATE_ERROR; return FS_TRAN_RESULT_MOUNT; // continue and terminate with error } item.dir.ParentOffset = 0; item.dir.NameLength = 4; strcpy((char *) item.dir.Name, "ROOT\0");fs_addroot: fs_scan_struct.scan_index = XAR_AddDirItem(&item, XTYPE_DIRECTORY); if (fs_scan_struct.scan_index < 1) // check if node was created { if (fs_scan_struct.scan_index == E_FAIL) goto fs_addroot3; #if (HAVE_FSHRINK==1) // shrink namesfs_addroot2: res = filesys_next_shrink_mode(); if(res>0) goto fs_addroot; if(!res) goto fs_addroot2;#endiffs_addroot3: // abort mount operation filesys_fsm_mount.error_reason = E_INSUFFICIENT_MEMORY; filesys_fsm_mount.transition = FS_MOUNT_STATE_ERROR; return FS_TRAN_RESULT_MOUNT; // continue and terminate with error } XAR_SetDirParent(fs_scan_struct.scan_index, 0); // root has no parent filesys_fsm_mount.transition = FS_MOUNT_STATE_SCAN_DIR; filesys_outevent |= FS_MOUNT_RESUME; return 0; case FS_MOUNT_STATE_SCAN_DIR: fs_scan_struct.DirRecordLba = XAR_DirRecordLba(fs_scan_struct.scan_index); fs_scan_struct.DirRecordOffset = 0; fs_scan_struct.DirItems = 0; //M.Ch. if (fs_scan_struct.fs_descriptor->FSType != FS_ISO9660_TYPE) { if ((fs_scan_struct.byte0 = XAR_DirRecordIsFile(fs_scan_struct.scan_index)) == S_TRUE) //in case of file parse ICB locations by different function //M.Ch. t.b.d. fs_scan_struct.FileSize = XAR_FileSize(fs_scan_struct.scan_index); fs_scan_struct.FatEntryCheck = 0xFFFFFFFF; } filesys_fsm_mount.transition = FS_MOUNT_STATE_SCAN_ITEMS; case FS_MOUNT_STATE_SCAN_ITEMS: res = pGETDIRITEM(&fs_scan_struct, &item, filesys_sectbuf);#if STACK_CHECK { static volatile int stack_check = 0; if (stack_check) { res = ISO_GetDirItem(&fs_scan_struct, &item, filesys_sectbuf);#if (HAVE_FAT) res = FAT_GetDirItem(&fs_scan_struct, &item, filesys_sectbuf);#endif } }#endif if ((res < 0 /*read error*/) || (res == S_NOT_FOUND)) { if(res == E_FORCED_UNPLUG) { //stop requested, detected in IO_read()#if 1 /* OT fix for issue #147 - stop mount cmd kept invalid volume node in X_array */ // [OT] close volume correctly XAR_SetLastNode(XAR_VolumeNode(fs_scan_struct.volume)); // restore#if HAVE_EXTERNAL_XARRAY writeSDRAM32((int16*)&X_POOL_TOP,string_top); // restore strings pool position#else X_POOL_TOP = string_top;#endif#endif //if 1 filesys_fsm_mount.state = FSM_ERROR; filesys_fsm_mount.error_reason = E_FORCED_TERMINATION; filesys_outevent |= FS_MOUNT_FINISHED; return FS_TRAN_RESULT_MOUNT; // continue and terminate with error } // switch to next dir/ICB parsing fs_scan_struct.IsRoot = false; //M.Ch. if ((!fs_scan_struct.DirItems) && XAR_IsDirectory(fs_scan_struct.scan_index)) { res = XAR_DeleteDir(fs_scan_struct.scan_index); if (res > 0) { fs_scan_struct.scan_index -= res; if(ItemsAdded>res) ItemsAdded -= res; } }find_dir: if (fs_scan_struct.scan_index < XAR_LastIndex()) { fs_scan_struct.scan_index++;#if (0 != HAVE_WMDRM) if ((fs_scan_struct.fs_descriptor->FSType == FS_ISO9660_TYPE) || (fs_scan_struct.fs_descriptor->FSType == FS_WMDRM_TYPE))#else if (fs_scan_struct.fs_descriptor->FSType == FS_ISO9660_TYPE) //M.Ch.#endif { if (!XAR_IsDirectory(fs_scan_struct.scan_index)) goto find_dir; } if (XAR_IsExtent(fs_scan_struct.scan_index) == S_TRUE) //M.Ch. goto find_dir; } else // very end of scanning, check next partition { XAR_SetVolumeTop(fs_scan_struct.volume, XAR_LastIndex());#ifndef APM_PICKUP XAR_CreateSongIndexes(fs_scan_struct.volume); // OT TODO XAR_CreateDirIndexes(fs_scan_struct.volume);#endif fs_scan_struct.partition++; filesys_fsm_mount.transition = FS_MOUNT_STATE_DETECT; filesys_outevent |= FS_MOUNT_RESUME; return 0; } filesys_fsm_mount.transition = FS_MOUNT_STATE_SCAN_DIR; filesys_outevent |= FS_MOUNT_RESUME; return 0; } switch (res) { case S_FILE_FOUND: // add file if(CONFIG_FS_MAX_ITEMS) { if(ItemsAdded >= CONFIG_FS_MAX_ITEMS) { ItemsThrown++; break; } }#if (0 != HAVE_UPDATE) if(!XAR_DirParent(fs_scan_struct.scan_index) && !XAR_DirFirstFile(fs_scan_struct.scan_index)) { if ((FS_ISO9660_TYPE == fs_scan_struct.fs_descriptor->FSType) || (FS_FAT_TYPE == fs_scan_struct.fs_descriptor->FSType)) //[MM] Modified for USB source { if (!strncmp(FLASH_IMAGE, (char *) item.file.Name, item.file.NameLength)) { if(FS_FAT_TYPE == fs_scan_struct.fs_descriptor->FSType) { item.file.ExtentLba = (((item.file.ExtentLba - 2) * (fs_scan_struct.fs_descriptor->PD.FAT_pd.BPB_boot_common.SecPerClust) + fs_scan_struct.fs_descriptor->PD.FAT_pd.FirstDataSector) * ((fs_scan_struct.fs_descriptor->PD.FAT_pd.BPB_boot_common.BytesPerSec) / fs_scan_struct.fs_descriptor->LargeBlockSize) + fs_scan_struct.fs_descriptor->PartitionLBA); } if (0 < (i = XAR_AddDirItem(&item, XTYPE_DATA_FILE))) { update_file_index = i; fs_scan_struct.DirItems++; XAR_UpdateNodeFlags(i, item.file.FileType); XAR_SetDirFirstFile(fs_scan_struct.scan_index, i); XAR_SetVolumeTop(fs_scan_struct.volume, XAR_LastIndex()); filesys_fsm_mount.state = FSM_DONE; filesys_outevent |= FS_MOUNT_FINISHED; CDinfo |= HAVE_FLASH_IMAGE; return FS_TRAN_RESULT_MOUNT; } } } }#endif /* HAVE_UPDATE */ file_ext_res = XAR_TestFileExtension(&item.file, X_exfilter); if (file_ext_res) { if(file_ext_res != S_SPECIAL_FILE_FOUND) item.file.NameLength -= 4; // remove extension#if (HAVE_FSHRINK==1) if(file_ext_res != S_SPECIAL_FILE_FOUND) {fs_addfile: res = filesys_shrink_name(file_shrink_mode,item.file.Name,item.file.NameLength); if(res>0) item.file.NameLength = res; }#endif if (0 < (i = XAR_AddDirItem(&item, XTYPE_DATA_FILE))) {#if ((1 == HAVE_HOST_UPDATE) || (1 == HAVE_HOST_UPDATE_NEW)) if ((!host_update_file_index)&&(file_ext_res == S_SPECIAL_FILE_FOUND)) { host_update_file_index = i; XAR_InsertSafeIndex(&host_update_file_index); }#endif fs_scan_struct.DirItems++; XAR_UpdateNodeFlags(i, item.file.FileType); if (!XAR_DirFirstFile(fs_scan_struct.scan_index)) XAR_SetDirFirstFile(fs_scan_struct.scan_index, i); ItemsAdded ++; } else { if (i == E_FAIL) goto fs_addfile3;#if (HAVE_FSHRINK==1)fs_addfile2: res = filesys_next_shrink_mode(); if(res>0) goto fs_addfile; if(!res) goto fs_addfile2;#endiffs_addfile3: ItemsThrown++; } } else { /* JS fix 31.8.2007 use variable for X_array addressing */ xid = XAR_VolumeNode(fs_scan_struct.volume); // increment foreing count, little bit tricky, used last_item for this purpose (X_array[xid].data.xvolume.nextfree_item)++; } break; case S_DIR_FOUND: // add directory if(CONFIG_FS_MAX_ITEMS) { if(ItemsAdded >= CONFIG_FS_MAX_ITEMS) { ItemsThrown++; break; } }#if (HAVE_FSHRINK==1)fs_adddir: res = filesys_shrink_name(dir_shrink_mode,item.dir.Name,item.dir.NameLength); if(res>0) item.dir.NameLength = res;#endif if (0 < (i = XAR_AddDirItem(&item, XTYPE_DIRECTORY))) { fs_scan_struct.DirItems++; XAR_SetDirParent(i, fs_scan_struct.scan_index); if (!XAR_DirChild(fs_scan_struct.scan_index)) XAR_SetDirChild(fs_scan_struct.scan_index, i); ItemsAdded ++; } else { if (i == E_FAIL) goto fs_adddir3;#if (HAVE_FSHRINK==1)fs_adddir2: res = filesys_next_shrink_mode(); if(res>0) goto fs_adddir; if(!res) goto fs_adddir2;#endiffs_adddir3: ItemsThrown++; } break;#if ((HAVE_FAT) || (HAVE_UDF)) case S_FILE_UPDATE_ITEM: fs_scan_struct.ExtentScanIndex = fs_scan_struct.scan_index; if (fs_scan_struct.fs_descriptor->FSType == FS_FAT_TYPE) item.file.ExtentLba = (((item.file.ExtentLba - 2) * (fs_scan_struct.fs_descriptor->PD.FAT_pd.BPB_boot_common.SecPerClust) + fs_scan_struct.fs_descriptor->PD.FAT_pd.FirstDataSector) * ((fs_scan_struct.fs_descriptor->PD.FAT_pd.BPB_boot_common.BytesPerSec) / fs_scan_struct.fs_descriptor->LargeBlockSize) + fs_scan_struct.fs_descriptor->PartitionLBA); if (fs_scan_struct.fs_descriptor->FSType == FS_UDF_TYPE) XAR_UpdateItem(fs_scan_struct.scan_index, &item, UPDATE_LBA + UPDATE_SIZE + UPDATE_UDF_FLAGS); else XAR_UpdateItem(fs_scan_struct.scan_index, &item, UPDATE_LBA + UPDATE_SIZE); break; case S_FILE_ADD_EXTEND: if (fs_scan_struct.fs_descriptor->FSType == FS_FAT_TYPE) item.file.ExtentLba = (((item.file.ExtentLba - 2) * (fs_scan_struct.fs_descriptor->PD.FAT_pd.BPB_boot_common.SecPerClust) + fs_scan_struct.fs_descriptor->PD.FAT_pd.FirstDataSector) * ((fs_scan_struct.fs_descriptor->PD.FAT_pd.BPB_boot_common.BytesPerSec) / fs_scan_struct.fs_descriptor->LargeBlockSize) + fs_scan_struct.fs_descriptor->PartitionLBA) * BLOCKS_PER_512BSector;fs_addext: if (0 < (i = XAR_AddDirItem(&item, XTYPE_FILE_EXTEND))) //create new extent to file { item.file.Position = i; XAR_UpdateItem(fs_scan_struct.ExtentScanIndex, &item, UPDATE_EXTEND); //connect previous item to newly created one fs_scan_struct.ExtentScanIndex = i; } else // shrink names or delete all previous extents here, TBD { if (i == E_FAIL) goto fs_addext3; #if (HAVE_FSHRINK==1)fs_addext2: res = filesys_next_shrink_mode(); if(res>0) goto fs_addext; if(!res) goto fs_addext2;#endiffs_addext3: ItemsThrown++; } break;#endif case S_FILE_SKIP: default: break; } filesys_outevent |= FS_MOUNT_RESUME; return 0; //case FS_MOUNT_STATE_ERROR: default: filesys_fsm_mount.state = FSM_ERROR; filesys_outevent |= FS_MOUNT_FINISHED; return FS_TRAN_RESULT_MOUNT; } /*ItemsThrown; */ // [RB] no side effect, removed to eliminate compiler warning return 0;}#if 0 // [RB] commented out to reduce ROM spaceGRESULT filesys_read_cache(uint32 count, uint8 *buf, uint32 offs){ PREPARE_IOREAD(FS_XFER_command_event, DEV_CD_ID, 150, 150, offs, 2048, buf, count, IO_READ_CACHE); return IO_Read(IO_READ_CACHE);}#endifvoid filesys_restore_si(t_SongInfos *song_info){ song_info->position = si_position; song_info->extent_index = si_extent_index; song_info->extent_position = si_extent_position; song_info->extent_lba = si_extent_lba; song_info->extent_size = si_extent_size;}//Func to SET offset pointer from beginning of file//Usage with use_cache<>0 is allowed only from filesys task !!!// use_cache mode works with single extent files or files with extents > 2 sectorsGRESULT XAR_SeekFile(t_SongInfos *song_info, uint32 offset, uint32 use_cache){ int32 diff; //t_SongInfos oldsi; // uint32 of1,of2; // [RB] unused // uint8 dummyb[10]; // [RB] unused uint16 temp_extent_index; song_info->flags &= ~XFILE_FLAG_EOF; //memcpy(&oldsi, song_info, sizeof(t_SongInfos)); si_position = song_info->position; si_extent_index = song_info->extent_index; si_extent_position = song_info->extent_position; si_extent_lba = song_info->extent_lba; si_extent_size = song_info->extent_size; diff = offset - song_info->position; if (!diff) return S_OK; if (diff > 0) { if (diff >= (song_info->extent_size - song_info->extent_position)) { // move towards through extents // diff -= (song_info->extent_size-song_info->extent_position); do { diff -= (song_info->extent_size - song_info->extent_position); song_info->extent_position = 0; temp_extent_index = song_info->extent_index; if (song_info->type == TRACK_CDDA) song_info->extent_index = 0; else song_info->extent_index = X_array[song_info->extent_index].data.xfile.next_extent \ & 0x7FFF ; // O.T. mask off UDF simple file flag if ((diff) && (!song_info->extent_index)) { filesys_restore_si(song_info); return E_PARAMETER_OUT_OF_RANGE; // seek beyond end of file; } if (!song_info->extent_index) { //no next extent, diff=0 ~ seek to beginning of extent == seek behind file song_info->extent_index = temp_extent_index; song_info->position = offset; song_info->extent_position = song_info->extent_size; if (song_info->type != TRACK_CDDA) #if HAVE_EXTERNAL_XARRAY song_info->extent_lba = X_array[song_info->extent_index].data.xfile.lba;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -