4 #include <ipxe/errortab.h>
5 #include <config/branding.h>
11 * The error numbers used by Etherboot are a superset of those defined
12 * by the PXE specification version 2.1. See errno.h for a listing of
15 * To save space in ROM images, error string tables are optional. Use
16 * the ERRORMSG_XXX options in config.h to select which error string
17 * tables you want to include. If an error string table is omitted,
18 * strerror() will simply return the text "Error 0x<errno>".
22 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL
);
25 * Find error description
27 * @v errno Error number
28 * @ret errortab Error description, or NULL
30 static struct errortab
* find_error ( int errno
) {
31 struct errortab
*errortab
;
33 for_each_table_entry ( errortab
, ERRORTAB
) {
34 if ( errortab
->errno
== errno
)
42 * Find closest error description
44 * @v errno Error number
45 * @ret errortab Error description, or NULL
49 static struct errortab
* find_closest_error ( int errno
) {
50 struct errortab
*errortab
;
52 /* First, look for an exact match */
53 if ( ( errortab
= find_error ( errno
) ) != NULL
)
56 /* Second, try masking off the iPXE-specific bit and seeing if
57 * we have an entry for the generic POSIX error message.
59 if ( ( errortab
= find_error ( errno
& 0x7f0000ff ) ) != NULL
)
66 * Retrieve string representation of error number.
68 * @v errno/rc Error number or return status code
69 * @ret strerror Pointer to error text
71 * If the error is not found in the linked-in error tables, generates
72 * a generic "Error 0x<errno>" message.
74 * The pointer returned by strerror() is valid only until the next
78 char * strerror ( int errno
) {
79 static char errbuf
[64];
80 struct errortab
*errortab
;
82 /* Allow for strerror(rc) as well as strerror(errno) */
86 /* Find the error description, if one exists */
87 errortab
= find_closest_error ( errno
);
89 /* Construct the error message */
91 snprintf ( errbuf
, sizeof ( errbuf
),
92 "%s (" PRODUCT_ERROR_URI
")",
93 errortab
->text
, errno
);
95 snprintf ( errbuf
, sizeof ( errbuf
),
96 "Error %#08x (" PRODUCT_ERROR_URI
")",
103 /* Do not include ERRFILE portion in the numbers in the error table */
107 /** The most common errors */
108 struct errortab common_errors
[] __errortab
= {
109 __einfo_errortab ( EINFO_ENOERR
),
110 __einfo_errortab ( EINFO_EACCES
),
111 __einfo_errortab ( EINFO_ECANCELED
),
112 __einfo_errortab ( EINFO_ECONNRESET
),
113 __einfo_errortab ( EINFO_EINVAL
),
114 __einfo_errortab ( EINFO_EIO
),
115 __einfo_errortab ( EINFO_ENETUNREACH
),
116 __einfo_errortab ( EINFO_ENODEV
),
117 __einfo_errortab ( EINFO_ENOENT
),
118 __einfo_errortab ( EINFO_ENOEXEC
),
119 __einfo_errortab ( EINFO_ENOMEM
),
120 __einfo_errortab ( EINFO_ENOSPC
),
121 __einfo_errortab ( EINFO_ENOTCONN
),
122 __einfo_errortab ( EINFO_ENOTSUP
),
123 __einfo_errortab ( EINFO_EPERM
),
124 __einfo_errortab ( EINFO_ERANGE
),
125 __einfo_errortab ( EINFO_ETIMEDOUT
),