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 * ----------------------------------------------------------------------- */
24 __export
uint32_t SysAppends
; /* Configuration variable */
25 __export
const char *sysappend_strings
[SYSAPPEND_MAX
];
28 * Copy a string, converting whitespace characters to underscores
29 * and compacting them. Return a pointer to the final null.
31 static char *copy_and_mangle(char *dst
, const char *src
)
33 bool was_space
= true; /* Kill leading whitespace */
37 while ((c
= *src
++)) {
38 if (c
<= ' ' || c
== '\x7f') {
53 * Handle sysappend strings.
55 * Writes the output to 'buf' with a space after each option.
57 __export
void do_sysappend(char *buf
)
61 uint32_t mask
= SysAppends
;
63 for (i
= 0; i
< SYSAPPEND_MAX
; i
++) {
64 if ((mask
& 1) && sysappend_strings
[i
]) {
65 q
= copy_and_mangle(q
, sysappend_strings
[i
]);
74 * Generate the SYSUUID= sysappend string
76 static bool is_valid_uuid(const uint8_t *uuid
)
78 /* Assume the uuid is valid if it has a type that is not 0 or 15 */
79 return (uuid
[6] >= 0x10 && uuid
[6] < 0xf0);
82 void sysappend_set_uuid(const uint8_t *src
)
84 static char sysuuid_str
[8+32+5] = "SYSUUID=";
85 static const uint8_t uuid_dashes
[] = {4, 2, 2, 2, 6, 0};
86 const uint8_t *uuid_ptr
= uuid_dashes
;
89 if (!src
|| !is_valid_uuid(src
))
98 dst
+= sprintf(dst
, "%02x", *src
++);
104 /* Remove last dash and zero-terminate */
107 sysappend_strings
[SYSAPPEND_SYSUUID
] = sysuuid_str
;
110 void sysappend_set_fs_uuid(void)
112 static char fsuuid_str
[7+32+7+1] = "FSUUID=";
119 snprintf(fsuuid_str
+ 7, sizeof(fsuuid_str
) - 7, "%s", uuid
);
120 fsuuid_str
[sizeof(fsuuid_str
) - 1] = '\0';
123 sysappend_strings
[SYSAPPEND_FSUUID
] = fsuuid_str
;
127 * Print the sysappend strings, in order
129 void print_sysappend(void)
133 for (i
= 0; i
< SYSAPPEND_MAX
; i
++) {
134 if (sysappend_strings
[i
])
135 printf("%s\n", sysappend_strings
[i
]);