Click here to Skip to main content
15,885,216 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to controll for usb mass storage device in linux,android
when usb device is in act to change a file, i wanner get the file in usb mass storage.
There is source code for Windows,but linux or android isn't.
please help me!
C++
void main(){
	HANDLE	SourceFile, IoPort;
        DWORD	nBytes;
          DWORD	vRet;
       DWORD	vFileSize;
      OVERLAPPED Overlapped;
    BYTE	*pBuf;
BOOL vStatus;
DWORD nFileSeek;
SourceFile = CreateFile("K:\\cmdtrans.bin",                             
						GENERIC_READ | GENERIC_WRITE,                             
						FILE_SHARE_READ,                             
						NULL,                             
						OPEN_EXISTING,                             
						FILE_FLAG_OVERLAPPED | FILE_FLAG_NO_BUFFERING,                            
						NULL);
if( SourceFile == INVALID_HANDLE_VALUE )	return;

IoPort = CreateIoCompletionPort(SourceFile,		//file handle to associate with I/O completion port.                                                              
								NULL,			//optional handle to existing I/O completion port.                                       
								0,				//completion key.                                       
								1);    
if( IoPort == NULL )	return;

vFileSize = GetFileSize(SourceFile, NULL);
//if( vFileSize != 65536 )	return;

pBuf = VirtualAlloc(NULL, vFileSize, MEM_COMMIT, PAGE_READWRITE);  

if( pBuf == NULL )	return;
gCapFlag =1
//SetFilePointer(SourceFile, 0, NULL, FILE_BEGIN);
while(gCapFlag)
{
	if( SetFilePointer(SourceFile, 0, NULL, FILE_BEGIN) == 0xFFFFFFFF )		break;

	Overlapped.Offset = 0;       
	Overlapped.OffsetHigh = 0;  
	Overlapped.hEvent = NULL;     // not needed
	
	vStatus = WriteFile(SourceFile,pBuf,512,&nBytes, &Overlapped);
	//if(vStatus){


	ReadFile(SourceFile, pBuf, 65536, &nBytes, &Overlapped);
	//memcpy(gImgBuffer,pBuf,vFileSize);

	//						//}
	// 						if(vStatus)	{
	DispFP( hWnd, pBuf, 65536 );
	// 						}
	ClearMessage();
}
OutputDebugString("breaked!!!");
//SetFilePointer(SourceFile, 0, NULL, FILE_BEGIN);
	CloseHandle(SourceFile);
	CloseHandle(IoPort);

	VirtualFree(pBuf, 65536, MEM_DECOMMIT);
}
Posted
Updated 13-Nov-14 18:34pm
v2
Comments
Richard MacCutchan 14-Nov-14 4:40am    
You need to look at the documentation for both Linux and Android, which will be quite different from Windows.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900