⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 yaffsfsd.c

📁 嵌入式linux yaffs文件系统源代码
💻 C
📖 第 1 页 / 共 5 页
字号:
				pfd->dwFileAttributes = yfsd_GetObjectWinAttributes(l);				yfsd_U32sToWinFileTime(l->win_ctime,&pfd->ftCreationTime);				yfsd_U32sToWinFileTime(l->win_atime,&pfd->ftLastAccessTime);				yfsd_U32sToWinFileTime(l->win_mtime,&pfd->ftLastWriteTime);				pfd->nFileSizeHigh = 0;				pfd->nFileSizeLow = yaffs_GetObjectFileLength(l);				pfd->dwOID = (CEOID)(INVALID_HANDLE_VALUE); // wtf is this???				MultiByteToWideChar(CP_ACP,0,name,-1,pfd->cFileName,YFSD_NAME_LENGTH);				RETAILMSG(MSGSTATE,(L"File %s id %d header %d nDataChunks %d scannedLength %d\r\n",							pfd->cFileName,l->objectId, l->chunkId, l->nDataChunks,							l->variant.fileVariant.scannedFileSize));				goto out_of_here;			}		}	}out_of_here:	yfsd_UnlockYAFFS();	if(!found)	{		SetLastError(ERROR_NO_MORE_FILES);	}	return found;	}#endifHANDLE YFSD_FindFirstFileW(PVOLUME pVolume, HANDLE hProc,PCWSTR pwsFileSpec, PWIN32_FIND_DATAW pfd ){	// Create a search context, register it, and do the first search	PSEARCH pSearch;	HANDLE h = INVALID_HANDLE_VALUE;	BOOL found = 0;	RETAILMSG (MSGSTATE, (L"YAFFS::FindFirst\r\n"));	pSearch = malloc(sizeof(yfsd_WinFind));	if(!pSearch)	{		SetLastError(ERROR_OUTOFMEMORY);	}	yfsd_LockYAFFS();	if(pSearch)	{		pSearch->foundObjects = NULL; //pSearch->currentPos = 0;		pSearch->dir = yfsd_FindDirectoryByWinPath(&pVolume->dev,pwsFileSpec,pSearch->pattern,YFSD_NAME_LENGTH);		if(pSearch->dir)		{				pSearch->dir->inUse++;		}		else		{			free(pSearch);			pSearch = NULL;			SetLastError(ERROR_PATH_NOT_FOUND);		}	}	yfsd_UnlockYAFFS();	if(pSearch)	{		found = yfsd_DoFindFile(pSearch,pfd);		if(found)		{			h = FSDMGR_CreateSearchHandle(pVolume->mgrVolume,hProc,pSearch);			if(h == INVALID_HANDLE_VALUE)			{				SetLastError(ERROR_NO_MORE_SEARCH_HANDLES);			}		}		else		{			SetLastError(ERROR_FILE_NOT_FOUND);		}		if(h == INVALID_HANDLE_VALUE)		{			yfsd_DeleteFinder(pSearch);		}	}	return h;}BOOL YFSD_FindNextFileW(PSEARCH pSearch, PWIN32_FIND_DATAW pfd ){	RETAILMSG (MSGSTATE, (L"YAFFS::FindNext\r\n"));	if(!pSearch)	{		return FALSE;	}	return yfsd_DoFindFile(pSearch,pfd);}BOOL YFSD_FindClose( PSEARCH pSearch ){		RETAILMSG (MSGSTATE, (L"YAFFS::FindClose\r\n"));	if(!pSearch)	{		return FALSE;	}	yfsd_DeleteFinder(pSearch);	return TRUE;}HANDLE YFSD_CreateFileW( 	PVOLUME pVolume, 	HANDLE hProc, 	PCWSTR pwsFileName, 	DWORD dwAccess, 	DWORD dwShareMode,	PSECURITY_ATTRIBUTES pSecurityAttributes, // ignore	DWORD dwCreate,	DWORD dwFlagsAndAttributes, 	HANDLE hTemplateFile ) // ignore{	yaffs_Object *parent = NULL;	yaffs_Object *obj = NULL;	char name[YFSD_NAME_LENGTH+1];	int mode;	yfsd_WinFile *f = NULL;	HANDLE handle = INVALID_HANDLE_VALUE;	unsigned modifiedTime[2];	unsigned objSize;	BOOL writePermitted = (dwAccess & GENERIC_WRITE) ? TRUE : FALSE;	BOOL readPermitted = (dwAccess & GENERIC_READ) ? TRUE : FALSE;	BOOL shareRead = (dwShareMode & FILE_SHARE_READ) ? TRUE : FALSE;	BOOL shareWrite = (dwShareMode & FILE_SHARE_WRITE) ? TRUE : FALSE;	BOOL openRead, openWrite, openReadAllowed, openWriteAllowed;	BOOL fileCreated = FALSE;		BOOL fAlwaysCreateOnExistingFile = FALSE;	BOOL fTruncateExistingFile = FALSE;	mode = dwFlagsAndAttributes & 0x00FFFFFF;  // ding off the flags	RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile (%s) flags %X mode %X\r\n", pwsFileName,dwFlagsAndAttributes,mode));	if(writePermitted)	{		RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile write permitted\r\n"));	}	else	{		RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile write not permitted\r\n"));	}	if(!yfsd_CheckValidAttributes(mode))	{			SetLastError(ERROR_INVALID_PARAMETER);			return FALSE;	}	yfsd_LockYAFFS();	parent = yfsd_FindDirectoryByWinPath(&pVolume->dev,pwsFileName,name,YFSD_NAME_LENGTH);	if(parent && yfsd_NameIsValid(name))	{		//slf021220b begin Fix still more bugs in CreateFile.		// Get the object for this file if it exists (only once).		obj = yfsd_FindObjectByWinPath(&pVolume->dev,pwsFileName);		//slf021220b end Fix still more bugs in CreateFile.		if(dwCreate == CREATE_NEW)		{			RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile creating file in CREATE_NEW\r\n"));			//slf021101c begin			//slf021220b begin Fix still more bugs in CreateFile.			// got above. obj = yfsd_FindObjectByWinPath(&pVolume->dev,pwsFileName);			//slf021220b end Fix still more bugs in CreateFile.			if(!obj)			{				obj = yaffs_MknodFile(parent,name,mode,0,0);				if(!obj)					SetLastError(ERROR_DISK_FULL);				fileCreated = TRUE;			}			//slf021220b begin Fix still more bugs in CreateFile.			else if (obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)			{				obj = NULL;				SetLastError(ERROR_ALREADY_EXISTS);			}			//slf021220b end Fix still more bugs in CreateFile.			else			{				obj = NULL;				//slf021220b begin Fix still more bugs in CreateFile.				//Match CE FAT error return SetLastError(ERROR_ALREADY_EXISTS);				SetLastError(ERROR_FILE_EXISTS);				//slf021220b begin Fix still more bugs in CreateFile.			}			//slf021101c end		}		else if( dwCreate == OPEN_ALWAYS)		{			//slf021220b begin Fix still more bugs in CreateFile.			// got above. obj = yfsd_FindObjectByWinPath(&pVolume->dev,pwsFileName);			//slf021220b end Fix still more bugs in CreateFile.			if(!obj)			{				RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile creating file in OPEN_ALWAYS\r\n"));				obj = yaffs_MknodFile(parent,name,mode,0,0);				if(!obj)					SetLastError(ERROR_DISK_FULL);				fileCreated = TRUE;			}			//slf021220b begin Fix still more bugs in CreateFile.			else if (obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)			{				obj = NULL;				SetLastError(ERROR_ACCESS_DENIED);			}			//slf021220b end Fix still more bugs in CreateFile.			else			{				RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile opening existing file in OPEN_ALWAYS\r\n"));			}		}		else if(dwCreate == OPEN_EXISTING)		{			RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile opening file in OPEN_EXISTING\r\n"));			//slf021220b begin Fix still more bugs in CreateFile.			// got above. obj = yfsd_FindObjectByWinPath(&pVolume->dev,pwsFileName);			//slf021220b end Fix still more bugs in CreateFile.			if(!obj)				SetLastError(ERROR_FILE_NOT_FOUND);		//slf021220b begin Fix still more bugs in CreateFile.            //slf021101c begin	    //			else	    //				if (yfsd_GetObjectWinAttributes(obj) & FILE_ATTRIBUTE_DIRECTORY)	    //				{	    //					SetLastError(ERROR_ACCESS_DENIED);	    //					obj = NULL;	    //				}            //slf021101c end			else if (obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)			{				SetLastError(ERROR_ACCESS_DENIED);				obj = NULL;			}		//slf021220b end Fix still more bugs in CreateFile.		}		else if(dwCreate == TRUNCATE_EXISTING)		{			RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile opening file in TRUNCATE_EXISTING\r\n"));			//slf021220b begin Fix still more bugs in CreateFile.			// got above. obj = yfsd_FindObjectByWinPath(&pVolume->dev,pwsFileName);			//if(obj)			if (!writePermitted || (obj  && (obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)))			{				obj = NULL;				SetLastError(ERROR_ACCESS_DENIED);			}			else if(obj)			//slf021220b end Fix still more bugs in CreateFile.			{				// Indicate that file is to be truncated.  This will happen later on assuming				// that a sharing violation does not occur and that we can get a file handle.				fTruncateExistingFile = TRUE;			}			else 			{				SetLastError(ERROR_FILE_NOT_FOUND);			}		}		else if(dwCreate == CREATE_ALWAYS)		{			//slf021220b begin Fix still more bugs in CreateFile.			// got above. obj = yfsd_FindObjectByWinPath(&pVolume->dev,pwsFileName);			//slf021220b end Fix still more bugs in CreateFile.			if(!obj)			{				RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile creating file parent %X, name %a in CREATE_ALWAYS\r\n",parent,name));				obj = yaffs_MknodFile(parent,name,mode,0,0);				if(!obj)					SetLastError(ERROR_DISK_FULL);				fileCreated = TRUE;			}			//slf021220b begin Fix still more bugs in CreateFile.			else if (obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY)			{				obj = NULL;				SetLastError(ERROR_ACCESS_DENIED);			}			//slf021220b end Fix still more bugs in CreateFile.			else			{							RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile in CREATE_ALWAYS (already exists)\r\n"));				// Indicate that file is to be recreated.  This will happen later on assuming				// that a sharing violation does not occur and that we can get a file handle.				fAlwaysCreateOnExistingFile = TRUE;			}		}		else		{				RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile called with unknown flags %x\r\n", dwCreate));				SetLastError(ERROR_INVALID_PARAMETER);		}	}	else	{		RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile unable to get parent node\r\n"));		SetLastError(ERROR_PATH_NOT_FOUND);	}	if(obj)	{			int i;			yfsd_WinFile *p;			openRead = openWrite =0;			openReadAllowed = openWriteAllowed = 1;			for(i = 0; i < MAX_WIN_FILE; i++)			{					p = &yfsd_winFile[i];					if(p->obj == obj)					{						if (p->readPermitted) openRead = 1;						if (p->writePermitted) openWrite = 1;						if (!p->shareRead) openReadAllowed = 0;						if (!p->shareWrite) openWriteAllowed = 0;					}			}			// Now we test if the share works out.			if((openRead && !shareRead) ||	 // already open for read, but we are not prepared to share it for read			   (openWrite && !shareWrite) || // already open for write, but we are not prepared to share it for write			   (!openReadAllowed && readPermitted) || // already open with read sharing not permitted			   (!openWriteAllowed && writePermitted)) // same... write			{				//slf021220c begin Fix error code for new sharing mode check code.				SetLastError(ERROR_SHARING_VIOLATION);				//slf021220c end Fix error code for new sharing mode check code.				obj = NULL;			}	}	if(obj)	{		RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile - we have an object\r\n"));		f = yfsd_GetWinFile();	}	else	{		RETAILMSG (MSGSTATE, (L"YAFFS::Creatfile - no object\r\n"));	}	if(f)	{		handle = FSDMGR_CreateFileHandle(pVolume->mgrVolume,hProc,f);		if(handle != INVALID_HANDLE_VALUE)		{			RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile - we have an fsdmgr handle\r\n"));			if (fTruncateExistingFile)			{				RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile - TRUNCATE_EXISTING - truncating existing file\r\n"));				yaffs_ResizeFile(obj,0);			}						if (fAlwaysCreateOnExistingFile)			{				RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile - CREATE_ALWAYS - zapping existing file\r\n"));				obj->st_mode = mode;				obj->dirty = 1;				yaffs_ResizeFile(obj,0);				yaffs_FlushFile(obj,1);			}									f->obj = obj;			f->offset = 0;			f->writePermitted = writePermitted;			//slf021220d begin oops typo.			f->readPermitted = readPermitted;			//slf021220d end oops typo.			f->shareRead= shareRead;			f->shareWrite = shareWrite;			f->myVolume = pVolume;			obj->inUse++;			modifiedTime[0] = obj->win_mtime[0];			modifiedTime[1] = obj->win_mtime[1];			objSize = yaffs_GetObjectFileLength(obj);			RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile - file size %d\r\n",objSize));		}		else		{			yfsd_PutWinFile(f);			RETAILMSG (MSGSTATE, (L"YAFFS::CreateFile - we have no fsdmgr handle\r\n"));		}	}	yfsd_UnlockYAFFS();	if(handle != INVALID_HANDLE_VALUE && 	   fileCreated &&	   pVolume->shellFunction)	{			FILECHANGEINFO fc;			WCHAR fpn[YFSD_FULL_PATH_NAME_SIZE];			fc.cbSize = sizeof(FILECHANGEINFO);			fc.wEventId = SHCNE_CREATE;			fc.uFlags = SHCNF_PATH;			fc.dwItem1 = (DWORD)yfsd_FullPathName(pVolume,fpn,YFSD_FULL_PATH_NAME_SIZE,pwsFileName);			fc.dwItem2 = 0;			fc.dwAttributes = mode;			yfsd_U32sToWinFileTime(modifiedTime,&fc.ftModified);			fc.nFileSize = objSize;			pVolume->shellFunction(&fc);			RETAILMSG (MSGSTATE, (L"YAFFS::shell function called\r\n"));			yfsd_ShellDirectoryChanged(pVolume,fpn);	}	if(handle != INVALID_HANDLE_VALUE && (fileCreated || writePermitted))	{			// Remember the name			WCHAR fpn[YFSD_FULL_PATH_NAME_SIZE];			int slen;			yfsd_FullPathName(pVolume,fpn,YFSD_FULL_PATH_NAME_SIZE,pwsFileName);			slen = wcslen(fpn);			f->fullName = malloc((slen+1)* sizeof(WCHAR));			if(f->fullName)			{				wcscpy(f->fullName,fpn);			}	}	return handle;}BOOL yfsd_DoReadFile( 	PFILE pFile, 	PVOID pBuffer, 	DWORD cbRead, 	PDWORD pcbRead){		DWORD maxRead;	int nread = 0;	yaffs_Object *obj = NULL;	if(pcbRead)	{		*pcbRead = 0;	}	else	{		RETAILMSG (MSGSTATE, (L"YAFFS::DoReadFile pcbRead was NULL. naughty.\r\n"));	}	RETAILMSG (MSGSTATE, (L"YAFFS::DoReadFile %d bytes\r\n",cbRead));	if(!pFile || !pFile->obj)	{		SetLastError(ERROR_INVALID_HANDLE);		return FALSE;	}		obj = pFile->obj;	if(yaffs_GetObjectFileLength(obj) > pFile->offset)	{		maxRead = yaffs_GetObjectFileLength(obj) - pFile->offset;	}	else	{		maxRead = 0;	}	if(cbRead > maxRead)	{		cbRead = maxRead;	}		if(maxRead > 0)	{		nread = yaffs_ReadDataFromFile(obj,pBuffer,pFile->offset,cbRead);		if(nread > 0)		{			pFile->offset += nread;			if(pcbRead)			{				*pcbRead = nread;			}		}	}	else	{		if(pcbRead) 		{			*pcbRead = maxRead;		}	}	return nread < 0? FALSE : TRUE; }BOOL YFSD_ReadFile( 	PFILE pFile, 	PVOID pBuffer, 	DWORD cbRead, 	PDWORD pcbRead, 	OVERLAPPED *pOverlapped ) //ignore{	BOOL result;	RETAILMSG (MSGSTATE, (L"YAFFS::ReadFile\r\n"));	if(!pFile || !pFile->obj)	{		SetLastError(ERROR_INVALID_HANDLE);		return FALSE;	}	yfsd_LockYAFFS();	result = yfsd_DoReadFile(pFile,pBuffer,cbRead,pcbRead);	yfsd_UnlockYAFFS();	return result;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -