Skip to content

Commit

Permalink
[sync] support of DFSv2 (#27)
Browse files Browse the repository at this point in the history
## Changes

* Support of DFSv2

Synchronization from upstream:

* fixed commented doxygen syntax mismatch;
* used environment variables in install directory;
* ext4_fs.c has an additional `CONFIG_EXTENTS_ENABLE` affect. Since this item is not additionally configured, and the default value has no effect on compilation conditions, no code was actually changed.
  • Loading branch information
polarvid authored Dec 2, 2024
1 parent a94fe63 commit 94982e4
Show file tree
Hide file tree
Showing 28 changed files with 1,054 additions and 438 deletions.
3 changes: 2 additions & 1 deletion SConscript
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ src/ext4_ialloc.c
src/ext4_inode.c
src/ext4_journal.c
src/ext4_mkfs.c
src/ext4_mp.c
src/ext4_super.c
src/ext4_trans.c
src/ext4_xattr.c
Expand All @@ -32,7 +33,7 @@ CPPDEFINES = ['CONFIG_USE_DEFAULT_CFG', 'CONFIG_HAVE_OWN_OFLAGS=0']

LOCAL_CCFLAGS = ''

group = DefineGroup('Filesystem', objs,
group = DefineGroup('Filesystem', objs,
depend = ['RT_USING_DFS', 'RT_USING_DFS_LWEXT4'],
CPPPATH = CPPPATH,
CPPDEFINES = CPPDEFINES,
Expand Down
10 changes: 5 additions & 5 deletions fs_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ add_executable(lwext4-mbr lwext4_mbr.c)
target_link_libraries(lwext4-mbr blockdev)
target_link_libraries(lwext4-mbr lwext4)

install (TARGETS lwext4-server DESTINATION /usr/bin)
install (TARGETS lwext4-client DESTINATION /usr/bin)
install (TARGETS lwext4-generic DESTINATION /usr/bin)
install (TARGETS lwext4-mkfs DESTINATION /usr/bin)
install (TARGETS lwext4-mbr DESTINATION /usr/bin)
install (TARGETS lwext4-server DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install (TARGETS lwext4-client DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install (TARGETS lwext4-generic DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install (TARGETS lwext4-mkfs DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)
install (TARGETS lwext4-mbr DESTINATION ${CMAKE_INSTALL_PREFIX}/bin)

32 changes: 22 additions & 10 deletions include/ext4.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ extern "C" {
#include <ext4_errno.h>
#include <ext4_oflags.h>
#include <ext4_debug.h>
#include <ext4_inode.h>
#include <ext4_fs.h>

#include <ext4_blockdev.h>

Expand Down Expand Up @@ -123,6 +125,13 @@ int ext4_mount(struct ext4_blockdev *bd,
const char *mount_point,
bool read_only);

/**@brief Umount operation.
*
* @param mount_point Mount point.
*
* @return Standard error code */
int ext4_umount_mp(struct ext4_mountpoint *mp);

/**@brief Umount operation.
*
* @param mount_pount Mount point.
Expand All @@ -140,23 +149,23 @@ int ext4_umount(const char *mount_point);
*
* ext4_journal_stop("/");
* ext4_umount("/");
* @param mount_pount Mount point.
* @param mount_point Mount point.
*
* @return Standard error code. */
int ext4_journal_start(const char *mount_point);

/**@brief Stops journaling. Journaling start/stop functions are transparent
* and might be used on filesystems without journaling support.
*
* @param mount_pount Mount point name.
* @param mount_point Mount point name.
*
* @return Standard error code. */
int ext4_journal_stop(const char *mount_point);

/**@brief Journal recovery.
* @warning Must be called after @ref ext4_mount.
*
* @param mount_pount Mount point.
* @param mount_point Mount point.
*
* @return Standard error code. */
int ext4_recover(const char *mount_point);
Expand All @@ -178,7 +187,7 @@ struct ext4_mount_stats {

/**@brief Get file mount point stats.
*
* @param mount_pount Mount point.
* @param mount_point Mount point.
* @param stats Filesystem stats.
*
* @return Standard error code. */
Expand All @@ -187,7 +196,7 @@ int ext4_mount_point_stats(const char *mount_point,

/**@brief Setup OS lock routines.
*
* @param mount_pount Mount point.
* @param mount_point Mount point.
* @param locks Lock and unlock functions
*
* @return Standard error code. */
Expand All @@ -196,7 +205,7 @@ int ext4_mount_setup_locks(const char *mount_point,

/**@brief Acquire the filesystem superblock pointer of a mp.
*
* @param mount_pount Mount point.
* @param mount_point Mount point.
* @param sb Superblock handle
*
* @return Standard error code. */
Expand Down Expand Up @@ -233,7 +242,7 @@ int ext4_get_sblock(const char *mount_point, struct ext4_sblock **sb);
* Write back mode is useful when you want to create a lot of empty
* files/directories.
*
* @param mount_pount Mount point.
* @param path Mount point.
* @param on Enable/disable cache writeback mode.
*
* @return Standard error code. */
Expand All @@ -242,7 +251,7 @@ int ext4_cache_write_back(const char *path, bool on);

/**@brief Force cache flush.
*
* @param mount_pount Mount point.
* @param path Mount point.
*
* @return Standard error code. */
int ext4_cache_flush(const char *path);
Expand Down Expand Up @@ -390,6 +399,9 @@ int ext4_raw_inode_fill(const char *path, uint32_t *ret_ino,
* @return Standard error code.*/
int ext4_inode_exist(const char *path, int type);

void* ext4_get_inode_ref(const char *path, struct ext4_inode_ref *ref);
int ext4_put_inode_ref(struct ext4_mountpoint *mp, struct ext4_inode_ref *ref);

/**@brief Change file/directory/link mode bits.
*
* @param path Path to file/dir/link.
Expand Down Expand Up @@ -517,8 +529,8 @@ int ext4_setxattr(const char *path, const char *name, size_t name_len,
* @param path Path to file/directory.
* @param name Name of the entry to get.
* @param name_len Length of @name in bytes.
* @param data Data of the entry to get.
* @param data_size Size of data to get.
* @param buf Data of the entry to get.
* @param buf_size Size of data to get.
*
* @return Standard error code.*/
int ext4_getxattr(const char *path, const char *name, size_t name_len,
Expand Down
5 changes: 2 additions & 3 deletions include/ext4_balloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ extern "C" {
#include <stdbool.h>

/**@brief Compute number of block group from block address.
* @param sb superblock pointer.
* @param s superblock pointer.
* @param baddr Absolute address of block.
* @return Block group index
*/
uint32_t ext4_balloc_get_bgid_of_block(struct ext4_sblock *s,
ext4_fsblk_t baddr);

/**@brief Compute the starting block address of a block group
* @param sb superblock pointer.
* @param s superblock pointer.
* @param bgid block group index
* @return Block address
*/
Expand Down Expand Up @@ -95,7 +95,6 @@ int ext4_balloc_free_blocks(struct ext4_inode_ref *inode_ref,

/**@brief Allocate block procedure.
* @param inode_ref inode reference
* @param goal
* @param baddr allocated block address
* @return standard error code*/
int ext4_balloc_alloc_block(struct ext4_inode_ref *inode_ref,
Expand Down
7 changes: 5 additions & 2 deletions include/ext4_bcache.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ struct ext4_buf {

/**@brief Reference count table*/
uint32_t refctr;
/* refcount for read */
uint32_t read_refctr;

/**@brief The block cache this buffer belongs to. */
struct ext4_bcache *bc;
Expand Down Expand Up @@ -185,9 +187,11 @@ static inline void ext4_bcache_clear_dirty(struct ext4_buf *buf) {

/**@brief Increment reference counter of buf by 1.*/
#define ext4_bcache_inc_ref(buf) ((buf)->refctr++)
#define ext4_bcache_inc_read_ref(buf) ((buf)->read_refctr++)

/**@brief Decrement reference counter of buf by 1.*/
#define ext4_bcache_dec_ref(buf) ((buf)->refctr--)
#define ext4_bcache_dec_read_ref(buf) ((buf)->read_refctr--)

/**@brief Insert buffer to dirty cache list
* @param bc block cache descriptor
Expand Down Expand Up @@ -248,8 +252,7 @@ void ext4_bcache_invalidate_buf(struct ext4_bcache *bc,
/**@brief Invalidate a range of buffers.
* @param bc block cache descriptor
* @param from starting lba
* @param cnt block counts
* @param buf buffer*/
* @param cnt block counts*/
void ext4_bcache_invalidate_lba(struct ext4_bcache *bc,
uint64_t from,
uint32_t cnt);
Expand Down
11 changes: 4 additions & 7 deletions include/ext4_block_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ static inline uint64_t ext4_bg_get_block_bitmap(struct ext4_bgroup *bg,
* @param bg pointer to block group
* @param s pointer to superblock
* @param blk block to set
* @return Address of block with block bitmap
*/
static inline void ext4_bg_set_block_bitmap(struct ext4_bgroup *bg,
struct ext4_sblock *s, uint64_t blk)
Expand Down Expand Up @@ -106,7 +105,6 @@ static inline uint64_t ext4_bg_get_inode_bitmap(struct ext4_bgroup *bg,
* @param bg Pointer to block group
* @param s Pointer to superblock
* @param blk block to set
* @return Address of block with i-node bitmap
*/
static inline void ext4_bg_set_inode_bitmap(struct ext4_bgroup *bg,
struct ext4_sblock *s, uint64_t blk)
Expand Down Expand Up @@ -139,7 +137,6 @@ ext4_bg_get_inode_table_first_block(struct ext4_bgroup *bg,
* @param bg Pointer to block group
* @param s Pointer to superblock
* @param blk block to set
* @return Address of first block of i-node table
*/
static inline void
ext4_bg_set_inode_table_first_block(struct ext4_bgroup *bg,
Expand All @@ -152,7 +149,7 @@ ext4_bg_set_inode_table_first_block(struct ext4_bgroup *bg,

/**@brief Get number of free blocks in block group.
* @param bg Pointer to block group
* @param sb Pointer to superblock
* @param s Pointer to superblock
* @return Number of free blocks in block group
*/
static inline uint32_t ext4_bg_get_free_blocks_count(struct ext4_bgroup *bg,
Expand Down Expand Up @@ -282,7 +279,7 @@ static inline void ext4_bg_set_checksum(struct ext4_bgroup *bg, uint16_t crc)

/**@brief Check if block group has a flag.
* @param bg Pointer to block group
* @param flag Flag to be checked
* @param f Flag to be checked
* @return True if flag is set to 1
*/
static inline bool ext4_bg_has_flag(struct ext4_bgroup *bg, uint32_t f)
Expand All @@ -292,7 +289,7 @@ static inline bool ext4_bg_has_flag(struct ext4_bgroup *bg, uint32_t f)

/**@brief Set flag of block group.
* @param bg Pointer to block group
* @param flag Flag to be set
* @param f Flag to be set
*/
static inline void ext4_bg_set_flag(struct ext4_bgroup *bg, uint32_t f)
{
Expand All @@ -303,7 +300,7 @@ static inline void ext4_bg_set_flag(struct ext4_bgroup *bg, uint32_t f)

/**@brief Clear flag of block group.
* @param bg Pointer to block group
* @param flag Flag to be cleared
* @param f Flag to be cleared
*/
static inline void ext4_bg_clear_flag(struct ext4_bgroup *bg, uint32_t f)
{
Expand Down
5 changes: 1 addition & 4 deletions include/ext4_blockdev.h
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ struct ext4_blockdev {
}

/**@brief Block device initialization.
* @param bdev block device descriptor
* @param bg_bsize logical block size
* @param bdev block device descriptor
* @return standard error code*/
int ext4_block_init(struct ext4_blockdev *bdev);
Expand Down Expand Up @@ -185,8 +183,7 @@ int ext4_block_flush_lba(struct ext4_blockdev *bdev, uint64_t lba);

/**@brief Set logical block size in block device.
* @param bdev block device descriptor
* @param lb_size logical block size (in bytes)
* @return standard error code*/
* @param lb_bsize logical block size (in bytes)*/
void ext4_block_set_lb_size(struct ext4_blockdev *bdev, uint32_t lb_bsize);

/**@brief Block get function (through cache, don't read).
Expand Down
2 changes: 1 addition & 1 deletion include/ext4_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ extern "C" {

/**@brief Maximum mountpoint count*/
#ifndef CONFIG_EXT4_MOUNTPOINTS_COUNT
#define CONFIG_EXT4_MOUNTPOINTS_COUNT 4
#define CONFIG_EXT4_MOUNTPOINTS_COUNT 20
#endif

/**@brief Include open flags from ext4_errno or standard library.*/
Expand Down
2 changes: 1 addition & 1 deletion include/ext4_crc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ uint32_t ext4_crc32(uint32_t crc, const void *buf, uint32_t size);
/**@brief CRC32C algorithm.
* @param crc input feed
* @param buf input buffer
* @param length input buffer length (bytes)
* @param size input buffer length (bytes)
* @return updated crc32c value*/
uint32_t ext4_crc32c(uint32_t crc, const void *buf, uint32_t size);

Expand Down
4 changes: 2 additions & 2 deletions include/ext4_debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,11 @@ static inline const char *ext4_dmask_id2str(uint32_t m)
#define DBG_ERROR "[error] "

/**@brief Global mask debug set.
* @brief m new debug mask.*/
* @param m new debug mask.*/
void ext4_dmask_set(uint32_t m);

/**@brief Global mask debug clear.
* @brief m new debug mask.*/
* @param m new debug mask.*/
void ext4_dmask_clr(uint32_t m);

/**@brief Global debug mask get.
Expand Down
6 changes: 3 additions & 3 deletions include/ext4_dir.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ static inline uint16_t ext4_dir_en_get_entry_len(struct ext4_dir_en *de)

/**@brief Set directory entry length.
* @param de Directory entry
* @param length Entry length
* @param l Entry length
*/
static inline void ext4_dir_en_set_entry_len(struct ext4_dir_en *de, uint16_t l)
{
Expand All @@ -135,7 +135,7 @@ static inline uint16_t ext4_dir_en_get_name_len(struct ext4_sblock *sb,
/**@brief Set directory entry name length.
* @param sb Superblock
* @param de Directory entry
* @param length Entry name length
* @param len Entry name length
*/
static inline void ext4_dir_en_set_name_len(struct ext4_sblock *sb,
struct ext4_dir_en *de,
Expand Down Expand Up @@ -165,7 +165,7 @@ static inline uint8_t ext4_dir_en_get_inode_type(struct ext4_sblock *sb,
/**@brief Set i-node type of directory entry.
* @param sb Superblock
* @param de Directory entry
* @param type I-node type (file, dir, etc.)
* @param t I-node type (file, dir, etc.)
*/

static inline void ext4_dir_en_set_inode_type(struct ext4_sblock *sb,
Expand Down
2 changes: 1 addition & 1 deletion include/ext4_dir_idx.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ struct ext4_dir_idx_block {

/**@brief Initialize index structure of new directory.
* @param dir Pointer to directory i-node
* @param dir Pointer to parent directory i-node
* @param parent Pointer to parent directory i-node
* @return Error code
*/
int ext4_dir_dx_init(struct ext4_inode_ref *dir,
Expand Down
9 changes: 4 additions & 5 deletions include/ext4_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ struct ext4_inode_ref {


/**@brief Convert block address to relative index in block group.
* @param sb Superblock pointer
* @param s Superblock pointer
* @param baddr Block number to convert
* @return Relative number of block
*/
Expand Down Expand Up @@ -187,7 +187,7 @@ void ext4_fs_inode_blocks_init(struct ext4_fs *fs,
int ext4_fs_put_inode_ref(struct ext4_inode_ref *ref);

/**@brief Convert filetype to inode mode.
* @param filetype
* @param filetype File type
* @return inode mode
*/
uint32_t ext4_fs_correspond_inode_mode(int filetype);
Expand Down Expand Up @@ -222,7 +222,6 @@ ext4_fsblk_t ext4_fs_inode_to_goal_block(struct ext4_inode_ref *inode_ref);

/**@brief Compute 'goal' for allocation algorithm (For blockmap).
* @param inode_ref Reference to inode, to allocate block for
* @param goal
* @return error code
*/
int ext4_fs_indirect_find_goal(struct ext4_inode_ref *inode_ref,
Expand Down Expand Up @@ -260,12 +259,12 @@ int ext4_fs_append_inode_dblk(struct ext4_inode_ref *inode_ref,
ext4_fsblk_t *fblock, ext4_lblk_t *iblock);

/**@brief Increment inode link count.
* @param inode none handle
* @param inode_ref none handle
*/
void ext4_fs_inode_links_count_inc(struct ext4_inode_ref *inode_ref);

/**@brief Decrement inode link count.
* @param inode none handle
* @param inode_ref none handle
*/
void ext4_fs_inode_links_count_dec(struct ext4_inode_ref *inode_ref);

Expand Down
Loading

0 comments on commit 94982e4

Please sign in to comment.