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=1796409639; b=s24HYTyOuFObsg0xynKeLaQJ6xlRFX/Zej1zjP74Kkj80BIYL5uRx0N3s2Jb0fB/F3ZI zMwrBp7zqcjxN1qny/lbkIUIHQ6zg4NVKo+ULMz/rf6FAcq1gJhqfx3oj3Pv3yCo5zykA vk3qmOEbM4brrM5MYR1nHyc6ksGeruZWePukJ/n9vXakAsy8bAzY7kRAJFtbM9uX15cYJ JNfRwk+Snbod1VNi75lCX5O/drP+tG6Nchj78jeOlelF4VsqoIERUCIgyhJ2nWvaz9Wnb 7KBIwyvd9kbK1DlTEp2EQSStGX4ZKxYTD0zwHBFRvdg7k4XmBFerAUg3rkbFZyCi7Yg== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796409639; 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=1t70HDrKz8OG9OR18kIIo5keJsJ095lfoVo4S3VWOO4=; b=zRvnd3crnhXfDcO3WkupGo2TmunKtdaHpDpwYhcWA04uYD2zLe0zbNGo/r6B/ckuKZGU bUUEjd0feV2jcybftS2S0nDJrOV7xEHApG7X6Jkepgngz5nyYDhIo9cpV1tytOMNthoLs m2UTIHXR3ihXLEJ9iVHsX6gex+W37z9ge03Xm623V0VY90WZ3bYixIEywKyQXZoPkG4/R vyy9ExoIwTypCRKrp2zVm5yxckTmTsGgQPn32Wmx4KdF/vve7nQk2M7zMYE1x4BtzjlC9 6sLKRupteSZnOz5CGb21QfnJJqX12Z1AZrC80O4WjB+wGMmAjN5MnfS3+6CVZyZHcXg== 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=cI5ZMJhS; 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 DFF2F606A69D; Fri, 4 Dec 2026 18:40:38 +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=cI5ZMJhS 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=1796409638; b=au0JpdySq0zXMAklmsLrm/5xBr1nMbIHW3wge4LRa76e4iqnfZuv45K14/E+rpOmrTZG nnLxaGBAddngJRNSn2N0tZZGBpIMKeUT6QKFAWoUAOHZNlv3nYEAxF34JZGJGoroYHisQ Nh5uwp4grmUX06rDEPpi3l/8iSiqzwPFjKSxIIu7xJi8Fe3QIgrwjcpEO5B8PDrbsJGmR BX4MuBUOr5Lyy7SCiWnxwByWVSl2zlhw3Me6Nd/fNV2RCeDN+hb+E6JYtrP7SxJp6oWmA +BmWYwpoMzF38UfT5y3NfWLFKwH9YK8s2SLPkC/P5rN7yWDODbFv10d6F0imH9o44Nw== ARC-Message-Signature: i=1; d=kernel.org; s=arc20260519; a=rsa-sha256; c=relaxed/relaxed; t=1796409638; 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=1t70HDrKz8OG9OR18kIIo5keJsJ095lfoVo4S3VWOO4=; b=YnKUANQr45YoJu9lK1/Lb1XAoBlynvJSKfMkjhtFNZP2pKfOk8196yVTq5k4iuUJigIl ASrS8CssIC3abPZa4lyQmNCI5YbuxSS02GjwHOCRIsGNexm1kl2eYKXMIHE4EGvNEfMZp pU2WicMHn57HeZ2KacqpxCsL778kQan1WX2HhT9voUcmpvrXGDkNlYpMswUVUSDG+M0qG +TzVGqp7Qb7XLnSJ+n8aeb8w5pAFDZYjJtVTFrKaOcJqoE1JpK4CXlpYjPUn59VHEyOyI Zdp4V0EW/jzlXm5gARQmyTrftNHsymSz6EbSpSqyj9LaSHnx9o7FinB2uQMZriuK+Jg== 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 C77491F00A1C; Fri, 4 Dec 2026 18:40:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796409638; bh=1t70HDrKz8OG9OR18kIIo5keJsJ095lfoVo4S3VWOO4=; h=From:Date:Subject:References:In-Reply-To:To:Cc:Reply-To; b=cI5ZMJhSJIjh/B+fH09kZeQoC8D5Ul1FvvY/5M9RSHPpOXRNhHEbTT+VzivGdfflR JyT8ud+5FiCW0etfGlZxPr3Y+S91g35n1n61N/KObweCNRKvompyl4eYGgCUrvWDmg bkan2cx6MazUNBiKjRg9rCfOm3lLQPdP2bKNtjgRmWzWMhjSf+HkF/gVHFYO/iCrqd 5IJpxuJxC+4yDUZx6kcGEayalkDBWd0J60UHFnwb1sFr/IGR4/cf2AM/X4ysLrFddW T2MXhoiObyfCeTmxM0EYevkXqYFqN2dK3ztqYWyUbPksYog4foid+CO+FKMPiFayzf eS3Dtcuuel/rQ== Received: from nexus.subspace.kernel.org (localhost [IPv6:::1]) by lkml.kernel.org (Postfix) with ESMTP id E37BD4DC46; Fri, 4 Dec 2026 18:40:35 +0000 (UTC) From: Ernest Borowski via B4 Relay Date: Fri, 04 Dec 2026 19:40:38 +0100 Subject: [PATCH v5 07/13] 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: <20261204-b4-ntfs-delalloc-fixes-v5-7-1cd0267df2cd@proton.me> References: <20261204-b4-ntfs-delalloc-fixes-v5-0-1cd0267df2cd@proton.me> In-Reply-To: <20261204-b4-ntfs-delalloc-fixes-v5-0-1cd0267df2cd@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, Baolin Liu , Ernest Borowski X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=3686; i=ernest.borowski.git@proton.me; s=default; h=from:subject:message-id; bh=aMbMqvI+XGbM//Srte++hpbLq7uYUPIQAW9dhcModak=; b=owGbwMvMwCVWzJ65uCpJ5D/jabUkhmxhTgXTtyyPf4ZNnef4dYVB7+ZNXcnfb3+P+2pecOyum dOiZH3XjlIWBjEuBlkxRZaO/zdCfEK+fVoWp9UHM4eVCWQIAxenAExkei/Df19hg+bcD9bdadGJ rn3T+n1LfnoxT3Pesbz59GxmywNFWYwMHetr5k3qdmu3NvMzk61Ikn6YMd3o1ow3sz03V0+59pW BGwA= 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 Reviewed-by: Baolin Liu 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