📄 yaffsfsd.c
字号:
fc.uFlags = SHCNF_PATH; fc.dwItem1 = (DWORD)yfsd_FullPathName(pVolume,fpn,YFSD_FULL_PATH_NAME_SIZE,pathName); fc.dwItem2 = 0; fc.dwAttributes = 0; yfsd_NullWinFileTime(&fc.ftModified); fc.nFileSize = 0; pVolume->shellFunction(&fc); RETAILMSG (MSGSTATE, (L"YAFFS::shell function called\r\n")); yfsd_ShellDirectoryChanged(pVolume,fpn); } return result ? TRUE : FALSE;}DWORD YFSD_GetFileAttributesW(PVOLUME pVolume, PCWSTR pwsFileName ){ yaffs_Object *obj = NULL; DWORD result = 0xFFFFFFFF; RETAILMSG (MSGSTATE, (L"YAFFS::GetFileAttributes\r\n")); yfsd_LockYAFFS(); obj = yfsd_FindObjectByWinPath(&pVolume->dev,pwsFileName); if(obj) { result = yfsd_GetObjectWinAttributes(obj); } else { SetLastError(ERROR_FILE_NOT_FOUND); } yfsd_UnlockYAFFS(); RETAILMSG (MSGSTATE, (L"YAFFS::GetFileAttributes for %s returning %X\r\n",pwsFileName,result)); return result; }BOOL YFSD_SetFileAttributesW( PVOLUME pVolume,PCWSTR pwsFileName, DWORD dwFileAttributes ){ yaffs_Object *obj = NULL; DWORD mtime[2]; DWORD attribs; DWORD objSize; int result = 0; RETAILMSG (MSGSTATE, (L"YAFFS::SetFileAttributes %X\r\n",dwFileAttributes)); if(!yfsd_CheckValidAttributes(dwFileAttributes)) { SetLastError(ERROR_INVALID_PARAMETER); return FALSE; } yfsd_LockYAFFS(); obj = yfsd_FindObjectByWinPath(&pVolume->dev,pwsFileName); if(obj) { obj->st_mode = dwFileAttributes; obj->dirty = 1; result = yaffs_FlushFile(obj,0); attribs = yfsd_GetObjectWinAttributes(obj); objSize = yaffs_GetObjectFileLength(obj); mtime[0] = obj->win_mtime[0]; mtime[1] = obj->win_mtime[1]; } else { SetLastError(ERROR_FILE_NOT_FOUND); } yfsd_UnlockYAFFS(); if(result && pVolume->shellFunction) { FILECHANGEINFO fc; WCHAR fpn[YFSD_FULL_PATH_NAME_SIZE]; fc.cbSize = sizeof(FILECHANGEINFO); fc.wEventId = SHCNE_ATTRIBUTES; fc.uFlags = SHCNF_PATH; fc.dwItem1 = (DWORD)yfsd_FullPathName(pVolume,fpn,YFSD_FULL_PATH_NAME_SIZE,pwsFileName); fc.dwItem2 = 0; fc.dwAttributes = attribs; yfsd_U32sToWinFileTime(mtime,&fc.ftModified); fc.nFileSize = objSize; pVolume->shellFunction(&fc); RETAILMSG (MSGSTATE, (L"YAFFS::shell function called\r\n")); //yfsd_ShellDirectoryChanged(pVolume,fpn); } return result;}BOOL YFSD_DeleteFileW( PVOLUME pVolume, PCWSTR pwsFileName ){ int result = FALSE; yaffs_Object *parent = NULL; yaffs_Object *obj; char name[YFSD_NAME_LENGTH+1]; RETAILMSG (MSGSTATE, (L"YAFFS::DeleteFileW (%s)\r\n", pwsFileName)); yfsd_LockYAFFS(); obj = yfsd_FindObjectByWinPath(&pVolume->dev,pwsFileName); if(!obj) { SetLastError(ERROR_FILE_NOT_FOUND); result = FALSE; } else if (obj->variantType != YAFFS_OBJECT_TYPE_FILE) { SetLastError(ERROR_ACCESS_DENIED); result = FALSE; } else if(obj->st_mode & FILE_ATTRIBUTE_READONLY) { SetLastError(ERROR_ACCESS_DENIED); result = FALSE; } else if(obj->inUse) { SetLastError(ERROR_ACCESS_DENIED); result = FALSE; } else { parent = yfsd_FindDirectoryByWinPath(&pVolume->dev,pwsFileName,name,YFSD_NAME_LENGTH); if(parent && yfsd_NameIsValid(name)) { result = yaffs_Unlink(parent,name); if(!result) SetLastError(ERROR_ACCESS_DENIED); } } yfsd_UnlockYAFFS(); if(result && pVolume->shellFunction) { FILECHANGEINFO fc; WCHAR fpn[YFSD_FULL_PATH_NAME_SIZE]; fc.cbSize = sizeof(FILECHANGEINFO); fc.wEventId = SHCNE_DELETE; fc.uFlags = SHCNF_PATH; fc.dwItem1 = (DWORD)yfsd_FullPathName(pVolume,fpn,YFSD_FULL_PATH_NAME_SIZE,pwsFileName); fc.dwItem2 = 0; fc.dwAttributes = -1; yfsd_NullWinFileTime(&fc.ftModified); fc.nFileSize = 0; pVolume->shellFunction(&fc); RETAILMSG (MSGSTATE, (L"YAFFS::shell function called\r\n")); yfsd_ShellDirectoryChanged(pVolume,fpn); } return result ? TRUE : FALSE;}BOOL YFSD_MoveFileW(PVOLUME pVolume,PCWSTR pwsOldFileName, PCWSTR pwsNewFileName ){ yaffs_Object *newParent = NULL; yaffs_Object *oldParent = NULL; yaffs_Object *obj = NULL; char oldName[YFSD_NAME_LENGTH+1]; char newName[YFSD_NAME_LENGTH+1]; int result = 0; int objIsDir = 0; DWORD attribs; DWORD objSize; DWORD mtime[2]; RETAILMSG (MSGSTATE, (L"YAFFS::MoveFile\r\n")); yfsd_LockYAFFS(); oldParent = yfsd_FindDirectoryByWinPath(&pVolume->dev,pwsOldFileName,oldName,YFSD_NAME_LENGTH); newParent = yfsd_FindDirectoryByWinPath(&pVolume->dev,pwsNewFileName,newName,YFSD_NAME_LENGTH); if(oldParent && yfsd_NameIsValid(oldName) && newParent && yfsd_NameIsValid(newName)) { result = yaffs_RenameObject(oldParent,oldName,newParent,newName); if(!result) { SetLastError(ERROR_FILE_NOT_FOUND); } obj = yfsd_FindObjectByWinPath(&pVolume->dev,pwsNewFileName); if(obj) { objIsDir = (obj->variantType == YAFFS_OBJECT_TYPE_DIRECTORY); attribs = yfsd_GetObjectWinAttributes(obj); objSize = yaffs_GetObjectFileLength(obj); mtime[0] = obj->win_mtime[0]; mtime[1] = obj->win_mtime[1]; } } else { SetLastError(ERROR_PATH_NOT_FOUND); } yfsd_UnlockYAFFS(); if(result && pVolume->shellFunction) { FILECHANGEINFO fc; WCHAR fpn1[YFSD_FULL_PATH_NAME_SIZE]; WCHAR fpn2[YFSD_FULL_PATH_NAME_SIZE]; fc.cbSize = sizeof(FILECHANGEINFO); fc.wEventId = objIsDir ? SHCNE_RENAMEFOLDER : SHCNE_RENAMEITEM; fc.uFlags = SHCNF_PATH; fc.dwItem1 = (DWORD)yfsd_FullPathName(pVolume,fpn1,YFSD_FULL_PATH_NAME_SIZE,pwsOldFileName); fc.dwItem2 = (DWORD)yfsd_FullPathName(pVolume,fpn2,YFSD_FULL_PATH_NAME_SIZE,pwsNewFileName); fc.dwAttributes = attribs; yfsd_U32sToWinFileTime(mtime,&fc.ftModified); fc.nFileSize = objSize; pVolume->shellFunction(&fc); RETAILMSG (MSGSTATE, (L"YAFFS::shell function called\r\n")); yfsd_ShellDirectoryChanged(pVolume,fpn1); yfsd_ShellDirectoryChanged(pVolume,fpn2); } return result ? TRUE : FALSE;}BOOL YFSD_DeleteAndRenameFileW(PVOLUME pVolume, PCWSTR pwsOldFileName, PCWSTR pwsNewFileName ){ //slf021104c begin BOOL fSuccess; //slf021104c end RETAILMSG (MSGSTATE, (L"YAFFS::DeleteAndRename\r\n")); //slf021104c begin if (fSuccess = YFSD_DeleteFileW(pVolume, pwsOldFileName)) fSuccess = YFSD_MoveFileW(pVolume, pwsNewFileName, pwsOldFileName); return fSuccess; //return FALSE; //slf021104c end}BOOL YFSD_GetDiskFreeSpaceW( PVOLUME pVolume, PCWSTR pwsPathName, PDWORD pSectorsPerCluster,PDWORD pBytesPerSector, PDWORD pFreeClusters, PDWORD pClusters ){ int nChunks; RETAILMSG (MSGSTATE, (L"YAFFS::GetFreeSpace\r\n")); yfsd_LockYAFFS(); nChunks = yaffs_GetNumberOfFreeChunks(&pVolume->dev); yfsd_UnlockYAFFS(); if(nChunks >= 0) { // Let's pretentd our clusters are the same size as eraseable blocks... *pBytesPerSector = 512; *pSectorsPerCluster =32; *pFreeClusters = nChunks/32; *pClusters = pVolume->dev.endBlock - pVolume->dev.startBlock + 1; } return (nChunks >= 0)? TRUE : FALSE;}void YFSD_Notify(PVOLUME pVolume, DWORD dwFlags ){ // Flags can be one of: // FSNOTIFY_POWER_ON: no action required // FSNOTIFY_POWER_OFF: flush all files // FSNOTIFY_DEVICE_ON: no action required RETAILMSG (MSGSTATE, (L"YAFFS::Notify\r\n")); if(dwFlags == FSNOTIFY_POWER_OFF) { yfsd_FlushAllFiles(); }}BOOL YFSD_RegisterFileSystemFunction(PVOLUME pVolume,SHELLFILECHANGEFUNC_t pfn ){ RETAILMSG (MSGSTATE, (L"YAFFS::RegisterFileSysFunction\r\n")); pVolume->shellFunction = pfn; return TRUE;}int iMatch(const char a, const char b){ if (a == '?' || b == '?') return 1; return (toupper(a) == toupper(b));}void pString(const char *inp){ while (*inp) RETAILMSG(1, (L"%c", *inp++));}int regularMatch(const char *regexp, const char *str){// pString(regexp);// RETAILMSG(1, (L" "));// pString(str);// RETAILMSG(1, (L"\r\n")); if (*regexp == 0 && *str == 0) { //RETAILMSG(1, (L"Match!\r\n")); return 1; } if (*regexp == '*') { regexp++; if (*regexp == 0) // end of the expression is a *, we must match { //RETAILMSG(1, (L"Match!\r\n")); return 1; } while (!iMatch(*regexp, *str)) // throw away chars from str until we match { if (*str == 0) // if we're not at the end { // if we have .* left to match, but the str is finished then match it OK if (regexp[0] == '.' && regexp[1] == '*') { //RETAILMSG(1, (L"Match!\r\n")); return 1; } else { // the extension failed the match //RETAILMSG(1, (L"No Match!\r\n")); return 0; } } str++; } // right now we should either eat more characters, or try to match return (regularMatch(regexp, str) || regularMatch(--regexp, ++str)); }// compare chars until we hit another *, or we fail while (iMatch(*regexp, *str)) { if (*regexp == 0 && *str == 0) { //RETAILMSG(1, (L"Match!\r\n")); return 1; } regexp++; str++; } if (*regexp == 0 && *str == 0) { //RETAILMSG(1, (L"Match!\r\n")); return 1; } if (*regexp == '*') return regularMatch(regexp, str); //RETAILMSG(1, (L"No Match!\r\n")); return 0;}void yfsd_DeleteFinder(PSEARCH pSearch){ if(pSearch->foundObjects) //If we found some objects we must clean up the cached linked list. { yaffs_FoundObject *it; yaffs_FoundObject *temp; it = pSearch->foundObjects; while(it != NULL) { temp = it; it = it->next; free(temp); } pSearch->foundObjects = NULL; } pSearch->dir->inUse--; free(pSearch);}BOOL yfsd_ObjectAlreadyFound(PSEARCH pSearch, yaffs_Object *l){ //Iterate through the current list of objs already found and return true if already exists. //If the object hasn't already been found then add it to the list (SIDE-EFFECT alert) and return false. BOOL found = FALSE; yaffs_FoundObject *it; it = pSearch->foundObjects; while(it->next != NULL) //iterate through singly linked list. { if(it->obj == l) { found = TRUE; break; } it = it->next; } if(!found) { //Add the item to the list. //'it' will currently be pointing to the last of the list nodes. i.e node->next == NULL it->next = malloc(sizeof(yaffs_FoundObject)); it->next->next = NULL; it->next->obj = 0; it->obj = l; } return found;}#if 0// slower oneBOOL yfsd_DoFindFile(PSEARCH pSearch, PWIN32_FIND_DATAW pfd){ struct list_head *i; int pos; yaffs_Object *l; BOOL found = 0; char name[YAFFS_MAX_NAME_LENGTH+1]; if(!pSearch->foundObjects) { pSearch->foundObjects = malloc(sizeof(yaffs_FoundObject)); pSearch->foundObjects->next = NULL; pSearch->foundObjects->obj = 0; } yfsd_LockYAFFS(); pos = 0; list_for_each(i,&pSearch->dir->variant.directoryVariant.children) { l = list_entry(i, yaffs_Object,siblings); yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1); if(regularMatch(pSearch->pattern,name)) { if(!yfsd_ObjectAlreadyFound(pSearch, l))//pos == pSearch->currentPos) { found = 1; //pSearch->currentPos++; // fill out find data 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; } else { pos++; } } }out_of_here: yfsd_UnlockYAFFS(); if(!found) { SetLastError(ERROR_NO_MORE_FILES); } return found; }#else// faster oneBOOL yfsd_DoFindFile(PSEARCH pSearch, PWIN32_FIND_DATAW pfd){ struct list_head *i; yaffs_Object *l; BOOL found = 0; char name[YAFFS_MAX_NAME_LENGTH+1]; if(!pSearch->foundObjects) { pSearch->foundObjects = malloc(sizeof(yaffs_FoundObject)); pSearch->foundObjects->next = NULL; pSearch->foundObjects->obj = 0; } yfsd_LockYAFFS(); list_for_each(i,&pSearch->dir->variant.directoryVariant.children) { l = list_entry(i, yaffs_Object,siblings); if(!yfsd_ObjectAlreadyFound(pSearch,l)) { // Only look at things we have not looked at already yaffs_GetObjectName(l,name,YAFFS_MAX_NAME_LENGTH+1); if(regularMatch(pSearch->pattern,name)) { found = 1; // fill out find data
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -