191f5a467SPedro F. Giffuni /*- 2*4d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause 3d63027b6SPedro F. Giffuni * 491f5a467SPedro F. Giffuni * Copyright (c) 2010, 2012 Zheng Liu <lz@freebsd.org> 591f5a467SPedro F. Giffuni * Copyright (c) 2012, Vyacheslav Matyushin 691f5a467SPedro F. Giffuni * All rights reserved. 791f5a467SPedro F. Giffuni * 891f5a467SPedro F. Giffuni * Redistribution and use in source and binary forms, with or without 991f5a467SPedro F. Giffuni * modification, are permitted provided that the following conditions 1091f5a467SPedro F. Giffuni * are met: 1191f5a467SPedro F. Giffuni * 1. Redistributions of source code must retain the above copyright 1291f5a467SPedro F. Giffuni * notice, this list of conditions and the following disclaimer. 1391f5a467SPedro F. Giffuni * 2. Redistributions in binary form must reproduce the above copyright 1491f5a467SPedro F. Giffuni * notice, this list of conditions and the following disclaimer in the 1591f5a467SPedro F. Giffuni * documentation and/or other materials provided with the distribution. 1691f5a467SPedro F. Giffuni * 1791f5a467SPedro F. Giffuni * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1891f5a467SPedro F. Giffuni * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1991f5a467SPedro F. Giffuni * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2091f5a467SPedro F. Giffuni * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2191f5a467SPedro F. Giffuni * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2291f5a467SPedro F. Giffuni * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2391f5a467SPedro F. Giffuni * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2491f5a467SPedro F. Giffuni * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2591f5a467SPedro F. Giffuni * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2691f5a467SPedro F. Giffuni * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2791f5a467SPedro F. Giffuni * SUCH DAMAGE. 2891f5a467SPedro F. Giffuni */ 2991f5a467SPedro F. Giffuni 3091f5a467SPedro F. Giffuni #ifndef _FS_EXT2FS_HTREE_H_ 3191f5a467SPedro F. Giffuni #define _FS_EXT2FS_HTREE_H_ 3291f5a467SPedro F. Giffuni 3391f5a467SPedro F. Giffuni /* EXT3 HTree directory indexing */ 3491f5a467SPedro F. Giffuni 3591f5a467SPedro F. Giffuni #define EXT2_HTREE_LEGACY 0 3691f5a467SPedro F. Giffuni #define EXT2_HTREE_HALF_MD4 1 3791f5a467SPedro F. Giffuni #define EXT2_HTREE_TEA 2 3891f5a467SPedro F. Giffuni #define EXT2_HTREE_LEGACY_UNSIGNED 3 3991f5a467SPedro F. Giffuni #define EXT2_HTREE_HALF_MD4_UNSIGNED 4 4091f5a467SPedro F. Giffuni #define EXT2_HTREE_TEA_UNSIGNED 5 4191f5a467SPedro F. Giffuni 4291f5a467SPedro F. Giffuni #define EXT2_HTREE_EOF 0x7FFFFFFF 4391f5a467SPedro F. Giffuni 4491f5a467SPedro F. Giffuni struct ext2fs_fake_direct { 4591f5a467SPedro F. Giffuni uint32_t e2d_ino; /* inode number of entry */ 4691f5a467SPedro F. Giffuni uint16_t e2d_reclen; /* length of this record */ 4791f5a467SPedro F. Giffuni uint8_t e2d_namlen; /* length of string in d_name */ 4891f5a467SPedro F. Giffuni uint8_t e2d_type; /* file type */ 4991f5a467SPedro F. Giffuni }; 5091f5a467SPedro F. Giffuni 5191f5a467SPedro F. Giffuni struct ext2fs_htree_count { 5291f5a467SPedro F. Giffuni uint16_t h_entries_max; 5391f5a467SPedro F. Giffuni uint16_t h_entries_num; 5491f5a467SPedro F. Giffuni }; 5591f5a467SPedro F. Giffuni 5691f5a467SPedro F. Giffuni struct ext2fs_htree_entry { 5791f5a467SPedro F. Giffuni uint32_t h_hash; 5891f5a467SPedro F. Giffuni uint32_t h_blk; 5991f5a467SPedro F. Giffuni }; 6091f5a467SPedro F. Giffuni 61512f29d1SFedor Uporov /* 62512f29d1SFedor Uporov * This goes at the end of each htree block. 63512f29d1SFedor Uporov */ 64512f29d1SFedor Uporov struct ext2fs_htree_tail { 65512f29d1SFedor Uporov uint32_t ht_reserved; 66512f29d1SFedor Uporov uint32_t ht_checksum; /* crc32c(uuid+inum+dirblock) */ 67512f29d1SFedor Uporov }; 68512f29d1SFedor Uporov 6991f5a467SPedro F. Giffuni struct ext2fs_htree_root_info { 7091f5a467SPedro F. Giffuni uint32_t h_reserved1; 7191f5a467SPedro F. Giffuni uint8_t h_hash_version; 7291f5a467SPedro F. Giffuni uint8_t h_info_len; 7391f5a467SPedro F. Giffuni uint8_t h_ind_levels; 7491f5a467SPedro F. Giffuni uint8_t h_reserved2; 7591f5a467SPedro F. Giffuni }; 7691f5a467SPedro F. Giffuni 7791f5a467SPedro F. Giffuni struct ext2fs_htree_root { 7891f5a467SPedro F. Giffuni struct ext2fs_fake_direct h_dot; 7991f5a467SPedro F. Giffuni char h_dot_name[4]; 8091f5a467SPedro F. Giffuni struct ext2fs_fake_direct h_dotdot; 8191f5a467SPedro F. Giffuni char h_dotdot_name[4]; 8291f5a467SPedro F. Giffuni struct ext2fs_htree_root_info h_info; 8391f5a467SPedro F. Giffuni struct ext2fs_htree_entry h_entries[0]; 8491f5a467SPedro F. Giffuni }; 8591f5a467SPedro F. Giffuni 8691f5a467SPedro F. Giffuni struct ext2fs_htree_node { 8791f5a467SPedro F. Giffuni struct ext2fs_fake_direct h_fake_dirent; 8891f5a467SPedro F. Giffuni struct ext2fs_htree_entry h_entries[0]; 8991f5a467SPedro F. Giffuni }; 9091f5a467SPedro F. Giffuni 9191f5a467SPedro F. Giffuni struct ext2fs_htree_lookup_level { 9291f5a467SPedro F. Giffuni struct buf *h_bp; 9391f5a467SPedro F. Giffuni struct ext2fs_htree_entry *h_entries; 9491f5a467SPedro F. Giffuni struct ext2fs_htree_entry *h_entry; 9591f5a467SPedro F. Giffuni }; 9691f5a467SPedro F. Giffuni 9791f5a467SPedro F. Giffuni struct ext2fs_htree_lookup_info { 9891f5a467SPedro F. Giffuni struct ext2fs_htree_lookup_level h_levels[2]; 9991f5a467SPedro F. Giffuni uint32_t h_levels_num; 10091f5a467SPedro F. Giffuni }; 10191f5a467SPedro F. Giffuni 10291f5a467SPedro F. Giffuni struct ext2fs_htree_sort_entry { 10391f5a467SPedro F. Giffuni uint16_t h_offset; 10491f5a467SPedro F. Giffuni uint16_t h_size; 10591f5a467SPedro F. Giffuni uint32_t h_hash; 10691f5a467SPedro F. Giffuni }; 10791f5a467SPedro F. Giffuni 10891f5a467SPedro F. Giffuni #endif /* !_FS_EXT2FS_HTREE_H_ */ 109