[eb91db7] | 1 | /*
|
---|
[d1538a1] | 2 | * Copyright (c) 2011 Martin Sucha
|
---|
[f22d5ef0] | 3 | * Copyright (c) 2012 Frantisek Princ
|
---|
[eb91db7] | 4 | * All rights reserved.
|
---|
| 5 | *
|
---|
| 6 | * Redistribution and use in source and binary forms, with or without
|
---|
| 7 | * modification, are permitted provided that the following conditions
|
---|
| 8 | * are met:
|
---|
| 9 | *
|
---|
| 10 | * - Redistributions of source code must retain the above copyright
|
---|
| 11 | * notice, this list of conditions and the following disclaimer.
|
---|
| 12 | * - Redistributions in binary form must reproduce the above copyright
|
---|
| 13 | * notice, this list of conditions and the following disclaimer in the
|
---|
| 14 | * documentation and/or other materials provided with the distribution.
|
---|
| 15 | * - The name of the author may not be used to endorse or promote products
|
---|
| 16 | * derived from this software without specific prior written permission.
|
---|
| 17 | *
|
---|
| 18 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
|
---|
| 19 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
---|
| 20 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
| 21 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
|
---|
| 22 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
| 23 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
---|
| 24 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
---|
| 25 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
---|
| 26 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
---|
| 27 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
---|
| 28 | */
|
---|
| 29 |
|
---|
| 30 | /** @addtogroup libext4
|
---|
| 31 | * @{
|
---|
[38542dc] | 32 | */
|
---|
[eb91db7] | 33 |
|
---|
| 34 | /**
|
---|
[4bfad34] | 35 | * @file superblock.c
|
---|
[38542dc] | 36 | * @brief Ext4 superblock operations.
|
---|
[eb91db7] | 37 | */
|
---|
| 38 |
|
---|
[fcb0d76] | 39 | #include <block.h>
|
---|
[01ab41b] | 40 | #include <byteorder.h>
|
---|
| 41 | #include <errno.h>
|
---|
[fcb0d76] | 42 | #include <mem.h>
|
---|
[38d150e] | 43 | #include <stdlib.h>
|
---|
[fcb0d76] | 44 | #include "ext4/superblock.h"
|
---|
[eb91db7] | 45 |
|
---|
[9fc72fb3] | 46 | /** Get number of i-nodes in the whole filesystem.
|
---|
| 47 | *
|
---|
[38542dc] | 48 | * @param sb Superblock
|
---|
| 49 | *
|
---|
| 50 | * @return Number of i-nodes
|
---|
| 51 | *
|
---|
[9fc72fb3] | 52 | */
|
---|
[3712434] | 53 | uint32_t ext4_superblock_get_inodes_count(ext4_superblock_t *sb)
|
---|
[01ab41b] | 54 | {
|
---|
[3712434] | 55 | return uint32_t_le2host(sb->inodes_count);
|
---|
[01ab41b] | 56 | }
|
---|
| 57 |
|
---|
[9fc72fb3] | 58 | /** Set number of i-nodes in the whole filesystem.
|
---|
| 59 | *
|
---|
[38542dc] | 60 | * @param sb Superblock
|
---|
| 61 | * @param count Number of i-nodes
|
---|
| 62 | *
|
---|
[9fc72fb3] | 63 | */
|
---|
[fe27eb4] | 64 | void ext4_superblock_set_inodes_count(ext4_superblock_t *sb, uint32_t count)
|
---|
| 65 | {
|
---|
| 66 | sb->inodes_count = host2uint32_t_le(count);
|
---|
| 67 | }
|
---|
| 68 |
|
---|
[9fc72fb3] | 69 | /** Get number of data blocks in the whole filesystem.
|
---|
| 70 | *
|
---|
[38542dc] | 71 | * @param sb Superblock
|
---|
| 72 | *
|
---|
| 73 | * @return Number of data blocks
|
---|
| 74 | *
|
---|
[9fc72fb3] | 75 | */
|
---|
[3712434] | 76 | uint64_t ext4_superblock_get_blocks_count(ext4_superblock_t *sb)
|
---|
| 77 | {
|
---|
[38542dc] | 78 | return ((uint64_t) uint32_t_le2host(sb->blocks_count_hi) << 32) |
|
---|
| 79 | uint32_t_le2host(sb->blocks_count_lo);
|
---|
[3712434] | 80 | }
|
---|
| 81 |
|
---|
[9fc72fb3] | 82 | /** Set number of data blocks in the whole filesystem.
|
---|
| 83 | *
|
---|
[38542dc] | 84 | * @param sb Superblock
|
---|
| 85 | * @param count Number of data blocks
|
---|
| 86 | *
|
---|
[9fc72fb3] | 87 | */
|
---|
[fe27eb4] | 88 | void ext4_superblock_set_blocks_count(ext4_superblock_t *sb, uint64_t count)
|
---|
| 89 | {
|
---|
| 90 | sb->blocks_count_lo = host2uint32_t_le((count << 32) >> 32);
|
---|
| 91 | sb->blocks_count_hi = host2uint32_t_le(count >> 32);
|
---|
| 92 | }
|
---|
| 93 |
|
---|
[9fc72fb3] | 94 | /** Get number of reserved data blocks in the whole filesystem.
|
---|
| 95 | *
|
---|
[38542dc] | 96 | * @param sb Superblock
|
---|
| 97 | *
|
---|
| 98 | * @return Number of reserved data blocks
|
---|
| 99 | *
|
---|
[9fc72fb3] | 100 | */
|
---|
[3712434] | 101 | uint64_t ext4_superblock_get_reserved_blocks_count(ext4_superblock_t *sb)
|
---|
| 102 | {
|
---|
[38542dc] | 103 | return ((uint64_t)
|
---|
| 104 | uint32_t_le2host(sb->reserved_blocks_count_hi) << 32) |
|
---|
| 105 | uint32_t_le2host(sb->reserved_blocks_count_lo);
|
---|
[3712434] | 106 | }
|
---|
| 107 |
|
---|
[9fc72fb3] | 108 | /** Set number of reserved data blocks in the whole filesystem.
|
---|
| 109 | *
|
---|
[38542dc] | 110 | * @param sb Superblock
|
---|
| 111 | * @param count Number of reserved data blocks
|
---|
| 112 | *
|
---|
[9fc72fb3] | 113 | */
|
---|
[38542dc] | 114 | void ext4_superblock_set_reserved_blocks_count(ext4_superblock_t *sb,
|
---|
| 115 | uint64_t count)
|
---|
[fe27eb4] | 116 | {
|
---|
| 117 | sb->reserved_blocks_count_lo = host2uint32_t_le((count << 32) >> 32);
|
---|
| 118 | sb->reserved_blocks_count_hi = host2uint32_t_le(count >> 32);
|
---|
| 119 | }
|
---|
| 120 |
|
---|
[9fc72fb3] | 121 | /** Get number of free data blocks in the whole filesystem.
|
---|
| 122 | *
|
---|
[38542dc] | 123 | * @param sb Superblock
|
---|
| 124 | *
|
---|
| 125 | * @return Number of free data blocks
|
---|
| 126 | *
|
---|
[9fc72fb3] | 127 | */
|
---|
[3712434] | 128 | uint64_t ext4_superblock_get_free_blocks_count(ext4_superblock_t *sb)
|
---|
| 129 | {
|
---|
[38542dc] | 130 | return ((uint64_t)
|
---|
| 131 | uint32_t_le2host(sb->free_blocks_count_hi) << 32) |
|
---|
| 132 | uint32_t_le2host(sb->free_blocks_count_lo);
|
---|
[3712434] | 133 | }
|
---|
| 134 |
|
---|
[9fc72fb3] | 135 | /** Set number of free data blocks in the whole filesystem.
|
---|
| 136 | *
|
---|
[38542dc] | 137 | * @param sb Superblock
|
---|
| 138 | * @param count Number of free data blocks
|
---|
| 139 | *
|
---|
[9fc72fb3] | 140 | */
|
---|
[38542dc] | 141 | void ext4_superblock_set_free_blocks_count(ext4_superblock_t *sb,
|
---|
| 142 | uint64_t count)
|
---|
[ae3d4f8] | 143 | {
|
---|
| 144 | sb->free_blocks_count_lo = host2uint32_t_le((count << 32) >> 32);
|
---|
| 145 | sb->free_blocks_count_hi = host2uint32_t_le(count >> 32);
|
---|
| 146 | }
|
---|
| 147 |
|
---|
[9fc72fb3] | 148 | /** Get number of free i-nodes in the whole filesystem.
|
---|
| 149 | *
|
---|
[38542dc] | 150 | * @param sb Superblock
|
---|
| 151 | *
|
---|
| 152 | * @return Number of free i-nodes
|
---|
| 153 | *
|
---|
[9fc72fb3] | 154 | */
|
---|
[3712434] | 155 | uint32_t ext4_superblock_get_free_inodes_count(ext4_superblock_t *sb)
|
---|
| 156 | {
|
---|
| 157 | return uint32_t_le2host(sb->free_inodes_count);
|
---|
| 158 | }
|
---|
| 159 |
|
---|
[9fc72fb3] | 160 | /** Set number of free i-nodes in the whole filesystem.
|
---|
| 161 | *
|
---|
[38542dc] | 162 | * @param sb Superblock
|
---|
| 163 | * @param count Number of free i-nodes
|
---|
| 164 | *
|
---|
[9fc72fb3] | 165 | */
|
---|
[38542dc] | 166 | void ext4_superblock_set_free_inodes_count(ext4_superblock_t *sb,
|
---|
| 167 | uint32_t count)
|
---|
[fe27eb4] | 168 | {
|
---|
| 169 | sb->free_inodes_count = host2uint32_t_le(count);
|
---|
| 170 | }
|
---|
| 171 |
|
---|
[38542dc] | 172 | /** Get index of first data block (block where the superblock is located)
|
---|
| 173 | *
|
---|
| 174 | * @param sb Superblock
|
---|
| 175 | *
|
---|
| 176 | * @return Index of the first data block
|
---|
[9fc72fb3] | 177 | *
|
---|
| 178 | */
|
---|
[3712434] | 179 | uint32_t ext4_superblock_get_first_data_block(ext4_superblock_t *sb)
|
---|
[01ab41b] | 180 | {
|
---|
[9c0c0e1] | 181 | return uint32_t_le2host(sb->first_data_block);
|
---|
[01ab41b] | 182 | }
|
---|
| 183 |
|
---|
[38542dc] | 184 | /** Set index of first data block (block where the superblock is located)
|
---|
| 185 | *
|
---|
| 186 | * @param sb Superblock
|
---|
| 187 | * @param first Index of the first data block
|
---|
[9fc72fb3] | 188 | *
|
---|
| 189 | */
|
---|
[38542dc] | 190 | void ext4_superblock_set_first_data_block(ext4_superblock_t *sb,
|
---|
| 191 | uint32_t first)
|
---|
[fe27eb4] | 192 | {
|
---|
| 193 | sb->first_data_block = host2uint32_t_le(first);
|
---|
| 194 | }
|
---|
| 195 |
|
---|
[9fc72fb3] | 196 | /** Get logarithmic block size (1024 << size == block_size)
|
---|
| 197 | *
|
---|
[38542dc] | 198 | * @param sb Superblock
|
---|
| 199 | *
|
---|
| 200 | * @return Logarithmic block size
|
---|
| 201 | *
|
---|
[9fc72fb3] | 202 | */
|
---|
[3712434] | 203 | uint32_t ext4_superblock_get_log_block_size(ext4_superblock_t *sb)
|
---|
[01ab41b] | 204 | {
|
---|
[9c0c0e1] | 205 | return uint32_t_le2host(sb->log_block_size);
|
---|
[01ab41b] | 206 | }
|
---|
| 207 |
|
---|
[9fc72fb3] | 208 | /** Set logarithmic block size (1024 << size == block_size)
|
---|
| 209 | *
|
---|
[38542dc] | 210 | * @param sb Superblock
|
---|
| 211 | *
|
---|
| 212 | * @return Logarithmic block size
|
---|
| 213 | *
|
---|
[9fc72fb3] | 214 | */
|
---|
[38542dc] | 215 | void ext4_superblock_set_log_block_size(ext4_superblock_t *sb,
|
---|
| 216 | uint32_t log_size)
|
---|
[fe27eb4] | 217 | {
|
---|
| 218 | sb->log_block_size = host2uint32_t_le(log_size);
|
---|
| 219 | }
|
---|
| 220 |
|
---|
[9fc72fb3] | 221 | /** Get size of data block (in bytes).
|
---|
| 222 | *
|
---|
[38542dc] | 223 | * @param sb Superblock
|
---|
| 224 | *
|
---|
| 225 | * @return Size of data block
|
---|
| 226 | *
|
---|
[9fc72fb3] | 227 | */
|
---|
[01ab41b] | 228 | uint32_t ext4_superblock_get_block_size(ext4_superblock_t *sb)
|
---|
| 229 | {
|
---|
[3712434] | 230 | return 1024 << ext4_superblock_get_log_block_size(sb);
|
---|
| 231 | }
|
---|
| 232 |
|
---|
[9fc72fb3] | 233 | /** Set size of data block (in bytes).
|
---|
| 234 | *
|
---|
[38542dc] | 235 | * @param sb Superblock
|
---|
| 236 | * @param size Size of data block (must be power of 2, at least 1024)
|
---|
| 237 | *
|
---|
[9fc72fb3] | 238 | */
|
---|
[fe27eb4] | 239 | void ext4_superblock_set_block_size(ext4_superblock_t *sb, uint32_t size)
|
---|
| 240 | {
|
---|
| 241 | uint32_t log = 0;
|
---|
| 242 | uint32_t tmp = size / EXT4_MIN_BLOCK_SIZE;
|
---|
[a35b458] | 243 |
|
---|
[fe27eb4] | 244 | tmp >>= 1;
|
---|
| 245 | while (tmp) {
|
---|
| 246 | log++;
|
---|
| 247 | tmp >>= 1;
|
---|
| 248 | }
|
---|
[a35b458] | 249 |
|
---|
[fe27eb4] | 250 | ext4_superblock_set_log_block_size(sb, log);
|
---|
| 251 | }
|
---|
[3712434] | 252 |
|
---|
[fb04cd90] | 253 | /** Get logarithmic fragment size (1024 << size)
|
---|
| 254 | *
|
---|
[38542dc] | 255 | * @param sb Superblock
|
---|
| 256 | *
|
---|
| 257 | * @return Logarithmic fragment size
|
---|
| 258 | *
|
---|
[fb04cd90] | 259 | */
|
---|
| 260 | uint32_t ext4_superblock_get_log_frag_size(ext4_superblock_t *sb)
|
---|
| 261 | {
|
---|
| 262 | return uint32_t_le2host(sb->log_frag_size);
|
---|
| 263 | }
|
---|
| 264 |
|
---|
| 265 | /** Set logarithmic fragment size (1024 << size)
|
---|
| 266 | *
|
---|
[38542dc] | 267 | * @param sb Superblock
|
---|
| 268 | * @param frag_size Logarithmic fragment size
|
---|
| 269 | *
|
---|
[fb04cd90] | 270 | */
|
---|
[38542dc] | 271 | void ext4_superblock_set_log_frag_size(ext4_superblock_t *sb,
|
---|
| 272 | uint32_t frag_size)
|
---|
[fb04cd90] | 273 | {
|
---|
| 274 | sb->log_frag_size = host2uint32_t_le(frag_size);
|
---|
| 275 | }
|
---|
| 276 |
|
---|
| 277 | /** Get size of fragment (in bytes).
|
---|
| 278 | *
|
---|
[38542dc] | 279 | * @param sb Superblock
|
---|
| 280 | *
|
---|
| 281 | * @return Size of fragment
|
---|
| 282 | *
|
---|
[fb04cd90] | 283 | */
|
---|
| 284 | uint32_t ext4_superblock_get_frag_size(ext4_superblock_t *sb)
|
---|
| 285 | {
|
---|
| 286 | return 1024 << ext4_superblock_get_log_frag_size(sb);
|
---|
| 287 | }
|
---|
| 288 |
|
---|
| 289 | /** Set size of fragment (in bytes).
|
---|
| 290 | *
|
---|
[38542dc] | 291 | * @param sb Superblock
|
---|
| 292 | * @param size Size of fragment (must be power of 2, at least 1024)
|
---|
| 293 | *
|
---|
[fb04cd90] | 294 | */
|
---|
| 295 | void ext4_superblock_set_frag_size(ext4_superblock_t *sb, uint32_t size)
|
---|
| 296 | {
|
---|
| 297 | uint32_t log = 0;
|
---|
| 298 | uint32_t tmp = size / EXT4_MIN_BLOCK_SIZE;
|
---|
[a35b458] | 299 |
|
---|
[fb04cd90] | 300 | tmp >>= 1;
|
---|
| 301 | while (tmp) {
|
---|
| 302 | log++;
|
---|
| 303 | tmp >>= 1;
|
---|
| 304 | }
|
---|
[a35b458] | 305 |
|
---|
[fb04cd90] | 306 | ext4_superblock_set_log_frag_size(sb, log);
|
---|
| 307 | }
|
---|
| 308 |
|
---|
[9fc72fb3] | 309 | /** Get number of data blocks per block group (except last BG)
|
---|
| 310 | *
|
---|
[38542dc] | 311 | * @param sb Superblock
|
---|
| 312 | *
|
---|
| 313 | * @return Data blocks per block group
|
---|
| 314 | *
|
---|
[9fc72fb3] | 315 | */
|
---|
[3712434] | 316 | uint32_t ext4_superblock_get_blocks_per_group(ext4_superblock_t *sb)
|
---|
| 317 | {
|
---|
| 318 | return uint32_t_le2host(sb->blocks_per_group);
|
---|
| 319 | }
|
---|
| 320 |
|
---|
[9fc72fb3] | 321 | /** Set number of data blocks per block group (except last BG)
|
---|
| 322 | *
|
---|
[38542dc] | 323 | * @param sb Superblock
|
---|
| 324 | * @param blocks Data blocks per block group
|
---|
| 325 | *
|
---|
[9fc72fb3] | 326 | */
|
---|
[38542dc] | 327 | void ext4_superblock_set_blocks_per_group(ext4_superblock_t *sb,
|
---|
| 328 | uint32_t blocks)
|
---|
[fe27eb4] | 329 | {
|
---|
| 330 | sb->blocks_per_group = host2uint32_t_le(blocks);
|
---|
| 331 | }
|
---|
| 332 |
|
---|
[fb04cd90] | 333 | /** Get number of fragments per block group (except last BG)
|
---|
| 334 | *
|
---|
[38542dc] | 335 | * @param sb Superblock
|
---|
| 336 | *
|
---|
| 337 | * @return Fragments per block group
|
---|
| 338 | *
|
---|
[fb04cd90] | 339 | */
|
---|
| 340 | uint32_t ext4_superblock_get_frags_per_group(ext4_superblock_t *sb)
|
---|
| 341 | {
|
---|
| 342 | return uint32_t_le2host(sb->frags_per_group);
|
---|
| 343 | }
|
---|
| 344 |
|
---|
| 345 | /** Set number of fragment per block group (except last BG)
|
---|
| 346 | *
|
---|
[38542dc] | 347 | * @param sb Superblock
|
---|
| 348 | * @param frags Fragments per block group
|
---|
[fb04cd90] | 349 | */
|
---|
| 350 | void ext4_superblock_set_frags_per_group(ext4_superblock_t *sb, uint32_t frags)
|
---|
| 351 | {
|
---|
| 352 | sb->frags_per_group = host2uint32_t_le(frags);
|
---|
| 353 | }
|
---|
| 354 |
|
---|
[9fc72fb3] | 355 | /** Get number of i-nodes per block group (except last BG)
|
---|
| 356 | *
|
---|
[38542dc] | 357 | * @param sb Superblock
|
---|
| 358 | *
|
---|
| 359 | * @return I-nodes per block group
|
---|
| 360 | *
|
---|
[9fc72fb3] | 361 | */
|
---|
[3712434] | 362 | uint32_t ext4_superblock_get_inodes_per_group(ext4_superblock_t *sb)
|
---|
| 363 | {
|
---|
| 364 | return uint32_t_le2host(sb->inodes_per_group);
|
---|
| 365 | }
|
---|
| 366 |
|
---|
[9fc72fb3] | 367 | /** Set number of i-nodes per block group (except last BG)
|
---|
| 368 | *
|
---|
[38542dc] | 369 | * @param sb Superblock
|
---|
| 370 | * @param inodes I-nodes per block group
|
---|
| 371 | *
|
---|
[9fc72fb3] | 372 | */
|
---|
[38542dc] | 373 | void ext4_superblock_set_inodes_per_group(ext4_superblock_t *sb,
|
---|
| 374 | uint32_t inodes)
|
---|
[fe27eb4] | 375 | {
|
---|
| 376 | sb->inodes_per_group = host2uint32_t_le(inodes);
|
---|
| 377 | }
|
---|
| 378 |
|
---|
[9fc72fb3] | 379 | /** Get time when filesystem was mounted (POSIX time).
|
---|
| 380 | *
|
---|
[38542dc] | 381 | * @param sb Superblock
|
---|
| 382 | *
|
---|
| 383 | * @return Mount time
|
---|
| 384 | *
|
---|
[9fc72fb3] | 385 | */
|
---|
[3712434] | 386 | uint32_t ext4_superblock_get_mount_time(ext4_superblock_t *sb)
|
---|
| 387 | {
|
---|
| 388 | return uint32_t_le2host(sb->mount_time);
|
---|
| 389 | }
|
---|
| 390 |
|
---|
[9fc72fb3] | 391 | /** Set time when filesystem was mounted (POSIX time).
|
---|
| 392 | *
|
---|
[38542dc] | 393 | * @param sb Superblock
|
---|
| 394 | * @param time Mount time
|
---|
| 395 | *
|
---|
[9fc72fb3] | 396 | */
|
---|
[fe27eb4] | 397 | void ext4_superblock_set_mount_time(ext4_superblock_t *sb, uint32_t time)
|
---|
| 398 | {
|
---|
| 399 | sb->mount_time = host2uint32_t_le(time);
|
---|
| 400 | }
|
---|
| 401 |
|
---|
[9fc72fb3] | 402 | /** Get time when filesystem was last accesed by write operation (POSIX time).
|
---|
| 403 | *
|
---|
[38542dc] | 404 | * @param sb Superblock
|
---|
| 405 | *
|
---|
| 406 | * @return Write time
|
---|
| 407 | *
|
---|
[9fc72fb3] | 408 | */
|
---|
[3712434] | 409 | uint32_t ext4_superblock_get_write_time(ext4_superblock_t *sb)
|
---|
| 410 | {
|
---|
| 411 | return uint32_t_le2host(sb->write_time);
|
---|
| 412 | }
|
---|
| 413 |
|
---|
[9fc72fb3] | 414 | /** Set time when filesystem was last accesed by write operation (POSIX time).
|
---|
| 415 | *
|
---|
[38542dc] | 416 | * @param sb Superblock
|
---|
| 417 | * @param time Write time
|
---|
| 418 | *
|
---|
[9fc72fb3] | 419 | */
|
---|
[fe27eb4] | 420 | void ext4_superblock_set_write_time(ext4_superblock_t *sb, uint32_t time)
|
---|
| 421 | {
|
---|
| 422 | sb->write_time = host2uint32_t_le(time);
|
---|
| 423 | }
|
---|
| 424 |
|
---|
[9fc72fb3] | 425 | /** Get number of mount from last filesystem check.
|
---|
| 426 | *
|
---|
[38542dc] | 427 | * @param sb Superblock
|
---|
| 428 | *
|
---|
| 429 | * @return Number of mounts
|
---|
| 430 | *
|
---|
[9fc72fb3] | 431 | */
|
---|
[3712434] | 432 | uint16_t ext4_superblock_get_mount_count(ext4_superblock_t *sb)
|
---|
| 433 | {
|
---|
| 434 | return uint16_t_le2host(sb->mount_count);
|
---|
| 435 | }
|
---|
| 436 |
|
---|
[9fc72fb3] | 437 | /** Set number of mount from last filesystem check.
|
---|
| 438 | *
|
---|
[38542dc] | 439 | * @param sb Superblock
|
---|
| 440 | * @param count Number of mounts
|
---|
| 441 | *
|
---|
[9fc72fb3] | 442 | */
|
---|
[fe27eb4] | 443 | void ext4_superblock_set_mount_count(ext4_superblock_t *sb, uint16_t count)
|
---|
| 444 | {
|
---|
| 445 | sb->mount_count = host2uint16_t_le(count);
|
---|
| 446 | }
|
---|
| 447 |
|
---|
[9fc72fb3] | 448 | /** Get maximum number of mount from last filesystem check.
|
---|
| 449 | *
|
---|
[38542dc] | 450 | * @param sb Superblock
|
---|
| 451 | *
|
---|
| 452 | * @return Maximum number of mounts
|
---|
| 453 | *
|
---|
[9fc72fb3] | 454 | */
|
---|
[3712434] | 455 | uint16_t ext4_superblock_get_max_mount_count(ext4_superblock_t *sb)
|
---|
| 456 | {
|
---|
| 457 | return uint16_t_le2host(sb->max_mount_count);
|
---|
| 458 | }
|
---|
| 459 |
|
---|
[9fc72fb3] | 460 | /** Set maximum number of mount from last filesystem check.
|
---|
| 461 | *
|
---|
[38542dc] | 462 | * @param sb Superblock
|
---|
| 463 | * @param count Maximum number of mounts
|
---|
| 464 | *
|
---|
[9fc72fb3] | 465 | */
|
---|
[fe27eb4] | 466 | void ext4_superblock_set_max_mount_count(ext4_superblock_t *sb, uint16_t count)
|
---|
| 467 | {
|
---|
| 468 | sb->max_mount_count = host2uint16_t_le(count);
|
---|
| 469 | }
|
---|
| 470 |
|
---|
[9fc72fb3] | 471 | /** Get superblock magic value.
|
---|
| 472 | *
|
---|
[38542dc] | 473 | * @param sb Superblock
|
---|
| 474 | *
|
---|
| 475 | * @return Magic value
|
---|
| 476 | *
|
---|
[9fc72fb3] | 477 | */
|
---|
[3712434] | 478 | uint16_t ext4_superblock_get_magic(ext4_superblock_t *sb)
|
---|
| 479 | {
|
---|
| 480 | return uint16_t_le2host(sb->magic);
|
---|
| 481 | }
|
---|
| 482 |
|
---|
[9fc72fb3] | 483 | /** Set superblock magic value.
|
---|
| 484 | *
|
---|
[38542dc] | 485 | * @param sb Superblock
|
---|
| 486 | * @param magic Magic value
|
---|
| 487 | *
|
---|
[9fc72fb3] | 488 | */
|
---|
| 489 | void ext4_superblock_set_magic(ext4_superblock_t *sb, uint16_t magic)
|
---|
| 490 | {
|
---|
| 491 | sb->magic = host2uint16_t_le(magic);
|
---|
| 492 | }
|
---|
| 493 |
|
---|
[2226cc3] | 494 | /** Get filesystem state.
|
---|
[9fc72fb3] | 495 | *
|
---|
[38542dc] | 496 | * @param sb Superblock
|
---|
| 497 | *
|
---|
| 498 | * @return Filesystem state
|
---|
| 499 | *
|
---|
[9fc72fb3] | 500 | */
|
---|
[3712434] | 501 | uint16_t ext4_superblock_get_state(ext4_superblock_t *sb)
|
---|
| 502 | {
|
---|
| 503 | return uint16_t_le2host(sb->state);
|
---|
| 504 | }
|
---|
| 505 |
|
---|
[2226cc3] | 506 | /** Set filesystem state.
|
---|
[9fc72fb3] | 507 | *
|
---|
[38542dc] | 508 | * @param sb Superblock
|
---|
| 509 | * @param state Filesystem state
|
---|
| 510 | *
|
---|
[9fc72fb3] | 511 | */
|
---|
[fe27eb4] | 512 | void ext4_superblock_set_state(ext4_superblock_t *sb, uint16_t state)
|
---|
| 513 | {
|
---|
| 514 | sb->state = host2uint16_t_le(state);
|
---|
| 515 | }
|
---|
| 516 |
|
---|
[2226cc3] | 517 | /** Get behavior code when errors detected.
|
---|
[9fc72fb3] | 518 | *
|
---|
[38542dc] | 519 | * @param sb Superblock
|
---|
| 520 | *
|
---|
| 521 | * @return Behavior code
|
---|
| 522 | *
|
---|
[9fc72fb3] | 523 | */
|
---|
[3712434] | 524 | uint16_t ext4_superblock_get_errors(ext4_superblock_t *sb)
|
---|
| 525 | {
|
---|
| 526 | return uint16_t_le2host(sb->errors);
|
---|
| 527 | }
|
---|
| 528 |
|
---|
[2226cc3] | 529 | /** Set behavior code when errors detected.
|
---|
[9fc72fb3] | 530 | *
|
---|
[38542dc] | 531 | * @param sb Superblock
|
---|
| 532 | * @param errors Behavior code
|
---|
| 533 | *
|
---|
[9fc72fb3] | 534 | */
|
---|
[fe27eb4] | 535 | void ext4_superblock_set_errors(ext4_superblock_t *sb, uint16_t errors)
|
---|
| 536 | {
|
---|
| 537 | sb->errors = host2uint16_t_le(errors);
|
---|
| 538 | }
|
---|
[3712434] | 539 |
|
---|
[2226cc3] | 540 | /** Get minor revision level of the filesystem.
|
---|
[9fc72fb3] | 541 | *
|
---|
[38542dc] | 542 | * @param sb Superblock
|
---|
| 543 | *
|
---|
| 544 | * @return Minor revision level
|
---|
| 545 | *
|
---|
[9fc72fb3] | 546 | */
|
---|
[3712434] | 547 | uint16_t ext4_superblock_get_minor_rev_level(ext4_superblock_t *sb)
|
---|
| 548 | {
|
---|
| 549 | return uint16_t_le2host(sb->minor_rev_level);
|
---|
| 550 | }
|
---|
| 551 |
|
---|
[2226cc3] | 552 | /** Set minor revision level of the filesystem.
|
---|
[9fc72fb3] | 553 | *
|
---|
[38542dc] | 554 | * @param sb Superblock
|
---|
| 555 | * @param level Minor revision level
|
---|
| 556 | *
|
---|
[9fc72fb3] | 557 | */
|
---|
[fe27eb4] | 558 | void ext4_superblock_set_minor_rev_level(ext4_superblock_t *sb, uint16_t level)
|
---|
| 559 | {
|
---|
| 560 | sb->minor_rev_level = host2uint16_t_le(level);
|
---|
| 561 | }
|
---|
| 562 |
|
---|
[2226cc3] | 563 | /** Get time of the last filesystem check.
|
---|
[9fc72fb3] | 564 | *
|
---|
[38542dc] | 565 | * @param sb Superblock
|
---|
| 566 | *
|
---|
| 567 | * @return Time of the last check (POSIX)
|
---|
| 568 | *
|
---|
[9fc72fb3] | 569 | */
|
---|
[3712434] | 570 | uint32_t ext4_superblock_get_last_check_time(ext4_superblock_t *sb)
|
---|
| 571 | {
|
---|
| 572 | return uint32_t_le2host(sb->last_check_time);
|
---|
| 573 | }
|
---|
| 574 |
|
---|
[2226cc3] | 575 | /** Set time of the last filesystem check.
|
---|
[9fc72fb3] | 576 | *
|
---|
[38542dc] | 577 | * @param sb Superblock
|
---|
| 578 | * @param time Time of the last check (POSIX)
|
---|
| 579 | *
|
---|
[9fc72fb3] | 580 | */
|
---|
[fe27eb4] | 581 | void ext4_superblock_set_last_check_time(ext4_superblock_t *sb, uint32_t time)
|
---|
| 582 | {
|
---|
| 583 | sb->state = host2uint32_t_le(time);
|
---|
| 584 | }
|
---|
| 585 |
|
---|
[2226cc3] | 586 | /** Get maximum time interval between two filesystem checks.
|
---|
[9fc72fb3] | 587 | *
|
---|
[38542dc] | 588 | * @param sb Superblock
|
---|
| 589 | *
|
---|
| 590 | * @return Time interval between two check (POSIX)
|
---|
| 591 | *
|
---|
[9fc72fb3] | 592 | */
|
---|
[38542dc] | 593 | uint32_t ext4_superblock_get_check_interval(ext4_superblock_t *sb)
|
---|
| 594 | {
|
---|
[3712434] | 595 | return uint32_t_le2host(sb->check_interval);
|
---|
| 596 | }
|
---|
| 597 |
|
---|
[2226cc3] | 598 | /** Set maximum time interval between two filesystem checks.
|
---|
[9fc72fb3] | 599 | *
|
---|
[38542dc] | 600 | * @param sb Superblock
|
---|
| 601 | * @param interval Time interval between two check (POSIX)
|
---|
| 602 | *
|
---|
[9fc72fb3] | 603 | */
|
---|
[fe27eb4] | 604 | void ext4_superblock_set_check_interval(ext4_superblock_t *sb, uint32_t interval)
|
---|
| 605 | {
|
---|
| 606 | sb->check_interval = host2uint32_t_le(interval);
|
---|
| 607 | }
|
---|
| 608 |
|
---|
[2226cc3] | 609 | /** Get operation system identifier, on which the filesystem was created.
|
---|
[9fc72fb3] | 610 | *
|
---|
[38542dc] | 611 | * @param sb Superblock
|
---|
| 612 | *
|
---|
| 613 | * @return Operation system identifier
|
---|
| 614 | *
|
---|
[9fc72fb3] | 615 | */
|
---|
[3712434] | 616 | uint32_t ext4_superblock_get_creator_os(ext4_superblock_t *sb)
|
---|
| 617 | {
|
---|
| 618 | return uint32_t_le2host(sb->creator_os);
|
---|
[01ab41b] | 619 | }
|
---|
| 620 |
|
---|
[2226cc3] | 621 | /** Set operation system identifier, on which the filesystem was created.
|
---|
[9fc72fb3] | 622 | *
|
---|
[38542dc] | 623 | * @param sb Superblock
|
---|
| 624 | * @param os Operation system identifier
|
---|
| 625 | *
|
---|
[9fc72fb3] | 626 | */
|
---|
[fe27eb4] | 627 | void ext4_superblock_set_creator_os(ext4_superblock_t *sb, uint32_t os)
|
---|
| 628 | {
|
---|
| 629 | sb->creator_os = host2uint32_t_le(os);
|
---|
| 630 | }
|
---|
| 631 |
|
---|
[2226cc3] | 632 | /** Get revision level of the filesystem.
|
---|
[9fc72fb3] | 633 | *
|
---|
[38542dc] | 634 | * @param sb Superblock
|
---|
| 635 | *
|
---|
| 636 | * @return Revision level
|
---|
| 637 | *
|
---|
[9fc72fb3] | 638 | */
|
---|
[9c0c0e1] | 639 | uint32_t ext4_superblock_get_rev_level(ext4_superblock_t *sb)
|
---|
| 640 | {
|
---|
| 641 | return uint32_t_le2host(sb->rev_level);
|
---|
| 642 | }
|
---|
| 643 |
|
---|
[2226cc3] | 644 | /** Set revision level of the filesystem.
|
---|
[9fc72fb3] | 645 | *
|
---|
[38542dc] | 646 | * @param sb Superblock
|
---|
| 647 | * @param level Revision level
|
---|
| 648 | *
|
---|
[9fc72fb3] | 649 | */
|
---|
[fe27eb4] | 650 | void ext4_superblock_set_rev_level(ext4_superblock_t *sb, uint32_t level)
|
---|
| 651 | {
|
---|
| 652 | sb->rev_level = host2uint32_t_le(level);
|
---|
| 653 | }
|
---|
| 654 |
|
---|
[2226cc3] | 655 | /** Get default user id for reserved blocks.
|
---|
[9fc72fb3] | 656 | *
|
---|
[38542dc] | 657 | * @param sb Superblock
|
---|
| 658 | *
|
---|
| 659 | * @return Default user id for reserved blocks.
|
---|
| 660 | *
|
---|
[9fc72fb3] | 661 | */
|
---|
[fe27eb4] | 662 | uint16_t ext4_superblock_get_def_resuid(ext4_superblock_t *sb)
|
---|
| 663 | {
|
---|
| 664 | return uint16_t_le2host(sb->def_resuid);
|
---|
| 665 | }
|
---|
| 666 |
|
---|
[2226cc3] | 667 | /** Set default user id for reserved blocks.
|
---|
[9fc72fb3] | 668 | *
|
---|
[38542dc] | 669 | * @param sb Superblock
|
---|
| 670 | * @param uid Default user id for reserved blocks.
|
---|
| 671 | *
|
---|
[9fc72fb3] | 672 | */
|
---|
[fe27eb4] | 673 | void ext4_superblock_set_def_resuid(ext4_superblock_t *sb, uint16_t uid)
|
---|
| 674 | {
|
---|
| 675 | sb->def_resuid = host2uint16_t_le(uid);
|
---|
| 676 | }
|
---|
| 677 |
|
---|
[2226cc3] | 678 | /** Get default group id for reserved blocks.
|
---|
[9fc72fb3] | 679 | *
|
---|
[38542dc] | 680 | * @param sb Superblock
|
---|
| 681 | *
|
---|
| 682 | * @return Default group id for reserved blocks.
|
---|
| 683 | *
|
---|
[9fc72fb3] | 684 | */
|
---|
[fe27eb4] | 685 | uint16_t ext4_superblock_get_def_resgid(ext4_superblock_t *sb)
|
---|
| 686 | {
|
---|
| 687 | return uint16_t_le2host(sb->def_resgid);
|
---|
| 688 | }
|
---|
| 689 |
|
---|
[2226cc3] | 690 | /** Set default group id for reserved blocks.
|
---|
[9fc72fb3] | 691 | *
|
---|
[38542dc] | 692 | * @param sb Superblock
|
---|
| 693 | * @param gid Default group id for reserved blocks.
|
---|
| 694 | *
|
---|
[9fc72fb3] | 695 | */
|
---|
[fe27eb4] | 696 | void ext4_superblock_set_def_resgid(ext4_superblock_t *sb, uint16_t gid)
|
---|
| 697 | {
|
---|
| 698 | sb->def_resgid = host2uint16_t_le(gid);
|
---|
| 699 | }
|
---|
| 700 |
|
---|
[2226cc3] | 701 | /** Get index of the first i-node, which can be used for allocation.
|
---|
[9fc72fb3] | 702 | *
|
---|
[38542dc] | 703 | * @param sb Superblock
|
---|
| 704 | *
|
---|
| 705 | * @return I-node index
|
---|
| 706 | *
|
---|
[9fc72fb3] | 707 | */
|
---|
[fe27eb4] | 708 | uint32_t ext4_superblock_get_first_inode(ext4_superblock_t *sb)
|
---|
| 709 | {
|
---|
| 710 | return uint32_t_le2host(sb->first_inode);
|
---|
| 711 | }
|
---|
| 712 |
|
---|
[2226cc3] | 713 | /** Set index of the first i-node, which can be used for allocation.
|
---|
[9fc72fb3] | 714 | *
|
---|
[38542dc] | 715 | * @param sb Superblock
|
---|
| 716 | * @param first_inode I-node index
|
---|
| 717 | *
|
---|
[9fc72fb3] | 718 | */
|
---|
[38542dc] | 719 | void ext4_superblock_set_first_inode(ext4_superblock_t *sb,
|
---|
| 720 | uint32_t first_inode)
|
---|
[fe27eb4] | 721 | {
|
---|
| 722 | sb->first_inode = host2uint32_t_le(first_inode);
|
---|
| 723 | }
|
---|
| 724 |
|
---|
[2226cc3] | 725 | /** Get size of i-node structure.
|
---|
| 726 | *
|
---|
| 727 | * For the oldest revision return constant number.
|
---|
[9fc72fb3] | 728 | *
|
---|
[38542dc] | 729 | * @param sb Superblock
|
---|
| 730 | *
|
---|
| 731 | * @return Size of i-node structure
|
---|
| 732 | *
|
---|
[9fc72fb3] | 733 | */
|
---|
[3711e7e] | 734 | uint16_t ext4_superblock_get_inode_size(ext4_superblock_t *sb)
|
---|
| 735 | {
|
---|
[38542dc] | 736 | if (ext4_superblock_get_rev_level(sb) == 0)
|
---|
[3711e7e] | 737 | return EXT4_REV0_INODE_SIZE;
|
---|
[a35b458] | 738 |
|
---|
[3711e7e] | 739 | return uint16_t_le2host(sb->inode_size);
|
---|
| 740 | }
|
---|
| 741 |
|
---|
[2226cc3] | 742 | /** Set size of i-node structure.
|
---|
[9fc72fb3] | 743 | *
|
---|
[38542dc] | 744 | * @param sb Superblock
|
---|
| 745 | * @param size Size of i-node structure
|
---|
| 746 | *
|
---|
[9fc72fb3] | 747 | */
|
---|
[fe27eb4] | 748 | void ext4_superblock_set_inode_size(ext4_superblock_t *sb, uint16_t size)
|
---|
| 749 | {
|
---|
| 750 | sb->inode_size = host2uint16_t_le(size);
|
---|
| 751 | }
|
---|
| 752 |
|
---|
[2226cc3] | 753 | /** Get index of block group, where superblock copy is located.
|
---|
[9fc72fb3] | 754 | *
|
---|
[38542dc] | 755 | * @param sb Superblock
|
---|
| 756 | *
|
---|
| 757 | * @return Block group index
|
---|
| 758 | *
|
---|
[9fc72fb3] | 759 | */
|
---|
[2226cc3] | 760 | uint16_t ext4_superblock_get_block_group_index(ext4_superblock_t *sb)
|
---|
[3711e7e] | 761 | {
|
---|
[2226cc3] | 762 | return uint16_t_le2host(sb->block_group_index);
|
---|
[3711e7e] | 763 | }
|
---|
| 764 |
|
---|
[2226cc3] | 765 | /** Set index of block group, where superblock copy is located.
|
---|
[9fc72fb3] | 766 | *
|
---|
[38542dc] | 767 | * @param sb Superblock
|
---|
| 768 | * @param bgid Block group index
|
---|
| 769 | *
|
---|
[9fc72fb3] | 770 | */
|
---|
[2226cc3] | 771 | void ext4_superblock_set_block_group_index(ext4_superblock_t *sb, uint16_t bgid)
|
---|
[fe27eb4] | 772 | {
|
---|
[2226cc3] | 773 | sb->block_group_index = host2uint16_t_le(bgid);
|
---|
[fe27eb4] | 774 | }
|
---|
| 775 |
|
---|
[2226cc3] | 776 | /** Get compatible features supported by the filesystem.
|
---|
[9fc72fb3] | 777 | *
|
---|
[38542dc] | 778 | * @param sb Superblock
|
---|
| 779 | *
|
---|
| 780 | * @return Compatible features bitmap
|
---|
| 781 | *
|
---|
[9fc72fb3] | 782 | */
|
---|
[9c0c0e1] | 783 | uint32_t ext4_superblock_get_features_compatible(ext4_superblock_t *sb)
|
---|
| 784 | {
|
---|
| 785 | return uint32_t_le2host(sb->features_compatible);
|
---|
| 786 | }
|
---|
| 787 |
|
---|
[2226cc3] | 788 | /** Set compatible features supported by the filesystem.
|
---|
[9fc72fb3] | 789 | *
|
---|
[38542dc] | 790 | * @param sb Superblock
|
---|
| 791 | * @param features Compatible features bitmap
|
---|
| 792 | *
|
---|
[9fc72fb3] | 793 | */
|
---|
[38542dc] | 794 | void ext4_superblock_set_features_compatible(ext4_superblock_t *sb,
|
---|
| 795 | uint32_t features)
|
---|
[fe27eb4] | 796 | {
|
---|
| 797 | sb->features_compatible = host2uint32_t_le(features);
|
---|
| 798 | }
|
---|
| 799 |
|
---|
[2226cc3] | 800 | /** Get incompatible features supported by the filesystem.
|
---|
[9fc72fb3] | 801 | *
|
---|
[38542dc] | 802 | * @param sb Superblock
|
---|
| 803 | *
|
---|
| 804 | * @return Incompatible features bitmap
|
---|
| 805 | *
|
---|
[9fc72fb3] | 806 | */
|
---|
[9c0c0e1] | 807 | uint32_t ext4_superblock_get_features_incompatible(ext4_superblock_t *sb)
|
---|
| 808 | {
|
---|
| 809 | return uint32_t_le2host(sb->features_incompatible);
|
---|
| 810 | }
|
---|
| 811 |
|
---|
[2226cc3] | 812 | /** Set incompatible features supported by the filesystem.
|
---|
[9fc72fb3] | 813 | *
|
---|
[38542dc] | 814 | * @param sb Superblock
|
---|
| 815 | * @param features Incompatible features bitmap
|
---|
| 816 | *
|
---|
[9fc72fb3] | 817 | */
|
---|
[38542dc] | 818 | void ext4_superblock_set_features_incompatible(ext4_superblock_t *sb,
|
---|
| 819 | uint32_t features)
|
---|
[fe27eb4] | 820 | {
|
---|
| 821 | sb->features_incompatible = host2uint32_t_le(features);
|
---|
| 822 | }
|
---|
| 823 |
|
---|
[2226cc3] | 824 | /** Get compatible features supported by the filesystem.
|
---|
[9fc72fb3] | 825 | *
|
---|
[38542dc] | 826 | * @param sb Superblock
|
---|
| 827 | *
|
---|
| 828 | * @return Read-only compatible features bitmap
|
---|
| 829 | *
|
---|
[9fc72fb3] | 830 | */
|
---|
[9c0c0e1] | 831 | uint32_t ext4_superblock_get_features_read_only(ext4_superblock_t *sb)
|
---|
| 832 | {
|
---|
| 833 | return uint32_t_le2host(sb->features_read_only);
|
---|
| 834 | }
|
---|
| 835 |
|
---|
[2226cc3] | 836 | /** Set compatible features supported by the filesystem.
|
---|
[9fc72fb3] | 837 | *
|
---|
[38542dc] | 838 | * @param sb Superblock
|
---|
| 839 | * @param feature Read-only compatible features bitmap
|
---|
| 840 | *
|
---|
[9fc72fb3] | 841 | */
|
---|
[38542dc] | 842 | void ext4_superblock_set_features_read_only(ext4_superblock_t *sb,
|
---|
| 843 | uint32_t features)
|
---|
[fe27eb4] | 844 | {
|
---|
| 845 | sb->features_read_only = host2uint32_t_le(features);
|
---|
| 846 | }
|
---|
[01ab41b] | 847 |
|
---|
[2226cc3] | 848 | /** Get UUID of the filesystem.
|
---|
[9fc72fb3] | 849 | *
|
---|
[38542dc] | 850 | * @param sb superblock
|
---|
| 851 | *
|
---|
| 852 | * @return Pointer to UUID array
|
---|
| 853 | *
|
---|
[9fc72fb3] | 854 | */
|
---|
[38542dc] | 855 | const uint8_t *ext4_superblock_get_uuid(ext4_superblock_t *sb)
|
---|
[291af81] | 856 | {
|
---|
| 857 | return sb->uuid;
|
---|
| 858 | }
|
---|
| 859 |
|
---|
[2226cc3] | 860 | /** Set UUID of the filesystem.
|
---|
[9fc72fb3] | 861 | *
|
---|
[38542dc] | 862 | * @param sb Superblock
|
---|
| 863 | * @param uuid Pointer to UUID array
|
---|
| 864 | *
|
---|
[9fc72fb3] | 865 | */
|
---|
[291af81] | 866 | void ext4_superblock_set_uuid(ext4_superblock_t *sb, const uint8_t *uuid)
|
---|
| 867 | {
|
---|
| 868 | memcpy(sb->uuid, uuid, sizeof(sb->uuid));
|
---|
| 869 | }
|
---|
| 870 |
|
---|
[2226cc3] | 871 | /** Get name of the filesystem volume.
|
---|
| 872 | *
|
---|
[38542dc] | 873 | * @param sb Superblock
|
---|
| 874 | *
|
---|
| 875 | * @return Name of the volume
|
---|
| 876 | *
|
---|
[2226cc3] | 877 | */
|
---|
[38542dc] | 878 | const char *ext4_superblock_get_volume_name(ext4_superblock_t *sb)
|
---|
[291af81] | 879 | {
|
---|
| 880 | return sb->volume_name;
|
---|
| 881 | }
|
---|
| 882 |
|
---|
[2226cc3] | 883 | /** Set name of the filesystem volume.
|
---|
[9fc72fb3] | 884 | *
|
---|
[38542dc] | 885 | * @param sb Superblock
|
---|
| 886 | * @param name New name of the volume
|
---|
[9fc72fb3] | 887 | */
|
---|
[291af81] | 888 | void ext4_superblock_set_volume_name(ext4_superblock_t *sb, const char *name)
|
---|
| 889 | {
|
---|
| 890 | memcpy(sb->volume_name, name, sizeof(sb->volume_name));
|
---|
| 891 | }
|
---|
| 892 |
|
---|
[2226cc3] | 893 | /** Get name of the directory, where this filesystem was mounted at last.
|
---|
[9fc72fb3] | 894 | *
|
---|
[38542dc] | 895 | * @param sb Superblock
|
---|
| 896 | *
|
---|
| 897 | * @return Directory name
|
---|
| 898 | *
|
---|
[9fc72fb3] | 899 | */
|
---|
[38542dc] | 900 | const char *ext4_superblock_get_last_mounted(ext4_superblock_t *sb)
|
---|
[291af81] | 901 | {
|
---|
| 902 | return sb->last_mounted;
|
---|
| 903 | }
|
---|
| 904 |
|
---|
[2226cc3] | 905 | /** Set name of the directory, where this filesystem was mounted at last.
|
---|
[9fc72fb3] | 906 | *
|
---|
[38542dc] | 907 | * @param sb Superblock
|
---|
| 908 | * @param last Directory name
|
---|
| 909 | *
|
---|
[9fc72fb3] | 910 | */
|
---|
[291af81] | 911 | void ext4_superblock_set_last_mounted(ext4_superblock_t *sb, const char *last)
|
---|
| 912 | {
|
---|
| 913 | memcpy(sb->last_mounted, last, sizeof(sb->last_mounted));
|
---|
| 914 | }
|
---|
| 915 |
|
---|
[2226cc3] | 916 | /** Get last orphaned i-node index.
|
---|
| 917 | *
|
---|
| 918 | * Orphans are stored in linked list.
|
---|
[9fc72fb3] | 919 | *
|
---|
[38542dc] | 920 | * @param sb Superblock
|
---|
| 921 | *
|
---|
| 922 | * @return Last orphaned i-node index
|
---|
| 923 | *
|
---|
[9fc72fb3] | 924 | */
|
---|
[ebcaff4] | 925 | uint32_t ext4_superblock_get_last_orphan(ext4_superblock_t *sb)
|
---|
| 926 | {
|
---|
| 927 | return uint32_t_le2host(sb->last_orphan);
|
---|
| 928 | }
|
---|
| 929 |
|
---|
[2226cc3] | 930 | /** Set last orphaned i-node index.
|
---|
| 931 | *
|
---|
| 932 | * Orphans are stored in linked list.
|
---|
[9fc72fb3] | 933 | *
|
---|
[38542dc] | 934 | * @param sb Superblock
|
---|
| 935 | * @param last_orphan Last orphaned i-node index
|
---|
| 936 | *
|
---|
[9fc72fb3] | 937 | */
|
---|
[38542dc] | 938 | void ext4_superblock_set_last_orphan(ext4_superblock_t *sb,
|
---|
| 939 | uint32_t last_orphan)
|
---|
[ebcaff4] | 940 | {
|
---|
| 941 | sb->last_orphan = host2uint32_t_le(last_orphan);
|
---|
| 942 | }
|
---|
| 943 |
|
---|
[2226cc3] | 944 | /** Get hash seed for directory index hash function.
|
---|
[9fc72fb3] | 945 | *
|
---|
[38542dc] | 946 | * @param sb Superblock
|
---|
| 947 | *
|
---|
| 948 | * @return Hash seed pointer
|
---|
| 949 | *
|
---|
[9fc72fb3] | 950 | */
|
---|
[38542dc] | 951 | const uint32_t *ext4_superblock_get_hash_seed(ext4_superblock_t *sb)
|
---|
[7bc4508] | 952 | {
|
---|
| 953 | return sb->hash_seed;
|
---|
| 954 | }
|
---|
| 955 |
|
---|
[2226cc3] | 956 | /** Set hash seed for directory index hash function.
|
---|
[9fc72fb3] | 957 | *
|
---|
[38542dc] | 958 | * @param sb Superblock
|
---|
| 959 | * @param seed Hash seed pointer
|
---|
| 960 | *
|
---|
[2226cc3] | 961 | */
|
---|
| 962 | void ext4_superblock_set_hash_seed(ext4_superblock_t *sb, const uint32_t *seed)
|
---|
| 963 | {
|
---|
| 964 | memcpy(sb->hash_seed, seed, sizeof(sb->hash_seed));
|
---|
| 965 | }
|
---|
| 966 |
|
---|
| 967 | /** Get default version of the hash algorithm version for directory index.
|
---|
| 968 | *
|
---|
[38542dc] | 969 | * @param sb Superblock
|
---|
| 970 | *
|
---|
| 971 | * @return Default hash version
|
---|
| 972 | *
|
---|
[9fc72fb3] | 973 | */
|
---|
[7eb033ce] | 974 | uint8_t ext4_superblock_get_default_hash_version(ext4_superblock_t *sb)
|
---|
| 975 | {
|
---|
| 976 | return sb->default_hash_version;
|
---|
| 977 | }
|
---|
| 978 |
|
---|
[2226cc3] | 979 | /** Set default version of the hash algorithm version for directory index.
|
---|
[9fc72fb3] | 980 | *
|
---|
[38542dc] | 981 | * @param sb Superblock
|
---|
| 982 | * @param version Default hash version
|
---|
| 983 | *
|
---|
[9fc72fb3] | 984 | */
|
---|
[38542dc] | 985 | void ext4_superblock_set_default_hash_version(ext4_superblock_t *sb,
|
---|
| 986 | uint8_t version)
|
---|
[7eb033ce] | 987 | {
|
---|
| 988 | sb->default_hash_version = version;
|
---|
| 989 | }
|
---|
| 990 |
|
---|
[2226cc3] | 991 | /** Get size of block group descriptor structure.
|
---|
[9fc72fb3] | 992 | *
|
---|
[2226cc3] | 993 | * Output value is checked for minimal size.
|
---|
| 994 | *
|
---|
[38542dc] | 995 | * @param sb Superblock
|
---|
| 996 | *
|
---|
| 997 | * @return Size of block group descriptor
|
---|
| 998 | *
|
---|
[9fc72fb3] | 999 | */
|
---|
[c25e39b] | 1000 | uint16_t ext4_superblock_get_desc_size(ext4_superblock_t *sb)
|
---|
| 1001 | {
|
---|
| 1002 | uint16_t size = uint16_t_le2host(sb->desc_size);
|
---|
[a35b458] | 1003 |
|
---|
[38542dc] | 1004 | if (size < EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
|
---|
[fb04cd90] | 1005 | size = EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE;
|
---|
[a35b458] | 1006 |
|
---|
[c25e39b] | 1007 | return size;
|
---|
| 1008 | }
|
---|
| 1009 |
|
---|
[2226cc3] | 1010 | /** Set size of block group descriptor structure.
|
---|
| 1011 | *
|
---|
| 1012 | * Input value is checked for minimal size.
|
---|
[9fc72fb3] | 1013 | *
|
---|
[38542dc] | 1014 | * @param sb Superblock
|
---|
| 1015 | * @param size Size of block group descriptor
|
---|
| 1016 | *
|
---|
[9fc72fb3] | 1017 | */
|
---|
[fe27eb4] | 1018 | void ext4_superblock_set_desc_size(ext4_superblock_t *sb, uint16_t size)
|
---|
| 1019 | {
|
---|
[38542dc] | 1020 | if (size < EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
|
---|
| 1021 | sb->desc_size =
|
---|
| 1022 | host2uint16_t_le(EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE);
|
---|
[a35b458] | 1023 |
|
---|
[fe27eb4] | 1024 | sb->desc_size = host2uint16_t_le(size);
|
---|
| 1025 | }
|
---|
| 1026 |
|
---|
[2226cc3] | 1027 | /** Get superblock flags.
|
---|
[9fc72fb3] | 1028 | *
|
---|
[38542dc] | 1029 | * @param sb Superblock
|
---|
| 1030 | *
|
---|
| 1031 | * @return Flags from the superblock
|
---|
| 1032 | *
|
---|
[9fc72fb3] | 1033 | */
|
---|
[7bc4508] | 1034 | uint32_t ext4_superblock_get_flags(ext4_superblock_t *sb)
|
---|
| 1035 | {
|
---|
| 1036 | return uint32_t_le2host(sb->flags);
|
---|
| 1037 | }
|
---|
| 1038 |
|
---|
[2226cc3] | 1039 | /** Set superblock flags.
|
---|
[9fc72fb3] | 1040 | *
|
---|
[38542dc] | 1041 | * @param sb Superblock
|
---|
| 1042 | * @param flags Flags for the superblock
|
---|
| 1043 | *
|
---|
[9fc72fb3] | 1044 | */
|
---|
[fe27eb4] | 1045 | void ext4_superblock_set_flags(ext4_superblock_t *sb, uint32_t flags)
|
---|
| 1046 | {
|
---|
| 1047 | sb->flags = host2uint32_t_le(flags);
|
---|
| 1048 | }
|
---|
| 1049 |
|
---|
[3712434] | 1050 | /*
|
---|
[c25e39b] | 1051 | * More complex superblock operations
|
---|
[01ab41b] | 1052 | */
|
---|
[3712434] | 1053 |
|
---|
[2226cc3] | 1054 | /** Check if superblock has specified flag.
|
---|
[9fc72fb3] | 1055 | *
|
---|
[38542dc] | 1056 | * @param sb Superblock
|
---|
| 1057 | * @param flag Flag to be checked
|
---|
| 1058 | *
|
---|
| 1059 | * @return True, if superblock has the flag
|
---|
| 1060 | *
|
---|
[9fc72fb3] | 1061 | */
|
---|
[7bc4508] | 1062 | bool ext4_superblock_has_flag(ext4_superblock_t *sb, uint32_t flag)
|
---|
| 1063 | {
|
---|
[38542dc] | 1064 | if (ext4_superblock_get_flags(sb) & flag)
|
---|
[7bc4508] | 1065 | return true;
|
---|
[a35b458] | 1066 |
|
---|
[7bc4508] | 1067 | return false;
|
---|
| 1068 | }
|
---|
| 1069 |
|
---|
[2226cc3] | 1070 | /** Check if filesystem supports compatible feature.
|
---|
[9fc72fb3] | 1071 | *
|
---|
[38542dc] | 1072 | * @param sb Superblock
|
---|
| 1073 | * @param feature Feature to be checked
|
---|
| 1074 | *
|
---|
| 1075 | * @return True, if filesystem supports the feature
|
---|
| 1076 | *
|
---|
[9fc72fb3] | 1077 | */
|
---|
[38542dc] | 1078 | bool ext4_superblock_has_feature_compatible(ext4_superblock_t *sb,
|
---|
| 1079 | uint32_t feature)
|
---|
[c25e39b] | 1080 | {
|
---|
[38542dc] | 1081 | if (ext4_superblock_get_features_compatible(sb) & feature)
|
---|
[c25e39b] | 1082 | return true;
|
---|
[a35b458] | 1083 |
|
---|
[c25e39b] | 1084 | return false;
|
---|
| 1085 | }
|
---|
| 1086 |
|
---|
[2226cc3] | 1087 | /** Check if filesystem supports incompatible feature.
|
---|
[9fc72fb3] | 1088 | *
|
---|
[38542dc] | 1089 | * @param sb Superblock
|
---|
| 1090 | * @param feature Feature to be checked
|
---|
| 1091 | *
|
---|
| 1092 | * @return True, if filesystem supports the feature
|
---|
| 1093 | *
|
---|
[9fc72fb3] | 1094 | */
|
---|
[38542dc] | 1095 | bool ext4_superblock_has_feature_incompatible(ext4_superblock_t *sb,
|
---|
| 1096 | uint32_t feature)
|
---|
[c25e39b] | 1097 | {
|
---|
[38542dc] | 1098 | if (ext4_superblock_get_features_incompatible(sb) & feature)
|
---|
[c25e39b] | 1099 | return true;
|
---|
[a35b458] | 1100 |
|
---|
[c25e39b] | 1101 | return false;
|
---|
| 1102 | }
|
---|
| 1103 |
|
---|
[2226cc3] | 1104 | /** Check if filesystem supports read-only compatible feature.
|
---|
[9fc72fb3] | 1105 | *
|
---|
[38542dc] | 1106 | * @param sb Superblock
|
---|
| 1107 | * @param feature Feature to be checked
|
---|
| 1108 | *
|
---|
| 1109 | * @return True, if filesystem supports the feature
|
---|
| 1110 | *
|
---|
[9fc72fb3] | 1111 | */
|
---|
[38542dc] | 1112 | bool ext4_superblock_has_feature_read_only(ext4_superblock_t *sb,
|
---|
| 1113 | uint32_t feature)
|
---|
[c25e39b] | 1114 | {
|
---|
[38542dc] | 1115 | if (ext4_superblock_get_features_read_only(sb) & feature)
|
---|
[c25e39b] | 1116 | return true;
|
---|
[a35b458] | 1117 |
|
---|
[c25e39b] | 1118 | return false;
|
---|
| 1119 | }
|
---|
| 1120 |
|
---|
[2226cc3] | 1121 | /** Read superblock directly from block device.
|
---|
[9fc72fb3] | 1122 | *
|
---|
[38542dc] | 1123 | * @param service_id Block device identifier
|
---|
| 1124 | * @param sb Output pointer to memory structure
|
---|
| 1125 | *
|
---|
| 1126 | * @return Eerror code.
|
---|
| 1127 | *
|
---|
[9fc72fb3] | 1128 | */
|
---|
[b7fd2a0] | 1129 | errno_t ext4_superblock_read_direct(service_id_t service_id, ext4_superblock_t **sb)
|
---|
[01ab41b] | 1130 | {
|
---|
[06d85e5] | 1131 | /* Allocated memory for superblock structure */
|
---|
[d9bbe45] | 1132 | void *data = malloc(EXT4_SUPERBLOCK_SIZE);
|
---|
[38542dc] | 1133 | if (data == NULL)
|
---|
[01ab41b] | 1134 | return ENOMEM;
|
---|
[a35b458] | 1135 |
|
---|
[06d85e5] | 1136 | /* Read data from block device */
|
---|
[b7fd2a0] | 1137 | errno_t rc = block_read_bytes_direct(service_id, EXT4_SUPERBLOCK_OFFSET,
|
---|
[01ab41b] | 1138 | EXT4_SUPERBLOCK_SIZE, data);
|
---|
[a35b458] | 1139 |
|
---|
[01ab41b] | 1140 | if (rc != EOK) {
|
---|
| 1141 | free(data);
|
---|
| 1142 | return rc;
|
---|
| 1143 | }
|
---|
[a35b458] | 1144 |
|
---|
[06d85e5] | 1145 | /* Set output value */
|
---|
[2226cc3] | 1146 | (*sb) = data;
|
---|
[a35b458] | 1147 |
|
---|
[01ab41b] | 1148 | return EOK;
|
---|
| 1149 | }
|
---|
| 1150 |
|
---|
[2226cc3] | 1151 | /** Write superblock structure directly to block device.
|
---|
[9fc72fb3] | 1152 | *
|
---|
[38542dc] | 1153 | * @param service_id Block device identifier
|
---|
| 1154 | * @param sb Superblock to be written
|
---|
| 1155 | *
|
---|
| 1156 | * @return Error code
|
---|
| 1157 | *
|
---|
[9fc72fb3] | 1158 | */
|
---|
[b7fd2a0] | 1159 | errno_t ext4_superblock_write_direct(service_id_t service_id, ext4_superblock_t *sb)
|
---|
[ae3d4f8] | 1160 | {
|
---|
[06d85e5] | 1161 | /* Load physical block size from block device */
|
---|
[38542dc] | 1162 | size_t phys_block_size;
|
---|
[b7fd2a0] | 1163 | errno_t rc = block_get_bsize(service_id, &phys_block_size);
|
---|
[38542dc] | 1164 | if (rc != EOK)
|
---|
[ae3d4f8] | 1165 | return rc;
|
---|
[a35b458] | 1166 |
|
---|
[06d85e5] | 1167 | /* Compute address of the first block */
|
---|
[d9bbe45] | 1168 | uint64_t first_block = EXT4_SUPERBLOCK_OFFSET / phys_block_size;
|
---|
[a35b458] | 1169 |
|
---|
[06d85e5] | 1170 | /* Compute number of block to write */
|
---|
[80bd676] | 1171 | size_t block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;
|
---|
[a35b458] | 1172 |
|
---|
[06d85e5] | 1173 | /* Check alignment */
|
---|
[38542dc] | 1174 | if (EXT4_SUPERBLOCK_SIZE % phys_block_size)
|
---|
[ae3d4f8] | 1175 | block_count++;
|
---|
[a35b458] | 1176 |
|
---|
[06d85e5] | 1177 | /* Write data */
|
---|
[ae3d4f8] | 1178 | return block_write_direct(service_id, first_block, block_count, sb);
|
---|
| 1179 | }
|
---|
| 1180 |
|
---|
[eb94d84] | 1181 | /** Release the memory allocated for the superblock structure
|
---|
| 1182 | *
|
---|
| 1183 | * @param sb Superblock to be freed
|
---|
| 1184 | *
|
---|
| 1185 | */
|
---|
| 1186 | void ext4_superblock_release(ext4_superblock_t *sb)
|
---|
| 1187 | {
|
---|
| 1188 | free(sb);
|
---|
| 1189 | }
|
---|
| 1190 |
|
---|
[5b26747] | 1191 | /** Check sanity of the superblock.
|
---|
[9fc72fb3] | 1192 | *
|
---|
[5b26747] | 1193 | * This check is performed at mount time.
|
---|
| 1194 | * Checks are described by one-line comments in the code.
|
---|
| 1195 | *
|
---|
[38542dc] | 1196 | * @param sb Superblock to check
|
---|
| 1197 | *
|
---|
| 1198 | * @return Error code
|
---|
| 1199 | *
|
---|
[9fc72fb3] | 1200 | */
|
---|
[b7fd2a0] | 1201 | errno_t ext4_superblock_check_sanity(ext4_superblock_t *sb)
|
---|
[01ab41b] | 1202 | {
|
---|
[38542dc] | 1203 | if (ext4_superblock_get_magic(sb) != EXT4_SUPERBLOCK_MAGIC)
|
---|
[9c0c0e1] | 1204 | return ENOTSUP;
|
---|
[a35b458] | 1205 |
|
---|
[38542dc] | 1206 | if (ext4_superblock_get_inodes_count(sb) == 0)
|
---|
[fb04cd90] | 1207 | return ENOTSUP;
|
---|
[a35b458] | 1208 |
|
---|
[38542dc] | 1209 | if (ext4_superblock_get_blocks_count(sb) == 0)
|
---|
[fb04cd90] | 1210 | return ENOTSUP;
|
---|
[a35b458] | 1211 |
|
---|
[38542dc] | 1212 | if (ext4_superblock_get_blocks_per_group(sb) == 0)
|
---|
[fb04cd90] | 1213 | return ENOTSUP;
|
---|
[a35b458] | 1214 |
|
---|
[38542dc] | 1215 | if (ext4_superblock_get_inodes_per_group(sb) == 0)
|
---|
[fb04cd90] | 1216 | return ENOTSUP;
|
---|
[a35b458] | 1217 |
|
---|
[38542dc] | 1218 | if (ext4_superblock_get_inode_size(sb) < 128)
|
---|
[fb04cd90] | 1219 | return ENOTSUP;
|
---|
[a35b458] | 1220 |
|
---|
[38542dc] | 1221 | if (ext4_superblock_get_first_inode(sb) < 11)
|
---|
[fb04cd90] | 1222 | return ENOTSUP;
|
---|
[a35b458] | 1223 |
|
---|
[38542dc] | 1224 | if (ext4_superblock_get_desc_size(sb) <
|
---|
| 1225 | EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
|
---|
[fb04cd90] | 1226 | return ENOTSUP;
|
---|
[a35b458] | 1227 |
|
---|
[38542dc] | 1228 | if (ext4_superblock_get_desc_size(sb) >
|
---|
| 1229 | EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE)
|
---|
[fb04cd90] | 1230 | return ENOTSUP;
|
---|
[a35b458] | 1231 |
|
---|
[01ab41b] | 1232 | return EOK;
|
---|
| 1233 | }
|
---|
[eb91db7] | 1234 |
|
---|
[2226cc3] | 1235 | /** Compute number of block groups in the filesystem.
|
---|
[9fc72fb3] | 1236 | *
|
---|
[38542dc] | 1237 | * @param sb Superblock
|
---|
| 1238 | *
|
---|
| 1239 | * @return Number of block groups
|
---|
| 1240 | *
|
---|
[9fc72fb3] | 1241 | */
|
---|
[b12ca16] | 1242 | uint32_t ext4_superblock_get_block_group_count(ext4_superblock_t *sb)
|
---|
| 1243 | {
|
---|
| 1244 | uint64_t blocks_count = ext4_superblock_get_blocks_count(sb);
|
---|
| 1245 | uint32_t blocks_per_group = ext4_superblock_get_blocks_per_group(sb);
|
---|
[a35b458] | 1246 |
|
---|
[b12ca16] | 1247 | uint32_t block_groups_count = blocks_count / blocks_per_group;
|
---|
[a35b458] | 1248 |
|
---|
[38542dc] | 1249 | if (blocks_count % blocks_per_group)
|
---|
[b12ca16] | 1250 | block_groups_count++;
|
---|
[a35b458] | 1251 |
|
---|
[b12ca16] | 1252 | return block_groups_count;
|
---|
| 1253 | }
|
---|
| 1254 |
|
---|
[2226cc3] | 1255 | /** Compute number of blocks in specified block group.
|
---|
[9fc72fb3] | 1256 | *
|
---|
[38542dc] | 1257 | * @param sb Superblock
|
---|
| 1258 | * @param bgid Block group index
|
---|
| 1259 | *
|
---|
| 1260 | * @return Number of blocks
|
---|
| 1261 | *
|
---|
[9fc72fb3] | 1262 | */
|
---|
[b12ca16] | 1263 | uint32_t ext4_superblock_get_blocks_in_group(ext4_superblock_t *sb, uint32_t bgid)
|
---|
| 1264 | {
|
---|
[38542dc] | 1265 | uint32_t block_group_count =
|
---|
| 1266 | ext4_superblock_get_block_group_count(sb);
|
---|
| 1267 | uint32_t blocks_per_group =
|
---|
| 1268 | ext4_superblock_get_blocks_per_group(sb);
|
---|
| 1269 | uint64_t total_blocks =
|
---|
| 1270 | ext4_superblock_get_blocks_count(sb);
|
---|
[a35b458] | 1271 |
|
---|
[38542dc] | 1272 | if (bgid < block_group_count - 1)
|
---|
[b12ca16] | 1273 | return blocks_per_group;
|
---|
[38542dc] | 1274 | else
|
---|
[b12ca16] | 1275 | return (total_blocks - ((block_group_count - 1) * blocks_per_group));
|
---|
| 1276 | }
|
---|
| 1277 |
|
---|
[2226cc3] | 1278 | /** Compute number of i-nodes in specified block group.
|
---|
[9fc72fb3] | 1279 | *
|
---|
[38542dc] | 1280 | * @param sb Superblock
|
---|
| 1281 | * @param bgid Block group index
|
---|
| 1282 | *
|
---|
| 1283 | * @return Number of i-nodes
|
---|
| 1284 | *
|
---|
[9fc72fb3] | 1285 | */
|
---|
[b12ca16] | 1286 | uint32_t ext4_superblock_get_inodes_in_group(ext4_superblock_t *sb, uint32_t bgid)
|
---|
| 1287 | {
|
---|
[38542dc] | 1288 | uint32_t block_group_count =
|
---|
| 1289 | ext4_superblock_get_block_group_count(sb);
|
---|
| 1290 | uint32_t inodes_per_group =
|
---|
| 1291 | ext4_superblock_get_inodes_per_group(sb);
|
---|
| 1292 | uint32_t total_inodes =
|
---|
| 1293 | ext4_superblock_get_inodes_count(sb);
|
---|
[a35b458] | 1294 |
|
---|
[38542dc] | 1295 | if (bgid < block_group_count - 1)
|
---|
[b12ca16] | 1296 | return inodes_per_group;
|
---|
[38542dc] | 1297 | else
|
---|
[b12ca16] | 1298 | return (total_inodes - ((block_group_count - 1) * inodes_per_group));
|
---|
| 1299 | }
|
---|
| 1300 |
|
---|
[6dd7f65] | 1301 | /** Get the backup groups used with SPARSE_SUPER2
|
---|
| 1302 | *
|
---|
| 1303 | * @param sb Pointer to the superblock
|
---|
| 1304 | * @param g1 Output pointer to the first backup group
|
---|
| 1305 | * @param g2 Output pointer to the second backup group
|
---|
| 1306 | */
|
---|
| 1307 | void ext4_superblock_get_backup_groups_sparse2(ext4_superblock_t *sb,
|
---|
| 1308 | uint32_t *g1, uint32_t *g2)
|
---|
| 1309 | {
|
---|
| 1310 | *g1 = uint32_t_le2host(sb->backup_bgs[0]);
|
---|
| 1311 | *g2 = uint32_t_le2host(sb->backup_bgs[1]);
|
---|
| 1312 | }
|
---|
| 1313 |
|
---|
| 1314 | /** Set the backup groups (SPARSE SUPER2)
|
---|
| 1315 | *
|
---|
| 1316 | * @param sb Pointer to the superblock
|
---|
| 1317 | * @param g1 Index of the first group
|
---|
| 1318 | * @param g2 Index of the second group
|
---|
| 1319 | */
|
---|
| 1320 | void ext4_superblock_set_backup_groups_sparse2(ext4_superblock_t *sb,
|
---|
| 1321 | uint32_t g1, uint32_t g2)
|
---|
| 1322 | {
|
---|
| 1323 | sb->backup_bgs[0] = host2uint32_t_le(g1);
|
---|
| 1324 | sb->backup_bgs[1] = host2uint32_t_le(g2);
|
---|
| 1325 | }
|
---|
| 1326 |
|
---|
| 1327 | /** Get the number of blocks (per group) reserved to GDT expansion
|
---|
| 1328 | *
|
---|
| 1329 | * @param sb Pointer to the superblock
|
---|
| 1330 | *
|
---|
| 1331 | * @return Number of blocks
|
---|
| 1332 | */
|
---|
| 1333 | uint32_t ext4_superblock_get_reserved_gdt_blocks(ext4_superblock_t *sb)
|
---|
| 1334 | {
|
---|
| 1335 | return uint32_t_le2host(sb->reserved_gdt_blocks);
|
---|
| 1336 | }
|
---|
| 1337 |
|
---|
| 1338 | /** Set the number of blocks (per group) reserved to GDT expansion
|
---|
| 1339 | *
|
---|
| 1340 | * @param sb Pointer to the superblock
|
---|
| 1341 | * @param n Number of reserved blocks
|
---|
| 1342 | */
|
---|
| 1343 | void ext4_superblock_set_reserved_gdt_blocks(ext4_superblock_t *sb,
|
---|
| 1344 | uint32_t n)
|
---|
| 1345 | {
|
---|
| 1346 | sb->reserved_gdt_blocks = host2uint32_t_le(n);
|
---|
| 1347 | }
|
---|
| 1348 |
|
---|
[eb91db7] | 1349 | /**
|
---|
| 1350 | * @}
|
---|
[38542dc] | 1351 | */
|
---|