Reactos

[TDILIB] Make tdiGetSetOfThings() return useful status

+40 -26
+40 -26
sdk/lib/tdilib/enum.c
··· 34 34 TCP_REQUEST_QUERY_INFORMATION_EX req = TCP_REQUEST_QUERY_INFORMATION_INIT; 35 35 PVOID entitySet = 0; 36 36 NTSTATUS status = STATUS_SUCCESS; 37 - DWORD allocationSizeForEntityArray = entrySize * MAX_TDI_ENTITIES, 38 - arraySize = entrySize * MAX_TDI_ENTITIES; 37 + DWORD allocationSizeForEntityArray = entrySize * MAX_TDI_ENTITIES; 38 + IO_STATUS_BLOCK Iosb; 39 39 40 40 req.ID.toi_class = toiClass; 41 41 req.ID.toi_type = toiType; ··· 52 52 * stabilizes. 53 53 */ 54 54 do { 55 - status = DeviceIoControl( tcpFile, 56 - IOCTL_TCP_QUERY_INFORMATION_EX, 57 - &req, 58 - sizeof(req), 59 - 0, 60 - 0, 61 - &allocationSizeForEntityArray, 62 - NULL ); 55 + status = NtDeviceIoControlFile( tcpFile, 56 + NULL, 57 + NULL, 58 + NULL, 59 + &Iosb, 60 + IOCTL_TCP_QUERY_INFORMATION_EX, 61 + &req, 62 + sizeof(req), 63 + NULL, 64 + 0); 65 + if (status == STATUS_PENDING) 66 + { 67 + status = NtWaitForSingleObject(tcpFile, FALSE, NULL); 68 + if (NT_SUCCESS(status)) status = Iosb.Status; 69 + } 63 70 64 - if(!status) 71 + if(!NT_SUCCESS(status)) 65 72 { 66 - return STATUS_UNSUCCESSFUL; 73 + return status; 67 74 } 68 75 69 - arraySize = allocationSizeForEntityArray; 70 - entitySet = HeapAlloc( GetProcessHeap(), 0, arraySize ); 76 + allocationSizeForEntityArray = Iosb.Information; 77 + entitySet = HeapAlloc( GetProcessHeap(), 0, allocationSizeForEntityArray ); 71 78 72 79 if( !entitySet ) { 73 80 status = STATUS_INSUFFICIENT_RESOURCES; 74 81 return status; 75 82 } 76 83 77 - status = DeviceIoControl( tcpFile, 78 - IOCTL_TCP_QUERY_INFORMATION_EX, 79 - &req, 80 - sizeof(req), 81 - entitySet, 82 - arraySize, 83 - &allocationSizeForEntityArray, 84 - NULL ); 84 + status = NtDeviceIoControlFile( tcpFile, 85 + NULL, 86 + NULL, 87 + NULL, 88 + &Iosb, 89 + IOCTL_TCP_QUERY_INFORMATION_EX, 90 + &req, 91 + sizeof(req), 92 + entitySet, 93 + allocationSizeForEntityArray); 94 + if (status == STATUS_PENDING) 95 + { 96 + status = NtWaitForSingleObject(tcpFile, FALSE, NULL); 97 + if (NT_SUCCESS(status)) status = Iosb.Status; 98 + } 85 99 86 100 /* This is why we have the loop -- we might have added an adapter */ 87 - if( arraySize == allocationSizeForEntityArray ) 101 + if( Iosb.Information == allocationSizeForEntityArray ) 88 102 break; 89 103 90 104 HeapFree( GetProcessHeap(), 0, entitySet ); 91 105 entitySet = 0; 92 106 93 - if(!status) 94 - return STATUS_UNSUCCESSFUL; 107 + if(!NT_SUCCESS(status)) 108 + return status; 95 109 } while( TRUE ); /* We break if the array we received was the size we 96 110 * expected. Therefore, we got here because it wasn't */ 97 111 98 - *numEntries = (arraySize - fixedPart) / entrySize; 112 + *numEntries = (allocationSizeForEntityArray - fixedPart) / entrySize; 99 113 *tdiEntitySet = entitySet; 100 114 101 115 return STATUS_SUCCESS;