@@ -1145,25 +1145,29 @@ zhack_repair_one_label_large(const zhack_repair_op_t op, const int fd,
11451145 }
11461146
11471147 uint32_t bootenv_size , vc_size , sc_size ;
1148- if ((err = nvlist_lookup_uint32 (toc , VDEV_TOC_BOOT_REGION ,
1149- & bootenv_size )) || (err = nvlist_lookup_uint32 (toc ,
1150- VDEV_TOC_VDEV_CONFIG , & vc_size )) || (err = nvlist_lookup_uint32 (toc ,
1151- VDEV_TOC_POOL_CONFIG , & sc_size ))) {
1148+ uint32_t bootenv_offset , vc_offset , sc_offset ;
1149+ if (!vdev_toc_get_secinfo (toc , VDEV_TOC_BOOT_REGION ,
1150+ & bootenv_size , & bootenv_offset ) || !vdev_toc_get_secinfo (toc ,
1151+ VDEV_TOC_VDEV_CONFIG , & vc_size , & vc_offset ) ||
1152+ !vdev_toc_get_secinfo (toc , VDEV_TOC_POOL_CONFIG , & sc_size ,
1153+ & sc_offset )) {
1154+ fnvlist_free (toc );
11521155 (void ) fprintf (stderr ,
11531156 "error: TOC missing core fields %d\n" , l );
11541157 goto out ;
11551158 }
1159+ fnvlist_free (toc );
11561160 bootenv = malloc (bootenv_size );
11571161 zio_eck_t * bootenv_eck = (zio_eck_t * )(bootenv + bootenv_size ) - 1 ;
11581162 vdev_config = malloc (vc_size );
11591163 zio_eck_t * vc_eck = (zio_eck_t * )(vdev_config + vc_size ) - 1 ;
11601164 spa_config = malloc (sc_size );
11611165 zio_eck_t * sc_eck = (zio_eck_t * )(spa_config + sc_size ) - 1 ;
11621166
1163- uint64_t offset = label_offset + VDEV_TOC_SIZE ;
1167+ uint64_t base_offset = label_offset ;
11641168 if (bootenv_size != 0 ) {
11651169 if ((err = zhack_repair_read (fd , bootenv ,
1166- bootenv_size , offset , l )))
1170+ bootenv_size , base_offset + bootenv_offset , l )))
11671171 goto out ;
11681172 if (byteswap ) {
11691173 byteswap_uint64_array (& bootenv_eck -> zec_cksum ,
@@ -1173,15 +1177,15 @@ zhack_repair_one_label_large(const zhack_repair_op_t op, const int fd,
11731177 }
11741178 if ((op & ZHACK_REPAIR_OP_CKSUM ) == 0 &&
11751179 zhack_repair_test_cksum (byteswap , bootenv , bootenv_size ,
1176- bootenv_eck , offset , l ) != 0 ) {
1180+ bootenv_eck , base_offset + bootenv_offset , l ) != 0 ) {
11771181 (void ) fprintf (stderr , "It would appear checksums are "
11781182 "corrupted. Try zhack repair label -c <device>\n" );
11791183 goto out ;
11801184 }
11811185 }
11821186
1183- offset += bootenv_size ;
1184- if (( err = zhack_repair_read ( fd , vdev_config , vc_size , offset , l )))
1187+ if (( err = zhack_repair_read ( fd , vdev_config , vc_size ,
1188+ base_offset + vc_offset , l )))
11851189 goto out ;
11861190
11871191 if (byteswap ) {
@@ -1191,13 +1195,13 @@ zhack_repair_one_label_large(const zhack_repair_op_t op, const int fd,
11911195 }
11921196 if ((op & ZHACK_REPAIR_OP_CKSUM ) == 0 &&
11931197 zhack_repair_test_cksum (byteswap , vdev_config , vc_size ,
1194- vc_eck , offset , l ) != 0 ) {
1198+ vc_eck , base_offset + vc_offset , l ) != 0 ) {
11951199 (void ) fprintf (stderr , "It would appear checksums are "
11961200 "corrupted. Try zhack repair label -c <device>\n" );
11971201 goto out ;
11981202 }
1199- offset += vc_size ;
1200- if (( err = zhack_repair_read ( fd , spa_config , sc_size , offset , l )))
1203+ if (( err = zhack_repair_read ( fd , spa_config , sc_size ,
1204+ base_offset + sc_offset , l )))
12011205 goto out ;
12021206
12031207 if (byteswap ) {
@@ -1207,7 +1211,7 @@ zhack_repair_one_label_large(const zhack_repair_op_t op, const int fd,
12071211 }
12081212 if ((op & ZHACK_REPAIR_OP_CKSUM ) == 0 &&
12091213 zhack_repair_test_cksum (byteswap , spa_config , sc_size ,
1210- sc_eck , offset , l ) != 0 ) {
1214+ sc_eck , base_offset + sc_offset , l ) != 0 ) {
12111215 (void ) fprintf (stderr , "It would appear checksums are "
12121216 "corrupted. Try zhack repair label -c <device>\n" );
12131217 goto out ;
@@ -1256,21 +1260,17 @@ zhack_repair_one_label_large(const zhack_repair_op_t op, const int fd,
12561260 label_offset , labels_repaired );
12571261 }
12581262
1259- offset = label_offset ;
12601263 if (zhack_repair_write_label (l , fd , byteswap , toc_data , toc_eck ,
1261- offset , VDEV_TOC_SIZE ))
1264+ base_offset , VDEV_TOC_SIZE ))
12621265 labels_repaired [l ] |= REPAIR_LABEL_STATUS_CKSUM ;
1263- offset += VDEV_TOC_SIZE ;
12641266 if (zhack_repair_write_label (l , fd , byteswap , bootenv , bootenv_eck ,
1265- offset , bootenv_size ))
1267+ base_offset + bootenv_offset , bootenv_size ))
12661268 labels_repaired [l ] |= REPAIR_LABEL_STATUS_CKSUM ;
1267- offset += bootenv_size ;
12681269 if (zhack_repair_write_label (l , fd , byteswap , vdev_config , vc_eck ,
1269- offset , vc_size ))
1270+ base_offset + vc_offset , vc_size ))
12701271 labels_repaired [l ] |= REPAIR_LABEL_STATUS_CKSUM ;
1271- offset += vc_size ;
12721272 if (zhack_repair_write_label (l , fd , byteswap , spa_config , sc_eck ,
1273- offset , sc_size ))
1273+ base_offset + sc_offset , sc_size ))
12741274 labels_repaired [l ] |= REPAIR_LABEL_STATUS_CKSUM ;
12751275
12761276 fsync (fd );
0 commit comments