void file_source_read_file(Value* file_source, Value* name, Value* contents) { if (file_source_is_map(file_source)) { Value* entry = hashtable_get(file_source, name); if (entry == NULL) set_null(contents); else copy(list_get(entry, 1), contents); return; } else if (file_source_is_filesystem_backed(file_source)) { Value fullPath; Value* rootDir = list_get(file_source, 1); copy(rootDir, &fullPath); join_path(&fullPath, name); read_text_file(as_cstring(&fullPath), contents); return; } else if (file_source_is_tarball_backed(file_source)) { Value* tarball = list_get(file_source, 1); tar_read_file(tarball, as_cstring(name), contents); return; } internal_error("file_source_read_file: file_source type not recognized"); }
static int grub_load_from_tar(void) { // prepare block api priv.index = partition_get_index("aboot"); priv.ptn = partition_get_offset(priv.index) + 1024*1024; // 1MB offset to aboot priv.is_ramdisk = 0; tio.blksz = BLOCK_SIZE; tio.lba = partition_get_size(priv.index) / tio.blksz - 1; // search file if(tar_get_fileinfo(&tio, "./boot/grub/core.img", &fi)) { dprintf(CRITICAL, "%s: couldn't find core.img!\n", __func__); return -1; } // load file into RAM if(tar_read_file(&tio, &fi, (void*)GRUB_LOADING_ADDRESS_VIRT)) { dprintf(CRITICAL, "%s: couldn't read core.img!\n", __func__); return -1; } grub_bootdev = strdup("hd1"); grub_bootpath = strdup("/boot/grub"); grub_found_tar = 1; dprintf(INFO, "Loaded GRUB from TAR\n"); return 0; }