zap_leaf.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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 2007 Sun Microsystems, Inc. All rights reserved.
  8. * Use is subject to license terms.
  9. */
  10. #ifndef _SYS_ZAP_LEAF_H
  11. #define _SYS_ZAP_LEAF_H
  12. #define ZAP_LEAF_MAGIC 0x2AB1EAF
  13. /* chunk size = 24 bytes */
  14. #define ZAP_LEAF_CHUNKSIZE 24
  15. /*
  16. * The amount of space within the chunk available for the array is:
  17. * chunk size - space for type (1) - space for next pointer (2)
  18. */
  19. #define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3)
  20. typedef enum zap_chunk_type {
  21. ZAP_CHUNK_FREE = 253,
  22. ZAP_CHUNK_ENTRY = 252,
  23. ZAP_CHUNK_ARRAY = 251,
  24. ZAP_CHUNK_TYPE_MAX = 250
  25. } zap_chunk_type_t;
  26. /*
  27. * TAKE NOTE:
  28. * If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified.
  29. */
  30. typedef struct zap_leaf_phys {
  31. struct zap_leaf_header {
  32. uint64_t lh_block_type; /* ZBT_LEAF */
  33. uint64_t lh_pad1;
  34. uint64_t lh_prefix; /* hash prefix of this leaf */
  35. uint32_t lh_magic; /* ZAP_LEAF_MAGIC */
  36. uint16_t lh_nfree; /* number free chunks */
  37. uint16_t lh_nentries; /* number of entries */
  38. uint16_t lh_prefix_len; /* num bits used to id this */
  39. /* above is accessable to zap, below is zap_leaf private */
  40. uint16_t lh_freelist; /* chunk head of free list */
  41. uint8_t lh_pad2[12];
  42. } l_hdr; /* 2 24-byte chunks */
  43. /*
  44. * The header is followed by a hash table with
  45. * ZAP_LEAF_HASH_NUMENTRIES(zap) entries. The hash table is
  46. * followed by an array of ZAP_LEAF_NUMCHUNKS(zap)
  47. * zap_leaf_chunk structures. These structures are accessed
  48. * with the ZAP_LEAF_CHUNK() macro.
  49. */
  50. uint16_t l_hash[1];
  51. } zap_leaf_phys_t;
  52. typedef union zap_leaf_chunk {
  53. struct zap_leaf_entry {
  54. uint8_t le_type; /* always ZAP_CHUNK_ENTRY */
  55. uint8_t le_int_size; /* size of ints */
  56. uint16_t le_next; /* next entry in hash chain */
  57. uint16_t le_name_chunk; /* first chunk of the name */
  58. uint16_t le_name_length; /* bytes in name, incl null */
  59. uint16_t le_value_chunk; /* first chunk of the value */
  60. uint16_t le_value_length; /* value length in ints */
  61. uint32_t le_cd; /* collision differentiator */
  62. uint64_t le_hash; /* hash value of the name */
  63. } l_entry;
  64. struct zap_leaf_array {
  65. uint8_t la_type; /* always ZAP_CHUNK_ARRAY */
  66. union {
  67. uint8_t la_array[ZAP_LEAF_ARRAY_BYTES];
  68. uint64_t la_array64;
  69. } __attribute__ ((packed));
  70. uint16_t la_next; /* next blk or CHAIN_END */
  71. } l_array;
  72. struct zap_leaf_free {
  73. uint8_t lf_type; /* always ZAP_CHUNK_FREE */
  74. uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES];
  75. uint16_t lf_next; /* next in free list, or CHAIN_END */
  76. } l_free;
  77. } zap_leaf_chunk_t;
  78. #endif /* _SYS_ZAP_LEAF_H */