From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796146992; b=lNcCY5ULueWXV4kI9TZvya0KC5jgPwpC89RWK0kEU8Md8n/0wUliEJy4z183Nw7gijzv oxEHxB+gajQLY4X7aF5zTwR2o48N5/0/iKzrQm04gM0a1wycggZSG6/xQXdtglF5BRXsV sWlGUrHHdODaVOk5VIfAjEDTeF/ChXiYBb0M44IojlkYGWGnaD5e0v/K/tJyZWahzVRLh DEFgKaQM+R7CNKC5xZH1L7tf/k1riyCUl7ngHtmho3ofMJO8bYhrNE4OI9re8OU1wdYGq bE3Wie2Gz9WXCsx4PzJ0EvEdD0bvFE1L/XhSYBQuAUAhEbQnxwTi2rzs7Yek52Mho/Q== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796146992; h=Received:DKIM-Signature:Received:From:Date:Subject:MIME-Version: Content-Type:Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=RI4kRWxl4XYAMairOnQShzPIXYese8AvwwdfRR+uYTw=; b=3Tu+NBtlWoh1W7BJdfi1rKdWTCqYlxY43QOtWPoLgijgTQkBD8PnxxAkJwhOWJ6RuhAK qX9d0VPp/Mvvq52VczmT6t53j9Qe+LCPvgI2jFqCtuQD1fQrXSh1bTSHgKhBwgzu/TBCc 9HkoGVFMdv9J/QMp7atTammASY4HozcRsjHiEfwHY58rwcibncyl/UDBQVs9zByBD8ijw QT4G+HvSDE2ln9FJxcyL933YyyYBmDhclZ+qU+5tKPE5HFqfIlPaIKZbz/xl9njlEJ5e2 xeYx2zZNoCnTXsH1e6iOMqaaiTpXjWVwnwJC/R0HY/6SgHRkgPDZTXTiRuCHQySHohg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SDKWmUs8; arc=pass header.oldest-pass=0 smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 556E860A2611; Tue, 1 Dec 2026 17:43:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=SDKWmUs8 Authentication-Results: smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 ARC-Seal: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; cv=none; t=1796146991; b=hBzpNwYnS+1i5diXU80YgZeeyBrDCUVKHRw1u71u8UAn7wd/rmUO3XTy2kjGJCy/CVeX aLHHV2I/vVZ/LCob0ZucUAohQURHYzLHm5wf/kL/u6GI43qHWizQidpbfNg8v7q4Iy5O8 Xg+Z5yY9LavvAaOcQa7dVCKMeMOc4W5CAsBcT/63LGyEXV+DBbZI96LUZpnQeM9hoaFkk zhIV8JvpJJXqsa+lreZocKbL5faXRpFLXaYX3hZkYc0qN2BwVajJTcpy3jhgAf+mARkwJ GlPlSRVs66VJ/oi+7CyLbmMNrd9ziX0hywM+DMiYbdmBrcUHOxp6HxOVr+x/AhNYQ2g== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796146991; h=DKIM-Signature:Received:From:Date:Subject:MIME-Version:Content-Type: Message-Id:References:In-Reply-To:To:Cc:X-Mailer: X-Developer-Signature:X-Developer-Key:X-Endpoint-Received: X-Original-From:Reply-To:Content-Transfer-Encoding; bh=RI4kRWxl4XYAMairOnQShzPIXYese8AvwwdfRR+uYTw=; b=r5LWxXosiQ4DHuGMcNTPyGEEpRxsB+x84rt3ORNJnJnmpCzeSjRFzMolqJ0LgcHJfkQk N0Z5wwujLrI8Fw0j40vGE5EN5URm/6Sv+BKejLWICZZr8yvm5aIUnJ4thvnevXsVwreBK x7aQFigUAFm85r4zmehXtDq/r3H1MUa2Nx9YnuDnsADcPJB1MkTMdEtVDmNtIu3ezW4T4 sd/jj7zSIn4a9TtZ7wr9qB19MYvbq8pFgMbYnD1xwEYUDE24RK75OMubQU9HPcCvRjkX/ 3GIb12YTrXnOvNpaTpDFusxDA+tdxnFgxkdS5L1wXZBIsG/2JlRQ+ODYpTfedIyfnAQ== ARC-Authentication-Results: i=1; smtp.kernel.org; arc=none smtp.remote-ip=100.80.115.77 Received: from lkml.kernel.org (nexus.subspace.kernel.org [100.80.115.77]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.kernel.org (Postfix) with ESMTPS id E0C1E1F00A1F; Tue, 1 Dec 2026 17:42:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796146991; bh=RI4kRWxl4XYAMairOnQShzPIXYese8AvwwdfRR+uYTw=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=SDKWmUs8xtGr7WuCKmQKpyLN2XI4zh8zNwOLFjwbgAe9KsEyS0GxyAWYZW/MehUY/ KCrBy3xfYnz4ufl+j9v9RSuvgYGNA07zxyUdBYkh83s8SsBWhKcSNQt8E+wMzTCN1N NLshPIQRzSXL0FU+fOBcz0JR59mAP59gcqY+0PdCeTl60/HXBpcW5uuIVYwf2IuSSE eYRDrosDCHquCYyR+kqGDBfqm8cmVxlI8FZIl4aZbAmHjrWdVwLzjPhk0XcyCNPp+1 j8Gg5K4npvYXCXPyzbxR/gJKkb4Bo/qXUMhYk45RerM4Hq+I2vBLvZ2v0IllTfjKsq TQjnQDDq7f3Xg== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id 48DAD4EF27; Tue, 1 Dec 2026 17:42:39 +0000 (UTC) From: Ernest Borowski via B4 Relay Date: Tue, 01 Dec 2026 18:42:42 +0100 Subject: [PATCH v4 07/11] ntfs: do not shift the cluster number of a delalloc run on split X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Message-Id: <20261201-b4-ntfs-delalloc-fixes-v4-7-e5dd6f77016a@proton.me> References: <20261201-b4-ntfs-delalloc-fixes-v4-0-e5dd6f77016a@proton.me> In-Reply-To: <20261201-b4-ntfs-delalloc-fixes-v4-0-e5dd6f77016a@proton.me> To: Namjae Jeon , Hyunchul Lee , Baolin Liu Cc: Christian Brauner , Christoph Hellwig , "Darrick J. Wong" , ntfs@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, Zhan Xusheng , stable@vger.kernel.org, Ernest Borowski X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3638; i=ernest.borowski.git@proton.me; s=default; h=from:subject:message-id; bh=QYrY3PPRwc1pxE1XgYFpRxvEIryQYj/9Bk2ICaRmWlw=; b=owGbwMvMwCVWzJ65uCpJ5D/jabUkhmx+dh7z/D8KBxe9nj0zIbCnV7ru8E/Vd1bfXrNKTZn1u OREueHEjlIWBjEuBlkxRZaO/zdCfEK+fVoWp9UHM4eVCWQIAxenAEykR5eR4byFtuMzhy2fWfQ9 VPw4p64/GvHt0jEbxYkxB75+inhXu43hn9rSlXNnCu/nKXSKnWiX+MRbouMS/6QvbJMVTko6miw +xQ4A X-Developer-Key: i=ernest.borowski.git@proton.me; a=openpgp; fpr=88FFD8544C54F6F2A65E2A8E730769A37A6214FF X-Endpoint-Received: by B4 Relay for ernest.borowski.git@proton.me/default with auth_id=1589 X-Original-From: Ernest Borowski Reply-To: ernest.borowski.git@proton.me Content-Transfer-Encoding: 7bit From: Ernest Borowski ntfs_rl_punch_hole() and ntfs_rl_collapse_range() advance the lcn of a run they split with "if (lcn > LCN_HOLE) lcn += n". LCN_DELALLOC (-1) is greater than LCN_HOLE (-2), so splitting a delalloc run turns its tail into a run of real clusters starting at n - 1. ntfs_rl_insert_range() advances it unconditionally; its callers insert holes, so only a hole split for a non-hole source and a split delalloc run are affected. ntfs_rle_lcn_contiguous() has the same problem and can merge a delalloc run with a following real run. The punched-out part then goes to ntfs_cluster_free_from_rl(), which frees clusters that belong to other files or to metadata, and the part left in the runlist maps the file onto them. Delalloc runs normally do not survive the writeback that fallocate() does first, but a buffered write that fails after ->iomap_begin() leaves one without dirty folios (fixed by the next patch); FALLOC_FL_PUNCH_HOLE or COLLAPSE_RANGE through it then corrupts the volume (ntfsck: "Found 1 inconsistent bitmap block(s)"). Only shift the lcn of runs that have real clusters. Fixes: 11ccc9107dc4 ("ntfs: update runlist handling and cluster allocator") Cc: stable@vger.kernel.org Signed-off-by: Ernest Borowski --- fs/ntfs/runlist.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fs/ntfs/runlist.c b/fs/ntfs/runlist.c index 76ba6ab72b..1e87db35ce 100644 --- a/fs/ntfs/runlist.c +++ b/fs/ntfs/runlist.c @@ -1770,7 +1770,7 @@ s64 ntfs_rl_get_compressed_size(struct ntfs_volume *vol, struct runlist_element static inline bool ntfs_rle_lcn_contiguous(struct runlist_element *left_rle, struct runlist_element *right_rle) { - if (left_rle->lcn > LCN_HOLE && + if (left_rle->lcn >= 0 && left_rle->lcn + left_rle->length == right_rle->lcn) return true; else if (left_rle->lcn == LCN_HOLE && right_rle->lcn == LCN_HOLE) @@ -1832,7 +1832,8 @@ struct runlist_element *ntfs_rl_insert_range(struct runlist_element *dst_rl, int i_rl[0].vcn = start_vcn; i_rl[0].length -= dst_rl_split.length; - i_rl[0].lcn += dst_rl_split.length; + if (i_rl[0].lcn >= 0) + i_rl[0].lcn += dst_rl_split.length; } else { struct runlist_element *dst_rle, *src_rle; merge_src_rle: @@ -1988,7 +1989,7 @@ struct runlist_element *ntfs_rl_punch_hole(struct runlist_element *dst_rl, int d (*punch_rl)[0].vcn = start_vcn; (*punch_rl)[0].length -= first_cnt; - if ((*punch_rl)[0].lcn > LCN_HOLE) + if ((*punch_rl)[0].lcn >= 0) (*punch_rl)[0].lcn += first_cnt; } @@ -2008,7 +2009,7 @@ struct runlist_element *ntfs_rl_punch_hole(struct runlist_element *dst_rl, int d new_rl[new_1st_cnt + 1].vcn = end_vcn + 1; new_rl[new_1st_cnt + 1].length -= first_cnt; - if (new_rl[new_1st_cnt + 1].lcn > LCN_HOLE) + if (new_rl[new_1st_cnt + 1].lcn >= 0) new_rl[new_1st_cnt + 1].lcn += first_cnt; if (one_split_3) @@ -2136,7 +2137,7 @@ struct runlist_element *ntfs_rl_collapse_range(struct runlist_element *dst_rl, i (*punch_rl)[0].vcn = start_vcn; (*punch_rl)[0].length -= first_cnt; - if ((*punch_rl)[0].lcn > LCN_HOLE) + if ((*punch_rl)[0].lcn >= 0) (*punch_rl)[0].lcn += first_cnt; } @@ -2150,7 +2151,7 @@ struct runlist_element *ntfs_rl_collapse_range(struct runlist_element *dst_rl, i new_rl[new_1st_cnt].vcn = end_vcn + 1; new_rl[new_1st_cnt].length -= first_cnt; - if (new_rl[new_1st_cnt].lcn > LCN_HOLE) + if (new_rl[new_1st_cnt].lcn >= 0) new_rl[new_1st_cnt].lcn += first_cnt; if (one_split_3) -- 2.56.1