You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

239 lines
7.4 KiB

11 years ago
/*
* Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
*
*
* HelenOS:
* Copyright (c) 2012 Martin Sucha
* Copyright (c) 2012 Frantisek Princ
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* - Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* - Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* - The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/** @addtogroup lwext4
* @{
*/
/**
* @file ext4_super.c
* @brief Superblock operations.
*/
#ifndef EXT4_SUPER_H_
#define EXT4_SUPER_H_
#ifdef __cplusplus
extern "C" {
#endif
#include <ext4_config.h>
#include <ext4_types.h>
#include <ext4_misc.h>
11 years ago
11 years ago
/**@brief Blocks count get stored in superblock.
* @param s superblock descriptor
* @return count of blocks*/
static inline uint64_t ext4_sb_get_blocks_cnt(struct ext4_sblock *s)
11 years ago
{
return ((uint64_t)to_le32(s->blocks_count_hi) << 32) |
to_le32(s->blocks_count_lo);
11 years ago
}
/**@brief Blocks count set in superblock.
* @param s superblock descriptor
* @return count of blocks*/
static inline void ext4_sb_set_blocks_cnt(struct ext4_sblock *s, uint64_t cnt)
{
s->blocks_count_lo = to_le32((cnt << 32) >> 32);
s->blocks_count_hi = to_le32(cnt >> 32);
}
11 years ago
/**@brief Free blocks count get stored in superblock.
* @param s superblock descriptor
* @return free blocks*/
static inline uint64_t ext4_sb_get_free_blocks_cnt(struct ext4_sblock *s)
11 years ago
{
return ((uint64_t)to_le32(s->free_blocks_count_hi) << 32) |
to_le32(s->free_blocks_count_lo);
11 years ago
}
11 years ago
/**@brief Free blocks count set.
* @param s superblock descriptor
* @param cnt new value of free blocks*/
static inline void ext4_sb_set_free_blocks_cnt(struct ext4_sblock *s,
uint64_t cnt)
11 years ago
{
s->free_blocks_count_lo = to_le32((cnt << 32) >> 32);
s->free_blocks_count_hi = to_le32(cnt >> 32);
11 years ago
}
11 years ago
/**@brief Block size get from superblock.
* @param s superblock descriptor
* @return block size in bytes*/
static inline uint32_t ext4_sb_get_block_size(struct ext4_sblock *s)
11 years ago
{
return 1024 << to_le32(s->log_block_size);
11 years ago
}
11 years ago
/**@brief Block group descriptor size.
* @param s superblock descriptor
* @return block group descriptor size in bytes*/
11 years ago
static inline uint16_t ext4_sb_get_desc_size(struct ext4_sblock *s)
{
uint16_t size = to_le16(s->desc_size);
11 years ago
return size < EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE
? EXT4_MIN_BLOCK_GROUP_DESCRIPTOR_SIZE
: size;
11 years ago
}
11 years ago
/*************************Flags and features*********************************/
11 years ago
11 years ago
/**@brief Support check of flag.
* @param s superblock descriptor
* @param v flag to check
* @return true if flag is supported*/
11 years ago
static inline bool ext4_sb_check_flag(struct ext4_sblock *s, uint32_t v)
{
return to_le32(s->flags) & v;
11 years ago
}
11 years ago
/**@brief Support check of feature compatible.
* @param s superblock descriptor
* @param v feature to check
* @return true if feature is supported*/
static inline bool ext4_sb_feature_com(struct ext4_sblock *s, uint32_t v)
11 years ago
{
return to_le32(s->features_compatible) & v;
11 years ago
}
11 years ago
/**@brief Support check of feature incompatible.
* @param s superblock descriptor
* @param v feature to check
* @return true if feature is supported*/
static inline bool ext4_sb_feature_incom(struct ext4_sblock *s, uint32_t v)
11 years ago
{
return to_le32(s->features_incompatible) & v;
11 years ago
}
11 years ago
/**@brief Support check of read only flag.
* @param s superblock descriptor
* @param v flag to check
* @return true if flag is supported*/
static inline bool ext4_sb_feature_ro_com(struct ext4_sblock *s, uint32_t v)
11 years ago
{
return to_le32(s->features_read_only) & v;
11 years ago
}
/**@brief Block group to flex group.
* @param s superblock descriptor
* @param block_group block group
* @return flex group id*/
static inline uint32_t ext4_sb_bg_to_flex(struct ext4_sblock *s,
uint32_t block_group)
{
return block_group >> to_le32(s->log_groups_per_flex);
}
/**@brief Flex block group size.
* @param s superblock descriptor
* @return flex bg size*/
static inline uint32_t ext4_sb_flex_bg_size(struct ext4_sblock *s)
{
return 1 << to_le32(s->log_groups_per_flex);
}
10 years ago
/**@brief Return first meta block group id.
* @param s superblock descriptor
* @return first meta_bg id */
static inline uint32_t ext4_sb_first_meta_bg(struct ext4_sblock *s)
{
return to_le32(s->first_meta_bg);
10 years ago
}
11 years ago
/**************************More complex functions****************************/
11 years ago
11 years ago
/**@brief Returns a block group count.
* @param s superblock descriptor
* @return count of block groups*/
11 years ago
uint32_t ext4_block_group_cnt(struct ext4_sblock *s);
11 years ago
/**@brief Returns block count in block group
11 years ago
* (last block group may have less blocks)
11 years ago
* @param s superblock descriptor
* @param bgid block group id
* @return blocks count*/
11 years ago
uint32_t ext4_blocks_in_group_cnt(struct ext4_sblock *s, uint32_t bgid);
11 years ago
/**@brief Returns inodes count in block group
11 years ago
* (last block group may have less inodes)
11 years ago
* @param s superblock descriptor
* @param bgid block group id
* @return inodes count*/
11 years ago
uint32_t ext4_inodes_in_group_cnt(struct ext4_sblock *s, uint32_t bgid);
11 years ago
/***************************Read/write/check superblock**********************/
11 years ago
11 years ago
/**@brief Superblock write.
* @param bdev block device descriptor.
10 years ago
* @param s superblock descriptor
11 years ago
* @return Standard error code */
int ext4_sb_write(struct ext4_blockdev *bdev, struct ext4_sblock *s);
11 years ago
11 years ago
/**@brief Superblock read.
* @param bdev block device descriptor.
10 years ago
* @param s superblock descriptor
11 years ago
* @return Standard error code */
int ext4_sb_read(struct ext4_blockdev *bdev, struct ext4_sblock *s);
11 years ago
11 years ago
/**@brief Superblock simple validation.
10 years ago
* @param s superblock descriptor
11 years ago
* @return true if OK*/
11 years ago
bool ext4_sb_check(struct ext4_sblock *s);
/**@brief Superblock presence in block group.
10 years ago
* @param s superblock descriptor
* @param block_group block group id
* @return true if block group has superblock*/
bool ext4_sb_is_super_in_bg(struct ext4_sblock *s, uint32_t block_group);
11 years ago
/**@brief TODO:*/
bool ext4_sb_sparse(uint32_t group);
/**@brief TODO:*/
uint32_t ext4_bg_num_gdb(struct ext4_sblock *s, uint32_t group);
/**@brief TODO:*/
uint32_t ext4_num_base_meta_clusters(struct ext4_sblock *s,
uint32_t block_group);
#ifdef __cplusplus
}
#endif
11 years ago
#endif /* EXT4_SUPER_H_ */
/**
* @}
*/