Lines Matching refs:device

103 static int get_disk_fd(ig_device_t *device);
302 if (init_device(&install_data.device, device_path) != BC_SUCCESS) { in handle_install()
322 if (is_bootpar(install_data.device.type) && do_version) in handle_install()
349 cleanup_device(&install_data.device); in handle_install()
371 ig_device_t *device = &data.device; in handle_getinfo() local
389 if (init_device(device, device_path) != BC_SUCCESS) { in handle_getinfo()
395 if (is_bootpar(device->type)) { in handle_getinfo()
401 ret = read_stage2_from_disk(device->part_fd, stage2, device->type); in handle_getinfo()
435 cleanup_device(&data.device); in handle_getinfo()
455 ig_device_t *curr_device = &curr_data.device; in handle_mirror()
456 ig_device_t *attach_device = &attach_data.device; in handle_mirror()
579 ig_device_t *src_device = &source->device; in propagate_bootblock()
580 ig_device_t *dest_device = &target->device; in propagate_bootblock()
634 init_device(ig_device_t *device, char *path) in init_device() argument
640 bzero(device, sizeof (*device)); in init_device()
641 device->part_fd = -1; in init_device()
642 device->disk_fd = -1; in init_device()
643 device->path_p0 = NULL; in init_device()
645 device->path = strdup(path); in init_device()
646 if (device->path == NULL) { in init_device()
651 if (strstr(device->path, "diskette")) { in init_device()
658 if (strstr(device->path, "p0:boot")) in init_device()
659 device->type = IG_DEV_X86BOOTPAR; in init_device()
661 if (get_disk_fd(device) != BC_SUCCESS) in init_device()
665 if (read(device->disk_fd, device->boot_sector, SECTOR_SIZE) in init_device()
672 if (efi_alloc_and_read(device->disk_fd, &vtoc) >= 0) { in init_device()
673 device->type = IG_DEV_EFI; in init_device()
677 if (get_raw_partition_fd(device) != BC_SUCCESS) in init_device()
680 if (is_efi(device->type)) { in init_device()
681 if (fstyp_init(device->part_fd, 0, NULL, &fhdl) != 0) in init_device()
693 if (get_start_sector(device) != BC_SUCCESS) in init_device()
700 cleanup_device(ig_device_t *device) in cleanup_device() argument
702 if (device->path) in cleanup_device()
703 free(device->path); in cleanup_device()
704 if (device->path_p0) in cleanup_device()
705 free(device->path_p0); in cleanup_device()
707 if (device->part_fd != -1) in cleanup_device()
708 (void) close(device->part_fd); in cleanup_device()
709 if (device->disk_fd != -1) in cleanup_device()
710 (void) close(device->disk_fd); in cleanup_device()
712 bzero(device, sizeof (ig_device_t)); in cleanup_device()
713 device->part_fd = -1; in cleanup_device()
714 device->disk_fd = -1; in cleanup_device()
726 get_start_sector(ig_device_t *device) in get_start_sector() argument
736 if (is_efi(device->type)) { in get_start_sector()
739 if (efi_alloc_and_read(device->disk_fd, &vtoc) < 0) in get_start_sector()
742 device->start_sector = vtoc->efi_parts[device->slice].p_start; in get_start_sector()
744 device->partition = device->slice; in get_start_sector()
745 device->slice = 0xff; in get_start_sector()
751 mboot = (struct mboot *)device->boot_sector; in get_start_sector()
753 if (is_bootpar(device->type)) { in get_start_sector()
758 device->start_sector = secnum; in get_start_sector()
759 device->partition = pno; in get_start_sector()
770 if (ioctl(device->part_fd, DKIOCEXTPARTINFO, &edkpi) < 0) { in get_start_sector()
771 if (ioctl(device->part_fd, DKIOCPARTINFO, &dkpi) < 0) { in get_start_sector()
805 device->start_sector = part->relsect; in get_start_sector()
806 device->partition = i; in get_start_sector()
814 if ((rval = libfdisk_init(&epp, device->path_p0, NULL, FDISK_READ_DISK)) in get_start_sector()
849 device->start_sector = secnum; in get_start_sector()
850 device->partition = pno - 1; in get_start_sector()
881 device->partition + 1); in get_start_sector()
889 get_disk_fd(ig_device_t *device) in get_disk_fd() argument
895 assert(device != NULL); in get_disk_fd()
896 assert(device->path != NULL); in get_disk_fd()
898 if (is_bootpar(device->type)) { in get_disk_fd()
899 end = strstr(device->path, "p0:boot"); in get_disk_fd()
906 i = strlen(device->path); in get_disk_fd()
907 save[0] = device->path[i - 2]; in get_disk_fd()
908 save[1] = device->path[i - 1]; in get_disk_fd()
909 device->path[i - 2] = 'p'; in get_disk_fd()
910 device->path[i - 1] = '0'; in get_disk_fd()
914 device->disk_fd = open(device->path, O_RDONLY); in get_disk_fd()
916 device->disk_fd = open(device->path, O_RDWR); in get_disk_fd()
918 device->path_p0 = strdup(device->path); in get_disk_fd()
919 if (device->path_p0 == NULL) { in get_disk_fd()
924 if (is_bootpar(device->type)) { in get_disk_fd()
927 device->path[i - 2] = save[0]; in get_disk_fd()
928 device->path[i - 1] = save[1]; in get_disk_fd()
931 if (device->disk_fd == -1) { in get_disk_fd()
982 ig_device_t *device = &install->device; in write_stage2() local
988 if (is_bootpar(device->type)) { in write_stage2()
994 if (write_out(device->part_fd, stage2->file, SECTOR_SIZE, in write_stage2()
997 write_out(device->part_fd, stage2->file + SECTOR_SIZE, in write_stage2()
1016 if (is_efi(device->type) && stage2->buf_size > STAGE2_MAXSIZE) { in write_stage2()
1021 offset = STAGE2_BLKOFF(device->type) * SECTOR_SIZE; in write_stage2()
1023 if (write_out(device->part_fd, stage2->buf, stage2->buf_size, in write_stage2()
1030 (void) fprintf(stdout, WRITE_STAGE2_DISK, device->partition, in write_stage2()
1031 (stage2->buf_size / SECTOR_SIZE) + 1, STAGE2_BLKOFF(device->type), in write_stage2()
1040 ig_device_t *device = &install->device; in write_stage1() local
1044 if (write_out(device->part_fd, install->stage1_buf, in write_stage1()
1052 (void) fprintf(stdout, WRITE_PBOOT, device->partition, in write_stage1()
1053 device->start_sector); in write_stage1()
1056 if (write_out(device->disk_fd, install->stage1_buf, in write_stage1()
1106 ig_device_t *device = &dest->device; in read_stage2_from_file() local
1120 if (!is_bootpar(device->type)) { in read_stage2_from_file()
1149 if (!(is_bootpar(device->type))) in read_stage2_from_file()
1177 ig_device_t *device = &install->device; in prepare_stage1() local
1182 if (is_bootpar(device->type)) { in prepare_stage1()
1185 if (pread(device->part_fd, bpb_sect, SECTOR_SIZE, 0) in prepare_stage1()
1195 bcopy(device->boot_sector + BOOTSZ, install->stage1_buf + BOOTSZ, in prepare_stage1()
1297 ig_device_t *device = &data->device; in is_update_necessary() local
1298 int dev_fd = device->part_fd; in is_update_necessary()
1301 assert(device->part_fd != -1); in is_update_necessary()
1306 if (read_stage2_from_disk(dev_fd, &stage2_disk, device->type) in is_update_necessary()
1308 BOOT_DEBUG("Unable to read stage2 from %s\n", device->path); in is_update_necessary()
1309 BOOT_DEBUG("No multiboot wrapped stage2 on %s\n", device->path); in is_update_necessary()
1326 "versioned one\n", device->path); in is_update_necessary()
1331 BOOT_DEBUG("Forcing update of %s bootblock\n", device->path); in is_update_necessary()
1350 ig_device_t *device = &install->device; in prepare_stage2() local
1388 if (is_bootpar(device->type)) { in prepare_stage2()
1395 if (read_stage2_blocklist(device->part_fd, blocklist) != 0) { in prepare_stage2()
1402 stage2->first_sector = device->start_sector + blocklist[0]; in prepare_stage2()
1422 START_BLOCK(pos) = blocklist[i] + device->start_sector; in prepare_stage2()
1431 if (device->start_sector > in prepare_stage2()
1432 UINT32_MAX - STAGE2_BLKOFF(device->type)) { in prepare_stage2()
1435 (uint64_t)UINT32_MAX - STAGE2_BLKOFF(device->type)); in prepare_stage2()
1438 stage2->first_sector = device->start_sector + in prepare_stage2()
1439 STAGE2_BLKOFF(device->type); in prepare_stage2()
1452 = (device->partition << 16) | (device->slice << 8) | 0xff; in prepare_stage2()
1479 get_raw_partition_path(ig_device_t *device) in get_raw_partition_path() argument
1484 if (is_bootpar(device->type)) { in get_raw_partition_path()
1488 mboot = (struct mboot *)device->boot_sector; in get_raw_partition_path()
1491 device->path_p0); in get_raw_partition_path()
1495 raw = strdup(device->path_p0); in get_raw_partition_path()
1506 raw = strdup(device->path); in get_raw_partition_path()
1513 if (!is_efi(device->type) && in get_raw_partition_path()
1519 device->slice = atoi(&raw[len - 1]); in get_raw_partition_path()
1521 if (!is_efi(device->type)) { in get_raw_partition_path()
1530 get_raw_partition_fd(ig_device_t *device) in get_raw_partition_fd() argument
1535 raw = get_raw_partition_path(device); in get_raw_partition_fd()
1540 device->part_fd = open(raw, O_RDONLY); in get_raw_partition_fd()
1542 device->part_fd = open(raw, O_RDWR); in get_raw_partition_fd()
1544 if (device->part_fd < 0 || fstat(device->part_fd, &stat) != 0) { in get_raw_partition_fd()
1552 (void) close(device->part_fd); in get_raw_partition_fd()
1553 device->part_fd = -1; in get_raw_partition_fd()