dnode.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* SPDX-License-Identifier: GPL-2.0+ */
  2. /*
  3. * GRUB -- GRand Unified Bootloader
  4. * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
  5. */
  6. /*
  7. * Copyright 2010 Sun Microsystems, Inc. All rights reserved.
  8. * Use is subject to license terms.
  9. */
  10. #ifndef _SYS_DNODE_H
  11. #define _SYS_DNODE_H
  12. #include <zfs/spa.h>
  13. /*
  14. * Fixed constants.
  15. */
  16. #define DNODE_SHIFT 9 /* 512 bytes */
  17. #define DN_MIN_INDBLKSHIFT 10 /* 1k */
  18. #define DN_MAX_INDBLKSHIFT 14 /* 16k */
  19. #define DNODE_BLOCK_SHIFT 14 /* 16k */
  20. #define DNODE_CORE_SIZE 64 /* 64 bytes for dnode sans blkptrs */
  21. #define DN_MAX_OBJECT_SHIFT 48 /* 256 trillion (zfs_fid_t limit) */
  22. #define DN_MAX_OFFSET_SHIFT 64 /* 2^64 bytes in a dnode */
  23. /*
  24. * Derived constants.
  25. */
  26. #define DNODE_SIZE (1 << DNODE_SHIFT)
  27. #define DN_MAX_NBLKPTR ((DNODE_SIZE - DNODE_CORE_SIZE) >> SPA_BLKPTRSHIFT)
  28. #define DN_MAX_BONUSLEN (DNODE_SIZE - DNODE_CORE_SIZE - (1 << SPA_BLKPTRSHIFT))
  29. #define DN_MAX_OBJECT (1ULL << DN_MAX_OBJECT_SHIFT)
  30. #define DNODES_PER_BLOCK_SHIFT (DNODE_BLOCK_SHIFT - DNODE_SHIFT)
  31. #define DNODES_PER_BLOCK (1ULL << DNODES_PER_BLOCK_SHIFT)
  32. #define DNODES_PER_LEVEL_SHIFT (DN_MAX_INDBLKSHIFT - SPA_BLKPTRSHIFT)
  33. #define DNODE_FLAG_SPILL_BLKPTR (1<<2)
  34. #define DN_BONUS(dnp) ((void *)((dnp)->dn_bonus + \
  35. (((dnp)->dn_nblkptr - 1) * sizeof(blkptr_t))))
  36. typedef struct dnode_phys {
  37. uint8_t dn_type; /* dmu_object_type_t */
  38. uint8_t dn_indblkshift; /* ln2(indirect block size) */
  39. uint8_t dn_nlevels; /* 1=dn_blkptr->data blocks */
  40. uint8_t dn_nblkptr; /* length of dn_blkptr */
  41. uint8_t dn_bonustype; /* type of data in bonus buffer */
  42. uint8_t dn_checksum; /* ZIO_CHECKSUM type */
  43. uint8_t dn_compress; /* ZIO_COMPRESS type */
  44. uint8_t dn_flags; /* DNODE_FLAG_* */
  45. uint16_t dn_datablkszsec; /* data block size in 512b sectors */
  46. uint16_t dn_bonuslen; /* length of dn_bonus */
  47. uint8_t dn_pad2[4];
  48. /* accounting is protected by dn_dirty_mtx */
  49. uint64_t dn_maxblkid; /* largest allocated block ID */
  50. uint64_t dn_used; /* bytes (or sectors) of disk space */
  51. uint64_t dn_pad3[4];
  52. blkptr_t dn_blkptr[1];
  53. uint8_t dn_bonus[DN_MAX_BONUSLEN - sizeof(blkptr_t)];
  54. blkptr_t dn_spill;
  55. } dnode_phys_t;
  56. #endif /* _SYS_DNODE_H */