shithub: lwext4

Download patch

ref: 5bf5ef05f8325209c4802aede035595fb2322831
parent: 6a8ef22973600f28f54e58ab2ea9322a15cdd5b8
author: gkostka <[email protected]>
date: Sun Oct 18 18:02:54 EDT 2015

Some minor cosmetic fixes

1. Move EXT_MAX_BLOCKS to ext4_types.h
2. Use EXT_MAX_BLOCKS instead of (ext4_lblk_t) (-1)
3. Change return value of ext4_ext_more_to_rm to bool
4. Move assignment ex = path[depth].extent outside if statement

--- a/lwext4/ext4_extent.c
+++ b/lwext4/ext4_extent.c
@@ -359,7 +359,7 @@
 int ext4_extent_remove_space(struct ext4_inode_ref *inode_ref, ext4_lblk_t from,
 			     ext4_lblk_t to)
 {
-	if (to != (ext4_lblk_t)-1)
+	if (to != EXT_MAX_BLOCKS)
 		return ENOTSUP;
 
 	/* Find the first extent to modify */
--- a/lwext4/ext4_extent_full.c
+++ b/lwext4/ext4_extent_full.c
@@ -1370,18 +1370,18 @@
 	return err;
 }
 
-static int ext4_ext_more_to_rm(struct ext4_extent_path *path, ext4_lblk_t to)
+static bool ext4_ext_more_to_rm(struct ext4_extent_path *path, ext4_lblk_t to)
 {
 	if (!to_le16(path->header->entries_count))
-		return 0;
+		return false;
 
 	if (path->index > EXT_LAST_INDEX(path->header))
-		return 0;
+		return false;
 
 	if (to_le32(path->index->first_block) > to)
-		return 0;
+		return false;
 
-	return 1;
+	return true;
 }
 
 int ext4_extent_remove_space(struct ext4_inode_ref *inode_ref, ext4_lblk_t from,
@@ -1396,9 +1396,10 @@
 	if (ret)
 		goto out;
 
-	if (!path[depth].extent ||
-	    !IN_RANGE(from, to_le32(path[depth].extent->first_block),
-		      ext4_ext_get_actual_len(path[depth].extent))) {
+	bool in_range = IN_RANGE(from, to_le32(path[depth].extent->first_block),
+			ext4_ext_get_actual_len(path[depth].extent));
+
+	if (!path[depth].extent || !in_range) {
 		ret = EOK;
 		goto out;
 	}
@@ -1579,15 +1580,6 @@
 	return err;
 }
 
-/*
- * ext4_ext_next_allocated_block:
- * returns allocated block in subsequent extent or EXT_MAX_BLOCKS.
- * NOTE: it considers block number from index entry as
- * allocated block. Thus, index entries have to be consistent
- * with leaves.
- */
-#define EXT_MAX_BLOCKS (ext4_lblk_t) - 1
-
 static ext4_lblk_t ext4_ext_next_allocated_block(struct ext4_extent_path *path)
 {
 	int32_t depth;
@@ -1672,7 +1664,8 @@
 	 * this situations is possible, though, _during_ tree modification
 	 * this is why assert can't be put in ext4_ext_find_extent()
 	 */
-	if ((ex = path[depth].extent)) {
+	ex = path[depth].extent;
+	if (ex) {
 		ext4_lblk_t ee_block = to_le32(ex->first_block);
 		ext4_fsblk_t ee_start = ext4_ext_pblock(ex);
 		uint16_t ee_len = ext4_ext_get_actual_len(ex);
--- a/lwext4/ext4_fs.c
+++ b/lwext4/ext4_fs.c
@@ -974,7 +974,7 @@
 		/* Extents require special operation */
 		if (diff_blocks_count) {
 			int rc = ext4_extent_remove_space(inode_ref,
-					new_blocks_count, (ext4_lblk_t)-1);
+					new_blocks_count, EXT_MAX_BLOCKS);
 			if (rc != EOK)
 				return rc;
 
--- a/lwext4/ext4_types.h
+++ b/lwext4/ext4_types.h
@@ -711,9 +711,16 @@
 	(sizeof(struct ext4_extent_header) +                                   \
 	 (sizeof(struct ext4_extent) * (hdr)->max_entries_count))
 
+/*
+ * ext4_ext_next_allocated_block:
+ * returns allocated block in subsequent extent or EXT_MAX_BLOCKS.
+ * NOTE: it considers block number from index entry as
+ * allocated block. Thus, index entries have to be consistent
+ * with leaves.
+ */
+#define EXT_MAX_BLOCKS (ext4_lblk_t) (-1)
 
 #define IN_RANGE(b, first, len)	((b) >= (first) && (b) <= (first) + (len) - 1)
-
 
 
 /******************************************************************************/