Skip to contentSkip to conversation

ntfs: keep i_size of a directory equal to its index root

PATCH Superseded Showta Ishizaki 4 participants 6 messages Nov 25 – Nov 26

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ntfs: keep i_size of a directory equal to its index root

After mkdir, stat() gives a size of 0 for the directory until it is read back from disk, where it gives the length of $INDEX_ROOT. __ntfs_create() opens the index root but does not set i_size from it.

When the index root is moved out to an index block, ntfs_ir_reparent() updates data_size but not i_size, which keeps the length the root had before.

Set i_size in both, as ntfs_ir_truncate() does.

Without the patch a new directory was 0 bytes and became 48 after a remount, and one with 300 files was 248 and became 56. With it the sizes are the same before and after.

Fixes af0db57d4293 ("ntfs: update inode operations")
Fixes 0a8ac0c1fa0b ("ntfs: update directory operations")
---
 fs/ntfs/index.c | 3 +++
 fs/ntfs/namei.c | 7 +++++++
 2 files changed, 10 insertions(+)
fs/ntfs/index.c +3 -0
index fe2a79b..73c8e6f 100644
@@ -1434,6 +1434,8 @@ retry:
 		icx->idx_ni->data_size = ix_root_size;
 		icx->idx_ni->initialized_size = ix_root_size;
 		icx->idx_ni->allocated_size = (ix_root_size + 7) & ~7;
+		/* As ntfs_ir_truncate() does; i_size kept the old length. */
+		i_size_write(VFS_I(icx->idx_ni), ix_root_size);
 	}
 
 	ntfs_ir_nill(ir);
@@ -1455,6 +1457,7 @@ retry:
 		icx->idx_ni->data_size = ix_root_size;
 		icx->idx_ni->initialized_size = ix_root_size;
 		icx->idx_ni->allocated_size = (ix_root_size + 7) & ~7;
+		i_size_write(VFS_I(icx->idx_ni), ix_root_size);
 	}
 	ntfs_ie_set_vcn(ie, new_ib_vcn);
 	goto err_out;
fs/ntfs/namei.c +7 -0
index 29f1bf5..e4b0fc4 100644
@@ -611,6 +611,13 @@ static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in
 		err = ntfs_attr_open(ni, AT_INDEX_ROOT, I30, 4);
 		if (err)
 			goto err_out;
+		/*
+		 * ntfs_attr_open() sets data_size to the length of the new
+		 * $INDEX_ROOT, as ntfs_read_locked_inode() does with i_size
+		 * too.  i_size stayed at the 0 set above, so stat() gave 0
+		 * until the directory was read back from disk.
+		 */
+		i_size_write(vi, ni->data_size);
 	} else {
 		/* Add DATA attribute to inode. */
 		err = ntfs_attr_add(ni, AT_DATA, AT_UNNAMED, 0, NULL, 0);
Signature · 1 line
2.54.0 (Apple Git-157)
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 10 lines · Showta Ishizaki

After mkdir, stat() gives a size of 0 for the directory until it is read back from disk, where it gives the length of $INDEX_ROOT. __ntfs_create() opens the index root but does not set i_size from it.

When the index root is moved out to an index block, ntfs_ir_reparent() updates data_size but not i_size, which keeps the length the root had before.

Set i_size in both, as ntfs_ir_truncate() does.

Quoted 7 lines

Without the patch a new directory was 0 bytes and became 48 after a remount, and one with 300 files was 248 and became 56. With it the sizes are the same before and after.

Fixes af0db57d4293 ("ntfs: update inode operations")
Fixes 0a8ac0c1fa0b ("ntfs: update directory operations")

Looks good to me.

Signature · 2 lines
Thanks,
Hyunchul
#2 lore raw

PATCH v2 1/1 ntfs: keep i_size of a directory equal to its index root

After mkdir, stat() gives a size of 0 for the directory until it is read back from disk, where it gives the length of $INDEX_ROOT. __ntfs_create() opens the index root but does not set i_size from it.

When the index root is moved out to an index block, ntfs_ir_reparent() updates data_size but not i_size, which keeps the length the root had before.

Set i_size in both, as ntfs_ir_truncate() does.

Without the patch a new directory was 0 bytes and became 48 after a remount, and one with 300 files was 248 and became 56. With it the sizes are the same before and after.

Fixes af0db57d4293 ("ntfs: update inode operations")
Fixes 0a8ac0c1fa0b ("ntfs: update directory operations")

---
v2: removed the two comments, as Hyunchul Lee asked.

 fs/ntfs/index.c | 2 ++
 fs/ntfs/namei.c | 1 +
 2 files changed, 3 insertions(+)
fs/ntfs/index.c +2 -0
index fe2a79b..73c8e6f 100644
@@ -1434,6 +1434,7 @@ retry:
 		icx->idx_ni->data_size = ix_root_size;
 		icx->idx_ni->initialized_size = ix_root_size;
 		icx->idx_ni->allocated_size = (ix_root_size + 7) & ~7;
+		i_size_write(VFS_I(icx->idx_ni), ix_root_size);
 	}
 
 	ntfs_ir_nill(ir);
@@ -1455,6 +1456,7 @@ retry:
 		icx->idx_ni->data_size = ix_root_size;
 		icx->idx_ni->initialized_size = ix_root_size;
 		icx->idx_ni->allocated_size = (ix_root_size + 7) & ~7;
+		i_size_write(VFS_I(icx->idx_ni), ix_root_size);
 	}
 	ntfs_ie_set_vcn(ie, new_ib_vcn);
 	goto err_out;
fs/ntfs/namei.c +1 -0
index 29f1bf5..e4b0fc4 100644
@@ -611,6 +611,7 @@ static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in
 		err = ntfs_attr_open(ni, AT_INDEX_ROOT, I30, 4);
 		if (err)
 			goto err_out;
+		i_size_write(vi, ni->data_size);
 	} else {
 		/* Add DATA attribute to inode. */
 		err = ntfs_attr_add(ni, AT_DATA, AT_UNNAMED, 0, NULL, 0);
Signature · 1 line
2.54.0 (Apple Git-157)
maintainer Applied
#3 lore raw
Quoted 15 lines · Showta Ishizaki

After mkdir, stat() gives a size of 0 for the directory until it is read back from disk, where it gives the length of $INDEX_ROOT. __ntfs_create() opens the index root but does not set i_size from it.

When the index root is moved out to an index block, ntfs_ir_reparent() updates data_size but not i_size, which keeps the length the root had before.

Set i_size in both, as ntfs_ir_truncate() does.

Without the patch a new directory was 0 bytes and became 48 after a remount, and one with 300 files was 248 and became 56. With it the sizes are the same before and after.

Quoted 5 lines
Fixes af0db57d4293 ("ntfs: update inode operations")
Fixes 0a8ac0c1fa0b ("ntfs: update directory operations")

Applied it to #ntfs-next.
Thanks.

Reviewed-by Baolin Liu on v1 1/1
#4 lore raw
In reply to Showta Ishizaki
Quoted 51 lines · Showta Ishizaki

After mkdir, stat() gives a size of 0 for the directory until it is read back from disk, where it gives the length of $INDEX_ROOT. __ntfs_create() opens the index root but does not set i_size from it.

When the index root is moved out to an index block, ntfs_ir_reparent() updates data_size but not i_size, which keeps the length the root had before.

Set i_size in both, as ntfs_ir_truncate() does.

Without the patch a new directory was 0 bytes and became 48 after a remount, and one with 300 files was 248 and became 56. With it the sizes are the same before and after.

Fixes af0db57d4293 ("ntfs: update inode operations")
Fixes 0a8ac0c1fa0b ("ntfs: update directory operations")
---
  fs/ntfs/index.c | 3 +++
  fs/ntfs/namei.c | 7 +++++++
  2 files changed, 10 insertions(+)
fs/ntfs/index.c +3 -0
index fe2a79b..73c8e6f 100644
@@ -1434,6 +1434,8 @@ retry:
  		icx->idx_ni->data_size = ix_root_size;
  		icx->idx_ni->initialized_size = ix_root_size;
  		icx->idx_ni->allocated_size = (ix_root_size + 7) & ~7;
+		/* As ntfs_ir_truncate() does; i_size kept the old length. */
+		i_size_write(VFS_I(icx->idx_ni), ix_root_size);
  	}
 
  	ntfs_ir_nill(ir);
@@ -1455,6 +1457,7 @@ retry:
  		icx->idx_ni->data_size = ix_root_size;
  		icx->idx_ni->initialized_size = ix_root_size;
  		icx->idx_ni->allocated_size = (ix_root_size + 7) & ~7;
+		i_size_write(VFS_I(icx->idx_ni), ix_root_size);
  	}
  	ntfs_ie_set_vcn(ie, new_ib_vcn);
  	goto err_out;
fs/ntfs/namei.c +0 -0
index 29f1bf5..e4b0fc4 100644
@@ -611,6 +611,13 @@ static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in
  		err = ntfs_attr_open(ni, AT_INDEX_ROOT, I30, 4);
  		if (err)
  			goto err_out;

fs/ntfs/namei.c static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in · line 623

Quoted 10 lines
fs/ntfs/namei.c +7 -0
+		/*
+		 * ntfs_attr_open() sets data_size to the length of the new
+		 * $INDEX_ROOT, as ntfs_read_locked_inode() does with i_size
+		 * too.  i_size stayed at the 0 set above, so stat() gave 0
+		 * until the directory was read back from disk.
+		 */
+		i_size_write(vi, ni->data_size);
  	} else {
  		/* Add DATA attribute to inode. */
  		err = ntfs_attr_add(ni, AT_DATA, AT_UNNAMED, 0, NULL, 0);

Looks good to me.

maintainer
#5 lore raw
In reply to Showta Ishizaki

Hi Showta,

fs/ntfs/index.c retry: · line 1437

Quoted 9 lines
fs/ntfs/index.c +1 -0
index fe2a79b..73c8e6f 100644
@@ -1434,6 +1434,8 @@ retry:
 		icx->idx_ni->data_size = ix_root_size;
 		icx->idx_ni->initialized_size = ix_root_size;
 		icx->idx_ni->allocated_size = (ix_root_size + 7) & ~7;
+		/* As ntfs_ir_truncate() does; i_size kept the old length. */

Could you remove this comment?

fs/ntfs/index.c static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in · line 619

Quoted 10 lines
fs/ntfs/index.c +6 -0
@@ -611,6 +611,13 @@ static struct ntfs_inode *__ntfs_create(const struct mnt_idmap *idmap, struct in
 		err = ntfs_attr_open(ni, AT_INDEX_ROOT, I30, 4);
 		if (err)
 			goto err_out;
+		/*
+		 * ntfs_attr_open() sets data_size to the length of the new
+		 * $INDEX_ROOT, as ntfs_read_locked_inode() does with i_size
+		 * too.  i_size stayed at the 0 set above, so stat() gave 0
+		 * until the directory was read back from disk.
+		 */

Please remove this one as well.

Quoted 7 lines
fs/ntfs/index.c +1 -0
+		i_size_write(vi, ni->data_size);
 	} else {
 		/* Add DATA attribute to inode. */
 		err = ntfs_attr_add(ni, AT_DATA, AT_UNNAMED, 0, NULL, 0);
Signature · 1 line
2.54.0 (Apple Git-157)
Signature · 2 lines
Thanks,
Hyunchul