@@ -960,25 +960,29 @@ zhack_repair_one_label_large(const zhack_repair_op_t op, const int fd,
960960 }
961961
962962 uint32_t bootenv_size , vc_size , sc_size ;
963- if ((err = nvlist_lookup_uint32 (toc , VDEV_TOC_BOOT_REGION ,
964- & bootenv_size )) || (err = nvlist_lookup_uint32 (toc ,
965- VDEV_TOC_VDEV_CONFIG , & vc_size )) || (err = nvlist_lookup_uint32 (toc ,
966- VDEV_TOC_POOL_CONFIG , & sc_size ))) {
963+ uint32_t bootenv_offset , vc_offset , sc_offset ;
964+ if (!vdev_toc_get_secinfo (toc , VDEV_TOC_BOOT_REGION ,
965+ & bootenv_size , & bootenv_offset ) || !vdev_toc_get_secinfo (toc ,
966+ VDEV_TOC_VDEV_CONFIG , & vc_size , & vc_offset ) ||
967+ !vdev_toc_get_secinfo (toc , VDEV_TOC_POOL_CONFIG , & sc_size ,
968+ & sc_offset )) {
969+ fnvlist_free (toc );
967970 (void ) fprintf (stderr ,
968971 "error: TOC missing core fields %d\n" , l );
969972 goto out ;
970973 }
974+ fnvlist_free (toc );
971975 bootenv = malloc (bootenv_size );
972976 zio_eck_t * bootenv_eck = (zio_eck_t * )(bootenv + bootenv_size ) - 1 ;
973977 vdev_config = malloc (vc_size );
974978 zio_eck_t * vc_eck = (zio_eck_t * )(vdev_config + vc_size ) - 1 ;
975979 spa_config = malloc (sc_size );
976980 zio_eck_t * sc_eck = (zio_eck_t * )(spa_config + sc_size ) - 1 ;
977981
978- uint64_t offset = label_offset + VDEV_TOC_SIZE ;
982+ uint64_t base_offset = label_offset ;
979983 if (bootenv_size != 0 ) {
980984 if ((err = zhack_repair_read (fd , bootenv ,
981- bootenv_size , offset , l )))
985+ bootenv_size , base_offset + bootenv_offset , l )))
982986 goto out ;
983987 if (byteswap ) {
984988 byteswap_uint64_array (& bootenv_eck -> zec_cksum ,
@@ -988,15 +992,15 @@ zhack_repair_one_label_large(const zhack_repair_op_t op, const int fd,
988992 }
989993 if ((op & ZHACK_REPAIR_OP_CKSUM ) == 0 &&
990994 zhack_repair_test_cksum (byteswap , bootenv , bootenv_size ,
991- bootenv_eck , offset , l ) != 0 ) {
995+ bootenv_eck , base_offset + bootenv_offset , l ) != 0 ) {
992996 (void ) fprintf (stderr , "It would appear checksums are "
993997 "corrupted. Try zhack repair label -c <device>\n" );
994998 goto out ;
995999 }
9961000 }
9971001
998- offset += bootenv_size ;
999- if (( err = zhack_repair_read ( fd , vdev_config , vc_size , offset , l )))
1002+ if (( err = zhack_repair_read ( fd , vdev_config , vc_size ,
1003+ base_offset + vc_offset , l )))
10001004 goto out ;
10011005
10021006 if (byteswap ) {
@@ -1006,13 +1010,13 @@ zhack_repair_one_label_large(const zhack_repair_op_t op, const int fd,
10061010 }
10071011 if ((op & ZHACK_REPAIR_OP_CKSUM ) == 0 &&
10081012 zhack_repair_test_cksum (byteswap , vdev_config , vc_size ,
1009- vc_eck , offset , l ) != 0 ) {
1013+ vc_eck , base_offset + vc_offset , l ) != 0 ) {
10101014 (void ) fprintf (stderr , "It would appear checksums are "
10111015 "corrupted. Try zhack repair label -c <device>\n" );
10121016 goto out ;
10131017 }
1014- offset += vc_size ;
1015- if (( err = zhack_repair_read ( fd , spa_config , sc_size , offset , l )))
1018+ if (( err = zhack_repair_read ( fd , spa_config , sc_size ,
1019+ base_offset + sc_offset , l )))
10161020 goto out ;
10171021
10181022 if (byteswap ) {
@@ -1022,7 +1026,7 @@ zhack_repair_one_label_large(const zhack_repair_op_t op, const int fd,
10221026 }
10231027 if ((op & ZHACK_REPAIR_OP_CKSUM ) == 0 &&
10241028 zhack_repair_test_cksum (byteswap , spa_config , sc_size ,
1025- sc_eck , offset , l ) != 0 ) {
1029+ sc_eck , base_offset + sc_offset , l ) != 0 ) {
10261030 (void ) fprintf (stderr , "It would appear checksums are "
10271031 "corrupted. Try zhack repair label -c <device>\n" );
10281032 goto out ;
@@ -1071,21 +1075,17 @@ zhack_repair_one_label_large(const zhack_repair_op_t op, const int fd,
10711075 label_offset , labels_repaired );
10721076 }
10731077
1074- offset = label_offset ;
10751078 if (zhack_repair_write_label (l , fd , byteswap , toc_data , toc_eck ,
1076- offset , VDEV_TOC_SIZE ))
1079+ base_offset , VDEV_TOC_SIZE ))
10771080 labels_repaired [l ] |= REPAIR_LABEL_STATUS_CKSUM ;
1078- offset += VDEV_TOC_SIZE ;
10791081 if (zhack_repair_write_label (l , fd , byteswap , bootenv , bootenv_eck ,
1080- offset , bootenv_size ))
1082+ base_offset + bootenv_offset , bootenv_size ))
10811083 labels_repaired [l ] |= REPAIR_LABEL_STATUS_CKSUM ;
1082- offset += bootenv_size ;
10831084 if (zhack_repair_write_label (l , fd , byteswap , vdev_config , vc_eck ,
1084- offset , vc_size ))
1085+ base_offset + vc_offset , vc_size ))
10851086 labels_repaired [l ] |= REPAIR_LABEL_STATUS_CKSUM ;
1086- offset += vc_size ;
10871087 if (zhack_repair_write_label (l , fd , byteswap , spa_config , sc_eck ,
1088- offset , sc_size ))
1088+ base_offset + sc_offset , sc_size ))
10891089 labels_repaired [l ] |= REPAIR_LABEL_STATUS_CKSUM ;
10901090
10911091 fsync (fd );
0 commit comments