zap_leaf.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * GRUB -- GRand Unified Bootloader
  3. * Copyright (C) 1999,2000,2001,2002,2003,2004 Free Software Foundation, Inc.
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. /*
  20. * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
  21. * Use is subject to license terms.
  22. */
  23. #ifndef _SYS_ZAP_LEAF_H
  24. #define _SYS_ZAP_LEAF_H
  25. #define ZAP_LEAF_MAGIC 0x2AB1EAF
  26. /* chunk size = 24 bytes */
  27. #define ZAP_LEAF_CHUNKSIZE 24
  28. /*
  29. * The amount of space within the chunk available for the array is:
  30. * chunk size - space for type (1) - space for next pointer (2)
  31. */
  32. #define ZAP_LEAF_ARRAY_BYTES (ZAP_LEAF_CHUNKSIZE - 3)
  33. typedef enum zap_chunk_type {
  34. ZAP_CHUNK_FREE = 253,
  35. ZAP_CHUNK_ENTRY = 252,
  36. ZAP_CHUNK_ARRAY = 251,
  37. ZAP_CHUNK_TYPE_MAX = 250
  38. } zap_chunk_type_t;
  39. /*
  40. * TAKE NOTE:
  41. * If zap_leaf_phys_t is modified, zap_leaf_byteswap() must be modified.
  42. */
  43. typedef struct zap_leaf_phys {
  44. struct zap_leaf_header {
  45. uint64_t lh_block_type; /* ZBT_LEAF */
  46. uint64_t lh_pad1;
  47. uint64_t lh_prefix; /* hash prefix of this leaf */
  48. uint32_t lh_magic; /* ZAP_LEAF_MAGIC */
  49. uint16_t lh_nfree; /* number free chunks */
  50. uint16_t lh_nentries; /* number of entries */
  51. uint16_t lh_prefix_len; /* num bits used to id this */
  52. /* above is accessable to zap, below is zap_leaf private */
  53. uint16_t lh_freelist; /* chunk head of free list */
  54. uint8_t lh_pad2[12];
  55. } l_hdr; /* 2 24-byte chunks */
  56. /*
  57. * The header is followed by a hash table with
  58. * ZAP_LEAF_HASH_NUMENTRIES(zap) entries. The hash table is
  59. * followed by an array of ZAP_LEAF_NUMCHUNKS(zap)
  60. * zap_leaf_chunk structures. These structures are accessed
  61. * with the ZAP_LEAF_CHUNK() macro.
  62. */
  63. uint16_t l_hash[1];
  64. } zap_leaf_phys_t;
  65. typedef union zap_leaf_chunk {
  66. struct zap_leaf_entry {
  67. uint8_t le_type; /* always ZAP_CHUNK_ENTRY */
  68. uint8_t le_int_size; /* size of ints */
  69. uint16_t le_next; /* next entry in hash chain */
  70. uint16_t le_name_chunk; /* first chunk of the name */
  71. uint16_t le_name_length; /* bytes in name, incl null */
  72. uint16_t le_value_chunk; /* first chunk of the value */
  73. uint16_t le_value_length; /* value length in ints */
  74. uint32_t le_cd; /* collision differentiator */
  75. uint64_t le_hash; /* hash value of the name */
  76. } l_entry;
  77. struct zap_leaf_array {
  78. uint8_t la_type; /* always ZAP_CHUNK_ARRAY */
  79. union {
  80. uint8_t la_array[ZAP_LEAF_ARRAY_BYTES];
  81. uint64_t la_array64;
  82. } __attribute__ ((packed));
  83. uint16_t la_next; /* next blk or CHAIN_END */
  84. } l_array;
  85. struct zap_leaf_free {
  86. uint8_t lf_type; /* always ZAP_CHUNK_FREE */
  87. uint8_t lf_pad[ZAP_LEAF_ARRAY_BYTES];
  88. uint16_t lf_next; /* next in free list, or CHAIN_END */
  89. } l_free;
  90. } zap_leaf_chunk_t;
  91. #endif /* _SYS_ZAP_LEAF_H */