Example #1
0
int read_extend(uint32_t extend_no, void *buf)
{
	size_t len = get_extend_size();
	int fd = get_disk_fd();
	off64_t offset = (uint32_t)extend_no * len;

	//log_dbg("%u", extend_no);

	if (read_from_disk(fd, buf, offset, len))
		return -1;

	return 0;
}
Example #2
0
/*
 * open the device and fill the various members of ig_device_t.
 */
static int
init_device(ig_device_t *device, char *path)
{
	struct dk_gpt *vtoc;
	fstyp_handle_t fhdl;
	const char *fident;

	bzero(device, sizeof (*device));
	device->part_fd = -1;
	device->disk_fd = -1;
	device->path_p0 = NULL;

	device->path = strdup(path);
	if (device->path == NULL) {
		perror(gettext("Memory allocation failed"));
		return (BC_ERROR);
	}

	if (strstr(device->path, "diskette")) {
		(void) fprintf(stderr, gettext("installing GRUB to a floppy "
		    "disk is no longer supported\n"));
		return (BC_ERROR);
	}

	/* Detect if the target device is a pcfs partition. */
	if (strstr(device->path, "p0:boot"))
		device->type = IG_DEV_X86BOOTPAR;

	if (get_disk_fd(device) != BC_SUCCESS)
		return (BC_ERROR);

	/* read in the device boot sector. */
	if (read(device->disk_fd, device->boot_sector, SECTOR_SIZE)
	    != SECTOR_SIZE) {
		(void) fprintf(stderr, gettext("Error reading boot sector\n"));
		perror("read");
		return (BC_ERROR);
	}

	if (efi_alloc_and_read(device->disk_fd, &vtoc) >= 0) {
		device->type = IG_DEV_EFI;
		efi_free(vtoc);
	}

	if (get_raw_partition_fd(device) != BC_SUCCESS)
		return (BC_ERROR);

	if (is_efi(device->type)) {
		if (fstyp_init(device->part_fd, 0, NULL, &fhdl) != 0)
			return (BC_ERROR);

		if (fstyp_ident(fhdl, "zfs", &fident) != 0) {
			fstyp_fini(fhdl);
			(void) fprintf(stderr, gettext("Booting of EFI labeled "
			    "disks is only supported with ZFS\n"));
			return (BC_ERROR);
		}
		fstyp_fini(fhdl);
	}

	if (get_start_sector(device) != BC_SUCCESS)
		return (BC_ERROR);

	return (BC_SUCCESS);
}