Commit 528ee697 authored by Filipe Manana's avatar Filipe Manana Committed by David Sterba

btrfs: put initial index value of a directory in a constant

At btrfs_set_inode_index_count() we refer twice to the number 2 as the
initial index value for a directory (when it's empty), with a proper
comment explaining the reason for that value. In the next patch I'll
have to use that magic value in the directory logging code, so put
the value in a #define at btrfs_inode.h, to avoid hardcoding the
magic value again at tree-log.c.
Signed-off-by: default avatarFilipe Manana <fdmanana@suse.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
parent a450a4af
...@@ -13,6 +13,13 @@ ...@@ -13,6 +13,13 @@
#include "ordered-data.h" #include "ordered-data.h"
#include "delayed-inode.h" #include "delayed-inode.h"
/*
* Since we search a directory based on f_pos (struct dir_context::pos) we have
* to start at 2 since '.' and '..' have f_pos of 0 and 1 respectively, so
* everybody else has to start at 2 (see btrfs_real_readdir() and dir_emit_dots()).
*/
#define BTRFS_DIR_START_INDEX 2
/* /*
* ordered_data_close is set by truncate when a file that used * ordered_data_close is set by truncate when a file that used
* to have good data has been truncated to zero. When it is set * to have good data has been truncated to zero. When it is set
...@@ -173,8 +180,9 @@ struct btrfs_inode { ...@@ -173,8 +180,9 @@ struct btrfs_inode {
u64 disk_i_size; u64 disk_i_size;
/* /*
* if this is a directory then index_cnt is the counter for the index * If this is a directory then index_cnt is the counter for the index
* number for new files that are created * number for new files that are created. For an empty directory, this
* must be initialized to BTRFS_DIR_START_INDEX.
*/ */
u64 index_cnt; u64 index_cnt;
......
...@@ -5971,14 +5971,8 @@ static int btrfs_set_inode_index_count(struct btrfs_inode *inode) ...@@ -5971,14 +5971,8 @@ static int btrfs_set_inode_index_count(struct btrfs_inode *inode)
goto out; goto out;
ret = 0; ret = 0;
/*
* MAGIC NUMBER EXPLANATION:
* since we search a directory based on f_pos we have to start at 2
* since '.' and '..' have f_pos of 0 and 1 respectively, so everybody
* else has to start at 2
*/
if (path->slots[0] == 0) { if (path->slots[0] == 0) {
inode->index_cnt = 2; inode->index_cnt = BTRFS_DIR_START_INDEX;
goto out; goto out;
} }
...@@ -5989,7 +5983,7 @@ static int btrfs_set_inode_index_count(struct btrfs_inode *inode) ...@@ -5989,7 +5983,7 @@ static int btrfs_set_inode_index_count(struct btrfs_inode *inode)
if (found_key.objectid != btrfs_ino(inode) || if (found_key.objectid != btrfs_ino(inode) ||
found_key.type != BTRFS_DIR_INDEX_KEY) { found_key.type != BTRFS_DIR_INDEX_KEY) {
inode->index_cnt = 2; inode->index_cnt = BTRFS_DIR_START_INDEX;
goto out; goto out;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment