mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
To: <ntfs3@lists.linux.dev>
Cc: <linux-kernel@vger.kernel.org>, <linux-fsdevel@vger.kernel.org>
Subject: [PATCH 5/5] fs/ntfs3: Fill duplicate info in ni_add_name
Date: Fri, 1 Jul 2022 16:11:35 +0300	[thread overview]
Message-ID: <02302c1c-d188-c326-7bad-1b2a2e7f9a15@paragon-software.com> (raw)
In-Reply-To: <34e58f6e-e508-4ad8-6941-37281ea7d3ef@paragon-software.com>

Work with names must be completed in ni_add_name

Signed-off-by: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
---
  fs/ntfs3/frecord.c | 20 ++++++++++++++------
  fs/ntfs3/inode.c   | 10 ----------
  2 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c
index 756d9a18fa00..acd9f444bd64 100644
--- a/fs/ntfs3/frecord.c
+++ b/fs/ntfs3/frecord.c
@@ -1614,7 +1614,8 @@ struct ATTR_FILE_NAME *ni_fname_name(struct ntfs_inode *ni,
  	struct ATTRIB *attr = NULL;
  	struct ATTR_FILE_NAME *fname;
  
-	*le = NULL;
+	if (le)
+		*le = NULL;
  
  	/* Enumerate all names. */
  next:
@@ -1630,7 +1631,7 @@ struct ATTR_FILE_NAME *ni_fname_name(struct ntfs_inode *ni,
  		goto next;
  
  	if (!uni)
-		goto next;
+		return fname;
  
  	if (uni->len != fname->name_len)
  		goto next;
@@ -2969,7 +2970,7 @@ bool ni_remove_name_undo(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,
  }
  
  /*
- * ni_add_name - Add new name in MFT and in directory.
+ * ni_add_name - Add new name into MFT and into directory.
   */
  int ni_add_name(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,
  		struct NTFS_DE *de)
@@ -2978,13 +2979,20 @@ int ni_add_name(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,
  	struct ATTRIB *attr;
  	struct ATTR_LIST_ENTRY *le;
  	struct mft_inode *mi;
+	struct ATTR_FILE_NAME *fname;
  	struct ATTR_FILE_NAME *de_name = (struct ATTR_FILE_NAME *)(de + 1);
  	u16 de_key_size = le16_to_cpu(de->key_size);
  
  	mi_get_ref(&ni->mi, &de->ref);
  	mi_get_ref(&dir_ni->mi, &de_name->home);
  
-	/* Insert new name in MFT. */
+	/* Fill duplicate from any ATTR_NAME. */
+	fname = ni_fname_name(ni, NULL, NULL, NULL, NULL);
+	if (fname)
+		memcpy(&de_name->dup, &fname->dup, sizeof(fname->dup));
+	de_name->dup.fa = ni->std_fa;
+
+	/* Insert new name into MFT. */
  	err = ni_insert_resident(ni, de_key_size, ATTR_NAME, NULL, 0, &attr,
  				 &mi, &le);
  	if (err)
@@ -2992,7 +3000,7 @@ int ni_add_name(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,
  
  	memcpy(Add2Ptr(attr, SIZEOF_RESIDENT), de_name, de_key_size);
  
-	/* Insert new name in directory. */
+	/* Insert new name into directory. */
  	err = indx_insert_entry(&dir_ni->dir, dir_ni, de, ni->mi.sbi, NULL, 0);
  	if (err)
  		ni_remove_attr_le(ni, attr, mi, le);
@@ -3016,7 +3024,7 @@ int ni_rename(struct ntfs_inode *dir_ni, struct ntfs_inode *new_dir_ni,
  	 * 1) Add new name and remove old name.
  	 * 2) Remove old name and add new name.
  	 *
-	 * In most cases (not all!) adding new name in MFT and in directory can
+	 * In most cases (not all!) adding new name into MFT and into directory can
  	 * allocate additional cluster(s).
  	 * Second way may result to bad inode if we can't add new name
  	 * and then can't restore (add) old name.
diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c
index a49da4ec6dc3..3ed319663747 100644
--- a/fs/ntfs3/inode.c
+++ b/fs/ntfs3/inode.c
@@ -1659,7 +1659,6 @@ int ntfs_link_inode(struct inode *inode, struct dentry *dentry)
  	struct ntfs_inode *ni = ntfs_i(inode);
  	struct ntfs_sb_info *sbi = inode->i_sb->s_fs_info;
  	struct NTFS_DE *de;
-	struct ATTR_FILE_NAME *de_name;
  
  	/* Allocate PATH_MAX bytes. */
  	de = __getname();
@@ -1674,15 +1673,6 @@ int ntfs_link_inode(struct inode *inode, struct dentry *dentry)
  	if (err)
  		goto out;
  
-	de_name = (struct ATTR_FILE_NAME *)(de + 1);
-	/* Fill duplicate info. */
-	de_name->dup.cr_time = de_name->dup.m_time = de_name->dup.c_time =
-		de_name->dup.a_time = kernel2nt(&inode->i_ctime);
-	de_name->dup.alloc_size = de_name->dup.data_size =
-		cpu_to_le64(inode->i_size);
-	de_name->dup.fa = ni->std_fa;
-	de_name->dup.ea_size = de_name->dup.reparse = 0;
-
  	err = ni_add_name(ntfs_i(d_inode(dentry->d_parent)), ni, de);
  out:
  	__putname(de);
-- 
2.37.0



      parent reply	other threads:[~2022-07-01 13:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-07-01 13:09 [PATCH 0/5] fs/ntfs3: Some fixes and refactoring Konstantin Komarov
2022-07-01 13:09 ` [PATCH 1/5] fs/ntfs3: Fix very fragmented case in attr_punch_hole Konstantin Komarov
2022-07-01 13:10 ` [PATCH 2/5] fs/ntfs3: Remove unused mi_mark_free Konstantin Komarov
2022-07-01 13:10 ` [PATCH 3/5] fs/ntfs3: Add new argument is_mft to ntfs_mark_rec_free Konstantin Komarov
2022-07-01 13:11 ` [PATCH 4/5] fs/ntfs3: Make static function attr_load_runs Konstantin Komarov
2022-07-01 13:11 ` Konstantin Komarov [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=02302c1c-d188-c326-7bad-1b2a2e7f9a15@paragon-software.com \
    --to=almaz.alexandrovich@paragon-software.com \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ntfs3@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®