阅读:1985回复:3
为什么ZwCreateFile会阻塞?如何避免被阻塞
用ZwCreateFile打开一个MSD卡上的文件,正常时不会出现问题。
但当MSD卡读卡器不稳定时,比如之前能访问MSD卡上文件,当读卡器出现问题时(MSD卡对应的盘不能打开),下面的程序将在ZwCreateFile处被一直阻塞。 请问为什么ZwCreateFile会被阻塞? 怎样才能防止被阻塞? 程序如下 OBJECT_ATTRIBUTES objectAttributes; IO_STATUS_BLOCK iostatus; UNICODE_STRING ustrFileName; RtlInitUnicodeString(&ustrFileName, L"\\??\\G:\\Test.bin"); //初始化objectAttributes InitializeObjectAttributes(&objectAttributes, &ustrFileName, OBJ_CASE_INSENSITIVE,//对大小写不敏感 NULL, NULL ); status = ZwCreateFile(&fd, GENERIC_WRITE | GENERIC_READ, &objectAttributes, &iostatus, NULL, FILE_ATTRIBUTE_NORMAL, FILE_SHARE_READ|FILE_SHARE_WRITE, //Device and intermediate drivers usually set ShareAccess to zero, which gives the caller exclusive access to the open file. FILE_OPEN_IF, //If the file already exists, open it. If it does not, create the given file. 0, NULL, 0); if (status != STATUS_SUCCESS) { KdPrint(("ZwCreateFile failed. [%08x]\n", status)); pCtx->fd = NULL; return status; } KdPrint(("iostatus.Information = [%08x]\n", iostatus.Information)); |
|