驱动中确认文件是否存在的一个方法

来源:互联网 发布:安卓手机备份数据 编辑:程序博客网 时间:2024/06/06 03:54

http://www.osronline.com/showThread.cfm?link=43778

//// Check if a local file or dir exists (via open)//BOOL CheckElementExistsViaOpen( PUNICODE_STRING puPath ){DBGASSERTIRQLEQUAL(PASSIVE_LEVEL);IO_STATUS_BLOCK IoStatus;NTSTATUS status = GetExistanceStatus( puPath, &IoStatus );if( NT_SUCCESS(status) ){return TRUE;}else if( (status == STATUS_OBJECT_NAME_NOT_FOUND) || (IoStatus.Information == FILE_DOES_NOT_EXIST) || (status == STATUS_OBJECT_PATH_NOT_FOUND) || (status == STATUS_OBJECT_NAME_INVALID) || (status == STATUS_OBJECT_PATH_INVALID) ){return FALSE;}return TRUE;}//// Get element's existance status//NTSTATUS GetExistanceStatus( PUNICODE_STRING puPath, PIO_STATUS_BLOCKpIoStatus ){DBGASSERTIRQLEQUAL(PASSIVE_LEVEL);NTSTATUS status;OBJECT_ATTRIBUTES aFileAttrib;FILE_NETWORK_OPEN_INFORMATION aInfo;#if (WINVER>=0x500)InitializeObjectAttributes( &aFileAttrib, puPath,OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL );#elseInitializeObjectAttributes( &aFileAttrib, puPath,OBJ_CASE_INSENSITIVE, NULL, NULL );#endif//// Use FastOpen (if possible). If not that call will roll// create IRP.//status = IoFastQueryNetworkAttributes( &aFileAttrib, SYNCHRONIZE, 0,pIoStatus, &aInfo);if( NT_SUCCESS(status) ){status = pIoStatus -> Status; }return status;}


0 0
原创粉丝点击