Lines Matching +full:slice +full:- +full:per +full:- +full:line

141 	 * retro-compatibility: installing the bootblock is the default  in main()
191 /* fall through to process non-optional args */ in main()
228 (void) fprintf(stderr, gettext("Only one of -M and -i can be " in check_options()
236 * -u and -F may actually reflect a user intent that is not in check_options()
239 * -e and -V have no meaning, be quiet here and only report the in check_options()
243 (void) fprintf(stderr, MEANINGLESS_OPT, "-u"); in check_options()
247 (void) fprintf(stderr, MEANINGLESS_OPT, "-F"); in check_options()
251 BOOT_DEBUG(MEANINGLESS_OPT, "-e|-V"); in check_options()
259 BOOT_DEBUG(MEANINGLESS_OPT, "-m|-f|-u|-F"); in check_options()
271 * Returns: BC_SUCCESS - if the installation is successful
272 * BC_ERROR - if the installation failed
273 * BC_NOUPDT - if no installation was performed because the GRUB
328 * if a non-versioned update is attempted over a versioned bootblock. in handle_install()
333 "Use -F to override or install without the -u option\n"), in handle_install()
340 * - the installed GRUB version is older than the one about to be in handle_install()
342 * - no versioning string has been passed through the command line. in handle_install()
343 * - a forced update is requested (-F). in handle_install()
362 * - BC_SUCCESS (and prints out einfo contents depending on 'flags')
363 * - BC_ERROR (on error)
364 * - BC_NOEINFO (no extended information available)
395 if (is_bootpar(device->type)) { in handle_getinfo()
401 ret = read_stage2_from_disk(device->part_fd, stage2, device->type); in handle_getinfo()
416 einfo = find_einfo(stage2->extra, stage2->extra_size); in handle_getinfo()
430 size = stage2->buf_size - P2ROUNDUP(stage2->file_size, 8); in handle_getinfo()
445 * - BC_SUCCESS (a successful propagation happened)
446 * - BC_ERROR (an error occurred)
447 * - BC_NOEXTRA (it is not possible to dump the current bootblock since
493 if (is_bootpar(curr_device->type) || is_bootpar(attach_device->type)) { in handle_mirror()
499 ret = read_stage2_from_disk(curr_device->part_fd, stage2_curr, in handle_mirror()
500 curr_device->type); in handle_mirror()
503 curr_device->path); in handle_mirror()
510 "stage2\n", curr_device->path); in handle_mirror()
515 einfo_curr = find_einfo(stage2_curr->extra, stage2_curr->extra_size); 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()
581 ig_stage2_t *src_stage2 = &source->stage2; in propagate_bootblock()
582 ig_stage2_t *dest_stage2 = &target->stage2; in propagate_bootblock()
590 if (read_stage1_from_disk(src_device->part_fd, target->stage1_buf) in propagate_bootblock()
602 buf_size = src_stage2->file_size + SECTOR_SIZE; in propagate_bootblock()
604 dest_stage2->buf_size = P2ROUNDUP(buf_size, SECTOR_SIZE); in propagate_bootblock()
605 dest_stage2->buf = malloc(dest_stage2->buf_size); in propagate_bootblock()
606 if (dest_stage2->buf == NULL) { in propagate_bootblock()
610 dest_stage2->file = dest_stage2->buf; in propagate_bootblock()
611 dest_stage2->file_size = src_stage2->file_size; in propagate_bootblock()
612 memcpy(dest_stage2->file, src_stage2->file, dest_stage2->file_size); in propagate_bootblock()
613 dest_stage2->extra = dest_stage2->buf + in propagate_bootblock()
614 P2ROUNDUP(dest_stage2->file_size, 8); in propagate_bootblock()
617 assert(src_stage2->mboot); in propagate_bootblock()
619 dest_stage2->mboot_off = src_stage2->mboot_off; in propagate_bootblock()
620 dest_stage2->mboot = (multiboot_header_t *)(dest_stage2->buf + in propagate_bootblock()
621 dest_stage2->mboot_off); in propagate_bootblock()
624 src_device->path, dest_device->path); in propagate_bootblock()
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()
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()
680 if (is_efi(device->type)) { in init_device()
681 if (fstyp_init(device->part_fd, 0, NULL, &fhdl) != 0) in init_device()
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()
713 device->part_fd = -1; in cleanup_device()
714 device->disk_fd = -1; in cleanup_device()
720 if (stage2->buf) in cleanup_stage2()
721 free(stage2->buf); in cleanup_stage2()
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()
743 /* GPT doesn't use traditional slice letters */ 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()
780 part = (struct ipart *)mboot->parts + i; in get_start_sector()
782 if (part->relsect == 0) { in get_start_sector()
787 if (edkpi.p_start >= part->relsect && in get_start_sector()
788 edkpi.p_start < (part->relsect + part->numsect)) { in get_start_sector()
804 if (!fdisk_is_dos_extended(part->systid)) { 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()
818 * The first 3 cases are not an error per-se, just that in get_start_sector()
849 device->start_sector = secnum; in get_start_sector()
850 device->partition = pno - 1; in get_start_sector()
854 /* get confirmation for -m */ in get_start_sector()
879 if (!log_part && part->bootid != 128 && !write_mbr) { in get_start_sector()
881 device->partition + 1); in get_start_sector()
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()
945 assert(stage2->mboot != NULL); in prepare_fake_multiboot()
946 assert(stage2->buf != NULL); in prepare_fake_multiboot()
948 mboot = stage2->mboot; in prepare_fake_multiboot()
954 assert(mboot->flags & BB_MBOOT_AOUT_FLAG); in prepare_fake_multiboot()
957 mboot->header_addr = stage2->mboot_off; in prepare_fake_multiboot()
958 mboot->load_addr = 0; in prepare_fake_multiboot()
959 mboot->load_end_addr = stage2->file_size; in prepare_fake_multiboot()
971 hs.src_buf = (unsigned char *)stage2->file; in add_stage2_einfo()
972 hs.src_size = stage2->file_size; in add_stage2_einfo()
974 avail_space = stage2->buf_size - P2ROUNDUP(stage2->file_size, 8); in add_stage2_einfo()
975 add_einfo(stage2->extra, updt_str, &hs, avail_space); in add_stage2_einfo()
982 ig_device_t *device = &install->device; in write_stage2()
983 ig_stage2_t *stage2 = &install->stage2; in write_stage2()
988 if (is_bootpar(device->type)) { in write_stage2()
994 if (write_out(device->part_fd, stage2->file, SECTOR_SIZE, in write_stage2()
995 stage2->pcfs_first_sectors[0] * SECTOR_SIZE) in write_stage2()
997 write_out(device->part_fd, stage2->file + SECTOR_SIZE, in write_stage2()
998 SECTOR_SIZE, stage2->pcfs_first_sectors[1] * SECTOR_SIZE) in write_stage2()
1009 * Note that we use stage2->buf rather than stage2->file, because we in write_stage2()
1012 * If we're writing to an EFI-labeled disk where stage2 lives in the 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()
1032 stage2->first_sector); in write_stage2()
1040 ig_device_t *device = &install->device; in write_stage1()
1044 if (write_out(device->part_fd, install->stage1_buf, in write_stage1()
1045 sizeof (install->stage1_buf), 0) != BC_SUCCESS) { 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()
1057 sizeof (install->stage1_buf), 0) != BC_SUCCESS) { in write_stage1()
1069 #define USAGE_STRING "%s [-m|-f|-n|-F|-u verstr] stage1 stage2 device\n" \
1070 "%s -M [-n] device1 device2\n" \
1071 "%s [-V|-e] -i device\n" \
1091 if (fd == -1 || in read_stage1_from_file()
1092 read(fd, dest->stage1_buf, SECTOR_SIZE) != SECTOR_SIZE) { in read_stage1_from_file()
1105 ig_stage2_t *stage2 = &dest->stage2; in read_stage2_from_file()
1106 ig_device_t *device = &dest->device; in read_stage2_from_file()
1110 assert(stage2->buf == NULL); in read_stage2_from_file()
1113 if (fstat(fd, &sb) == -1) { in read_stage2_from_file()
1118 stage2->file_size = sb.st_size; in read_stage2_from_file()
1120 if (!is_bootpar(device->type)) { in read_stage2_from_file()
1126 buf_size = stage2->file_size + SECTOR_SIZE; in read_stage2_from_file()
1129 buf_size = stage2->file_size; in read_stage2_from_file()
1132 stage2->buf_size = P2ROUNDUP(buf_size, SECTOR_SIZE); in read_stage2_from_file()
1134 BOOT_DEBUG("stage2 buffer size = %d (%d sectors)\n", stage2->buf_size, in read_stage2_from_file()
1135 stage2->buf_size / SECTOR_SIZE); in read_stage2_from_file()
1137 stage2->buf = malloc(stage2->buf_size); in read_stage2_from_file()
1138 if (stage2->buf == NULL) { in read_stage2_from_file()
1143 stage2->file = stage2->buf; in read_stage2_from_file()
1147 * end of stage2, aligned on a 8-byte boundary. in read_stage2_from_file()
1149 if (!(is_bootpar(device->type))) in read_stage2_from_file()
1150 stage2->extra = stage2->file + P2ROUNDUP(stage2->file_size, 8); in read_stage2_from_file()
1152 if (lseek(fd, 0, SEEK_SET) == -1) { in read_stage2_from_file()
1157 if (read(fd, stage2->file, stage2->file_size) < 0) { in read_stage2_from_file()
1166 free(stage2->buf); in read_stage2_from_file()
1167 stage2->buf = NULL; in read_stage2_from_file()
1177 ig_device_t *device = &install->device; in prepare_stage1()
1182 if (is_bootpar(device->type)) { in prepare_stage1()
1185 if (pread(device->part_fd, bpb_sect, SECTOR_SIZE, 0) in prepare_stage1()
1191 install->stage1_buf + STAGE1_BPB_OFFSET, STAGE1_BPB_SIZE); in prepare_stage1()
1195 bcopy(device->boot_sector + BOOTSZ, install->stage1_buf + BOOTSZ, in prepare_stage1()
1196 SECTOR_SIZE - BOOTSZ); in prepare_stage1()
1198 *((unsigned char *)(install->stage1_buf + STAGE1_FORCE_LBA)) = 1; in prepare_stage1()
1199 *((ulong_t *)(install->stage1_buf + STAGE1_STAGE2_SECTOR)) in prepare_stage1()
1200 = install->stage2.first_sector; in prepare_stage1()
1201 *((ushort_t *)(install->stage1_buf + STAGE1_STAGE2_ADDRESS)) in prepare_stage1()
1203 *((ushort_t *)(install->stage1_buf + STAGE1_STAGE2_SEGMENT)) in prepare_stage1()
1233 assert(dev_fd != -1); in read_stage2_from_disk()
1253 if (mboot->load_end_addr == 0 || in read_stage2_from_disk()
1254 mboot->load_end_addr < mboot->load_addr) in read_stage2_from_disk()
1262 size = mboot->load_end_addr - mboot->load_addr; in read_stage2_from_disk()
1265 stage2->buf = malloc(buf_size); in read_stage2_from_disk()
1266 if (stage2->buf == NULL) { in read_stage2_from_disk()
1270 stage2->buf_size = buf_size; in read_stage2_from_disk()
1272 if (read_in(dev_fd, stage2->buf, buf_size, STAGE2_BLKOFF(type) * in read_stage2_from_disk()
1275 free(stage2->buf); in read_stage2_from_disk()
1280 stage2->file = stage2->buf; in read_stage2_from_disk()
1281 stage2->file_size = size; in read_stage2_from_disk()
1282 stage2->mboot_off = mboot_off; in read_stage2_from_disk()
1283 stage2->mboot = (multiboot_header_t *)(stage2->buf + stage2->mboot_off); in read_stage2_from_disk()
1284 stage2->extra = stage2->buf + P2ROUNDUP(stage2->file_size, 8); in read_stage2_from_disk()
1285 stage2->extra_size = stage2->buf_size - P2ROUNDUP(stage2->file_size, 8); in read_stage2_from_disk()
1296 ig_stage2_t *stage2_file = &data->stage2; in is_update_necessary()
1297 ig_device_t *device = &data->device; in is_update_necessary()
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()
1336 stage2_hs.src_buf = (unsigned char *)stage2_file->file; in is_update_necessary()
1337 stage2_hs.src_size = stage2_file->file_size; in is_update_necessary()
1350 ig_device_t *device = &install->device; in prepare_stage2()
1351 ig_stage2_t *stage2 = &install->stage2; in prepare_stage2()
1355 assert(stage2->file != NULL); in prepare_stage2()
1358 if (find_multiboot(stage2->file, stage2->file_size, &mboot_off) in prepare_stage2()
1369 stage2->mboot_off = mboot_off; in prepare_stage2()
1370 stage2->mboot = (multiboot_header_t *)(stage2->file + in prepare_stage2()
1388 if (is_bootpar(device->type)) { in prepare_stage2()
1395 if (read_stage2_blocklist(device->part_fd, blocklist) != 0) { in prepare_stage2()
1401 pos = (uchar_t *)stage2->file + STAGE2_BLOCKLIST; in prepare_stage2()
1402 stage2->first_sector = device->start_sector + blocklist[0]; in prepare_stage2()
1403 stage2->pcfs_first_sectors[0] = blocklist[0]; in prepare_stage2()
1404 BOOT_DEBUG("stage2 first sector: %d\n", stage2->first_sector); in prepare_stage2()
1409 blocklist[1]--; in prepare_stage2()
1414 stage2->pcfs_first_sectors[1] = blocklist[i]; in prepare_stage2()
1417 if (START_BLOCK(pos - 8) != 0 && in prepare_stage2()
1418 START_BLOCK(pos - 8) != blocklist[i + 2]) { in prepare_stage2()
1422 START_BLOCK(pos) = blocklist[i] + device->start_sector; in prepare_stage2()
1426 pos -= 8; 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()
1440 BOOT_DEBUG("stage2 first sector: %d\n", stage2->first_sector); in prepare_stage2()
1445 *((ulong_t *)(stage2->file + STAGE2_BLOCKLIST)) = in prepare_stage2()
1446 stage2->first_sector + 1; in prepare_stage2()
1450 *((unsigned char *) (stage2->file + STAGE2_FORCE_LBA)) = 1; in prepare_stage2()
1451 *((long *)(stage2->file + STAGE2_INSTALLPART)) in prepare_stage2()
1452 = (device->partition << 16) | (device->slice << 8) | 0xff; in prepare_stage2()
1465 part = (struct ipart *)mboot->parts + i; in find_x86_bootpar()
1466 if (part->systid == 0xbe) { in find_x86_bootpar()
1468 *start_sect = part->relsect; in find_x86_bootpar()
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()
1501 raw[strlen(raw) - 2] = '1' + part; in get_raw_partition_path()
1505 /* For disk, remember slice and return whole fdisk partition */ 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()
1514 (raw[len - 2] != 's' || raw[len - 1] == '2')) { 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()
1522 raw[len - 2] = 's'; in get_raw_partition_path()
1523 raw[len - 1] = '2'; in get_raw_partition_path()
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()