阅读:1227回复:0
如何用ZwCreateFile打开USB磁盘,进行Sector操作?!
我在磁盘驱动层,如何可以操作一个U盘(如“F:”盘)进行SECTOR扇区的读写,以便实现以上功能。
以下为目前测试写事例,总是写不成功??? NTSTATUS ntStatus; OBJECT_ATTRIBUTES objectAttributes; WCHAR FileName[1024] = L"\\DosDevices\\F:\\"; UNICODE_STRING fileNameUnicodeString; HANDLE ntFileHandle; IO_STATUS_BLOCK ioStatus; LARGE_INTEGER ByteOffset; DbgPrint(("UsbDiskDrive called\n")); RtlZeroMemory( &ByteOffset, sizeof( LARGE_INTEGER ) ); RtlInitUnicodeString( &fileNameUnicodeString, FileName ); InitializeObjectAttributes( &objectAttributes, &fileNameUnicodeString, OBJ_CASE_INSENSITIVE, NULL, NULL ); //SYNCHRONIZE|FILE_ANY_ACCESS, ntStatus = ZwCreateFile(\ &ntFileHandle,\ GENERIC_READ | GENERIC_WRITE,\ &objectAttributes,\ &ioStatus,\ NULL,\ 0,\ FILE_SHARE_READ | FILE_SHARE_WRITE,\ FILE_OPEN,\ FILE_RANDOM_ACCESS|FILE_SYNCHRONOUS_IO_NONALERT|FILE_DIRECTORY_FILE,\ NULL,\ 0 ); if( !NT_SUCCESS( ntStatus ) ){ DbgPrint("UsbDiskDrive called 0.\n"); DbgPrint("Filemon: Could not open drive %c: %x\n", 'F', ntStatus ); return FALSE; } DbgPrint("UsbDiskDrive called 1.\n"); DbgPrint("Filemon: opened the root directory!!! handle: %p\n", ntFileHandle); ntStatus = ZwWriteFile( ntFileHandle, NULL, NULL, NULL, &ioStatus, (PUCHAR)FileName, 1024, &ByteOffset, NULL ); if( !NT_SUCCESS( ntStatus ) ){ DbgPrint("UsbDiskDrive write 1024 bytes failure !\n"); ZwClose( ntFileHandle ); return FALSE; } DbgPrint("UsbDiskDrive write 1024 bytes success !\n"); ZwClose( ntFileHandle ); 任务紧急,还希望各位帮忙喔! |
|
|