阅读:2930回复:14
做卷快照时遇到的问题
请问各位朋友,如何将内存中的缓冲刷新到硬盘上呢?
|
|
沙发#
发布于:2007-11-20 23:08
,吼吼,顶
|
|
板凳#
发布于:2007-11-21 09:24
刷文件系统的缓存,直接向根目录发送IRP_MJ_FLUSH_BUFFERS就可以了,另外可能
IOCTL_VOLSNAP_FLUSH_AND_HOLD_WRITES更符合楼主的目的。 |
|
地板#
发布于:2007-11-21 16:05
谢谢老大,我这样调用导致了蓝屏,您帮我看看:
IO_STATUS_BLOCK ioStatusBlock; NTSTATUS ntStatus; PIRP irp; PFILE_OBJECT fileObject; PDEVICE_OBJECT deviceObject; KEVENT event; UNICODE_STRING name; RtlInitUnicodeString(&name, L"\\Ntfs"); ntStatus = IoGetDeviceObjectPointer(&name, FILE_READ_ATTRIBUTES, &fileObject, &deviceObject); if (!NT_SUCCESS(ntStatus)) { return ntStatus; } KeInitializeEvent(&event, NotificationEvent, FALSE); irp = IoBuildDeviceIoControlRequest (IOCTL_VOLSNAP_FLUSH_AND_HOLD_WRITES, deviceObject, InputBuffer, InputBufferSize, OutputBuffer, OutputBufferSize, FALSE, &event, &ioStatusBlock); if (irp == NULL) { ObDereferenceObject(fileObject); return STATUS_INSUFFICIENT_RESOURCES; } ntStatus = IoCallDriver (deviceObject, irp); if (ntStatus == STATUS_PENDING) { KeWaitForSingleObject (&event, UserRequest, UserMode, FALSE, NULL); ntStatus = ioStatusBlock.Status; } ObDereferenceObject(fileObject); return ntStatus; |
|
地下室#
发布于:2007-11-22 09:33
看看fastfat源码,IOCTL_VOLSNAP_FLUSH_AND_HOLD_WRITES不是文件系统控制设备的控制命令。
|
|
5楼#
发布于:2007-11-22 14:21
老大帮帮忙啊,我这么调用,是“拒绝访问”的错误提示。
var hTmp:THandle; mBytesReturned:Cardinal; VOLSNAPCONTROLTYPE,IOCTL_VOLSNAP_FLUSH_AND_HOLD_WRITES:Cardinal; begin VOLSNAPCONTROLTYPE := (ULONG('S')); IOCTL_VOLSNAP_FLUSH_AND_HOLD_WRITES := CTL_CODE(VOLSNAPCONTROLTYPE, 0, METHOD_BUFFERED, FILE_READ_ACCESS or FILE_WRITE_ACCESS); hTmp := CreateFile('\\.\C:', 0,0, nil, OPEN_EXISTING, 0,0); Result:=(hTmp<>INVALID_HANDLE_VALUE); if not Result then begin Raise Exception.Create('1 ' + SysErrorMessage(GetLastError())); end; if not Windows.DeviceIoControl( hTmp, IOCTL_VOLSNAP_FLUSH_AND_HOLD_WRITES, nil, 0, nil, 0, mBytesReturned, nil ) then begin CloseHandle(hTmp); Raise Exception.Create('2 ' + SysErrorMessage(GetLastError)); end; CloseHandle(hTmp); Result:=True; end; |
|
6楼#
发布于:2007-11-22 15:37
CreateFile参数不对。dwDesiredAccess不能为0
|
|
7楼#
发布于:2007-11-22 18:38
tooflat老大,改成这样,现在的错误是DeviceIoControl返回“参数错误”。
var hTmp:THandle; mBytesReturned:Cardinal; VOLSNAPCONTROLTYPE,IOCTL_VOLSNAP_FLUSH_AND_HOLD_WRITES:Cardinal; begin hTmp := CreateFile('\\.\C:", GENERIC_READ or GENERIC_WRITE, FILE_SHARE_READ or FILE_SHARE_WRITE, nil, OPEN_EXISTING, 0,0); Result:=(hTmp<>INVALID_HANDLE_VALUE); if not Result then begin Raise Exception.CreateFmt(ERR_CONNECT_SERVER,[STR_PROTECTION_SERVICE + '1',SysErrorMessage(GetLastError)]); end; FlushFileBuffers(hTmp); VOLSNAPCONTROLTYPE := (Ord('S')); IOCTL_VOLSNAP_FLUSH_AND_HOLD_WRITES := CTL_CODE(VOLSNAPCONTROLTYPE, 0, METHOD_BUFFERED, FILE_READ_ACCESS or FILE_WRITE_ACCESS); mBytesReturned:=0; Result:=Windows.DeviceIoControl( hTmp, IOCTL_VOLSNAP_FLUSH_AND_HOLD_WRITES, nil, 0, nil, 0, mBytesReturned, nil ); if not Result then begin CloseHandle(hTmp); Raise Exception.CreateFmt(ERR_CONNECT_SERVER,[STR_PROTECTION_SERVICE + '3',SysErrorMessage(GetLastError)]); end; CloseHandle(hTmp); Result:=True; end; |
|
8楼#
发布于:2007-11-22 22:12
顶一下
|
|
9楼#
发布于:2007-11-23 11:18
,比较难
|
|
10楼#
发布于:2007-11-23 17:00
貌似很难,在学习FastFat代码中.....
|
|
11楼#
发布于:2007-11-27 11:41
,再顶
|
|
12楼#
发布于:2007-11-27 14:19
这个IOCTL能把文件从磁盘中召回还是把文件缓存写到磁盘?
|
|
|
13楼#
发布于:2007-11-28 12:37
搞定了,谢谢各位。
|
|
14楼#
发布于:2011-01-26 15:35
回 13楼(lovehhy) 的帖子
怎么搞定的,贴出来啊。不能只提问题,不给答题啊,即使答案后来是自己搞定的。 大家遇到相同的问题,搜索跑到这来,最后看不到问题怎么解决,多郁闷啊。 |
|