コード例 #1
0
ファイル: FATMGR.C プロジェクト: AlexShiLucky/HelloX_STM32
//Create a new file in given directory.
BOOL CreateFatFile(__FAT32_FS* pFat32Fs,DWORD dwStartCluster,CHAR* pszFileName,BYTE Attributes)
{
	DWORD               dwInitCluster = 0;
	__FAT32_SHORTENTRY  DirEntry;
	BOOL                bResult       = FALSE;

	if((NULL == pFat32Fs) || (dwStartCluster < 2) || IS_EOC(dwStartCluster) || (NULL == pszFileName))
	{
		goto __TERMINAL;
	}
	//Allocate a free cluster for the new created file.
	if(!GetFreeCluster(pFat32Fs,0,&dwInitCluster))
	{
		PrintLine("In CreateFatFile: Can not get a free cluster.");
		goto __TERMINAL;
	}
	if(!InitShortEntry(&DirEntry,pszFileName,dwInitCluster,0,FILE_ATTR_ARCHIVE))
	{
		PrintLine("In CreateFatFile: Can not initialize short entry.");
		goto __TERMINAL;
	}
	if(!CreateDirEntry(pFat32Fs,dwStartCluster,&DirEntry))
	{
		PrintLine("In CreateFatFile: Can not create directory entry in parent dir.");
		ReleaseCluster(pFat32Fs,dwInitCluster);
		goto __TERMINAL;
	}
	bResult = TRUE;
__TERMINAL:
	return bResult;
}
コード例 #2
0
ファイル: FATMGR.C プロジェクト: AlexShiLucky/HelloX_STM32
//Create directory in a given uper level directory.
//Steps as follows:
// 1. One free cluster is allocated as data cluster by calling GetFreeCluster;
// 2. Initialize this cluster by calling InitDirectory;
// 3. Create the short directory entry by calling CreateDirEntry.
//
BOOL CreateFatDir(__FAT32_FS* pFat32Fs,DWORD dwStartCluster,CHAR* pszDirName,BYTE Attributes)
{
	DWORD               dwDirCluster = 0;
	__FAT32_SHORTENTRY  DirEntry;
	BOOL                bResult      = FALSE;

	if((NULL == pFat32Fs) || (dwStartCluster < 2) || IS_EOC(dwStartCluster) || (NULL == pszDirName))
	{
		goto __TERMINAL;
	}
	if(!GetFreeCluster(pFat32Fs,0,&dwDirCluster))
	{
		PrintLine("In CreateFatDir: Can not get a free cluster.");
		goto __TERMINAL;
	}

	if(!InitDirectory(pFat32Fs,dwStartCluster,dwDirCluster))
	{
		PrintLine("In CreateFatDir: Can not initialize the directory cluster.");
		goto __TERMINAL;
	}
	//Initialize the directory entry.
	/*
	DirEntry.CreateDate       = 0;
	DirEntry.CreateTime       = 0;
	DirEntry.CreateTimeTenth  = 0;
	DirEntry.dwFileSize       = 0;
	DirEntry.FileAttributes   = FILE_ATTR_DIRECTORY;
	DirEntry.LastAccessDate   = 0;
	DirEntry.wFirstClusHi     = (WORD)(dwDirCluster >> 16);
	DirEntry.wFirstClusLow    = (WORD)dwDirCluster;
	DirEntry.WriteDate        = 0;
	DirEntry.WriteTime        = 0;
	for(i = 0;i < 11;i ++)
	{
		DirEntry.FileName[i] = pszDirName[i];
	}*/
	if(!InitShortEntry(&DirEntry,pszDirName,dwDirCluster,0,FILE_ATTR_DIRECTORY))
	{
		goto __TERMINAL;
	}
	if(!CreateDirEntry(pFat32Fs,dwStartCluster,&DirEntry))
	{
		PrintLine("In CreateFatDir: Can not create directory entry in parent dir.");
		ReleaseCluster(pFat32Fs,dwDirCluster);
		goto __TERMINAL;
	}
	bResult = TRUE;
__TERMINAL:
	return bResult;
}
コード例 #3
0
ファイル: dir.c プロジェクト: taysom/tau
static DirEntry_s *CreateTree (int width, int depth, int level)
{
	int i;
	DirEntry_s *direntry;
	DirEntry_s *child;
	int type = random_percent(level * 15) ? T_FILE : T_DIR;
	direntry = CreateDirEntry(type);
	if ((depth == 0) || (type != T_DIR)) {
		return direntry;
	}
	chdir(direntry->name);
	for (i = 0; i < width; i++) {
		child = CreateTree(width, depth - 1, level + 1);
		child->sibling = direntry->child;
		direntry->child = child;
	}
	chdir("..");
	return direntry;
}
コード例 #4
0
BOOL CreateFatDir(__FAT32_FS* pFat32Fs,DWORD dwStartCluster,CHAR* pszDirName,BYTE Attributes)
{
	__FAT32_SHORTENTRY  DirEntry     = {0};
	DWORD               dwDirCluster = 0;	
	BOOL                bResult      = FALSE;

	
	if((NULL == pFat32Fs) || (dwStartCluster < 2) || IS_EOC(dwStartCluster) || (NULL == pszDirName))
	{
		goto __TERMINAL;
	}

	if(!GetFreeCluster(pFat32Fs,0,&dwDirCluster))
	{
		goto __TERMINAL;
	}

	if(!InitDirectory(pFat32Fs,dwStartCluster,dwDirCluster))
	{
		goto __TERMINAL;
	}


	if(!InitShortEntry(&DirEntry,pszDirName,dwDirCluster,0,FILE_ATTR_DIRECTORY))
	{
		goto __TERMINAL;
	}

	DirEntry.CreateTimeTenth = 10;
	SetFatFileDateTime(&DirEntry,FAT32_DATETIME_CREATE|FAT32_DATETIME_WRITE);

	if(!CreateDirEntry(pFat32Fs,dwStartCluster,&DirEntry))
	{
	//	PrintLine("In CreateFatDir: Can not create directory entry in parent dir.");
		ReleaseCluster(pFat32Fs,dwDirCluster);
		goto __TERMINAL;
	}
	bResult = TRUE;
__TERMINAL:
	return bResult;
}
コード例 #5
0
//Create a new file in given directory.
BOOL CreateFatFile(__FAT32_FS* pFat32Fs,DWORD dwStartCluster,CHAR* pszFileName,BYTE Attributes)
{
	DWORD               dwInitCluster = 0;
	__FAT32_SHORTENTRY  DirEntry      = {0};
	BOOL                bResult       = FALSE;


	if((NULL == pFat32Fs) || (dwStartCluster < 2) || IS_EOC(dwStartCluster) || (NULL == pszFileName))
	{
		goto __TERMINAL;
	}

	//Allocate a free cluster for the new created file.
	if(!GetFreeCluster(pFat32Fs,0,&dwInitCluster))
	{
		goto __TERMINAL;
	}
	if(!InitShortEntry(&DirEntry,pszFileName,dwInitCluster,0,FILE_ATTR_ARCHIVE))
	{
		//PrintLine("In CreateFatFile: Can not initialize short entry.");
		goto __TERMINAL;
	}

	DirEntry.CreateTimeTenth = 10;
	SetFatFileDateTime(&DirEntry,FAT32_DATETIME_CREATE|FAT32_DATETIME_WRITE);

	if(!CreateDirEntry(pFat32Fs,dwStartCluster,&DirEntry))
	{
		ReleaseCluster(pFat32Fs,dwInitCluster);
		goto __TERMINAL;
	}

	bResult = TRUE;
__TERMINAL:

	return bResult;
}