/*
* Copyright (c) 2013 Grzegorz Kostka (kostka.grzegorz@gmail.com)
* 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.h
* @brief Ext4 high level operations (file, directory, mountpoints...)
*/
#include <ext4_config.h>
#include <ext4_types.h>
#include <ext4_misc.h>
#include <ext4_errno.h>
#include <ext4_oflags.h>
#include <ext4_debug.h>
#include <ext4.h>
#include <ext4_trans.h>
#include <ext4_blockdev.h>
#include <ext4_fs.h>
#include <ext4_dir.h>
#include <ext4_inode.h>
#include <ext4_super.h>
#include <ext4_block_group.h>
#include <ext4_dir_idx.h>
#include <ext4_xattr.h>
#include <ext4_journal.h>
#include <stdlib.h>
#include <string.h>
/**@brief Mount point OS dependent lock*/
#define EXT4_MP_LOCK(_m) \
do { \
if ((_m)->os_locks) \
(_m)->os_locks->lock(); \
} while (0)
/**@brief Mount point OS dependent unlock*/
#define EXT4_MP_UNLOCK(_m) \
do { \
if ((_m)->os_locks) \
(_m)->os_locks->unlock(); \
} while (0)
/**@brief Mount point descriptor.*/
struct ext4_mountpoint {
/**@brief Mount done flag.*/
bool mounted;
/**@brief Mount point name (@ref ext4_mount)*/
char name[CONFIG_EXT4_MAX_MP_NAME + 1];
/**@brief OS dependent lock/unlock functions.*/
const struct ext4_lock *os_locks;
/**@brief Ext4 filesystem internals.*/
struct ext4_fs fs;
/**@brief JBD fs.*/
struct jbd_fs jbd_fs;
/**@brief Journal.*/
struct jbd_journal jbd_journal;
/**@brief Block cache.*/
struct ext4_bcache bc;
};
/**@brief Block devices descriptor.*/
struct ext4_block_devices {
/**@brief Block device name.*/
char name[CONFIG_EXT4_MAX_BLOCKDEV_NAME + 1];
/**@brief Block device handle.*/
struct ext4_blockdev *bd;
};
/**@brief Block devices.*/
static struct ext4_block_devices s_bdevices[CONFIG_EXT4_BLOCKDEVS_COUNT];
/**@brief Mountpoints.*/
static struct ext4_mountpoint s_mp[CONFIG_EXT4_MOUNTPOINTS_COUNT];
int ext4_device_register(struct ext4_blockdev *bd,
const char *dev_name)
{
ext4_assert(bd && dev_name);
if (strlen(dev_name) > CONFIG_EXT4_MAX_BLOCKDEV_NAME)
return EINVAL;
for (size_t i = 0; i < CONFIG_EXT4_BLOCKDEVS_COUNT; ++i) {
if (!strcmp(s_bdevices[i].name, dev_name))
return EEXIST;
}
for (size_t i = 0; i < CONFIG_EXT4_BLOCKDEVS_COUNT; ++i) {
if (!s_bdevices[i].bd) {
strcpy(s_bdevices[i].name, dev_name);
s_bdevices[i].bd = bd;
return EOK;
}
}
return ENOSPC;
}
int ext4_device_unregister(const char *dev_name)
{
ext4_assert(dev_name);
for (size_t i = 0; i < CONFIG_EXT4_BLOCKDEVS_COUNT; ++i) {
if (strcmp(s_bdevices[i].name, dev_name))
continue;
memset(&s_bdevices[i], 0, sizeof(s_bdevices[i]));
}
return ENOENT;
}
int ext4_device_unregister_all(void)
{
memset(s_bdevices, 0, sizeof(s_bdevices));
return EOK;
}
/****************************************************************************/
static bool ext4_is_dots(const uint8_t *name, size_t name_size)
{
if ((name_size == 1) && (name[0] == '.'))
return true;
if ((name_size == 2) && (name[0] == '.') && (name[1] == '.'))
return true;
return false;
}
static int ext4_has_children(bool *has_children, struct ext4_inode_ref *enode)
{
struct ext4_sblock *sb = &enode->fs->sb;
/* Check if node is directory */
if (!ext4_inode_is_type(sb, enode->inode, EXT4_INODE_MODE_DIRECTORY)) {
*has_children = false;
return EOK;
}
struct ext4_dir_iter it;
int rc = ext4_dir_iterator_init(&it, enode, 0);
if (rc != EOK)
return rc;
/* Find a non-empty directory entry */
bool found = false;
while (it.curr != NULL) {
if (ext4_dir_en_get_inode(it.curr) != 0) {
uint16_t nsize;
nsize = ext4_dir_en_get_name_len(sb, it.curr);
if (!ext4_is_dots(it.curr->name, nsize)) {
found = true;
break;
}
}
rc = ext4_dir_iterator_next(&it);
if (rc != EOK) {
ext4_dir_iterator_fini(&it);
return rc;
}
}
rc = ext4_dir_iterator_fini(&it);
if (rc != EOK)
return rc;
*has_children = found;
return EOK;
}
static int ext4_link(struct ext4_mountpoint *mp, struct ext4_inode_ref *parent,
struct ext4_inode_ref *ch, const char *n,
uint32_t len, bool rename)
{
/* Check maximum name length */
if (len > EXT4_DIRECTORY_FILENAME_LEN)
return EINVAL;
/* Add entry to parent directory */
int r = ext4_dir_add_entry(parent, n, len, ch);
if (r != EOK)
return r;
/* Fill new dir -> add '.' and '..' entries.
* Also newly allocated inode should have 0 link count.
*/
bool is_dir = ext4_inode_is_type(&mp->fs.sb, ch->inode,
EXT4_INODE_MODE_DIRECTORY);
if (is_dir && !rename) {
#if CONFIG_DIR_INDEX_ENABLE
/* Initialize directory index if supported */
if (ext4_sb_feature_com(&mp->fs.sb, EXT4_FCOM_DIR_INDEX)) {
r = ext4_dir_dx_init(ch, parent);
if (r != EOK)
return r;
ext4_inode_set_flag(ch->inode, EXT4_INODE_FLAG_INDEX);
ch->dirty = true;
} else
#endif
{
r = ext4_dir_add_entry(ch, ".", strlen("."), ch);
if (r != EOK) {
ext4_dir_remove_entry(parent, n, strlen(n));
return r;
}
r = ext4_dir_add_entry(ch, "..", strlen(".."), parent);
if (r != EOK) {
ext4_dir_remove_entry(parent, n, strlen(n));
ext4_dir_remove_entry(ch, ".", strlen("."));
return r;
}
}
/*New empty directory. Two links (. and ..) */
ext4_inode_set_links_cnt(ch->inode, 2);
ext4_fs_inode_links_count_inc(parent);
ch->dirty = true;
parent->dirty = true;
return r;
}
/*
* In case we want to rename a directory,
* we reset the original '..' pointer.
*/
if (is_dir) {
bool idx;
idx = ext4_inode_has_flag(ch->inode, EXT4_INODE_FLAG_INDEX);
struct ext4_dir_search_result res;
if (!idx) {
r = ext4_dir_find_entry(&res, ch, "..", strlen(".."));
if (r != EOK)
return EIO;
ext4_dir_en_set_inode(res.dentry, parent->index);
ext4_trans_set_block_dirty(res.block.buf);
r = ext4_dir_destroy_result(ch, &res);
if (r != EOK)
return r;
} else {
#if CONFIG_DIR_INDEX_ENABLE
r = ext4_dir_dx_reset_parent_inode(ch, parent->index);
if (r != EOK)
return r;
#endif
}
ext4_fs_inode_links_count_inc(parent);
parent->dirty = true;
}
if (!rename) {
ext4_fs_inode_links_count_inc(ch);
ch->dirty = true;
}
return r;
}
static int
没有合适的资源?快使用搜索试试~ 我知道了~
ext4写的动态库_QT_ext4
共64个文件
h:36个
c:25个
pro:1个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 139 浏览量
2022-09-22
15:50:40
上传
评论
收藏 202KB RAR 举报
温馨提示
测试ext4文件系统的源码,在QT下封装了库
资源推荐
资源详情
资源评论
收起资源包目录
ext4写的动态库.rar (64个子文件)
ZMD_EXT4_FileSystem_DLL
misc
tree.h 27KB
queue.h 23KB
zmd_ext4_filesystem_dll.cpp 924B
ZMD_EXT4_FileSystem_DLL.pro 2KB
ext4_errno.h 3KB
ext4_inode.h 11KB
test_lwext4.h 2KB
lwext4_generic.c 9KB
ext4_dir_idx.h 3KB
ext4_ialloc.c 10KB
ext4_super.c 7KB
file_windows.h 2KB
ext4.c 65KB
ext4_block_group.h 10KB
ext4_trans.c 3KB
ext4_debug.h 5KB
lwext4_mkfs.c 6KB
ext4_trans.h 3KB
ext4_hash.h 2KB
file_windows.c 9KB
ext4_blockdev.c 10KB
tree.h 27KB
ext4_oflags.h 2KB
ext4_mkfs.c 24KB
ext4_journal.c 60KB
ext4_bcache.c 8KB
ext4_dir.c 19KB
ext4_ialloc.h 3KB
ext4_bitmap.c 3KB
ext4_inode.c 10KB
ext4_mkfs.h 2KB
ext4_super.h 7KB
stdbool.h 2KB
ext4_fs.c 48KB
ext4_debug.c 2KB
ext4_xattr.c 40KB
ext4_fs.h 9KB
zmd_ext4_filesystem_dll_global.h 348B
ext4_config.h 5KB
ext4.h 18KB
ext4_extent.h 2KB
ext4_dir_idx.c 39KB
generated
ext4_config.h 5KB
ext4_dir.h 9KB
ext4_blockdev.h 9KB
ext4_bitmap.h 3KB
ext4_crc32.c 9KB
ext4_mbr.h 2KB
ext4_hash.c 9KB
ext4_extent.c 57KB
ext4_journal.h 4KB
ext4_xattr.h 3KB
ZMD_EXT4_FileSystem_DLL.pro.user 24KB
ext4_balloc.c 18KB
zmd_ext4_filesystem_dll.h 665B
test_lwext4.c 10KB
ext4_balloc.h 4KB
queue.h 23KB
ext4_crc32.h 2KB
ext4_types.h 27KB
ext4_misc.h 5KB
ext4_mbr.c 6KB
ext4_block_group.c 4KB
ext4_bcache.h 8KB
共 64 条
- 1
资源评论
朱moyimi
- 粉丝: 65
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功