@@ -69,6 +69,10 @@ def BF64_GET(x: drgn.Object, low: int, length: int) -> int:
6969 return BF64_DECODE (x , low , length )
7070
7171
72+ def BF64_GET_SB (x : int , low : int , length : int , shift : int , bias : int ) -> int :
73+ return (BF64_GET (x , low , length ) + bias ) << shift
74+
75+
7276def WEIGHT_IS_SPACEBASED (weight : int ) -> bool :
7377 return weight == 0 or (BF64_GET (weight , 60 , 1 ) != 0 )
7478
@@ -81,6 +85,184 @@ def WEIGHT_GET_COUNT(weight: int) -> int:
8185 return BF64_GET ((weight ), 0 , 54 )
8286
8387
88+ def BPE_GET_ETYPE (bp : drgn .Object ) -> int :
89+ return BF64_GET (bp .blk_prop , 40 , 8 )
90+
91+
92+ def BPE_GET_LSIZE (bp : drgn .Object ) -> int :
93+ return BF64_GET_SB (bp .blk_prop , 0 , 25 , 0 , 1 )
94+
95+
96+ def BPE_GET_PSIZE (bp : drgn .Object ) -> int :
97+ return BF64_GET_SB (bp .blk_prop , 25 , 7 , 0 , 1 )
98+
99+
100+ def BP_GET_LSIZE (bp : drgn .Object ) -> int :
101+ if BP_IS_EMBEDDED (bp ):
102+ if BPE_GET_ETYPE (bp ) == BP_EMBEDDED_TYPE_DATA :
103+ return BPE_GET_LSIZE (bp )
104+ return 0
105+ return BF64_GET_SB (bp .blk_prop , 0 , SPA_LSIZEBITS , SPA_MINBLOCKSHIFT , 1 )
106+
107+
108+ def BP_GET_PSIZE (bp : drgn .Object ) -> int :
109+ if BP_IS_EMBEDDED (bp ):
110+ return 0
111+ return BF64_GET_SB (bp .blk_prop , 16 , SPA_PSIZEBITS , SPA_MINBLOCKSHIFT , 1 )
112+
113+
114+ def BP_GET_COMPRESS (bp : drgn .Object ) -> int :
115+ return BF64_GET (bp .blk_prop , 32 , SPA_COMPRESSBITS )
116+
117+
118+ def BP_IS_EMBEDDED (bp : drgn .Object ) -> bool :
119+ return bool (BF64_GET (bp .blk_prop , 39 , 1 ))
120+
121+
122+ def BP_GET_CHECKSUM (bp : drgn .Object ) -> int :
123+ if BP_IS_EMBEDDED (bp ):
124+ return ZIO_CHECKSUM_OFF
125+ return BF64_GET (bp .blk_prop , 40 , 8 )
126+
127+
128+ def BP_GET_TYPE (bp : drgn .Object ) -> int :
129+ return BF64_GET (bp .blk_prop , 48 , 8 )
130+
131+
132+ def BP_GET_LEVEL (bp : drgn .Object ) -> int :
133+ return BF64_GET (bp .blk_prop , 56 , 5 )
134+
135+
136+ def BP_USES_CRYPT (bp : drgn .Object ) -> bool :
137+ return bool (BF64_GET (bp .blk_prop , 61 , 1 ))
138+
139+
140+ def BP_IS_ENCRYPTED (bp : drgn .Object ) -> bool :
141+ return (BP_USES_CRYPT (bp ) and BP_GET_LEVEL (bp ) <= 0 and
142+ DMU_OT_IS_ENCRYPTED (BP_GET_TYPE (bp )))
143+
144+
145+ def BP_IS_AUTHENTICATED (bp : drgn .Object ) -> bool :
146+ return (BP_USES_CRYPT (bp ) and BP_GET_LEVEL (bp ) <= 0 and
147+ not DMU_OT_IS_ENCRYPTED (BP_GET_TYPE (bp )))
148+
149+
150+ def BP_HAS_INDIRECT_MAC_CKSUM (bp : drgn .Object ) -> bool :
151+ return (BP_USES_CRYPT (bp ) and BP_GET_LEVEL (bp ) > 0 )
152+
153+
154+ def BP_GET_DEDUP (bp : drgn .Object ) -> bool :
155+ return bool (BF64_GET (bp .blk_prop , 62 , 1 ))
156+
157+
158+ def BP_GET_BYTEORDER (bp : drgn .Object ) -> int :
159+ return BF64_GET (bp .blk_prop , 63 , 1 )
160+
161+
162+ def BP_GET_LAYER (bp : drgn .Object ) -> int :
163+ if sdb .get_type ('blkptr_t' ).has_member ('blk_logical_birth' ):
164+ return BF64_GET (bp .blk_logical_birth , 56 , 8 )
165+ return BF64_GET (bp .blk_birth , 56 , 8 )
166+
167+
168+ def BP_LOGICAL_BIRTH (bp : drgn .Object ) -> int :
169+ if sdb .get_type ('blkptr_t' ).has_member ('blk_logical_birth' ):
170+ return BF64_GET (bp .blk_logical_birth , 0 , 56 )
171+ return BF64_GET (bp .blk_birth , 0 , 56 )
172+
173+
174+ def BP_PHYSICAL_BIRTH (bp : drgn .Object ) -> int :
175+ if sdb .get_type ('blkptr_t' ).has_member ('blk_physical_birth' ):
176+ return BF64_GET (bp .blk_physical_birth , 0 , 56 )
177+ return BF64_GET (bp .blk_phys_birth , 0 , 56 )
178+
179+
180+ def BP_GET_BIRTH (bp : drgn .Object ) -> int :
181+ if BP_IS_EMBEDDED (bp ):
182+ return 0
183+ if BP_PHYSICAL_BIRTH (bp ):
184+ return BP_PHYSICAL_BIRTH (bp )
185+ return BP_LOGICAL_BIRTH (bp )
186+
187+
188+ def BP_GET_FILL (bp : drgn .Object ) -> int :
189+ if BP_IS_ENCRYPTED (bp ):
190+ return BF64_GET (bp .blk_fill , 0 , 32 )
191+ if BP_IS_EMBEDDED (bp ):
192+ return 1
193+ return int (bp .blk_fill )
194+
195+
196+ def BP_GET_IV2 (bp : drgn .Object ) -> int :
197+ return BF64_GET (bp .blk_fill , 32 , 32 )
198+
199+
200+ def BP_IS_GANG (bp : drgn .Object ) -> bool :
201+ if BP_IS_EMBEDDED (bp ):
202+ return False
203+ return bool (BF64_GET (bp .blk_dva [0 ].dva_word [1 ], 63 , 1 ))
204+
205+
206+ def BP_IS_REDACTED (bp : drgn .Object ) -> bool :
207+ return (BP_IS_EMBEDDED (bp ) and
208+ BPE_GET_ETYPE (bp ) == BP_EMBEDDED_TYPE_REDACTED )
209+
210+
211+ def BP_IS_HOLE (bp : drgn .Object ) -> bool :
212+ return (not BP_IS_EMBEDDED (bp ) and DVA_IS_EMPTY (bp .blk_dva [0 ]))
213+
214+
215+ def BP_GET_NDVAS (bp : drgn .Object ) -> int :
216+ if BP_IS_EMBEDDED (bp ):
217+ return 0
218+ ndvas = 0
219+ for d in range (0 , 3 ):
220+ ndvas += DVA_GET_ASIZE (bp .blk_dva [d ]) != 0
221+ return ndvas
222+
223+
224+ def DVA_GET_ASIZE (dva : drgn .Object ) -> int :
225+ return BF64_GET_SB (dva .dva_word [0 ], 0 , SPA_ASIZEBITS , SPA_MINBLOCKSHIFT , 0 )
226+
227+
228+ def DVA_GET_VDEV (dva : drgn .Object ) -> int :
229+ return BF64_GET (dva .dva_word [0 ], 32 , SPA_VDEVBITS )
230+
231+
232+ def DVA_GET_OFFSET (dva : drgn .Object ) -> int :
233+ return BF64_GET_SB (dva .dva_word [1 ], 0 , 63 , SPA_MINBLOCKSHIFT , 0 )
234+
235+
236+ def DVA_IS_VALID (dva : drgn .Object ) -> bool :
237+ return DVA_GET_ASIZE (dva ) != 0
238+
239+
240+ def DVA_IS_EMPTY (dva : drgn .Object ) -> bool :
241+ return bool (dva .dva_word [0 ] == 0 and dva .dva_word [1 ] == 0 )
242+
243+
244+ def DMU_OT_IS_ENCRYPTED (ot : int ) -> bool :
245+ if ot & DMU_OT_NEWTYPE :
246+ return bool (ot & DMU_OT_ENCRYPTED )
247+ return bool (sdb .get_object ("dmu_ot" )[ot ].ot_encrypt )
248+
249+
250+ SPA_LSIZEBITS = 16
251+ SPA_PSIZEBITS = 16
252+ SPA_ASIZEBITS = 24
253+ SPA_COMPRESSBITS = 7
254+ SPA_VDEVBITS = 24
255+ SPA_MINBLOCKSHIFT = 9
256+
257+ ZIO_CHECKSUM_OFF = 2
258+
259+ DMU_OT_ENCRYPTED = 0x20
260+ DMU_OT_NEWTYPE = 0x80
261+
262+ BP_EMBEDDED_TYPE_DATA = 0
263+ BP_EMBEDDED_TYPE_RESERVED = 1
264+ BP_EMBEDDED_TYPE_REDACTED = 2
265+
84266METASLAB_WEIGHT_PRIMARY = int (1 << 63 )
85267METASLAB_WEIGHT_SECONDARY = int (1 << 62 )
86268METASLAB_WEIGHT_CLAIM = int (1 << 61 )
0 commit comments