From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B7DA6C4167B for ; Wed, 6 Dec 2023 15:14:23 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442469AbjLFPOP (ORCPT ); Wed, 6 Dec 2023 10:14:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379244AbjLFPOK (ORCPT ); Wed, 6 Dec 2023 10:14:10 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2355DD64; Wed, 6 Dec 2023 07:14:16 -0800 (PST) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id DCC301D47; Wed, 6 Dec 2023 15:02:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701874953; bh=h7CldxQv2S5Mzb+cgzMS8C/4d3oWIhrtzyaVf9z57fs=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=FtCj3ZeRaBPZiv12dqOADExR+OT9YeqY3/k6OC2QQKJ9fE5ai7DN/5guAiwZgrx0Y jzP8+1cDoiXU1I2OILGI8oMrFGQ8Mzot78sQq7PJSr+NK9SifuC9zxxEqJPwFMUUQW 5WoniFgJM0xApmStxoud0SP6WIR1lmABVdHpzCw8= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id 243202117; Wed, 6 Dec 2023 15:08:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875337; bh=h7CldxQv2S5Mzb+cgzMS8C/4d3oWIhrtzyaVf9z57fs=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=eyslm8PSDjgl/rJxNS7F5ffPQA97GTxlXUWYf2oWGY5RTCsYMvvFyqCsElJpRYSwz 6npCQYykuV9udtf+8QOPyVk307zBuOQjVyLCP2+qixg9ZdLjMW9bmjegmNrIfmBVN8 0V/6teX8F6muUqbGlKbZHgFBNOh1lspt8A1CwIIE= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:08:56 +0300 Message-ID: <53c3c86f-c816-4747-9262-592c3ddc6660@paragon-software.com> Date: Wed, 6 Dec 2023 18:08:56 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 01/16] fs/ntfs3: Improve alternative boot processing Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/super.c | 35 +++++++++++++++++------------------ =C2=A01 file changed, 17 insertions(+), 18 deletions(-) diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 9153dffde950..09d61c6c90aa 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -866,6 +866,7 @@ static int ntfs_init_from_boot(struct super_block=20 *sb, u32 sector_size, =C2=A0=C2=A0=C2=A0 =C2=A0u16 fn, ao; =C2=A0=C2=A0=C2=A0 =C2=A0u8 cluster_bits; =C2=A0=C2=A0=C2=A0 =C2=A0u32 boot_off =3D 0; +=C2=A0=C2=A0 =C2=A0sector_t boot_block =3D 0; =C2=A0=C2=A0=C2=A0 =C2=A0const char *hint =3D "Primary boot"; =C2=A0=C2=A0=C2=A0 =C2=A0/* Save original dev_size. Used with alternative = boot. */ @@ -873,11 +874,11 @@ static int ntfs_init_from_boot(struct super_block=20 *sb, u32 sector_size, =C2=A0=C2=A0=C2=A0 =C2=A0sbi->volume.blocks =3D dev_size >> PAGE_SHIFT; -=C2=A0=C2=A0 =C2=A0bh =3D ntfs_bread(sb, 0); +read_boot: +=C2=A0=C2=A0 =C2=A0bh =3D ntfs_bread(sb, boot_block); =C2=A0=C2=A0=C2=A0 =C2=A0if (!bh) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return boot_block ? -EINVAL : -EIO; -check_boot: =C2=A0=C2=A0=C2=A0 =C2=A0err =3D -EINVAL; =C2=A0=C2=A0=C2=A0 =C2=A0/* Corrupted image; do not read OOB */ @@ -1108,26 +1109,24 @@ static int ntfs_init_from_boot(struct=20 super_block *sb, u32 sector_size, =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0out: -=C2=A0=C2=A0 =C2=A0if (err =3D=3D -EINVAL && !bh->b_blocknr && dev_size0 >= PAGE_SHIFT) { +=C2=A0=C2=A0 =C2=A0brelse(bh); + +=C2=A0=C2=A0 =C2=A0if (err =3D=3D -EINVAL && !boot_block && dev_size0 > PA= GE_SHIFT) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0u32 block_size =3D min_t(u32, = sector_size, PAGE_SIZE); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0u64 lbo =3D dev_size0 - sizeof= (*boot); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* -=C2=A0=C2=A0 =C2=A0 =C2=A0=C2=A0 =C2=A0 * Try alternative boot (last secto= r) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 */ -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0brelse(bh); - -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0sb_set_blocksize(sb, block_size); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0bh =3D ntfs_bread(sb, lbo >> blksize= _bits(block_size)); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!bh) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EINVAL; - +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0boot_block =3D lbo >> blksize_bits(b= lock_size); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0boot_off =3D lbo & (block_size= - 1); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0hint =3D "Alternative boot"; -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0dev_size =3D dev_size0; /* restore o= riginal size. */ -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto check_boot; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (boot_block && block_size >=3D bo= ot_off + sizeof(*boot)) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 * Try alternativ= e boot (last sector) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0sb_set_blocksize(= sb, block_size); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0hint =3D "Alterna= tive boot"; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0dev_size =3D dev_= size0; /* restore original size. */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto read_boot; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0} -=C2=A0=C2=A0 =C2=A0brelse(bh); =C2=A0=C2=A0=C2=A0 =C2=A0return err; =C2=A0} --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 51307C4167B for ; Wed, 6 Dec 2023 15:09:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442447AbjLFPJn (ORCPT ); Wed, 6 Dec 2023 10:09:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442406AbjLFPJl (ORCPT ); Wed, 6 Dec 2023 10:09:41 -0500 X-Greylist: delayed 99 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 06 Dec 2023 07:09:48 PST Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02ADDC6; Wed, 6 Dec 2023 07:09:47 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 75DD71E1A; Wed, 6 Dec 2023 15:03:21 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875001; bh=Ifmg2OmIcc1e099M3eAc7+M0D09LHndtu4YB0fZ10AE=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=CM28fQWfl2jtqKv/4Q00K5fqN1XehGPo+klnsLEdY+l3HE67RQZYkzBqf6GrkQUfr djhTyaAxCW/vH267eQpmpDRK6Px0x/CmTqlYadmRB8vyT2X9uyiv7/Ivcky6dxEE49 O+rzp55tAH/NRfKemZdi/99Qye5kO0nISMZtbgX8= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:09:45 +0300 Message-ID: Date: Wed, 6 Dec 2023 18:09:45 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 02/16] fs/ntfs3: Modified fix directory element type detection Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Unfortunately reparse attribute is used for many purposes (several dozens). It is not possible here to know is this name symlink or not. To get exactly the type of name we should to open inode (read mft). getattr for opened file (fstat) correctly returns symlink. Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/dir.c | 30 +++++++++++++++++++++++++----- =C2=A01 file changed, 25 insertions(+), 5 deletions(-) diff --git a/fs/ntfs3/dir.c b/fs/ntfs3/dir.c index ec0566b322d5..22ede4da0450 100644 --- a/fs/ntfs3/dir.c +++ b/fs/ntfs3/dir.c @@ -309,11 +309,31 @@ static inline int ntfs_filldir(struct ntfs_sb_info=20 *sbi, struct ntfs_inode *ni, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return 0; =C2=A0=C2=A0=C2=A0 =C2=A0} -=C2=A0=C2=A0 =C2=A0/* NTFS: symlinks are "dir + reparse" or "file + repars= e" */ -=C2=A0=C2=A0 =C2=A0if (fname->dup.fa & FILE_ATTRIBUTE_REPARSE_POINT) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0dt_type =3D DT_LNK; -=C2=A0=C2=A0 =C2=A0else -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0dt_type =3D (fname->dup.fa & FILE_AT= TRIBUTE_DIRECTORY) ? DT_DIR :=20 DT_REG; +=C2=A0=C2=A0 =C2=A0/* +=C2=A0=C2=A0 =C2=A0 * NTFS: symlinks are "dir + reparse" or "file + repars= e" +=C2=A0=C2=A0 =C2=A0 * Unfortunately reparse attribute is used for many pur= poses=20 (several dozens). +=C2=A0=C2=A0 =C2=A0 * It is not possible here to know is this name symlink= or not. +=C2=A0=C2=A0 =C2=A0 * To get exactly the type of name we should to open in= ode (read mft). +=C2=A0=C2=A0 =C2=A0 * getattr for opened file (fstat) correctly returns sy= mlink. +=C2=A0=C2=A0 =C2=A0 */ +=C2=A0=C2=A0 =C2=A0dt_type =3D (fname->dup.fa & FILE_ATTRIBUTE_DIRECTORY) = ? DT_DIR : DT_REG; + +=C2=A0=C2=A0 =C2=A0/* +=C2=A0=C2=A0 =C2=A0 * It is not reliable to detect the type of name using = duplicated=20 information +=C2=A0=C2=A0 =C2=A0 * stored in parent directory. +=C2=A0=C2=A0 =C2=A0 * The only correct way to get the type of name - read = MFT record=20 and find ATTR_STD. +=C2=A0=C2=A0 =C2=A0 * The code below is not good idea. +=C2=A0=C2=A0 =C2=A0 * It does additional locks/reads just to get the type = of name. +=C2=A0=C2=A0 =C2=A0 * Should we use additional mount option to enable bran= ch below? +=C2=A0=C2=A0 =C2=A0 */ +=C2=A0=C2=A0 =C2=A0if ((fname->dup.fa & FILE_ATTRIBUTE_REPARSE_POINT) && +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 ino !=3D ni->mi.rno) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0struct inode *inode =3D ntfs_iget5(s= bi->sb, &e->ref, NULL); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!IS_ERR_OR_NULL(inode)) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0dt_type =3D fs_um= ode_to_dtype(inode->i_mode); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0iput(inode); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} +=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0return !dir_emit(ctx, (s8 *)name, name_len, ino, = dt_type); =C2=A0} --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D6ADBC4167B for ; Wed, 6 Dec 2023 15:10:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442430AbjLFPK2 (ORCPT ); Wed, 6 Dec 2023 10:10:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442448AbjLFPKV (ORCPT ); Wed, 6 Dec 2023 10:10:21 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31BBADE; Wed, 6 Dec 2023 07:10:27 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id D92B11E1A; Wed, 6 Dec 2023 15:04:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875040; bh=/GAY4vh49Ey49PjOB0D7aW4BJClWKFEVXZZb9RVpvm8=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=bV1feHdOoc85vxuNTcRIuuIj4OKvvVliIheZoWfeIjMagZtKTIExoG1tZP5GKcmcC 2Xm3LxPkbcoWDpxWt3fxCzNeybO3lNj/Zk/uh1gmH2/1enCbGpFcHF7wyUjchAGCIv 2RCP2b2+LXWKnHQCqKpaT1lY7nUqnYMKO5UJM8XU= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:10:24 +0300 Message-ID: Date: Wed, 6 Dec 2023 18:10:24 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 03/16] fs/ntfs3: Improve ntfs_dir_count Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/dir.c | 10 +++------- =C2=A01 file changed, 3 insertions(+), 7 deletions(-) diff --git a/fs/ntfs3/dir.c b/fs/ntfs3/dir.c index 22ede4da0450..726122ecd39b 100644 --- a/fs/ntfs3/dir.c +++ b/fs/ntfs3/dir.c @@ -515,11 +515,9 @@ static int ntfs_dir_count(struct inode *dir, bool=20 *is_empty, size_t *dirs, =C2=A0=C2=A0=C2=A0 =C2=A0struct INDEX_HDR *hdr; =C2=A0=C2=A0=C2=A0 =C2=A0const struct ATTR_FILE_NAME *fname; =C2=A0=C2=A0=C2=A0 =C2=A0u32 e_size, off, end; -=C2=A0=C2=A0 =C2=A0u64 vbo =3D 0; =C2=A0=C2=A0=C2=A0 =C2=A0size_t drs =3D 0, fles =3D 0, bit =3D 0; -=C2=A0=C2=A0 =C2=A0loff_t i_size =3D ni->vfs_inode.i_size; =C2=A0=C2=A0=C2=A0 =C2=A0struct indx_node *node =3D NULL; -=C2=A0=C2=A0 =C2=A0u8 index_bits =3D ni->dir.index_bits; +=C2=A0=C2=A0 =C2=A0size_t max_indx =3D ni->vfs_inode.i_size >> ni->dir.ind= ex_bits; =C2=A0=C2=A0=C2=A0 =C2=A0if (is_empty) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0*is_empty =3D true; @@ -563,7 +561,7 @@ static int ntfs_dir_count(struct inode *dir, bool=20 *is_empty, size_t *dirs, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0fles +=3D 1; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (vbo >=3D i_size) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (bit >=3D max_indx) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D indx_used_bit(&ni->dir= , ni, &bit); @@ -573,8 +571,7 @@ static int ntfs_dir_count(struct inode *dir, bool=20 *is_empty, size_t *dirs, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (bit =3D=3D MINUS_ONE_T) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0vbo =3D (u64)bit << index_bits; -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (vbo >=3D i_size) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (bit >=3D max_indx) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D indx_read(&ni->dir, ni= , bit << ni->dir.idx2vbn_bits, @@ -584,7 +581,6 @@ static int ntfs_dir_count(struct inode *dir, bool=20 *is_empty, size_t *dirs, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0hdr =3D &node->index->ihdr; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0bit +=3D 1; -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0vbo =3D (u64)bit << ni->dir.idx2vbn_= bits; =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0out: --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C657C46CA0 for ; Wed, 6 Dec 2023 15:21:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379166AbjLFPLK (ORCPT ); Wed, 6 Dec 2023 10:11:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379221AbjLFPKs (ORCPT ); Wed, 6 Dec 2023 10:10:48 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 096DCD5B; Wed, 6 Dec 2023 07:10:54 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 751C91E1A; Wed, 6 Dec 2023 15:04:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875068; bh=mAuuCGMqlStfHaypyBJ9iLMuzcr3BmzULzMWMwWTRuE=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=bLupnkpLf7fzkUc2Zt5omBwLubjPcPeYPgaJ3tqLEQExUyjSso2/GDYWv58+hM9Zd fhwCheq3GPFBlwishCkRPuzN547xVQMTB6CcNxkddptzAQzbiVxJDeavPAQdzRFKtx 4XYrwbbISqytrtKzvacmxjfRMfH0G33BplXtpoVE= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:10:52 +0300 Message-ID: <8cb671f9-252b-443b-a903-ca62c9097533@paragon-software.com> Date: Wed, 6 Dec 2023 18:10:52 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 04/16] fs/ntfs3: Correct hard links updating when dealing with DOS neams Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/record.c | 16 ++++++++++++++-- =C2=A01 file changed, 14 insertions(+), 2 deletions(-) diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c index 53629b1f65e9..7b6423584eae 100644 --- a/fs/ntfs3/record.c +++ b/fs/ntfs3/record.c @@ -535,8 +535,20 @@ bool mi_remove_attr(struct ntfs_inode *ni, struct=20 mft_inode *mi, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return false; =C2=A0=C2=A0=C2=A0 =C2=A0if (ni && is_attr_indexed(attr)) { -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0le16_add_cpu(&ni->mi.mrec->hard_link= s, -1); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ni->mi.dirty =3D true; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0u16 links =3D le16_to_cpu(ni->mi.mre= c->hard_links); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0struct ATTR_FILE_NAME *fname =3D +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0attr->type !=3D A= TTR_NAME ? +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0NULL : +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0resident_data_ex(attr, +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 SIZEOF_ATTRIBUTE_FILENAME); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (fname && fname->type =3D=3D FILE= _NAME_DOS) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* Do not decreas= e links count deleting DOS name. */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} else if (!links) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* minor error. N= ot critical. */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} else { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ni->mi.mrec->hard= _links =3D cpu_to_le16(links - 1); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ni->mi.dirty =3D = true; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0used -=3D asize; --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1AE8C4167B for ; Wed, 6 Dec 2023 15:11:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379195AbjLFPLO (ORCPT ); Wed, 6 Dec 2023 10:11:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379096AbjLFPLJ (ORCPT ); Wed, 6 Dec 2023 10:11:09 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BC519A; Wed, 6 Dec 2023 07:11:15 -0800 (PST) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 4775E1E1A; Wed, 6 Dec 2023 15:04:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875089; bh=2BFRYk4Moqh9lL8OQcoNVoZ0RV2c9czsoWnrNagsXik=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=W9QM4y1PMOeSapyHHNSO54M7gNOc1aLuFNGjtTYjQSJV0htdC4x+VrQzupF0/j9I2 UQ/Qz+SxSN+tutElWa0RtsRilM5yspu+upzKbRQtGAS3NGzhFCZufJlfmJhGi0hO+U tyjNmuWSVtRiSUFQIzuDruoiwdUzHk7LPQA+M7rs= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id 7F1272117; Wed, 6 Dec 2023 15:11:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875473; bh=2BFRYk4Moqh9lL8OQcoNVoZ0RV2c9czsoWnrNagsXik=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=LhPCq7kwV1lA63gtdTSLts0Uu8PS4YjNDVw1GJMjGvA42Ak90TZUseTrn1H2SP9cN sxA8xmWKrdoRbOZEcndzE9IUEt+a/pP//oH3NFdTK23dYF2ejGyECH6+V9PauMUPIH I7ouj8D/oTC4AJ8ES2dOWKSGaeBFkG1lESNnyQ7I= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:11:12 +0300 Message-ID: <44b1dd7e-f5fc-4908-84f1-8e631cdc23d9@paragon-software.com> Date: Wed, 6 Dec 2023 18:11:12 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 05/16] fs/ntfs3: Print warning while fixing hard links count Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/inode.c | 2 +- =C2=A01 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 5e3d71374918..fa6c7965473c 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -412,7 +412,6 @@ static struct inode *ntfs_read_mft(struct inode *inode, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0if (!is_match && name) { -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* Reuse rec as buffer for ascii nam= e. */ =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D -ENOENT; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0} @@ -427,6 +426,7 @@ static struct inode *ntfs_read_mft(struct inode *inode, =C2=A0=C2=A0=C2=A0 =C2=A0if (names !=3D le16_to_cpu(rec->hard_links)) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* Correct minor error on the = fly. Do not mark inode as dirty. */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ntfs_inode_warn(inode, "Correct link= s count -> %u.", names); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0rec->hard_links =3D cpu_to_le1= 6(names); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ni->mi.dirty =3D true; =C2=A0=C2=A0=C2=A0 =C2=A0} --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 68870C4167B for ; Wed, 6 Dec 2023 15:11:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379165AbjLFPLl (ORCPT ); Wed, 6 Dec 2023 10:11:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48964 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379090AbjLFPLi (ORCPT ); Wed, 6 Dec 2023 10:11:38 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1F6F112; Wed, 6 Dec 2023 07:11:42 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id C6A3D212D; Wed, 6 Dec 2023 15:05:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875116; bh=RexGtu8XWQhs4tm8penzzSeBhtaDj8gNGca25jwrs2M=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=hXLqwnBonYPKS90AP/XXpXvpg5+f5SWde19cling7MoZ4UnWwskiL/hAMPHubIxpw Of4FcC2fjOf/dQzXu8I2+vhD8p4R9EntgiXK60JCya/xpV8K9VtmMDipKLzh3QLjox JsiEpCgDcYrptLa+d6fhqSCIT7nICinhP97CaNZM= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:11:40 +0300 Message-ID: <17bac290-26bf-484d-bcf2-9a65e93add78@paragon-software.com> Date: Wed, 6 Dec 2023 18:11:40 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 06/16] fs/ntfs3: Reduce stack usage Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/fslog.c | 218 +++++++++++++++++++++------------------------= -- =C2=A01 file changed, 98 insertions(+), 120 deletions(-) diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c index 98ccb6650858..7dbb000fc691 100644 --- a/fs/ntfs3/fslog.c +++ b/fs/ntfs3/fslog.c @@ -974,6 +974,16 @@ static inline void *alloc_rsttbl_from_idx(struct=20 RESTART_TABLE **tbl, u32 vbo) =C2=A0=C2=A0=C2=A0 =C2=A0return e; =C2=A0} +struct restart_info { +=C2=A0=C2=A0 =C2=A0u64 last_lsn; +=C2=A0=C2=A0 =C2=A0struct RESTART_HDR *r_page; +=C2=A0=C2=A0 =C2=A0u32 vbo; +=C2=A0=C2=A0 =C2=A0bool chkdsk_was_run; +=C2=A0=C2=A0 =C2=A0bool valid_page; +=C2=A0=C2=A0 =C2=A0bool initialized; +=C2=A0=C2=A0 =C2=A0bool restart; +}; + =C2=A0#define RESTART_SINGLE_PAGE_IO cpu_to_le16(0x0001) =C2=A0#define NTFSLOG_WRAPPED 0x00000001 @@ -987,6 +997,7 @@ struct ntfs_log { =C2=A0=C2=A0=C2=A0 =C2=A0struct ntfs_inode *ni; =C2=A0=C2=A0=C2=A0 =C2=A0u32 l_size; +=C2=A0=C2=A0 =C2=A0u32 orig_file_size; =C2=A0=C2=A0=C2=A0 =C2=A0u32 sys_page_size; =C2=A0=C2=A0=C2=A0 =C2=A0u32 sys_page_mask; =C2=A0=C2=A0=C2=A0 =C2=A0u32 page_size; @@ -1040,6 +1051,8 @@ struct ntfs_log { =C2=A0=C2=A0=C2=A0 =C2=A0struct CLIENT_ID client_id; =C2=A0=C2=A0=C2=A0 =C2=A0u32 client_undo_commit; + +=C2=A0=C2=A0 =C2=A0struct restart_info rst_info, rst_info2; =C2=A0}; =C2=A0static inline u32 lsn_to_vbo(struct ntfs_log *log, const u64 lsn) @@ -1105,16 +1118,6 @@ static inline bool verify_client_lsn(struct=20 ntfs_log *log, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 lsn <=3D le6= 4_to_cpu(log->ra->current_lsn) && lsn; =C2=A0} -struct restart_info { -=C2=A0=C2=A0 =C2=A0u64 last_lsn; -=C2=A0=C2=A0 =C2=A0struct RESTART_HDR *r_page; -=C2=A0=C2=A0 =C2=A0u32 vbo; -=C2=A0=C2=A0 =C2=A0bool chkdsk_was_run; -=C2=A0=C2=A0 =C2=A0bool valid_page; -=C2=A0=C2=A0 =C2=A0bool initialized; -=C2=A0=C2=A0 =C2=A0bool restart; -}; - =C2=A0static int read_log_page(struct ntfs_log *log, u32 vbo, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 struct REC= ORD_PAGE_HDR **buffer, bool *usa_error) =C2=A0{ @@ -1176,7 +1179,7 @@ static int read_log_page(struct ntfs_log *log, u32=20 vbo, =C2=A0 * restart page header. It will stop the first time we find a =C2=A0 * valid page header. =C2=A0 */ -static int log_read_rst(struct ntfs_log *log, u32 l_size, bool first, +static int log_read_rst(struct ntfs_log *log, bool first, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0struct rest= art_info *info) =C2=A0{ =C2=A0=C2=A0=C2=A0 =C2=A0u32 skip, vbo; @@ -1192,7 +1195,7 @@ static int log_read_rst(struct ntfs_log *log, u32=20 l_size, bool first, =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0/* Loop continuously until we succeed. */ -=C2=A0=C2=A0 =C2=A0for (; vbo < l_size; vbo =3D 2 * vbo + skip, skip =3D 0= ) { +=C2=A0=C2=A0 =C2=A0for (; vbo < log->l_size; vbo =3D 2 * vbo + skip, skip = =3D 0) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0bool usa_error; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0bool brst, bchk; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0struct RESTART_AREA *ra; @@ -1285,22 +1288,17 @@ static int log_read_rst(struct ntfs_log *log,=20 u32 l_size, bool first, =C2=A0/* =C2=A0 * Ilog_init_pg_hdr - Init @log from restart page header. =C2=A0 */ -static void log_init_pg_hdr(struct ntfs_log *log, u32 sys_page_size, -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2= =A0 u32 page_size, u16 major_ver, u16 minor_ver) +static void log_init_pg_hdr(struct ntfs_log *log, u16 major_ver, u16=20 minor_ver) =C2=A0{ -=C2=A0=C2=A0 =C2=A0log->sys_page_size =3D sys_page_size; -=C2=A0=C2=A0 =C2=A0log->sys_page_mask =3D sys_page_size - 1; -=C2=A0=C2=A0 =C2=A0log->page_size =3D page_size; -=C2=A0=C2=A0 =C2=A0log->page_mask =3D page_size - 1; -=C2=A0=C2=A0 =C2=A0log->page_bits =3D blksize_bits(page_size); +=C2=A0=C2=A0 =C2=A0log->sys_page_size =3D log->page_size; +=C2=A0=C2=A0 =C2=A0log->sys_page_mask =3D log->page_mask; =C2=A0=C2=A0=C2=A0 =C2=A0log->clst_per_page =3D log->page_size >> log->ni-= >mi.sbi->cluster_bits; =C2=A0=C2=A0=C2=A0 =C2=A0if (!log->clst_per_page) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0log->clst_per_page =3D 1; -=C2=A0=C2=A0 =C2=A0log->first_page =3D major_ver >=3D 2 ? -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0 0x22 * page_size : -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0 ((sys_page_size << 1) + (page_size << 1)); +=C2=A0=C2=A0 =C2=A0log->first_page =3D major_ver >=3D 2 ? 0x22 * log->page= _size : +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 4 * log->page_size; =C2=A0=C2=A0=C2=A0 =C2=A0log->major_ver =3D major_ver; =C2=A0=C2=A0=C2=A0 =C2=A0log->minor_ver =3D minor_ver; =C2=A0} @@ -1308,12 +1306,11 @@ static void log_init_pg_hdr(struct ntfs_log=20 *log, u32 sys_page_size, =C2=A0/* =C2=A0 * log_create - Init @log in cases when we don't have a restart area=20 to use. =C2=A0 */ -static void log_create(struct ntfs_log *log, u32 l_size, const u64=20 last_lsn, +static void log_create(struct ntfs_log *log, const u64 last_lsn, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0 u32 open_log_count, bool wrapped, bool use_multi_page) =C2=A0{ -=C2=A0=C2=A0 =C2=A0log->l_size =3D l_size; =C2=A0=C2=A0=C2=A0 =C2=A0/* All file offsets must be quadword aligned. */ -=C2=A0=C2=A0 =C2=A0log->file_data_bits =3D blksize_bits(l_size) - 3; +=C2=A0=C2=A0 =C2=A0log->file_data_bits =3D blksize_bits(log->l_size) - 3; =C2=A0=C2=A0=C2=A0 =C2=A0log->seq_num_mask =3D (8 << log->file_data_bits) = - 1; =C2=A0=C2=A0=C2=A0 =C2=A0log->seq_num_bits =3D sizeof(u64) * 8 - log->file= _data_bits; =C2=A0=C2=A0=C2=A0 =C2=A0log->seq_num =3D (last_lsn >> log->file_data_bits= ) + 2; @@ -3720,10 +3717,8 @@ int log_replay(struct ntfs_inode *ni, bool=20 *initialized) =C2=A0=C2=A0=C2=A0 =C2=A0struct ntfs_sb_info *sbi =3D ni->mi.sbi; =C2=A0=C2=A0=C2=A0 =C2=A0struct ntfs_log *log; -=C2=A0=C2=A0 =C2=A0struct restart_info rst_info, rst_info2; -=C2=A0=C2=A0 =C2=A0u64 rec_lsn, ra_lsn, checkpt_lsn =3D 0, rlsn =3D 0; +=C2=A0=C2=A0 =C2=A0u64 rec_lsn, checkpt_lsn =3D 0, rlsn =3D 0; =C2=A0=C2=A0=C2=A0 =C2=A0struct ATTR_NAME_ENTRY *attr_names =3D NULL; -=C2=A0=C2=A0 =C2=A0struct ATTR_NAME_ENTRY *ane; =C2=A0=C2=A0=C2=A0 =C2=A0struct RESTART_TABLE *dptbl =3D NULL; =C2=A0=C2=A0=C2=A0 =C2=A0struct RESTART_TABLE *trtbl =3D NULL; =C2=A0=C2=A0=C2=A0 =C2=A0const struct RESTART_TABLE *rt; @@ -3741,9 +3736,7 @@ int log_replay(struct ntfs_inode *ni, bool=20 *initialized) =C2=A0=C2=A0=C2=A0 =C2=A0struct TRANSACTION_ENTRY *tr; =C2=A0=C2=A0=C2=A0 =C2=A0struct DIR_PAGE_ENTRY *dp; =C2=A0=C2=A0=C2=A0 =C2=A0u32 i, bytes_per_attr_entry; -=C2=A0=C2=A0 =C2=A0u32 l_size =3D ni->vfs_inode.i_size; -=C2=A0=C2=A0 =C2=A0u32 orig_file_size =3D l_size; -=C2=A0=C2=A0 =C2=A0u32 page_size, vbo, tail, off, dlen; +=C2=A0=C2=A0 =C2=A0u32 vbo, tail, off, dlen; =C2=A0=C2=A0=C2=A0 =C2=A0u32 saved_len, rec_len, transact_id; =C2=A0=C2=A0=C2=A0 =C2=A0bool use_second_page; =C2=A0=C2=A0=C2=A0 =C2=A0struct RESTART_AREA *ra2, *ra =3D NULL; @@ -3758,52 +3751,50 @@ int log_replay(struct ntfs_inode *ni, bool=20 *initialized) =C2=A0=C2=A0=C2=A0 =C2=A0u16 t16; =C2=A0=C2=A0=C2=A0 =C2=A0u32 t32; -=C2=A0=C2=A0 =C2=A0/* Get the size of page. NOTE: To replay we can use def= ault page. */ -#if PAGE_SIZE >=3D DefaultLogPageSize && PAGE_SIZE <=3D DefaultLogPageSize= * 2 -=C2=A0=C2=A0 =C2=A0page_size =3D norm_file_page(PAGE_SIZE, &l_size, true); -#else -=C2=A0=C2=A0 =C2=A0page_size =3D norm_file_page(PAGE_SIZE, &l_size, false); -#endif -=C2=A0=C2=A0 =C2=A0if (!page_size) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EINVAL; - =C2=A0=C2=A0=C2=A0 =C2=A0log =3D kzalloc(sizeof(struct ntfs_log), GFP_NOFS= ); =C2=A0=C2=A0=C2=A0 =C2=A0if (!log) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -ENOMEM; =C2=A0=C2=A0=C2=A0 =C2=A0log->ni =3D ni; -=C2=A0=C2=A0 =C2=A0log->l_size =3D l_size; -=C2=A0=C2=A0 =C2=A0log->one_page_buf =3D kmalloc(page_size, GFP_NOFS); +=C2=A0=C2=A0 =C2=A0log->l_size =3D log->orig_file_size =3D ni->vfs_inode.i= _size; + +=C2=A0=C2=A0 =C2=A0/* Get the size of page. NOTE: To replay we can use def= ault page. */ +#if PAGE_SIZE >=3D DefaultLogPageSize && PAGE_SIZE <=3D DefaultLogPageSize= * 2 +=C2=A0=C2=A0 =C2=A0log->page_size =3D norm_file_page(PAGE_SIZE, &log->l_si= ze, true); +#else +=C2=A0=C2=A0 =C2=A0log->page_size =3D norm_file_page(PAGE_SIZE, &log->l_si= ze, false); +#endif +=C2=A0=C2=A0 =C2=A0if (!log->page_size) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D -EINVAL; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; +=C2=A0=C2=A0 =C2=A0} +=C2=A0=C2=A0 =C2=A0log->one_page_buf =3D kmalloc(log->page_size, GFP_NOFS); =C2=A0=C2=A0=C2=A0 =C2=A0if (!log->one_page_buf) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D -ENOMEM; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0} -=C2=A0=C2=A0 =C2=A0log->page_size =3D page_size; -=C2=A0=C2=A0 =C2=A0log->page_mask =3D page_size - 1; -=C2=A0=C2=A0 =C2=A0log->page_bits =3D blksize_bits(page_size); +=C2=A0=C2=A0 =C2=A0log->page_mask =3D log->page_size - 1; +=C2=A0=C2=A0 =C2=A0log->page_bits =3D blksize_bits(log->page_size); =C2=A0=C2=A0=C2=A0 =C2=A0/* Look for a restart area on the disk. */ -=C2=A0=C2=A0 =C2=A0memset(&rst_info, 0, sizeof(struct restart_info)); -=C2=A0=C2=A0 =C2=A0err =3D log_read_rst(log, l_size, true, &rst_info); +=C2=A0=C2=A0 =C2=A0err =3D log_read_rst(log, true, &log->rst_info); =C2=A0=C2=A0=C2=A0 =C2=A0if (err) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0/* remember 'initialized' */ -=C2=A0=C2=A0 =C2=A0*initialized =3D rst_info.initialized; +=C2=A0=C2=A0 =C2=A0*initialized =3D log->rst_info.initialized; -=C2=A0=C2=A0 =C2=A0if (!rst_info.restart) { -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (rst_info.initialized) { +=C2=A0=C2=A0 =C2=A0if (!log->rst_info.restart) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (log->rst_info.initialized) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* No resta= rt area but the file is not initialized. */ =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D -EI= NVAL; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0log_init_pg_hdr(log, page_size, page= _size, 1, 1); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0log_create(log, l_size, 0, get_rando= m_u32(), false, false); - -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0log->ra =3D ra; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0log_init_pg_hdr(log, 1, 1); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0log_create(log, 0, get_random_u32(),= false, false); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ra =3D log_create_ra(log); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!ra) { @@ -3820,25 +3811,26 @@ int log_replay(struct ntfs_inode *ni, bool=20 *initialized) =C2=A0=C2=A0=C2=A0 =C2=A0 * If the restart offset above wasn't zero then w= e won't =C2=A0=C2=A0=C2=A0 =C2=A0 * look for a second restart. =C2=A0=C2=A0=C2=A0 =C2=A0 */ -=C2=A0=C2=A0 =C2=A0if (rst_info.vbo) +=C2=A0=C2=A0 =C2=A0if (log->rst_info.vbo) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto check_restart_area; -=C2=A0=C2=A0 =C2=A0memset(&rst_info2, 0, sizeof(struct restart_info)); -=C2=A0=C2=A0 =C2=A0err =3D log_read_rst(log, l_size, false, &rst_info2); +=C2=A0=C2=A0 =C2=A0err =3D log_read_rst(log, false, &log->rst_info2); =C2=A0=C2=A0=C2=A0 =C2=A0if (err) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0/* Determine which restart area to use. */ -=C2=A0=C2=A0 =C2=A0if (!rst_info2.restart || rst_info2.last_lsn <=3D rst_i= nfo.last_lsn) +=C2=A0=C2=A0 =C2=A0if (!log->rst_info2.restart || +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 log->rst_info2.last_lsn <=3D log->rs= t_info.last_lsn) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto use_first_page; =C2=A0=C2=A0=C2=A0 =C2=A0use_second_page =3D true; -=C2=A0=C2=A0 =C2=A0if (rst_info.chkdsk_was_run && page_size !=3D rst_info.= vbo) { +=C2=A0=C2=A0 =C2=A0if (log->rst_info.chkdsk_was_run && +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 log->page_size !=3D log->rst_info.vb= o) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0struct RECORD_PAGE_HDR *sp =3D= NULL; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0bool usa_error; -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!read_log_page(log, page_size, &= sp, &usa_error) && +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!read_log_page(log, log->page_si= ze, &sp, &usa_error) && =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 sp->rhdr.si= gn =3D=3D NTFS_CHKD_SIGNATURE) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0use_second_= page =3D false; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} @@ -3846,52 +3838,43 @@ int log_replay(struct ntfs_inode *ni, bool=20 *initialized) =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0if (use_second_page) { -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0kfree(rst_info.r_page); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0memcpy(&rst_info, &rst_info2, sizeof= (struct restart_info)); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0rst_info2.r_page =3D NULL; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0kfree(log->rst_info.r_page); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0memcpy(&log->rst_info, &log->rst_inf= o2, +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= sizeof(struct restart_info)); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0log->rst_info2.r_page =3D NULL; =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0use_first_page: -=C2=A0=C2=A0 =C2=A0kfree(rst_info2.r_page); +=C2=A0=C2=A0 =C2=A0kfree(log->rst_info2.r_page); =C2=A0check_restart_area: =C2=A0=C2=A0=C2=A0 =C2=A0/* =C2=A0=C2=A0=C2=A0 =C2=A0 * If the restart area is at offset 0, we want =C2=A0=C2=A0=C2=A0 =C2=A0 * to write the second restart area first. =C2=A0=C2=A0=C2=A0 =C2=A0 */ -=C2=A0=C2=A0 =C2=A0log->init_ra =3D !!rst_info.vbo; +=C2=A0=C2=A0 =C2=A0log->init_ra =3D !!log->rst_info.vbo; =C2=A0=C2=A0=C2=A0 =C2=A0/* If we have a valid page then grab a pointer to= the restart area. */ -=C2=A0=C2=A0 =C2=A0ra2 =3D rst_info.valid_page ? -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Add2P= tr(rst_info.r_page, -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 le16_to_cpu(rst_info.r_page->ra_off)) : +=C2=A0=C2=A0 =C2=A0ra2 =3D log->rst_info.valid_page ? +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 Add2P= tr(log->rst_info.r_page, +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0 le16_to_cpu(log->rst_info.r_page->ra_off)) : =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= NULL; -=C2=A0=C2=A0 =C2=A0if (rst_info.chkdsk_was_run || +=C2=A0=C2=A0 =C2=A0if (log->rst_info.chkdsk_was_run || =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 (ra2 && ra2->client_idx[1] =3D= =3D LFS_NO_CLIENT_LE)) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0bool wrapped =3D false; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0bool use_multi_page =3D false; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0u32 open_log_count; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* Do some checks based on whe= ther we have a valid log page. */ -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!rst_info.valid_page) { -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0open_log_count = =3D get_random_u32(); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto init_log_ins= tance; -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0open_log_count =3D le32_to_cpu(ra2->= open_log_count); - -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 * If the restart page size isn't ch= anging then we want to -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 * check how much work we need to do. -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 */ -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (page_size !=3D le32_to_cpu(rst_i= nfo.r_page->sys_page_size)) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto init_log_ins= tance; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0open_log_count =3D log->rst_info.val= id_page ? +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0=C2=A0 =C2=A0 le32_to_cpu(ra2->open_log_count) : +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0=C2=A0 =C2=A0 get_random_u32(); -init_log_instance: -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0log_init_pg_hdr(log, page_size, page= _size, 1, 1); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0log_init_pg_hdr(log, 1, 1); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0log_create(log, l_size, rst_info.las= t_lsn, open_log_count, -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 wrap= ped, use_multi_page); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0log_create(log, log->rst_info.last_l= sn, open_log_count, wrapped, +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 use_= multi_page); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ra =3D log_create_ra(log); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!ra) { @@ -3916,28 +3899,27 @@ int log_replay(struct ntfs_inode *ni, bool=20 *initialized) =C2=A0=C2=A0=C2=A0 =C2=A0 * use the log file. We must use the system page = size instead of the =C2=A0=C2=A0=C2=A0 =C2=A0 * default size if there is not a clean shutdown. =C2=A0=C2=A0=C2=A0 =C2=A0 */ -=C2=A0=C2=A0 =C2=A0t32 =3D le32_to_cpu(rst_info.r_page->sys_page_size); -=C2=A0=C2=A0 =C2=A0if (page_size !=3D t32) { -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0l_size =3D orig_file_size; -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0page_size =3D -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0norm_file_page(t3= 2, &l_size, t32 =3D=3D DefaultLogPageSize); +=C2=A0=C2=A0 =C2=A0t32 =3D le32_to_cpu(log->rst_info.r_page->sys_page_size= ); +=C2=A0=C2=A0 =C2=A0if (log->page_size !=3D t32) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0log->l_size =3D log->orig_file_size; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0log->page_size =3D norm_file_page(t3= 2, &log->l_size, +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0t32 =3D=3D DefaultLogPageSize); =C2=A0=C2=A0=C2=A0 =C2=A0} -=C2=A0=C2=A0 =C2=A0if (page_size !=3D t32 || -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 page_size !=3D le32_to_cpu(rst_info.= r_page->page_size)) { +=C2=A0=C2=A0 =C2=A0if (log->page_size !=3D t32 || +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 log->page_size !=3D le32_to_cpu(log-= >rst_info.r_page->page_size)) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D -EINVAL; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0/* If the file size has shrunk then we won't moun= t it. */ -=C2=A0=C2=A0 =C2=A0if (l_size < le64_to_cpu(ra2->l_size)) { +=C2=A0=C2=A0 =C2=A0if (log->l_size < le64_to_cpu(ra2->l_size)) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D -EINVAL; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0} -=C2=A0=C2=A0 =C2=A0log_init_pg_hdr(log, page_size, page_size, -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0le16_to_cpu(rst_i= nfo.r_page->major_ver), -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0le16_to_cpu(rst_i= nfo.r_page->minor_ver)); +=C2=A0=C2=A0 =C2=A0log_init_pg_hdr(log, le16_to_cpu(log->rst_info.r_page->= major_ver), +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0le16_to_cpu(log->= rst_info.r_page->minor_ver)); =C2=A0=C2=A0=C2=A0 =C2=A0log->l_size =3D le64_to_cpu(ra2->l_size); =C2=A0=C2=A0=C2=A0 =C2=A0log->seq_num_bits =3D le32_to_cpu(ra2->seq_num_bi= ts); @@ -3945,7 +3927,7 @@ int log_replay(struct ntfs_inode *ni, bool=20 *initialized) =C2=A0=C2=A0=C2=A0 =C2=A0log->seq_num_mask =3D (8 << log->file_data_bits) = - 1; =C2=A0=C2=A0=C2=A0 =C2=A0log->last_lsn =3D le64_to_cpu(ra2->current_lsn); =C2=A0=C2=A0=C2=A0 =C2=A0log->seq_num =3D log->last_lsn >> log->file_data_= bits; -=C2=A0=C2=A0 =C2=A0log->ra_off =3D le16_to_cpu(rst_info.r_page->ra_off); +=C2=A0=C2=A0 =C2=A0log->ra_off =3D le16_to_cpu(log->rst_info.r_page->ra_of= f); =C2=A0=C2=A0=C2=A0 =C2=A0log->restart_size =3D log->sys_page_size - log->r= a_off; =C2=A0=C2=A0=C2=A0 =C2=A0log->record_header_len =3D le16_to_cpu(ra2->rec_h= dr_len); =C2=A0=C2=A0=C2=A0 =C2=A0log->ra_size =3D le16_to_cpu(ra2->ra_len); @@ -4045,7 +4027,7 @@ int log_replay(struct ntfs_inode *ni, bool=20 *initialized) =C2=A0=C2=A0=C2=A0 =C2=A0log->current_avail =3D current_log_avail(log); =C2=A0=C2=A0=C2=A0 =C2=A0/* Remember which restart area to write first. */ -=C2=A0=C2=A0 =C2=A0log->init_ra =3D rst_info.vbo; +=C2=A0=C2=A0 =C2=A0log->init_ra =3D log->rst_info.vbo; =C2=A0process_log: =C2=A0=C2=A0=C2=A0 =C2=A0/* 1.0, 1.1, 2.0 log->major_ver/minor_ver - short= values. */ @@ -4105,7 +4087,7 @@ int log_replay(struct ntfs_inode *ni, bool=20 *initialized) =C2=A0=C2=A0=C2=A0 =C2=A0log->client_id.seq_num =3D cr->seq_num; =C2=A0=C2=A0=C2=A0 =C2=A0log->client_id.client_idx =3D client; -=C2=A0=C2=A0 =C2=A0err =3D read_rst_area(log, &rst, &ra_lsn); +=C2=A0=C2=A0 =C2=A0err =3D read_rst_area(log, &rst, &checkpt_lsn); =C2=A0=C2=A0=C2=A0 =C2=A0if (err) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; @@ -4114,9 +4096,8 @@ int log_replay(struct ntfs_inode *ni, bool=20 *initialized) =C2=A0=C2=A0=C2=A0 =C2=A0bytes_per_attr_entry =3D !rst->major_ver ? 0x2C := 0x28; -=C2=A0=C2=A0 =C2=A0checkpt_lsn =3D le64_to_cpu(rst->check_point_start); -=C2=A0=C2=A0 =C2=A0if (!checkpt_lsn) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0checkpt_lsn =3D ra_lsn; +=C2=A0=C2=A0 =C2=A0if (rst->check_point_start) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0checkpt_lsn =3D le64_to_cpu(rst->che= ck_point_start); =C2=A0=C2=A0=C2=A0 =C2=A0/* Allocate and Read the Transaction Table. */ =C2=A0=C2=A0=C2=A0 =C2=A0if (!rst->transact_table_len) @@ -4330,23 +4311,20 @@ int log_replay(struct ntfs_inode *ni, bool=20 *initialized) =C2=A0=C2=A0=C2=A0 =C2=A0lcb =3D NULL; =C2=A0check_attribute_names2: -=C2=A0=C2=A0 =C2=A0if (!rst->attr_names_len) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto trace_attribute_table; - -=C2=A0=C2=A0 =C2=A0ane =3D attr_names; -=C2=A0=C2=A0 =C2=A0if (!oatbl) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto trace_attribute_table; -=C2=A0=C2=A0 =C2=A0while (ane->off) { -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* TODO: Clear table on exit! */ -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0oe =3D Add2Ptr(oatbl, le16_to_cpu(an= e->off)); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0t16 =3D le16_to_cpu(ane->name_bytes); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0oe->name_len =3D t16 / sizeof(short); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0oe->ptr =3D ane->name; -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0oe->is_attr_name =3D 2; -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ane =3D Add2Ptr(ane, sizeof(struct A= TTR_NAME_ENTRY) + t16); -=C2=A0=C2=A0 =C2=A0} - -trace_attribute_table: +=C2=A0=C2=A0 =C2=A0if (rst->attr_names_len && oatbl) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0struct ATTR_NAME_ENTRY *ane =3D attr= _names; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0while (ane->off) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* TODO: Clear ta= ble on exit! */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0oe =3D Add2Ptr(oa= tbl, le16_to_cpu(ane->off)); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0t16 =3D le16_to_c= pu(ane->name_bytes); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0oe->name_len =3D = t16 / sizeof(short); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0oe->ptr =3D ane->= name; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0oe->is_attr_name = =3D 2; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ane =3D Add2Ptr(a= ne, +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 sizeof(struct ATTR_NAME_ENTRY) + t16); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} +=C2=A0=C2=A0 =C2=A0} + =C2=A0=C2=A0=C2=A0 =C2=A0/* =C2=A0=C2=A0=C2=A0 =C2=A0 * If the checkpt_lsn is zero, then this is a fre= shly =C2=A0=C2=A0=C2=A0 =C2=A0 * formatted disk and we have no work to do. @@ -5189,7 +5167,7 @@ int log_replay(struct ntfs_inode *ni, bool=20 *initialized) =C2=A0=C2=A0=C2=A0 =C2=A0kfree(oatbl); =C2=A0=C2=A0=C2=A0 =C2=A0kfree(dptbl); =C2=A0=C2=A0=C2=A0 =C2=A0kfree(attr_names); -=C2=A0=C2=A0 =C2=A0kfree(rst_info.r_page); +=C2=A0=C2=A0 =C2=A0kfree(log->rst_info.r_page); =C2=A0=C2=A0=C2=A0 =C2=A0kfree(ra); =C2=A0=C2=A0=C2=A0 =C2=A0kfree(log->one_page_buf); --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BE42AC4167B for ; Wed, 6 Dec 2023 15:12:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442406AbjLFPMD (ORCPT ); Wed, 6 Dec 2023 10:12:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379090AbjLFPMA (ORCPT ); Wed, 6 Dec 2023 10:12:00 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 52FF1C6; Wed, 6 Dec 2023 07:12:06 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 2AAFC2120; Wed, 6 Dec 2023 15:05:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875140; bh=KEnz3KTE1Z9/osOlDauLKgWtI6LdwFBhWwhEahHqNQo=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=ml0RcwIB/jbk6KHc50rd9/kLCglaBQgfFiOHbhazURkapxReFpC4vxnpvlYMS8nrP 58adYEG0RnhgyeLDEMwND0AqrD9TZFlz6HTNiuDEmvzUmC5+PXmjU2b3YGybT7p0QH p4lAjZYfowSTC2GQFaBSEjxTjNgDlilQX4n/rSpU= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:12:03 +0300 Message-ID: <7ae15d02-7745-4241-8b28-197eebbb6b7b@paragon-software.com> Date: Wed, 6 Dec 2023 18:12:03 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 07/16] fs/ntfs3: Fix multithreaded stress test Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/attrib.c | 21 ++++++++++++++------- =C2=A01 file changed, 14 insertions(+), 7 deletions(-) diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c index 63f70259edc0..4b78b669a3bd 100644 --- a/fs/ntfs3/attrib.c +++ b/fs/ntfs3/attrib.c @@ -886,7 +886,7 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST=20 vcn, CLST clen, CLST *lcn, =C2=A0=C2=A0=C2=A0 =C2=A0struct runs_tree *run =3D &ni->file.run; =C2=A0=C2=A0=C2=A0 =C2=A0struct ntfs_sb_info *sbi; =C2=A0=C2=A0=C2=A0 =C2=A0u8 cluster_bits; -=C2=A0=C2=A0 =C2=A0struct ATTRIB *attr =3D NULL, *attr_b; +=C2=A0=C2=A0 =C2=A0struct ATTRIB *attr, *attr_b; =C2=A0=C2=A0=C2=A0 =C2=A0struct ATTR_LIST_ENTRY *le, *le_b; =C2=A0=C2=A0=C2=A0 =C2=A0struct mft_inode *mi, *mi_b; =C2=A0=C2=A0=C2=A0 =C2=A0CLST hint, svcn, to_alloc, evcn1, next_svcn, asiz= e, end, vcn0, alen; @@ -904,12 +904,8 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST=20 vcn, CLST clen, CLST *lcn, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0*len =3D 0; =C2=A0=C2=A0=C2=A0 =C2=A0up_read(&ni->file.run_lock); -=C2=A0=C2=A0 =C2=A0if (*len) { -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (*lcn !=3D SPARSE_LCN || !new) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return 0; /* Fast= normal way without allocation. */ -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0else if (clen > *len) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0clen =3D *len; -=C2=A0=C2=A0 =C2=A0} +=C2=A0=C2=A0 =C2=A0if (*len && (*lcn !=3D SPARSE_LCN || !new)) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return 0; /* Fast normal way without= allocation. */ =C2=A0=C2=A0=C2=A0 =C2=A0/* No cluster in cache or we need to allocate clu= ster in hole. */ =C2=A0=C2=A0=C2=A0 =C2=A0sbi =3D ni->mi.sbi; @@ -918,6 +914,17 @@ int attr_data_get_block(struct ntfs_inode *ni, CLST=20 vcn, CLST clen, CLST *lcn, =C2=A0=C2=A0=C2=A0 =C2=A0ni_lock(ni); =C2=A0=C2=A0=C2=A0 =C2=A0down_write(&ni->file.run_lock); +=C2=A0=C2=A0 =C2=A0/* Repeat the code above (under write lock). */ +=C2=A0=C2=A0 =C2=A0if (!run_lookup_entry(run, vcn, lcn, len, NULL)) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0*len =3D 0; + +=C2=A0=C2=A0 =C2=A0if (*len) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (*lcn !=3D SPARSE_LCN || !new) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; /* norm= al way without allocation. */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (clen > *len) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0clen =3D *len; +=C2=A0=C2=A0 =C2=A0} + =C2=A0=C2=A0=C2=A0 =C2=A0le_b =3D NULL; =C2=A0=C2=A0=C2=A0 =C2=A0attr_b =3D ni_find_attr(ni, NULL, &le_b, ATTR_DAT= A, NULL, 0, NULL,=20 &mi_b); =C2=A0=C2=A0=C2=A0 =C2=A0if (!attr_b) { --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5520C4167B for ; Wed, 6 Dec 2023 15:12:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379092AbjLFPMb (ORCPT ); Wed, 6 Dec 2023 10:12:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46218 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379228AbjLFPM1 (ORCPT ); Wed, 6 Dec 2023 10:12:27 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5AACBD7F; Wed, 6 Dec 2023 07:12:26 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 0ECBE1E1A; Wed, 6 Dec 2023 15:06:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875160; bh=oUVQuELufd+5uJnO89HaHyCbduYubrq21BOGdkAjVXA=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=FOwzIfudC9bkRwbf6E0CtzufD/ejcjuSxV7Z5x/uEjKnx7LMxtYMRpGMY3a0f+Xj1 VTN9Wid82R80TU43j6P6Id0vICyjWksAudOq7xKWIgihy04fyxDrpW81CcbUOoqSiM 4rGdNcNiGvt9vbbsKkj/CzhrpECl0PL2b3/cdjq8= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:12:23 +0300 Message-ID: <61494224-68a8-431b-ba76-46b4812c241c@paragon-software.com> Date: Wed, 6 Dec 2023 18:12:23 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 08/16] fs/ntfs3: Fix detected field-spanning write (size 8) of single field "le->name" Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/ntfs.h | 2 +- =C2=A01 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ntfs3/ntfs.h b/fs/ntfs3/ntfs.h index 86aecbb01a92..13e96fc63dae 100644 --- a/fs/ntfs3/ntfs.h +++ b/fs/ntfs3/ntfs.h @@ -523,7 +523,7 @@ struct ATTR_LIST_ENTRY { =C2=A0=C2=A0=C2=A0 =C2=A0__le64 vcn;=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0= // 0x08: Starting VCN of this attribute. =C2=A0=C2=A0=C2=A0 =C2=A0struct MFT_REF ref;=C2=A0=C2=A0 =C2=A0// 0x10: MF= T record number with attribute. =C2=A0=C2=A0=C2=A0 =C2=A0__le16 id;=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/= / 0x18: struct ATTRIB ID. -=C2=A0=C2=A0 =C2=A0__le16 name[3];=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0//= 0x1A: Just to align. To get real name can=20 use bNameOffset. +=C2=A0=C2=A0 =C2=A0__le16 name[];=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0// = 0x1A: Just to align. To get real name can=20 use name_off. =C2=A0}; // sizeof(0x20) --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7AAC5C4167B for ; Wed, 6 Dec 2023 15:12:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442459AbjLFPMi (ORCPT ); Wed, 6 Dec 2023 10:12:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59142 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379090AbjLFPMg (ORCPT ); Wed, 6 Dec 2023 10:12:36 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92A799A; Wed, 6 Dec 2023 07:12:42 -0800 (PST) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 6CBA71E1A; Wed, 6 Dec 2023 15:06:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875176; bh=uNOivJvRpFbPgTjjVYSC1qoe7uSyIYuTw1rYbo9Hp0w=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=bj/RGX+6H/0ra5+wZHFHw7x8ZHxC4RWyNh6puOtIUKz5QvQUmsZ0xpgJCSi/3kgd8 CIsytNXKjsTuT5Mx61jzLyhwiQnJd83CIzQ/z1e9e85Gj6tRy0SUOh6XKrUueruEHx 18Yo98VSLGmUOGFrBa2t/w8+BTvfuN+wPVYQ0NHY= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id AF2152117; Wed, 6 Dec 2023 15:12:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875560; bh=uNOivJvRpFbPgTjjVYSC1qoe7uSyIYuTw1rYbo9Hp0w=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=EDu7HbCK/E19/EVWbQReaNUWjnJLDH4T6JYEPDGhrvSGr5wZUxVJQM4lhLYJD/t0W oR+i7ET+/BXRId+BZ8LmBGtxuI6ob1ldfPfm/VIOAwEHZKDQULAHXsEE6jT94qMOJ2 9BGkKHDpMtgzU6Cv1q/cZpWUFN0QVVDb06lPOESw= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:12:40 +0300 Message-ID: <29a1087c-c903-488c-993a-2e3c23c2d4d2@paragon-software.com> Date: Wed, 6 Dec 2023 18:12:40 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 09/16] fs/ntfs3: Correct use bh_read Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/file.c=C2=A0 | 19 +++++++++---------- =C2=A0fs/ntfs3/inode.c |=C2=A0 7 +++---- =C2=A02 files changed, 12 insertions(+), 14 deletions(-) diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index a5a30a24ce5d..5691f04e6751 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -188,6 +188,7 @@ static int ntfs_zero_range(struct inode *inode, u64=20 vbo, u64 vbo_to) =C2=A0=C2=A0=C2=A0 =C2=A0u32 bh_next, bh_off, to; =C2=A0=C2=A0=C2=A0 =C2=A0sector_t iblock; =C2=A0=C2=A0=C2=A0 =C2=A0struct folio *folio; +=C2=A0=C2=A0 =C2=A0bool dirty =3D false; =C2=A0=C2=A0=C2=A0 =C2=A0for (; idx < idx_end; idx +=3D 1, from =3D 0) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0page_off =3D (loff_t)idx << PA= GE_SHIFT; @@ -223,29 +224,27 @@ static int ntfs_zero_range(struct inode *inode,=20 u64 vbo, u64 vbo_to) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* Ok, it's= mapped. Make sure it's up-to-date. */ =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (folio_t= est_uptodate(folio)) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0set_buffer_uptodate(bh); - -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!buffer_uptod= ate(bh)) { -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0err =3D bh_read(bh, 0); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0if (err < 0) { -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0=C2=A0 =C2=A0folio_unlock(folio); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0=C2=A0 =C2=A0folio_put(folio); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0=C2=A0=C2=A0 =C2=A0goto out; -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0} +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0else if (bh_read(= bh, 0) < 0) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0err =3D -EIO; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0folio_unlock(folio); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0folio_put(folio); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0mark_buffer= _dirty(bh); - =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} while (bh_off =3D bh_next, i= block +=3D 1, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0 head !=3D = (bh =3D bh->b_this_page)); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0folio_zero_segment(folio, from= , to); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0dirty =3D true; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0folio_unlock(folio); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0folio_put(folio); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0cond_resched(); =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0out: -=C2=A0=C2=A0 =C2=A0mark_inode_dirty(inode); +=C2=A0=C2=A0 =C2=A0if (dirty) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0mark_inode_dirty(inode); =C2=A0=C2=A0=C2=A0 =C2=A0return err; =C2=A0} diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index fa6c7965473c..bba0208c4afd 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -345,9 +345,7 @@ static struct inode *ntfs_read_mft(struct inode *inode, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0inode->i_si= ze =3D le16_to_cpu(rp.SymbolicLinkReparseBuffer =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0= =C2=A0=C2=A0 .PrintNameLength) / =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 =C2=A0sizeof(u16); - =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ni->i_valid= =3D inode->i_size; - =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* Clear di= rectory bit. */ =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (ni->ni_= flags & NI_FLAG_DIR) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0indx_clear(&ni->dir); @@ -653,9 +651,10 @@ static noinline int ntfs_get_block_vbo(struct inode=20 *inode, u64 vbo, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0off =3D vbo= & (PAGE_SIZE - 1); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0folio_set_b= h(bh, folio, off); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D bh_read(b= h, 0); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (err < 0) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (bh_read(bh, 0= ) < 0) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0err =3D -EIO; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0goto out; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0folio_zero_= segment(folio, off + voff, off + block_size); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0} --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C1CCBC10DC1 for ; Wed, 6 Dec 2023 15:13:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442465AbjLFPM4 (ORCPT ); Wed, 6 Dec 2023 10:12:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39972 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379090AbjLFPMy (ORCPT ); Wed, 6 Dec 2023 10:12:54 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BAA0D44; Wed, 6 Dec 2023 07:13:00 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 346BF1E1A; Wed, 6 Dec 2023 15:06:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875194; bh=5WNxqIEiVf5xBesOyM4G/OuoGM3roOgonpEjUNzMoQc=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=SKOa+CHdhTDrT3JdA0I4GHvBuQyY1T0VvV9P7kGKydPxnb9m3t+8rtPN4g79s6Lwt nT3xoGGzTdH0XsfnMSCfZnc21q3dm8plyc7QvNSfcNOYeCRijRrabXr/Meqx8jTC9w xi4LFnvnnREfe4Bd80iBXzJ2WaMh/hFMKhNHYV+w= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:12:58 +0300 Message-ID: <3fbcb5a7-2b6f-44ae-8355-06461e7a1447@paragon-software.com> Date: Wed, 6 Dec 2023 18:12:58 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 10/16] fs/ntfs3: Add file_modified Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/file.c | 13 +++++++++++++ =C2=A01 file changed, 13 insertions(+) diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 5691f04e6751..bb80ce2eec2f 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -632,11 +632,17 @@ static long ntfs_fallocate(struct file *file, int=20 mode, loff_t vbo, loff_t len) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 &ni->file.run, i_size, &ni-= >i_valid, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 true, NULL); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ni_unlock(n= i); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (err) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} else if (new_size > i_size) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0inode->i_si= ze =3D new_size; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0} +=C2=A0=C2=A0 =C2=A0err =3D file_modified(file); +=C2=A0=C2=A0 =C2=A0if (err) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; + =C2=A0out: =C2=A0=C2=A0=C2=A0 =C2=A0if (map_locked) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0filemap_invalidate_unlock(mapp= ing); @@ -1040,6 +1046,7 @@ static ssize_t ntfs_file_write_iter(struct kiocb=20 *iocb, struct iov_iter *from) =C2=A0=C2=A0=C2=A0 =C2=A0struct address_space *mapping =3D file->f_mapping; =C2=A0=C2=A0=C2=A0 =C2=A0struct inode *inode =3D mapping->host; =C2=A0=C2=A0=C2=A0 =C2=A0ssize_t ret; +=C2=A0=C2=A0 =C2=A0int err; =C2=A0=C2=A0=C2=A0 =C2=A0struct ntfs_inode *ni =3D ntfs_i(inode); =C2=A0=C2=A0=C2=A0 =C2=A0if (is_encrypted(ni)) { @@ -1067,6 +1074,12 @@ static ssize_t ntfs_file_write_iter(struct kiocb=20 *iocb, struct iov_iter *from) =C2=A0=C2=A0=C2=A0 =C2=A0if (ret <=3D 0) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; +=C2=A0=C2=A0 =C2=A0err =3D file_modified(iocb->ki_filp); +=C2=A0=C2=A0 =C2=A0if (err) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ret =3D err; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; +=C2=A0=C2=A0 =C2=A0} + =C2=A0=C2=A0=C2=A0 =C2=A0if (WARN_ON(ni->ni_flags & NI_FLAG_COMPRESSED_MAS= K)) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* Should never be here, see n= tfs_file_open(). */ =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ret =3D -EOPNOTSUPP; --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CE64AC4167B for ; Wed, 6 Dec 2023 15:13:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442480AbjLFPNN (ORCPT ); Wed, 6 Dec 2023 10:13:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379228AbjLFPNL (ORCPT ); Wed, 6 Dec 2023 10:13:11 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF039DE; Wed, 6 Dec 2023 07:13:17 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 903201E1A; Wed, 6 Dec 2023 15:06:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875211; bh=F097v/jB8ZR21e/O3vd36dCK4gneA3BrFHtMeimQuV4=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=m3/oqph84dOfSvsyEUrnjup2sI052twZlQVgqAS6UOH+jafuQ1FPCmz6Fu7lGEQQi 2/82ZDbxioT09DRo45akAqbUhutD4t5bbxSm44sL5MnKUhvjmAyx/0IIaHypmgn1vm OEh6DBzuauAM8FnZ1RUItM5m01Y3W9cCWxkOJYF0= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:13:15 +0300 Message-ID: <89861d9e-f3a4-483d-b88d-4085dc2e0a8b@paragon-software.com> Date: Wed, 6 Dec 2023 18:13:15 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 11/16] fs/ntfs3: Drop suid and sgid bits as a part of fpunch Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/file.c | 9 +++++++++ =C2=A01 file changed, 9 insertions(+) diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index bb80ce2eec2f..0ff5d3af2889 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -498,10 +498,14 @@ static long ntfs_fallocate(struct file *file, int=20 mode, loff_t vbo, loff_t len) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ni_lock(ni); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D attr_punch_hole(ni, vb= o, len, &frame_size); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ni_unlock(ni); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!err) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto ok; + =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (err !=3D E_NTFS_NOTALIGNED) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* Process not aligned punch. = */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D 0; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0mask =3D frame_size - 1; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0vbo_a =3D (vbo + mask) & ~mask; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0end_a =3D end & ~mask; @@ -524,6 +528,8 @@ static long ntfs_fallocate(struct file *file, int=20 mode, loff_t vbo, loff_t len) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ni_lock(ni); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D att= r_punch_hole(ni, vbo_a, end_a - vbo_a, NULL); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ni_unlock(n= i); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (err) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0} else if (mode & FALLOC_FL_COLLAPSE_RANGE) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* @@ -563,6 +569,8 @@ static long ntfs_fallocate(struct file *file, int=20 mode, loff_t vbo, loff_t len) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ni_lock(ni); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D attr_insert_range(ni, = vbo, len); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ni_unlock(ni); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (err) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0} else { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* Check new size. */ =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0u8 cluster_bits =3D sbi->clust= er_bits; @@ -639,6 +647,7 @@ static long ntfs_fallocate(struct file *file, int=20 mode, loff_t vbo, loff_t len) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0} +ok: =C2=A0=C2=A0=C2=A0 =C2=A0err =3D file_modified(file); =C2=A0=C2=A0=C2=A0 =C2=A0if (err) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 410F8C4167B for ; Wed, 6 Dec 2023 15:13:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1379245AbjLFPNb (ORCPT ); Wed, 6 Dec 2023 10:13:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379228AbjLFPN3 (ORCPT ); Wed, 6 Dec 2023 10:13:29 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B797FD5E; Wed, 6 Dec 2023 07:13:34 -0800 (PST) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 8507D1E1A; Wed, 6 Dec 2023 15:07:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875228; bh=uJ8yXb35Y3nvlXGaUfbKb2hU6mLxvvg7KJ352HRIl1g=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=eDwoUKNxnC3Mgo5YqMg62nEwQlIzs9ZN6vkl1Oj/N6/RT0nvXp72F+JN+rfgOMvXZ foAWQKxkFIIu8YklSD8zsvXh7Y6NfK7Y2fLZ8YkDkPMmdNYLJax5arNk3jQiZY1W5r cPNFAPUzgIEbNaip/DtL7zgWlJgjCSwWstIw/ml0= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id C75A42117; Wed, 6 Dec 2023 15:13:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875612; bh=uJ8yXb35Y3nvlXGaUfbKb2hU6mLxvvg7KJ352HRIl1g=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=Ku8/RedgSWDEvC1aHorRRbeFaxRRq9RroNtmTSCrs4SWXGRQM6g37ggHj/tEIDN7b 3EUjBCU0mnJo9y1wgCDSBcr/wdKVNjL3KM0gP50TDKsOV84HDSDA9jUQFNyBmpKVpy Qr3UwRwAkk39i6GpMLxR/4D3cv1L7zyyfGVMbXNM= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:13:32 +0300 Message-ID: <4f013a0c-9f3f-4a4a-88fa-17460abd702e@paragon-software.com> Date: Wed, 6 Dec 2023 18:13:32 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 12/16] fs/ntfs3: Implement super_operations::shutdown Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/file.c=C2=A0=C2=A0=C2=A0 | 18 ++++++++++++++++++ =C2=A0fs/ntfs3/frecord.c |=C2=A0 3 +++ =C2=A0fs/ntfs3/inode.c=C2=A0=C2=A0 | 21 +++++++++++++++++++-- =C2=A0fs/ntfs3/namei.c=C2=A0=C2=A0 | 12 ++++++++++++ =C2=A0fs/ntfs3/ntfs_fs.h |=C2=A0 9 ++++++++- =C2=A0fs/ntfs3/super.c=C2=A0=C2=A0 | 12 ++++++++++++ =C2=A0fs/ntfs3/xattr.c=C2=A0=C2=A0 |=C2=A0 3 +++ =C2=A07 files changed, 75 insertions(+), 3 deletions(-) diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 0ff5d3af2889..07ed3d946e7c 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -260,6 +260,9 @@ static int ntfs_file_mmap(struct file *file, struct=20 vm_area_struct *vma) =C2=A0=C2=A0=C2=A0 =C2=A0bool rw =3D vma->vm_flags & VM_WRITE; =C2=A0=C2=A0=C2=A0 =C2=A0int err; +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(inode->i_sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0if (is_encrypted(ni)) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ntfs_inode_warn(inode, "mmap e= ncrypted not supported"); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EOPNOTSUPP; @@ -677,6 +680,9 @@ int ntfs3_setattr(struct mnt_idmap *idmap, struct=20 dentry *dentry, =C2=A0=C2=A0=C2=A0 =C2=A0umode_t mode =3D inode->i_mode; =C2=A0=C2=A0=C2=A0 =C2=A0int err; +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(inode->i_sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0err =3D setattr_prepare(idmap, dentry, attr); =C2=A0=C2=A0=C2=A0 =C2=A0if (err) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out; @@ -732,6 +738,9 @@ static ssize_t ntfs_file_read_iter(struct kiocb=20 *iocb, struct iov_iter *iter) =C2=A0=C2=A0=C2=A0 =C2=A0struct inode *inode =3D file->f_mapping->host; =C2=A0=C2=A0=C2=A0 =C2=A0struct ntfs_inode *ni =3D ntfs_i(inode); +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(inode->i_sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0if (is_encrypted(ni)) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ntfs_inode_warn(inode, "encryp= ted i/o not supported"); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EOPNOTSUPP; @@ -766,6 +775,9 @@ static ssize_t ntfs_file_splice_read(struct file=20 *in, loff_t *ppos, =C2=A0=C2=A0=C2=A0 =C2=A0struct inode *inode =3D in->f_mapping->host; =C2=A0=C2=A0=C2=A0 =C2=A0struct ntfs_inode *ni =3D ntfs_i(inode); +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(inode->i_sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0if (is_encrypted(ni)) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ntfs_inode_warn(inode, "encryp= ted i/o not supported"); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EOPNOTSUPP; @@ -1058,6 +1070,9 @@ static ssize_t ntfs_file_write_iter(struct kiocb=20 *iocb, struct iov_iter *from) =C2=A0=C2=A0=C2=A0 =C2=A0int err; =C2=A0=C2=A0=C2=A0 =C2=A0struct ntfs_inode *ni =3D ntfs_i(inode); +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(inode->i_sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0if (is_encrypted(ni)) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ntfs_inode_warn(inode, "encryp= ted i/o not supported"); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EOPNOTSUPP; @@ -1118,6 +1133,9 @@ int ntfs_file_open(struct inode *inode, struct=20 file *file) =C2=A0{ =C2=A0=C2=A0=C2=A0 =C2=A0struct ntfs_inode *ni =3D ntfs_i(inode); +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(inode->i_sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0if (unlikely((is_compressed(ni) || is_encrypted(n= i)) && =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 (file= ->f_flags & O_DIRECT))) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EOPNOTSUPP; diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c index 3df2d9e34b91..8744ba36d422 100644 --- a/fs/ntfs3/frecord.c +++ b/fs/ntfs3/frecord.c @@ -3259,6 +3259,9 @@ int ni_write_inode(struct inode *inode, int sync,=20 const char *hint) =C2=A0=C2=A0=C2=A0 =C2=A0if (is_bad_inode(inode) || sb_rdonly(sb)) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return 0; +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0if (!ni_trylock(ni)) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* 'ni' is under modification,= skip for now. */ =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0mark_inode_dirty_sync(inode); diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index bba0208c4afd..85452a6b1d40 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -852,9 +852,13 @@ static int ntfs_resident_writepage(struct folio *folio, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 struct writeback_control *wbc, void *data) =C2=A0{ =C2=A0=C2=A0=C2=A0 =C2=A0struct address_space *mapping =3D data; -=C2=A0=C2=A0 =C2=A0struct ntfs_inode *ni =3D ntfs_i(mapping->host); +=C2=A0=C2=A0 =C2=A0struct inode *inode =3D mapping->host; +=C2=A0=C2=A0 =C2=A0struct ntfs_inode *ni =3D ntfs_i(inode); =C2=A0=C2=A0=C2=A0 =C2=A0int ret; +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(inode->i_sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0ni_lock(ni); =C2=A0=C2=A0=C2=A0 =C2=A0ret =3D attr_data_write_resident(ni, &folio->page= ); =C2=A0=C2=A0=C2=A0 =C2=A0ni_unlock(ni); @@ -868,7 +872,12 @@ static int ntfs_resident_writepage(struct folio *folio, =C2=A0static int ntfs_writepages(struct address_space *mapping, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 struct writeback_control *wbc) =C2=A0{ -=C2=A0=C2=A0 =C2=A0if (is_resident(ntfs_i(mapping->host))) +=C2=A0=C2=A0 =C2=A0struct inode *inode =3D mapping->host; + +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(inode->i_sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + +=C2=A0=C2=A0 =C2=A0if (is_resident(ntfs_i(inode))) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return write_cache_pages(mappi= ng, wbc, ntfs_resident_writepage, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 =C2=A0 mapping); =C2=A0=C2=A0=C2=A0 =C2=A0return mpage_writepages(mapping, wbc, ntfs_get_bl= ock); @@ -888,6 +897,9 @@ int ntfs_write_begin(struct file *file, struct=20 address_space *mapping, =C2=A0=C2=A0=C2=A0 =C2=A0struct inode *inode =3D mapping->host; =C2=A0=C2=A0=C2=A0 =C2=A0struct ntfs_inode *ni =3D ntfs_i(inode); +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(inode->i_sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0*pagep =3D NULL; =C2=A0=C2=A0=C2=A0 =C2=A0if (is_resident(ni)) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0struct page *page =3D @@ -1305,6 +1317,11 @@ struct inode *ntfs_create_inode(struct mnt_idmap=20 *idmap, struct inode *dir, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out1; =C2=A0=C2=A0=C2=A0 =C2=A0} +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(sb))) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0err =3D -EIO; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0goto out2; +=C2=A0=C2=A0 =C2=A0} + =C2=A0=C2=A0=C2=A0 =C2=A0/* Mark rw ntfs as dirty. it will be cleared at u= mount. */ =C2=A0=C2=A0=C2=A0 =C2=A0ntfs_set_state(sbi, NTFS_DIRTY_DIRTY); diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c index ee3093be5170..cae41db0aaa7 100644 --- a/fs/ntfs3/namei.c +++ b/fs/ntfs3/namei.c @@ -181,6 +181,9 @@ static int ntfs_unlink(struct inode *dir, struct=20 dentry *dentry) =C2=A0=C2=A0=C2=A0 =C2=A0struct ntfs_inode *ni =3D ntfs_i(dir); =C2=A0=C2=A0=C2=A0 =C2=A0int err; +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(dir->i_sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0ni_lock_dir(ni); =C2=A0=C2=A0=C2=A0 =C2=A0err =3D ntfs_unlink_inode(dir, dentry); @@ -199,6 +202,9 @@ static int ntfs_symlink(struct mnt_idmap *idmap,=20 struct inode *dir, =C2=A0=C2=A0=C2=A0 =C2=A0u32 size =3D strlen(symname); =C2=A0=C2=A0=C2=A0 =C2=A0struct inode *inode; +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(dir->i_sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0inode =3D ntfs_create_inode(idmap, dir, dentry, N= ULL, S_IFLNK | 0777, 0, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0 symname, size, NULL); @@ -227,6 +233,9 @@ static int ntfs_rmdir(struct inode *dir, struct=20 dentry *dentry) =C2=A0=C2=A0=C2=A0 =C2=A0struct ntfs_inode *ni =3D ntfs_i(dir); =C2=A0=C2=A0=C2=A0 =C2=A0int err; +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(dir->i_sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0ni_lock_dir(ni); =C2=A0=C2=A0=C2=A0 =C2=A0err =3D ntfs_unlink_inode(dir, dentry); @@ -264,6 +273,9 @@ static int ntfs_rename(struct mnt_idmap *idmap,=20 struct inode *dir, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= 1024); =C2=A0=C2=A0=C2=A0 =C2=A0static_assert(PATH_MAX >=3D 4 * 1024); +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0if (flags & ~RENAME_NOREPLACE) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EINVAL; diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index f6706143d14b..d40bc7669ae5 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -61,6 +61,8 @@ enum utf16_endian; =C2=A0/* sbi->flags */ =C2=A0#define NTFS_FLAGS_NODISCARD=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A00x= 00000001 +/* ntfs in shutdown state. */ +#define NTFS_FLAGS_SHUTDOWN=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A00x00000002 =C2=A0/* Set when LogFile is replaying. */ =C2=A0#define NTFS_FLAGS_LOG_REPLAYING=C2=A0=C2=A0 =C2=A00x00000008 =C2=A0/* Set when we changed first MFT's which copy must be updated in=20 $MftMirr. */ @@ -226,7 +228,7 @@ struct ntfs_sb_info { =C2=A0=C2=A0=C2=A0 =C2=A0u64 maxbytes; // Maximum size for normal files. =C2=A0=C2=A0=C2=A0 =C2=A0u64 maxbytes_sparse; // Maximum size for sparse f= ile. -=C2=A0=C2=A0 =C2=A0u32 flags; // See NTFS_FLAGS_XXX. +=C2=A0=C2=A0 =C2=A0unsigned long flags; // See NTFS_FLAGS_ =C2=A0=C2=A0=C2=A0 =C2=A0CLST zone_max; // Maximum MFT zone length in clus= ters =C2=A0=C2=A0=C2=A0 =C2=A0CLST bad_clusters; // The count of marked bad clu= sters. @@ -999,6 +1001,11 @@ static inline struct ntfs_sb_info *ntfs_sb(struct=20 super_block *sb) =C2=A0=C2=A0=C2=A0 =C2=A0return sb->s_fs_info; =C2=A0} +static inline bool ntfs3_forced_shutdown(struct super_block *sb) +{ +=C2=A0=C2=A0 =C2=A0return test_bit(NTFS_FLAGS_SHUTDOWN, &ntfs_sb(sb)->flag= s); +} + =C2=A0/* =C2=A0 * ntfs_up_cluster - Align up on cluster boundary. =C2=A0 */ diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 09d61c6c90aa..af8521a6ed95 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -714,6 +714,14 @@ static int ntfs_show_options(struct seq_file *m,=20 struct dentry *root) =C2=A0=C2=A0=C2=A0 =C2=A0return 0; =C2=A0} +/* + * ntfs_shutdown - super_operations::shutdown + */ +static void ntfs_shutdown(struct super_block *sb) +{ +=C2=A0=C2=A0 =C2=A0set_bit(NTFS_FLAGS_SHUTDOWN, &ntfs_sb(sb)->flags); +} + =C2=A0/* =C2=A0 * ntfs_sync_fs - super_operations::sync_fs =C2=A0 */ @@ -724,6 +732,9 @@ static int ntfs_sync_fs(struct super_block *sb, int=20 wait) =C2=A0=C2=A0=C2=A0 =C2=A0struct ntfs_inode *ni; =C2=A0=C2=A0=C2=A0 =C2=A0struct inode *inode; +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0ni =3D sbi->security.ni; =C2=A0=C2=A0=C2=A0 =C2=A0if (ni) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0inode =3D &ni->vfs_inode; @@ -763,6 +774,7 @@ static const struct super_operations ntfs_sops =3D { =C2=A0=C2=A0=C2=A0 =C2=A0.put_super =3D ntfs_put_super, =C2=A0=C2=A0=C2=A0 =C2=A0.statfs =3D ntfs_statfs, =C2=A0=C2=A0=C2=A0 =C2=A0.show_options =3D ntfs_show_options, +=C2=A0=C2=A0 =C2=A0.shutdown =3D ntfs_shutdown, =C2=A0=C2=A0=C2=A0 =C2=A0.sync_fs =3D ntfs_sync_fs, =C2=A0=C2=A0=C2=A0 =C2=A0.write_inode =3D ntfs3_write_inode, =C2=A0}; diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c index 4274b6f31cfa..071356d096d8 100644 --- a/fs/ntfs3/xattr.c +++ b/fs/ntfs3/xattr.c @@ -744,6 +744,9 @@ static int ntfs_getxattr(const struct xattr_handler=20 *handler, struct dentry *de, =C2=A0=C2=A0=C2=A0 =C2=A0int err; =C2=A0=C2=A0=C2=A0 =C2=A0struct ntfs_inode *ni =3D ntfs_i(inode); +=C2=A0=C2=A0 =C2=A0if (unlikely(ntfs3_forced_shutdown(inode->i_sb))) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return -EIO; + =C2=A0=C2=A0=C2=A0 =C2=A0/* Dispatch request. */ =C2=A0=C2=A0=C2=A0 =C2=A0if (!strcmp(name, SYSTEM_DOS_ATTRIB)) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/* system.dos_attrib */ --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A2495C4167B for ; Wed, 6 Dec 2023 15:13:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442481AbjLFPNp (ORCPT ); Wed, 6 Dec 2023 10:13:45 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442472AbjLFPNn (ORCPT ); Wed, 6 Dec 2023 10:13:43 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FBC0B5; Wed, 6 Dec 2023 07:13:49 -0800 (PST) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 216141E1A; Wed, 6 Dec 2023 15:07:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875243; bh=CUZk88fabksVMQIwptkfOhP6XsgOcXbEpcc4odQSDSQ=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=NCK6bfmAVok0RLfrG2qNu60LQBlIyV8PnwhtGpjL8OHnbfVEi3NJ4VX370Q1e5hk3 HOzmdUxENLGFoCwvBzdk7CzHTnC0QkqbXH/Uig2v9kOtjc8kTdItbUuJFx9ZVhn1V6 awSW+hE0eS335PqIP4VtGv0WlMxfI8F7ZdrLM6YU= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id 64E4B2117; Wed, 6 Dec 2023 15:13:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875627; bh=CUZk88fabksVMQIwptkfOhP6XsgOcXbEpcc4odQSDSQ=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=cKTfILwvtBLLE19pwq14wyqj1avYe8W/4CiDi8l/6aJTt4VI1IVYevoAo22826ksJ ROfjf2aOvncNloeosyx2+MUuiP2wVYUZC88epJYNhDB5WBuYiKNKTKnqQBeu/gg51w R0UbWXrBWjm1M6WFpRGa90JZRnpvbf+JG4wMctg4= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:13:46 +0300 Message-ID: <6e9cc7e7-b29c-4d63-a73c-9aadd1589f18@paragon-software.com> Date: Wed, 6 Dec 2023 18:13:46 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 13/16] fs/ntfs3: ntfs3_forced_shutdown use int instead of bool Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/fsntfs.c=C2=A0 | 3 ++- =C2=A0fs/ntfs3/ntfs_fs.h | 6 +++--- =C2=A0fs/ntfs3/super.c=C2=A0=C2=A0 | 2 +- =C2=A03 files changed, 6 insertions(+), 5 deletions(-) diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index fbfe21dbb425..350461d8cece 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -853,7 +853,8 @@ void ntfs_update_mftmirr(struct ntfs_sb_info *sbi,=20 int wait) =C2=A0=C2=A0=C2=A0 =C2=A0/* =C2=A0=C2=A0=C2=A0 =C2=A0 * sb can be NULL here. In this case sbi->flags s= hould be 0 too. =C2=A0=C2=A0=C2=A0 =C2=A0 */ -=C2=A0=C2=A0 =C2=A0if (!sb || !(sbi->flags & NTFS_FLAGS_MFTMIRR)) +=C2=A0=C2=A0 =C2=A0if (!sb || !(sbi->flags & NTFS_FLAGS_MFTMIRR) || +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0 unlikely(ntfs3_forced_shutdown(sb))) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0return; =C2=A0=C2=A0=C2=A0 =C2=A0blocksize =3D sb->s_blocksize; diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index d40bc7669ae5..7510875efef6 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -62,7 +62,7 @@ enum utf16_endian; =C2=A0/* sbi->flags */ =C2=A0#define NTFS_FLAGS_NODISCARD=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A00x= 00000001 =C2=A0/* ntfs in shutdown state. */ -#define NTFS_FLAGS_SHUTDOWN=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A00x00000002 +#define NTFS_FLAGS_SHUTDOWN_BIT=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A00x000= 00002=C2=A0 /* =3D=3D 4*/ =C2=A0/* Set when LogFile is replaying. */ =C2=A0#define NTFS_FLAGS_LOG_REPLAYING=C2=A0=C2=A0 =C2=A00x00000008 =C2=A0/* Set when we changed first MFT's which copy must be updated in=20 $MftMirr. */ @@ -1001,9 +1001,9 @@ static inline struct ntfs_sb_info *ntfs_sb(struct=20 super_block *sb) =C2=A0=C2=A0=C2=A0 =C2=A0return sb->s_fs_info; =C2=A0} -static inline bool ntfs3_forced_shutdown(struct super_block *sb) +static inline int ntfs3_forced_shutdown(struct super_block *sb) =C2=A0{ -=C2=A0=C2=A0 =C2=A0return test_bit(NTFS_FLAGS_SHUTDOWN, &ntfs_sb(sb)->flag= s); +=C2=A0=C2=A0 =C2=A0return test_bit(NTFS_FLAGS_SHUTDOWN_BIT, &ntfs_sb(sb)->= flags); =C2=A0} =C2=A0/* diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index af8521a6ed95..65ef4b57411f 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -719,7 +719,7 @@ static int ntfs_show_options(struct seq_file *m,=20 struct dentry *root) =C2=A0 */ =C2=A0static void ntfs_shutdown(struct super_block *sb) =C2=A0{ -=C2=A0=C2=A0 =C2=A0set_bit(NTFS_FLAGS_SHUTDOWN, &ntfs_sb(sb)->flags); +=C2=A0=C2=A0 =C2=A0set_bit(NTFS_FLAGS_SHUTDOWN_BIT, &ntfs_sb(sb)->flags); =C2=A0} =C2=A0/* --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C5D2CC4167B for ; Wed, 6 Dec 2023 15:14:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442508AbjLFPOE (ORCPT ); Wed, 6 Dec 2023 10:14:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46164 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379228AbjLFPOC (ORCPT ); Wed, 6 Dec 2023 10:14:02 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31CCDD50; Wed, 6 Dec 2023 07:14:07 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 6E1C01E1A; Wed, 6 Dec 2023 15:07:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875261; bh=/4I47So9TsCFHrAhRoQV8zzXSeAqCb/39siaVWL+gX0=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=kN9J13WYKnTwM0/sOLGjGLDz5CC0z/k/AWpQjtIuyS78sqffL6F87LGiEKPYmwkL7 XsjaUGyF0vm3bNzJtlU1jEwm+8I+J8WbK9Qb1LZvwz2k8okN3eA6tNWNsW0vDDrybY zpr03m2YeMhs+FawFYMsmtMwLO398U/xikV1iWiY= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:14:05 +0300 Message-ID: <9cfeb726-0b6a-48bc-a640-435bcb6e359a@paragon-software.com> Date: Wed, 6 Dec 2023 18:14:05 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 14/16] fs/ntfs3: Add and fix comments Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/dir.c=C2=A0=C2=A0=C2=A0=C2=A0 | 4 +++- =C2=A0fs/ntfs3/fsntfs.c=C2=A0 | 2 +- =C2=A0fs/ntfs3/ntfs.h=C2=A0=C2=A0=C2=A0 | 2 +- =C2=A0fs/ntfs3/ntfs_fs.h | 2 +- =C2=A04 files changed, 6 insertions(+), 4 deletions(-) diff --git a/fs/ntfs3/dir.c b/fs/ntfs3/dir.c index 726122ecd39b..9f6dd445eb04 100644 --- a/fs/ntfs3/dir.c +++ b/fs/ntfs3/dir.c @@ -536,8 +536,10 @@ static int ntfs_dir_count(struct inode *dir, bool=20 *is_empty, size_t *dirs, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0e =3D Add2P= tr(hdr, off); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0e_size =3D = le16_to_cpu(e->size); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (e_size = < sizeof(struct NTFS_DE) || -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2= =A0 off + e_size > end) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2= =A0 off + e_size > end) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0/* Looks like corruption. */ =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0break; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (de_is_l= ast(e)) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0break; diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index 350461d8cece..321978019407 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -2129,8 +2129,8 @@ int ntfs_insert_security(struct ntfs_sb_info *sbi, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (le32_to= _cpu(d_security->size) =3D=3D new_sec_size && =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0=C2=A0 d_security->key.hash =3D=3D hash_key.hash && =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0=C2=A0 !memcmp(d_security + 1, sd, size_sd)) { -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0*security_id =3D d_security->key.sec_id; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0/* Such security already exists. */ +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0*security_id =3D d_security->key.sec_id; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0err =3D 0; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0goto out; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} diff --git a/fs/ntfs3/ntfs.h b/fs/ntfs3/ntfs.h index 13e96fc63dae..c8981429c721 100644 --- a/fs/ntfs3/ntfs.h +++ b/fs/ntfs3/ntfs.h @@ -523,7 +523,7 @@ struct ATTR_LIST_ENTRY { =C2=A0=C2=A0=C2=A0 =C2=A0__le64 vcn;=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0= // 0x08: Starting VCN of this attribute. =C2=A0=C2=A0=C2=A0 =C2=A0struct MFT_REF ref;=C2=A0=C2=A0 =C2=A0// 0x10: MF= T record number with attribute. =C2=A0=C2=A0=C2=A0 =C2=A0__le16 id;=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0/= / 0x18: struct ATTRIB ID. -=C2=A0=C2=A0 =C2=A0__le16 name[];=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0// = 0x1A: Just to align. To get real name can=20 use name_off. +=C2=A0=C2=A0 =C2=A0__le16 name[];=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0// = 0x1A: To get real name use name_off. =C2=A0}; // sizeof(0x20) diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 7510875efef6..abbc7182554a 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -874,7 +874,7 @@ int ntfs_init_acl(struct mnt_idmap *idmap, struct=20 inode *inode, =C2=A0int ntfs_acl_chmod(struct mnt_idmap *idmap, struct dentry *dentry); =C2=A0ssize_t ntfs_listxattr(struct dentry *dentry, char *buffer, size_t s= ize); -extern const struct xattr_handler * const ntfs_xattr_handlers[]; +extern const struct xattr_handler *const ntfs_xattr_handlers[]; =C2=A0int ntfs_save_wsl_perm(struct inode *inode, __le16 *ea_size); =C2=A0void ntfs_get_wsl_perm(struct inode *inode); --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E4644C4167B for ; Wed, 6 Dec 2023 15:14:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442539AbjLFPOX (ORCPT ); Wed, 6 Dec 2023 10:14:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59860 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1442535AbjLFPOV (ORCPT ); Wed, 6 Dec 2023 10:14:21 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 08B67112; Wed, 6 Dec 2023 07:14:26 -0800 (PST) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id E6D181D0B; Wed, 6 Dec 2023 15:08:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875280; bh=W/TNdgmKDqNDYIi7mUSo5ayyxeI6Wi55D54a4MJS5O8=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=uB7SJ5ZV34Sc6PLOrZBUBpCENFmPGqlFtRZvqJoH9vKlKM7YeJH4IMKAHPy9I9iEa ejo/mhQFbObUfY7QSS46h7IJ+xwplvgdoZFTxSFtWgAmYnNnVdXzTJPHQhaaWOBNo5 SWLDXhH3caMbQcpe06yX7DO97jt+0K3UDKKUucwE= Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayfre-01.paragon-software.com (Postfix) with ESMTPS id 32A922117; Wed, 6 Dec 2023 15:14:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875665; bh=W/TNdgmKDqNDYIi7mUSo5ayyxeI6Wi55D54a4MJS5O8=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=HwerjDqSLEHZuqFn+zzPuEhCBWA0uFcD4nADai1942YJ983cNo0j/pryidiex2rWP H0uuBaQ306w3AFnBoJcJRFcIIK8vQDQuWbmPIeusCe3s3FXdqFM+hDeHsYQD0L0g+x O29n04DNf2rqk9XpwAgCpKfKdguOdnw9nTpi3aCo= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:14:24 +0300 Message-ID: Date: Wed, 6 Dec 2023 18:14:24 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 15/16] fs/ntfs3: Add NULL ptr dereference checking at the end of attr_allocate_frame() Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org It is preferable to exit through the out: label because internal debugging functions are located there. Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/attrib.c | 20 ++++++++++++-------- =C2=A01 file changed, 12 insertions(+), 8 deletions(-) diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c index 4b78b669a3bd..646e2dad1b75 100644 --- a/fs/ntfs3/attrib.c +++ b/fs/ntfs3/attrib.c @@ -1743,8 +1743,10 @@ int attr_allocate_frame(struct ntfs_inode *ni,=20 CLST frame, size_t compr_size, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0le_b =3D NU= LL; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0attr_b =3D = ni_find_attr(ni, NULL, &le_b, ATTR_DATA, NULL, =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2= =A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 0, NULL, &mi_b); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!attr_b) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0return -ENOENT; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (!attr_b) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0err =3D -ENOENT; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2= =A0goto out; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0attr =3D at= tr_b; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0le =3D le_b; @@ -1825,13 +1827,15 @@ int attr_allocate_frame(struct ntfs_inode *ni,=20 CLST frame, size_t compr_size, =C2=A0ok: =C2=A0=C2=A0=C2=A0 =C2=A0run_truncate_around(run, vcn); =C2=A0out: -=C2=A0=C2=A0 =C2=A0if (new_valid > data_size) -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0new_valid =3D data_size; +=C2=A0=C2=A0 =C2=A0if (attr_b) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (new_valid > data_size) +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0new_valid =3D dat= a_size; -=C2=A0=C2=A0 =C2=A0valid_size =3D le64_to_cpu(attr_b->nres.valid_size); -=C2=A0=C2=A0 =C2=A0if (new_valid !=3D valid_size) { -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0attr_b->nres.valid_size =3D cpu_to_l= e64(valid_size); -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0mi_b->dirty =3D true; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0valid_size =3D le64_to_cpu(attr_b->n= res.valid_size); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (new_valid !=3D valid_size) { +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0attr_b->nres.vali= d_size =3D cpu_to_le64(valid_size); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0mi_b->dirty =3D t= rue; +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0} =C2=A0=C2=A0=C2=A0 =C2=A0return err; --=20 2.34.1 From nobody Thu Sep 11 22:15:40 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10224C10DC1 for ; Wed, 6 Dec 2023 15:15:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1442537AbjLFPOz (ORCPT ); Wed, 6 Dec 2023 10:14:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56028 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1379260AbjLFPOw (ORCPT ); Wed, 6 Dec 2023 10:14:52 -0500 Received: from relayaws-01.paragon-software.com (relayaws-01.paragon-software.com [35.157.23.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 07BE51707; Wed, 6 Dec 2023 07:14:48 -0800 (PST) Received: from dlg2.mail.paragon-software.com (vdlg-exch-02.paragon-software.com [172.30.1.105]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 860301D0B; Wed, 6 Dec 2023 15:08:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1701875302; bh=nuQ7oyEDVSuk9DOyuMG/cLB7BA1E7v6X/Af9iud7LTk=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=b9ns4krgsqsEKFEpkwSUxPt90w7J8llYZPi9MyON8+FjGR7kqRSI3r83ZLpiL8lua ljtibIPMsXBzU9i7KmTZE+TYjrZbhXEUlTTPX1RmZnUNPjnPkSSmcbBBJ+/dCgQp0e QeHhsteLuAYXMv33bEAa0QG5/Ze27T+lmW+bHQoM= Received: from [172.16.192.129] (192.168.211.144) by vdlg-exch-02.paragon-software.com (172.30.1.105) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.7; Wed, 6 Dec 2023 18:14:46 +0300 Message-ID: <8babdfbc-5be7-428d-9c23-ca8ed66f7ec5@paragon-software.com> Date: Wed, 6 Dec 2023 18:14:46 +0300 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: [PATCH 16/16] fs/ntfs3: Fix c/mtime typo Content-Language: en-US From: Konstantin Komarovc To: CC: , References: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> In-Reply-To: <00fd1558-fda5-421b-be43-7de69e32cb4e@paragon-software.com> Content-Type: text/plain; charset="utf-8"; format="flowed" Content-Transfer-Encoding: quoted-printable X-Originating-IP: [192.168.211.144] X-ClientProxiedBy: vobn-exch-01.paragon-software.com (172.30.72.13) To vdlg-exch-02.paragon-software.com (172.30.1.105) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Signed-off-by: Konstantin Komarov --- =C2=A0fs/ntfs3/frecord.c | 2 +- =C2=A01 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c index 8744ba36d422..6ff4f70ba077 100644 --- a/fs/ntfs3/frecord.c +++ b/fs/ntfs3/frecord.c @@ -3291,7 +3291,7 @@ int ni_write_inode(struct inode *inode, int sync,=20 const char *hint) =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0modified = =3D true; =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0} -=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ts =3D inode_get_mtime(inode); +=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0ts =3D inode_get_ctime(inode); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0dup.c_time =3D kernel2nt(&ts); =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0if (std->c_time !=3D dup.c_tim= e) { =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0=C2=A0=C2=A0 =C2=A0std->c_time= =3D dup.c_time; --=20 2.34.1