ext2fs_extents.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*-
  2. * Copyright (c) 2012, 2010 Zheng Liu <lz@freebsd.org>
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms, with or without
  6. * modification, are permitted provided that the following conditions
  7. * are met:
  8. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. *
  14. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  15. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  16. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  17. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  18. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  19. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  20. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  21. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  22. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  23. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  24. * SUCH DAMAGE.
  25. *
  26. * $FreeBSD: head/sys/fs/ext2fs/ext2_extents.h 262623 2014-02-28 21:25:32Z pfg $
  27. */
  28. #ifndef _FS_EXT2FS_EXT2_EXTENTS_H_
  29. #define _FS_EXT2FS_EXT2_EXTENTS_H_
  30. #include <sys/types.h>
  31. #define EXT4_EXT_MAGIC 0xf30a
  32. #define EXT4_EXT_CACHE_NO 0
  33. #define EXT4_EXT_CACHE_GAP 1
  34. #define EXT4_EXT_CACHE_IN 2
  35. /*
  36. * Ext4 file system extent on disk.
  37. */
  38. struct ext4_extent {
  39. uint32_t e_blk; /* first logical block */
  40. uint16_t e_len; /* number of blocks */
  41. uint16_t e_start_hi; /* high 16 bits of physical block */
  42. uint32_t e_start_lo; /* low 32 bits of physical block */
  43. };
  44. /*
  45. * Extent index on disk.
  46. */
  47. struct ext4_extent_index {
  48. uint32_t ei_blk; /* indexes logical blocks */
  49. uint32_t ei_leaf_lo; /* points to physical block of the
  50. * next level */
  51. uint16_t ei_leaf_hi; /* high 16 bits of physical block */
  52. uint16_t ei_unused;
  53. };
  54. /*
  55. * Extent tree header.
  56. */
  57. struct ext4_extent_header {
  58. uint16_t eh_magic; /* magic number: 0xf30a */
  59. uint16_t eh_ecount; /* number of valid entries */
  60. uint16_t eh_max; /* capacity of store in entries */
  61. uint16_t eh_depth; /* the depth of extent tree */
  62. uint32_t eh_gen; /* generation of extent tree */
  63. };
  64. /*
  65. * Save cached extent.
  66. */
  67. struct ext4_extent_cache {
  68. daddr_t ec_start; /* extent start */
  69. uint32_t ec_blk; /* logical block */
  70. uint32_t ec_len;
  71. uint32_t ec_type;
  72. };
  73. /*
  74. * Save path to some extent.
  75. */
  76. struct ext4_extent_path {
  77. uint16_t ep_depth;
  78. struct buf *ep_bp;
  79. struct ext4_extent *ep_ext;
  80. struct ext4_extent_index *ep_index;
  81. struct ext4_extent_header *ep_header;
  82. };
  83. struct inode;
  84. struct m_ext2fs;
  85. int ext4_ext_in_cache(struct inode *, daddr_t, struct ext4_extent *);
  86. void ext4_ext_put_cache(struct inode *, struct ext4_extent *, int);
  87. struct ext4_extent_path *ext4_ext_find_extent(struct m_ext2fs *fs,
  88. struct inode *, daddr_t, struct ext4_extent_path *);
  89. #endif /* !_FS_EXT2FS_EXT2_EXTENTS_H_ */