阅读:1418回复:0
求助,KFILE读写文件的问题
我是一个超级菜鸟,刚刚接触DS的,我的系统:Win2000+ds2.7+vc6+2000ddk,
我在试验DS的例子程序RAMDISK,我想把它改造成一个FILEDISK程序,我在类RamdiskDevice的构造函数里,使用KFile类来打开一个硬盘上的文件,读写这个文件都是正常的,但是,当我把读写操作移到函数RamdiskDevice::ReadWrite(KIrp I)里面时候的,写文件是成功的,但是读文件总是失败,返回状态字为0XC0008,当时我认为可能是IRQ级别的文件,我就在类RamdiskDevice的构造函数里创建了一个系统线程: status = PsCreateSystemThread( //创建一个系统线程 &m_ThreadHandle, //线程句柄 (ACCESS_MASK) 0L, NULL, NULL, NULL, FileDiskThread,///线程地址 this //类RamdiskDevice的this 指针 ); status = ObReferenceObjectByHandle( m_ThreadHandle, THREAD_ALL_ACCESS, NULL, KernelMode, &m_thread_pointer, NULL ); 在线程FileDiskThread中有如下试验代码: ANSI_STRING AnsiStr; UNICODE_STRING UniStr; NTSTATUS stat; ULONG uLen; KFile kf; KTrace t; RtlInitAnsiString(&AnsiStr, \"\\\\DosDevices\\\\E:\\\\DISK_DISK.IMG\"); RtlAnsiStringToUnicodeString(&UniStr, &AnsiStr, TRUE); stat = kf.OpenCreate( &UniStr, NULL, FILE_GENERIC_READ | FILE_GENERIC_WRITE | SYNCHRONIZE, OBJ_CASE_INSENSITIVE, 0, FILE_SHARE_READ, FILE_OPEN, FILE_NON_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT ); RtlFreeUnicodeString(&UniStr); PUCHAR pBuff = new(NonPagedPool) UCHAR[512 * 128]; LARGE_INTEGER offset; memset(&offset, 0, sizeof offset); if (NULL != pBuff) { memset(pBuff, 0x5a, 512 * 128); uLen = 0; stat = kf.Write(pBuff, 512*128, &uLen, &offset); t.Trace(TraceAlways, \"WriteFile stat = 0X%x uLen=%d\", stat, uLen); uLen = 0; stat = kf.Read(pBuff, 512*128, &uLen, &offset); t.Trace(TraceAlways, \"ReadFile stat = 0X%x uLen=%d\", stat, uLen); delete pBuff; pBuff = NULL; } kf.Close(); 得到的调试信息: 00000001 0.00022573 WriteFile stat = 0Xc0000008 uLen=-1248002716 00000002 0.00024333 ReadFile stat = 0Xc0000008 uLen=-1248002716 00000005 0.00045285 WriteFile stat = 0Xc0000008 uLen=-1248002716 00000006 0.00046961 ReadFile stat = 0Xc0000008 uLen=-1248002716 求救,我改用什么方才才能读写文件?? |
|