|
@@ -47,8 +47,6 @@
|
|
|
|
|
|
|
|
#include <string.h>
|
|
#include <string.h>
|
|
|
|
|
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
/****************************************************************************/
|
|
/****************************************************************************/
|
|
|
|
|
|
|
|
/**@brief Do some checks before returning iterator.
|
|
/**@brief Do some checks before returning iterator.
|
|
@@ -57,7 +55,7 @@
|
|
|
* @return Error code
|
|
* @return Error code
|
|
|
*/
|
|
*/
|
|
|
static int ext4_dir_iterator_set(struct ext4_directory_iterator *it,
|
|
static int ext4_dir_iterator_set(struct ext4_directory_iterator *it,
|
|
|
- uint32_t block_size)
|
|
|
|
|
|
|
+ uint32_t block_size)
|
|
|
{
|
|
{
|
|
|
it->current = NULL;
|
|
it->current = NULL;
|
|
|
|
|
|
|
@@ -72,7 +70,7 @@ static int ext4_dir_iterator_set(struct ext4_directory_iterator *it,
|
|
|
return EIO;
|
|
return EIO;
|
|
|
|
|
|
|
|
struct ext4_directory_entry_ll *entry =
|
|
struct ext4_directory_entry_ll *entry =
|
|
|
- (void *)(it->current_block.data + offset_in_block);
|
|
|
|
|
|
|
+ (void *)(it->current_block.data + offset_in_block);
|
|
|
|
|
|
|
|
/* Ensure that the whole entry does not overflow the block */
|
|
/* Ensure that the whole entry does not overflow the block */
|
|
|
uint16_t length = ext4_dir_entry_ll_get_entry_length(entry);
|
|
uint16_t length = ext4_dir_entry_ll_get_entry_length(entry);
|
|
@@ -80,8 +78,8 @@ static int ext4_dir_iterator_set(struct ext4_directory_iterator *it,
|
|
|
return EIO;
|
|
return EIO;
|
|
|
|
|
|
|
|
/* Ensure the name length is not too large */
|
|
/* Ensure the name length is not too large */
|
|
|
- if (ext4_dir_entry_ll_get_name_length(
|
|
|
|
|
- &it->inode_ref->fs->sb, entry) > length-8)
|
|
|
|
|
|
|
+ if (ext4_dir_entry_ll_get_name_length(&it->inode_ref->fs->sb, entry) >
|
|
|
|
|
+ length - 8)
|
|
|
return EIO;
|
|
return EIO;
|
|
|
|
|
|
|
|
/* Everything OK - "publish" the entry */
|
|
/* Everything OK - "publish" the entry */
|
|
@@ -96,10 +94,10 @@ static int ext4_dir_iterator_set(struct ext4_directory_iterator *it,
|
|
|
* @return Error code
|
|
* @return Error code
|
|
|
*/
|
|
*/
|
|
|
static int ext4_dir_iterator_seek(struct ext4_directory_iterator *it,
|
|
static int ext4_dir_iterator_seek(struct ext4_directory_iterator *it,
|
|
|
- uint64_t pos)
|
|
|
|
|
|
|
+ uint64_t pos)
|
|
|
{
|
|
{
|
|
|
- uint64_t size = ext4_inode_get_size(&it->inode_ref->fs->sb,
|
|
|
|
|
- it->inode_ref->inode);
|
|
|
|
|
|
|
+ uint64_t size =
|
|
|
|
|
+ ext4_inode_get_size(&it->inode_ref->fs->sb, it->inode_ref->inode);
|
|
|
|
|
|
|
|
/* The iterator is not valid until we seek to the desired position */
|
|
/* The iterator is not valid until we seek to the desired position */
|
|
|
it->current = NULL;
|
|
it->current = NULL;
|
|
@@ -108,8 +106,8 @@ static int ext4_dir_iterator_seek(struct ext4_directory_iterator *it,
|
|
|
if (pos >= size) {
|
|
if (pos >= size) {
|
|
|
if (it->current_block.lb_id) {
|
|
if (it->current_block.lb_id) {
|
|
|
|
|
|
|
|
- int rc = ext4_block_set(it->inode_ref->fs->bdev,
|
|
|
|
|
- &it->current_block);
|
|
|
|
|
|
|
+ int rc =
|
|
|
|
|
+ ext4_block_set(it->inode_ref->fs->bdev, &it->current_block);
|
|
|
it->current_block.lb_id = 0;
|
|
it->current_block.lb_id = 0;
|
|
|
|
|
|
|
|
if (rc != EOK)
|
|
if (rc != EOK)
|
|
@@ -121,8 +119,7 @@ static int ext4_dir_iterator_seek(struct ext4_directory_iterator *it,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Compute next block address */
|
|
/* Compute next block address */
|
|
|
- uint32_t block_size =
|
|
|
|
|
- ext4_sb_get_block_size(&it->inode_ref->fs->sb);
|
|
|
|
|
|
|
+ uint32_t block_size = ext4_sb_get_block_size(&it->inode_ref->fs->sb);
|
|
|
uint64_t current_block_idx = it->current_offset / block_size;
|
|
uint64_t current_block_idx = it->current_offset / block_size;
|
|
|
uint64_t next_block_idx = pos / block_size;
|
|
uint64_t next_block_idx = pos / block_size;
|
|
|
|
|
|
|
@@ -131,9 +128,10 @@ static int ext4_dir_iterator_seek(struct ext4_directory_iterator *it,
|
|
|
* we need to get another block
|
|
* we need to get another block
|
|
|
*/
|
|
*/
|
|
|
if ((it->current_block.lb_id == 0) ||
|
|
if ((it->current_block.lb_id == 0) ||
|
|
|
- (current_block_idx != next_block_idx)) {
|
|
|
|
|
|
|
+ (current_block_idx != next_block_idx)) {
|
|
|
if (it->current_block.lb_id) {
|
|
if (it->current_block.lb_id) {
|
|
|
- int rc = ext4_block_set(it->inode_ref->fs->bdev, &it->current_block);
|
|
|
|
|
|
|
+ int rc =
|
|
|
|
|
+ ext4_block_set(it->inode_ref->fs->bdev, &it->current_block);
|
|
|
it->current_block.lb_id = 0;
|
|
it->current_block.lb_id = 0;
|
|
|
|
|
|
|
|
if (rc != EOK)
|
|
if (rc != EOK)
|
|
@@ -141,14 +139,13 @@ static int ext4_dir_iterator_seek(struct ext4_directory_iterator *it,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
uint32_t next_block_phys_idx;
|
|
uint32_t next_block_phys_idx;
|
|
|
- int rc = ext4_fs_get_inode_data_block_index(it->inode_ref,
|
|
|
|
|
- next_block_idx, &next_block_phys_idx);
|
|
|
|
|
|
|
+ int rc = ext4_fs_get_inode_data_block_index(
|
|
|
|
|
+ it->inode_ref, next_block_idx, &next_block_phys_idx);
|
|
|
if (rc != EOK)
|
|
if (rc != EOK)
|
|
|
return rc;
|
|
return rc;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
rc = ext4_block_get(it->inode_ref->fs->bdev, &it->current_block,
|
|
rc = ext4_block_get(it->inode_ref->fs->bdev, &it->current_block,
|
|
|
- next_block_phys_idx);
|
|
|
|
|
|
|
+ next_block_phys_idx);
|
|
|
if (rc != EOK) {
|
|
if (rc != EOK) {
|
|
|
it->current_block.lb_id = 0;
|
|
it->current_block.lb_id = 0;
|
|
|
return rc;
|
|
return rc;
|
|
@@ -160,9 +157,8 @@ static int ext4_dir_iterator_seek(struct ext4_directory_iterator *it,
|
|
|
return ext4_dir_iterator_set(it, block_size);
|
|
return ext4_dir_iterator_set(it, block_size);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
int ext4_dir_iterator_init(struct ext4_directory_iterator *it,
|
|
int ext4_dir_iterator_init(struct ext4_directory_iterator *it,
|
|
|
- struct ext4_inode_ref *inode_ref, uint64_t pos)
|
|
|
|
|
|
|
+ struct ext4_inode_ref *inode_ref, uint64_t pos)
|
|
|
{
|
|
{
|
|
|
it->inode_ref = inode_ref;
|
|
it->inode_ref = inode_ref;
|
|
|
it->current = 0;
|
|
it->current = 0;
|
|
@@ -177,14 +173,14 @@ int ext4_dir_iterator_next(struct ext4_directory_iterator *it)
|
|
|
int r = EOK;
|
|
int r = EOK;
|
|
|
uint16_t skip;
|
|
uint16_t skip;
|
|
|
|
|
|
|
|
- while(r == EOK){
|
|
|
|
|
|
|
+ while (r == EOK) {
|
|
|
skip = ext4_dir_entry_ll_get_entry_length(it->current);
|
|
skip = ext4_dir_entry_ll_get_entry_length(it->current);
|
|
|
r = ext4_dir_iterator_seek(it, it->current_offset + skip);
|
|
r = ext4_dir_iterator_seek(it, it->current_offset + skip);
|
|
|
|
|
|
|
|
- if(!it->current)
|
|
|
|
|
|
|
+ if (!it->current)
|
|
|
break;
|
|
break;
|
|
|
/*Skip NULL referenced entry*/
|
|
/*Skip NULL referenced entry*/
|
|
|
- if(it->current->inode != 0)
|
|
|
|
|
|
|
+ if (it->current->inode != 0)
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -202,8 +198,9 @@ int ext4_dir_iterator_fini(struct ext4_directory_iterator *it)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void ext4_dir_write_entry(struct ext4_sblock *sb,
|
|
void ext4_dir_write_entry(struct ext4_sblock *sb,
|
|
|
- struct ext4_directory_entry_ll *entry, uint16_t entry_len,
|
|
|
|
|
- struct ext4_inode_ref *child, const char *name, size_t name_len)
|
|
|
|
|
|
|
+ struct ext4_directory_entry_ll *entry,
|
|
|
|
|
+ uint16_t entry_len, struct ext4_inode_ref *child,
|
|
|
|
|
+ const char *name, size_t name_len)
|
|
|
{
|
|
{
|
|
|
/* Check maximum entry length */
|
|
/* Check maximum entry length */
|
|
|
ext4_assert(entry_len <= ext4_sb_get_block_size(sb));
|
|
ext4_assert(entry_len <= ext4_sb_get_block_size(sb));
|
|
@@ -219,22 +216,22 @@ void ext4_dir_write_entry(struct ext4_sblock *sb,
|
|
|
/* Set type of entry */
|
|
/* Set type of entry */
|
|
|
if (ext4_inode_is_type(sb, child->inode, EXT4_INODE_MODE_DIRECTORY))
|
|
if (ext4_inode_is_type(sb, child->inode, EXT4_INODE_MODE_DIRECTORY))
|
|
|
ext4_dir_entry_ll_set_inode_type(sb, entry,
|
|
ext4_dir_entry_ll_set_inode_type(sb, entry,
|
|
|
- EXT4_DIRECTORY_FILETYPE_DIR);
|
|
|
|
|
|
|
+ EXT4_DIRECTORY_FILETYPE_DIR);
|
|
|
else
|
|
else
|
|
|
ext4_dir_entry_ll_set_inode_type(sb, entry,
|
|
ext4_dir_entry_ll_set_inode_type(sb, entry,
|
|
|
- EXT4_DIRECTORY_FILETYPE_REG_FILE);
|
|
|
|
|
|
|
+ EXT4_DIRECTORY_FILETYPE_REG_FILE);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,
|
|
int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,
|
|
|
- uint32_t name_len, struct ext4_inode_ref *child)
|
|
|
|
|
|
|
+ uint32_t name_len, struct ext4_inode_ref *child)
|
|
|
{
|
|
{
|
|
|
struct ext4_fs *fs = parent->fs;
|
|
struct ext4_fs *fs = parent->fs;
|
|
|
|
|
|
|
|
#if CONFIG_DIR_INDEX_ENABLE
|
|
#if CONFIG_DIR_INDEX_ENABLE
|
|
|
/* Index adding (if allowed) */
|
|
/* Index adding (if allowed) */
|
|
|
if ((ext4_sb_has_feature_compatible(&fs->sb,
|
|
if ((ext4_sb_has_feature_compatible(&fs->sb,
|
|
|
- EXT4_FEATURE_COMPAT_DIR_INDEX)) &&
|
|
|
|
|
- (ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX))) {
|
|
|
|
|
|
|
+ EXT4_FEATURE_COMPAT_DIR_INDEX)) &&
|
|
|
|
|
+ (ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX))) {
|
|
|
int rc = ext4_dir_dx_add_entry(parent, child, name);
|
|
int rc = ext4_dir_dx_add_entry(parent, child, name);
|
|
|
|
|
|
|
|
/* Check if index is not corrupted */
|
|
/* Check if index is not corrupted */
|
|
@@ -258,24 +255,20 @@ int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,
|
|
|
uint32_t inode_size = ext4_inode_get_size(&fs->sb, parent->inode);
|
|
uint32_t inode_size = ext4_inode_get_size(&fs->sb, parent->inode);
|
|
|
uint32_t total_blocks = inode_size / block_size;
|
|
uint32_t total_blocks = inode_size / block_size;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
/* Find block, where is space for new entry and try to add */
|
|
/* Find block, where is space for new entry and try to add */
|
|
|
bool success = false;
|
|
bool success = false;
|
|
|
for (iblock = 0; iblock < total_blocks; ++iblock) {
|
|
for (iblock = 0; iblock < total_blocks; ++iblock) {
|
|
|
- int rc = ext4_fs_get_inode_data_block_index(parent,
|
|
|
|
|
- iblock, &fblock);
|
|
|
|
|
|
|
+ int rc = ext4_fs_get_inode_data_block_index(parent, iblock, &fblock);
|
|
|
if (rc != EOK)
|
|
if (rc != EOK)
|
|
|
return rc;
|
|
return rc;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
struct ext4_block block;
|
|
struct ext4_block block;
|
|
|
rc = ext4_block_get(fs->bdev, &block, fblock);
|
|
rc = ext4_block_get(fs->bdev, &block, fblock);
|
|
|
if (rc != EOK)
|
|
if (rc != EOK)
|
|
|
return rc;
|
|
return rc;
|
|
|
|
|
|
|
|
/* If adding is successful, function can finish */
|
|
/* If adding is successful, function can finish */
|
|
|
- rc = ext4_dir_try_insert_entry(&fs->sb, &block,
|
|
|
|
|
- child, name, name_len);
|
|
|
|
|
|
|
+ rc = ext4_dir_try_insert_entry(&fs->sb, &block, child, name, name_len);
|
|
|
if (rc == EOK)
|
|
if (rc == EOK)
|
|
|
success = true;
|
|
success = true;
|
|
|
|
|
|
|
@@ -305,8 +298,8 @@ int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,
|
|
|
/* Fill block with zeroes */
|
|
/* Fill block with zeroes */
|
|
|
memset(new_block.data, 0, block_size);
|
|
memset(new_block.data, 0, block_size);
|
|
|
struct ext4_directory_entry_ll *block_entry = (void *)new_block.data;
|
|
struct ext4_directory_entry_ll *block_entry = (void *)new_block.data;
|
|
|
- ext4_dir_write_entry(&fs->sb, block_entry, block_size,
|
|
|
|
|
- child, name, name_len);
|
|
|
|
|
|
|
+ ext4_dir_write_entry(&fs->sb, block_entry, block_size, child, name,
|
|
|
|
|
+ name_len);
|
|
|
|
|
|
|
|
/* Save new block */
|
|
/* Save new block */
|
|
|
new_block.dirty = true;
|
|
new_block.dirty = true;
|
|
@@ -316,18 +309,16 @@ int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int ext4_dir_find_entry(struct ext4_directory_search_result *result,
|
|
int ext4_dir_find_entry(struct ext4_directory_search_result *result,
|
|
|
- struct ext4_inode_ref *parent, const char *name, uint32_t name_len)
|
|
|
|
|
|
|
+ struct ext4_inode_ref *parent, const char *name,
|
|
|
|
|
+ uint32_t name_len)
|
|
|
{
|
|
{
|
|
|
struct ext4_sblock *sb = &parent->fs->sb;
|
|
struct ext4_sblock *sb = &parent->fs->sb;
|
|
|
|
|
|
|
|
-
|
|
|
|
|
#if CONFIG_DIR_INDEX_ENABLE
|
|
#if CONFIG_DIR_INDEX_ENABLE
|
|
|
/* Index search */
|
|
/* Index search */
|
|
|
- if ((ext4_sb_has_feature_compatible(sb,
|
|
|
|
|
- EXT4_FEATURE_COMPAT_DIR_INDEX)) &&
|
|
|
|
|
- (ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX))) {
|
|
|
|
|
- int rc = ext4_dir_dx_find_entry(result, parent, name_len,
|
|
|
|
|
- name);
|
|
|
|
|
|
|
+ if ((ext4_sb_has_feature_compatible(sb, EXT4_FEATURE_COMPAT_DIR_INDEX)) &&
|
|
|
|
|
+ (ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX))) {
|
|
|
|
|
+ int rc = ext4_dir_dx_find_entry(result, parent, name_len, name);
|
|
|
|
|
|
|
|
/* Check if index is not corrupted */
|
|
/* Check if index is not corrupted */
|
|
|
if (rc != EXT4_ERR_BAD_DX_DIR) {
|
|
if (rc != EXT4_ERR_BAD_DX_DIR) {
|
|
@@ -354,21 +345,19 @@ int ext4_dir_find_entry(struct ext4_directory_search_result *result,
|
|
|
/* Walk through all data blocks */
|
|
/* Walk through all data blocks */
|
|
|
for (iblock = 0; iblock < total_blocks; ++iblock) {
|
|
for (iblock = 0; iblock < total_blocks; ++iblock) {
|
|
|
/* Load block address */
|
|
/* Load block address */
|
|
|
- int rc = ext4_fs_get_inode_data_block_index(parent, iblock,
|
|
|
|
|
- &fblock);
|
|
|
|
|
|
|
+ int rc = ext4_fs_get_inode_data_block_index(parent, iblock, &fblock);
|
|
|
if (rc != EOK)
|
|
if (rc != EOK)
|
|
|
return rc;
|
|
return rc;
|
|
|
|
|
|
|
|
/* Load data block */
|
|
/* Load data block */
|
|
|
struct ext4_block block;
|
|
struct ext4_block block;
|
|
|
- rc = ext4_block_get( parent->fs->bdev, &block, fblock);
|
|
|
|
|
|
|
+ rc = ext4_block_get(parent->fs->bdev, &block, fblock);
|
|
|
if (rc != EOK)
|
|
if (rc != EOK)
|
|
|
return rc;
|
|
return rc;
|
|
|
|
|
|
|
|
/* Try to find entry in block */
|
|
/* Try to find entry in block */
|
|
|
struct ext4_directory_entry_ll *res_entry;
|
|
struct ext4_directory_entry_ll *res_entry;
|
|
|
- rc = ext4_dir_find_in_block(&block, sb, name_len, name,
|
|
|
|
|
- &res_entry);
|
|
|
|
|
|
|
+ rc = ext4_dir_find_in_block(&block, sb, name_len, name, &res_entry);
|
|
|
if (rc == EOK) {
|
|
if (rc == EOK) {
|
|
|
result->block = block;
|
|
result->block = block;
|
|
|
result->dentry = res_entry;
|
|
result->dentry = res_entry;
|
|
@@ -391,11 +380,11 @@ int ext4_dir_find_entry(struct ext4_directory_search_result *result,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,
|
|
int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,
|
|
|
- uint32_t name_len)
|
|
|
|
|
|
|
+ uint32_t name_len)
|
|
|
{
|
|
{
|
|
|
/* Check if removing from directory */
|
|
/* Check if removing from directory */
|
|
|
if (!ext4_inode_is_type(&parent->fs->sb, parent->inode,
|
|
if (!ext4_inode_is_type(&parent->fs->sb, parent->inode,
|
|
|
- EXT4_INODE_MODE_DIRECTORY))
|
|
|
|
|
|
|
+ EXT4_INODE_MODE_DIRECTORY))
|
|
|
return ENOTDIR;
|
|
return ENOTDIR;
|
|
|
|
|
|
|
|
/* Try to find entry */
|
|
/* Try to find entry */
|
|
@@ -408,7 +397,7 @@ int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,
|
|
|
ext4_dir_entry_ll_set_inode(result.dentry, 0);
|
|
ext4_dir_entry_ll_set_inode(result.dentry, 0);
|
|
|
|
|
|
|
|
/* Store entry position in block */
|
|
/* Store entry position in block */
|
|
|
- uint32_t pos = (uint8_t *) result.dentry - result.block.data;
|
|
|
|
|
|
|
+ uint32_t pos = (uint8_t *)result.dentry - result.block.data;
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
* If entry is not the first in block, it must be merged
|
|
* If entry is not the first in block, it must be merged
|
|
@@ -420,24 +409,22 @@ int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,
|
|
|
/* Start from the first entry in block */
|
|
/* Start from the first entry in block */
|
|
|
struct ext4_directory_entry_ll *tmp_dentry = (void *)result.block.data;
|
|
struct ext4_directory_entry_ll *tmp_dentry = (void *)result.block.data;
|
|
|
uint16_t tmp_dentry_length =
|
|
uint16_t tmp_dentry_length =
|
|
|
- ext4_dir_entry_ll_get_entry_length(tmp_dentry);
|
|
|
|
|
|
|
+ ext4_dir_entry_ll_get_entry_length(tmp_dentry);
|
|
|
|
|
|
|
|
/* Find direct predecessor of removed entry */
|
|
/* Find direct predecessor of removed entry */
|
|
|
while ((offset + tmp_dentry_length) < pos) {
|
|
while ((offset + tmp_dentry_length) < pos) {
|
|
|
- offset +=
|
|
|
|
|
- ext4_dir_entry_ll_get_entry_length(tmp_dentry);
|
|
|
|
|
|
|
+ offset += ext4_dir_entry_ll_get_entry_length(tmp_dentry);
|
|
|
tmp_dentry = (void *)(result.block.data + offset);
|
|
tmp_dentry = (void *)(result.block.data + offset);
|
|
|
- tmp_dentry_length =
|
|
|
|
|
- ext4_dir_entry_ll_get_entry_length(tmp_dentry);
|
|
|
|
|
|
|
+ tmp_dentry_length = ext4_dir_entry_ll_get_entry_length(tmp_dentry);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
ext4_assert(tmp_dentry_length + offset == pos);
|
|
ext4_assert(tmp_dentry_length + offset == pos);
|
|
|
|
|
|
|
|
/* Add to removed entry length to predecessor's length */
|
|
/* Add to removed entry length to predecessor's length */
|
|
|
uint16_t del_entry_length =
|
|
uint16_t del_entry_length =
|
|
|
- ext4_dir_entry_ll_get_entry_length(result.dentry);
|
|
|
|
|
- ext4_dir_entry_ll_set_entry_length(tmp_dentry,
|
|
|
|
|
- tmp_dentry_length + del_entry_length);
|
|
|
|
|
|
|
+ ext4_dir_entry_ll_get_entry_length(result.dentry);
|
|
|
|
|
+ ext4_dir_entry_ll_set_entry_length(tmp_dentry, tmp_dentry_length +
|
|
|
|
|
+ del_entry_length);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
result.block.dirty = true;
|
|
result.block.dirty = true;
|
|
@@ -446,8 +433,9 @@ int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
|
|
int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
|
|
|
- struct ext4_block *target_block, struct ext4_inode_ref *child,
|
|
|
|
|
- const char *name, uint32_t name_len)
|
|
|
|
|
|
|
+ struct ext4_block *target_block,
|
|
|
|
|
+ struct ext4_inode_ref *child, const char *name,
|
|
|
|
|
+ uint32_t name_len)
|
|
|
{
|
|
{
|
|
|
/* Compute required length entry and align it to 4 bytes */
|
|
/* Compute required length entry and align it to 4 bytes */
|
|
|
uint32_t block_size = ext4_sb_get_block_size(sb);
|
|
uint32_t block_size = ext4_sb_get_block_size(sb);
|
|
@@ -457,9 +445,9 @@ int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
|
|
|
required_len += 4 - (required_len % 4);
|
|
required_len += 4 - (required_len % 4);
|
|
|
|
|
|
|
|
/* Initialize pointers, stop means to upper bound */
|
|
/* Initialize pointers, stop means to upper bound */
|
|
|
- struct ext4_directory_entry_ll *dentry = (void *)target_block->data;
|
|
|
|
|
|
|
+ struct ext4_directory_entry_ll *dentry = (void *)target_block->data;
|
|
|
struct ext4_directory_entry_ll *stop =
|
|
struct ext4_directory_entry_ll *stop =
|
|
|
- (void *)(target_block->data + block_size);
|
|
|
|
|
|
|
+ (void *)(target_block->data + block_size);
|
|
|
|
|
|
|
|
/*
|
|
/*
|
|
|
* Walk through the block and check for invalid entries
|
|
* Walk through the block and check for invalid entries
|
|
@@ -471,8 +459,7 @@ int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
|
|
|
|
|
|
|
|
/* If invalid and large enough entry, use it */
|
|
/* If invalid and large enough entry, use it */
|
|
|
if ((inode == 0) && (rec_len >= required_len)) {
|
|
if ((inode == 0) && (rec_len >= required_len)) {
|
|
|
- ext4_dir_write_entry(sb, dentry, rec_len, child,
|
|
|
|
|
- name, name_len);
|
|
|
|
|
|
|
+ ext4_dir_write_entry(sb, dentry, rec_len, child, name, name_len);
|
|
|
target_block->dirty = true;
|
|
target_block->dirty = true;
|
|
|
|
|
|
|
|
return EOK;
|
|
return EOK;
|
|
@@ -481,10 +468,10 @@ int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
|
|
|
/* Valid entry, try to split it */
|
|
/* Valid entry, try to split it */
|
|
|
if (inode != 0) {
|
|
if (inode != 0) {
|
|
|
uint16_t used_name_len =
|
|
uint16_t used_name_len =
|
|
|
- ext4_dir_entry_ll_get_name_length(sb, dentry);
|
|
|
|
|
|
|
+ ext4_dir_entry_ll_get_name_length(sb, dentry);
|
|
|
|
|
|
|
|
uint16_t used_space =
|
|
uint16_t used_space =
|
|
|
- sizeof(struct ext4_fake_directory_entry) + used_name_len;
|
|
|
|
|
|
|
+ sizeof(struct ext4_fake_directory_entry) + used_name_len;
|
|
|
|
|
|
|
|
if ((used_name_len % 4) != 0)
|
|
if ((used_name_len % 4) != 0)
|
|
|
used_space += 4 - (used_name_len % 4);
|
|
used_space += 4 - (used_name_len % 4);
|
|
@@ -496,9 +483,9 @@ int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
|
|
|
/* Cut tail of current entry */
|
|
/* Cut tail of current entry */
|
|
|
ext4_dir_entry_ll_set_entry_length(dentry, used_space);
|
|
ext4_dir_entry_ll_set_entry_length(dentry, used_space);
|
|
|
struct ext4_directory_entry_ll *new_entry =
|
|
struct ext4_directory_entry_ll *new_entry =
|
|
|
- (void *) ((uint8_t *)dentry + used_space);
|
|
|
|
|
- ext4_dir_write_entry(sb, new_entry,
|
|
|
|
|
- free_space, child, name, name_len);
|
|
|
|
|
|
|
+ (void *)((uint8_t *)dentry + used_space);
|
|
|
|
|
+ ext4_dir_write_entry(sb, new_entry, free_space, child, name,
|
|
|
|
|
+ name_len);
|
|
|
|
|
|
|
|
target_block->dirty = true;
|
|
target_block->dirty = true;
|
|
|
return EOK;
|
|
return EOK;
|
|
@@ -506,54 +493,51 @@ int ext4_dir_try_insert_entry(struct ext4_sblock *sb,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Jump to the next entry */
|
|
/* Jump to the next entry */
|
|
|
- dentry = (void *) ((uint8_t *)dentry + rec_len);
|
|
|
|
|
|
|
+ dentry = (void *)((uint8_t *)dentry + rec_len);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* No free space found for new entry */
|
|
/* No free space found for new entry */
|
|
|
return ENOSPC;
|
|
return ENOSPC;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-
|
|
|
|
|
int ext4_dir_find_in_block(struct ext4_block *block, struct ext4_sblock *sb,
|
|
int ext4_dir_find_in_block(struct ext4_block *block, struct ext4_sblock *sb,
|
|
|
- size_t name_len, const char *name,
|
|
|
|
|
- struct ext4_directory_entry_ll **res_entry)
|
|
|
|
|
|
|
+ size_t name_len, const char *name,
|
|
|
|
|
+ struct ext4_directory_entry_ll **res_entry)
|
|
|
{
|
|
{
|
|
|
/* Start from the first entry in block */
|
|
/* Start from the first entry in block */
|
|
|
struct ext4_directory_entry_ll *dentry =
|
|
struct ext4_directory_entry_ll *dentry =
|
|
|
- (struct ext4_directory_entry_ll *) block->data;
|
|
|
|
|
|
|
+ (struct ext4_directory_entry_ll *)block->data;
|
|
|
|
|
|
|
|
/* Set upper bound for cycling */
|
|
/* Set upper bound for cycling */
|
|
|
uint8_t *addr_limit = block->data + ext4_sb_get_block_size(sb);
|
|
uint8_t *addr_limit = block->data + ext4_sb_get_block_size(sb);
|
|
|
|
|
|
|
|
/* Walk through the block and check entries */
|
|
/* Walk through the block and check entries */
|
|
|
- while ((uint8_t *) dentry < addr_limit) {
|
|
|
|
|
|
|
+ while ((uint8_t *)dentry < addr_limit) {
|
|
|
/* Termination condition */
|
|
/* Termination condition */
|
|
|
- if ((uint8_t *) dentry + name_len > addr_limit)
|
|
|
|
|
|
|
+ if ((uint8_t *)dentry + name_len > addr_limit)
|
|
|
break;
|
|
break;
|
|
|
|
|
|
|
|
/* Valid entry - check it */
|
|
/* Valid entry - check it */
|
|
|
if (dentry->inode != 0) {
|
|
if (dentry->inode != 0) {
|
|
|
/* For more effectivity compare firstly only lengths */
|
|
/* For more effectivity compare firstly only lengths */
|
|
|
- if (ext4_dir_entry_ll_get_name_length(sb, dentry) ==
|
|
|
|
|
- name_len) {
|
|
|
|
|
|
|
+ if (ext4_dir_entry_ll_get_name_length(sb, dentry) == name_len) {
|
|
|
/* Compare names */
|
|
/* Compare names */
|
|
|
- if (memcmp((uint8_t *) name, dentry->name, name_len) == 0) {
|
|
|
|
|
|
|
+ if (memcmp((uint8_t *)name, dentry->name, name_len) == 0) {
|
|
|
*res_entry = dentry;
|
|
*res_entry = dentry;
|
|
|
return EOK;
|
|
return EOK;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- uint16_t dentry_len =
|
|
|
|
|
- ext4_dir_entry_ll_get_entry_length(dentry);
|
|
|
|
|
|
|
+ uint16_t dentry_len = ext4_dir_entry_ll_get_entry_length(dentry);
|
|
|
|
|
|
|
|
/* Corrupted entry */
|
|
/* Corrupted entry */
|
|
|
if (dentry_len == 0)
|
|
if (dentry_len == 0)
|
|
|
return EINVAL;
|
|
return EINVAL;
|
|
|
|
|
|
|
|
/* Jump to next entry */
|
|
/* Jump to next entry */
|
|
|
- dentry = (struct ext4_directory_entry_ll *)
|
|
|
|
|
- ((uint8_t *) dentry + dentry_len);
|
|
|
|
|
|
|
+ dentry =
|
|
|
|
|
+ (struct ext4_directory_entry_ll *)((uint8_t *)dentry + dentry_len);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/* Entry not found */
|
|
/* Entry not found */
|
|
@@ -561,7 +545,7 @@ int ext4_dir_find_in_block(struct ext4_block *block, struct ext4_sblock *sb,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
int ext4_dir_destroy_result(struct ext4_inode_ref *parent,
|
|
int ext4_dir_destroy_result(struct ext4_inode_ref *parent,
|
|
|
- struct ext4_directory_search_result *result)
|
|
|
|
|
|
|
+ struct ext4_directory_search_result *result)
|
|
|
{
|
|
{
|
|
|
if (result->block.lb_id)
|
|
if (result->block.lb_id)
|
|
|
return ext4_block_set(parent->fs->bdev, &result->block);
|
|
return ext4_block_set(parent->fs->bdev, &result->block);
|