Lines Matching refs:device

103 static int get_disk_fd(ig_device_t *device);
267 * Install a new stage1/stage2 pair on the specified device. handle_install()
269 * the target device).
299 BOOT_DEBUG("stage1 path: %s, stage2 path: %s, device: %s\n",
302 if (init_device(&install_data.device, device_path) != BC_SUCCESS) {
303 (void) fprintf(stderr, gettext("Unable to gather device "
322 if (is_bootpar(install_data.device.type) && do_version)
349 cleanup_device(&install_data.device);
358 * Retrieves from a device the extended information (einfo) associated to the
360 * Expects one parameter, the device path, in the form: /dev/rdsk/c?[t?]d?s0.
371 ig_device_t *device = &data.device;
387 BOOT_DEBUG("device path: %s\n", device_path);
389 if (init_device(device, device_path) != BC_SUCCESS) {
390 (void) fprintf(stderr, gettext("Unable to gather device "
395 if (is_bootpar(device->type)) {
401 ret = read_stage2_from_disk(device->part_fd, stage2, device->type);
435 cleanup_device(&data.device);
455 ig_device_t *curr_device = &curr_data.device;
456 ig_device_t *attach_device = &attach_data.device;
474 BOOT_DEBUG("Current device path is: %s, attaching device path is: "
481 (void) fprintf(stderr, gettext("Unable to gather device "
482 "information for %s (current device)\n"), curr_device_path);
487 (void) fprintf(stderr, gettext("Unable to gather device "
488 "information for %s (attaching device)\n"),
579 ig_device_t *src_device = &source->device;
580 ig_device_t *dest_device = &target->device;
631 * open the device and fill the various members of ig_device_t.
634 init_device(ig_device_t *device, char *path)
640 bzero(device, sizeof (*device));
641 device->part_fd = -1;
642 device->disk_fd = -1;
643 device->path_p0 = NULL;
645 device->path = strdup(path);
646 if (device->path == NULL) {
651 if (strstr(device->path, "diskette")) {
657 /* Detect if the target device is a pcfs partition. */
658 if (strstr(device->path, "p0:boot"))
659 device->type = IG_DEV_X86BOOTPAR;
661 if (get_disk_fd(device) != BC_SUCCESS)
664 /* read in the device boot sector. */
665 if (read(device->disk_fd, device->boot_sector, SECTOR_SIZE)
672 if (efi_alloc_and_read(device->disk_fd, &vtoc) >= 0) {
673 device->type = IG_DEV_EFI;
677 if (get_raw_partition_fd(device) != BC_SUCCESS)
680 if (is_efi(device->type)) {
681 if (fstyp_init(device->part_fd, 0, NULL, &fhdl) != 0)
693 if (get_start_sector(device) != BC_SUCCESS)
700 cleanup_device(ig_device_t *device)
702 if (device->path)
703 free(device->path);
704 if (device->path_p0)
705 free(device->path_p0);
707 if (device->part_fd != -1)
708 (void) close(device->part_fd);
709 if (device->disk_fd != -1)
710 (void) close(device->disk_fd);
712 bzero(device, sizeof (ig_device_t));
713 device->part_fd = -1;
714 device->disk_fd = -1;
726 get_start_sector(ig_device_t *device)
736 if (is_efi(device->type)) {
739 if (efi_alloc_and_read(device->disk_fd, &vtoc) < 0)
742 device->start_sector = vtoc->efi_parts[device->slice].p_start;
744 device->slice = 0xff;
745 device->partition = 0;
751 mboot = (struct mboot *)device->boot_sector;
753 if (is_bootpar(device->type)) {
758 device->start_sector = secnum;
759 device->partition = pno;
766 * Get the solaris partition information from the device
770 if (ioctl(device->part_fd, DKIOCEXTPARTINFO, &edkpi) < 0) {
771 if (ioctl(device->part_fd, DKIOCPARTINFO, &dkpi) < 0) {
805 device->start_sector = part->relsect;
806 device->partition = i;
814 if ((rval = libfdisk_init(&epp, device->path_p0, NULL, FDISK_READ_DISK))
849 device->start_sector = secnum;
850 device->partition = pno - 1;
881 device->partition + 1);
889 get_disk_fd(ig_device_t *device)
895 assert(device != NULL);
896 assert(device->path != NULL);
898 if (is_bootpar(device->type)) {
899 end = strstr(device->path, "p0:boot");
906 i = strlen(device->path);
907 save[0] = device->path[i - 2];
908 save[1] = device->path[i - 1];
909 device->path[i - 2] = 'p';
910 device->path[i - 1] = '0';
914 device->disk_fd = open(device->path, O_RDONLY);
916 device->disk_fd = open(device->path, O_RDWR);
918 device->path_p0 = strdup(device->path);
919 if (device->path_p0 == NULL) {
924 if (is_bootpar(device->type)) {
927 device->path[i - 2] = save[0];
928 device->path[i - 1] = save[1];
931 if (device->disk_fd == -1) {
982 ig_device_t *device = &install->device;
988 if (is_bootpar(device->type)) {
994 if (write_out(device->part_fd, stage2->file, SECTOR_SIZE,
997 write_out(device->part_fd, stage2->file + SECTOR_SIZE,
1016 if (is_efi(device->type) && stage2->buf_size > STAGE2_MAXSIZE) {
1021 offset = STAGE2_BLKOFF(device->type) * SECTOR_SIZE;
1023 if (write_out(device->part_fd, stage2->buf, stage2->buf_size,
1030 (void) fprintf(stdout, WRITE_STAGE2_DISK, device->partition,
1031 (stage2->buf_size / SECTOR_SIZE) + 1, STAGE2_BLKOFF(device->type),
1040 ig_device_t *device = &install->device;
1044 if (write_out(device->part_fd, install->stage1_buf,
1052 (void) fprintf(stdout, WRITE_PBOOT, device->partition,
1053 device->start_sector);
1056 if (write_out(device->disk_fd, install->stage1_buf,
1069 #define USAGE_STRING "%s [-m|-f|-n|-F|-u verstr] stage1 stage2 device\n" \
1071 "%s [-V|-e] -i device\n" \
1106 ig_device_t *device = &dest->device;
1120 if (!is_bootpar(device->type)) {
1149 if (!(is_bootpar(device->type)))
1177 ig_device_t *device = &install->device;
1182 if (is_bootpar(device->type)) {
1185 if (pread(device->part_fd, bpb_sect, SECTOR_SIZE, 0)
1195 bcopy(device->boot_sector + BOOTSZ, install->stage1_buf + BOOTSZ,
1210 * Grab stage1 from the specified device file descriptor.
1297 ig_device_t *device = &data->device;
1298 int dev_fd = device->part_fd;
1301 assert(device->part_fd != -1);
1305 /* Gather stage2 (if present) from the target device. */
1306 if (read_stage2_from_disk(dev_fd, &stage2_disk, device->type)
1308 BOOT_DEBUG("Unable to read stage2 from %s\n", device->path);
1309 BOOT_DEBUG("No multiboot wrapped stage2 on %s\n", device->path);
1324 (void) fprintf(stdout, "WARNING: target device %s has a "
1326 "versioned one\n", device->path);
1331 BOOT_DEBUG("Forcing update of %s bootblock\n", device->path);
1350 ig_device_t *device = &install->device;
1388 if (is_bootpar(device->type)) {
1395 if (read_stage2_blocklist(device->part_fd, blocklist) != 0) {
1402 stage2->first_sector = device->start_sector + blocklist[0];
1422 START_BLOCK(pos) = blocklist[i] + device->start_sector;
1431 if (device->start_sector >
1432 UINT32_MAX - STAGE2_BLKOFF(device->type)) {
1435 (uint64_t)UINT32_MAX - STAGE2_BLKOFF(device->type));
1438 stage2->first_sector = device->start_sector +
1439 STAGE2_BLKOFF(device->type);
1452 = (device->partition << 16) | (device->slice << 8) | 0xff;
1479 get_raw_partition_path(ig_device_t *device)
1484 if (is_bootpar(device->type)) {
1488 mboot = (struct mboot *)device->boot_sector;
1491 device->path_p0);
1495 raw = strdup(device->path_p0);
1506 raw = strdup(device->path);
1513 if (!is_efi(device->type) &&
1519 device->slice = atoi(&raw[len - 1]);
1521 if (!is_efi(device->type)) {
1530 get_raw_partition_fd(ig_device_t *device)
1535 raw = get_raw_partition_path(device);
1540 device->part_fd = open(raw, O_RDONLY);
1542 device->part_fd = open(raw, O_RDWR);
1544 if (device->part_fd < 0 || fstat(device->part_fd, &stat) != 0) {
1552 (void) close(device->part_fd);
1553 device->part_fd = -1;