阅读:1234回复:8
怎么处理 Delete 请求?
我的目的是自己写个 文件系统, 影射到一个指定的目录, 创建,删除文件等操作。
现在在实现 Delete 操作的时候, 提示 “无法删除文件 无法读源文件或磁盘” 我想 Delete 可能涉及到 3个 例程, 1.在 Create 例程中, 如下处理的 if (RequestedDisposition==FILE_CREATE||RequestedDisposition==FILE_OPEN_IF|| RequestedDisposition==FILE_OVERWRITE_IF || RequestedDisposition==FILE_SUPERSEDE ) { 新建文件 } if (RequestedDisposition==FILE_OPEN || RequestedDisposition==FILE_OPEN_IF || RequestedDisposition==FILE_OVERWRITE_IF || RequestedDisposition==FILE_SUPERSEDE) { 打开文件 } 2. QueryFileInformation 中回填 File 的一些信息 3. SetFileInformation 中 置 DeleteFile 为 TRUE 第 3 步 始终没有执行 大虾们, 指点一下 [编辑 - 9/17/04 by newkey] |
|
|
沙发#
发布于:2004-09-17 13:27
你错了,
删除在 IRP_MJ_SETINFOMATION 中, 其实是ReName操作, |
|
板凳#
发布于:2004-09-17 14:56
看不出你是怎么区分新建文件和打开文件 if ( RequestedDisposition==FILE_OPEN_IF ) { ???? } |
|
|
地板#
发布于:2004-09-17 15:12
发表于: 2004/9/17 - 13:27
你错了, 删除在 IRP_MJ_SETINFOMATION 中, 其实是ReName操作, ------------------------------------ 我就是在 IRP_MJ_SETINFOMATION 处理 删除的,但就是没到这个地方来, ReName操作-〉 1.delete 2.new 应该是 ReName操作 包括 delete ,不应该 “其实是ReName操作”??? ======================================================= 看不出你是怎么区分新建文件和打开文件 FILE_CREATE FILE_OPEN 区别开 因为 FILE_OPEN_IF FILE_OVERWRITE_IF FILE_SUPERSEDE 这3个都是 “如果有,则打开; 没有,则创建” |
|
|
地下室#
发布于:2004-09-17 16:39
在 QueryDir 返回了 STATUS_NO_MORE_FILES, 所以导致 提示 “无法删除文件 无法读源文件或磁盘”
根据 《nt file sys>> 所描述 // There is one other piece of information that your FSD must store // in the CCB structure for query directory support. This is the index // value (i.e. the offset in your on-disk directory structure) from // which you should start searching. // However, the flags supplied with the IRP can make us override this // as well. if (FileIndex) { // Caller has told us wherefrom to begin. // You may need to round this to an appropriate directory entry // entry alignment value. StartingIndexForSearch = FileIndex; } else if (RestartScan) { StartingIndexForSearch = 0; } else { // Get the starting offset from the CCB. // Remember to update this value on your way out from this function. // But, do not update the CCB CurrentByteOffset field if you reach // the end of the directory (or get an error reading the directory) // while performing the search. StartingIndexForSearch = PtrCCB->CurrentByteOffset.LowPart; } // Now, your FSD must determine the best way to read the directory // contents from disk and search through them. // If ReturnSingleEntry is TRUE, please return information on only // one matching entry. // One final note though: // If you do not find a directory entry OR while searching you reach the // end of the directory, then the return code should be set as follows: // (a) If any files have been returned (i.e. ReturnSingleEntry was FALSE // and you did find at least one match), then return STATUS_SUCCESS // (b) If no entry is being returned then: // (i) If this is the first query i.e. FirstTimeQuery is TRUE // then return STATUS_NO_SUCH_FILE // (ii) Otherwise, return STATUS_NO_MORE_FILES -------------------------------------------------- 是这样处理吗? 1。 其中的 StartingIndexForSearch 是不是指 从第几项开始返回 (如: StartingIndexForSearch =5, 在我转向的目录中有9个文件,那我只填充 6,7,8,9 这几个文件给 FILE_BOTH_DIR_INFORMATION ) 2. STATUS = STATUS_SUCCESS; if (没有找到匹配的文件) if(FirstTimeQuery) return STATUS_NO_SUCH_FILE; else return STATUS_NO_MORE_FILES; return STATUS ; |
|
|
5楼#
发布于:2004-09-17 19:31
对于delete操作:
如果是使用shift+delete删除 则直接是在SetFileInformation中的FileDispositionInformation中完成 如果是按delete键删除 则是rename操作 因为windows会首先把它移动到回收站中 所以改成recyled/***之类的名字 |
|
6楼#
发布于:2004-09-17 19:36
这些你可以使用filemonitor观察到的
另外你还是要实现changenotify命令 这个才是解决rename和delete的关键 |
|
7楼#
发布于:2004-09-20 15:13
发表于: 2004/9/17 - 13:27 新生成文件,如何辨别系统是通过FILE_CREATE还是FILE_OPEN_IF、FILE_OVERWRITE_IF、FILE_SUPERSEDE 生成的? |
|
|
8楼#
发布于:2004-09-21 16:38
如果是新生成的文件,那么在irp完成后,Irp->IoStatus.Information == FILE_CREATED
|
|