阅读:1227回复:6
filedisk如何将文件改为虚拟一个磁盘内的部分空间???
filedisk是将一个文件虚拟为一个驱动器。我们现在想把一个磁盘内的部分空间虚拟为一个驱动器。
时间紧,任务急!!!请问各位高手: 在磁盘驱动层,如何操作一个磁盘(驱动器,如“F:”盘)读写,以便实现以上功能。 以下为目前测试写事例,总是写不成功??? 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 ); |
|
|
沙发#
发布于:2007-07-10 11:15
备注:我们最终可能要直接操作U盘的部分空间。
各位高手路过,请一定要多指点呀!!!!!!! |
|
|
板凳#
发布于:2007-07-10 11:58
你用在什么系统上啊,
读写在2000/xp上用CreateFile,ReadFile,WriteFile |
|
地板#
发布于:2007-07-10 18:46
在2000/XP系统,我们不在用户态操作U盘
而是在内核驱动(filedisk)中使用,因此直接用createfile不行的。 但我想createfile一定是调用了内核的ZwCreateFile函数,所以一定有办法的。 大家帮忙看看我实现的代码有什么问题?! |
|
|
地下室#
发布于:2007-07-11 09:58
路过的朋友一定给出出注意呀,这里先谢了!?
|
|
|
5楼#
发布于:2007-07-11 12:22
向disk DO发送SRB去读写
|
|
|
6楼#
发布于:2007-07-11 12:47
5楼仁兄:不好意思,我是新手。
disk DO如何使用,请指点一二?! |
|
|