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; }
void Read_Next(void *p_context, STATUS status) { FT_Test_Context *p_test_context = (FT_Test_Context *)p_context; TRACE_ENTRY(Read_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; } status = FF_Read( 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, &Read_Next_Callback); if (status != OK) { // Terminate and run parent context. Callback_Context::Terminate(p_test_context, status); return; } } // Read_Next
static BT_u32 fullfat_read(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 sRead = FF_Read(pFile->pFile, 1, ulSize, (FF_T_UINT8 *) pBuffer); return (BT_u32) sRead; }
/* 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; }
NTSTATUS NTAPI FatiRead(PFAT_IRP_CONTEXT IrpContext) { ULONG NumberOfBytes; LARGE_INTEGER ByteOffset; PFILE_OBJECT FileObject; TYPE_OF_OPEN OpenType; PIO_STACK_LOCATION IrpSp = IrpContext->Stack; PFCB Fcb; PVCB Vcb; PCCB Ccb; PVOID Buffer; LONG BytesRead; FileObject = IrpSp->FileObject; NumberOfBytes = IrpSp->Parameters.Read.Length; ByteOffset = IrpSp->Parameters.Read.ByteOffset; if (NumberOfBytes == 0) { FatCompleteRequest(IrpContext, IrpContext->Irp, STATUS_SUCCESS); return STATUS_SUCCESS; } OpenType = FatDecodeFileObject(FileObject, &Vcb, &Fcb, &Ccb); DPRINT("FatiRead() Fcb %p, Name %wZ, Offset %d, Length %d, Handle %p\n", Fcb, &FileObject->FileName, ByteOffset.LowPart, NumberOfBytes, Fcb->FatHandle); /* Perform actual read */ if (IrpContext->MinorFunction & IRP_MN_MDL) { DPRINT1("MDL read\n"); } else { Buffer = FatMapUserBuffer(IrpContext->Irp); DPRINT("Normal cached read, buffer %p\n"); /* Set offset */ FF_Seek(Fcb->FatHandle, ByteOffset.LowPart, FF_SEEK_SET); /* Read */ BytesRead = FF_Read(Fcb->FatHandle, NumberOfBytes, 1, Buffer); DPRINT("Read %d bytes\n", BytesRead); /* Indicate we read requested amount of bytes */ IrpContext->Irp->IoStatus.Information = BytesRead; IrpContext->Irp->IoStatus.Status = STATUS_SUCCESS; } /* Complete the request */ FatCompleteRequest(IrpContext, IrpContext->Irp, STATUS_SUCCESS); return STATUS_SUCCESS; }
/** * @public * @brief MD5 Data Hashing function. * * Generates and displays an MD5 hash of a file. This is really useful when * verify files for their integrity. We used MD5 extensively while stabilising * the read and write functionality of FullFAT. * **/ int md5_cmd(int argc, char **argv, FF_ENVIRONMENT *pEnv) { FF_IOMAN *pIoman = pEnv->pIoman; FF_T_INT8 path[FF_MAX_PATH]; FF_T_UINT8 readBuf[8192]; FF_FILE *fSource; FF_ERROR Error; int len; md5_state_t state; md5_byte_t digest[16]; int di; if(argc == 2) { ProcessPath(path, argv[1], pEnv); fSource = FF_Open(pIoman, path, FF_MODE_READ, &Error); if(fSource) { md5_init(&state); do { len = FF_Read(fSource, 1, 8192, readBuf); md5_append(&state, (const md5_byte_t *)readBuf, len); } while(len); md5_finish(&state, digest); for (di = 0; di < 16; ++di) cons_printf("%02x", digest[di]); cons_printf ("\n"); FF_Close(fSource); } else { cons_printf("Could not open file - %s\n", FF_GetErrMessage(Error)); } } else { cons_printf("Usage: %s [filename]\n", argv[0]); } 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; }
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