@@ -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,188 @@ 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 BP_IS_EMBEDDED (bp ):
164+ if sdb .get_type ('blkptr_t' ).has_member ('blk_logical_birth' ):
165+ return BF64_GET (bp .blk_logical_birth , 56 , 8 )
166+ return BF64_GET (bp .blk_birth , 56 , 8 )
167+ if sdb .get_type ('blkptr_t' ).has_member ('blk_physical_birth' ):
168+ return BF64_GET (bp .blk_physical_birth , 56 , 8 )
169+ return BF64_GET (bp .blk_phys_birth , 56 , 8 )
170+
171+
172+ def BP_LOGICAL_BIRTH (bp : drgn .Object ) -> int :
173+ if sdb .get_type ('blkptr_t' ).has_member ('blk_logical_birth' ):
174+ return BF64_GET (bp .blk_logical_birth , 0 , 56 )
175+ return BF64_GET (bp .blk_birth , 0 , 56 )
176+
177+
178+ def BP_PHYSICAL_BIRTH (bp : drgn .Object ) -> int :
179+ if sdb .get_type ('blkptr_t' ).has_member ('blk_physical_birth' ):
180+ return BF64_GET (bp .blk_physical_birth , 0 , 56 )
181+ return BF64_GET (bp .blk_phys_birth , 0 , 56 )
182+
183+
184+ def BP_GET_BIRTH (bp : drgn .Object ) -> int :
185+ if BP_IS_EMBEDDED (bp ):
186+ return 0
187+ if BP_PHYSICAL_BIRTH (bp ):
188+ return BP_PHYSICAL_BIRTH (bp )
189+ return BP_LOGICAL_BIRTH (bp )
190+
191+
192+ def BP_GET_FILL (bp : drgn .Object ) -> int :
193+ if BP_IS_ENCRYPTED (bp ):
194+ return BF64_GET (bp .blk_fill , 0 , 32 )
195+ if BP_IS_EMBEDDED (bp ):
196+ return 1
197+ return int (bp .blk_fill )
198+
199+
200+ def BP_GET_IV2 (bp : drgn .Object ) -> int :
201+ return BF64_GET (bp .blk_fill , 32 , 32 )
202+
203+
204+ def BP_IS_GANG (bp : drgn .Object ) -> bool :
205+ if BP_IS_EMBEDDED (bp ):
206+ return False
207+ return bool (BF64_GET (bp .blk_dva [0 ].dva_word [1 ], 63 , 1 ))
208+
209+
210+ def BP_IS_REDACTED (bp : drgn .Object ) -> bool :
211+ return (BP_IS_EMBEDDED (bp ) and
212+ BPE_GET_ETYPE (bp ) == BP_EMBEDDED_TYPE_REDACTED )
213+
214+
215+ def BP_IS_HOLE (bp : drgn .Object ) -> bool :
216+ return (not BP_IS_EMBEDDED (bp ) and DVA_IS_EMPTY (bp .blk_dva [0 ]))
217+
218+
219+ def BP_GET_NDVAS (bp : drgn .Object ) -> int :
220+ if BP_IS_EMBEDDED (bp ):
221+ return 0
222+ ndvas = 0
223+ for d in range (0 , 3 ):
224+ ndvas += DVA_GET_ASIZE (bp .blk_dva [d ]) != 0
225+ return ndvas
226+
227+
228+ def DVA_GET_ASIZE (dva : drgn .Object ) -> int :
229+ return BF64_GET_SB (dva .dva_word [0 ], 0 , SPA_ASIZEBITS , SPA_MINBLOCKSHIFT , 0 )
230+
231+
232+ def DVA_GET_VDEV (dva : drgn .Object ) -> int :
233+ return BF64_GET (dva .dva_word [0 ], 32 , SPA_VDEVBITS )
234+
235+
236+ def DVA_GET_OFFSET (dva : drgn .Object ) -> int :
237+ return BF64_GET_SB (dva .dva_word [1 ], 0 , 63 , SPA_MINBLOCKSHIFT , 0 )
238+
239+
240+ def DVA_IS_VALID (dva : drgn .Object ) -> bool :
241+ return DVA_GET_ASIZE (dva ) != 0
242+
243+
244+ def DVA_IS_EMPTY (dva : drgn .Object ) -> bool :
245+ return bool (dva .dva_word [0 ] == 0 and dva .dva_word [1 ] == 0 )
246+
247+
248+ def DMU_OT_IS_ENCRYPTED (ot : int ) -> bool :
249+ if ot & DMU_OT_NEWTYPE :
250+ return bool (ot & DMU_OT_ENCRYPTED )
251+ return bool (sdb .get_object ("dmu_ot" )[ot ].ot_encrypt )
252+
253+
254+ SPA_LSIZEBITS = 16
255+ SPA_PSIZEBITS = 16
256+ SPA_ASIZEBITS = 24
257+ SPA_COMPRESSBITS = 7
258+ SPA_VDEVBITS = 24
259+ SPA_MINBLOCKSHIFT = 9
260+
261+ ZIO_CHECKSUM_OFF = 2
262+
263+ DMU_OT_ENCRYPTED = 0x20
264+ DMU_OT_NEWTYPE = 0x80
265+
266+ BP_EMBEDDED_TYPE_DATA = 0
267+ BP_EMBEDDED_TYPE_RESERVED = 1
268+ BP_EMBEDDED_TYPE_REDACTED = 2
269+
84270METASLAB_WEIGHT_PRIMARY = int (1 << 63 )
85271METASLAB_WEIGHT_SECONDARY = int (1 << 62 )
86272METASLAB_WEIGHT_CLAIM = int (1 << 61 )
0 commit comments