Changeset 38542dc in mainline for uspace/lib/ext4/libext4_superblock.c


Ignore:
Timestamp:
2012-08-12T18:36:10Z (12 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
49505fe
Parents:
b08e7970
Message:

ext4 code review and coding style cleanup

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/lib/ext4/libext4_superblock.c

    rb08e7970 r38542dc  
    2929/** @addtogroup libext4
    3030 * @{
    31  */ 
     31 */
    3232
    3333/**
    34  * @file        libext4_superblock.c
    35  * @brief       Ext4 superblock operations.
     34 * @file  libext4_superblock.c
     35 * @brief Ext4 superblock operations.
    3636 */
    3737
     
    4444/** Get number of i-nodes in the whole filesystem.
    4545 *
    46  * @param sb            superblock
    47  * @return                      number of i-nodes
     46 * @param sb Superblock
     47 *
     48 * @return Number of i-nodes
     49 *
    4850 */
    4951uint32_t ext4_superblock_get_inodes_count(ext4_superblock_t *sb)
     
    5456/** Set number of i-nodes in the whole filesystem.
    5557 *
    56  * @param sb            superblock
    57  * @param count         number of i-nodes
     58 * @param sb    Superblock
     59 * @param count Number of i-nodes
     60 *
    5861 */
    5962void ext4_superblock_set_inodes_count(ext4_superblock_t *sb, uint32_t count)
     
    6467/** Get number of data blocks in the whole filesystem.
    6568 *
    66  * @param sb            superblock
    67  * @return                      number of data blocks
     69 * @param sb Superblock
     70 *
     71 * @return Number of data blocks
     72 *
    6873 */
    6974uint64_t ext4_superblock_get_blocks_count(ext4_superblock_t *sb)
    7075{
    71         return ((uint64_t)uint32_t_le2host(sb->blocks_count_hi) << 32) |
    72                         uint32_t_le2host(sb->blocks_count_lo);
     76        return ((uint64_t) uint32_t_le2host(sb->blocks_count_hi) << 32) |
     77            uint32_t_le2host(sb->blocks_count_lo);
    7378}
    7479
    7580/** Set number of data blocks in the whole filesystem.
    7681 *
    77  * @param sb            superblock
    78  * @param count         number of data blocks
     82 * @param sb    Superblock
     83 * @param count Number of data blocks
     84 *
    7985 */
    8086void ext4_superblock_set_blocks_count(ext4_superblock_t *sb, uint64_t count)
     
    8692/** Get number of reserved data blocks in the whole filesystem.
    8793 *
    88  * @param sb            superblock
    89  * @return                      number of reserved data blocks
     94 * @param sb Superblock
     95 *
     96 * @return Number of reserved data blocks
     97 *
    9098 */
    9199uint64_t ext4_superblock_get_reserved_blocks_count(ext4_superblock_t *sb)
    92100{
    93         return ((uint64_t)uint32_t_le2host(sb->reserved_blocks_count_hi) << 32) |
    94                         uint32_t_le2host(sb->reserved_blocks_count_lo);
     101        return ((uint64_t)
     102            uint32_t_le2host(sb->reserved_blocks_count_hi) << 32) |
     103            uint32_t_le2host(sb->reserved_blocks_count_lo);
    95104}
    96105
    97106/** Set number of reserved data blocks in the whole filesystem.
    98107 *
    99  * @param sb            superblock
    100  * @param count         number of reserved data blocks
    101  */
    102 void ext4_superblock_set_reserved_blocks_count(ext4_superblock_t *sb, uint64_t count)
     108 * @param sb    Superblock
     109 * @param count Number of reserved data blocks
     110 *
     111 */
     112void ext4_superblock_set_reserved_blocks_count(ext4_superblock_t *sb,
     113    uint64_t count)
    103114{
    104115        sb->reserved_blocks_count_lo = host2uint32_t_le((count << 32) >> 32);
     
    108119/** Get number of free data blocks in the whole filesystem.
    109120 *
    110  * @param sb            superblock
    111  * @return                      number of free data blocks
     121 * @param sb Superblock
     122 *
     123 * @return Number of free data blocks
     124 *
    112125 */
    113126uint64_t ext4_superblock_get_free_blocks_count(ext4_superblock_t *sb)
    114127{
    115         return ((uint64_t)uint32_t_le2host(sb->free_blocks_count_hi) << 32) |
    116                         uint32_t_le2host(sb->free_blocks_count_lo);
     128        return ((uint64_t)
     129            uint32_t_le2host(sb->free_blocks_count_hi) << 32) |
     130            uint32_t_le2host(sb->free_blocks_count_lo);
    117131}
    118132
    119133/** Set number of free data blocks in the whole filesystem.
    120134 *
    121  * @param sb            superblock
    122  * @param count         number of free data blocks
    123  */
    124 void ext4_superblock_set_free_blocks_count(ext4_superblock_t *sb, uint64_t count)
     135 * @param sb    Superblock
     136 * @param count Number of free data blocks
     137 *
     138 */
     139void ext4_superblock_set_free_blocks_count(ext4_superblock_t *sb,
     140    uint64_t count)
    125141{
    126142        sb->free_blocks_count_lo = host2uint32_t_le((count << 32) >> 32);
     
    130146/** Get number of free i-nodes in the whole filesystem.
    131147 *
    132  * @param sb            superblock
    133  * @return                      number of free i-nodes
     148 * @param sb Superblock
     149 *
     150 * @return Number of free i-nodes
     151 *
    134152 */
    135153uint32_t ext4_superblock_get_free_inodes_count(ext4_superblock_t *sb)
     
    140158/** Set number of free i-nodes in the whole filesystem.
    141159 *
    142  * @param sb            superblock
    143  * @param count         number of free i-nodes
    144  */
    145 void ext4_superblock_set_free_inodes_count(ext4_superblock_t *sb, uint32_t count)
     160 * @param sb    Superblock
     161 * @param count Number of free i-nodes
     162 *
     163 */
     164void ext4_superblock_set_free_inodes_count(ext4_superblock_t *sb,
     165    uint32_t count)
    146166{
    147167        sb->free_inodes_count = host2uint32_t_le(count);
    148168}
    149169
    150 /** Get index of first data block (block, where is located superblock)
    151  *
    152  * @param sb            superblock
    153  * @return                      index of the first data block
     170/** Get index of first data block (block where the superblock is located)
     171 *
     172 * @param sb Superblock
     173 *
     174 * @return Index of the first data block
     175 *
    154176 */
    155177uint32_t ext4_superblock_get_first_data_block(ext4_superblock_t *sb)
     
    158180}
    159181
    160 /** Set index of first data block (block, where is located superblock)
    161  *
    162  * @param sb            superblock
    163  * @param first         index of the first data block
    164  */
    165 void ext4_superblock_set_first_data_block(ext4_superblock_t *sb, uint32_t first)
     182/** Set index of first data block (block where the superblock is located)
     183 *
     184 * @param sb    Superblock
     185 * @param first Index of the first data block
     186 *
     187 */
     188void ext4_superblock_set_first_data_block(ext4_superblock_t *sb,
     189    uint32_t first)
    166190{
    167191        sb->first_data_block = host2uint32_t_le(first);
     
    170194/** Get logarithmic block size (1024 << size == block_size)
    171195 *
    172  * @param sb            superblock
    173  * @return                      logarithmic block size
     196 * @param sb Superblock
     197 *
     198 * @return Logarithmic block size
     199 *
    174200 */
    175201uint32_t ext4_superblock_get_log_block_size(ext4_superblock_t *sb)
     
    180206/** Set logarithmic block size (1024 << size == block_size)
    181207 *
    182  * @param sb            superblock
    183  * @return                      logarithmic block size
    184  */
    185 void ext4_superblock_set_log_block_size(ext4_superblock_t *sb, uint32_t log_size)
     208 * @param sb Superblock
     209 *
     210 * @return Logarithmic block size
     211 *
     212 */
     213void ext4_superblock_set_log_block_size(ext4_superblock_t *sb,
     214    uint32_t log_size)
    186215{
    187216        sb->log_block_size = host2uint32_t_le(log_size);
     
    190219/** Get size of data block (in bytes).
    191220 *
    192  * @param sb            superblock
    193  * @return                      size of data block
     221 * @param sb Superblock
     222 *
     223 * @return Size of data block
     224 *
    194225 */
    195226uint32_t ext4_superblock_get_block_size(ext4_superblock_t *sb)
     
    200231/** Set size of data block (in bytes).
    201232 *
    202  * @param sb            superblock
    203  * @param size          size of data block (must be power of 2, at least 1024)
     233 * @param sb   Superblock
     234 * @param size Size of data block (must be power of 2, at least 1024)
     235 *
    204236 */
    205237void ext4_superblock_set_block_size(ext4_superblock_t *sb, uint32_t size)
     
    207239        uint32_t log = 0;
    208240        uint32_t tmp = size / EXT4_MIN_BLOCK_SIZE;
    209 
     241       
    210242        tmp >>= 1;
    211243        while (tmp) {
     
    213245                tmp >>= 1;
    214246        }
    215 
     247       
    216248        ext4_superblock_set_log_block_size(sb, log);
    217249}
     
    219251/** Get logarithmic fragment size (1024 << size)
    220252 *
    221  * @param sb            superblock
    222  * @return                      logarithmic fragment size
     253 * @param sb Superblock
     254 *
     255 * @return Logarithmic fragment size
     256 *
    223257 */
    224258uint32_t ext4_superblock_get_log_frag_size(ext4_superblock_t *sb)
     
    229263/** Set logarithmic fragment size (1024 << size)
    230264 *
    231  * @param sb            superblock
    232  * @return                      logarithmic fragment size
    233  */
    234 
    235 void ext4_superblock_set_log_frag_size(ext4_superblock_t *sb, uint32_t frag_size)
     265 * @param sb        Superblock
     266 * @param frag_size Logarithmic fragment size
     267 *
     268 */
     269void ext4_superblock_set_log_frag_size(ext4_superblock_t *sb,
     270    uint32_t frag_size)
    236271{
    237272        sb->log_frag_size = host2uint32_t_le(frag_size);
     
    240275/** Get size of fragment (in bytes).
    241276 *
    242  * @param sb            superblock
    243  * @return                      size of fragment
     277 * @param sb Superblock
     278 *
     279 * @return Size of fragment
     280 *
    244281 */
    245282uint32_t ext4_superblock_get_frag_size(ext4_superblock_t *sb)
     
    250287/** Set size of fragment (in bytes).
    251288 *
    252  * @param sb            superblock
    253  * @param size          size of fragment (must be power of 2, at least 1024)
     289 * @param sb   Superblock
     290 * @param size Size of fragment (must be power of 2, at least 1024)
     291 *
    254292 */
    255293void ext4_superblock_set_frag_size(ext4_superblock_t *sb, uint32_t size)
     
    257295        uint32_t log = 0;
    258296        uint32_t tmp = size / EXT4_MIN_BLOCK_SIZE;
    259 
     297       
    260298        tmp >>= 1;
    261299        while (tmp) {
     
    263301                tmp >>= 1;
    264302        }
    265 
     303       
    266304        ext4_superblock_set_log_frag_size(sb, log);
    267305}
     
    269307/** Get number of data blocks per block group (except last BG)
    270308 *
    271  * @param sb            superblock
    272  * @return                      data blocks per block group
     309 * @param sb Superblock
     310 *
     311 * @return Data blocks per block group
     312 *
    273313 */
    274314uint32_t ext4_superblock_get_blocks_per_group(ext4_superblock_t *sb)
     
    279319/** Set number of data blocks per block group (except last BG)
    280320 *
    281  * @param sb            superblock
    282  * @param blocks        data blocks per block group
    283  */
    284 void ext4_superblock_set_blocks_per_group(ext4_superblock_t *sb, uint32_t blocks)
     321 * @param sb     Superblock
     322 * @param blocks Data blocks per block group
     323 *
     324 */
     325void ext4_superblock_set_blocks_per_group(ext4_superblock_t *sb,
     326    uint32_t blocks)
    285327{
    286328        sb->blocks_per_group = host2uint32_t_le(blocks);
     
    289331/** Get number of fragments per block group (except last BG)
    290332 *
    291  * @param sb            superblock
    292  * @return                      fragments per block group
     333 * @param sb Superblock
     334 *
     335 * @return Fragments per block group
     336 *
    293337 */
    294338uint32_t ext4_superblock_get_frags_per_group(ext4_superblock_t *sb)
     
    299343/** Set number of fragment per block group (except last BG)
    300344 *
    301  * @param sb            superblock
    302  * @param frags         fragments per block group
     345 * @param sb    Superblock
     346 * @param frags Fragments per block group
    303347 */
    304348void ext4_superblock_set_frags_per_group(ext4_superblock_t *sb, uint32_t frags)
     
    307351}
    308352
    309 
    310353/** Get number of i-nodes per block group (except last BG)
    311354 *
    312  * @param sb            superblock
    313  * @return                      i-nodes per block group
     355 * @param sb Superblock
     356 *
     357 * @return I-nodes per block group
     358 *
    314359 */
    315360uint32_t ext4_superblock_get_inodes_per_group(ext4_superblock_t *sb)
     
    320365/** Set number of i-nodes per block group (except last BG)
    321366 *
    322  * @param sb            superblock
    323  * @param inodes        i-nodes per block group
    324  */
    325 void ext4_superblock_set_inodes_per_group(ext4_superblock_t *sb, uint32_t inodes)
     367 * @param sb     Superblock
     368 * @param inodes I-nodes per block group
     369 *
     370 */
     371void ext4_superblock_set_inodes_per_group(ext4_superblock_t *sb,
     372    uint32_t inodes)
    326373{
    327374        sb->inodes_per_group = host2uint32_t_le(inodes);
     
    330377/** Get time when filesystem was mounted (POSIX time).
    331378 *
    332  * @param sb            superblock
    333  * @return                      mount time
     379 * @param sb Superblock
     380 *
     381 * @return Mount time
     382 *
    334383 */
    335384uint32_t ext4_superblock_get_mount_time(ext4_superblock_t *sb)
     
    340389/** Set time when filesystem was mounted (POSIX time).
    341390 *
    342  * @param sb            superblock
    343  * @param time          mount time
     391 * @param sb   Superblock
     392 * @param time Mount time
     393 *
    344394 */
    345395void ext4_superblock_set_mount_time(ext4_superblock_t *sb, uint32_t time)
     
    350400/** Get time when filesystem was last accesed by write operation (POSIX time).
    351401 *
    352  * @param sb            superblock
    353  * @return                      write time
     402 * @param sb Superblock
     403 *
     404 * @return Write time
     405 *
    354406 */
    355407uint32_t ext4_superblock_get_write_time(ext4_superblock_t *sb)
     
    360412/** Set time when filesystem was last accesed by write operation (POSIX time).
    361413 *
    362  * @param sb            superblock
    363  * @param time          write time
     414 * @param sb   Superblock
     415 * @param time Write time
     416 *
    364417 */
    365418void ext4_superblock_set_write_time(ext4_superblock_t *sb, uint32_t time)
     
    370423/** Get number of mount from last filesystem check.
    371424 *
    372  * @param sb            superblock
    373  * @return                      number of mounts
     425 * @param sb Superblock
     426 *
     427 * @return Number of mounts
     428 *
    374429 */
    375430uint16_t ext4_superblock_get_mount_count(ext4_superblock_t *sb)
     
    380435/** Set number of mount from last filesystem check.
    381436 *
    382  * @param sb            superblock
    383  * @param count         number of mounts
     437 * @param sb    Superblock
     438 * @param count Number of mounts
     439 *
    384440 */
    385441void ext4_superblock_set_mount_count(ext4_superblock_t *sb, uint16_t count)
     
    390446/** Get maximum number of mount from last filesystem check.
    391447 *
    392  * @param sb            superblock
    393  * @return                      maximum number of mounts
     448 * @param sb Superblock
     449 *
     450 * @return Maximum number of mounts
     451 *
    394452 */
    395453uint16_t ext4_superblock_get_max_mount_count(ext4_superblock_t *sb)
     
    400458/** Set maximum number of mount from last filesystem check.
    401459 *
    402  * @param sb            superblock
    403  * @param count         maximum number of mounts
     460 * @param sb    Superblock
     461 * @param count Maximum number of mounts
     462 *
    404463 */
    405464void ext4_superblock_set_max_mount_count(ext4_superblock_t *sb, uint16_t count)
     
    410469/** Get superblock magic value.
    411470 *
    412  * @param sb            superblock
    413  * @return                      magic value
     471 * @param sb Superblock
     472 *
     473 * @return Magic value
     474 *
    414475 */
    415476uint16_t ext4_superblock_get_magic(ext4_superblock_t *sb)
     
    420481/** Set superblock magic value.
    421482 *
    422  * @param sb            superblock
    423  * @param                       magic value
     483 * @param sb    Superblock
     484 * @param magic Magic value
     485 *
    424486 */
    425487void ext4_superblock_set_magic(ext4_superblock_t *sb, uint16_t magic)
     
    430492/** Get filesystem state.
    431493 *
    432  * @param sb            superblock
    433  * @return                      filesystem state
     494 * @param sb Superblock
     495 *
     496 * @return Filesystem state
     497 *
    434498 */
    435499uint16_t ext4_superblock_get_state(ext4_superblock_t *sb)
     
    440504/** Set filesystem state.
    441505 *
    442  * @param sb            superblock
    443  * @param state         filesystem state
     506 * @param sb    Superblock
     507 * @param state Filesystem state
     508 *
    444509 */
    445510void ext4_superblock_set_state(ext4_superblock_t *sb, uint16_t state)
     
    450515/** Get behavior code when errors detected.
    451516 *
    452  * @param sb            superblock
    453  * @return                      behavior code
     517 * @param sb Superblock
     518 *
     519 * @return Behavior code
     520 *
    454521 */
    455522uint16_t ext4_superblock_get_errors(ext4_superblock_t *sb)
     
    460527/** Set behavior code when errors detected.
    461528 *
    462  * @param sb            superblock
    463  * @param errors        behavior code
     529 * @param sb     Superblock
     530 * @param errors Behavior code
     531 *
    464532 */
    465533void ext4_superblock_set_errors(ext4_superblock_t *sb, uint16_t errors)
     
    470538/** Get minor revision level of the filesystem.
    471539 *
    472  * @param sb            superblock
    473  * @return                      minor revision level
     540 * @param sb Superblock
     541 *
     542 * @return Minor revision level
     543 *
    474544 */
    475545uint16_t ext4_superblock_get_minor_rev_level(ext4_superblock_t *sb)
     
    480550/** Set minor revision level of the filesystem.
    481551 *
    482  * @param sb            superblock
    483  * @param level         minor revision level
     552 * @param sb    Superblock
     553 * @param level Minor revision level
     554 *
    484555 */
    485556void ext4_superblock_set_minor_rev_level(ext4_superblock_t *sb, uint16_t level)
     
    490561/** Get time of the last filesystem check.
    491562 *
    492  * @param sb            superblock
    493  * @return                      time of the last check (POSIX)
     563 * @param sb Superblock
     564 *
     565 * @return Time of the last check (POSIX)
     566 *
    494567 */
    495568uint32_t ext4_superblock_get_last_check_time(ext4_superblock_t *sb)
     
    500573/** Set time of the last filesystem check.
    501574 *
    502  * @param sb            superblock
    503  * @param time          time of the last check (POSIX)
     575 * @param sb   Superblock
     576 * @param time Time of the last check (POSIX)
     577 *
    504578 */
    505579void ext4_superblock_set_last_check_time(ext4_superblock_t *sb, uint32_t time)
     
    510584/** Get maximum time interval between two filesystem checks.
    511585 *
    512  * @param sb            superblock
    513  * @return                      time interval between two check (POSIX)
    514  */
    515 uint32_t ext4_superblock_get_check_interval(ext4_superblock_t *sb){
     586 * @param sb Superblock
     587 *
     588 * @return Time interval between two check (POSIX)
     589 *
     590 */
     591uint32_t ext4_superblock_get_check_interval(ext4_superblock_t *sb)
     592{
    516593        return uint32_t_le2host(sb->check_interval);
    517594}
     
    519596/** Set maximum time interval between two filesystem checks.
    520597 *
    521  * @param sb                    superblock
    522  * @param interval              time interval between two check (POSIX)
     598 * @param sb       Superblock
     599 * @param interval Time interval between two check (POSIX)
     600 *
    523601 */
    524602void ext4_superblock_set_check_interval(ext4_superblock_t *sb, uint32_t interval)
     
    529607/** Get operation system identifier, on which the filesystem was created.
    530608 *
    531  * @param sb            superblock
    532  * @return                      operation system identifier
     609 * @param sb Superblock
     610 *
     611 * @return Operation system identifier
     612 *
    533613 */
    534614uint32_t ext4_superblock_get_creator_os(ext4_superblock_t *sb)
     
    539619/** Set operation system identifier, on which the filesystem was created.
    540620 *
    541  * @param sb            superblock
    542  * @param os            operation system identifier
     621 * @param sb Superblock
     622 * @param os Operation system identifier
     623 *
    543624 */
    544625void ext4_superblock_set_creator_os(ext4_superblock_t *sb, uint32_t os)
     
    549630/** Get revision level of the filesystem.
    550631 *
    551  * @param sb            superblock
    552  * @return                      revision level
     632 * @param sb Superblock
     633 *
     634 * @return Revision level
     635 *
    553636 */
    554637uint32_t ext4_superblock_get_rev_level(ext4_superblock_t *sb)
     
    559642/** Set revision level of the filesystem.
    560643 *
    561  * @param sb            superblock
    562  * @param level         revision level
     644 * @param sb    Superblock
     645 * @param level Revision level
     646 *
    563647 */
    564648void ext4_superblock_set_rev_level(ext4_superblock_t *sb, uint32_t level)
     
    569653/** Get default user id for reserved blocks.
    570654 *
    571  * @param sb            superblock
    572  * @return                      default user id for reserved blocks.
     655 * @param sb Superblock
     656 *
     657 * @return Default user id for reserved blocks.
     658 *
    573659 */
    574660uint16_t ext4_superblock_get_def_resuid(ext4_superblock_t *sb)
     
    579665/** Set default user id for reserved blocks.
    580666 *
    581  * @param sb            superblock
    582  * @param uid           default user id for reserved blocks.
     667 * @param sb  Superblock
     668 * @param uid Default user id for reserved blocks.
     669 *
    583670 */
    584671void ext4_superblock_set_def_resuid(ext4_superblock_t *sb, uint16_t uid)
     
    589676/** Get default group id for reserved blocks.
    590677 *
    591  * @param sb            superblock
    592  * @return                      default group id for reserved blocks.
     678 * @param sb Superblock
     679 *
     680 * @return Default group id for reserved blocks.
     681 *
    593682 */
    594683uint16_t ext4_superblock_get_def_resgid(ext4_superblock_t *sb)
     
    599688/** Set default group id for reserved blocks.
    600689 *
    601  * @param sb            superblock
    602  * @param gid           default group id for reserved blocks.
     690 * @param sb  Superblock
     691 * @param gid Default group id for reserved blocks.
     692 *
    603693 */
    604694void ext4_superblock_set_def_resgid(ext4_superblock_t *sb, uint16_t gid)
     
    609699/** Get index of the first i-node, which can be used for allocation.
    610700 *
    611  * @param sb            superblock
    612  * @return                      i-node index
     701 * @param sb Superblock
     702 *
     703 * @return I-node index
     704 *
    613705 */
    614706uint32_t ext4_superblock_get_first_inode(ext4_superblock_t *sb)
     
    619711/** Set index of the first i-node, which can be used for allocation.
    620712 *
    621  * @param sb                    superblock
    622  * @param first_inode   i-node index
    623  */
    624 void ext4_superblock_set_first_inode(ext4_superblock_t *sb, uint32_t first_inode)
     713 * @param sb          Superblock
     714 * @param first_inode I-node index
     715 *
     716 */
     717void ext4_superblock_set_first_inode(ext4_superblock_t *sb,
     718    uint32_t first_inode)
    625719{
    626720        sb->first_inode = host2uint32_t_le(first_inode);
     
    631725 * For the oldest revision return constant number.
    632726 *
    633  * @param sb                    superblock
    634  * @return                              size of i-node structure
     727 * @param sb Superblock
     728 *
     729 * @return Size of i-node structure
     730 *
    635731 */
    636732uint16_t ext4_superblock_get_inode_size(ext4_superblock_t *sb)
    637733{
    638         if (ext4_superblock_get_rev_level(sb) == 0) {
     734        if (ext4_superblock_get_rev_level(sb) == 0)
    639735                return EXT4_REV0_INODE_SIZE;
    640         }
     736       
    641737        return uint16_t_le2host(sb->inode_size);
    642738}
     
    644740/** Set size of i-node structure.
    645741 *
    646  * @param sb                    superblock
    647  * @param size                  size of i-node structure
     742 * @param sb   Superblock
     743 * @param size Size of i-node structure
     744 *
    648745 */
    649746void ext4_superblock_set_inode_size(ext4_superblock_t *sb, uint16_t size)
     
    654751/** Get index of block group, where superblock copy is located.
    655752 *
    656  * @param sb                    superblock
    657  * @return                              block group index
     753 * @param sb Superblock
     754 *
     755 * @return Block group index
     756 *
    658757 */
    659758uint16_t ext4_superblock_get_block_group_index(ext4_superblock_t *sb)
     
    664763/** Set index of block group, where superblock copy is located.
    665764 *
    666  * @param sb                    superblock
    667  * @param bgid                  block group index
     765 * @param sb   Superblock
     766 * @param bgid Block group index
     767 *
    668768 */
    669769void ext4_superblock_set_block_group_index(ext4_superblock_t *sb, uint16_t bgid)
     
    674774/** Get compatible features supported by the filesystem.
    675775 *
    676  * @param sb            superblock
    677  * @return                      compatible features bitmap
     776 * @param sb Superblock
     777 *
     778 * @return Compatible features bitmap
     779 *
    678780 */
    679781uint32_t ext4_superblock_get_features_compatible(ext4_superblock_t *sb)
     
    684786/** Set compatible features supported by the filesystem.
    685787 *
    686  * @param sb                    superblock
    687  * @param features              compatible features bitmap
    688  */
    689 void ext4_superblock_set_features_compatible(ext4_superblock_t *sb, uint32_t features)
     788 * @param sb       Superblock
     789 * @param features Compatible features bitmap
     790 *
     791 */
     792void ext4_superblock_set_features_compatible(ext4_superblock_t *sb,
     793    uint32_t features)
    690794{
    691795        sb->features_compatible = host2uint32_t_le(features);
     
    694798/** Get incompatible features supported by the filesystem.
    695799 *
    696  * @param sb            superblock
    697  * @return                      incompatible features bitmap
     800 * @param sb Superblock
     801 *
     802 * @return Incompatible features bitmap
     803 *
    698804 */
    699805uint32_t ext4_superblock_get_features_incompatible(ext4_superblock_t *sb)
     
    704810/** Set incompatible features supported by the filesystem.
    705811 *
    706  * @param sb                    superblock
    707  * @param features              incompatible features bitmap
    708  */
    709 void ext4_superblock_set_features_incompatible(ext4_superblock_t *sb, uint32_t features)
     812 * @param sb       Superblock
     813 * @param features Incompatible features bitmap
     814 *
     815 */
     816void ext4_superblock_set_features_incompatible(ext4_superblock_t *sb,
     817    uint32_t features)
    710818{
    711819        sb->features_incompatible = host2uint32_t_le(features);
     
    714822/** Get compatible features supported by the filesystem.
    715823 *
    716  * @param sb            superblock
    717  * @return                      read-only compatible features bitmap
     824 * @param sb Superblock
     825 *
     826 * @return Read-only compatible features bitmap
     827 *
    718828 */
    719829uint32_t ext4_superblock_get_features_read_only(ext4_superblock_t *sb)
     
    724834/** Set compatible features supported by the filesystem.
    725835 *
    726  * @param sb                    superblock
    727  * @param feature               read-only compatible features bitmap
    728  */
    729 void ext4_superblock_set_features_read_only(ext4_superblock_t *sb, uint32_t features)
     836 * @param sb      Superblock
     837 * @param feature Read-only compatible features bitmap
     838 *
     839 */
     840void ext4_superblock_set_features_read_only(ext4_superblock_t *sb,
     841    uint32_t features)
    730842{
    731843        sb->features_read_only = host2uint32_t_le(features);
     
    734846/** Get UUID of the filesystem.
    735847 *
    736  * @param sb            superblock
    737  * @return                      pointer to UUID array
    738  */
    739 const uint8_t * ext4_superblock_get_uuid(ext4_superblock_t *sb)
     848 * @param sb superblock
     849 *
     850 * @return Pointer to UUID array
     851 *
     852 */
     853const uint8_t *ext4_superblock_get_uuid(ext4_superblock_t *sb)
    740854{
    741855        return sb->uuid;
     
    744858/** Set UUID of the filesystem.
    745859 *
    746  * @param sb            superblock
    747  * @param uuid          pointer to UUID array
     860 * @param sb   Superblock
     861 * @param uuid Pointer to UUID array
     862 *
    748863 */
    749864void ext4_superblock_set_uuid(ext4_superblock_t *sb, const uint8_t *uuid)
     
    754869/** Get name of the filesystem volume.
    755870 *
    756  * @param sb            superblock
    757  * @return                      name of the volume
    758  */
    759 const char * ext4_superblock_get_volume_name(ext4_superblock_t *sb)
     871 * @param sb Superblock
     872 *
     873 * @return Name of the volume
     874 *
     875 */
     876const char *ext4_superblock_get_volume_name(ext4_superblock_t *sb)
    760877{
    761878        return sb->volume_name;
     
    764881/** Set name of the filesystem volume.
    765882 *
    766  * @param sb            superblock
    767  * @param name          new name of the volume
     883 * @param sb   Superblock
     884 * @param name New name of the volume
    768885 */
    769886void ext4_superblock_set_volume_name(ext4_superblock_t *sb, const char *name)
     
    774891/** Get name of the directory, where this filesystem was mounted at last.
    775892 *
    776  * @param sb            superblock
    777  * @return                      directory name
    778  */
    779 const char * ext4_superblock_get_last_mounted(ext4_superblock_t *sb)
     893 * @param sb Superblock
     894 *
     895 * @return Directory name
     896 *
     897 */
     898const char *ext4_superblock_get_last_mounted(ext4_superblock_t *sb)
    780899{
    781900        return sb->last_mounted;
     
    784903/** Set name of the directory, where this filesystem was mounted at last.
    785904 *
    786  * @param sb            superblock
    787  * @param last          directory name
     905 * @param sb   Superblock
     906 * @param last Directory name
     907 *
    788908 */
    789909void ext4_superblock_set_last_mounted(ext4_superblock_t *sb, const char *last)
     
    796916 * Orphans are stored in linked list.
    797917 *
    798  * @param sb            superblock
    799  * @return                      last orphaned i-node index
     918 * @param sb Superblock
     919 *
     920 * @return Last orphaned i-node index
     921 *
    800922 */
    801923uint32_t ext4_superblock_get_last_orphan(ext4_superblock_t *sb)
     
    808930 * Orphans are stored in linked list.
    809931 *
    810  * @param sb                    superblock
    811  * @param last_orphan   last orphaned i-node index
    812  */
    813 void ext4_superblock_set_last_orphan(ext4_superblock_t *sb, uint32_t last_orphan)
     932 * @param sb          Superblock
     933 * @param last_orphan Last orphaned i-node index
     934 *
     935 */
     936void ext4_superblock_set_last_orphan(ext4_superblock_t *sb,
     937    uint32_t last_orphan)
    814938{
    815939        sb->last_orphan = host2uint32_t_le(last_orphan);
     
    818942/** Get hash seed for directory index hash function.
    819943 *
    820  * @param sb            superblock
    821  * @return                      hash seed pointer
    822  */
    823 const uint32_t * ext4_superblock_get_hash_seed(ext4_superblock_t *sb)
     944 * @param sb Superblock
     945 *
     946 * @return Hash seed pointer
     947 *
     948 */
     949const uint32_t *ext4_superblock_get_hash_seed(ext4_superblock_t *sb)
    824950{
    825951        return sb->hash_seed;
     
    828954/** Set hash seed for directory index hash function.
    829955 *
    830  * @param sb            superblock
    831  * @param seed          hash seed pointer
     956 * @param sb   Superblock
     957 * @param seed Hash seed pointer
     958 *
    832959 */
    833960void ext4_superblock_set_hash_seed(ext4_superblock_t *sb, const uint32_t *seed)
     
    838965/** Get default version of the hash algorithm version for directory index.
    839966 *
    840  * @param sb            superblock
    841  * @return                      default hash version
     967 * @param sb Superblock
     968 *
     969 * @return Default hash version
     970 *
    842971 */
    843972uint8_t ext4_superblock_get_default_hash_version(ext4_superblock_t *sb)
     
    848977/** Set default version of the hash algorithm version for directory index.
    849978 *
    850  * @param sb            superblock
    851  * @param version       default hash version
    852  */
    853 void ext4_superblock_set_default_hash_version(ext4_superblock_t *sb, uint8_t version)
     979 * @param sb      Superblock
     980 * @param version Default hash version
     981 *
     982 */
     983void ext4_superblock_set_default_hash_version(ext4_superblock_t *sb,
     984    uint8_t version)
    854985{
    855986        sb->default_hash_version = version;
     
    860991 * Output value is checked for minimal size.
    861992 *
    862  * @param sb            superblock
    863  * @return                      size of block group descriptor
     993 * @param sb Superblock
     994 *
     995 * @return Size of block group descriptor
     996 *
    864997 */
    865998uint16_t ext4_superblock_get_desc_size(ext4_superblock_t *sb)
    866999{
    8671000        uint16_t size = uint16_t_le2host(sb->desc_size);
    868 
    869         if (size < EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
     1001       
     1002        if (size < EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
    8701003                size = EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE;
    871         }
    872 
     1004       
    8731005        return size;
    8741006}
     
    8781010 * Input value is checked for minimal size.
    8791011 *
    880  * @param sb            superblock
    881  * @param size          size of block group descriptor
     1012 * @param sb   Superblock
     1013 * @param size Size of block group descriptor
     1014 *
    8821015 */
    8831016void ext4_superblock_set_desc_size(ext4_superblock_t *sb, uint16_t size)
    8841017{
    885         if (size < EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
    886                 sb->desc_size = host2uint16_t_le(EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE);
    887         }
    888 
     1018        if (size < EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
     1019                sb->desc_size =
     1020                    host2uint16_t_le(EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE);
     1021       
    8891022        sb->desc_size = host2uint16_t_le(size);
    8901023}
     
    8921025/** Get superblock flags.
    8931026 *
    894  * @param sb            superblock
    895  * @return                      flags from the superblock
     1027 * @param sb Superblock
     1028 *
     1029 * @return Flags from the superblock
     1030 *
    8961031 */
    8971032uint32_t ext4_superblock_get_flags(ext4_superblock_t *sb)
     
    9021037/** Set superblock flags.
    9031038 *
    904  * @param sb            superblock
    905  * @param flags         flags for the superblock
     1039 * @param sb    Superblock
     1040 * @param flags Flags for the superblock
     1041 *
    9061042 */
    9071043void ext4_superblock_set_flags(ext4_superblock_t *sb, uint32_t flags)
     
    9161052/** Check if superblock has specified flag.
    9171053 *
    918  * @param sb                    superblock
    919  * @param flag                  flag to be checked
    920  * @return                              true, if superblock has the flag
     1054 * @param sb   Superblock
     1055 * @param flag Flag to be checked
     1056 *
     1057 * @return True, if superblock has the flag
     1058 *
    9211059 */
    9221060bool ext4_superblock_has_flag(ext4_superblock_t *sb, uint32_t flag)
    9231061{
    924         if (ext4_superblock_get_flags(sb) & flag) {
     1062        if (ext4_superblock_get_flags(sb) & flag)
    9251063                return true;
    926         }
     1064       
    9271065        return false;
    9281066}
     
    9301068/** Check if filesystem supports compatible feature.
    9311069 *
    932  * @param sb                    superblock
    933  * @param feature               feature to be checked
    934  * @return                              true, if filesystem supports the feature
    935  */
    936 bool ext4_superblock_has_feature_compatible(ext4_superblock_t *sb, uint32_t feature)
    937 {
    938         if (ext4_superblock_get_features_compatible(sb) & feature) {
     1070 * @param sb      Superblock
     1071 * @param feature Feature to be checked
     1072 *
     1073 * @return True, if filesystem supports the feature
     1074 *
     1075 */
     1076bool ext4_superblock_has_feature_compatible(ext4_superblock_t *sb,
     1077    uint32_t feature)
     1078{
     1079        if (ext4_superblock_get_features_compatible(sb) & feature)
    9391080                return true;
    940         }
     1081       
    9411082        return false;
    9421083}
     
    9441085/** Check if filesystem supports incompatible feature.
    9451086 *
    946  * @param sb                    superblock
    947  * @param feature               feature to be checked
    948  * @return                              true, if filesystem supports the feature
    949  */
    950 bool ext4_superblock_has_feature_incompatible(ext4_superblock_t *sb, uint32_t feature)
    951 {
    952         if (ext4_superblock_get_features_incompatible(sb) & feature) {
     1087 * @param sb      Superblock
     1088 * @param feature Feature to be checked
     1089 *
     1090 * @return True, if filesystem supports the feature
     1091 *
     1092 */
     1093bool ext4_superblock_has_feature_incompatible(ext4_superblock_t *sb,
     1094    uint32_t feature)
     1095{
     1096        if (ext4_superblock_get_features_incompatible(sb) & feature)
    9531097                return true;
    954         }
     1098       
    9551099        return false;
    9561100}
     
    9581102/** Check if filesystem supports read-only compatible feature.
    9591103 *
    960  * @param sb                    superblock
    961  * @param feature               feature to be checked
    962  * @return                              true, if filesystem supports the feature
    963  */
    964 bool ext4_superblock_has_feature_read_only(ext4_superblock_t *sb, uint32_t feature)
    965 {
    966         if (ext4_superblock_get_features_read_only(sb) & feature) {
     1104 * @param sb      Superblock
     1105 * @param feature Feature to be checked
     1106 *
     1107 * @return True, if filesystem supports the feature
     1108 *
     1109 */
     1110bool ext4_superblock_has_feature_read_only(ext4_superblock_t *sb,
     1111    uint32_t feature)
     1112{
     1113        if (ext4_superblock_get_features_read_only(sb) & feature)
    9671114                return true;
    968         }
     1115       
    9691116        return false;
    9701117}
     
    9721119/** Read superblock directly from block device.
    9731120 *
    974  * @param service_id            block device identifier
    975  * @param sb                            output pointer to memory structure
    976  * @return                                      error code.
    977  */
    978 int ext4_superblock_read_direct(service_id_t service_id,
    979     ext4_superblock_t **sb)
    980 {
    981         int rc;
    982 
     1121 * @param service_id Block device identifier
     1122 * @param sb         Output pointer to memory structure
     1123 *
     1124 * @return Eerror code.
     1125 *
     1126 */
     1127int ext4_superblock_read_direct(service_id_t service_id, ext4_superblock_t **sb)
     1128{
    9831129        /* Allocated memory for superblock structure */
    9841130        void *data = malloc(EXT4_SUPERBLOCK_SIZE);
    985         if (data == NULL) {
     1131        if (data == NULL)
    9861132                return ENOMEM;
    987         }
    988 
     1133       
    9891134        /* Read data from block device */
    990         rc = block_read_bytes_direct(service_id, EXT4_SUPERBLOCK_OFFSET,
     1135        int rc = block_read_bytes_direct(service_id, EXT4_SUPERBLOCK_OFFSET,
    9911136            EXT4_SUPERBLOCK_SIZE, data);
    992 
     1137       
    9931138        if (rc != EOK) {
    9941139                free(data);
    9951140                return rc;
    9961141        }
    997 
     1142       
    9981143        /* Set output value */
    9991144        (*sb) = data;
    1000 
     1145       
    10011146        return EOK;
    10021147}
     
    10041149/** Write superblock structure directly to block device.
    10051150 *
    1006  * @param service_id            block device identifier
    1007  * @param sb                            superblock to be written
    1008  * @return                                      error code
    1009  */
    1010 int ext4_superblock_write_direct(service_id_t service_id,
    1011                 ext4_superblock_t *sb)
    1012 {
    1013         int rc;
     1151 * @param service_id Block device identifier
     1152 * @param sb         Superblock to be written
     1153 *
     1154 * @return Error code
     1155 *
     1156 */
     1157int ext4_superblock_write_direct(service_id_t service_id, ext4_superblock_t *sb)
     1158{
     1159        /* Load physical block size from block device */
    10141160        size_t phys_block_size;
    1015 
    1016         /* Load physical block size from block device */
    1017         rc = block_get_bsize(service_id, &phys_block_size);
    1018         if (rc != EOK) {
     1161        int rc = block_get_bsize(service_id, &phys_block_size);
     1162        if (rc != EOK)
    10191163                return rc;
    1020         }
    1021 
     1164       
    10221165        /* Compute address of the first block */
    10231166        uint64_t first_block = EXT4_SUPERBLOCK_OFFSET / phys_block_size;
     1167       
    10241168        /* Compute number of block to write */
    10251169        size_t block_count = EXT4_SUPERBLOCK_SIZE / phys_block_size;
    1026 
     1170       
    10271171        /* Check alignment */
    1028         if (EXT4_SUPERBLOCK_SIZE % phys_block_size) {
     1172        if (EXT4_SUPERBLOCK_SIZE % phys_block_size)
    10291173                block_count++;
    1030         }
    1031 
     1174       
    10321175        /* Write data */
    10331176        return block_write_direct(service_id, first_block, block_count, sb);
    1034 
    10351177}
    10361178
     
    10401182 * Checks are described by one-line comments in the code.
    10411183 *
    1042  * @param sb            superblock to check
    1043  * @return                      error code
     1184 * @param sb Superblock to check
     1185 *
     1186 * @return Error code
     1187 *
    10441188 */
    10451189int ext4_superblock_check_sanity(ext4_superblock_t *sb)
    10461190{
    1047         if (ext4_superblock_get_magic(sb) != EXT4_SUPERBLOCK_MAGIC) {
     1191        if (ext4_superblock_get_magic(sb) != EXT4_SUPERBLOCK_MAGIC)
    10481192                return ENOTSUP;
    1049         }
    1050 
    1051         if (ext4_superblock_get_inodes_count(sb) == 0) {
     1193       
     1194        if (ext4_superblock_get_inodes_count(sb) == 0)
    10521195                return ENOTSUP;
    1053         }
    1054 
    1055         if (ext4_superblock_get_blocks_count(sb) == 0) {
     1196       
     1197        if (ext4_superblock_get_blocks_count(sb) == 0)
    10561198                return ENOTSUP;
    1057         }
    1058 
    1059         if (ext4_superblock_get_blocks_per_group(sb) == 0) {
     1199       
     1200        if (ext4_superblock_get_blocks_per_group(sb) == 0)
    10601201                return ENOTSUP;
    1061         }
    1062 
    1063         if (ext4_superblock_get_inodes_per_group(sb) == 0) {
     1202       
     1203        if (ext4_superblock_get_inodes_per_group(sb) == 0)
    10641204                return ENOTSUP;
    1065         }
    1066 
    1067         if (ext4_superblock_get_inode_size(sb) < 128) {
     1205       
     1206        if (ext4_superblock_get_inode_size(sb) < 128)
    10681207                return ENOTSUP;
    1069         }
    1070 
    1071         if (ext4_superblock_get_first_inode(sb) < 11) {
     1208       
     1209        if (ext4_superblock_get_first_inode(sb) < 11)
    10721210                return ENOTSUP;
    1073         }
    1074 
    1075         if (ext4_superblock_get_desc_size(sb) < EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE) {
     1211       
     1212        if (ext4_superblock_get_desc_size(sb) <
     1213            EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE)
    10761214                return ENOTSUP;
    1077         }
    1078 
    1079         if (ext4_superblock_get_desc_size(sb) > EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE) {
     1215       
     1216        if (ext4_superblock_get_desc_size(sb) >
     1217            EXT4_MAX_BLOCK_GROUP_DESCRIPTOR_SIZE)
    10801218                return ENOTSUP;
    1081         }
    1082 
     1219       
    10831220        return EOK;
    10841221}
     
    10861223/** Compute number of block groups in the filesystem.
    10871224 *
    1088  * @param sb            superblock
    1089  * @return                      number of block groups
     1225 * @param sb Superblock
     1226 *
     1227 * @return Number of block groups
     1228 *
    10901229 */
    10911230uint32_t ext4_superblock_get_block_group_count(ext4_superblock_t *sb)
     
    10931232        uint64_t blocks_count = ext4_superblock_get_blocks_count(sb);
    10941233        uint32_t blocks_per_group = ext4_superblock_get_blocks_per_group(sb);
    1095 
     1234       
    10961235        uint32_t block_groups_count = blocks_count / blocks_per_group;
    1097 
    1098         if (blocks_count % blocks_per_group) {
     1236       
     1237        if (blocks_count % blocks_per_group)
    10991238                block_groups_count++;
    1100         }
    1101 
     1239       
    11021240        return block_groups_count;
    1103 
    11041241}
    11051242
    11061243/** Compute number of blocks in specified block group.
    11071244 *
    1108  * @param sb                    superblock
    1109  * @param bgid                  block group index
    1110  * @return                              number of blocks
     1245 * @param sb   Superblock
     1246 * @param bgid Block group index
     1247 *
     1248 * @return Number of blocks
     1249 *
    11111250 */
    11121251uint32_t ext4_superblock_get_blocks_in_group(ext4_superblock_t *sb, uint32_t bgid)
    11131252{
    1114         uint32_t block_group_count = ext4_superblock_get_block_group_count(sb);
    1115         uint32_t blocks_per_group = ext4_superblock_get_blocks_per_group(sb);
    1116         uint64_t total_blocks = ext4_superblock_get_blocks_count(sb);
    1117 
    1118         if (bgid < block_group_count - 1) {
     1253        uint32_t block_group_count =
     1254            ext4_superblock_get_block_group_count(sb);
     1255        uint32_t blocks_per_group =
     1256            ext4_superblock_get_blocks_per_group(sb);
     1257        uint64_t total_blocks =
     1258            ext4_superblock_get_blocks_count(sb);
     1259       
     1260        if (bgid < block_group_count - 1)
    11191261                return blocks_per_group;
    1120         } else {
     1262        else
    11211263                return (total_blocks - ((block_group_count - 1) * blocks_per_group));
    1122         }
    1123 
    11241264}
    11251265
    11261266/** Compute number of i-nodes in specified block group.
    11271267 *
    1128  * @param sb            superblock
    1129  * @param bgid          block group index
    1130  * @return                      number of i-nodes
     1268 * @param sb   Superblock
     1269 * @param bgid Block group index
     1270 *
     1271 * @return Number of i-nodes
     1272 *
    11311273 */
    11321274uint32_t ext4_superblock_get_inodes_in_group(ext4_superblock_t *sb, uint32_t bgid)
    11331275{
    1134         uint32_t block_group_count = ext4_superblock_get_block_group_count(sb);
    1135         uint32_t inodes_per_group = ext4_superblock_get_inodes_per_group(sb);
    1136         uint32_t total_inodes = ext4_superblock_get_inodes_count(sb);
    1137 
    1138         if (bgid < block_group_count - 1) {
     1276        uint32_t block_group_count =
     1277            ext4_superblock_get_block_group_count(sb);
     1278        uint32_t inodes_per_group =
     1279            ext4_superblock_get_inodes_per_group(sb);
     1280        uint32_t total_inodes =
     1281            ext4_superblock_get_inodes_count(sb);
     1282       
     1283        if (bgid < block_group_count - 1)
    11391284                return inodes_per_group;
    1140         } else {
     1285        else
    11411286                return (total_inodes - ((block_group_count - 1) * inodes_per_group));
    1142         }
    1143 
    11441287}
    11451288
    11461289/**
    11471290 * @}
    1148  */ 
     1291 */
Note: See TracChangeset for help on using the changeset viewer.