Lines Matching +full:data +full:- +full:path
1 // SPDX-License-Identifier: GPL-2.0
48 while (cnode && xbc_node_is_key(cnode) && !cnode->next) { in xbc_show_compact_tree()
61 if (vnode && xbc_node_is_value(vnode) && vnode->next) in xbc_show_compact_tree()
80 if (cnode->next) { in xbc_show_compact_tree()
89 if (node->next) { in xbc_show_compact_tree()
93 while (!node->next) { in xbc_show_compact_tree()
97 if (!xbc_node_get_child(node)->next) in xbc_show_compact_tree()
100 depth--; in xbc_show_compact_tree()
140 return -ENOMEM; in load_xbc_fd()
144 return -errno; in load_xbc_fd()
150 /* Return the read size or -errno */
151 static int load_xbc_file(const char *path, char **buf) in load_xbc_file() argument
156 fd = open(path, O_RDONLY); in load_xbc_file()
158 return -errno; in load_xbc_file()
161 return -errno; in load_xbc_file()
186 return -errno; in load_xbc_from_initrd()
191 if (lseek(fd, -BOOTCONFIG_MAGIC_LEN, SEEK_END) < 0) in load_xbc_from_initrd()
192 return pr_errno("Failed to lseek for magic", -errno); in load_xbc_from_initrd()
195 return pr_errno("Failed to read", -errno); in load_xbc_from_initrd()
201 if (lseek(fd, -(8 + BOOTCONFIG_MAGIC_LEN), SEEK_END) < 0) in load_xbc_from_initrd()
202 return pr_errno("Failed to lseek for size", -errno); in load_xbc_from_initrd()
205 return pr_errno("Failed to read size", -errno); in load_xbc_from_initrd()
209 return pr_errno("Failed to read checksum", -errno); in load_xbc_from_initrd()
215 return -E2BIG; in load_xbc_from_initrd()
218 if (lseek(fd, stat.st_size - (size + 8 + BOOTCONFIG_MAGIC_LEN), in load_xbc_from_initrd()
220 return pr_errno("Failed to lseek", -errno); in load_xbc_from_initrd()
230 return -EINVAL; in load_xbc_from_initrd()
234 /* Wrong data */ in load_xbc_from_initrd()
243 static void show_xbc_error(const char *data, const char *msg, int pos) in show_xbc_error() argument
255 if (data[i] == '\n') { in show_xbc_error()
257 col = pos - i; in show_xbc_error()
271 return -ENOMEM; in init_xbc_with_error()
281 static int show_xbc(const char *path, bool list) in show_xbc() argument
287 ret = stat(path, &st); in show_xbc()
289 ret = -errno; in show_xbc()
290 pr_err("Failed to stat %s: %d\n", path, ret); in show_xbc()
294 fd = open(path, O_RDONLY); in show_xbc()
296 ret = -errno; in show_xbc()
297 pr_err("Failed to open initrd %s: %d\n", path, ret); in show_xbc()
309 ret = load_xbc_file(path, &buf); in show_xbc()
328 static int delete_xbc(const char *path) in delete_xbc() argument
334 fd = open(path, O_RDWR); in delete_xbc()
336 ret = -errno; in delete_xbc()
337 pr_err("Failed to open initrd %s: %d\n", path, ret); in delete_xbc()
349 - size - 8 - BOOTCONFIG_MAGIC_LEN); in delete_xbc()
351 ret = -errno; in delete_xbc()
360 static int apply_xbc(const char *path, const char *xbc_path) in apply_xbc() argument
362 char *buf, *data, *p; in apply_xbc() local
378 /* Backup the bootconfig data */ in apply_xbc()
379 data = calloc(size + BOOTCONFIG_ALIGN + in apply_xbc()
381 if (!data) in apply_xbc()
382 return -ENOMEM; in apply_xbc()
383 memcpy(data, buf, size); in apply_xbc()
385 /* Check the data format */ in apply_xbc()
388 show_xbc_error(data, msg, pos); in apply_xbc()
389 free(data); in apply_xbc()
394 printf("Apply %s to %s\n", xbc_path, path); in apply_xbc()
405 ret = delete_xbc(path); in apply_xbc()
408 free(data); in apply_xbc()
413 fd = open(path, O_RDWR | O_APPEND); in apply_xbc()
415 ret = -errno; in apply_xbc()
416 pr_err("Failed to open %s: %d\n", path, ret); in apply_xbc()
417 free(data); in apply_xbc()
420 /* TODO: Ensure the @path is initramfs/initrd image */ in apply_xbc()
422 ret = -errno; in apply_xbc()
423 pr_err("Failed to get the size of %s\n", path); in apply_xbc()
429 pad = ((total_size + BOOTCONFIG_ALIGN - 1) & (~BOOTCONFIG_ALIGN_MASK)) - total_size; in apply_xbc()
433 p = data + size; in apply_xbc()
443 total_size = p - data; in apply_xbc()
445 ret = write(fd, data, total_size); in apply_xbc()
448 ret = -errno; in apply_xbc()
457 free(data); in apply_xbc()
462 /* Map the partial write to -ENOSPC */ in apply_xbc()
464 ret = -ENOSPC; in apply_xbc()
466 ret = -errno; in apply_xbc()
468 pr_err("The initrd %s may be corrupted. Recommend to rebuild.\n", path); in apply_xbc()
479 " -a <config>: Apply boot config to initrd\n" in usage()
480 " -d : Delete boot config file from initrd\n" in usage()
481 " -l : list boot config in initrd or file\n\n" in usage()
483 return -1; in usage()
488 char *path = NULL; in main() local
493 while ((opt = getopt(argc, argv, "hda:l")) != -1) { in main()
511 pr_err("Error: You can give one of -a, -d or -l at once.\n"); in main()
520 path = argv[optind]; in main()
523 return apply_xbc(path, apply); in main()
525 return delete_xbc(path); in main()
527 return show_xbc(path, list); in main()