int cp_cmd(int argc, char **argv, FF_ENVIRONMENT *pEnv) { FF_IOMAN *pIoman = pEnv->pIoman; FF_FILE *fSource, *fDest; FF_ERROR Error; FF_T_INT8 path[FF_MAX_PATH]; FF_T_UINT8 copybuf[COPY_BUFFER_SIZE]; FF_T_SINT32 BytesRead; //LARGE_INTEGER ticksPerSecond; //LARGE_INTEGER start_ticks, end_ticks, cputime; float transferRate = 0; //QueryPerformanceFrequency(&ticksPerSecond); if(argc == 3) { if(strstr(argv[1], "*") || strstr(argv[2], "*")) { return wildcopy(argc, argv, pEnv); } ProcessPath(path, argv[1], pEnv); fSource = FF_Open(pIoman, path, FF_MODE_READ, &Error); if(fSource) { ProcessPath(path, argv[2], pEnv); fDest = FF_Open(pIoman, path, FF_GetModeBits("w"), &Error); if(fDest) { // Do the copy //QueryPerformanceCounter(&start_ticks); //QueryPerformanceCounter(&end_ticks); do{ BytesRead = FF_Read(fSource, COPY_BUFFER_SIZE, 1, (FF_T_UINT8 *)copybuf); FF_Write(fDest, BytesRead, 1, (FF_T_UINT8 *) copybuf); //QueryPerformanceCounter(&end_ticks); //cputime.QuadPart = end_ticks.QuadPart - start_ticks.QuadPart; //time = ((float)cputime.QuadPart/(float)ticksPerSecond.QuadPart); //transferRate = (fSource->FilePointer / time) / 1024; //cons_printf("%f% - %10ld Bytes Copied, %f Kb/S\r", ((float)((float)fSource->FilePointer/(float)fSource->Filesize) * 100), fSource->FilePointer, transferRate); }while(BytesRead > 0); //cons_printf("%f% - %10ld Bytes Copied, %f Kb/S\n", ((float)((float)fSource->FilePointer/(float)fSource->Filesize) * 100), fSource->FilePointer, transferRate); FF_Close(fSource); FF_Close(fDest); } else { FF_Close(fSource); cons_printf("Could not open destination file - %s\n", FF_GetErrMessage(Error)); } } else { cons_printf("Could not open source file - %s\n", FF_GetErrMessage(Error)); } } else { cons_printf("Usage: %s [source file] [destination file]\n", argv[0]); } return 0; }
int mkfile_cmd(int argc, char **argv, FF_ENVIRONMENT *pEnv) { FF_FILE *f; FF_T_UINT32 Bytes; FF_T_UINT32 BytesWritten = 0; FF_T_UINT32 ElementSize = 0, Elements = 0, Multiplier = 0; FF_T_UINT8 IntBuffer[4096*4]; // 16Kb of Integers! FF_T_UINT32 i = 0, x; FF_T_INT8 path[FF_MAX_PATH]; FF_ERROR Error; FF_T_UINT64 TicksPerSecond, TicksStart, TicksEnd, Ticks; float transferRate = 0.0, time; TicksPerSecond = FFTerm_GetTickRate(pEnv->pConsole); if(argc == 5) { sscanf(argv[1], "%lu", &ElementSize); /*if(!ElementSize) { printf("Invalid Element Size!\n"); return 0; }*/ sscanf(argv[2], "%lu", &Elements); /*if(!Elements) { printf("Invalid Number of Elements\n"); return 0; }*/ sscanf(argv[3], "%lu", &Multiplier); /*if(!Multiplier) { printf("Invalid Multiplier\n"); return 0; }*/ Bytes = ElementSize * Elements * Multiplier; printf("Creating file of size %lu Bytes (%0.2f MB) (%0.3f GB)\n", Bytes, (float)((float)Bytes / 1048576.0), (float)(((float)Bytes / 1048576.0)/1024.0)); ProcessPath(path, argv[4], pEnv); f = FF_Open(pEnv->pIoman, path, FF_GetModeBits("wb"), &Error); if(f) { while(Bytes) { for(x = 0; x < 4096*4; x++) { IntBuffer[x] = (FF_T_UINT8)i++; } TicksStart = FFTerm_GetTicks(pEnv->pConsole); if(Bytes >= (4096 * 4)) { BytesWritten += 4096 * 4; Bytes -= FF_Write(f, 1, 4096 * 4, (FF_T_UINT8 *) IntBuffer); } else { BytesWritten += Bytes; Bytes -= FF_Write(f, 1, Bytes, (FF_T_UINT8 *) IntBuffer); } TicksEnd = FFTerm_GetTicks(pEnv->pConsole); Ticks += (TicksEnd - TicksStart); time = ((float)Ticks/(float)TicksPerSecond); transferRate = (BytesWritten / time) / 1024; printf("Written %0.2f MB (%7.2f KB/s)\r", (float) ((float)BytesWritten / 1048576.0), transferRate); } printf("Written %0.2f MB (%7.2f KB/s)\n", (float) ((float)BytesWritten / 1048576.0), transferRate); FF_Close(f); } else { printf("Error opening file: %s\n", FF_GetErrMessage(Error)); } } else { printf("Generates a File filled with 32-bit integers.\n\n"); printf("Usage: %s [Element Size] [Elements] [Multiplier] [filename]\n\n", argv[0]); printf("E.g. a 1Mb File, \tFullFAT\\>%s 1024\t 1024\t 1\t 1m.dat\n", argv[0]); printf("E.g. a 2Mb File, \tFullFAT\\>%s 1024\t 1024\t 2\t 2m.dat\n", argv[0]); printf("E.g. a 10Mb File, \tFullFAT\\>%s 1024\t 1024\t 10\t 10m.dat\n", argv[0]); printf("E.g. a 100Mb File, \tFullFAT\\>%s 1024\t 1024\t 100\t 100m.dat\n\n", argv[0]); } return 0; }
/* This isn't a command, but rather a simple copy function designed to aid wildCard copying. */ int filecopy(const char *src, const char *dest, FF_ENVIRONMENT *pEnv) { FF_IOMAN *pIoman = pEnv->pIoman; FF_ERROR Error; FF_FILE *fSource, *fDest; FF_T_UINT8 copybuf[COPY_BUFFER_SIZE]; FF_T_SINT32 BytesRead; //LARGE_INTEGER ticksPerSecond; //LARGE_INTEGER start_ticks, end_ticks, cputime, ostart, oend; float transferRate = 0; //int ticks; //QueryPerformanceFrequency(&ticksPerSecond); //QueryPerformanceCounter(&ostart); fSource = FF_Open(pIoman, src, FF_MODE_READ, &Error); //QueryPerformanceCounter(&oend); //ticks = (int) (oend.QuadPart - ostart.QuadPart); //cons_printf("Source: Open took %d\n", ticks); if(fSource) { //QueryPerformanceCounter(&ostart); fDest = FF_Open(pIoman, dest, FF_GetModeBits("w"), &Error); //QueryPerformanceCounter(&oend); //ticks = (int) (oend.QuadPart - ostart.QuadPart); //cons_printf("Dest: Open took %d\n", ticks); if(fDest) { // Do the copy //QueryPerformanceCounter(&start_ticks); do{ BytesRead = FF_Read(fSource, COPY_BUFFER_SIZE, 1, (FF_T_UINT8 *)copybuf); FF_Write(fDest, BytesRead, 1, (FF_T_UINT8 *) copybuf); //QueryPerformanceCounter(&end_ticks); //cputime.QuadPart = end_ticks.QuadPart - start_ticks.QuadPart; //time = ((float)cputime.QuadPart/(float)ticksPerSecond.QuadPart); //transferRate = (fSource->FilePointer / time) / 1024; cons_printf("%3.0f%% - %10ld Bytes Copied, %7.2f Kb/S\r", ((float)((float)fSource->FilePointer/(float)fSource->Filesize) * 100), fSource->FilePointer, transferRate); }while(BytesRead > 0); cons_printf("%3.0f%% - %10ld Bytes Copied, %7.2f Kb/S\n", ((float)((float)fSource->FilePointer/(float)fSource->Filesize) * 100), fSource->FilePointer, transferRate); FF_Close(fSource); FF_Close(fDest); } else { FF_Close(fSource); cons_printf("Could not open destination file - %s\n", FF_GetErrMessage(Error)); } } else { if(Error == FF_ERR_FILE_OBJECT_IS_A_DIR) { return FF_ERR_FILE_OBJECT_IS_A_DIR; } cons_printf("Could not open source file - %s\n", FF_GetErrMessage(Error)); } return 0; }
void Write_Next(void *p_context, STATUS status) { FT_Test_Context *p_test_context = (FT_Test_Context *)p_context; TRACE_ENTRY(Write_Next); if (p_test_context->m_page_number >= p_test_context->m_num_pages) { // Save number of pages written in parent context ((FT_Test_Context *)p_test_context->Get_Parent())->Set_Return_Value (p_test_context->m_num_pages); // Terminate and run parent context. Callback_Context::Terminate(p_test_context, OK); return; } // Fill the page with data that we can verify. // Each word contains its byte offset. U32 *p_data = (U32 *)p_test_context->m_p_buffer; U32 num_words = p_test_context->m_block_size / sizeof(U32); U32 word_written; U32 logical_byte_address = p_test_context->m_block_size * p_test_context->m_page_number; for (U32 index = 0; index < num_words; index++) { word_written = logical_byte_address + (index * sizeof(U32)); *(p_data + index) = word_written; } status = FF_Write( FT_flash_handle, p_test_context->m_p_buffer, p_test_context->m_block_size, // transfer_byte_count, p_test_context->m_block_size * p_test_context->m_page_number, // logical_byte_address, p_context, &Write_Next_Callback); if (status != OK) { // Terminate and run parent context. Callback_Context::Terminate(p_test_context, status); return; } // Increment the page number. p_test_context->m_page_number++; } // Write_Next
DWORD WINAPI IOTestThread( LPVOID lpParam ) { THREAD hThread = (THREAD) lpParam; // Cast the thread param to the FF File. FF_T_UINT16 i; FF_T_UINT16 buf[1024]; for(i = 0; i < 1024; i++) { buf[i] = i; } while(!hThread->tKill) { i = (FF_T_UINT16) FF_Write(hThread->pFile, 2, 1024, (FF_T_UINT8 *) buf); FF_Seek(hThread->pFile, 0, FF_SEEK_SET); hThread->nThreadBytes += i; //Sleep(1000); } printf("Thread %d: Received Kill Signal\n", hThread->nThreadNum); hThread->isDead = FF_TRUE; return 0; }
static int copy_file(const char *szsrcPath, const char *szdestPath, FF_T_BOOL bVerbose, FF_ENVIRONMENT *pEnv) { FF_FILE *pfSource; FF_FILE *pfDestination = NULL; FILE *pex; FF_ERROR ffError; FF_T_SINT32 slBytesRead, slBytesWritten; unsigned char buffer[CP_BUFFER_SIZE]; if(!strcmp(szsrcPath, szdestPath)) { // Ensure that source and destination are not the same file. printf("cp: Source and Destination files are identical: illegal operation.\n"); return 0; } pfSource = FF_Open(pEnv->pIoman, szsrcPath, FF_MODE_READ, &ffError); // Attempt to open the source. if(!pfSource) { printf("cp: %s: open failed: %s\n", szsrcPath, FF_GetErrMessage(ffError)); // Display a meaningful error message. return 0; } if(!bExternal) { pfDestination = FF_Open(pEnv->pIoman, szdestPath, (FF_MODE_WRITE | FF_MODE_CREATE | FF_MODE_TRUNCATE), &ffError); } else { pex = fopen(szdestPath+1, "w"); } if(!pfDestination && !pex) { printf("cp: %s: open failed: %s\n", szdestPath, FF_GetErrMessage(ffError)); FF_Close(pfSource); // Don't forget to close the Source file. return 0; } // Source and Destination files are open, copy the data from Source to Dest! do { slBytesRead = FF_Read(pfSource, 1, CP_BUFFER_SIZE, buffer); if(!bExternal) { slBytesWritten = FF_Write(pfDestination, 1, slBytesRead, buffer); } else { slBytesWritten = fwrite(buffer, 1, slBytesRead, pex); } if(slBytesWritten != slBytesRead) { printf("cp: write error: %s\n", FF_GetErrMessage(slBytesWritten)); break; } } while(slBytesRead); FF_Close(pfSource); if(!bExternal) { FF_Close(pfDestination); } else { fclose(pex); } if(bVerbose) { printf("'%s' -> '%s'\n", szsrcPath, szdestPath); } return 0; }
static BT_u32 fullfat_write(BT_HANDLE hFile, BT_u32 ulFlags, BT_u32 ulSize, void *pBuffer, BT_ERROR *pError) { BT_FF_FILE *pFile = (BT_FF_FILE *) hFile; FF_T_SINT32 sWritten = FF_Write(pFile->pFile, 1, ulSize, (FF_T_UINT8 *) pBuffer); return (BT_u32) sWritten; }
STATUS SSD_Ddm::Process_BSA_Request(Message *p_message) { // Save p_message for debugging. SSD_Ddm_p_message = p_message; // Increment the number of requests outstanding. m_num_requests_outstanding++; TRACEF(TRACE_L5, ("\nProcess_BSA_Request: requests outstanding = %d, req_code = %X", m_num_requests_outstanding, p_message->reqCode)); // Check to be sure the flash file system is open. if (m_flash_file_system_open == 0) { Reply_With_Status(p_message, I2O_DETAIL_STATUS_DEVICE_NOT_AVAILABLE); return OK; } // Check to be sure we are not formatting. if (m_p_format_message) { Reply_With_Status(p_message, I2O_DEATIL_STATUS_DEVICE_BUSY); return OK; } // Is this a BSA_STATUS_CHECK? if (p_message->reqCode == BSA_STATUS_CHECK) { // BSA_STATUS_CHECK is a noop. Reply_With_Status(p_message, OK); return OK; } // Is this a BSA_DEVICE_RESET? if (p_message->reqCode == BSA_DEVICE_RESET) { // BSA_DEVICE_RESET is a noop. Reply_With_Status(p_message, OK); return OK; } // Is this a BSA_POWER_MANAGEMENT? if (p_message->reqCode == BSA_POWER_MANAGEMENT) { // BSA_POWER_MANAGEMENT is a noop. Reply_With_Status(p_message, OK); return OK; } // Create a callback context. SSD_Request_Context *p_request_context = (SSD_Request_Context *)Callback_Context::Allocate(sizeof(SSD_Request_Context)); if (p_request_context == 0) { // We could not allocate a callback context. Reply_With_Status(p_message, I2O_DETAIL_STATUS_INSUFFICIENT_RESOURCE_SOFT); return OK; } // Save flash handle in callback context. p_request_context->m_flash_handle = m_flash_handle; // Save pointer to message in callback context. p_request_context->m_p_message = p_message; // Save pointer to this DDM so that context can signal us when the // request terminates. p_request_context->m_p_ddm = this; // Get pointer to block storage payload BSA_RW_PAYLOAD *p_BSA = (BSA_RW_PAYLOAD *)p_message->GetPPayload(); // Get an SGL from the original message. SGE_SIMPLE_ELEMENT* p_element = p_message->GetPSgl(0); // Get byte address from logical block address. I64 logical_byte_address = p_BSA->LogicalBlockAddress * 512; // Get count of SGL elements. U32 SGL_element_count = p_message->GetCSgl(); STATUS status; // TEMPORARY for breaking if (SGL_element_count > 1) { FF_Break(); status = OK; } switch (p_message->reqCode) { case BSA_BLOCK_READ: TRACEF(TRACE_L5, ("\nBSA_BLOCK_READ: TransferByteCount = 0X%X, LogicalBlockAddress = 0X%X, element count = %d", p_BSA->TransferByteCount, p_BSA->LogicalBlockAddress, SGL_element_count)); // Start the read from the flash file system. // Call Read_Write_Callback when the read has completed. status = FF_Read( m_flash_handle, p_element, p_BSA->TransferByteCount, logical_byte_address, p_request_context, &Read_Write_Callback); break; case BSA_BLOCK_WRITE: TRACEF(TRACE_L5, ("\nBSA_BLOCK_WRITE: TransferByteCount = 0X%X, LogicalBlockAddress = 0X%X, element count = %d", p_BSA->TransferByteCount, p_BSA->LogicalBlockAddress, SGL_element_count)); // Start the write to the flash file system. // Call Read_Write_Callback when the read has completed. status = FF_Write( m_flash_handle, p_element, p_BSA->TransferByteCount, logical_byte_address, p_request_context, &Read_Write_Callback); break; default: // We should not get any other request codes. CT_ASSERT(p_message->reqCode, SSD_Ddm::Process_BSA_Request); Tracef("\nInvalid request code = %X", p_message->reqCode); status = OS_DETAIL_STATUS_INAPPROPRIATE_FUNCTION; } // switch (p_message->reqCode) if (status != OK) // We were not able to start the flash operation. Reply_With_Status(p_message, Translate_Status_To_BSA(status)); return OK; } // SSD_Ddm::Process_BSA_Request
int mkfile_cmd(int xargc, char **xargv, FF_ENVIRONMENT *pEnv) { FF_FILE *f; FF_T_UINT32 Bytes; FF_T_UINT32 BytesWritten = 0; FF_T_UINT32 ElementSize = 0, Elements = 0, Multiplier = 0; FF_T_UINT32 IntBuffer[4096]; // 16Kb of Integers! FF_T_UINT32 i = 0, x; FF_T_INT8 path[FF_MAX_PATH]; FF_ERROR Error; //LARGE_INTEGER ticksPerSecond; //LARGE_INTEGER start_ticks, end_ticks, cputime; float transferRate = 0.0; //cputime.QuadPart = 0; //QueryPerformanceFrequency(&ticksPerSecond); if(xargc == 5) { sscanf(xargv[1], "%d", &ElementSize); //cons_printf("%d ",ElementSize); if(!ElementSize) { cons_printf("Invalid Element Size!\n"); return 0; } sscanf(xargv[2], "%d", &Elements); //cons_printf("%d ",Elements); if(!Elements) { cons_printf("Invalid Number of Elements\n"); return 0; } sscanf(xargv[3], "%d", &Multiplier); //cons_printf("%d \n",Multiplier); if(!Multiplier) { cons_printf("Invalid Multiplier\n"); return 0; } Bytes = ElementSize * Elements * Multiplier; //cons_printf("Creating file of size %lu Bytes (%0.2f MB) (%0.3f GB)\n", Bytes, (float)((float)Bytes / 1048576.0), (float)(((float)Bytes / 1048576.0)/1024.0)); ProcessPath(path, xargv[4], pEnv); f = FF_Open(pEnv->pIoman, path, FF_GetModeBits("wb"), &Error); if(f) { for(x = 0; x < 4096; x++) { IntBuffer[x] = i++; } while(Bytes) { //QueryPerformanceCounter(&start_ticks); if(Bytes >= 4096) { BytesWritten += 4096; Bytes -= FF_Write(f, 1, 4096, (FF_T_UINT8 *) IntBuffer); } else { BytesWritten += Bytes; Bytes -= FF_Write(f, 1, Bytes, (FF_T_UINT8 *) IntBuffer); } //QueryPerformanceCounter(&end_ticks); //cputime.QuadPart += (end_ticks.QuadPart - start_ticks.QuadPart); //time = ((float)cputime.QuadPart/(float)ticksPerSecond.QuadPart); //transferRate = (BytesWritten / time) / 1024; //cons_printf("Written %0.2f MB (%7.2f KB/s)\r", (float) ((float)BytesWritten / 1048576.0), transferRate); } //cons_printf("Written %0.2f MB (%7.2f KB/s)\n", (float) ((float)BytesWritten / 1048576.0), transferRate); FF_Close(f); } else { cons_printf("Error opening file: %s\n", FF_GetErrMessage(Error)); } } else { cons_printf("Generates a File filled with 32-bit integers.\n\n"); cons_printf("Usage: %s [Element Size] [Elements] [Multiplier] [filename]\n\n", xargv[0]); cons_printf("E.g. a 1Mb File, \tFullFAT\\>%s 1024\t 1024\t 1\t 1m.dat\n", xargv[0]); cons_printf("E.g. a 2Mb File, \tFullFAT\\>%s 1024\t 1024\t 2\t 2m.dat\n", xargv[0]); cons_printf("E.g. a 2Mb File, \tFullFAT\\>%s 1024\t 1024\t 10\t 10m.dat\n", xargv[0]); cons_printf("E.g. a 2Mb File, \tFullFAT\\>%s 1024\t 1024\t 100\t 100m.dat\n\n", xargv[0]); } return 0; }