|
@@ -24,9 +24,60 @@ static struct errortab errortab_end[0]
|
24
|
24
|
__table_end ( struct errortab, errortab );
|
25
|
25
|
|
26
|
26
|
/**
|
27
|
|
- * Retrieve string representation of error number.
|
|
27
|
+ * Find error description
|
|
28
|
+ *
|
|
29
|
+ * @v errno Error number
|
|
30
|
+ * @v mask Mask of bits that we care about
|
|
31
|
+ * @ret errortab Error description, or NULL
|
|
32
|
+ */
|
|
33
|
+static struct errortab * find_error ( int errno, int mask ) {
|
|
34
|
+ struct errortab *errortab;
|
|
35
|
+
|
|
36
|
+ for ( errortab = errortab_start ; errortab < errortab_end ;
|
|
37
|
+ errortab++ ) {
|
|
38
|
+ if ( ( ( errortab->errno ^ errno ) & mask ) == 0 )
|
|
39
|
+ return errortab;
|
|
40
|
+ }
|
|
41
|
+
|
|
42
|
+ return NULL;
|
|
43
|
+}
|
|
44
|
+
|
|
45
|
+/**
|
|
46
|
+ * Find closest error description
|
28
|
47
|
*
|
29
|
48
|
* @v errno Error number
|
|
49
|
+ * @ret errortab Error description, or NULL
|
|
50
|
+ *
|
|
51
|
+ *
|
|
52
|
+ */
|
|
53
|
+static struct errortab * find_closest_error ( int errno ) {
|
|
54
|
+ struct errortab *errortab;
|
|
55
|
+
|
|
56
|
+ /* First, look for an exact match */
|
|
57
|
+ if ( ( errortab = find_error ( errno, 0x7fffffff ) ) != NULL )
|
|
58
|
+ return errortab;
|
|
59
|
+
|
|
60
|
+ /* Second, try masking off the gPXE-specific bit and seeing if
|
|
61
|
+ * we have an entry for the generic POSIX error message.
|
|
62
|
+ */
|
|
63
|
+ if ( ( errortab = find_error ( errno, 0x0000ffff ) ) != NULL )
|
|
64
|
+ return errortab;
|
|
65
|
+
|
|
66
|
+ /* Lastly, try masking off the POSIX bits and seeing if we
|
|
67
|
+ * have a match just based on the PXENV component. This
|
|
68
|
+ * allows us to report errors from underlying PXE stacks.
|
|
69
|
+ */
|
|
70
|
+ if ( ( errortab = find_error ( ( errno & 0x000000ff ),
|
|
71
|
+ 0xffff00ff ) ) != NULL )
|
|
72
|
+ return errortab;
|
|
73
|
+
|
|
74
|
+ return NULL;
|
|
75
|
+}
|
|
76
|
+
|
|
77
|
+/**
|
|
78
|
+ * Retrieve string representation of error number.
|
|
79
|
+ *
|
|
80
|
+ * @v errno/rc Error number or return status code
|
30
|
81
|
* @ret strerror Pointer to error text
|
31
|
82
|
*
|
32
|
83
|
* If the error is not found in the linked-in error tables, generates
|
|
@@ -37,21 +88,25 @@ static struct errortab errortab_end[0]
|
37
|
88
|
*
|
38
|
89
|
*/
|
39
|
90
|
const char * strerror ( int errno ) {
|
40
|
|
- static char *generic_message = "Error 0x0000";
|
|
91
|
+ static char errbuf[64];
|
41
|
92
|
struct errortab *errortab;
|
42
|
93
|
|
43
|
94
|
/* Allow for strerror(rc) as well as strerror(errno) */
|
44
|
95
|
if ( errno < 0 )
|
45
|
96
|
errno = -errno;
|
46
|
97
|
|
47
|
|
- for ( errortab = errortab_start ; errortab < errortab_end ;
|
48
|
|
- errortab++ ) {
|
49
|
|
- if ( errortab->errno == errno )
|
50
|
|
- return errortab->text;
|
|
98
|
+ /* Find the error description, if one exists */
|
|
99
|
+ errortab = find_closest_error ( errno );
|
|
100
|
+
|
|
101
|
+ /* Construct the error message */
|
|
102
|
+ if ( errortab ) {
|
|
103
|
+ snprintf ( errbuf, sizeof ( errbuf ), "%s (%#08x)",
|
|
104
|
+ errortab->text, errno );
|
|
105
|
+ } else {
|
|
106
|
+ snprintf ( errbuf, sizeof ( errbuf ), "Error %#08x", errno );
|
51
|
107
|
}
|
52
|
108
|
|
53
|
|
- sprintf ( generic_message + 8, "%hx", errno );
|
54
|
|
- return generic_message;
|
|
109
|
+ return errbuf;
|
55
|
110
|
}
|
56
|
111
|
|
57
|
112
|
/** The most common errors */
|