-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathioreturn-text.c
118 lines (112 loc) · 7.55 KB
/
ioreturn-text.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <IOKit/IOReturn.h>
/**
* Returns a string containing a verbal description of the specified IOReturn code.
*
* The caller is responsible for freeing the returned string.
*
* Copyright (C) 2015 Steve Mokris. Use and distribution permitted under the terms of the Apache License Version 2.0.
*/
char *getIOReturnText(IOReturn ret)
{
if (err_get_code(ret) == err_get_code(kIOReturnSuccess))
return strdup("OK");
int sys = err_get_system(ret);
char *sysText;
if (sys == err_get_system(sys_iokit)) sysText = strdup("IOKit");
else
asprintf(&sysText, "unknown(0x%04x)", sys);
int sub = err_get_sub(ret);
char *subText;
if (sub == err_get_sub(sub_iokit_common)) subText = strdup("Common");
else if (sub == err_get_sub(sub_iokit_usb)) subText = strdup("USB");
else if (sub == err_get_sub(sub_iokit_firewire)) subText = strdup("Firewire");
else if (sub == err_get_sub(sub_iokit_block_storage)) subText = strdup("Storage");
else if (sub == err_get_sub(sub_iokit_graphics)) subText = strdup("Graphics");
else if (sub == err_get_sub(sub_iokit_networking)) subText = strdup("Networking");
else if (sub == err_get_sub(sub_iokit_bluetooth)) subText = strdup("Bluetooth");
else if (sub == err_get_sub(sub_iokit_pmu)) subText = strdup("PMU");
else if (sub == err_get_sub(sub_iokit_acpi)) subText = strdup("ACPI");
else if (sub == err_get_sub(sub_iokit_smbus)) subText = strdup("SMBUS");
else if (sub == err_get_sub(sub_iokit_ahci)) subText = strdup("AHCI");
else if (sub == err_get_sub(sub_iokit_powermanagement)) subText = strdup("Power Management");
else if (sub == err_get_sub(sub_iokit_hidsystem)) subText = strdup("HID System");
else if (sub == err_get_sub(sub_iokit_scsi)) subText = strdup("SCSI");
else if (sub == err_get_sub(sub_iokit_thunderbolt)) subText = strdup("Thunderbolt");
else if (sub == err_get_sub(sub_iokit_audio_video)) subText = strdup("Audio/Video");
else if (sub == err_get_sub(sub_iokit_hsic)) subText = strdup("HSIC");
else if (sub == err_get_sub(sub_iokit_sdio)) subText = strdup("SDIO");
else if (sub == err_get_sub(sub_iokit_wlan)) subText = strdup("WLAN");
else if (sub == err_get_sub(sub_iokit_vendor_specific)) subText = strdup("Vendor-specific");
else if (sub == err_get_sub(sub_iokit_reserved)) subText = strdup("Reserved");
else asprintf(&subText, "unknown(0x%04x)", sub);
int err = err_get_code(ret);
char *errText;
if (err == err_get_code(kIOReturnError)) errText = strdup("general error");
else if (err == err_get_code(kIOReturnNoMemory)) errText = strdup("can't allocate memory");
else if (err == err_get_code(kIOReturnNoResources)) errText = strdup("resource shortage");
else if (err == err_get_code(kIOReturnIPCError)) errText = strdup("error during IPC");
else if (err == err_get_code(kIOReturnNoDevice)) errText = strdup("no such device");
else if (err == err_get_code(kIOReturnNotPrivileged)) errText = strdup("privilege violation");
else if (err == err_get_code(kIOReturnBadArgument)) errText = strdup("invalid argument");
else if (err == err_get_code(kIOReturnLockedRead)) errText = strdup("device read locked");
else if (err == err_get_code(kIOReturnLockedWrite)) errText = strdup("device write locked");
else if (err == err_get_code(kIOReturnExclusiveAccess)) errText = strdup("exclusive access and device already open");
else if (err == err_get_code(kIOReturnBadMessageID)) errText = strdup("sent/received messages had different msg_id");
else if (err == err_get_code(kIOReturnUnsupported)) errText = strdup("unsupported function");
else if (err == err_get_code(kIOReturnVMError)) errText = strdup("misc. VM failure");
else if (err == err_get_code(kIOReturnInternalError)) errText = strdup("internal error");
else if (err == err_get_code(kIOReturnIOError)) errText = strdup("general I/O error");
else if (err == err_get_code(kIOReturnCannotLock)) errText = strdup("can't acquire lock");
else if (err == err_get_code(kIOReturnNotOpen)) errText = strdup("device not open");
else if (err == err_get_code(kIOReturnNotReadable)) errText = strdup("read not supported");
else if (err == err_get_code(kIOReturnNotWritable)) errText = strdup("write not supported");
else if (err == err_get_code(kIOReturnNotAligned)) errText = strdup("alignment error");
else if (err == err_get_code(kIOReturnBadMedia)) errText = strdup("media error");
else if (err == err_get_code(kIOReturnStillOpen)) errText = strdup("device(s) still open");
else if (err == err_get_code(kIOReturnRLDError)) errText = strdup("rld failure");
else if (err == err_get_code(kIOReturnDMAError)) errText = strdup("DMA failure");
else if (err == err_get_code(kIOReturnBusy)) errText = strdup("device busy");
else if (err == err_get_code(kIOReturnTimeout)) errText = strdup("I/O Timeout");
else if (err == err_get_code(kIOReturnOffline)) errText = strdup("device offline");
else if (err == err_get_code(kIOReturnNotReady)) errText = strdup("not ready");
else if (err == err_get_code(kIOReturnNotAttached)) errText = strdup("device not attached");
else if (err == err_get_code(kIOReturnNoChannels)) errText = strdup("no DMA channels left");
else if (err == err_get_code(kIOReturnNoSpace)) errText = strdup("no space for data ");
else if (err == err_get_code(kIOReturnPortExists)) errText = strdup("port already exists");
else if (err == err_get_code(kIOReturnCannotWire)) errText = strdup("can't wire down physical memory");
else if (err == err_get_code(kIOReturnNoInterrupt)) errText = strdup("no interrupt attached");
else if (err == err_get_code(kIOReturnNoFrames)) errText = strdup("no DMA frames enqueued");
else if (err == err_get_code(kIOReturnMessageTooLarge)) errText = strdup("oversized msg received on interrupt port");
else if (err == err_get_code(kIOReturnNotPermitted)) errText = strdup("not permitted");
else if (err == err_get_code(kIOReturnNoPower)) errText = strdup("no power to device");
else if (err == err_get_code(kIOReturnNoMedia)) errText = strdup("media not present");
else if (err == err_get_code(kIOReturnUnformattedMedia)) errText = strdup("edia not formatted");
else if (err == err_get_code(kIOReturnUnsupportedMode)) errText = strdup("no such mode");
else if (err == err_get_code(kIOReturnUnderrun)) errText = strdup("data underrun");
else if (err == err_get_code(kIOReturnOverrun)) errText = strdup("data overrun");
else if (err == err_get_code(kIOReturnDeviceError)) errText = strdup("the device is not working properly");
else if (err == err_get_code(kIOReturnNoCompletion)) errText = strdup("a completion routine is required");
else if (err == err_get_code(kIOReturnAborted)) errText = strdup("operation aborted");
else if (err == err_get_code(kIOReturnNoBandwidth)) errText = strdup("bus bandwidth would be exceeded");
else if (err == err_get_code(kIOReturnNotResponding)) errText = strdup("device not responding");
else if (err == err_get_code(kIOReturnIsoTooOld)) errText = strdup("isochronous I/O request for distant past");
else if (err == err_get_code(kIOReturnIsoTooNew)) errText = strdup("isochronous I/O request for distant future");
else if (err == err_get_code(kIOReturnNotFound)) errText = strdup("data was not found");
else if (err == err_get_code(kIOReturnInvalid)) errText = strdup("invalid");
else
asprintf(&errText, "unknown(0x%04x)", err);
char *text;
asprintf(&text, "%s %s: %s", sysText, subText, errText);
free(sysText);
free(subText);
free(errText);
return text;
}
int main(void)
{
IOReturn ret = -536870203;
printf("%08x %s\n", ret, getIOReturnText(ret));
}