shithub: lwext4

Download patch

ref: b1083b540d92bad9fecc510d0c0ca4e12abd14a0
parent: d8eb51d6cbf9f9704ec7189e011fe89e6ac7bd07
author: gkostka <kostka.grzegorz@gmail.com>
date: Thu Dec 3 16:30:39 EST 2015

ext4_fs: reactor some long function names

New, more useful names:
 - ext4_fs_init_inode_dblk_idx
 - ext4_fs_get_inode_dblk_idx
 - ext4_fs_append_inode_dblk

--- a/lwext4/ext4.c
+++ b/lwext4/ext4.c
@@ -228,7 +228,7 @@
 		}
 
 		/*New empty directory. Two links (. and ..) */
-		ext4_inode_set_links_cnt(c->inode, 2);
+		ext4_inode_set_links_cnt(ch->inode, 2);
 		ext4_fs_inode_links_count_inc(parent);
 		ch->dirty = true;
 		parent->dirty = true;
@@ -240,7 +240,7 @@
 	 */
 	if (is_dir) {
 		bool idx;
-		idx = ext4_inode_has_flag(c->inode, EXT4_INODE_FLAG_INDEX);
+		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(".."));
@@ -316,7 +316,7 @@
 	 * ext4_inode_set_change_inode_time(child->inode,
 	 *     (uint32_t) now);
 	 */
-	if (ext4_inode_get_links_cnt(child_inode_ref->inode)) {
+	if (ext4_inode_get_links_cnt(child->inode)) {
 		ext4_fs_inode_links_count_dec(child);
 		child->dirty = true;
 	}
@@ -1353,8 +1353,7 @@
 		if (size > (block_size - unalg))
 			len = block_size - unalg;
 
-		r = ext4_fs_get_inode_data_block_index(&ref, iblock_idx,
-							&fblock, true);
+		r = ext4_fs_get_inode_dblk_idx(&ref, iblock_idx, &fblock, true);
 		if (r != EOK)
 			goto Finish;
 
@@ -1388,8 +1387,8 @@
 	fblock_count = 0;
 	while (size >= block_size) {
 		while (iblock_idx < iblock_last) {
-			r = ext4_fs_get_inode_data_block_index(&ref, iblock_idx,
-							       &fblock, true);
+			r = ext4_fs_get_inode_dblk_idx(&ref, iblock_idx,
+						       &fblock, true);
 			if (r != EOK)
 				goto Finish;
 
@@ -1421,8 +1420,7 @@
 	}
 
 	if (size) {
-		r = ext4_fs_get_inode_data_block_index(&ref, iblock_idx,
-						       &fblock, true);
+		r = ext4_fs_get_inode_dblk_idx(&ref, iblock_idx, &fblock, true);
 		if (r != EOK)
 			goto Finish;
 
@@ -1502,7 +1500,7 @@
 		if (size > (block_size - unalg))
 			len = block_size - unalg;
 
-		r = ext4_fs_init_inode_data_block_index(&ref, iblk_idx, &fblk);
+		r = ext4_fs_init_inode_dblk_idx(&ref, iblk_idx, &fblk);
 		if (r != EOK)
 			goto Finish;
 
@@ -1538,12 +1536,12 @@
 
 		while (iblk_idx < iblock_last) {
 			if (iblk_idx < ifile_blocks) {
-				r = ext4_fs_init_inode_data_block_index(
-				    &ref, iblk_idx, &fblk);
+				r = ext4_fs_init_inode_dblk_idx(&ref, iblk_idx,
+								&fblk);
 				if (r != EOK)
 					goto Finish;
 			} else {
-				rr = ext4_fs_append_inode_block(&ref, &fblk,
+				rr = ext4_fs_append_inode_dblk(&ref, &fblk,
 							       &iblk_idx);
 				if (rr != EOK) {
 					/* Unable to append more blocks. But
@@ -1597,12 +1595,11 @@
 
 	if (size) {
 		if (iblk_idx < ifile_blocks) {
-			r = ext4_fs_init_inode_data_block_index(&ref, iblk_idx,
-							        &fblk);
+			r = ext4_fs_init_inode_dblk_idx(&ref, iblk_idx, &fblk);
 			if (r != EOK)
 				goto Finish;
 		} else {
-			r = ext4_fs_append_inode_block(&ref, &fblk, &iblk_idx);
+			r = ext4_fs_append_inode_dblk(&ref, &fblk, &iblk_idx);
 			if (r != EOK)
 				/*Node size sholud be updated.*/
 				goto out_fsize;
@@ -1888,7 +1885,7 @@
 		ext4_inode_clear_flag(ref.inode, EXT4_INODE_FLAG_EXTENTS);
 	} else {
 		ext4_fs_inode_blocks_init(&f->mp->fs, &ref);
-		r = ext4_fs_append_inode_block(&ref, &fblock, &sblock);
+		r = ext4_fs_append_inode_dblk(&ref, &fblock, &sblock);
 		if (r != EOK)
 			goto Finish;
 
--- a/lwext4/ext4_dir.c
+++ b/lwext4/ext4_dir.c
@@ -234,8 +234,8 @@
 		}
 
 		ext4_fsblk_t next_blk;
-		r = ext4_fs_get_inode_data_block_index(it->inode_ref,
-						next_blk_idx, &next_blk, false);
+		r = ext4_fs_get_inode_dblk_idx(it->inode_ref, next_blk_idx,
+					       &next_blk, false);
 		if (r != EOK)
 			return r;
 
@@ -325,6 +325,7 @@
 int ext4_dir_add_entry(struct ext4_inode_ref *parent, const char *name,
 		       uint32_t name_len, struct ext4_inode_ref *child)
 {
+	int r;
 	struct ext4_fs *fs = parent->fs;
 	struct ext4_sblock *sb = &parent->fs->sb;
 
@@ -332,12 +333,12 @@
 	/* Index adding (if allowed) */
 	if ((ext4_sb_feature_com(sb, EXT4_FCOM_DIR_INDEX)) &&
 	    (ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX))) {
-		int rc = ext4_dir_dx_add_entry(parent, child, name);
+		r = ext4_dir_dx_add_entry(parent, child, name);
 
 		/* Check if index is not corrupted */
-		if (rc != EXT4_ERR_BAD_DX_DIR) {
-			if (rc != EOK)
-				return rc;
+		if (r != EXT4_ERR_BAD_DX_DIR) {
+			if (r != EOK)
+				return r;
 
 			return EOK;
 		}
@@ -358,15 +359,14 @@
 	/* Find block, where is space for new entry and try to add */
 	bool success = false;
 	for (iblock = 0; iblock < total_blocks; ++iblock) {
-		int rc = ext4_fs_get_inode_data_block_index(parent, iblock,
-							&fblock, false);
-		if (rc != EOK)
-			return rc;
+		r = ext4_fs_get_inode_dblk_idx(parent, iblock, &fblock, false);
+		if (r != EOK)
+			return r;
 
 		struct ext4_block block;
-		rc = ext4_block_get(fs->bdev, &block, fblock);
-		if (rc != EOK)
-			return rc;
+		r = ext4_block_get(fs->bdev, &block, fblock);
+		if (r != EOK)
+			return r;
 
 		if (!ext4_dir_csum_verify(parent, (void *)block.data)) {
 			ext4_dbg(DEBUG_DIR,
@@ -378,14 +378,14 @@
 		}
 
 		/* If adding is successful, function can finish */
-		rc = ext4_dir_try_insert_entry(sb, parent, &block, child,
+		r = ext4_dir_try_insert_entry(sb, parent, &block, child,
 						name, name_len);
-		if (rc == EOK)
+		if (r == EOK)
 			success = true;
 
-		rc = ext4_block_set(fs->bdev, &block);
-		if (rc != EOK)
-			return rc;
+		r = ext4_block_set(fs->bdev, &block);
+		if (r != EOK)
+			return r;
 
 		if (success)
 			return EOK;
@@ -395,16 +395,16 @@
 
 	iblock = 0;
 	fblock = 0;
-	int rc = ext4_fs_append_inode_block(parent, &fblock, &iblock);
-	if (rc != EOK)
-		return rc;
+	r = ext4_fs_append_inode_dblk(parent, &fblock, &iblock);
+	if (r != EOK)
+		return r;
 
 	/* Load new block */
 	struct ext4_block b;
 
-	rc = ext4_block_get_noread(fs->bdev, &b, fblock);
-	if (rc != EOK)
-		return rc;
+	r = ext4_block_get_noread(fs->bdev, &b, fblock);
+	if (r != EOK)
+		return r;
 
 	/* Fill block with zeroes */
 	memset(b.data, 0, block_size);
@@ -422,9 +422,9 @@
 
 	ext4_dir_set_csum(parent, (void *)b.data);
 	b.dirty = true;
-	rc = ext4_block_set(fs->bdev, &b);
+	r = ext4_block_set(fs->bdev, &b);
 
-	return rc;
+	return r;
 }
 
 int ext4_dir_find_entry(struct ext4_dir_search_result *result,
@@ -431,6 +431,7 @@
 			struct ext4_inode_ref *parent, const char *name,
 			uint32_t name_len)
 {
+	int r;
 	struct ext4_sblock *sb = &parent->fs->sb;
 
 	/* Entry clear */
@@ -441,12 +442,11 @@
 	/* Index search */
 	if ((ext4_sb_feature_com(sb, EXT4_FCOM_DIR_INDEX)) &&
 	    (ext4_inode_has_flag(parent->inode, EXT4_INODE_FLAG_INDEX))) {
-		int rc = ext4_dir_dx_find_entry(result, parent, name_len, name);
-
+		r = ext4_dir_dx_find_entry(result, parent, name_len, name);
 		/* Check if index is not corrupted */
-		if (rc != EXT4_ERR_BAD_DX_DIR) {
-			if (rc != EOK)
-				return rc;
+		if (r != EXT4_ERR_BAD_DX_DIR) {
+			if (r != EOK)
+				return r;
 
 			return EOK;
 		}
@@ -468,18 +468,15 @@
 	/* Walk through all data blocks */
 	for (iblock = 0; iblock < total_blocks; ++iblock) {
 		/* Load block address */
-		int rc =
-		    ext4_fs_get_inode_data_block_index(parent,
-				    iblock, &fblock,
-				    false);
-		if (rc != EOK)
-			return rc;
+		r = ext4_fs_get_inode_dblk_idx(parent, iblock, &fblock, false);
+		if (r != EOK)
+			return r;
 
 		/* Load data block */
 		struct ext4_block b;
-		rc = ext4_block_get(parent->fs->bdev, &b, fblock);
-		if (rc != EOK)
-			return rc;
+		r = ext4_block_get(parent->fs->bdev, &b, fblock);
+		if (r != EOK)
+			return r;
 
 		if (!ext4_dir_csum_verify(parent, (void *)b.data)) {
 			ext4_dbg(DEBUG_DIR,
@@ -492,8 +489,8 @@
 
 		/* Try to find entry in block */
 		struct ext4_dir_en *res_entry;
-		rc = ext4_dir_find_in_block(&b, sb, name_len, name, &res_entry);
-		if (rc == EOK) {
+		r = ext4_dir_find_in_block(&b, sb, name_len, name, &res_entry);
+		if (r == EOK) {
 			result->block = b;
 			result->dentry = res_entry;
 			return EOK;
@@ -501,9 +498,9 @@
 
 		/* Entry not found - put block and continue to the next block */
 
-		rc = ext4_block_set(parent->fs->bdev, &b);
-		if (rc != EOK)
-			return rc;
+		r = ext4_block_set(parent->fs->bdev, &b);
+		if (r != EOK)
+			return r;
 	}
 
 	return ENOENT;
--- a/lwext4/ext4_dir_idx.c
+++ b/lwext4/ext4_dir_idx.c
@@ -348,7 +348,7 @@
 	struct ext4_sblock *sb = &dir->fs->sb;
 	uint32_t block_size = ext4_sb_get_block_size(&dir->fs->sb);
 
-	int rc = ext4_fs_append_inode_block(dir, &fblock, &iblock);
+	int rc = ext4_fs_append_inode_dblk(dir, &fblock, &iblock);
 	if (rc != EOK)
 		return rc;
 
@@ -396,7 +396,7 @@
 	ext4_dir_dx_climit_set_limit(climit, root_limit);
 
 	/* Append new block, where will be new entries inserted in the future */
-	rc = ext4_fs_append_inode_block(dir, &fblock, &iblock);
+	rc = ext4_fs_append_inode_dblk(dir, &fblock, &iblock);
 	if (rc != EOK) {
 		ext4_block_set(dir->fs->bdev, &block);
 		return rc;
@@ -523,7 +523,7 @@
 	struct ext4_dir_idx_entry *q;
 	struct ext4_dir_idx_entry *m;
 	struct ext4_dir_idx_entry *at;
-	ext4_fsblk_t fblock;
+	ext4_fsblk_t fblk;
 	uint32_t block_size;
 	uint16_t limit;
 	uint16_t entry_space;
@@ -572,16 +572,15 @@
 		}
 
 		/* Goto child node */
-		uint32_t next_block = ext4_dir_dx_entry_get_block(at);
+		uint32_t n_blk = ext4_dir_dx_entry_get_block(at);
 
 		ind_level--;
 
-		r = ext4_fs_get_inode_data_block_index(inode_ref, next_block,
-						       &fblock, false);
+		r = ext4_fs_get_inode_dblk_idx(inode_ref, n_blk, &fblk, false);
 		if (r != EOK)
 			return r;
 
-		r = ext4_block_get(inode_ref->fs->bdev, tmp_blk, fblock);
+		r = ext4_block_get(inode_ref->fs->bdev, tmp_blk, fblk);
 		if (r != EOK)
 			return r;
 
@@ -605,7 +604,7 @@
 					"Inode: %" PRIu32", "
 					"Block: %" PRIu32"\n",
 					inode_ref->index,
-					next_block);
+					n_blk);
 		}
 
 		++tmp_dx_blk;
@@ -629,7 +628,7 @@
 {
 	int r;
 	uint32_t num_handles = 0;
-	ext4_fsblk_t block_addr;
+	ext4_fsblk_t blk_adr;
 	struct ext4_dir_idx_block *p = dx_block;
 
 	/* Try to find data block with next bunch of entries */
@@ -657,15 +656,13 @@
 
 	/* Fill new path */
 	while (num_handles--) {
-		uint32_t block_idx = ext4_dir_dx_entry_get_block(p->position);
-
-		r = ext4_fs_get_inode_data_block_index(inode_ref, block_idx,
-						       &block_addr, false);
+		uint32_t blk = ext4_dir_dx_entry_get_block(p->position);
+		r = ext4_fs_get_inode_dblk_idx(inode_ref, blk, &blk_adr, false);
 		if (r != EOK)
 			return r;
 
 		struct ext4_block b;
-		r = ext4_block_get(inode_ref->fs->bdev, &b, block_addr);
+		r = ext4_block_get(inode_ref->fs->bdev, &b, blk_adr);
 		if (r != EOK)
 			return r;
 
@@ -675,7 +672,7 @@
 					"Inode: %" PRIu32", "
 					"Block: %" PRIu32"\n",
 					inode_ref->index,
-					block_idx);
+					blk);
 		}
 
 		p++;
@@ -701,8 +698,7 @@
 	ext4_fsblk_t root_block_addr;
 	int rc2;
 	int rc;
-	rc = ext4_fs_get_inode_data_block_index(inode_ref,  0, &root_block_addr,
-					       false);
+	rc = ext4_fs_get_inode_dblk_idx(inode_ref,  0, &root_block_addr, false);
 	if (rc != EOK)
 		return rc;
 
@@ -752,8 +748,8 @@
 		struct ext4_block b;
 
 		leaf_blk_idx = ext4_dir_dx_entry_get_block(dx_block->position);
-		rc = ext4_fs_get_inode_data_block_index(inode_ref, leaf_blk_idx,
-						       &leaf_block_addr, false);
+		rc = ext4_fs_get_inode_dblk_idx(inode_ref, leaf_blk_idx,
+						&leaf_block_addr, false);
 		if (rc != EOK)
 			goto cleanup;
 
@@ -989,7 +985,7 @@
 	/* Allocate new block for store the second part of entries */
 	ext4_fsblk_t new_fblock;
 	uint32_t new_iblock;
-	rc = ext4_fs_append_inode_block(inode_ref, &new_fblock, &new_iblock);
+	rc = ext4_fs_append_inode_dblk(inode_ref, &new_fblock, &new_iblock);
 	if (rc != EOK) {
 		free(sort);
 		free(entry_buffer);
@@ -1140,7 +1136,7 @@
 		/* Add new block to directory */
 		ext4_fsblk_t new_fblk;
 		uint32_t new_iblk;
-		r = ext4_fs_append_inode_block(ino_ref, &new_fblk, &new_iblk);
+		r = ext4_fs_append_inode_dblk(ino_ref, &new_fblk, &new_iblk);
 		if (r != EOK)
 			return r;
 
@@ -1260,7 +1256,7 @@
 	int r;
 	/* Get direct block 0 (index root) */
 	ext4_fsblk_t rblock_addr;
-	r =  ext4_fs_get_inode_data_block_index(parent, 0, &rblock_addr, false);
+	r =  ext4_fs_get_inode_dblk_idx(parent, 0, &rblock_addr, false);
 	if (r != EOK)
 		return r;
 
@@ -1306,7 +1302,7 @@
 	/* Try to insert to existing data block */
 	uint32_t leaf_block_idx = ext4_dir_dx_entry_get_block(dx_blk->position);
 	ext4_fsblk_t leaf_block_addr;
-	r = ext4_fs_get_inode_data_block_index(parent, leaf_block_idx,
+	r = ext4_fs_get_inode_dblk_idx(parent, leaf_block_idx,
 						&leaf_block_addr, false);
 	if (r != EOK)
 		goto release_index;
@@ -1393,7 +1389,7 @@
 {
 	/* Load block 0, where will be index root located */
 	ext4_fsblk_t fblock;
-	int rc = ext4_fs_get_inode_data_block_index(dir, 0, &fblock, false);
+	int rc = ext4_fs_get_inode_dblk_idx(dir, 0, &fblock, false);
 	if (rc != EOK)
 		return rc;
 
--- a/lwext4/ext4_fs.c
+++ b/lwext4/ext4_fs.c
@@ -1249,8 +1249,8 @@
 
 	/* If inode has some blocks, get last block address + 1 */
 	if (iblock_cnt > 0) {
-		r = ext4_fs_get_inode_data_block_index(inode_ref, iblock_cnt - 1,
-						       goal, false);
+		r = ext4_fs_get_inode_dblk_idx(inode_ref, iblock_cnt - 1,
+					       goal, false);
 		if (r != EOK)
 			return r;
 
@@ -1303,7 +1303,7 @@
 	return ext4_fs_put_block_group_ref(&bg_ref);
 }
 
-static int ext4_fs_get_inode_data_block_idx(struct ext4_inode_ref *inode_ref,
+static int ext4_fs_get_inode_dblk_idx_internal(struct ext4_inode_ref *inode_ref,
 				       uint64_t iblock, ext4_fsblk_t *fblock,
 				       bool extent_create,
 				       bool support_unwritten __unused)
@@ -1418,19 +1418,19 @@
 }
 
 
-int ext4_fs_get_inode_data_block_index(struct ext4_inode_ref *inode_ref,
-				       uint64_t iblock, ext4_fsblk_t *fblock,
-				       bool support_unwritten)
+int ext4_fs_get_inode_dblk_idx(struct ext4_inode_ref *inode_ref,
+			       uint64_t iblock, ext4_fsblk_t *fblock,
+			       bool support_unwritten)
 {
-	return ext4_fs_get_inode_data_block_idx(inode_ref, iblock, fblock,
-			false, support_unwritten);
+	return ext4_fs_get_inode_dblk_idx_internal(inode_ref, iblock, fblock,
+						   false, support_unwritten);
 }
 
-int ext4_fs_init_inode_data_block_index(struct ext4_inode_ref *inode_ref,
-				       uint64_t iblock, ext4_fsblk_t *fblock)
+int ext4_fs_init_inode_dblk_idx(struct ext4_inode_ref *inode_ref,
+				uint64_t iblock, ext4_fsblk_t *fblock)
 {
-	return ext4_fs_get_inode_data_block_idx(inode_ref, iblock, fblock,
-			true, true);
+	return ext4_fs_get_inode_dblk_idx_internal(inode_ref, iblock, fblock,
+						   true, true);
 }
 
 static int ext4_fs_set_inode_data_block_index(struct ext4_inode_ref *inode_ref,
@@ -1598,8 +1598,8 @@
 }
 
 
-int ext4_fs_append_inode_block(struct ext4_inode_ref *inode_ref,
-			       ext4_fsblk_t *fblock, uint32_t *iblock)
+int ext4_fs_append_inode_dblk(struct ext4_inode_ref *inode_ref,
+			      ext4_fsblk_t *fblock, uint32_t *iblock)
 {
 #if CONFIG_EXTENT_ENABLE
 	/* Handle extents separately */
@@ -1614,7 +1614,6 @@
 
 		rc = ext4_extent_get_blocks(inode_ref, *iblock, 1,
 						&current_fsblk, true, NULL);
-
 
 		*fblock = current_fsblk;
 		ext4_assert(*fblock);
--- a/lwext4/ext4_fs.h
+++ b/lwext4/ext4_fs.h
@@ -141,7 +141,8 @@
  * @param fs        Filesystem to reset blocks field of i-inode on
  * @param inode_ref ref Pointer for inode to be operated on
  */
-void ext4_fs_inode_blocks_init(struct ext4_fs *fs, struct ext4_inode_ref *inode_ref);
+void ext4_fs_inode_blocks_init(struct ext4_fs *fs,
+			       struct ext4_inode_ref *inode_ref);
 
 /**@brief Put reference to i-node.
  * @param ref Pointer for reference to be put back
@@ -200,9 +201,9 @@
  *                          is supported under the current context
  * @return Error code
  */
-int ext4_fs_get_inode_data_block_index(struct ext4_inode_ref *inode_ref,
-				       uint64_t iblock, ext4_fsblk_t *fblock,
-				       bool support_unwritten);
+int ext4_fs_get_inode_dblk_idx(struct ext4_inode_ref *inode_ref,
+				 uint64_t iblock, ext4_fsblk_t *fblock,
+				 bool support_unwritten);
 
 /**@brief Initialize a part of unwritten range of the inode.
  * @param inode_ref I-node to proceed on.
@@ -210,8 +211,8 @@
  * @param fblock    Output pointer for return physical block address
  * @return Error code
  */
-int ext4_fs_init_inode_data_block_index(struct ext4_inode_ref *inode_ref,
-				       uint64_t iblock, ext4_fsblk_t *fblock);
+int ext4_fs_init_inode_dblk_idx(struct ext4_inode_ref *inode_ref,
+				  uint64_t iblock, ext4_fsblk_t *fblock);
 
 /**@brief Append following logical block to the i-node.
  * @param inode_ref I-node to append block to
@@ -219,8 +220,8 @@
  * @param iblock    Output logical number of newly allocated block
  * @return Error code
  */
-int ext4_fs_append_inode_block(struct ext4_inode_ref *inode_ref,
-			       ext4_fsblk_t *fblock, uint32_t *iblock);
+int ext4_fs_append_inode_dblk(struct ext4_inode_ref *inode_ref,
+			      ext4_fsblk_t *fblock, uint32_t *iblock);
 
 /**@brief   Increment inode link count.
  * @param   inode none handle
--- a/lwext4/ext4_journal.c
+++ b/lwext4/ext4_journal.c
@@ -175,7 +175,7 @@
 		   ext4_lblk_t iblock,
 		   ext4_fsblk_t *fblock)
 {
-	int rc = ext4_fs_get_inode_data_block_index(
+	int rc = ext4_fs_get_inode_dblk_idx(
 			&jbd_fs->inode_ref,
 			iblock,
 			fblock,