[eb91db7] | 1 | /*
|
---|
[f22d5ef0] | 2 | * Copyright (c) 2012 Frantisek Princ
|
---|
[eb91db7] | 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 | * @{
|
---|
[9875711] | 31 | */
|
---|
[eb91db7] | 32 |
|
---|
| 33 | #ifndef LIBEXT4_LIBEXT4_SUPERBLOCK_H_
|
---|
| 34 | #define LIBEXT4_LIBEXT4_SUPERBLOCK_H_
|
---|
| 35 |
|
---|
[01ab41b] | 36 | #include <libblock.h>
|
---|
[9875711] | 37 | #include <sys/types.h>
|
---|
| 38 |
|
---|
[b53a733] | 39 | #include "libext4_types.h"
|
---|
[7bc4508] | 40 |
|
---|
[3712434] | 41 | extern uint32_t ext4_superblock_get_inodes_count(ext4_superblock_t *);
|
---|
[fe27eb4] | 42 | extern void ext4_superblock_set_inodes_count(ext4_superblock_t *, uint32_t);
|
---|
[3712434] | 43 | extern uint64_t ext4_superblock_get_blocks_count(ext4_superblock_t *);
|
---|
[fe27eb4] | 44 | extern void ext4_superblock_set_blocks_count(ext4_superblock_t *, uint64_t);
|
---|
[3712434] | 45 | extern uint64_t ext4_superblock_get_reserved_blocks_count(ext4_superblock_t *);
|
---|
[fe27eb4] | 46 | extern void ext4_superblock_set_reserved_blocks_count(ext4_superblock_t *, uint64_t);
|
---|
[3712434] | 47 | extern uint64_t ext4_superblock_get_free_blocks_count(ext4_superblock_t *);
|
---|
[ae3d4f8] | 48 | extern void ext4_superblock_set_free_blocks_count(ext4_superblock_t *, uint64_t);
|
---|
[3712434] | 49 | extern uint32_t ext4_superblock_get_free_inodes_count(ext4_superblock_t *);
|
---|
[fe27eb4] | 50 | extern void ext4_superblock_set_free_inodes_count(ext4_superblock_t *, uint32_t);
|
---|
[3712434] | 51 | extern uint32_t ext4_superblock_get_first_data_block(ext4_superblock_t *);
|
---|
[fe27eb4] | 52 | extern void ext4_superblock_set_first_data_block(ext4_superblock_t *, uint32_t);
|
---|
[3712434] | 53 | extern uint32_t ext4_superblock_get_log_block_size(ext4_superblock_t *);
|
---|
[fe27eb4] | 54 | extern void ext4_superblock_set_log_block_size(ext4_superblock_t *, uint32_t);
|
---|
[01ab41b] | 55 | extern uint32_t ext4_superblock_get_block_size(ext4_superblock_t *);
|
---|
[fe27eb4] | 56 | extern void ext4_superblock_set_block_size(ext4_superblock_t *, uint32_t);
|
---|
[3712434] | 57 | extern uint32_t ext4_superblock_get_blocks_per_group(ext4_superblock_t *);
|
---|
[fe27eb4] | 58 | extern void ext4_superblock_set_blocks_per_group(ext4_superblock_t *, uint32_t);
|
---|
[3712434] | 59 | extern uint32_t ext4_superblock_get_inodes_per_group(ext4_superblock_t *);
|
---|
[fe27eb4] | 60 | extern void ext4_superblock_set_inodes_per_group(ext4_superblock_t *, uint32_t);
|
---|
[3712434] | 61 | extern uint32_t ext4_superblock_get_mount_time(ext4_superblock_t *);
|
---|
[fe27eb4] | 62 | extern void ext4_superblock_set_mount_time(ext4_superblock_t *, uint32_t);
|
---|
[3712434] | 63 | extern uint32_t ext4_superblock_get_write_time(ext4_superblock_t *);
|
---|
[fe27eb4] | 64 | extern void ext4_superblock_set_write_time(ext4_superblock_t *, uint32_t);
|
---|
[3712434] | 65 | extern uint16_t ext4_superblock_get_mount_count(ext4_superblock_t *);
|
---|
[fe27eb4] | 66 | extern void ext4_superblock_set_mount_count(ext4_superblock_t *, uint16_t);
|
---|
[3712434] | 67 | extern uint16_t ext4_superblock_get_max_mount_count(ext4_superblock_t *);
|
---|
[fe27eb4] | 68 | extern void ext4_superblock_set_max_mount_count(ext4_superblock_t *, uint16_t);
|
---|
[3712434] | 69 | extern uint16_t ext4_superblock_get_magic(ext4_superblock_t *);
|
---|
| 70 | extern uint16_t ext4_superblock_get_state(ext4_superblock_t *);
|
---|
[fe27eb4] | 71 | extern void ext4_superblock_set_state(ext4_superblock_t *, uint16_t);
|
---|
[3712434] | 72 | extern uint16_t ext4_superblock_get_errors(ext4_superblock_t *);
|
---|
[fe27eb4] | 73 | extern void ext4_superblock_set_errors(ext4_superblock_t *, uint16_t);
|
---|
[3712434] | 74 | extern uint16_t ext4_superblock_get_minor_rev_level(ext4_superblock_t *);
|
---|
[fe27eb4] | 75 | extern void ext4_superblock_set_minor_rev_level(ext4_superblock_t *, uint16_t);
|
---|
[3712434] | 76 | extern uint32_t ext4_superblock_get_last_check_time(ext4_superblock_t *);
|
---|
[fe27eb4] | 77 | extern void ext4_superblock_set_last_check_time(ext4_superblock_t *, uint32_t);
|
---|
[3712434] | 78 | extern uint32_t ext4_superblock_get_check_interval(ext4_superblock_t *);
|
---|
[fe27eb4] | 79 | extern void ext4_superblock_set_check_interval(ext4_superblock_t *, uint32_t);
|
---|
[3712434] | 80 | extern uint32_t ext4_superblock_get_creator_os(ext4_superblock_t *);
|
---|
[fe27eb4] | 81 | extern void ext4_superblock_set_creator_os(ext4_superblock_t *, uint32_t);
|
---|
[3712434] | 82 | extern uint32_t ext4_superblock_get_rev_level(ext4_superblock_t *);
|
---|
[fe27eb4] | 83 | extern void ext4_superblock_set_rev_level(ext4_superblock_t *, uint32_t);
|
---|
| 84 | extern uint16_t ext4_superblock_get_def_resuid(ext4_superblock_t *);
|
---|
| 85 | extern void ext4_superblock_set_def_resuid(ext4_superblock_t *, uint16_t);
|
---|
| 86 | extern uint16_t ext4_superblock_get_def_resgid(ext4_superblock_t *);
|
---|
| 87 | extern void ext4_superblock_set_def_resgid(ext4_superblock_t *, uint16_t);
|
---|
[3712434] | 88 | extern uint32_t ext4_superblock_get_first_inode(ext4_superblock_t *);
|
---|
[fe27eb4] | 89 | extern void ext4_superblock_set_first_inode(ext4_superblock_t *, uint32_t);
|
---|
[3712434] | 90 | extern uint16_t ext4_superblock_get_inode_size(ext4_superblock_t *);
|
---|
[fe27eb4] | 91 | extern void ext4_superblock_set_inode_size(ext4_superblock_t *, uint16_t);
|
---|
[3712434] | 92 | extern uint16_t ext4_superblock_get_block_group_number(ext4_superblock_t *);
|
---|
[fe27eb4] | 93 | extern void ext4_superblock_set_block_group_number(ext4_superblock_t *, uint16_t);
|
---|
[9c0c0e1] | 94 | extern uint32_t ext4_superblock_get_features_compatible(ext4_superblock_t *);
|
---|
[fe27eb4] | 95 | extern void ext4_superblock_set_features_compatible(ext4_superblock_t *, uint32_t);
|
---|
[9c0c0e1] | 96 | extern uint32_t ext4_superblock_get_features_incompatible(ext4_superblock_t *);
|
---|
[fe27eb4] | 97 | extern void ext4_superblock_set_features_incompatible(ext4_superblock_t *, uint32_t);
|
---|
[9c0c0e1] | 98 | extern uint32_t ext4_superblock_get_features_read_only(ext4_superblock_t *);
|
---|
[fe27eb4] | 99 | extern void ext4_superblock_set_features_read_only(ext4_superblock_t *, uint32_t);
|
---|
[01ab41b] | 100 |
|
---|
[3712434] | 101 | /*
|
---|
| 102 | uint8_t s_uuid[16]; // 128-bit uuid for volume
|
---|
| 103 | char volume_name[16]; // Volume name
|
---|
| 104 | char last_mounted[64]; // Directory where last mounted
|
---|
| 105 | uint32_t s_algorithm_usage_bitmap; // For compression
|
---|
| 106 | uint8_t s_prealloc_blocks; // Number of blocks to try to preallocate
|
---|
| 107 | uint8_t s_prealloc_dir_blocks; // Number to preallocate for dirs
|
---|
| 108 | uint16_t s_reserved_gdt_blocks; // Per group desc for online growth
|
---|
| 109 | uint8_t s_journal_uuid[16]; // UUID of journal superblock
|
---|
| 110 | uint32_t s_journal_inum; // Inode number of journal file
|
---|
| 111 | uint32_t s_journal_dev; // Device number of journal file
|
---|
[7bc4508] | 112 | */
|
---|
[ebcaff4] | 113 | extern uint32_t ext4_superblock_get_last_orphan(ext4_superblock_t *);
|
---|
| 114 | extern void ext4_superblock_set_last_orphan(ext4_superblock_t *, uint32_t);
|
---|
[7bc4508] | 115 | extern uint32_t* ext4_superblock_get_hash_seed(ext4_superblock_t *);
|
---|
[7eb033ce] | 116 | extern uint8_t ext4_superblock_get_default_hash_version(ext4_superblock_t *);
|
---|
| 117 | extern void ext4_superblock_set_default_hash_version(ext4_superblock_t *, uint8_t);
|
---|
[7bc4508] | 118 | /*
|
---|
[3712434] | 119 | uint8_t s_jnl_backup_type;
|
---|
[c25e39b] | 120 | */
|
---|
| 121 |
|
---|
| 122 | extern uint16_t ext4_superblock_get_desc_size(ext4_superblock_t *);
|
---|
[fe27eb4] | 123 | extern void ext4_superblock_set_desc_size(ext4_superblock_t *, uint16_t);
|
---|
[c25e39b] | 124 |
|
---|
| 125 | /*
|
---|
[3712434] | 126 | uint32_t s_default_mount_opts; // Default mount options
|
---|
| 127 | uint32_t s_first_meta_bg; // First metablock block group
|
---|
| 128 | uint32_t s_mkfs_time; // When the filesystem was created
|
---|
| 129 | uint32_t s_jnl_blocks[17]; // Backup of the journal inode
|
---|
| 130 | uint16_t s_min_extra_isize; // All inodes have at least # bytes
|
---|
| 131 | uint16_t s_want_extra_isize; // New inodes should reserve # bytes
|
---|
[7bc4508] | 132 | */
|
---|
| 133 | extern uint32_t ext4_superblock_get_flags(ext4_superblock_t *);
|
---|
[fe27eb4] | 134 | extern void ext4_superblock_set_flags(ext4_superblock_t *, uint32_t);
|
---|
[7bc4508] | 135 | /*
|
---|
[3712434] | 136 | uint16_t s_raid_stride; // RAID stride
|
---|
| 137 | uint16_t s_mmp_interval; // # seconds to wait in MMP checking
|
---|
| 138 | uint64_t s_mmp_block; // Block for multi-mount protection
|
---|
| 139 | uint32_t s_raid_stripe_width; // blocks on all data disks (N*stride)
|
---|
| 140 | uint8_t s_log_groups_per_flex; // FLEX_BG group size
|
---|
| 141 | uint8_t s_reserved_char_pad;
|
---|
| 142 | uint16_t s_reserved_pad;
|
---|
| 143 | uint64_t s_kbytes_written; // Number of lifetime kilobytes written
|
---|
| 144 | uint32_t s_snapshot_inum; // Inode number of active snapshot
|
---|
| 145 | uint32_t s_snapshot_id; // Sequential ID of active snapshot
|
---|
| 146 | uint64_t s_snapshot_r_blocks_count; // reserved blocks for active snapshot's future use
|
---|
| 147 | uint32_t s_snapshot_list; // inode number of the head of the on-disk snapshot list
|
---|
| 148 | uint32_t s_error_count; // number of fs errors
|
---|
| 149 | uint32_t s_first_error_time; // First time an error happened
|
---|
| 150 | uint32_t s_first_error_ino; // Inode involved in first error
|
---|
| 151 | uint64_t s_first_error_block; // block involved of first error
|
---|
| 152 | uint8_t s_first_error_func[32]; // Function where the error happened
|
---|
| 153 | uint32_t s_first_error_line; // Line number where error happened
|
---|
| 154 | uint32_t s_last_error_time; // Most recent time of an error
|
---|
| 155 | uint32_t s_last_error_ino; // Inode involved in last error
|
---|
| 156 | uint32_t s_last_error_line; // Line number where error happened
|
---|
| 157 | uint64_t s_last_error_block; // block involved of last error
|
---|
| 158 | uint8_t s_last_error_func[32]; // function where the error happened
|
---|
| 159 | uint8_t s_mount_opts[64];
|
---|
| 160 | */
|
---|
| 161 |
|
---|
| 162 | /* More complex superblock functions */
|
---|
[7bc4508] | 163 | extern bool ext4_superblock_has_flag(ext4_superblock_t *, uint32_t);
|
---|
[c25e39b] | 164 | extern bool ext4_superblock_has_feature_compatible(ext4_superblock_t *, uint32_t);
|
---|
| 165 | extern bool ext4_superblock_has_feature_incompatible(ext4_superblock_t *, uint32_t);
|
---|
| 166 | extern bool ext4_superblock_has_feature_read_only(ext4_superblock_t *, uint32_t);
|
---|
[01ab41b] | 167 | extern int ext4_superblock_read_direct(service_id_t, ext4_superblock_t **);
|
---|
[ae3d4f8] | 168 | extern int ext4_superblock_write_direct(service_id_t, ext4_superblock_t *);
|
---|
[01ab41b] | 169 | extern int ext4_superblock_check_sanity(ext4_superblock_t *);
|
---|
[eb91db7] | 170 |
|
---|
[b12ca16] | 171 | extern uint32_t ext4_superblock_get_block_group_count(ext4_superblock_t *);
|
---|
| 172 | extern uint32_t ext4_superblock_get_blocks_in_group(ext4_superblock_t *, uint32_t);
|
---|
| 173 | extern uint32_t ext4_superblock_get_inodes_in_group(ext4_superblock_t *, uint32_t);
|
---|
| 174 |
|
---|
[eb91db7] | 175 | #endif
|
---|
| 176 |
|
---|
| 177 | /**
|
---|
| 178 | * @}
|
---|
| 179 | */
|
---|