| 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 | /**
|
|---|
| 34 | * @file libext4_extent.c
|
|---|
| 35 | * @brief Ext4 extent structures operations.
|
|---|
| 36 | */
|
|---|
| 37 |
|
|---|
| 38 | #include <byteorder.h>
|
|---|
| 39 | #include "libext4_extent.h"
|
|---|
| 40 |
|
|---|
| 41 | uint32_t ext4_extent_get_first_block(ext4_extent_t *extent)
|
|---|
| 42 | {
|
|---|
| 43 | return uint32_t_le2host(extent->first_block);
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | void ext4_extent_set_first_block(ext4_extent_t *extent, uint32_t first_block)
|
|---|
| 47 | {
|
|---|
| 48 | extent->first_block = host2uint32_t_le(first_block);
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | uint16_t ext4_extent_get_block_count(ext4_extent_t *extent)
|
|---|
| 52 | {
|
|---|
| 53 | return uint16_t_le2host(extent->block_count);
|
|---|
| 54 | }
|
|---|
| 55 |
|
|---|
| 56 | void ext4_extent_set_block_count(ext4_extent_t *extent, uint16_t block_count)
|
|---|
| 57 | {
|
|---|
| 58 | extent->block_count = host2uint16_t_le(block_count);
|
|---|
| 59 | }
|
|---|
| 60 |
|
|---|
| 61 | uint64_t ext4_extent_get_start(ext4_extent_t *extent)
|
|---|
| 62 | {
|
|---|
| 63 | return ((uint64_t)uint16_t_le2host(extent->start_hi)) << 32 |
|
|---|
| 64 | ((uint64_t)uint32_t_le2host(extent->start_lo));
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | void ext4_extent_set_start(ext4_extent_t *extent, uint64_t start)
|
|---|
| 68 | {
|
|---|
| 69 | extent->start_lo = host2uint32_t_le((start << 32) >> 32);
|
|---|
| 70 | extent->start_hi = host2uint16_t_le((uint16_t)(start >> 32));
|
|---|
| 71 | }
|
|---|
| 72 |
|
|---|
| 73 | uint32_t ext4_extent_index_get_first_block(ext4_extent_index_t *index)
|
|---|
| 74 | {
|
|---|
| 75 | return uint32_t_le2host(index->first_block);
|
|---|
| 76 | }
|
|---|
| 77 |
|
|---|
| 78 | void ext4_extent_index_set_first_block(ext4_extent_index_t *index,
|
|---|
| 79 | uint32_t first)
|
|---|
| 80 | {
|
|---|
| 81 | index->first_block = host2uint32_t_le(first);
|
|---|
| 82 | }
|
|---|
| 83 |
|
|---|
| 84 | uint64_t ext4_extent_index_get_leaf(ext4_extent_index_t *index)
|
|---|
| 85 | {
|
|---|
| 86 | return ((uint64_t)uint16_t_le2host(index->leaf_hi)) << 32 |
|
|---|
| 87 | ((uint64_t)uint32_t_le2host(index->leaf_lo));
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | void ext4_extent_index_set_leaf(ext4_extent_index_t *index, uint64_t leaf)
|
|---|
| 91 | {
|
|---|
| 92 | index->leaf_lo = host2uint32_t_le((leaf << 32) >> 32);
|
|---|
| 93 | index->leaf_hi = host2uint16_t_le((uint16_t)(leaf >> 32));
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | uint16_t ext4_extent_header_get_magic(ext4_extent_header_t *header)
|
|---|
| 97 | {
|
|---|
| 98 | return uint16_t_le2host(header->magic);
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | void ext4_extent_header_set_magic(ext4_extent_header_t *header, uint16_t magic)
|
|---|
| 102 | {
|
|---|
| 103 | header->magic = host2uint16_t_le(magic);
|
|---|
| 104 | }
|
|---|
| 105 |
|
|---|
| 106 | uint16_t ext4_extent_header_get_entries_count(ext4_extent_header_t *header)
|
|---|
| 107 | {
|
|---|
| 108 | return uint16_t_le2host(header->entries_count);
|
|---|
| 109 | }
|
|---|
| 110 |
|
|---|
| 111 | void ext4_extent_header_set_entries_count(ext4_extent_header_t *header,
|
|---|
| 112 | uint16_t count)
|
|---|
| 113 | {
|
|---|
| 114 | header->entries_count = host2uint16_t_le(count);
|
|---|
| 115 | }
|
|---|
| 116 |
|
|---|
| 117 | uint16_t ext4_extent_header_get_max_entries_count(ext4_extent_header_t *header)
|
|---|
| 118 | {
|
|---|
| 119 | return uint16_t_le2host(header->max_entries_count);
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | void ext4_extent_header_set_max_entries_count(ext4_extent_header_t *header,
|
|---|
| 123 | uint16_t max_count)
|
|---|
| 124 | {
|
|---|
| 125 | header->max_entries_count = host2uint16_t_le(max_count);
|
|---|
| 126 | }
|
|---|
| 127 |
|
|---|
| 128 | uint16_t ext4_extent_header_get_depth(ext4_extent_header_t *header)
|
|---|
| 129 | {
|
|---|
| 130 | return uint16_t_le2host(header->depth);
|
|---|
| 131 | }
|
|---|
| 132 |
|
|---|
| 133 | void ext4_extent_header_set_depth(ext4_extent_header_t *header, uint16_t depth)
|
|---|
| 134 | {
|
|---|
| 135 | header->depth = host2uint16_t_le(depth);
|
|---|
| 136 | }
|
|---|
| 137 |
|
|---|
| 138 | uint32_t ext4_extent_header_get_generation(ext4_extent_header_t *header)
|
|---|
| 139 | {
|
|---|
| 140 | return uint32_t_le2host(header->generation);
|
|---|
| 141 | }
|
|---|
| 142 |
|
|---|
| 143 | void ext4_extent_header_set_generation(ext4_extent_header_t *header,
|
|---|
| 144 | uint32_t generation)
|
|---|
| 145 | {
|
|---|
| 146 | header->generation = host2uint32_t_le(generation);
|
|---|
| 147 | }
|
|---|
| 148 |
|
|---|
| 149 | /**
|
|---|
| 150 | * @}
|
|---|
| 151 | */
|
|---|