/* object instantiation */
struct Module_Hardware_Obj *initInstance_Module_Hardware(void)
{
  struct Module_Hardware_Obj *self;
  /* object instantiation / implicit memory allocation */
  CREATE_OBJECT(self, Module_Hardware);
  return (self);
};
Exemplo n.º 2
0
//Initialize FAT32 partition,this routine is called by CheckPartition,which is then
//called by CreateDevice of IOManager.
static __FAT32_FS* InitFat32(__COMMON_OBJECT* pPartObj)
{
    __DEVICE_OBJECT*  pPartition  = (__DEVICE_OBJECT*)pPartObj;
    __FAT32_FS*       pFatObject = NULL;
    BYTE              buff[SECTOR_SIZE];

    if(NULL == pPartition)
    {
        goto __TERMINAL;
    }

    //Check the validity of partition device object.
    if(DEVICE_OBJECT_SIGNATURE != pPartition->dwSignature)  //Invalid signature.
    {
        goto __TERMINAL;
    }

    if(!ReadDeviceSector(pPartObj,
                         0,
                         1,
                         buff))
    {
        PrintLine("Can not read sector 0.");
        goto __TERMINAL;
    }
    pFatObject = (__FAT32_FS*)CREATE_OBJECT(__FAT32_FS);
    if(NULL == pFatObject)  //Can not create FAT32 object.
    {
        goto __TERMINAL;
    }
    pFatObject->pPartition = pPartObj;    //Very important.
    //Initialize the FAT32 file system.
    if(!Fat32Init(pFatObject,buff))
    {
        PrintLine("Can not initialize the FAT32 file system.");
        RELEASE_OBJECT(pFatObject);       //Release it.
        pFatObject = NULL;
        goto __TERMINAL;
    }
    GetVolumeLbl(pFatObject,pFatObject->VolumeLabel);  //This operation may failed,but we no
    //need to concern it.
    DumpFat32(pFatObject);
__TERMINAL:
    return pFatObject;
}
Exemplo n.º 3
0
//Helper routine used to build the directory cluster list given a name.
//The appropriate find handle is returned if all successfully.
static __FAT32_FIND_HANDLE* BuildFindHandle(__FAT32_FS* pFat32Fs,CHAR* pszDirName)
{
    __FAT32_FIND_HANDLE*    pFindHandle     = NULL;
    __FAT32_DIR_CLUSTER*    pDirCluster     = NULL;
    __FAT32_SHORTENTRY      ShortEntry      = {0};     //Short entry of target dir.
    DWORD                   dwCurrClus      = 0;
    DWORD                   dwSector        = 0;
    BOOL                    bResult         = FALSE;

    if(!GetDirEntry(pFat32Fs,&pszDirName[0],&ShortEntry,NULL,NULL))
    {
        goto __TERMINAL;
    }
    if(!(ShortEntry.FileAttributes & FILE_ATTR_DIRECTORY))  //Not a directory.
    {
        goto __TERMINAL;
    }
    pFindHandle = (__FAT32_FIND_HANDLE*)CREATE_OBJECT(__FAT32_FIND_HANDLE);
    if(NULL == pFindHandle)
    {
        goto __TERMINAL;
    }
    //Initialize the find hanlde object.
    pFindHandle->dwClusterOffset = 0;
    pFindHandle->dwClusterSize   = pFat32Fs->dwClusterSize;
    pFindHandle->pClusterRoot    = NULL;
    pFindHandle->pCurrCluster    = NULL;
    dwCurrClus = ((DWORD)ShortEntry.wFirstClusHi << 16) + (DWORD)ShortEntry.wFirstClusLow;
    while(!IS_EOC(dwCurrClus))
    {
        pDirCluster = (__FAT32_DIR_CLUSTER*)CREATE_OBJECT(__FAT32_DIR_CLUSTER);
        if(NULL == pDirCluster)  //Can not allocate memory.
        {
            goto __TERMINAL;
        }
        pDirCluster->pCluster = (BYTE*)FatMem_Alloc(pFat32Fs->dwClusterSize);
        if(NULL == pDirCluster->pCluster)
        {
            goto __TERMINAL;
        }
        pDirCluster->pNext = NULL;
        //Now try to read the directory cluster data.
        dwSector = GetClusterSector(pFat32Fs,dwCurrClus);
        if(0 == dwSector)
        {
            goto __TERMINAL;
        }
        if(!ReadDeviceSector((__COMMON_OBJECT*)pFat32Fs->pPartition,
                             dwSector,
                             pFat32Fs->SectorPerClus,
                             pDirCluster->pCluster))  //Can not read directory cluster.
        {
            goto __TERMINAL;
        }
        //Attach this cluster into directory cluster list.
        if(NULL == pFindHandle->pClusterRoot)  //First cluster now.
        {
            pFindHandle->pClusterRoot = pDirCluster;
            pFindHandle->pCurrCluster = pDirCluster;
        }
        else  //Not the first cluster,pCurrCluster pointing to the last node.
        {
            pFindHandle->pCurrCluster->pNext = pDirCluster;
            pFindHandle->pCurrCluster        = pDirCluster;
        }
        if(!GetNextCluster(pFat32Fs,&dwCurrClus))
        {
            goto __TERMINAL;
        }
    }
    pFindHandle->pCurrCluster = pFindHandle->pClusterRoot;
    pDirCluster = NULL;  //Indicate the successful execution of above while block.
    bResult = TRUE;  //Mark the successful flag.

__TERMINAL:
    if(bResult)  //Successful.
    {
        return pFindHandle;
    }
    else  //Failed,should release the allocated resource.
    {
        if(pDirCluster)  //Directory cluster object has been allocated.
        {
            if(pDirCluster->pCluster)
            {
                FatMem_Free(pDirCluster->pCluster);
            }
            FatMem_Free(pDirCluster);
        }
        //Release the directory cluster object in list.
        if(NULL == pFindHandle)
        {
            goto __RETURN;
        }
        while(pFindHandle->pClusterRoot)
        {
            pFindHandle->pCurrCluster = pFindHandle->pClusterRoot;
            pFindHandle->pClusterRoot = pFindHandle->pClusterRoot->pNext;
            if(pFindHandle->pCurrCluster->pCluster)
            {
                FatMem_Free(pFindHandle->pCurrCluster->pCluster);
            }
            FatMem_Free(pFindHandle->pCurrCluster);
        }

        //Release the find handle object.
        FatMem_Free(pFindHandle);

__RETURN:

        return NULL;
    }
}
Exemplo n.º 4
0
//Implementation of CreateFile for FAT file system.
static __COMMON_OBJECT* FatDeviceOpen(__COMMON_OBJECT* lpDrv,
                                      __COMMON_OBJECT* lpDev,
                                      __DRCB* lpDrcb)   //Open file.
{
    __FAT32_FILE*       pFat32File    = NULL;
    __FAT32_FS*         pFat32Fs      = NULL;
    __COMMON_OBJECT*    pFileDevice   = NULL;
    CHAR                FileName[MAX_FILE_NAME_LEN];
    __FAT32_SHORTENTRY  ShortEntry;
    DWORD               dwDirClus     = 0;
    DWORD               dwDirOffset   = 0;
    DWORD               dwFlags;
    static CHAR         NameIndex     = 0;
    BOOL                bResult       = FALSE;
    CHAR                FileDevName[16];

    if((NULL == lpDrv) || (NULL == lpDev))
    {
        goto __TERMINAL;
    }
    pFat32Fs = (__FAT32_FS*)(((__DEVICE_OBJECT*)lpDev)->lpDevExtension);
    //strcpy(FileName,(LPSTR)lpDrcb->lpInputBuffer);
    StrCpy((LPSTR)lpDrcb->lpInputBuffer,FileName);
    ToCapital(FileName);
    if(!GetDirEntry(pFat32Fs,&FileName[0],&ShortEntry,&dwDirClus,&dwDirOffset))
    {
        goto __TERMINAL;
    }

    if(FILE_ATTR_DIRECTORY & ShortEntry.FileAttributes)  //Is a directory.
    {
        goto __TERMINAL;
    }
    //Create a file object.
    pFat32File = (__FAT32_FILE*)CREATE_OBJECT(__FAT32_FILE);
    if(NULL == pFat32File)
    {
        goto __TERMINAL;
    }
    pFat32File->Attributes     = ShortEntry.FileAttributes;
    pFat32File->dwClusOffset   = 0;
    pFat32File->bInRoot        = FALSE;          //Caution,not check currently.
    pFat32File->dwCurrClusNum  = ((DWORD)ShortEntry.wFirstClusHi << 16)
                                 + (DWORD)ShortEntry.wFirstClusLow;
    pFat32File->dwCurrPos      = 0;
    pFat32File->dwFileSize     = ShortEntry.dwFileSize;
    pFat32File->dwOpenMode     = lpDrcb->dwInputLen;     //dwInputLen is used to contain open mode.
    pFat32File->dwShareMode    = lpDrcb->dwOutputLen;    //dwOutputLen is used to contain share mode.
    pFat32File->dwStartClusNum = pFat32File->dwCurrClusNum;
    pFat32File->pFileSystem    = pFat32Fs;
    pFat32File->pPartition     = pFat32Fs->pPartition;   //CAUTION!!!
    pFat32File->dwParentClus   = dwDirClus;              //Save parent directory's information.
    pFat32File->dwParentOffset = dwDirOffset;
    pFat32File->pNext          = NULL;
    pFat32File->pPrev          = NULL;
    //Now insert the file object to file system object's file list.
    __ENTER_CRITICAL_SECTION(NULL,dwFlags);
    if(pFat32Fs->pFileList == NULL)  //Not any file object in list yet.
    {
        pFat32Fs->pFileList = pFat32File;
        pFat32File->pNext = NULL;
        pFat32File->pPrev = NULL;
    }
    else
    {
        pFat32File->pNext = pFat32Fs->pFileList;
        pFat32Fs->pFileList->pPrev = pFat32File;

        pFat32File->pPrev = NULL;
        pFat32Fs->pFileList = pFat32File;
    }
    __LEAVE_CRITICAL_SECTION(NULL,dwFlags);
    //Now create file device object.
    //strcpy(FileDevName,FAT32_FILE_NAME_BASE);
    StrCpy(FAT32_FILE_NAME_BASE,FileDevName);
    FileDevName[13] += NameIndex;
    NameIndex ++;
    pFileDevice = (__COMMON_OBJECT*)IOManager.CreateDevice((__COMMON_OBJECT*)&IOManager,
                  FileDevName,
                  DEVICE_TYPE_FILE,
                  1, //For file,block size is 1.
                  DEVICE_BLOCK_SIZE_ANY,
                  DEVICE_BLOCK_SIZE_ANY,
                  pFat32File,
                  (__DRIVER_OBJECT*)lpDrv);
    if(NULL == pFileDevice)
    {
        goto __TERMINAL;
    }
    bResult = TRUE;
__TERMINAL:
    if(!bResult)  //The transaction has failed.
    {
        if(pFat32File)
        {
            RELEASE_OBJECT(pFat32File);
        }
        if(pFileDevice)
        {
            IOManager.DestroyDevice((__COMMON_OBJECT*)&IOManager,
                                    (__DEVICE_OBJECT*)pFileDevice);
        }
        return NULL;
    }
    return pFileDevice;
}
Exemplo n.º 5
0
//---------------------------------------------------------------------------
void ShowError(JSContext *cx, const char *message, JSErrorReport *report) {
    int  where;
    char *cstr;

    void                   *CREPORT;
    INVOKE_CALL            Invoke      = InvokePtr;
    CALL_BACK_VARIABLE_SET SetVariable = _SetVariable;
    void                   *HANDLER    = CONCEPT_HANDLER;

    if (!ERR_DELEGATE) {
        printError(cx, message, report);
        return;
    }

    CREATE_VARIABLE(CREPORT);

    if (!CREATE_OBJECT(CREPORT, "JSErrorReport"))
        return;    // (void *)"Failed to INVOKE_CREATE_OBJECT";


    void *member = 0;

    if (!IS_OK(GET_MEMBER_VAR(CREPORT, "filename", member)))
        return;

    SET_STRING_VARIABLE(member, report->filename);

    if (!IS_OK(GET_MEMBER_VAR(CREPORT, "lineno", member)))
        return;

    SET_NUMBER_VARIABLE(member, report->lineno);

    if (!IS_OK(GET_MEMBER_VAR(CREPORT, "linebuf", member)))
        return;

    SET_STRING_VARIABLE(member, (char *)report->linebuf);

    if (!IS_OK(GET_MEMBER_VAR(CREPORT, "tokenptr", member)))
        return;

    SET_STRING_VARIABLE(member, (char *)report->tokenptr);

    if (!IS_OK(GET_MEMBER_VAR(CREPORT, "uclinebuf", member)))
        return;

    SET_STRING_VARIABLE(member, (char *)report->linebuf);

    if (!IS_OK(GET_MEMBER_VAR(CREPORT, "uctokenptr", member)))
        return;

    SET_STRING_VARIABLE(member, (char *)report->tokenptr);

    if (!IS_OK(GET_MEMBER_VAR(CREPORT, "flags", member)))
        return;

    SET_NUMBER_VARIABLE(member, report->flags);

    if (!IS_OK(GET_MEMBER_VAR(CREPORT, "errorNumber", member)))
        return;

    SET_NUMBER_VARIABLE(member, report->errorNumber);

    if (!IS_OK(GET_MEMBER_VAR(CREPORT, "ucmessage", member)))
        return;

    SET_STRING_VARIABLE(member, message);

    if (!IS_OK(GET_MEMBER_VAR(CREPORT, "messageArgs", member)))
        return;

    CREATE_ARRAY(member);

    /*int i=0;
       char **messageArg=report->messageArgs ? report->messageArgs[i] : 0;
       while (messageArg) {
       Invoke(INVOKE_SET_ARRAY_ELEMENT,member,(INTEGER)i,(INTEGER)VARIABLE_STRING,(char *)messageArg,(NUMBER)0);
       messageArg=report->messageArgs[++i];
       }*/
    // call delegate
    CALL_DELEGATE(ERR_DELEGATE, (INTEGER)3, (INTEGER)VARIABLE_NUMBER, (char *)"", (NUMBER)(SYS_INT)cx, (INTEGER)VARIABLE_STRING, (char *)message, (NUMBER)0, (INTEGER)VARIABLE_UNDEFINED, CREPORT);
    FREE_VARIABLE(CREPORT);
}
Exemplo n.º 6
0
//For each extension partition in hard disk,this function travels the
//extension partition table list,to install one by one into IOManager.
//How many logical partition(s) is returned.
static int InitExtension(int nHdNum,          //The hard disk number.
						 BYTE* pSector0,      //First sector of extension partition.
						 DWORD dwStartSector, //Position of this partition,in physical disk.
						 DWORD dwExtendStart, //Start position of extension partition.
						 int nBaseNumber,     //The partition base number.
						 __DRIVER_OBJECT* lpDrvObject)
{
	__DEVICE_OBJECT* pDevObject = NULL;
	__PARTITION_EXTENSION* pPe = NULL;
	BYTE* pStart = NULL;
	BYTE  buffer[512];  //Buffer used to read one sector.
	DWORD dwNextStart;  //Next extension's start sector if any.
	DWORD dwAttributes = DEVICE_TYPE_PARTITION;
	CHAR strDevName[MAX_DEV_NAME_LEN + 1];
	DWORD dwFlags;
	int nPartitionNum = 0;

	if((NULL == pSector0) || (NULL == lpDrvObject)) //Invalid parameters.
	{
		goto __TERMINAL;
	}
	//Locate the partition table's position.
	pStart = pSector0 + 0x1BE;
	if(0 == *(pStart + 4)) //Partition type is zero,invalid.
	{
		goto __TERMINAL;
	}
	//Now create the partition extension object and initialize it.
	pPe = (__PARTITION_EXTENSION*)CREATE_OBJECT(__PARTITION_EXTENSION);
	if(NULL == pPe)
	{
		goto __TERMINAL;
	}
	pPe->dwCurrPos     = 0;
	pPe->BootIndicator = *pStart;
	pStart += 4;
	pPe->PartitionType = *pStart;
	pStart += 4;
	pPe->dwStartSector = *(DWORD*)pStart;
	pStart += 4;
	pPe->dwSectorNum   = *(DWORD*)pStart;
	pStart += 4;  //Now pStart pointing to next partition entry.
	//Validate if all parameters are correct.
	if((pPe->dwStartSector == 0)  ||  //Should invalid.
	   (pPe->dwSectorNum   == 0))     //Impossible.
	{
		goto __TERMINAL;
	}
	switch(pPe->PartitionType)
	{
	case 0x0B:  //FAT32
	case 0x0C:  //FAT32
	case 0x0E:
		dwAttributes |= DEVICE_TYPE_FAT32;
		break;
	case 0x07:
		dwAttributes |= DEVICE_TYPE_NTFS;
		break;
	default:
		break;
	}
	pPe->dwStartSector += dwStartSector;  //Adjust the start sector to physical one.
	//Partiton information is OK,now create the device object.
	StrCpy(PARTITION_NAME_BASE,strDevName); //Form device name.
	__ENTER_CRITICAL_SECTION(NULL, dwFlags);
	strDevName[StrLen(PARTITION_NAME_BASE) - 1] += (CHAR)IOManager.dwPartitionNumber;
	IOManager.dwPartitionNumber += 1;
	__LEAVE_CRITICAL_SECTION(NULL, dwFlags);
	pDevObject = IOManager.CreateDevice(
		(__COMMON_OBJECT*)&IOManager,
		strDevName,
		dwAttributes,
		512,
		16384,
		16384,
		pPe,
		lpDrvObject);
	nPartitionNum += 1;

	//Now check the next table entry to see if there is another extension embeded.
	if(*(pStart + 4) == 0x05)  //Is a extension partition.
	{
		dwNextStart = dwExtendStart + (*(DWORD*)(pStart + 8));
		if(!ReadSector(
			nHdNum,
			dwNextStart,
			1,
			buffer))
		{
			goto __TERMINAL;
		}
		nPartitionNum += InitExtension(
			nHdNum,
			buffer,
			pPe->dwStartSector + pPe->dwSectorNum,//dwStartSector,
			dwExtendStart,
			nBaseNumber + 1,
			lpDrvObject);
	}

__TERMINAL:
	if(0 == nPartitionNum)  //Not any logical partiton is created.
	{
		if(pPe)
		{
			RELEASE_OBJECT(pPe);
		}
		if(pDevObject)
		{
			IOManager.DestroyDevice((__COMMON_OBJECT*)&IOManager,
				pDevObject);
		}
	}
	return nPartitionNum;
}
Exemplo n.º 7
0
//This function travels all partition table in sector 0 in current
//hard disk,from the MBR,to install each primary partition into IOManager.
//For extension partition,it calls InitExtension function to install.
static int InitPartitions(int nHdNum,
						  BYTE* pSector0,
						  __DRIVER_OBJECT* lpDrvObject)
{
	static int nPartNum = 0;  //How many partitons in current system.
	__DEVICE_OBJECT* pDevObject = NULL;
	__PARTITION_EXTENSION* pPe  = NULL;
	BYTE* pStart                = NULL;
	DWORD dwStartSector;  //Used to seek next partition.
	DWORD dwAttributes = DEVICE_TYPE_PARTITION;
	CHAR strDevName[MAX_DEV_NAME_LEN + 1];
	int i;
	DWORD dwFlags;
	BYTE Buff[512];

	if((NULL == pSector0) || (NULL == lpDrvObject))  //Invalid parameter.
	{
		return 0;
	}
	pStart = pSector0 + 0x1be;  //Locate to the partition table start position.
	for(i = 0;i < 4;i ++) //Analyze each partition table entry.
	{
		if(*(pStart + 4) == 0) //Table entry is empty.
		{
			break;
		}
		if(*(pStart + 4) == 0x0F)  //Extension partiton.
		{
			dwStartSector = *(DWORD*)(pStart + 8);
			if(!ReadSector(nHdNum,dwStartSector,1,Buff))
			{
				break;
			}
			nPartNum += InitExtension(nHdNum,
				Buff,
				dwStartSector,
				dwStartSector,
				i,
				lpDrvObject);
			pStart += 16;  //Pointing to next partition table entry.
			continue;
		}
		pPe = (__PARTITION_EXTENSION*)CREATE_OBJECT(__PARTITION_EXTENSION);
		if(NULL == pPe)  //Can not create object.
		{
			break;
		}
		pPe->dwCurrPos     = 0;
		pPe->BootIndicator = *pStart;
		pStart += 4;
		pPe->PartitionType = *pStart;
		pStart += 4;
		pPe->dwStartSector = *(DWORD*)pStart;
		pStart += 4;
		pPe->dwSectorNum   = *(DWORD*)pStart;
		pStart += 4;  //Pointing to next partition table entry.
		switch(pPe->PartitionType)
		{
		case 0x0B:   //FAT32.
		case 0x0C:   //Also FAT32.
		case 0x0E:   //FAT32 also.
			dwAttributes |= DEVICE_TYPE_FAT32;
			break;
		case 0x07:
			dwAttributes |= DEVICE_TYPE_NTFS;
			break;
		default:
			break;
		}

		//Create device object for this partition.
		//strcpy(strDevName,PARTITION_NAME_BASE);  // -------- CAUTION !!! ---------
		StrCpy(PARTITION_NAME_BASE,strDevName);
		__ENTER_CRITICAL_SECTION(NULL, dwFlags);
		strDevName[StrLen(PARTITION_NAME_BASE) - 1] += (BYTE)IOManager.dwPartitionNumber;
		IOManager.dwPartitionNumber += 1;
		__LEAVE_CRITICAL_SECTION(NULL, dwFlags);
		nPartNum ++;  //Increment the partition number.
		pDevObject = IOManager.CreateDevice(
			(__COMMON_OBJECT*)&IOManager,
			strDevName,
			dwAttributes,
			512,
			16384,
			16384,
			pPe,
			lpDrvObject);
		if(NULL == pDevObject)  //Can not create device object.
		{
			RELEASE_OBJECT(pPe);
			break;
		}
		dwAttributes = DEVICE_TYPE_PARTITION;  //Reset to default value,very important.
	}
	return nPartNum;
}