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;
879 (void) fprintf(stdout, SOLPAR_INACTIVE, device->partition + 1);
886 get_disk_fd(ig_device_t *device)
892 assert(device != NULL);
893 assert(device->path != NULL);
895 if (is_bootpar(device->type)) {
896 end = strstr(device->path, "p0:boot");
903 i = strlen(device->path);
904 save[0] = device->path[i - 2];
905 save[1] = device->path[i - 1];
906 device->path[i - 2] = 'p';
907 device->path[i - 1] = '0';
911 device->disk_fd = open(device->path, O_RDONLY);
913 device->disk_fd = open(device->path, O_RDWR);
915 device->path_p0 = strdup(device->path);
916 if (device->path_p0 == NULL) {
921 if (is_bootpar(device->type)) {
924 device->path[i - 2] = save[0];
925 device->path[i - 1] = save[1];
928 if (device->disk_fd == -1) {
979 ig_device_t *device = &install->device;
985 if (is_bootpar(device->type)) {
991 if (write_out(device->part_fd, stage2->file, SECTOR_SIZE,
994 write_out(device->part_fd, stage2->file + SECTOR_SIZE,
1013 if (is_efi(device->type) && stage2->buf_size > STAGE2_MAXSIZE) {
1018 offset = STAGE2_BLKOFF(device->type) * SECTOR_SIZE;
1020 if (write_out(device->part_fd, stage2->buf, stage2->buf_size,
1027 (void) fprintf(stdout, WRITE_STAGE2_DISK, device->partition,
1028 (stage2->buf_size / SECTOR_SIZE) + 1, STAGE2_BLKOFF(device->type),
1037 ig_device_t *device = &install->device;
1041 if (write_out(device->part_fd, install->stage1_buf,
1049 (void) fprintf(stdout, WRITE_PBOOT, device->partition,
1050 device->start_sector);
1053 if (write_out(device->disk_fd, install->stage1_buf,
1066 #define USAGE_STRING "%s [-m|-f|-n|-F|-u verstr] stage1 stage2 device\n" \
1068 "%s [-V|-e] -i device\n" \
1103 ig_device_t *device = &dest->device;
1117 if (!is_bootpar(device->type)) {
1146 if (!(is_bootpar(device->type)))
1174 ig_device_t *device = &install->device;
1179 if (is_bootpar(device->type)) {
1182 if (pread(device->part_fd, bpb_sect, SECTOR_SIZE, 0)
1192 bcopy(device->boot_sector + BOOTSZ, install->stage1_buf + BOOTSZ,
1207 * Grab stage1 from the specified device file descriptor.
1294 ig_device_t *device = &data->device;
1295 int dev_fd = device->part_fd;
1298 assert(device->part_fd != -1);
1302 /* Gather stage2 (if present) from the target device. */
1303 if (read_stage2_from_disk(dev_fd, &stage2_disk, device->type)
1305 BOOT_DEBUG("Unable to read stage2 from %s\n", device->path);
1306 BOOT_DEBUG("No multiboot wrapped stage2 on %s\n", device->path);
1321 (void) fprintf(stdout, "WARNING: target device %s has a "
1323 "versioned one\n", device->path);
1328 BOOT_DEBUG("Forcing update of %s bootblock\n", device->path);
1347 ig_device_t *device = &install->device;
1385 if (is_bootpar(device->type)) {
1392 if (read_stage2_blocklist(device->part_fd, blocklist) != 0) {
1399 stage2->first_sector = device->start_sector + blocklist[0];
1419 START_BLOCK(pos) = blocklist[i] + device->start_sector;
1428 stage2->first_sector = device->start_sector +
1429 STAGE2_BLKOFF(device->type);
1442 = (device->partition << 16) | (device->slice << 8) | 0xff;
1469 get_raw_partition_path(ig_device_t *device)
1474 if (is_bootpar(device->type)) {
1478 mboot = (struct mboot *)device->boot_sector;
1481 device->path_p0);
1485 raw = strdup(device->path_p0);
1496 raw = strdup(device->path);
1503 if (!is_efi(device->type) &&
1509 device->slice = atoi(&raw[len - 1]);
1511 if (!is_efi(device->type)) {
1520 get_raw_partition_fd(ig_device_t *device)
1525 raw = get_raw_partition_path(device);
1530 device->part_fd = open(raw, O_RDONLY);
1532 device->part_fd = open(raw, O_RDWR);
1534 if (device->part_fd < 0 || fstat(device->part_fd, &stat) != 0) {
1542 (void) close(device->part_fd);
1543 device->part_fd = -1;