📄 apdevsys.c
字号:
/************************************************** * * apdevsys.c * * CVS ID: $Id: apdevsys.c,v 1.25 2007/09/21 05:29:14 hara Exp $ * Author: Ondrej Trubac [OT] - STM * Date: $Date: 2007/09/21 05:29:14 $ * Revision: $Revision: 1.25 $ * * Description: * * *************************************************** * * COPYRIGHT (C) ST Microelectronics 2005 * All Rights Reserved * **************************************************** * * \par Change History: * * - BB060929a Improved no TOC and Copyprotected CD support * *************************************************** * * STM CVS Log: * * $Log: apdevsys.c,v $ * Revision 1.25 2007/09/21 05:29:14 hara * Initial implementation for WMDRM feature into A+. * * Revision 1.24 2006/11/15 12:26:42 trubac * E_FORCED_UNPLUG handling * * Revision 1.23 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.22 2006/10/17 09:56:04 trubac * toc reading and mounting improvement by BB * * Revision 1.21 2006/09/27 19:50:31 belardi * Removed (global) unused variables * * Revision 1.20 2006/09/18 09:55:22 belardi * Corrected CVS keyword usage * * Revision 1.19 2006/09/18 09:24:01 belardi * Added Log CVS keyword into file header * * ***************************************************/#include <stdlib.h>#include "configuration.h"#include "accordoptypes.h" // "aptypes.h"#include "apdevsys.h"#include "xfile.h"#include "iso9660.h"#include "filesys.h"#include "FAT.h" //M.Ch.#include "cddevice.h"#if (HAVE_UDF)#include "UDF_getUDF.h"#endif#if (1 == HAVE_WMDRM) #include "usb.h" #include "WMDRM_Receiver.h"#endif//FS_DESCRIPTOR FAT_descriptor; // [RB] unusedDeviceInfoStruct AP_DeviceTable[SYS_MAX_NUMBER_DEVICES]; // cd,sd,usbvoid SYS_DeviceTableInit(void){ int i, j; for (i = 0; i < SYS_MAX_NUMBER_DEVICES; i++) { AP_DeviceTable[i].DeviceID = i + 1; AP_DeviceTable[i].DeviceStatus = DEV_STATUS_UNKNOWN; AP_DeviceTable[i].DeviceType = DEV_NO_DEVICE; AP_DeviceTable[i].DeviceAttr = 0; AP_DeviceTable[i].NumPartitions = 0; AP_DeviceTable[i].LargeBlockSize = 0; AP_DeviceTable[i].vpDescript = NULL; for (j = 0; j < MAX_DEV_PARTITIONS; j++) AP_DeviceTable[i].PartitionLBA[j] = 0; for (j = 0; j < MAX_FS_COUNT; j++) { AP_DeviceTable[i].FS_list[j] = 0; AP_DeviceTable[i].FS_desc[j] = NULL; } }}DUID SYS_RegisterDevice(DUID id, t_duid devtype, UInt devattr, void *DeviceDescriptor){ if (id > SYS_MAX_NUMBER_DEVICES) return 0; AP_DeviceTable[id - 1].DeviceType = devtype; AP_DeviceTable[id - 1].DeviceAttr = devattr; AP_DeviceTable[id - 1].vpDescript = DeviceDescriptor; AP_DeviceTable[id - 1].DeviceStatus = DEV_STATUS_ASSIGNED; return id;}t_duid SYS_DeviceType(DUID duid){ return AP_DeviceTable[duid - 1].DeviceType;}DeviceInfoStruct * SYS_DeviceInfoStruct(DUID duid){ return &AP_DeviceTable[duid - 1];}void * SYS_DeviceDescriptor(DUID duid){ return AP_DeviceTable[duid - 1].vpDescript;}GRESULT SYS_ClearDeviceAttribute(DUID did, unsigned int flags){ AP_DeviceTable[did - 1].DeviceAttr &= (MAX_UINT_VALUE - flags); return S_OK;}GRESULT SYS_SetDeviceAttribute(DUID did, unsigned int flags){ AP_DeviceTable[did - 1].DeviceAttr |= flags; return S_OK;}UInt SYS_DeviceAttributes(t_duid dev){ int i = 0; while (i < SYS_MAX_NUMBER_DEVICES) { if (AP_DeviceTable[i].DeviceType == dev) return AP_DeviceTable[i].DeviceAttr; i++; } return 0;}//int16 SYS_DetectFileSystem ( DUID did, int fstype , int partition , FS_DESCRIPTOR *fsdesc, UInt flags)int16 SYS_DetectFileSystem(DUID did, int fstype, int partition, FS_DESCRIPTOR *fsdesc){ GRESULT res; //int max_alloc_size=10000; FDID fid; switch (fstype) { case FS_ISO9660_TYPE: if (partition > 0) return E_INVALID_PARAMETER; res = ISO_Detect(did, partition, fsdesc); if (res == S_TRUE) break; if(res == E_FORCED_UNPLUG) { return res; } if ((res == E_INVALID_DEVICE_TYPE) || (res == E_INVALID_DEVICE_DESCRIPTOR) || (res == E_NO_FS_CARRIER)) { return E_FAIL; } return E_FS_TRYNEXTTRACK;#if (HAVE_FAT) case FS_FAT_TYPE: //res = FAT_Detect(did,partition,fsdesc, flags, max_alloc_size); res = FAT_Detect(did, partition, fsdesc); if (res == S_TRUE) break; return res; //E_FAIL;#endif#if (HAVE_UDF) case FS_UDF_TYPE: res = UDF_Detect(did,partition,fsdesc); if(res==S_TRUE) break; if(res == E_FORCED_UNPLUG) { return res; } if ((res == E_INVALID_DEVICE_TYPE) || (res == E_INVALID_DEVICE_DESCRIPTOR) || (res == E_NO_FS_CARRIER)) { return E_FAIL; } return E_FS_TRYNEXTTRACK;#endif#if (HAVE_WMDRM) case FS_WMDRM_TYPE: res = WMDRM_Detect(did,partition,fsdesc); if (res == S_TRUE) break; return E_FAIL;#endif default: return E_UNKNOWN_FS_TYPE; } fid = SYS_OpenFileSystem(did, fsdesc); // if(fid<1) // free(fsdesc); return fid;}GRESULT SYS_ClearPartitions(DUID did){ DeviceInfoStruct *dev; dev = SYS_DeviceInfoStruct(did); dev->NumPartitions = 0; return S_OK;}GRESULT SYS_ClearFSEntries(DUID did){ DeviceInfoStruct *dev; int i; dev = SYS_DeviceInfoStruct(did); for (i = 0; i < MAX_FS_COUNT; i++) { if (dev->FS_list[i]) { // free(dev->FS_desc[i]); // no dynamic allocations of FS_DESCRIPTOR has to be used dev->FS_desc[i] = NULL; dev->FS_list[i] = 0; } } return S_OK;}FDID SYS_OpenFileSystem(DUID did, FS_DESCRIPTOR *fsdesc){ int i; DeviceInfoStruct *dev; FDID fid; dev = SYS_DeviceInfoStruct(did); for (i = 0; i < MAX_FS_COUNT; i++) { if (!dev->FS_list[i]) { dev->FS_desc[i] = fsdesc; dev->FS_list[i] = fsdesc->FSType; break; } } if (i == MAX_FS_COUNT) return E_NO_FREE_FS_SLOT; fid = did + (i << 8); return fid;}uint32 SYS_PartitionLBA(DUID id, UInt partition, UInt lbsize){ uint32 lba; UInt bsize; UInt bs; DeviceInfoStruct *ds; ds = SYS_DeviceInfoStruct(id); if (partition > ds->NumPartitions) return 0; lba = ds->PartitionLBA[partition]; bsize = ds->LargeBlockSize; if (lbsize > bsize) { bs = bsize; // smaller block size is from DeviceInfoStruct while (bs < lbsize) { bs = bs << 1; lba = lba >> 1; } } else { bs = lbsize; // smaller block sice is from FS descriptor while (bs < bsize) { bs = bs << 1; lba = lba << 1; } } return lba;}/*void SYS_ResetDeviceInfoStruct(DeviceInfoStruct *dis){int i; dis->DeviceID=0; dis->DeviceType=(t_duid)0; //M.Ch. dis->DeviceAttr=0; dis->DeviceStatus=DEV_STATUS_UNKNOWN; dis->NumPartitions=0; dis->LargeBlockSize=0; for(i=0;i<MAX_DEV_PARTITIONS;i++) dis->PartitionLBA[i]=0; for(i=0;i<MAX_FS_COUNT;i++) { dis->FS_list[i]=0; dis->FS_desc[i]=NULL; } dis->vpDescript=NULL;}*/FS_DESCRIPTOR * SYS_FSDescriptor(FDID fd){ DeviceInfoStruct *dis; dis = SYS_DeviceInfoStruct(fd & 0xff); if (!dis->FS_list[fd >> 8]) return NULL; return dis->FS_desc[fd >> 8];}void SYS_DeletePartitions(DUID id){ DeviceInfoStruct *dis; int i; dis = SYS_DeviceInfoStruct(id); for (i = 0; i < MAX_DEV_PARTITIONS; i++) dis->PartitionLBA[i] = 0; dis->NumPartitions = 0;}void SYS_SetLargeBlockSize(DUID did, uint16 bsize){ DeviceInfoStruct *dis; dis = SYS_DeviceInfoStruct(did); dis->LargeBlockSize = bsize;}GRESULT SYS_AddPartition(DUID did, uint32 lba){ DeviceInfoStruct *dis; dis = SYS_DeviceInfoStruct(did); if (dis->NumPartitions < (MAX_DEV_PARTITIONS - 1)) { dis->PartitionLBA[dis->NumPartitions] = lba; dis->NumPartitions++; return S_OK; } return E_FAIL;}t_FStype SYS_PreferedFSType(t_duid devid, uint8 check){ switch (devid) { case DEV_CD_ID: if ((check == 1)&&(1==HAVE_UDF)) return FS_UDF_TYPE; if(check==0) return FS_ISO9660_TYPE; break; #if HAVE_FAT#if (0 != HAVE_USB) case DEV_USB_ID:#endif#if (0 != HAVE_SDC) case DEV_SDC_ID:#endif if (check > 0) return FS_INVALID;#if (0 != HAVE_WMDRM) if (USB_is_currnt_device_mtp()) return FS_WMDRM_TYPE;#endif return FS_FAT_TYPE;#endif default: break; } return FS_INVALID;}GRESULT SYS_DetectPartitions(t_duid dev, uint8 *sectbuf){ DUID did; FS_DESCRIPTOR fsdesc_tmp; //filesys_sectbuf - working buffer //fsdesc_tmp - working FS descriptor, only for sector management did = SYS_GetDeviceID(dev); SYS_ClearFSEntries(did); SYS_ClearPartitions(did); switch (dev) { case DEV_CD_ID: if (0 > CD_LastSessionLBA()) return E_FAIL; SYS_DeviceInfoStruct(did)->NumPartitions = 1; SYS_DeviceInfoStruct(did)->PartitionLBA[0] = 0; return S_OK;#if (HAVE_FAT) case DEV_USB_ID: case DEV_SDC_ID:#if (1 == HAVE_WMDRM) if ( USB_is_currnt_device_mtp()) /* MTP device is connected */ { SYS_DeviceInfoStruct(did)->NumPartitions = 1; SYS_DeviceInfoStruct(did)->PartitionLBA[0] = 0; return S_OK; }#endif return FAT_GetPartitions(did, sectbuf, &fsdesc_tmp);#endif } ASSERT(0, "SYS_DetectPartitions unknown device"); return E_FAIL;}DUID SYS_GetDeviceID(t_duid dev){ DUID did = 1; while (did <= SYS_MAX_NUMBER_DEVICES) { if (AP_DeviceTable[did - 1].DeviceType == dev) return did; did++; } return 0; // no device found}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -