Lines Matching defs:vtoc

37 #include <sys/vtoc.h>
81 * Default vtoc information for non-SVr4 partitions
144 efi_alloc_and_init(int fd, uint32_t nparts, struct dk_gpt **vtoc)
178 if ((*vtoc = calloc(length, 1)) == NULL)
181 vptr = *vtoc;
205 efi_alloc_and_read(int fd, struct dk_gpt **vtoc)
215 if ((*vtoc = calloc(length, 1)) == NULL)
218 (*vtoc)->efi_nparts = nparts;
219 rval = efi_read(fd, *vtoc);
221 if ((rval == VT_EINVAL) && (*vtoc)->efi_nparts > nparts) {
225 ((*vtoc)->efi_nparts - 1);
226 nparts = (*vtoc)->efi_nparts;
227 if ((tmp = realloc(*vtoc, length)) == NULL) {
228 free (*vtoc);
229 *vtoc = NULL;
232 *vtoc = tmp;
233 rval = efi_read(fd, *vtoc);
242 free (*vtoc);
243 *vtoc = NULL;
309 efi_read(int fd, struct dk_gpt *vtoc)
373 if (NBLOCKS(vtoc->efi_nparts, disk_info.dki_lbsize) < 34) {
376 label_len = vtoc->efi_nparts * (int) sizeof (efi_gpe_t) +
389 user_length = vtoc->efi_nparts;
445 vtoc->efi_flags |= EFI_GPT_PRIMARY_CORRUPT;
446 vtoc->efi_nparts =
514 vtoc->efi_version = LE_32(efi->efi_gpt_Revision);
515 vtoc->efi_nparts = LE_32(efi->efi_gpt_NumberOfPartitionEntries);
516 vtoc->efi_part_size = LE_32(efi->efi_gpt_SizeOfPartitionEntry);
517 vtoc->efi_lbasize = disk_info.dki_lbsize;
518 vtoc->efi_last_lba = disk_info.dki_capacity - 1;
519 vtoc->efi_first_u_lba = LE_64(efi->efi_gpt_FirstUsableLBA);
520 vtoc->efi_last_u_lba = LE_64(efi->efi_gpt_LastUsableLBA);
521 vtoc->efi_altern_lba = LE_64(efi->efi_gpt_AlternateLBA);
522 UUID_LE_CONVERT(vtoc->efi_disk_uguid, efi->efi_gpt_DiskGUID);
528 if (user_length < vtoc->efi_nparts) {
532 for (i = 0; i < vtoc->efi_nparts; i++) {
534 UUID_LE_CONVERT(vtoc->efi_parts[i].p_guid,
541 if (bcmp(&vtoc->efi_parts[i].p_guid,
544 vtoc->efi_parts[i].p_tag = j;
548 if (vtoc->efi_parts[i].p_tag == V_UNASSIGNED)
550 vtoc->efi_parts[i].p_flag =
552 vtoc->efi_parts[i].p_start =
554 vtoc->efi_parts[i].p_size =
556 vtoc->efi_parts[i].p_start + 1;
558 vtoc->efi_parts[i].p_name[j] =
563 UUID_LE_CONVERT(vtoc->efi_parts[i].p_uguid,
573 write_pmbr(int fd, struct dk_gpt *vtoc)
582 len = (vtoc->efi_lbasize == 0) ? sizeof (mb) : vtoc->efi_lbasize;
625 size_in_lba = vtoc->efi_last_lba;
660 check_input(struct dk_gpt *vtoc)
669 for (i = 0; i < vtoc->efi_nparts; i++) {
671 if ((vtoc->efi_parts[i].p_tag == V_UNASSIGNED) &&
672 (vtoc->efi_parts[i].p_size != 0)) {
677 vtoc->efi_parts[i].p_size);
681 if (vtoc->efi_parts[i].p_tag == V_UNASSIGNED) {
682 if (uuid_is_null((uchar_t *)&vtoc->efi_parts[i].p_guid))
685 vtoc->efi_parts[i].p_tag = 0xff;
687 if (vtoc->efi_parts[i].p_tag == V_RESERVED) {
698 if ((vtoc->efi_parts[i].p_start < vtoc->efi_first_u_lba) ||
699 (vtoc->efi_parts[i].p_start > vtoc->efi_last_u_lba)) {
704 vtoc->efi_parts[i].p_start);
707 vtoc->efi_first_u_lba,
708 vtoc->efi_last_u_lba);
712 if ((vtoc->efi_parts[i].p_start +
713 vtoc->efi_parts[i].p_size <
714 vtoc->efi_first_u_lba) ||
715 (vtoc->efi_parts[i].p_start +
716 vtoc->efi_parts[i].p_size >
717 vtoc->efi_last_u_lba + 1)) {
722 vtoc->efi_parts[i].p_start +
723 vtoc->efi_parts[i].p_size);
726 vtoc->efi_first_u_lba,
727 vtoc->efi_last_u_lba);
732 for (j = 0; j < vtoc->efi_nparts; j++) {
733 isize = vtoc->efi_parts[i].p_size;
734 jsize = vtoc->efi_parts[j].p_size;
735 istart = vtoc->efi_parts[i].p_start;
736 jstart = vtoc->efi_parts[j].p_start;
843 efi_write(int fd, struct dk_gpt *vtoc)
873 if (check_input(vtoc)) {
884 if (NBLOCKS(vtoc->efi_nparts, vtoc->efi_lbasize) < 34) {
885 dk_ioc.dki_length = EFI_MIN_ARRAY_SIZE + vtoc->efi_lbasize;
887 dk_ioc.dki_length = NBLOCKS(vtoc->efi_nparts,
888 vtoc->efi_lbasize) *
889 vtoc->efi_lbasize;
895 nblocks = dk_ioc.dki_length / vtoc->efi_lbasize - 1;
902 lba_backup_gpt_hdr = vtoc->efi_last_u_lba + 1 + nblocks;
910 efi->efi_gpt_Revision = LE_32(vtoc->efi_version); /* 0x02000100 */
915 efi->efi_gpt_FirstUsableLBA = LE_64(vtoc->efi_first_u_lba);
916 efi->efi_gpt_LastUsableLBA = LE_64(vtoc->efi_last_u_lba);
918 efi->efi_gpt_NumberOfPartitionEntries = LE_32(vtoc->efi_nparts);
920 UUID_LE_CONVERT(efi->efi_gpt_DiskGUID, vtoc->efi_disk_uguid);
923 efi_parts = (efi_gpe_t *)((char *)dk_ioc.dki_data + vtoc->efi_lbasize);
925 for (i = 0; i < vtoc->efi_nparts; i++) {
930 if (vtoc->efi_parts[i].p_tag == j) {
947 vtoc->efi_parts[i].p_tag);
953 LE_64(vtoc->efi_parts[i].p_start);
955 LE_64(vtoc->efi_parts[i].p_start +
956 vtoc->efi_parts[i].p_size - 1);
958 LE_16(vtoc->efi_parts[i].p_flag);
961 LE_16((ushort_t)vtoc->efi_parts[i].p_name[j]);
963 if ((vtoc->efi_parts[i].p_tag != V_UNASSIGNED) &&
964 uuid_is_null((uchar_t *)&vtoc->efi_parts[i].p_uguid)) {
966 &vtoc->efi_parts[i].p_uguid);
968 bcopy(&vtoc->efi_parts[i].p_uguid,
974 vtoc->efi_nparts * (int)sizeof (struct efi_gpe)));
996 dk_ioc.dki_lba = vtoc->efi_last_u_lba + 1;
997 dk_ioc.dki_length -= vtoc->efi_lbasize;
1000 vtoc->efi_lbasize);
1010 vtoc->efi_last_u_lba + 1,
1019 dk_ioc.dki_length = vtoc->efi_lbasize;
1022 vtoc->efi_lbasize);
1025 efi->efi_gpt_PartitionEntryLBA = LE_64(vtoc->efi_last_u_lba + 1);
1041 (void) write_pmbr(fd, vtoc);
1060 struct vtoc vtoc;
1067 if (ioctl(fd, DKIOCGVTOC, &vtoc) == -1)
1076 efi_err_check(struct dk_gpt *vtoc)
1086 for (i = 0; i < vtoc->efi_nparts; i++) {
1088 if ((vtoc->efi_parts[i].p_tag == V_UNASSIGNED) &&
1089 (vtoc->efi_parts[i].p_size != 0)) {
1092 "of %llu\n", i, vtoc->efi_parts[i].p_size);
1094 if (vtoc->efi_parts[i].p_tag == V_UNASSIGNED) {
1097 if (vtoc->efi_parts[i].p_tag == V_RESERVED) {
1104 if (vtoc->efi_parts[i].p_size != EFI_MIN_RESV_SIZE)
1109 if ((vtoc->efi_parts[i].p_start < vtoc->efi_first_u_lba) ||
1110 (vtoc->efi_parts[i].p_start > vtoc->efi_last_u_lba)) {
1114 vtoc->efi_parts[i].p_start);
1117 vtoc->efi_first_u_lba,
1118 vtoc->efi_last_u_lba);
1120 if ((vtoc->efi_parts[i].p_start +
1121 vtoc->efi_parts[i].p_size <
1122 vtoc->efi_first_u_lba) ||
1123 (vtoc->efi_parts[i].p_start +
1124 vtoc->efi_parts[i].p_size >
1125 vtoc->efi_last_u_lba + 1)) {
1129 vtoc->efi_parts[i].p_start +
1130 vtoc->efi_parts[i].p_size);
1133 vtoc->efi_first_u_lba,
1134 vtoc->efi_last_u_lba);
1137 for (j = 0; j < vtoc->efi_nparts; j++) {
1138 isize = vtoc->efi_parts[i].p_size;
1139 jsize = vtoc->efi_parts[j].p_size;
1140 istart = vtoc->efi_parts[i].p_start;
1141 jstart = vtoc->efi_parts[j].p_start;
1171 efi_auto_sense(int fd, struct dk_gpt **vtoc)
1179 if (efi_alloc_and_init(fd, EFI_NUMPAR, vtoc) != 0) {
1186 for (i = 0; i < min((*vtoc)->efi_nparts, V_NUMPAR); i++) {
1187 (*vtoc)->efi_parts[i].p_tag = default_vtoc_map[i].p_tag;
1188 (*vtoc)->efi_parts[i].p_flag = default_vtoc_map[i].p_flag;
1189 (*vtoc)->efi_parts[i].p_start = 0;
1190 (*vtoc)->efi_parts[i].p_size = 0;
1198 (*vtoc)->efi_parts[0].p_start = 34;
1199 (*vtoc)->efi_parts[0].p_size = 262144;
1202 (*vtoc)->efi_parts[1].p_start = 262178;
1203 (*vtoc)->efi_parts[1].p_size = 262144;
1206 (*vtoc)->efi_parts[2].p_tag = V_UNASSIGNED;
1209 (*vtoc)->efi_parts[6].p_start = 524322;
1210 (*vtoc)->efi_parts[6].p_size = (*vtoc)->efi_last_u_lba - 524322
1214 (*vtoc)->efi_parts[8].p_start = (*vtoc)->efi_last_u_lba - (1024 * 16);
1215 (*vtoc)->efi_parts[8].p_size = (1024 * 16);
1216 (*vtoc)->efi_parts[8].p_tag = V_RESERVED;