From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtpbgjp3.qq.com (smtpbgjp3.qq.com [54.92.39.34]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9A70713777E for ; Mon, 27 Jul 2026 09:13:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=54.92.39.34 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785143590; cv=none; b=ZyPnm9BiusvDRSWqzRNFyGSV5xLIYjDZRIdX2VcfTXZqeYZOwfxuIXFgqV1MIgdEV+QEMZEKi37S18QWb20RYP6xNCYbJDoi5Ueiyta3RWs2lpelHRUTXKEO5lviDvuWE9W/jgOxhRyeBG0ZVoUBkDQ4EflFAnGzGhIuE+608gA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785143590; c=relaxed/simple; bh=9+SvBZVrnAudAJ3bQfJ0d3An5WP4WIFutYffFApVi4k=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=l5Bm057HPbSquYJK0g2/yaRTAlD7ZLxmsW4XjiJV+28IyvzaVnIbGoWGQGXiHEYHM3ihsYLOComBumKXQURH8pCDJzcSEUAh3JQB6tbr1ml84ezecjrF572fEADtJNWMu336nVc3p6wK0UvPvXRD2ej3aobIZejjPS9Ezcudgnc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com; spf=pass smtp.mailfrom=uniontech.com; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b=NMHhTDhK; arc=none smtp.client-ip=54.92.39.34 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=uniontech.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=uniontech.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=uniontech.com header.i=@uniontech.com header.b="NMHhTDhK" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=uniontech.com; s=onoh2408; t=1785143555; bh=BT28hkOI+P00PIuaVjtfWrFDM1LLEFTz6sSkrPAldmo=; h=From:To:Subject:Date:Message-Id:MIME-Version; b=NMHhTDhKXLhl4liARFDdnMPOt9RoysUGgzUvLcy2swEwsIO4lyW5TMILVrab0YK+P CO2r9BL/HOKDxDQ8c/55le9ntkYGm99R03oryGOGYTbN3kkbjT2JWSbKx6k3XqOIZP cqFEtNqWiJMVAhT3aBqRAWbnp+HvYXBM40pVAlMM= X-QQ-mid: zesmtpsz9t1785143538t45a40dc8 X-QQ-Originating-IP: doSpESKBuRWZHbEdAR7q6C0FZn+Vm4KJ2/90jct3o50= Received: from uniontech.com ( [113.57.152.160]) by bizesmtp.qq.com (ESMTP) with id ; Mon, 27 Jul 2026 17:12:16 +0800 (CST) X-QQ-SSF: 0000000000000000000000000000000 X-QQ-GoodBg: 1 X-BIZMAIL-ID: 13925937074661905614 EX-QQ-RecipientCnt: 6 From: Yichong Chen To: linkinjeon@kernel.org, sj1557.seo@samsung.com Cc: yuezhang.mo@sony.com, exfat@lists.linux.dev, linux-kernel@vger.kernel.org, Yichong Chen Subject: [PATCH] exfat: write moved entry before removing source Date: Mon, 27 Jul 2026 17:12:14 +0800 Message-Id: <20260727091214.355917-1-chenyichong@uniontech.com> X-Mailer: git-send-email 2.20.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-QQ-SENDSIZE: 520 Feedback-ID: zesmtpsz:uniontech.com:qybglogicsvrgz:qybglogicsvrgz3a-0 X-QQ-XMAILINFO: NGGv7ksYK5KE6Adh1n+cGp4OslnydtclsG7YoFeBX0Pc4bJvAt/ksFL3 2Hzv8xbTjZj9XSs/85oFqNBx87h2pMbvxMmGCNnfMzunbInFk02gO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at_move_file() removes the old directory entry before the new entry has been written. If writing the new entry fails, rename returns an error after the source entry has already been marked deleted. Write the new entry first, then remove the old entry and update the cached inode location. This keeps the source entry intact if creating the destination entry fails. Signed-off-by: Yichong Chen --- fs/exfat/namei.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/fs/exfat/namei.c b/fs/exfat/namei.c index cd9c9eca58f8..038bc6fed681 100644 --- a/fs/exfat/namei.c +++ b/fs/exfat/namei.c @@ -1116,11 +1116,6 @@ static int exfat_move_file(struct inode *parent_inode, exfat_init_ext_entry(&new_es, num_new_entries, p_uniname, &mov_es, num_extra_entries); - exfat_remove_entries(parent_inode, &mov_es, ES_IDX_FILE, false); - - ei->dir = newdir; - ei->entry = newentry; - ret = exfat_put_dentry_set(&new_es, IS_DIRSYNC(parent_inode)); if (ret) { /* Best-effort delete to avoid duplicate entries */ @@ -1134,6 +1129,11 @@ static int exfat_move_file(struct inode *parent_inode, goto put_mov_es; } + exfat_remove_entries(parent_inode, &mov_es, ES_IDX_FILE, false); + + ei->dir = newdir; + ei->entry = newentry; + return exfat_put_dentry_set(&mov_es, IS_DIRSYNC(parent_inode)); put_mov_es: -- 2.51.0