| 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_BLOCK_GROUP_H_
|
|---|
| 34 | #define LIBEXT4_LIBEXT4_BLOCK_GROUP_H_
|
|---|
| 35 |
|
|---|
| 36 | #include <libblock.h>
|
|---|
| 37 | #include <sys/types.h>
|
|---|
| 38 | #include "libext4_block_group.h"
|
|---|
| 39 | /*
|
|---|
| 40 | * Structure of a blocks group descriptor
|
|---|
| 41 | */
|
|---|
| 42 | typedef struct ext4_block_group {
|
|---|
| 43 | uint32_t block_bitmap_lo; // Blocks bitmap block
|
|---|
| 44 | uint32_t inode_bitmap_lo; // Inodes bitmap block
|
|---|
| 45 | uint32_t inode_table_first_block_lo; // Inodes table block
|
|---|
| 46 | uint16_t free_blocks_count_lo; // Free blocks count
|
|---|
| 47 | uint16_t free_inodes_count_lo; // Free inodes count
|
|---|
| 48 | uint16_t used_dirs_count_lo; // Directories count
|
|---|
| 49 | uint16_t flags; // EXT4_BG_flags (INODE_UNINIT, etc)
|
|---|
| 50 | uint32_t reserved[2]; // Likely block/inode bitmap checksum
|
|---|
| 51 | uint16_t itable_unused_lo; // Unused inodes count
|
|---|
| 52 | uint16_t checksum; // crc16(sb_uuid+group+desc)
|
|---|
| 53 | uint32_t block_bitmap_hi; // Blocks bitmap block MSB
|
|---|
| 54 | uint32_t inode_bitmap_hi; // Inodes bitmap block MSB
|
|---|
| 55 | uint32_t inode_table_first_block_hi; // Inodes table block MSB
|
|---|
| 56 | uint16_t free_blocks_count_hi; // Free blocks count MSB
|
|---|
| 57 | uint16_t free_inodes_count_hi; // Free inodes count MSB
|
|---|
| 58 | uint16_t used_dirs_count_hi; // Directories count MSB
|
|---|
| 59 | uint16_t itable_unused_hi; // Unused inodes count MSB
|
|---|
| 60 | uint32_t reserved2[3]; // Padding
|
|---|
| 61 | } ext4_block_group_t;
|
|---|
| 62 |
|
|---|
| 63 | typedef struct ext4_block_group_ref {
|
|---|
| 64 | block_t *block; // Reference to a block containing this block group descr
|
|---|
| 65 | ext4_block_group_t *block_group;
|
|---|
| 66 | } ext4_block_group_ref_t;
|
|---|
| 67 |
|
|---|
| 68 | // TODO check value
|
|---|
| 69 | #define EXT4_BLOCK_GROUP_DESCRIPTOR_SIZE 32
|
|---|
| 70 |
|
|---|
| 71 | extern uint64_t ext4_block_group_get_block_bitmap(ext4_block_group_t *);
|
|---|
| 72 | extern uint64_t ext4_block_group_get_inode_bitmap(ext4_block_group_t *);
|
|---|
| 73 | extern uint64_t ext4_block_group_get_inode_table_first_block(ext4_block_group_t *);
|
|---|
| 74 | extern uint32_t ext4_block_group_get_free_blocks_count(ext4_block_group_t *);
|
|---|
| 75 | extern uint32_t ext4_block_group_get_free_inodes_count(ext4_block_group_t *);
|
|---|
| 76 | extern uint32_t ext4_block_group_get_used_dirs_count(ext4_block_group_t *);
|
|---|
| 77 | extern uint16_t ext4_block_group_get_flags(ext4_block_group_t *);
|
|---|
| 78 | extern uint32_t ext4_block_group_get_itable_unused(ext4_block_group_t *);
|
|---|
| 79 | extern uint16_t ext4_block_group_get_checksum(ext4_block_group_t *);
|
|---|
| 80 |
|
|---|
| 81 | #endif
|
|---|
| 82 |
|
|---|
| 83 | /**
|
|---|
| 84 | * @}
|
|---|
| 85 | */
|
|---|