Lines Matching refs:device

122 static int read_bootblock_from_disk(ib_device_t *device, ib_bootblock_t *,
238 read_bootblock_from_disk(ib_device_t *device, ib_bootblock_t *bblock,
247 assert(device != NULL);
250 if (device->target.fstype == IG_FS_ZFS) {
251 dev_fd = device->target.fd;
253 *path = device->target.path;
255 dev_fd = device->stage.fd;
256 offset = device->stage.offset * SECTOR_SIZE;
257 *path = device->stage.path;
329 ib_device_t *device = &data->device;
337 ret = read_bootblock_from_disk(device, &bblock_disk, &path);
368 gettext("WARNING: target device %s has a "
370 "non versioned one\n"), device->path);
375 BOOT_DEBUG("Forcing update of %s bootblock\n", device->path);
418 ib_device_t *device;
421 device = &data->device;
424 bcopy(device->mbr + STAGE1_BPB_OFFSET,
429 bcopy(device->mbr + STAGE1_SIG, data->stage1 + STAGE1_SIG,
442 if (device->target.fstype == IG_FS_ZFS)
444 device->target.start + device->target.offset;
447 device->stage.start + device->stage.offset;
463 ib_device_t *device;
469 device = &data->device;
472 *ptr = device->target.start;
487 ib_device_t *device = &data->device;
505 if (device->target.fstype == IG_FS_ZFS) {
506 dev_fd = device->target.fd;
507 abs = device->target.start + device->target.offset;
509 path = device->target.path;
511 dev_fd = device->stage.fd;
512 abs = device->stage.start + device->stage.offset;
513 offset = device->stage.offset * SECTOR_SIZE;
514 path = device->stage.path;
516 (device->stage.size - device->stage.offset) * SECTOR_SIZE) {
539 ib_device_t *device = &data->device;
552 if (device->stage.start != 0 &&
553 strcmp(device->target.path, device->stage.path)) {
555 if (write_out(device->stage.fd, data->stage1,
565 device->devtype == IG_DEV_MBR? "partition":"slice",
566 device->stage.id, device->stage.start);
574 if (device->devtype != IG_DEV_VTOC &&
575 device->target.fstype != IG_FS_PCFS) {
576 if (write_out(device->target.fd, data->stage1,
586 device->devtype == IG_DEV_MBR? "partition":"slice",
587 device->target.id, device->target.start);
591 if (write_out(device->fd, data->stage1,
610 get_start_sector(ib_device_t *device)
620 if (device->devtype == IG_DEV_EFI) {
623 if (efi_alloc_and_read(device->fd, &vtoc) < 0)
626 if (device->stage.start == 0) {
628 assert(device->target.fstype == IG_FS_ZFS);
630 device->stage.start =
631 vtoc->efi_parts[device->stage.id].p_start;
632 device->stage.size =
633 vtoc->efi_parts[device->stage.id].p_size;
634 device->stage.offset = BBLK_ZFS_BLK_OFF;
635 device->target.offset = BBLK_ZFS_BLK_OFF;
638 device->target.start =
639 vtoc->efi_parts[device->target.id].p_start;
640 device->target.size =
641 vtoc->efi_parts[device->target.id].p_size;
644 if (device->target.fstype == IG_FS_PCFS) {
653 mboot = (struct mboot *)device->mbr;
655 /* For MBR we have device->stage filled already. */
656 if (device->devtype == IG_DEV_MBR) {
658 pno = device->target.id - 1;
664 device->target.id);
667 device->target.start = part->relsect;
668 device->target.size = part->numsect;
671 if (device->target.fstype == IG_FS_PCFS) {
675 if (device->target.fstype == IG_FS_ZFS)
676 device->target.offset = BBLK_ZFS_BLK_OFF;
683 * Get the solaris partition information from the device
687 if (ioctl(device->target.fd, DKIOCEXTPARTINFO, &edkpi) < 0) {
688 if (ioctl(device->target.fd, DKIOCPARTINFO, &dkpi) < 0) {
698 device->target.start = edkpi.p_start;
699 device->target.size = edkpi.p_length;
700 if (device->target.fstype == IG_FS_ZFS)
701 device->target.offset = BBLK_ZFS_BLK_OFF;
731 device->stage.start = part->relsect;
732 device->stage.size = part->numsect;
733 if (device->target.fstype == IG_FS_ZFS)
734 device->stage.offset = BBLK_ZFS_BLK_OFF;
736 device->stage.offset = BBLK_BLKLIST_OFF;
737 device->stage.id = i + 1;
746 if ((rval = libfdisk_init(&epp, device->path, NULL, FDISK_READ_DISK))
788 device->stage.start = secnum;
789 device->stage.size = numsec;
790 device->stage.id = pno;
811 if (device->devtype != IG_DEV_EFI) {
814 "partition is inactive.\n"), device->stage.id);
846 (void) fprintf(stderr, gettext("%s: Not a character device\n"),
856 get_boot_partition(ib_device_t *device, struct mboot *mbr)
870 device->stage.path = strdup(device->path);
871 if (device->stage.path == NULL) {
875 device->stage.fd = dup(device->fd);
876 device->stage.id = 0;
877 device->stage.devtype = IG_DEV_MBR;
878 device->stage.fstype = IG_FS_NONE;
879 device->stage.start = 0;
880 device->stage.size = part[0].relsect;
881 device->stage.offset = BBLK_BLKLIST_OFF;
885 if ((path = strdup(device->path)) == NULL) {
899 device->stage.path = ptr;
900 device->stage.fd = open_device(ptr);
901 device->stage.id = i + 1;
902 device->stage.devtype = IG_DEV_MBR;
903 device->stage.fstype = IG_FS_NONE;
904 device->stage.start = part[i].relsect;
905 device->stage.size = part[i].numsect;
906 device->stage.offset = 1; /* leave sector 0 for VBR */
911 get_boot_slice(ib_device_t *device, struct dk_gpt *vtoc)
918 if ((path = strdup(device->target.path)) == NULL) {
931 device->stage.path = ptr;
932 device->stage.fd = open_device(ptr);
933 device->stage.id = i;
934 device->stage.devtype = IG_DEV_EFI;
935 device->stage.fstype = IG_FS_NONE;
936 device->stage.start = vtoc->efi_parts[i].p_start;
937 device->stage.size = vtoc->efi_parts[i].p_size;
938 device->stage.offset = 1; /* leave sector 0 for VBR */
946 init_device(ib_device_t *device, char *path)
955 bzero(device, sizeof (*device));
956 device->fd = -1; /* whole disk fd */
957 device->stage.fd = -1; /* bootblock partition fd */
958 device->target.fd = -1; /* target fs partition fd */
966 "whole disk device is not supported\n"));
969 device->target.path = strdup(path);
970 if (device->target.path == NULL) {
974 device->path = strdup(path);
975 if (device->path == NULL) {
980 /* change device name to p0 */
981 device->path[pathlen - 2] = 'p';
982 device->path[pathlen - 1] = '0';
984 if (strstr(device->target.path, "diskette")) {
990 /* Detect if the target device is a pcfs partition. */
991 if (strstr(device->target.path, "p0:boot")) {
997 if ((device->fd = open_device(device->path)) == -1)
1000 /* read in the device boot sector. */
1001 if (read(device->fd, device->mbr, SECTOR_SIZE) != SECTOR_SIZE) {
1007 device->devtype = IG_DEV_VTOC;
1008 if (efi_alloc_and_read(device->fd, &vtoc) >= 0) {
1009 ret = get_boot_slice(device, vtoc);
1010 device->devtype = IG_DEV_EFI;
1014 } else if (device->target.path[pathlen - 2] == 'p') {
1015 device->devtype = IG_DEV_MBR;
1016 ret = get_boot_partition(device, (struct mboot *)device->mbr);
1019 } else if (device->target.path[pathlen - 1] == '2') {
1025 gettext("raw device must be a root slice (not s2)\n"));
1030 if (device->stage.path == NULL) {
1031 if ((device->stage.path = strdup(path)) == NULL) {
1035 if (device->devtype == IG_DEV_VTOC) {
1037 device->stage.path[pathlen - 2] = 's';
1038 device->stage.path[pathlen - 1] = '2';
1039 device->stage.id = 2;
1041 p = strrchr(device->stage.path, 'p');
1043 p = strrchr(device->stage.path, 's');
1044 device->stage.id = atoi(++p);
1046 device->stage.devtype = device->devtype;
1047 device->stage.fd = open_device(device->stage.path);
1050 p = strrchr(device->target.path, 'p');
1052 p = strrchr(device->target.path, 's');
1053 device->target.id = atoi(++p);
1055 if (strcmp(device->stage.path, device->target.path) == 0)
1056 device->target.fd = dup(device->stage.fd);
1058 device->target.fd = open_device(device->target.path);
1060 if (fstyp_init(device->target.fd, 0, NULL, &fhdl) != 0)
1071 if (device->devtype == IG_DEV_EFI && strcmp(fident, "zfs") &&
1072 device->stage.size == 0) {
1079 device->target.fstype = IG_FS_ZFS;
1081 device->target.fstype = IG_FS_UFS;
1083 device->target.fstype = IG_FS_PCFS;
1093 if (device->stage.size) {
1094 if (fstyp_init(device->stage.fd, 0, NULL, &fhdl) != 0)
1105 return (get_start_sector(device));
1109 cleanup_device(ib_device_t *device)
1111 if (device->path)
1112 free(device->path);
1113 if (device->stage.path)
1114 free(device->stage.path);
1115 if (device->target.path)
1116 free(device->target.path);
1118 if (device->fd != -1)
1119 (void) close(device->fd);
1120 if (device->stage.fd != -1)
1121 (void) close(device->stage.fd);
1122 if (device->target.fd != -1)
1123 (void) close(device->target.fd);
1124 bzero(device, sizeof (*device));
1150 if (read(src->device.fd, dest->stage1, SECTOR_SIZE) != SECTOR_SIZE) {
1152 src->device.path);
1177 src->device.path, dest->device.path);
1209 * Install a new bootblock on the given device. handle_install() expects argv
1210 * to contain 3 parameters (the target device path and the path to the
1239 BOOT_DEBUG("device path: %s, stage1 path: %s bootblock path: %s\n",
1243 if (init_device(&install_data.device, device_path) != BC_SUCCESS) {
1244 (void) fprintf(stderr, gettext("Unable to open device %s\n"),
1278 cleanup_device(&install_data.device);
1287 * Retrieves from a device the extended information (einfo) associated to the
1289 * Expects one parameter, the device path, in the form: /dev/rdsk/c?[t?]d?s0.
1301 ib_device_t *device = &data.device;
1316 BOOT_DEBUG("device path: %s\n", device_path);
1318 if (init_device(device, device_path) != BC_SUCCESS) {
1319 (void) fprintf(stderr, gettext("Unable to gather device "
1324 ret = read_bootblock_from_disk(device, bblock, &path);
1359 cleanup_device(&data.device);
1379 ib_device_t *curr_device = &curr_data.device;
1380 ib_device_t *attach_device = &attach_data.device;
1399 BOOT_DEBUG("Current device path is: %s, attaching device path is: "
1406 (void) fprintf(stderr, gettext("Unable to gather device "
1407 "information from %s (current device)\n"),
1413 (void) fprintf(stderr, gettext("Unable to gather device "
1414 "information from %s (attaching device)\n"),
1453 "raw-device\n" \
1454 "\t%s -M [-n] raw-device attach-raw-device\n" \
1455 "\t%s [-e|-V] -i raw-device\n"