struct vpf_fh * VPF_Open(const char *path, mode_t mode, pid_t *pidptr) { struct vpf_fh *pfh; struct stat sb; int fd; /* * Open the PID file and obtain exclusive lock. * We truncate PID file here only to remove old PID immediately, * PID file will be truncated again in VPF_Write(), so * VPF_Write() can be called multiple times. */ fd = VFL_Open(path, O_WRONLY | O_CREAT | O_TRUNC | O_CLOEXEC | O_NONBLOCK, mode); if (fd == -1) { if (errno == EWOULDBLOCK && pidptr != NULL) { errno = VPF_Read(path, pidptr); if (errno == 0) errno = EEXIST; } return (NULL); } /* * Remember file information, so in VPF_Write() we are sure we write * to the proper descriptor. */ AZ(fstat(fd, &sb)); pfh = malloc(sizeof(*pfh)); AN(pfh); pfh->pf_path = strdup(path); AN(pfh->pf_path); pfh->pf_fd = fd; pfh->pf_dev = sb.st_dev; pfh->pf_ino = sb.st_ino; return (pfh); }
UINT32 PSII_HALWrapper(VOID *pPacket, VOID *pInOutBuf, UINT32 *pResult) { FTLPacket *pstInPacketFTL = NULL; VFLPacket *pstInPacketVFL = NULL; UINT32 nCtrlCode; UINT32 nLsn; UINT32 nNumOfScts; UINT8 *pBuf; UINT32 *pTotalScts; UINT32 nVbn; UINT32 nVpn; UINT32 nSrcVpn; UINT32 nDesVpn; BOOL32 bCleanChk; BUFType eType; Buffer *pbBuf; /* UINT16 *pFTLCxtVbn = NULL; */ HALWP_LOG_PRINT((TEXT("[HALWP: IN] ++PSII_HALWrapper()\r\n"))); pstInPacketFTL = (FTLPacket*)pPacket; if (pstInPacketFTL->nCtrlCode <= PM_HAL_FIL_INIT) { HALWP_LOG_PRINT((TEXT("[HALWP:LOG] VFL packet\r\n"))); pstInPacketFTL = NULL; pstInPacketVFL = (VFLPacket*)pPacket; nCtrlCode = pstInPacketVFL->nCtrlCode; nVbn = pstInPacketVFL->nVbn; nVpn = pstInPacketVFL->nVpn; pbBuf = pstInPacketVFL->pBuf; nSrcVpn = pstInPacketVFL->nSrcVpn; nDesVpn = pstInPacketVFL->nDesVpn; bCleanChk = pstInPacketVFL->bCleanCheck; eType = pstInPacketVFL->eType; } else { HALWP_LOG_PRINT((TEXT("[HALWP:LOG] FTL packet\r\n"))); nCtrlCode = pstInPacketFTL->nCtrlCode; nLsn = pstInPacketFTL->nLsn; nNumOfScts = pstInPacketFTL->nNumOfScts; pBuf = pstInPacketFTL->pBuf; pTotalScts = pstInPacketFTL->pTotalScts; } HALWP_LOG_PRINT((TEXT("[HALWP:LOG] nCtrlCode = %d\r\n"), nCtrlCode)); HALWP_LOG_PRINT((TEXT("[HALWP:LOG] nLsn = %d(0x%x)\r\n"), nLsn, nLsn)); HALWP_LOG_PRINT((TEXT("[HALWP:LOG] nNumOfScts = %d\r\n"), nNumOfScts)); HALWP_LOG_PRINT((TEXT("[HALWP:LOG] pBuf = 0x%x\r\n"), (UINT32)pBuf)); //HALWP_LOG_PRINT((TEXT("[HALWP:LOG] pTotalScts = %d(0x%x)\r\n"), *pTotalScts,(UINT32)pTotalScts)); switch (nCtrlCode) { case PM_HAL_VFL_INIT: HALWP_RTL_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_VFL_INIT\r\n"))); *pResult = (UINT32)VFL_Init(); pInOutBuf = NULL; break; case PM_HAL_VFL_OPEN: HALWP_RTL_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_VFL_OPEN\r\n"))); *pResult = (UINT32)VFL_Open(); pInOutBuf = NULL; break; case PM_HAL_FIL_INIT: HALWP_RTL_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_FIL_INIT\r\n"))); *pResult = (UINT32)FIL_Init(); pInOutBuf = NULL; break; case PM_HAL_FIL_GET_NANDINFO: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_FTL_INIT\r\n"))); GetNandInfo((NAND_INFO *)pInOutBuf); break; case PM_HAL_FTL_INIT: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_FTL_INIT\r\n"))); *pResult = (UINT32)FTL_Init(); pInOutBuf = NULL; break; case PM_HAL_FTL_OPEN: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_FTL_OPEN\r\n"))); HALWP_INF_PRINT((TEXT("[HALWP:INF] pTotalScts = %d\r\n"), *pTotalScts)); if ( bAllreadyFTLOpen == FALSE ) { *pResult = (UINT32)FTL_Open(pTotalScts); if ( *pResult == FTL_SUCCESS ) { bAllreadyFTLOpen = TRUE; TotalScts = *pTotalScts; } } else { *pTotalScts = TotalScts; *pResult = FTL_SUCCESS; HALWP_ERR_PRINT((TEXT("[HALWP:INF] TotalScts = %d\r\n"), TotalScts)); } pInOutBuf = NULL; break; case PM_HAL_FTL_FORMAT: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_FTL_FORMAT\r\n"))); *pResult = (UINT32)FTL_Format(); pInOutBuf = NULL; break; case PM_HAL_VFL_READ: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_VFL_READ\r\n"))); HALWP_INF_PRINT((TEXT("[HALWP:INF] nVpn = %d(0x%x)\r\n"), nVpn)); HALWP_INF_PRINT((TEXT("[HALWP:INF] pBuf = 0x%x\r\n"), (UINT32)pBuf)); HALWP_INF_PRINT((TEXT("[HALWP:INF] bCleanChk = 0x%x\r\n"), (UINT32)bCleanChk)); *pResult = (UINT32)VFL_Read(nVpn,(Buffer*)pbBuf,bCleanChk); break; case PM_HAL_FTL_READ: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_FTL_READ\r\n"))); HALWP_INF_PRINT((TEXT("[HALWP:INF] nLsn = %d\r\n"), nLsn)); HALWP_INF_PRINT((TEXT("[HALWP:INF] nNumOfScts= %d\r\n"), nNumOfScts)); HALWP_INF_PRINT((TEXT("[HALWP:INF] pBuf = 0x%x\r\n"), (UINT32)pBuf)); *pResult = (UINT32)FTL_Read(nLsn,nNumOfScts,(UINT8*)pBuf); pInOutBuf = NULL; break; case PM_HAL_FTL_SCAN: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_FTL_SCAN\r\n"))); // nLsn number is SCAN_FS or SCAN_OS *pResult = (UINT32)FTL_Scan(nLsn); pInOutBuf = NULL; break; #if (WMR_READ_RECLAIM) case PM_HAL_FTL_READRECLAIM: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_FTL_READRECLAIM\r\n"))); *pResult = (UINT32)FTL_ReadReclaim(); pInOutBuf = NULL; break; #endif case PM_HAL_FTL_WRITE: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_FTL_WRITE\r\n"))); HALWP_INF_PRINT((TEXT("[HALWP:INF] nLsn = %d\r\n"), nLsn)); HALWP_INF_PRINT((TEXT("[HALWP:INF] nNumOfScts= %d\r\n"), nNumOfScts)); HALWP_INF_PRINT((TEXT("[HALWP:INF] pBuf = 0x%x\r\n"), (UINT32)pBuf)); *pResult = (UINT32)FTL_Write(nLsn,nNumOfScts,(UINT8*)pBuf); pInOutBuf = NULL; break; case PM_HAL_FTL_DELETE: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_FTL_DELETE\r\n"))); HALWP_INF_PRINT((TEXT("[HALWP:INF] nLsn = %d\r\n"), nLsn)); HALWP_INF_PRINT((TEXT("[HALWP:INF] nNumOfScts= %d\r\n"), nNumOfScts)); *pResult = (UINT32)FTL_Delete(nLsn,nNumOfScts); pInOutBuf = NULL; break; case PM_HAL_FTL_CLOSE: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_FTL_CLOSE\r\n"))); *pResult = (UINT32)FTL_Close(); pInOutBuf = NULL; bAllreadyFTLOpen = FALSE; TotalScts = 0; break; case PM_HAL_FTL_GARBAGECOLLECT: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_FTL_GARBAGECOLLECT\r\n"))); *pResult = (UINT32)FTL_GarbageCollect(); pInOutBuf = NULL; break; case PM_HAL_FTL_FORMATPROC: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_FTL_FORMATPROC\r\n"))); // *pResult = (UINT32)FTL_FormatProc(); pInOutBuf = NULL; break; case PM_HAL_WMR_FORMAT_FIL: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_WMR_FORMAT_FIL\r\n"))); *pResult = (UINT32)WMR_Format_FIL(); pInOutBuf = NULL; break; case PM_HAL_WMR_FORMAT_VFL: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_WMR_FORMAT_VFL\r\n"))); *pResult = (UINT32)WMR_Format_VFL(); pInOutBuf = NULL; break; case PM_HAL_WMR_FORMAT_FTL: HALWP_INF_PRINT((TEXT("[HALWP:INF] nCtrlCode = PM_HAL_WMR_FORMAT_FTL\r\n"))); *pResult = (UINT32)WMR_Format_FTL(); pInOutBuf = NULL; break; default: return FALSE; } HALWP_LOG_PRINT((TEXT("[HALWP:OUT] --PSII_HALWrapper()\r\n"))); return TRUE; }
int ftl_setup() { if(HasFTLInit) return 0; nand_setup(); Data = nand_get_geometry(); Data2 = nand_get_data(); if(VFL_Init() != 0) { bufferPrintf("ftl: VFL_Init failed\r\n"); return -1; } if(FTL_Init() != 0) { bufferPrintf("ftl: FTL_Init failed\r\n"); return -1; } int i; int foundSignature = FALSE; DebugPrintf("ftl: Attempting to read %d pages from first block of first bank.\r\n", Data->pagesPerBlock); uint8_t* buffer = malloc(Data->bytesPerPage); for(i = 0; i < Data->pagesPerBlock; i++) { int ret; if((ret = nand_read_alternate_ecc(0, i, buffer)) == 0) { uint32_t id = *((uint32_t*) buffer); if(id == FTL_ID_V1 || id == FTL_ID_V2) { bufferPrintf("ftl: Found production format: %x\r\n", id); foundSignature = TRUE; break; } else { DebugPrintf("ftl: Found non-matching signature: %x\r\n", ((uint32_t*) buffer)); } } else { DebugPrintf("ftl: page %d of first bank is unreadable: %x!\r\n", i, ret); } } free(buffer); if(!foundSignature || !hasDeviceInfoBBT()) { bufferPrintf("ftl: no signature or production format.\r\n"); return -1; } if(VFL_Open() != 0) { bufferPrintf("ftl: VFL_Open failed\r\n"); return -1; } int pagesAvailable; int bytesPerPage; if(FTL_Open(&pagesAvailable, &bytesPerPage) != 0) { bufferPrintf("ftl: FTL_Open failed\r\n"); return -1; } HasFTLInit = TRUE; return 0; }