4 #include <gpxe/errortab.h>
10 * The error numbers used by Etherboot are a superset of those defined
11 * by the PXE specification version 2.1. See errno.h for a listing of
14 * To save space in ROM images, error string tables are optional. Use
15 * the ERRORMSG_XXX options in config.h to select which error string
16 * tables you want to include. If an error string table is omitted,
17 * strerror() will simply return the text "Error 0x<errno>".
21 FILE_LICENCE ( GPL2_OR_LATER
);
24 * Find error description
26 * @v errno Error number
27 * @v mask Mask of bits that we care about
28 * @ret errortab Error description, or NULL
30 static struct errortab
* find_error ( int errno
, int mask
) {
31 struct errortab
*errortab
;
33 for_each_table_entry ( errortab
, ERRORTAB
) {
34 if ( ( ( errortab
->errno
^ errno
) & mask
) == 0 )
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
, 0x7fffffff ) ) != NULL
)
56 /* Second, try masking off the gPXE-specific bit and seeing if
57 * we have an entry for the generic POSIX error message.
59 if ( ( errortab
= find_error ( errno
, 0x4f0000ff ) ) != 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 const 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
), "%s (%#08x)",
92 errortab
->text
, errno
);
94 snprintf ( errbuf
, sizeof ( errbuf
), "Error %#08x", errno
);
100 /* Do not include ERRFILE portion in the numbers in the error table */
104 /** The most common errors */
105 struct errortab common_errors
[] __errortab
= {
107 { EACCES
, "Permission denied" },
108 { ECANCELED
, "Operation cancelled" },
109 { ECONNRESET
, "Connection reset" },
110 { EINVAL
, "Invalid argument" },
111 { EIO
, "Input/output error" },
112 { ENETUNREACH
, "Network unreachable" },
113 { ENODEV
, "No such device" },
114 { ENOENT
, "File not found" },
115 { ENOEXEC
, "Not an executable image" },
116 { ENOMEM
, "Out of memory" },
117 { ENOSPC
, "No space left on device" },
118 { ENOTCONN
, "Not connected" },
119 { ENOTSUP
, "Not supported" },
120 { EPERM
, "Operation not permitted" },
121 { ERANGE
, "Out of range" },
122 { ETIMEDOUT
, "Connection timed out" },