| 1 | /*
|
|---|
| 2 | * Copyright (c) 2011 Frantisek Princ
|
|---|
| 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 | *
|
|---|
| 9 | * - Redistributions of source code must retain the above copyright
|
|---|
| 10 | * notice, this list of conditions and the following disclaimer.
|
|---|
| 11 | * - Redistributions in binary form must reproduce the above copyright
|
|---|
| 12 | * notice, this list of conditions and the following disclaimer in the
|
|---|
| 13 | * documentation and/or other materials provided with the distribution.
|
|---|
| 14 | * - The name of the author may not be used to endorse or promote products
|
|---|
| 15 | * derived from this software without specific prior written permission.
|
|---|
| 16 | *
|
|---|
| 17 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
|---|
| 18 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|---|
| 19 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|---|
| 20 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|---|
| 21 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|---|
| 22 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|---|
| 23 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|---|
| 24 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|---|
| 25 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|---|
| 26 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | /** @addtogroup libext4
|
|---|
| 30 | * @{
|
|---|
| 31 | */
|
|---|
| 32 |
|
|---|
| 33 | #ifndef LIBEXT4_LIBEXT4_EXTENT_H_
|
|---|
| 34 | #define LIBEXT4_LIBEXT4_EXTENT_H_
|
|---|
| 35 |
|
|---|
| 36 | /*
|
|---|
| 37 | * This is the extent on-disk structure.
|
|---|
| 38 | * It's used at the bottom of the tree.
|
|---|
| 39 | */
|
|---|
| 40 | typedef struct ext4_extent {
|
|---|
| 41 | uint32_t first_block; // First logical block extent covers
|
|---|
| 42 | uint16_t block_count; // Number of blocks covered by extent
|
|---|
| 43 | uint16_t start_hi; // High 16 bits of physical block
|
|---|
| 44 | uint32_t start_lo; // Low 32 bits of physical block
|
|---|
| 45 | } ext4_extent_t;
|
|---|
| 46 |
|
|---|
| 47 | /*
|
|---|
| 48 | * This is index on-disk structure.
|
|---|
| 49 | * It's used at all the levels except the bottom.
|
|---|
| 50 | */
|
|---|
| 51 | typedef struct ext4_extent_index {
|
|---|
| 52 | uint32_t first_block; // Index covers logical blocks from 'block'
|
|---|
| 53 | uint32_t leaf_lo; /* Pointer to the physical block of the next
|
|---|
| 54 | * level. leaf or next index could be there */
|
|---|
| 55 | uint16_t leaf_hi; /* high 16 bits of physical block */
|
|---|
| 56 | uint16_t padding;
|
|---|
| 57 | } ext4_extent_index_t;
|
|---|
| 58 |
|
|---|
| 59 | /*
|
|---|
| 60 | * Each block (leaves and indexes), even inode-stored has header.
|
|---|
| 61 | */
|
|---|
| 62 | typedef struct ext4_extent_header {
|
|---|
| 63 | uint16_t magic;
|
|---|
| 64 | uint16_t entries_count; // Number of valid entries
|
|---|
| 65 | uint16_t max_entries_count; // Capacity of store in entries
|
|---|
| 66 | uint16_t depth; // Has tree real underlying blocks?
|
|---|
| 67 | uint32_t generation; // generation of the tree
|
|---|
| 68 | } ext4_extent_header_t;
|
|---|
| 69 |
|
|---|
| 70 | #define EXT4_EXTENT_MAGIC 0xF30A
|
|---|
| 71 | #define EXT4_EXTENT_FIRST(header) \
|
|---|
| 72 | ((ext4_extent_t *) (((void *) (header)) + sizeof(ext4_extent_header_t)))
|
|---|
| 73 | #define EXT4_EXTENT_FIRST_INDEX(header) \
|
|---|
| 74 | ((ext4_extent_index_t *) (((void *) (header)) + sizeof(ext4_extent_header_t)))
|
|---|
| 75 |
|
|---|
| 76 | extern uint32_t ext4_extent_get_first_block(ext4_extent_t *);
|
|---|
| 77 | extern void ext4_extent_set_first_block(ext4_extent_t *, uint32_t);
|
|---|
| 78 | extern uint16_t ext4_extent_get_block_count(ext4_extent_t *);
|
|---|
| 79 | extern void ext4_extent_set_block_count(ext4_extent_t *, uint16_t);
|
|---|
| 80 | extern uint64_t ext4_extent_get_start(ext4_extent_t *);
|
|---|
| 81 | extern void ext4_extent_set_start(ext4_extent_t *, uint64_t);
|
|---|
| 82 |
|
|---|
| 83 | extern uint32_t ext4_extent_index_get_first_block(ext4_extent_index_t *);
|
|---|
| 84 | extern void ext4_extent_index_set_first_block(ext4_extent_index_t *, uint32_t);
|
|---|
| 85 | extern uint64_t ext4_extent_index_get_leaf(ext4_extent_index_t *);
|
|---|
| 86 | extern void ext4_extent_index_set_leaf(ext4_extent_index_t *, uint64_t);
|
|---|
| 87 |
|
|---|
| 88 | extern uint16_t ext4_extent_header_get_magic(ext4_extent_header_t *);
|
|---|
| 89 | extern void ext4_extent_header_set_magic(ext4_extent_header_t *, uint16_t);
|
|---|
| 90 | extern uint16_t ext4_extent_header_get_entries_count(ext4_extent_header_t *);
|
|---|
| 91 | extern void ext4_extent_header_set_entries_count(ext4_extent_header_t *,
|
|---|
| 92 | uint16_t);
|
|---|
| 93 | extern uint16_t ext4_extent_header_get_max_entries_count(ext4_extent_header_t *);
|
|---|
| 94 | extern void ext4_extent_header_set_max_entries_count(ext4_extent_header_t *,
|
|---|
| 95 | uint16_t);
|
|---|
| 96 | extern uint16_t ext4_extent_header_get_depth(ext4_extent_header_t *);
|
|---|
| 97 | extern void ext4_extent_header_set_depth(ext4_extent_header_t *, uint16_t);
|
|---|
| 98 | extern uint32_t ext4_extent_header_get_generation(ext4_extent_header_t *);
|
|---|
| 99 | extern void ext4_extent_header_set_generation(ext4_extent_header_t *, uint32_t);
|
|---|
| 100 |
|
|---|
| 101 | #endif
|
|---|
| 102 |
|
|---|
| 103 | /**
|
|---|
| 104 | * @}
|
|---|
| 105 | */
|
|---|