MCPcopy Create free account
hub / github.com/F-Stack/f-stack / dnode_byteswap

Function dnode_byteswap

freebsd/contrib/openzfs/module/zfs/dnode.c:314–365  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

312#endif
313
314void
315dnode_byteswap(dnode_phys_t *dnp)
316{
317 uint64_t *buf64 = (void*)&dnp->dn_blkptr;
318 int i;
319
320 if (dnp->dn_type == DMU_OT_NONE) {
321 bzero(dnp, sizeof (dnode_phys_t));
322 return;
323 }
324
325 dnp->dn_datablkszsec = BSWAP_16(dnp->dn_datablkszsec);
326 dnp->dn_bonuslen = BSWAP_16(dnp->dn_bonuslen);
327 dnp->dn_extra_slots = BSWAP_8(dnp->dn_extra_slots);
328 dnp->dn_maxblkid = BSWAP_64(dnp->dn_maxblkid);
329 dnp->dn_used = BSWAP_64(dnp->dn_used);
330
331 /*
332 * dn_nblkptr is only one byte, so it's OK to read it in either
333 * byte order. We can't read dn_bouslen.
334 */
335 ASSERT(dnp->dn_indblkshift <= SPA_MAXBLOCKSHIFT);
336 ASSERT(dnp->dn_nblkptr <= DN_MAX_NBLKPTR);
337 for (i = 0; i < dnp->dn_nblkptr * sizeof (blkptr_t)/8; i++)
338 buf64[i] = BSWAP_64(buf64[i]);
339
340 /*
341 * OK to check dn_bonuslen for zero, because it won't matter if
342 * we have the wrong byte order. This is necessary because the
343 * dnode dnode is smaller than a regular dnode.
344 */
345 if (dnp->dn_bonuslen != 0) {
346 /*
347 * Note that the bonus length calculated here may be
348 * longer than the actual bonus buffer. This is because
349 * we always put the bonus buffer after the last block
350 * pointer (instead of packing it against the end of the
351 * dnode buffer).
352 */
353 int off = (dnp->dn_nblkptr-1) * sizeof (blkptr_t);
354 int slots = dnp->dn_extra_slots + 1;
355 size_t len = DN_SLOTS_TO_BONUSLEN(slots) - off;
356 dmu_object_byteswap_t byteswap;
357 ASSERT(DMU_OT_IS_VALID(dnp->dn_bonustype));
358 byteswap = DMU_OT_BYTESWAP(dnp->dn_bonustype);
359 dmu_ot_byteswap[byteswap].ob_func(dnp->dn_bonus + off, len);
360 }
361
362 /* Swap SPILL block if we have one */
363 if (dnp->dn_flags & DNODE_FLAG_SPILL_BLKPTR)
364 byteswap_uint64_array(DN_SPILL_BLKPTR(dnp), sizeof (blkptr_t));
365}
366
367void
368dnode_buf_byteswap(void *vbuf, size_t size)

Callers 2

dnode_buf_byteswapFunction · 0.85
dmu_objset_byteswapFunction · 0.85

Calls 2

bzeroFunction · 0.85
byteswap_uint64_arrayFunction · 0.85

Tested by

no test coverage detected