Lines Matching defs:device
236 read_bootblock_from_disk(ib_device_t *device, ib_bootblock_t *bblock,
245 assert(device != NULL);
248 if (device->target.fstype == IG_FS_ZFS) {
249 dev_fd = device->target.fd;
251 *path = device->target.path;
253 dev_fd = device->stage.fd;
254 offset = device->stage.offset * SECTOR_SIZE;
255 *path = device->stage.path;
327 ib_device_t *device = &data->device;
335 ret = read_bootblock_from_disk(device, &bblock_disk, &path);
366 gettext("WARNING: target device %s has a "
368 "non versioned one\n"), device->path);
373 BOOT_DEBUG("Forcing update of %s bootblock\n", device->path);
416 ib_device_t *device;
419 device = &data->device;
422 bcopy(device->mbr + STAGE1_BPB_OFFSET,
427 bcopy(device->mbr + STAGE1_SIG, data->stage1 + STAGE1_SIG,
440 if (device->target.fstype == IG_FS_ZFS)
442 device->target.start + device->target.offset;
445 device->stage.start + device->stage.offset;
461 ib_device_t *device;
467 device = &data->device;
470 *ptr = device->target.start;
485 ib_device_t *device = &data->device;
503 if (device->target.fstype == IG_FS_ZFS) {
504 dev_fd = device->target.fd;
505 abs = device->target.start + device->target.offset;
507 path = device->target.path;
509 dev_fd = device->stage.fd;
510 abs = device->stage.start + device->stage.offset;
511 offset = device->stage.offset * SECTOR_SIZE;
512 path = device->stage.path;
514 (device->stage.size - device->stage.offset) * SECTOR_SIZE) {
559 ib_device_t *device = &data->device;
571 if (device->stage.start != 0 &&
572 strcmp(device->target.path, device->stage.path)) {
574 if (write_out(device->stage.fd, data->stage1,
584 device->devtype == IG_DEV_MBR? "partition":"slice",
585 device->stage.id, device->stage.start);
586 start = device->stage.start;
594 if (device->devtype != IG_DEV_VTOC &&
595 device->target.fstype != IG_FS_PCFS) {
596 if (write_out(device->target.fd, data->stage1,
606 device->devtype == IG_DEV_MBR? "partition":"slice",
607 device->target.id, device->target.start);
608 start = device->target.start;
621 if (write_out(device->fd, data->stage1,
640 get_start_sector(ib_device_t *device)
650 if (device->devtype == IG_DEV_EFI) {
653 if (efi_alloc_and_read(device->fd, &vtoc) < 0)
656 if (device->stage.start == 0) {
658 assert(device->target.fstype == IG_FS_ZFS);
660 device->stage.start =
661 vtoc->efi_parts[device->stage.id].p_start;
662 device->stage.size =
663 vtoc->efi_parts[device->stage.id].p_size;
664 device->stage.offset = BBLK_ZFS_BLK_OFF;
665 device->target.offset = BBLK_ZFS_BLK_OFF;
668 device->target.start =
669 vtoc->efi_parts[device->target.id].p_start;
670 device->target.size =
671 vtoc->efi_parts[device->target.id].p_size;
674 if (device->target.fstype == IG_FS_PCFS) {
683 mboot = (struct mboot *)device->mbr;
685 /* For MBR we have device->stage filled already. */
686 if (device->devtype == IG_DEV_MBR) {
688 pno = device->target.id - 1;
694 device->target.id);
697 device->target.start = part->relsect;
698 device->target.size = part->numsect;
701 if (device->target.fstype == IG_FS_PCFS) {
705 if (device->target.fstype == IG_FS_ZFS)
706 device->target.offset = BBLK_ZFS_BLK_OFF;
713 * Get the solaris partition information from the device
717 if (ioctl(device->target.fd, DKIOCEXTPARTINFO, &edkpi) < 0) {
718 if (ioctl(device->target.fd, DKIOCPARTINFO, &dkpi) < 0) {
728 device->target.start = edkpi.p_start;
729 device->target.size = edkpi.p_length;
730 if (device->target.fstype == IG_FS_ZFS)
731 device->target.offset = BBLK_ZFS_BLK_OFF;
761 device->stage.start = part->relsect;
762 device->stage.size = part->numsect;
763 if (device->target.fstype == IG_FS_ZFS)
764 device->stage.offset = BBLK_ZFS_BLK_OFF;
766 device->stage.offset = BBLK_BLKLIST_OFF;
767 device->stage.id = i + 1;
776 if ((rval = libfdisk_init(&epp, device->path, NULL, FDISK_READ_DISK))
818 device->stage.start = secnum;
819 device->stage.size = numsec;
820 device->stage.id = pno;
841 if (device->devtype != IG_DEV_EFI) {
844 "partition is inactive.\n"), device->stage.id);
876 (void) fprintf(stderr, gettext("%s: Not a character device\n"),
886 get_boot_partition(ib_device_t *device, struct mboot *mbr)
900 device->stage.path = strdup(device->path);
901 if (device->stage.path == NULL) {
905 device->stage.fd = dup(device->fd);
906 device->stage.id = 0;
907 device->stage.devtype = IG_DEV_MBR;
908 device->stage.fstype = IG_FS_NONE;
909 device->stage.start = 0;
910 device->stage.size = part[0].relsect;
911 device->stage.offset = BBLK_BLKLIST_OFF;
915 if ((path = strdup(device->path)) == NULL) {
929 device->stage.path = ptr;
930 device->stage.fd = open_device(ptr);
931 device->stage.id = i + 1;
932 device->stage.devtype = IG_DEV_MBR;
933 device->stage.fstype = IG_FS_NONE;
934 device->stage.start = part[i].relsect;
935 device->stage.size = part[i].numsect;
936 device->stage.offset = 1; /* leave sector 0 for VBR */
941 get_boot_slice(ib_device_t *device, struct dk_gpt *vtoc)
948 if ((path = strdup(device->target.path)) == NULL) {
961 device->stage.path = ptr;
962 device->stage.fd = open_device(ptr);
963 device->stage.id = i;
964 device->stage.devtype = IG_DEV_EFI;
965 device->stage.fstype = IG_FS_NONE;
966 device->stage.start = vtoc->efi_parts[i].p_start;
967 device->stage.size = vtoc->efi_parts[i].p_size;
968 device->stage.offset = 1; /* leave sector 0 for VBR */
976 init_device(ib_device_t *device, char *path)
985 bzero(device, sizeof (*device));
986 device->fd = -1; /* whole disk fd */
987 device->stage.fd = -1; /* bootblock partition fd */
988 device->target.fd = -1; /* target fs partition fd */
996 "whole disk device is not supported\n"));
999 device->target.path = strdup(path);
1000 if (device->target.path == NULL) {
1004 device->path = strdup(path);
1005 if (device->path == NULL) {
1010 /* change device name to p0 */
1011 device->path[pathlen - 2] = 'p';
1012 device->path[pathlen - 1] = '0';
1014 if (strstr(device->target.path, "diskette")) {
1020 /* Detect if the target device is a pcfs partition. */
1021 if (strstr(device->target.path, "p0:boot")) {
1027 if ((device->fd = open_device(device->path)) == -1)
1030 /* read in the device boot sector. */
1031 if (read(device->fd, device->mbr, SECTOR_SIZE) != SECTOR_SIZE) {
1037 device->devtype = IG_DEV_VTOC;
1038 if (efi_alloc_and_read(device->fd, &vtoc) >= 0) {
1039 ret = get_boot_slice(device, vtoc);
1040 device->devtype = IG_DEV_EFI;
1044 } else if (device->target.path[pathlen - 2] == 'p') {
1045 device->devtype = IG_DEV_MBR;
1046 ret = get_boot_partition(device, (struct mboot *)device->mbr);
1049 } else if (device->target.path[pathlen - 1] == '2') {
1055 gettext("raw device must be a root slice (not s2)\n"));
1060 if (device->stage.path == NULL) {
1061 if ((device->stage.path = strdup(path)) == NULL) {
1065 if (device->devtype == IG_DEV_VTOC) {
1067 device->stage.path[pathlen - 2] = 's';
1068 device->stage.path[pathlen - 1] = '2';
1069 device->stage.id = 2;
1071 p = strrchr(device->stage.path, 'p');
1073 p = strrchr(device->stage.path, 's');
1074 device->stage.id = atoi(++p);
1076 device->stage.devtype = device->devtype;
1077 device->stage.fd = open_device(device->stage.path);
1080 p = strrchr(device->target.path, 'p');
1082 p = strrchr(device->target.path, 's');
1083 device->target.id = atoi(++p);
1085 if (strcmp(device->stage.path, device->target.path) == 0)
1086 device->target.fd = dup(device->stage.fd);
1088 device->target.fd = open_device(device->target.path);
1090 if (fstyp_init(device->target.fd, 0, NULL, &fhdl) != 0)
1101 if (device->devtype == IG_DEV_EFI && strcmp(fident, "zfs") &&
1102 device->stage.size == 0) {
1109 device->target.fstype = IG_FS_ZFS;
1111 device->target.fstype = IG_FS_UFS;
1113 device->target.fstype = IG_FS_PCFS;
1123 if (device->stage.size) {
1124 if (fstyp_init(device->stage.fd, 0, NULL, &fhdl) != 0)
1135 return (get_start_sector(device));
1139 cleanup_device(ib_device_t *device)
1141 if (device->path)
1142 free(device->path);
1143 if (device->stage.path)
1144 free(device->stage.path);
1145 if (device->target.path)
1146 free(device->target.path);
1148 if (device->fd != -1)
1149 (void) close(device->fd);
1150 if (device->stage.fd != -1)
1151 (void) close(device->stage.fd);
1152 if (device->target.fd != -1)
1153 (void) close(device->target.fd);
1154 bzero(device, sizeof (*device));
1180 if (read(src->device.fd, dest->stage1, SECTOR_SIZE) != SECTOR_SIZE) {
1182 src->device.path);
1207 src->device.path, dest->device.path);
1239 * Install a new bootblock on the given device. handle_install() expects argv
1240 * to contain 3 parameters (the target device path and the path to the
1270 BOOT_DEBUG("device path: %s, stage1 path: %s bootblock path: %s\n",
1274 if (init_device(&install_data.device, device_path) != BC_SUCCESS) {
1275 (void) fprintf(stderr, gettext("Unable to open device %s\n"),
1309 cleanup_device(&install_data.device);
1318 * Retrieves from a device the extended information (einfo) associated to the
1320 * Expects one parameter, the device path, in the form: /dev/rdsk/c?[t?]d?s0
1332 ib_device_t device;
1352 bzero(&device, sizeof (device));
1353 BOOT_DEBUG("device path: %s\n", device_path);
1359 if (init_device(&device, device_path) != BC_SUCCESS) {
1361 "device information from %s\n"), device_path);
1364 ret = read_bootblock_from_disk(&device, &bblock, &path);
1402 cleanup_device(&device);
1422 ib_device_t *curr_device = &curr_data.device;
1423 ib_device_t *attach_device = &attach_data.device;
1442 BOOT_DEBUG("Current device path is: %s, attaching device path is: "
1449 (void) fprintf(stderr, gettext("Unable to gather device "
1450 "information from %s (current device)\n"),
1456 (void) fprintf(stderr, gettext("Unable to gather device "
1457 "information from %s (attaching device)\n"),
1496 "raw-device\n" \
1497 "\t%s -M [-n] raw-device attach-raw-device\n" \
1498 "\t%s [-e|-V] -i raw-device | file\n"