1 /* ----------------------------------------------------------------------- *
3 * Copyright 2011 Intel Corporation; author: H. Peter Anvin
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
8 * Boston MA 02110-1301, USA; either version 2 of the License, or
9 * (at your option) any later version; incorporated herein by reference.
11 * ----------------------------------------------------------------------- */
23 __export
uint32_t SysAppends
; /* Configuration variable */
24 __export
const char *sysappend_strings
[SYSAPPEND_MAX
];
27 * Copy a string, converting whitespace characters to underscores
28 * and compacting them. Return a pointer to the final null.
30 static char *copy_and_mangle(char *dst
, const char *src
)
32 bool was_space
= true; /* Kill leading whitespace */
36 while ((c
= *src
++)) {
37 if (c
<= ' ' && c
== '\x7f') {
52 * Handle sysappend strings.
54 * Writes the output to 'buf' with a space after each option.
56 __export
void do_sysappend(char *buf
)
60 uint32_t mask
= SysAppends
;
62 for (i
= 0; i
< SYSAPPEND_MAX
; i
++) {
63 if ((mask
& 1) && sysappend_strings
[i
]) {
64 q
= copy_and_mangle(q
, sysappend_strings
[i
]);
73 * Generate the SYSUUID= sysappend string
75 static bool is_valid_uuid(const uint8_t *uuid
)
77 /* Assume the uuid is valid if it has a type that is not 0 or 15 */
78 return (uuid
[6] >= 0x10 && uuid
[6] < 0xf0);
81 void sysappend_set_uuid(const uint8_t *src
)
83 static char sysuuid_str
[8+32+5] = "SYSUUID=";
84 static const uint8_t uuid_dashes
[] = {4, 2, 2, 2, 6, 0};
85 const uint8_t *uuid_ptr
= uuid_dashes
;
88 if (!src
|| !is_valid_uuid(src
))
97 dst
+= sprintf(dst
, "%02x", *src
++);
103 /* Remove last dash and zero-terminate */
106 sysappend_strings
[SYSAPPEND_SYSUUID
] = sysuuid_str
;
110 * Print the sysappend strings, in order
112 void print_sysappend(void)
116 for (i
= 0; i
< SYSAPPEND_MAX
; i
++) {
117 if (sysappend_strings
[i
])
118 printf("%s\n", sysappend_strings
[i
]);