Quellcode durchsuchen

Added errno, strerror and the "%m" printf metacharacter. These will allow

us to return proper PXE status codes, while simultaneously allowing for
more consistent error reporting (complete with verbose error messages as a
build-time option).
tags/v0.9.3
Michael Brown vor 19 Jahren
Ursprung
Commit
ff9104e029
3 geänderte Dateien mit 180 neuen und 9 gelöschten Zeilen
  1. 29
    0
      src/core/errno.c
  2. 13
    9
      src/core/vsprintf.c
  3. 138
    0
      src/include/errno.h

+ 29
- 0
src/core/errno.c Datei anzeigen

@@ -0,0 +1,29 @@
1
+#include "errno.h"
2
+#include "vsprintf.h"
3
+
4
+/* Global "last error" number */
5
+int errno;
6
+
7
+static struct errortab errortab_start[0] __table_start(errortab);
8
+static struct errortab errortab_end[0] __table_end(errortab);
9
+
10
+/*
11
+ * Retrieve string representation of error number.
12
+ *
13
+ * If error not found in the error table, generate a generic "Error
14
+ * 0x0000" message.
15
+ *
16
+ */
17
+const char * strerror ( int errno ) {
18
+	static char *generic_message = "Error 0x0000";
19
+	struct errortab *errortab;
20
+
21
+	for ( errortab = errortab_start ; errortab < errortab_end ;
22
+	      errortab++ ) {
23
+		if ( errortab->errno == errno )
24
+			return errortab->text;
25
+	}
26
+
27
+	sprintf ( generic_message + 8, "%hx", errno );
28
+	return generic_message;
29
+}

+ 13
- 9
src/core/vsprintf.c Datei anzeigen

@@ -2,6 +2,7 @@
2 2
 #include "if_ether.h" /* for ETH_ALEN */
3 3
 #include "limits.h" /* for CHAR_BIT */
4 4
 #include "console.h"
5
+#include "errno.h"
5 6
 #include "vsprintf.h"
6 7
 
7 8
 #define LONG_SHIFT  ((int)((sizeof(unsigned long)*CHAR_BIT) - 4))
@@ -31,7 +32,8 @@ PRINTF and friends
31 32
 **************************************************************************/
32 33
 static int vsprintf(char *buf, const char *fmt, va_list args)
33 34
 {
34
-	char *p, *s;
35
+	const char *p;
36
+	char *s;
35 37
 	s = buf;
36 38
 	for ( ; *fmt != '\0'; ++fmt) {
37 39
 		if (*fmt != '%') {
@@ -49,8 +51,10 @@ static int vsprintf(char *buf, const char *fmt, va_list args)
49 51
 		if (*fmt == 's') {
50 52
 			for(p = va_arg(args, char *); *p != '\0'; p++) 
51 53
 				buf ? *s++ = *p : putchar(*p);
52
-		}
53
-		else {	/* Length of item is bounded */
54
+		} else if (*fmt == 'm') {
55
+			for(p = strerror(errno); *p != '\0'; p++)
56
+				buf ? *s++ = *p : putchar(*p);
57
+		} else {	/* Length of item is bounded */
54 58
 			char tmp[40], *q = tmp;
55 59
 			int alt = 0;
56 60
 			int shift = INT_SHIFT;
@@ -93,7 +97,7 @@ static int vsprintf(char *buf, const char *fmt, va_list args)
93 97
 					*q++ = "0123456789ABCDEF"[(h >> shift) & 0xF] | ncase;
94 98
 			}
95 99
 			else if (*fmt == 'd') {
96
-				char *r;
100
+				char *r, *t;
97 101
 				long i;
98 102
 				if (shift > INT_SHIFT) {
99 103
 					i = va_arg(args, long);
@@ -104,17 +108,17 @@ static int vsprintf(char *buf, const char *fmt, va_list args)
104 108
 					*q++ = '-';
105 109
 					i = -i;
106 110
 				}
107
-				p = q;		/* save beginning of digits */
111
+				t = q;		/* save beginning of digits */
108 112
 				do {
109 113
 					*q++ = '0' + (i % 10);
110 114
 					i /= 10;
111 115
 				} while (i);
112 116
 				/* reverse digits, stop in middle */
113 117
 				r = q;		/* don't alter q */
114
-				while (--r > p) {
118
+				while (--r > t) {
115 119
 					i = *r;
116
-					*r = *p;
117
-					*p++ = i;
120
+					*r = *t;
121
+					*t++ = i;
118 122
 				}
119 123
 			}
120 124
 			else if (*fmt == '@') {
@@ -129,7 +133,7 @@ static int vsprintf(char *buf, const char *fmt, va_list args)
129 133
 				--q;
130 134
 			}
131 135
 			else if (*fmt == '!') {
132
-				char *r;
136
+				const char *r;
133 137
 				p = va_arg(args, char *);
134 138
 				for (r = p + ETH_ALEN; p < r; ++p)
135 139
 					q += sprintf(q, "%hhX:", *p);

+ 138
- 0
src/include/errno.h Datei anzeigen

@@ -0,0 +1,138 @@
1
+#ifndef ERRNO_H
2
+#define ERRNO_H
3
+
4
+/*
5
+ * We define error codes that are a superset of those mentioned in the
6
+ * PXE specification.  Various error string tables may be compiled in
7
+ * if required; if not compiled in, strerror(errno) will produce the
8
+ * text "error 0x<errno>".
9
+ *
10
+ */
11
+
12
+/* PXE error codes are determined by the PXE specification */
13
+
14
+/* Generic errors */
15
+#define	PXENV_STATUS_SUCCESS				0x00
16
+#define	PXENV_STATUS_FAILURE				0x01
17
+#define	PXENV_STATUS_BAD_FUNC				0x02
18
+#define	PXENV_STATUS_UNSUPPORTED			0x03
19
+#define	PXENV_STATUS_KEEP_UNDI				0x04
20
+#define	PXENV_STATUS_KEEP_ALL				0x05
21
+#define	PXENV_STATUS_OUT_OF_RESOURCES			0x06
22
+
23
+/* ARP errors (0x10 to 0x1f) */
24
+#define	PXENV_STATUS_ARP_TIMEOUT			0x11
25
+
26
+/* Base-Code state errors */
27
+#define	PXENV_STATUS_UDP_CLOSED				0x18
28
+#define	PXENV_STATUS_UDP_OPEN				0x19
29
+#define	PXENV_STATUS_TFTP_CLOSED			0x1a
30
+#define	PXENV_STATUS_TFTP_OPEN				0x1b
31
+
32
+/* BIOS/system errors (0x20 to 0x2f) */
33
+#define	PXENV_STATUS_MCOPY_PROBLEM			0x20
34
+#define	PXENV_STATUS_BIS_INTEGRITY_FAILURE		0x21
35
+#define	PXENV_STATUS_BIS_VALIDATE_FAILURE		0x22
36
+#define	PXENV_STATUS_BIS_INIT_FAILURE			0x23
37
+#define	PXENV_STATUS_BIS_SHUTDOWN_FAILURE		0x24
38
+#define	PXENV_STATUS_BIS_GBOA_FAILURE			0x25
39
+#define	PXENV_STATUS_BIS_FREE_FAILURE			0x26
40
+#define	PXENV_STATUS_BIS_GSI_FAILURE			0x27
41
+#define	PXENV_STATUS_BIS_BAD_CKSUM			0x28
42
+
43
+/* TFTP/MTFTP errors (0x30 to 0x3f) */
44
+#define	PXENV_STATUS_TFTP_CANNOT_ARP_ADDRESS		0x30
45
+#define	PXENV_STATUS_TFTP_OPEN_TIMEOUT			0x32
46
+#define	PXENV_STATUS_TFTP_UNKNOWN_OPCODE		0x33
47
+#define	PXENV_STATUS_TFTP_READ_TIMEOUT			0x35
48
+#define	PXENV_STATUS_TFTP_ERROR_OPCODE			0x36
49
+#define	PXENV_STATUS_TFTP_CANNOT_OPEN_CONNECTION	0x38
50
+#define	PXENV_STATUS_TFTP_CANNOT_READ_FROM_CONNECTION	0x39
51
+#define	PXENV_STATUS_TFTP_TOO_MANY_PACKAGES		0x3a
52
+#define	PXENV_STATUS_TFTP_FILE_NOT_FOUND		0x3b
53
+#define	PXENV_STATUS_TFTP_ACCESS_VIOLATION		0x3c
54
+#define	PXENV_STATUS_TFTP_NO_MCAST_ADDRESS		0x3d
55
+#define	PXENV_STATUS_TFTP_NO_FILESIZE			0x3e
56
+#define	PXENV_STATUS_TFTP_INVALID_PACKET_SIZE		0x3f
57
+
58
+/* Reserved errors 0x40 to 0x4f) */
59
+
60
+/* DHCP/BOOTP errors (0x50 to 0x5f) */
61
+#define	PXENV_STATUS_DHCP_TIMEOUT			0x51
62
+#define	PXENV_STATUS_DHCP_NO_IP_ADDRESS			0x52
63
+#define	PXENV_STATUS_DHCP_NO_BOOTFILE_NAME		0x53
64
+#define	PXENV_STATUS_DHCP_BAD_IP_ADDRESS		0x54
65
+
66
+/* Driver errors (0x60 to 0x6f) */
67
+#define	PXENV_STATUS_UNDI_INVALID_FUNCTION		0x60
68
+#define	PXENV_STATUS_UNDI_MEDIATEST_FAILED		0x61
69
+#define	PXENV_STATUS_UNDI_CANNOT_INIT_NIC_FOR_MCAST	0x62
70
+#define	PXENV_STATUS_UNDI_CANNOT_INITIALIZE_NIC		0x63
71
+#define	PXENV_STATUS_UNDI_CANNOT_INITIALIZE_PHY		0x64
72
+#define	PXENV_STATUS_UNDI_CANNOT_READ_CONFIG_DATA	0x65
73
+#define	PXENV_STATUS_UNDI_CANNOT_READ_INIT_DATA		0x66
74
+#define	PXENV_STATUS_UNDI_BAD_MAC_ADDRESS		0x67
75
+#define	PXENV_STATUS_UNDI_BAD_EEPROM_CHECKSUM		0x68
76
+#define	PXENV_STATUS_UNDI_ERROR_SETTING_ISR		0x69
77
+#define	PXENV_STATUS_UNDI_INVALID_STATE			0x6a
78
+#define	PXENV_STATUS_UNDI_TRANSMIT_ERROR		0x6b
79
+#define	PXENV_STATUS_UNDI_INVALID_PARAMETER		0x6c
80
+
81
+/* ROM and NBP bootstrap errors (0x70 to 0x7f) */
82
+#define	PXENV_STATUS_BSTRAP_PROMPT_MENU			0x74
83
+#define	PXENV_STATUS_BSTRAP_MCAST_ADDR			0x76
84
+#define	PXENV_STATUS_BSTRAP_MISSING_LIST		0x77
85
+#define	PXENV_STATUS_BSTRAP_NO_RESPONSE			0x78
86
+#define	PXENV_STATUS_BSTRAP_FILE_TOO_BIG		0x79
87
+
88
+/* Environment NBP errors (0x80 to 0x8f) */
89
+
90
+/* Reserved errors (0x90 to 0x9f) */
91
+
92
+/* Miscellaneous errors (0xa0 to 0xaf) */
93
+#define	PXENV_STATUS_BINL_CANCELED_BY_KEYSTROKE		0xa0
94
+#define	PXENV_STATUS_BINL_NO_PXE_SERVER			0xa1
95
+#define	PXENV_STATUS_NOT_AVAILABLE_IN_PMODE		0xa2
96
+#define	PXENV_STATUS_NOT_AVAILABLE_IN_RMODE		0xa3
97
+
98
+/* BUSD errors (0xb0 to 0xbf) */
99
+#define	PXENV_STATUS_BUSD_DEVICE_NOT_SUPPORTED		0xb0
100
+
101
+/* Loader errors (0xc0 to 0xcf) */
102
+#define	PXENV_STATUS_LOADER_NO_FREE_BASE_MEMORY		0xc0
103
+#define	PXENV_STATUS_LOADER_NO_BC_ROMID			0xc1
104
+#define	PXENV_STATUS_LOADER_BAD_BC_ROMID		0xc2
105
+#define	PXENV_STATUS_LOADER_BAD_BC_RUNTIME_IMAGE	0xc3
106
+#define	PXENV_STATUS_LOADER_NO_UNDI_ROMID		0xc4
107
+#define	PXENV_STATUS_LOADER_BAD_UNDI_ROMID		0xc5
108
+#define	PXENV_STATUS_LOADER_BAD_UNDI_DRIVER_IMAGE	0xc6
109
+#define	PXENV_STATUS_LOADER_NO_PXE_STRUCT		0xc8
110
+#define	PXENV_STATUS_LOADER_NO_PXENV_STRUCT		0xc9
111
+#define	PXENV_STATUS_LOADER_UNDI_START			0xca
112
+#define	PXENV_STATUS_LOADER_BC_START			0xcb
113
+
114
+/*
115
+ * The range 0xd0 to 0xff is defined as "Vendor errors" by the PXE
116
+ * spec.  We place all our Etherboot-specific errors in this range.
117
+ * We also define some generic errors as aliases to the PXE errors.
118
+ *
119
+ */
120
+
121
+#define ENOMEM	PXENV_STATUS_OUT_OF_RESOURCES
122
+
123
+/* Data structures and declarations */
124
+
125
+#include "tables.h"
126
+
127
+extern int errno;
128
+
129
+extern const char * strerror ( int errno );
130
+
131
+struct errortab {
132
+	int errno;
133
+	const char *text;
134
+};
135
+
136
+#define __errortab __table(errortab,01)
137
+
138
+#endif /* ERRNO_H */

Laden…
Abbrechen
Speichern