static void write_rootdev (grub_device_t root_dev, char *boot_img, grub_uint64_t first_sector) { #ifdef GRUB_SETUP_BIOS { grub_uint8_t *boot_drive; void *kernel_sector; boot_drive = (grub_uint8_t *) (boot_img + GRUB_BOOT_MACHINE_BOOT_DRIVE); kernel_sector = (boot_img + GRUB_BOOT_MACHINE_KERNEL_SECTOR); /* FIXME: can this be skipped? */ *boot_drive = 0xFF; grub_set_unaligned64 (kernel_sector, grub_cpu_to_le64 (first_sector)); } #endif #ifdef GRUB_SETUP_SPARC64 { void *kernel_byte; kernel_byte = (boot_img + GRUB_BOOT_AOUT_HEADER_SIZE + GRUB_BOOT_MACHINE_KERNEL_BYTE); grub_set_unaligned64 (kernel_byte, grub_cpu_to_be64 (first_sector << GRUB_DISK_SECTOR_BITS)); } #endif }
static grub_err_t hfsplus_open_compressed_real (struct grub_hfsplus_file *node) { grub_err_t err; struct grub_hfsplus_btnode *attr_node; grub_off_t attr_off; struct grub_hfsplus_key_internal key; struct grub_hfsplus_attr_header *attr_head; struct grub_hfsplus_compress_attr *cmp_head; #define c grub_cpu_to_be16_compile_time const grub_uint16_t compress_attr_name[] = { c('c'), c('o'), c('m'), c('.'), c('a'), c('p'), c('p'), c('l'), c('e'), c('.'), c('d'), c('e'), c('c'), c('m'), c('p'), c('f'), c('s') }; #undef c if (node->size) return 0; key.attrkey.cnid = node->fileid; key.attrkey.namelen = sizeof (compress_attr_name) / sizeof (compress_attr_name[0]); key.attrkey.name = compress_attr_name; err = grub_hfsplus_btree_search (&node->data->attr_tree, &key, grub_hfsplus_cmp_attrkey, &attr_node, &attr_off); if (err || !attr_node) { grub_errno = 0; return 0; } attr_head = (struct grub_hfsplus_attr_header *) ((char *) grub_hfsplus_btree_recptr (&node->data->attr_tree, attr_node, attr_off) + sizeof (struct grub_hfsplus_attrkey) + sizeof (compress_attr_name)); if (attr_head->type != 0x10 || !(attr_head->size & grub_cpu_to_be64_compile_time(~0xfULL))) { grub_free (attr_node); return 0; } cmp_head = (struct grub_hfsplus_compress_attr *) (attr_head + 1); if (cmp_head->magic != grub_cpu_to_be32_compile_time (0x66706d63)) { grub_free (attr_node); return 0; } node->size = grub_le_to_cpu32 (cmp_head->uncompressed_inline_size); if (cmp_head->type == grub_cpu_to_le32_compile_time (HFSPLUS_COMPRESSION_RESOURCE)) { grub_uint32_t index_size; node->compressed = 2; if (grub_hfsplus_read_file (node, 0, 0, 0x104, sizeof (index_size), (char *) &index_size) != 4) { node->compressed = 0; grub_free (attr_node); grub_errno = 0; return 0; } node->compress_index_size = grub_le_to_cpu32 (index_size); node->compress_index = grub_malloc (node->compress_index_size * sizeof (node->compress_index[0])); if (!node->compress_index) { node->compressed = 0; grub_free (attr_node); return grub_errno; } if (grub_hfsplus_read_file (node, 0, 0, 0x104 + sizeof (index_size), node->compress_index_size * sizeof (node->compress_index[0]), (char *) node->compress_index) != (grub_ssize_t) (node->compress_index_size * sizeof (node->compress_index[0]))) { node->compressed = 0; grub_free (attr_node); grub_free (node->compress_index); grub_errno = 0; return 0; } node->cbuf_block = -1; node->cbuf = grub_malloc (HFSPLUS_COMPRESS_BLOCK_SIZE); grub_free (attr_node); if (!node->cbuf) { node->compressed = 0; grub_free (node->compress_index); return grub_errno; } return 0; } if (cmp_head->type != HFSPLUS_COMPRESSION_INLINE) { grub_free (attr_node); return 0; } node->cbuf = grub_malloc (node->size); if (!node->cbuf) return grub_errno; if (grub_zlib_decompress ((char *) (cmp_head + 1), grub_cpu_to_be64 (attr_head->size) - sizeof (*cmp_head), 0, node->cbuf, node->size) < 0) return grub_errno; node->compressed = 1; return 0; }