ReactOS是一些高手根据Windows XP的内核编写出的类XP。内核实现机理和API函数调用几乎相同。甚至可以兼容XP的程序。喜欢研究系统内核的人可以看一看。

源代码在线查看: delete.c

软件大小: 40209 K
上传用户: xushenghao001
关键词: ReactOS Windows 内核 API
下载地址: 免注册下载 普通下载 VIP

相关代码

				/* $Id: delete.c 21253 2006-03-08 21:33:04Z audit $
				 *
				 * COPYRIGHT:       See COPYING in the top level directory
				 * PROJECT:         ReactOS system libraries
				 * FILE:            lib/kernel32/file/delete.c
				 * PURPOSE:         Deleting files
				 * PROGRAMMER:      Ariadne (ariadne@xs4all.nl)
				 * UPDATE HISTORY:
				 *                  Created 01/11/98
				 */
				
				/* INCLUDES ****************************************************************/
				
				#include 
				
				#define NDEBUG
				#include "../include/debug.h"
				
				
				/* FUNCTIONS ****************************************************************/
				
				/*
				 * @implemented
				 */
				BOOL
				STDCALL
				DeleteFileA (
					LPCSTR	lpFileName
					)
				{
					PWCHAR FileNameW;
				
				   if (!(FileNameW = FilenameA2W(lpFileName, FALSE)))
				      return FALSE;
				
					return DeleteFileW (FileNameW);
				}
				
				
				/*
				 * @implemented
				 */
				BOOL
				STDCALL
				DeleteFileW (
					LPCWSTR	lpFileName
					)
				{
					FILE_DISPOSITION_INFORMATION FileDispInfo;
					OBJECT_ATTRIBUTES ObjectAttributes;
					IO_STATUS_BLOCK IoStatusBlock;
					UNICODE_STRING NtPathU;
					HANDLE FileHandle;
					NTSTATUS Status;
				
					DPRINT("DeleteFileW (lpFileName %S)\n",lpFileName);
				
					if (!RtlDosPathNameToNtPathName_U (lpFileName,
					                                   &NtPathU,
					                                   NULL,
					                                   NULL))
				   {
				      SetLastError(ERROR_PATH_NOT_FOUND);
						return FALSE;
				   }
				
					DPRINT("NtPathU \'%wZ\'\n", &NtPathU);
				
				        InitializeObjectAttributes(&ObjectAttributes,
				                                   &NtPathU,
				                                   OBJ_CASE_INSENSITIVE,
				                                   NULL,
				                                   NULL);
				
					Status = NtCreateFile (&FileHandle,
					                       DELETE,
					                       &ObjectAttributes,
					                       &IoStatusBlock,
					                       NULL,
					                       FILE_ATTRIBUTE_NORMAL,
					                       FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
					                       FILE_OPEN,
				                               FILE_NON_DIRECTORY_FILE,
					                       NULL,
					                       0);
				
					RtlFreeHeap(RtlGetProcessHeap(),
				                    0,
				                    NtPathU.Buffer);
				
					if (!NT_SUCCESS(Status))
					{
						CHECKPOINT;
						SetLastErrorByStatus (Status);
						return FALSE;
					}
				
					FileDispInfo.DeleteFile = TRUE;
				
					Status = NtSetInformationFile (FileHandle,
					                               &IoStatusBlock,
					                               &FileDispInfo,
					                               sizeof(FILE_DISPOSITION_INFORMATION),
					                               FileDispositionInformation);
					if (!NT_SUCCESS(Status))
					{
						CHECKPOINT;
						NtClose (FileHandle);
						SetLastErrorByStatus (Status);
						return FALSE;
					}
				
					Status = NtClose (FileHandle);
					if (!NT_SUCCESS (Status))
					{
						CHECKPOINT;
						SetLastErrorByStatus (Status);
						return FALSE;
					}
				
					return TRUE;
				}
				
				/* EOF */
							

相关资源