Ejemplo n.º 1
0
//Implementation of CreateDirectory.
BOOL APIENTRY AddDirToVhd(HANDLE hVhdObj,LPCSTR pDirName)    //Create directory.
{
	DWORD                    dwDirCluster                  = 0;
	CHAR                     DirName[MAX_FILE_NAME_LEN]    = {0};
	CHAR                     SubDirName[MAX_FILE_NAME_LEN] = {0};
	__FAT32_SHORTENTRY       DirShortEntry                 = {0};
	__FAT32_FS*              pFat32Fs                      = (__FAT32_FS*)hVhdObj;
	

	if((NULL == pFat32Fs) || (NULL == pDirName))
	{
		return FALSE;
	}

	if(!GetPathName((LPSTR)pDirName,DirName,SubDirName))
	{
		return FALSE;
	}

	//Try to open the parent directory.
	if(!GetDirEntry(pFat32Fs,DirName,&DirShortEntry,NULL,NULL))
	{	
		return FALSE;
	}

	if(!(DirShortEntry.FileAttributes & FILE_ATTR_DIRECTORY))  //Is not a directory.
	{
		return FALSE;
	}

	dwDirCluster = MAKELONG(DirShortEntry.wFirstClusLow,DirShortEntry.wFirstClusHi);

	return CreateFatDir(pFat32Fs,dwDirCluster,SubDirName,0);
}
Ejemplo n.º 2
0
long GetFileInfo(const char * dirSpec, const char * name,
                 long * flags, long * time)
{
    long         index = 0;
    const char * entryName;

    if (gMakeDirSpec == 0)
        gMakeDirSpec = (char *)malloc(1024);

    if (!dirSpec) {
        long       idx, len;

        len = strlen(name);

        for (idx = len; idx && (name[idx] != '/' && name[idx] != '\\'); idx--) {}
        if (idx == 0) {
            gMakeDirSpec[0] = '/';
            gMakeDirSpec[1] = '\0';
        } else {
            idx++;
            strncpy(gMakeDirSpec, name, idx);
            name += idx;
        }
        dirSpec = gMakeDirSpec;
    }

    while (GetDirEntry(dirSpec, &index, &entryName, flags, time) == 0)
    {
        if (strcmp(entryName, name) == 0)
            return 0;  // success
    }
    return -1;  // file not found
}
Ejemplo n.º 3
0
uffs_DIR * uffs_opendir(const char *path)
{
    int err = 0;
    uffs_DIR *ret = NULL;
    uffs_DIR *dirp = GetDirEntry();

    if (dirp) {
        dirp->obj = uffs_GetObject();
        if (dirp->obj) {
            if (uffs_OpenObject(dirp->obj, path, UO_RDONLY | UO_DIR) == U_SUCC) {
                if (uffs_FindObjectOpen(&dirp->f, dirp->obj) == U_SUCC) {
                    ret = dirp;
                    goto ext;
                } else {
                    uffs_CloseObject(dirp->obj);
                }
            } else {
                err = uffs_GetObjectErr(dirp->obj);
            }
            uffs_PutObject(dirp->obj);
            dirp->obj = NULL;
        } else {
            err = UEMFILE;
        }
        PutDirEntry(dirp);
    } else {
        err = UEMFILE;
    }
ext:
    uffs_set_error(-err);
    return ret;
}
Ejemplo n.º 4
0
//Implementation of _fat32GetFileAttributes.
static DWORD _fat32GetFileAttributes(__COMMON_OBJECT* lpDev, LPCTSTR  pszFileName)  //Get file's attribute.
{
    __FAT32_FS*         pFat32Fs      = NULL;
    CHAR                FileName[MAX_FILE_NAME_LEN];
    __FAT32_SHORTENTRY  ShortEntry;
    DWORD               dwFileAttributes = 0;

    if((NULL == pszFileName) || (NULL == lpDev))
    {
        goto __TERMINAL;
    }
    pFat32Fs = (__FAT32_FS*)(((__DEVICE_OBJECT*)lpDev)->lpDevExtension);
    //strcpy(FileName,(LPSTR)lpDrcb->lpInputBuffer);
    StrCpy((CHAR*)pszFileName,FileName);
    ToCapital(FileName);
    if(!GetDirEntry(pFat32Fs,&FileName[0],&ShortEntry,NULL,NULL))
    {
        _hx_printf("In _fat32GetFileAttributes: Can not get directory entry.\n%s\n",FileName);
        goto __TERMINAL;
    }
    dwFileAttributes = ShortEntry.FileAttributes;

__TERMINAL:
    return dwFileAttributes;
}
Ejemplo n.º 5
0
Archivo: fs.c Proyecto: aosm/BootX
long GetFileInfo(char *dirSpec, char *name, long *flags, long *time)
{
  long ret;
  unsigned long index = 0;
  char *curName;

  if (!dirSpec) {
    long       idx, len;

    len = strlen(name);

    for (idx = len; idx && (name[idx] != '\\'); idx--) {}
    idx++;
    strncpy(gMakeDirSpec, name, idx);
    name += idx;
    dirSpec = gMakeDirSpec;
  }
  
  while (1) {
    ret = GetDirEntry(dirSpec, &index, &curName, flags, time);
    if (ret == -1) break;
    
    if (!strcmp(name, curName)) break;
  }
  
  return ret;
}
Ejemplo n.º 6
0
//Delete a subdirectory in a given directory.
BOOL DeleteFatDir(__FAT32_FS* pFat32Fs,CHAR* pszFileName)
{
	__FAT32_SHORTENTRY         ShortEntry;
	__FAT32_SHORTENTRY*        pFileEntry     = NULL;
	DWORD                      dwParentClus   = 0;
	DWORD                      dwParentOffset = 0;
	DWORD                      dwStartClus    = 0;
	DWORD                      dwSector       = 0;
	BOOL                       bResult        = FALSE;
	BYTE*                      pBuffer        = NULL;

	if(!GetDirEntry(pFat32Fs,
		pszFileName,
		&ShortEntry,
		&dwParentClus,    //Parent directory's cluster where this entry resides.
		&dwParentOffset)) //Cluster offset.
	{
		goto __TERMINAL;
	}
	if(0 == (FILE_ATTR_DIRECTORY & ShortEntry.FileAttributes))  //Not a directory.
	{
		goto __TERMINAL;
	}
	//Remove the directory entry in it's parent directory.
	pBuffer = (BYTE*)KMemAlloc(pFat32Fs->dwClusterSize,KMEM_SIZE_TYPE_ANY);
	if(NULL == pBuffer)
	{
		goto __TERMINAL;
	}
	dwSector = GetClusterSector(pFat32Fs,dwParentClus);
	if(0 == dwSector)
	{
		goto __TERMINAL;
	}
	if(!ReadDeviceSector((__COMMON_OBJECT*)pFat32Fs->pPartition,
		dwSector,
		pFat32Fs->SectorPerClus,
		pBuffer))
	{
		goto __TERMINAL;
	}
	pFileEntry = (__FAT32_SHORTENTRY*)(pBuffer + dwParentOffset);
	memzero(pFileEntry,sizeof(__FAT32_SHORTENTRY));
	pFileEntry->FileName[0] = (CHAR)0xE5;   //Empty this short entry.
	if(!WriteDeviceSector((__COMMON_OBJECT*)pFat32Fs->pPartition,
		dwSector,
		pFat32Fs->SectorPerClus,
		pBuffer))
	{
		goto __TERMINAL;
	}
	bResult = TRUE;
__TERMINAL:
	if(pBuffer)
	{
		KMemFree(pBuffer,KMEM_SIZE_TYPE_ANY,0);
	}
	return bResult;
}
Ejemplo n.º 7
0
long
FileLoadDrivers( char * dirSpec, long plugin )
{
    long         ret, length, flags, time, bundleType;
    long long	 index;
    long         result = -1;
    const char * name;
 
    if ( !plugin )
    {
        // First try 10.6's path for loading Extensions.mkext.
        if (FileLoadMKext(dirSpec, "Caches/com.apple.kext.caches/Startup/") == 0)
            return 0;

        // Next try the legacy path.
        else if (FileLoadMKext(dirSpec, "") == 0)
          return 0;

        strcat(dirSpec, "Extensions");
    }

    index = 0;
    while (1) {
        ret = GetDirEntry(dirSpec, &index, &name, &flags, &time);
        if (ret == -1) break;

        // Make sure this is a directory.
        if ((flags & kFileTypeMask) != kFileTypeDirectory) continue;
        
        // Make sure this is a kext.
        length = strlen(name);
        if (strcmp(name + length - 5, ".kext")) continue;

        // Save the file name.
        strcpy(gFileName, name);
    
        // Determine the bundle type.
        sprintf(gTempSpec, "%s/%s", dirSpec, gFileName);
        ret = GetFileInfo(gTempSpec, "Contents", &flags, &time);
        if (ret == 0) bundleType = kCFBundleType2;
        else bundleType = kCFBundleType3;

        if (!plugin)
            sprintf(gDriverSpec, "%s/%s/%sPlugIns", dirSpec, gFileName,
                    (bundleType == kCFBundleType2) ? "Contents/" : "");

        ret = LoadDriverPList(dirSpec, gFileName, bundleType);

        if (result != 0)
          result = ret;

        if (!plugin) 
          FileLoadDrivers(gDriverSpec, 1);
    }

    return result;
}
Ejemplo n.º 8
0
long GetFileInfo(char *dirSpec, char *name, long *flags, long *time)
{
    long ret, index = 0;
    char *curName;

    while (1) {
        ret = GetDirEntry(dirSpec, &index, &curName, flags, time);
        if (ret == -1) break;
        if (!strcmp(name, curName)) break;
    }
    return ret;
}
Ejemplo n.º 9
0
BOOL APIENTRY AddFileToVhd(HANDLE hVhdObj,LPCSTR pSrcFile,LPCSTR pDstFile)
{
	__FAT32_FS*         pFat32Fs                    = (__FAT32_FS*)hVhdObj;
	__FAT32_FILE*       pFat32File                  = NULL; 
	__FAT32_SHORTENTRY  DirShortEntry               = {0};
	CHAR                DirName[MAX_FILE_NAME_LEN]  = {0};
	CHAR                FileName[MAX_FILE_NAME_LEN] = {0};
	CHAR*               pszFileName                 = (CHAR*)pDstFile;	
	DWORD               dwDirCluster                = 0;
	DWORD               dwResult                    = 0;


	if(pFat32Fs == NULL)
	{
		return FALSE;
	}
		
	if(!GetPathName(pszFileName,DirName,FileName) || strlen(FileName) <= 0)
	{
		return FALSE;
	}
	
	//Try to open the parent directory.
	if(!GetDirEntry(pFat32Fs,DirName,&DirShortEntry,NULL,NULL))
	{	
		return FALSE;
	}

	if(!(DirShortEntry.FileAttributes & FILE_ATTR_DIRECTORY))  //Is not a directory.
	{
		return FALSE;
	}
	dwDirCluster =   DirShortEntry.wFirstClusHi;
	dwDirCluster <<= 16;
	dwDirCluster +=  DirShortEntry.wFirstClusLow;

	if(!CreateFatFile(pFat32Fs,	dwDirCluster,FileName,0))
	{
		return FALSE;		
	}
		
	pFat32File  = OpenFat32File(pFat32Fs,pszFileName);	
	if(pFat32File)
	{
		//Now start writefile
		WriteFileToVhd(pFat32Fs,pFat32File,pSrcFile);
		
		LocalFree(pFat32File);
	}


	return TRUE;
}
Ejemplo n.º 10
0
long DumpDir(char *dirSpec)
{
    long ret, flags, time, index = 0;
    char *name;

    printf("DumpDir on [%s]\n", dirSpec);

    while (1) {
        ret = GetDirEntry(dirSpec, &index, &name, &flags, &time);
        if (ret == -1) break;

        printf("%x %x [%s]\n", flags, time, name);
    }

    return 0;
}
Ejemplo n.º 11
0
  bool GetU16FullName(mozilla::u16string& aU16FullName)
  {
    const TableDirEntry* dirEntry =
      GetDirEntry(TRUETYPE_TAG('n', 'a', 'm', 'e'));
    if (!dirEntry) {
      gfxWarning() << "Name table entry not found.";
      return false;
    }

    UniquePtr<SFNTNameTable> nameTable =
      SFNTNameTable::Create((mFontData + dirEntry->offset), dirEntry->length);
    if (!nameTable) {
      return false;
    }

    return nameTable->GetU16FullName(aU16FullName);
  }
Ejemplo n.º 12
0
long GetFileInfo(const char * dirSpec, const char * name, long * flags, long * time)
{
	long long index = 0;
	const char * entryName;

	if (gMakeDirSpec == 0)
	{
		gMakeDirSpec = (char *)malloc(1024);
	}

	if (!dirSpec)
	{
		long       idx, len;

		len = strlen(name);

        for (idx = len; idx && (name[idx] != '/' && name[idx] != '\\'); idx--) {}
		if (idx == 0)
		{
			if(name[idx] == '/' || name[idx] == '\\') ++name;   // todo: ensure other functions handel \ properly
			gMakeDirSpec[0] = '/';
			gMakeDirSpec[1] = '\0';
			gMakeDirSpec[idx] = '\0';
		}
		else
		{
			idx++;
			strncpy(gMakeDirSpec, name, idx);
			gMakeDirSpec[idx] = '\0'; // ISSUE: http://forge.voodooprojects.org/p/chameleon/issues/270/
			name += idx;
		}

		dirSpec = gMakeDirSpec;
	}

	while (GetDirEntry(dirSpec, &index, &entryName, flags, time) == 0)
	{
		if (strcmp(entryName, name) == 0)
		{
			return 0;  // success
		}
	}

	return -1;  // file not found
}
Ejemplo n.º 13
0
//Implementation of CreateDirectory.
static BOOL _CreateDirectory(__COMMON_OBJECT* lpDev,
                             CHAR*   pszFileName,
                             LPVOID  pReserved)    //Create directory.
{
    __DEVICE_OBJECT*         pFatDevice = (__DEVICE_OBJECT*)lpDev;
    DWORD                    dwDirCluster = 0;
    CHAR                     DirName[MAX_FILE_NAME_LEN];
    CHAR                     SubDirName[MAX_FILE_NAME_LEN];
    __FAT32_SHORTENTRY       DirShortEntry;

    if((NULL == pFatDevice) || (NULL == pszFileName))
    {
        return FALSE;
    }
    if(!GetPathName(pszFileName,DirName,SubDirName))
    {
        return FALSE;
    }


    //Try to open the parent directory.
    if(!GetDirEntry((__FAT32_FS*)pFatDevice->lpDevExtension,	DirName,&DirShortEntry,NULL,NULL))
    {
        PrintLine("Can not get directory entry of parent dir.");
        return FALSE;
    }

    //return FALSE;
    if(!(DirShortEntry.FileAttributes & FILE_ATTR_DIRECTORY))  //Is not a directory.
    {
        PrintLine("The parent directory is not a directory.");
        return FALSE;
    }
    dwDirCluster =   DirShortEntry.wFirstClusHi;
    dwDirCluster <<= 16;
    dwDirCluster +=  DirShortEntry.wFirstClusLow;


    return CreateFatDir((__FAT32_FS*)pFatDevice->lpDevExtension,	dwDirCluster,SubDirName,FILE_ATTR_DIRECTORY);
}
Ejemplo n.º 14
0
static LONG
PathWalk(Global_T *g, 
	 UBYTE *FullName,
	 LONG FullNameLen,
	 UBYTE *LinkPath,	/* Buf to get result into, IN/OUTPUT name of LINK */
	 ULONG BufLen,		/* length of buf above */
	 LONG *Res2)		/* OUTPUT */
{
    UBYTE *PComp; /* points to current path component */
    UBYTE *WorkPath = NULL;
    DCEntry *ParDir, *ActDir;
    NEntry *ActNEnt;
    ACEntry *ACE;
    LONG LastElement = 0; /* flag: if set, last element of directory is found */
    /* (init important !) */
    LONG Pos = 0; /* fn_ScanPath needs this as buffer */
    /* (init important !) */
    LONG Res = 1;

    D(DBF_ALWAYS, "\tPathWalk(\"%s\")", FullName);

    WorkPath = StrNDup(FullName, FullNameLen); /* we will modify WorkPath */
    if(!WorkPath)
    {
	*Res2 = ERROR_NO_FREE_STORE;
	Res = 0;
	
    }
    else
    {
	/* get (cached) root handle */
	ParDir = GetDirEntry(g, 
			     NULL, /* no name entry */
			     g->g_MntAttr.fileid,
			     &g->g_MntFh,
			     NULL, /* currently not used */
			     Res2);
	if(ParDir)
	{
	    if(FullNameLen)	/* Filename != "" */
	    {
		do
		{
		    PComp = fn_ScanPath(WorkPath, FullNameLen,
					&Pos, &LastElement);
		    ASSERT(PComp);

		    D(DBF_ALWAYS,"\tPComp = \"%s\"", PComp);
		    if(*PComp == '/') /* goto parent dir, not allowed in this 
					 version, must be unified path ! */
		    {
			    E(DBF_ALWAYS, "FIXME: *** parent dir reference not allowed !!");
			    Res = 0;
			    break;
		    }
		    ActNEnt = GetNameEntry(g, ParDir, PComp, &ACE, Res2);
		    if(!ActNEnt)
		    {
			Res = 0;
			break;
		    }

		    if((ActNEnt->ne_FType != NFDIR)
		       && (ActNEnt->ne_FType != NFLNK))
		    {
			*Res2 = ERROR_INVALID_COMPONENT_NAME;
			Res = 0;
			break;
		    }
		    if(ActNEnt->ne_FType == NFLNK)
		    {
			nfspath u_lpath;
		    
			ASSERT(ACE);
			ASSERT(LinkPath);
			u_lpath = nfs_ReadLink(g->g_NFSClnt,
					       &ACE->ace_NFSFh, Res2);
			if(u_lpath)
			{
			    D(DBF_ALWAYS,"\treadlink returned: %s", u_lpath);
#if 0
			    if(UseUnixLinks(g))
				;
#endif
			    if(fn_InsertLink(LinkPath,
					     BufLen,
					     g->g_VolumeName,
					     FullName,
					     PComp-WorkPath,
					     strlen(PComp),
					     u_lpath,
					     Res2) == NULL)
			    {
				if(*Res2 == ERROR_NO_FREE_STORE)
				    Res = -1;
				else
				    Res = 0;
			    }
			    else
				Res = 2;
			}
			else
			{
			    Res = 0;
			}
			break;
		    }
		    /* note: GetDirEntry will modify ActNEnt if necessary */
		    ActDir = GetDirEntry(g, 
					 ActNEnt,
					 DCE_ID_UNUSED,
					 &ACE->ace_NFSFh,
					 PComp,
					 Res2);
		    ParDir = ActDir;
		} while(!LastElement && ParDir);
	    }
	    else
	    {			/* filename: "" */
		LinkPath[0] = 0;
		Res = 1;
	    }
	}
	else
	    Res = 0;
	fn_Delete(&WorkPath);
    }
    return Res;
}
Ejemplo n.º 15
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;
    }
}
Ejemplo n.º 16
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;
}
Ejemplo n.º 17
0
static long
FileLoadDrivers( char * dirSpec, long plugin )
{
    long         ret, length, index, flags, time, bundleType;
    const char * name;

    if ( !plugin )
    {
        long time2;

        ret = GetFileInfo(dirSpec, "Extensions.mkext", &flags, &time);
        if ((ret == 0) && ((flags & kFileTypeMask) == kFileTypeFlat))
        {
            ret = GetFileInfo(dirSpec, "Extensions", &flags, &time2);
            if ((ret != 0) || ((flags & kFileTypeMask) != kFileTypeDirectory) ||
                (((gBootMode & kBootModeSafe) == 0) && (time == (time2 + 1))))
            {
                sprintf(gDriverSpec, "%sExtensions.mkext", dirSpec);
                verbose("LoadDrivers: Loading from [%s]\n", gDriverSpec);
                if (LoadDriverMKext(gDriverSpec) == 0) return 0;
            }
        }

        strcat(dirSpec, "Extensions");
    }

    verbose("LoadDrivers: Loading from [%s]\n", dirSpec);

    index = 0;
    while (1) {
        ret = GetDirEntry(dirSpec, &index, &name, &flags, &time);
        if (ret == -1) break;

        // Make sure this is a directory.
        if ((flags & kFileTypeMask) != kFileTypeDirectory) continue;
        
        // Make sure this is a kext.
        length = strlen(name);
        if (strcmp(name + length - 5, ".kext")) continue;

        // Save the file name.
        strcpy(gFileName, name);
    
        // Determine the bundle type.
        sprintf(gTempSpec, "%s/%s", dirSpec, gFileName);
        ret = GetFileInfo(gTempSpec, "Contents", &flags, &time);
        if (ret == 0) bundleType = kCFBundleType2;
        else bundleType = kCFBundleType3;

        if (!plugin)
            sprintf(gDriverSpec, "%s/%s/%sPlugIns", dirSpec, gFileName,
                    (bundleType == kCFBundleType2) ? "Contents/" : "");

        ret = LoadDriverPList(dirSpec, gFileName, bundleType);
        if (ret != 0)
        {
            //printf("LoadDrivers: failed for '%s'/'%s'\n", dirSpec, gFileName);
        }

        if (!plugin) 
            ret = FileLoadDrivers(gDriverSpec, 1);
    }

    return 0;
}
Ejemplo n.º 18
0
static int loadKexts(char * targetFolder, bool isPluginRun)
{
	bool isBundleType2 = false;
	
    long result = -1;
    long dirEntryFlags, dirEntryTime, dirEntryIndex = 0;
	
    const char * dirEntryName;
	
	while (1)
	{
		_DRIVERS_DEBUG_DUMP("O");
		
		result = GetDirEntry(targetFolder, &dirEntryIndex, &dirEntryName, &dirEntryFlags, &dirEntryTime);
		
		if (result == -1)
		{
			_DRIVERS_DEBUG_DUMP("b");
			
			// Back to loadKexts() when isPluginRun is true or loadDrivers() when false.
			break;
		}
		
		// Kexts are just folders so we need to have one.
		if ((dirEntryFlags & kFileTypeMask) == kFileTypeDirectory)
		{
			// Checking the file extension.
			if (strcmp(dirEntryName + (strlen(dirEntryName) - 5), ".kext") == 0)
			{
				sprintf(gPlatform.KextFileName, "%s/%s", targetFolder, dirEntryName);

#if DEBUG_DRIVERS
				if (strlen(gPlatform.KextFileName) >= MAX_KEXT_PATH_LENGTH)
				{
					stop("Error: gPlatform.KextFileName >= %d chars. Change MAX_KEXT_PATH_LENGTH!", MAX_KEXT_PATH_LENGTH);
				}
#endif
				// Determine bundle type.
				isBundleType2 = (GetFileInfo(gPlatform.KextFileName, "Contents", &dirEntryFlags, &dirEntryTime) == 0);

				result = loadPlist(gPlatform.KextFileName, isBundleType2);

				// False the first time we're here but true for the recursive call.
				if (!isPluginRun)
				{
					// Setup plug-ins path.
					sprintf(gPlatform.KextFileSpec, "%s/%sPlugIns", gPlatform.KextFileName, (isBundleType2) ? "Contents/" : "");

#if DEBUG_DRIVERS
					if (strlen(gPlatform.KextFileSpec) >= MAX_KEXT_PATH_LENGTH)
					{
						stop("Error: gPlatform.KextFileSpec >= %d chars. Change MAX_KEXT_PATH_LENGTH!", MAX_KEXT_PATH_LENGTH);
					}
#endif
					_DRIVERS_DEBUG_DUMP("R");

					// Recursive call for kexts in the PlugIns folder.
					result = loadKexts(gPlatform.KextFileSpec, true);
				}
			}
		}
	}

	return result;
}
Ejemplo n.º 19
0
__FAT32_FILE*   OpenFat32File(__FAT32_FS*   pFat32Fs,CHAR*  pszFileName)
{
	__FAT32_FILE*     pFat32File      = NULL; 		
	__FAT32_SHORTENTRY  ShortEntry    = {0};
	CHAR                FileName[MAX_FILE_NAME_LEN];
	CHAR                DirName[MAX_FILE_NAME_LEN];
	DWORD               dwDirClus     = 0;
	DWORD               dwDirOffset   = 0;	
	BOOL                bResult       = FALSE;
	
	strcpy(FileName,pszFileName);	

		
	if(!GetDirEntry(pFat32Fs,FileName,&ShortEntry,&dwDirClus,&dwDirOffset))
	{
		goto __TERMINAL;
	}

	if(FILE_ATTR_DIRECTORY & ShortEntry.FileAttributes)  //Is a directory.
	{
		goto __TERMINAL;
	}
	//Create a file object.
	pFat32File = (__FAT32_FILE*)LocalAlloc(LPTR,sizeof(__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     = 0;;
	pFat32File->dwShareMode    = 0;;
	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.
	
	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;
	}

__TERMINAL:

	return pFat32File;
}