Stack usage improvement.
* |---------------------------------------------------------------|\r
* | w+ or wb+ or w+b O_RDWR|O_CREAT|O_TRUNC |\r
* |---------------------------------------------------------------|\r
- * | a+ or ab+ or a+b O_RDWR|O_CREAT|O_APPEND |\r
+ * | a+ or ab+ or a+b O_RDWR|O_CREAT|O_APPEND |\r
* |---------------------------------------------------------------|\r
*\r
* @return standard error code*/\r
#include <stdlib.h>\r
#include <string.h>\r
\r
-#include "ext4.h"\r
+#include <ext4.h>\r
\r
/**@brief Mount point OS dependent lock*/\r
#define EXT4_MP_LOCK(_m) \\r
\r
\r
static int ext4_link(struct ext4_mountpoint *mp, struct ext4_inode_ref *parent,\r
- struct ext4_inode_ref *child, const char *name)\r
+ struct ext4_inode_ref *child, const char *name, uint32_t name_len)\r
{\r
/* Check maximum name length */\r
- if (strlen(name) > EXT4_DIRECTORY_FILENAME_LEN)\r
+ if(name_len > EXT4_DIRECTORY_FILENAME_LEN)\r
return EINVAL;\r
\r
/* Add entry to parent directory */\r
- int rc = ext4_dir_add_entry(parent, name,\r
+ int rc = ext4_dir_add_entry(parent, name, name_len,\r
child);\r
if (rc != EOK)\r
return rc;\r
/* Fill new dir -> add '.' and '..' entries */\r
if (ext4_inode_is_type(&mp->fs.sb, child->inode,\r
EXT4_INODE_MODE_DIRECTORY)) {\r
- rc = ext4_dir_add_entry(child, ".",\r
+ rc = ext4_dir_add_entry(child, ".", strlen("."),\r
child);\r
if (rc != EOK) {\r
- ext4_dir_remove_entry(parent, name);\r
+ ext4_dir_remove_entry(parent, name, strlen(name));\r
return rc;\r
}\r
\r
- rc = ext4_dir_add_entry(child, "..",\r
+ rc = ext4_dir_add_entry(child, "..", strlen(".."),\r
parent);\r
if (rc != EOK) {\r
- ext4_dir_remove_entry(parent, name);\r
- ext4_dir_remove_entry(child, ".");\r
+ ext4_dir_remove_entry(parent, name, strlen(name));\r
+ ext4_dir_remove_entry(child, ".", strlen("."));\r
return rc;\r
}\r
\r
\r
static int ext4_unlink(struct ext4_mountpoint *mp,\r
struct ext4_inode_ref *parent, struct ext4_inode_ref *child_inode_ref,\r
- const char *name)\r
+ const char *name, uint32_t name_len)\r
{\r
bool has_children;\r
int rc = ext4_has_children(&has_children, child_inode_ref);\r
\r
/* Remove entry from parent directory */\r
\r
- rc = ext4_dir_remove_entry(parent, name);\r
+ rc = ext4_dir_remove_entry(parent, name, name_len);\r
if (rc != EOK)\r
return rc;\r
\r
struct ext4_mountpoint *mp = ext4_get_mount(path);\r
struct ext4_directory_search_result result;\r
struct ext4_inode_ref ref;\r
- char entry_name[255];\r
bool is_goal = false;\r
uint8_t inode_type;\r
int r = ENOENT;\r
break;\r
}\r
\r
- memcpy(entry_name, path, len);\r
- entry_name[len] = 0;\r
-\r
- r = ext4_dir_find_entry(&result, &ref, entry_name);\r
+ r = ext4_dir_find_entry(&result, &ref, path, len);\r
if(r != EOK){\r
\r
if(r != ENOENT)\r
ext4_dir_destroy_result(&ref, &result);\r
\r
/*Link with root dir.*/\r
- r = ext4_link(mp, &ref, &child_ref, entry_name);\r
+ r = ext4_link(mp, &ref, &child_ref, path, len);\r
if(r != EOK){\r
/*Fali. Free new inode.*/\r
ext4_fs_free_inode(&child_ref);\r
{\r
struct ext4_mountpoint *mp = ext4_get_mount(path);\r
struct ext4_directory_search_result result;\r
- char entry_name[255];\r
bool is_goal = false;\r
uint8_t inode_type;\r
int r = ENOENT;\r
\r
struct ext4_inode_ref parent;\r
struct ext4_inode_ref child;\r
+ int len = 0;\r
\r
if(!mp)\r
return ENOENT;\r
\r
while(1){\r
\r
- int len = ext4_path_check(path, &is_goal);\r
+ len = ext4_path_check(path, &is_goal);\r
\r
if(!len){\r
r = ENOENT;\r
break;\r
}\r
\r
- memcpy(entry_name, path, len);\r
- entry_name[len] = 0;\r
-\r
- r = ext4_dir_find_entry(&result, &parent, entry_name);\r
+ r = ext4_dir_find_entry(&result, &parent, path, len);\r
if(r != EOK){\r
ext4_dir_destroy_result(&parent, &result);\r
break;\r
goto Finish;\r
\r
/*Unlink from parent.*/\r
- r = ext4_unlink(mp, &parent, &child, entry_name);\r
+ r = ext4_unlink(mp, &parent, &child, path, len);\r
if(r != EOK)\r
goto Finish;\r
\r
/*Update usage marker*/\r
bc->lru_id[i] = ++bc->lru_ctr;\r
\r
- /*Set valid cache data*/\r
+ /*Set valid cache data and id*/\r
b->data = bc->data + i * bc->itemsize;\r
+ b->cache_id = i;\r
\r
return EOK;\r
}\r
bc->refctr[cache_id] = 1;\r
bc->lru_id[cache_id] = ++bc->lru_ctr;\r
\r
- /*Set valid cache data*/\r
+ /*Set valid cache data and id*/\r
b->data = bc->data + cache_id * bc->itemsize;\r
+ b->cache_id = cache_id;\r
\r
/*Statistics*/\r
bc->ref_blocks++;\r
int ext4_bcache_free (struct ext4_bcache *bc, struct ext4_block *b,\r
uint8_t free_delay)\r
{\r
- uint32_t i;\r
-\r
ext4_assert(bc && b);\r
\r
/*Check if valid.*/\r
ext4_assert(b->lb_id);\r
\r
/*Block should be in cache.*/\r
- for (i = 0; i < bc->cnt; ++i) {\r
+ ext4_assert(b->cache_id < bc->cnt);\r
\r
- if(bc->lba[i] != b->lb_id)\r
- continue;\r
-\r
- /*Check if someone don't try free unreferenced block cache.*/\r
- ext4_assert(bc->refctr[i]);\r
+ /*Check if someone don't try free unreferenced block cache.*/\r
+ ext4_assert(bc->refctr[b->cache_id]);\r
\r
- /*Just decrease reference counter*/\r
- if(bc->refctr[i])\r
- bc->refctr[i]--;\r
+ /*Just decrease reference counter*/\r
+ if(bc->refctr[b->cache_id])\r
+ bc->refctr[b->cache_id]--;\r
\r
+ if(free_delay)\r
+ bc->free_delay[b->cache_id] = free_delay;\r
\r
- if(free_delay)\r
- bc->free_delay[i] = free_delay;\r
+ /*Update statistics*/\r
+ if(!bc->refctr[b->cache_id] && !bc->free_delay[b->cache_id])\r
+ bc->ref_blocks--;\r
\r
- /*Update statistics*/\r
- if(!bc->refctr[i] && !bc->free_delay[i])\r
- bc->ref_blocks--;\r
+ b->lb_id = 0;\r
+ b->data = 0;\r
+ b->cache_id = 0;\r
\r
- b->lb_id = 0;\r
- b->data = 0;\r
+ return EOK;\r
+}\r
\r
- return EOK;\r
- }\r
\r
- ext4_dprintf(EXT4_DEBUG_BCACHE,\r
- "ext4_bcache_free: FAIL, block should be in cache memory !\n");\r
- return EFAULT;\r
-}\r
\r
bool ext4_bcache_is_full(struct ext4_bcache *bc)\r
{\r
/**@brief Logical block ID*/\r
uint64_t lb_id;\r
\r
+ /**@brief Cache id*/\r
+ uint32_t cache_id;\r
+\r
/**@brief Data buffer.*/\r
uint8_t *data;\r
};\r
return EOK;
}
- b->dirty = false;
-
-
/*Free cache delay mode*/
if(bdev->cache_flush_delay){
}\r
\r
int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,\r
- struct ext4_inode_ref *child)\r
+ uint32_t name_len, struct ext4_inode_ref *child)\r
{\r
struct ext4_fs *fs = parent->fs;\r
\r
uint32_t inode_size = ext4_inode_get_size(&fs->sb, parent->inode);\r
uint32_t total_blocks = inode_size / block_size;\r
\r
- uint32_t name_len = strlen(name);\r
\r
/* Find block, where is space for new entry and try to add */\r
bool success = false;\r
}\r
\r
int ext4_dir_find_entry(struct ext4_directory_search_result *result,\r
- struct ext4_inode_ref *parent, const char *name)\r
+ struct ext4_inode_ref *parent, const char *name, uint32_t name_len)\r
{\r
- uint32_t name_len = strlen(name);\r
-\r
struct ext4_sblock *sb = &parent->fs->sb;\r
\r
\r
return ENOENT;\r
}\r
\r
-int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name)\r
+int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,\r
+ uint32_t name_len)\r
{\r
/* Check if removing from directory */\r
if (!ext4_inode_is_type(&parent->fs->sb, parent->inode,\r
\r
/* Try to find entry */\r
struct ext4_directory_search_result result;\r
- int rc = ext4_dir_find_entry(&result, parent, name);\r
+ int rc = ext4_dir_find_entry(&result, parent, name, name_len);\r
if (rc != EOK)\r
return rc;\r
\r
struct ext4_directory_entry_ll *entry, uint16_t entry_len,\r
struct ext4_inode_ref *child, const char *name, size_t name_len);\r
\r
-int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,\r
- struct ext4_inode_ref *child);\r
+int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,\r
+ uint32_t name_len, struct ext4_inode_ref *child);\r
\r
int ext4_dir_find_entry(struct ext4_directory_search_result *result,\r
- struct ext4_inode_ref *parent, const char *name);\r
+ struct ext4_inode_ref *parent, const char *name, uint32_t name_len);\r
\r
-int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name);\r
+int ext4_dir_remove_entry(struct ext4_inode_ref *parent, const char *name,\r
+ uint32_t name_len);\r
\r
int ext4_dir_try_insert_entry(struct ext4_sblock *sb,\r
struct ext4_block *target_block, struct ext4_inode_ref *child,\r