From patchwork Wed Feb 15 13:34:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 57569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp202714wrn; Wed, 15 Feb 2023 05:55:29 -0800 (PST) X-Google-Smtp-Source: AK7set8B5o5pRhGsx3zf9SK0KfxPwwaLNw4WM9nJBwFFesp6nvK623+mBHu0VppdrQxZYFGqZPNt X-Received: by 2002:a05:6402:180f:b0:4ac:be53:1789 with SMTP id g15-20020a056402180f00b004acbe531789mr2090481edy.40.1676469329153; Wed, 15 Feb 2023 05:55:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676469329; cv=none; d=google.com; s=arc-20160816; b=sio9hyLYNivTPdvJd9QBzWHY7ipZfUAP8BvxXh+BO6aXFepzK/5zizat070Y9qqwAy 7pfEa8cChlgyM1vSikHfgafwv4VS+ubyP/OqVNfJHSzSweuDNuJTLhSGY2bgPkc6X9dh WThoI3lkO9SuapFnH2BYbraWlYSuJUkpsaoeWLEN7L+r7eoM9SNnUKNnCKRvHUv1Yze3 DJP5m2qYGp2IktU27i4ySZ+wQ72Ok6C9Zjw4GbwOaiAcoPBmtDOz8wZ+oKPmg6Fis5hH OJKizqmnMkYROT4tJsfO0QC/iItsLtrZXUdv/cYtWmL3Q/lrlShOH3reYUjNQdu3HWRq TZbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature; bh=ERksTfD1/XuhpX5Xy+AmdTxEr0QconrM00RyDm/UdXY=; b=ItLDFElodaI0SzdMD4mP0TN3UPX21fiwG6TOd8VArLTSzKD4bkE7a6VoiYst70XCPu GyK/xPzrliWsxcl5C5OCG/TlnU7+1t/vE3B5G+mDRSOc53PwEhuZh5ihYUTY1EX6Bvjz fsheIK57zf6AgJWNWfUQH8+rnpzsmjuE3G8J6qoAEaW4947Ku/zWXJEK+C2rj22aB1Wn Iw1h5uklBB6gCsVvt+TDm4d3rrVZAEiTE/tqxACuzCjquuH8Od/BMN3yiteSIZNB5D3g WfC5FHybUV9NfmPMQP9rFSzzYZDmuQV/qeMsWbif8anR38pSJ2RX6pB4zPWgbARo366n 2Qew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=g1u1V3iN; dkim=pass header.i=@paragon-software.com header.s=mail header.b=AsdxIAg+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o7-20020aa7dd47000000b0049e420baaeesi20742161edw.470.2023.02.15.05.55.05; Wed, 15 Feb 2023 05:55:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=g1u1V3iN; dkim=pass header.i=@paragon-software.com header.s=mail header.b=AsdxIAg+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229841AbjBONlR (ORCPT + 99 others); Wed, 15 Feb 2023 08:41:17 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59014 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229576AbjBONlM (ORCPT ); Wed, 15 Feb 2023 08:41:12 -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 42B4B392B4; Wed, 15 Feb 2023 05:41:09 -0800 (PST) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 93C162120; Wed, 15 Feb 2023 13:30:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676467804; bh=ERksTfD1/XuhpX5Xy+AmdTxEr0QconrM00RyDm/UdXY=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=g1u1V3iNHInPiICLDPOXbO+m0D/AjSraShkh5o+Gdxcb5hXxGKb1W5vFsOyEzfZ63 idhN4dsDVU1iRW8pwpS4vKgsltLnpXdE2yZ/HPC6oqlNewjdozg0ytl0XXgGIaRtit UvoDHMb5JT/NYn5rIBwytEXTZGVgUPDby8exVw+g= 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 DBFA11E70; Wed, 15 Feb 2023 13:34:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676468054; bh=ERksTfD1/XuhpX5Xy+AmdTxEr0QconrM00RyDm/UdXY=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=AsdxIAg+F0mmU8xLtS285CIFiOgbi3Nq0/LFvbkT5/t6Sy4eQqmwp5I2wwqNCnBZm SYlMbIl9H+ZO9k382nRanwhucO7DIZKhyoSGndWseJweTTlazsCD+695oMhADOFMR0 35UyY0KUgxcWRkGL+zb9MBIpskCfEICBkHKzwQVc= Received: from [192.168.211.36] (192.168.211.36) 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, 15 Feb 2023 16:34:14 +0300 Message-ID: <878105e3-d075-4d4e-5c47-3f22f95e23c8@paragon-software.com> Date: Wed, 15 Feb 2023 17:34:13 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: [PATCH 01/11] fs/ntfs3: Use bh_read to simplify code Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.36] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757905503158778230?= X-GMAIL-MSGID: =?utf-8?q?1757905503158778230?= The duplicating code is replaced by a generic function bh_read() Signed-off-by: Konstantin Komarov ---  fs/ntfs3/file.c  | 10 ++--------  fs/ntfs3/inode.c |  1 +  2 files changed, 3 insertions(+), 8 deletions(-)                  goto out; diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index d294cd975688..d37df7376543 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -223,16 +223,10 @@ static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to)                  set_buffer_uptodate(bh);              if (!buffer_uptodate(bh)) { -                lock_buffer(bh); -                bh->b_end_io = end_buffer_read_sync; -                get_bh(bh); -                submit_bh(REQ_OP_READ, bh); - -                wait_on_buffer(bh); -                if (!buffer_uptodate(bh)) { +                err = bh_read(bh, 0); +                if (err < 0) {                      unlock_page(page);                      put_page(page); -                    err = -EIO;                      goto out;                  }              } diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index e80e94325467..5e06299591ed 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -648,6 +648,7 @@ static noinline int ntfs_get_block_vbo(struct inode *inode, u64 vbo,              bh->b_size = block_size;              off = vbo & (PAGE_SIZE - 1);              set_bh_page(bh, page, off); +              err = bh_read(bh, 0);              if (err < 0) From patchwork Wed Feb 15 13:34:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 57553 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp198700wrn; Wed, 15 Feb 2023 05:46:40 -0800 (PST) X-Google-Smtp-Source: AK7set+tcF229tWD0ZIIl2I4xBsR81BJbf0Lq0TZS8fK8Vi2CXNYqvJ7Kfx1BnOIXxRv+6I0lbiv X-Received: by 2002:a17:90b:3148:b0:234:d1c:f112 with SMTP id ip8-20020a17090b314800b002340d1cf112mr2979775pjb.0.1676468800338; Wed, 15 Feb 2023 05:46:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676468800; cv=none; d=google.com; s=arc-20160816; b=aJDi+s3SOpNWsfR3BJl/Ek2h5CZjT9fqnrKY3pVEaduOA5LC4GLi5KIyz8bKW47oez uSHqPysioM1Cu00saWp9Yf03ezZArsVL2FkhqldCwwXbW9jDZKROjSDGCX7nCsUUwkU/ AAMTz/5UFWpUszdn38spUh9BdsbZAoGz/ctAjCss3MkKinTA/VgImYO96zFF7SF/jw4/ v5ipVe0eZ3Nx31vVrEw6V6YiGklmyTDJyXuy6gm9lBpKrM3nfshwM/VBN/tbA3G3j5mm LZFp4dHbToB6SvLS/FI+vDdS6dzbXpl8QA7Cp+Sz1b9XQxadz9Exl/hjxxv1m1tGAjWy eAgg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=cRbFAcsOeNInjJ/7aNI+flXOVb7jAlQp1y5wkLFBBeE=; b=aijyRpTe3cHMAWxwF5/Erho0t9Yt86u1jsb1jFV9t/ZF7VBD+3gHDe8SFFbO2SflES zOT4bDbdSsvecGUxAssIC2Z20ynNMoyoUadVzNpXS5SFsOe3cXY7k62YS+fNUC9wTJhL DoSYveSoBVHrAVssCv0UH69JwBn0fB+tTS7P2s2dIpgz+rHMDjz7jyDj/AABnL8aB8Tl eARxyfjfQbJnPh+bX+ZQZ7VedVD2olrbKzAvqVMFHHlpAw+i3cRMFfPNRFSagKUOjTmD CHstjmzUQv4FotOpwVqivS+Uarm0N0V7E4wscxd9cGL4VA5ihdGhbSkwy9MzK1fwTSz8 Z8pQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=SM6lEK6R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l11-20020a17090aec0b00b0022c2d541c38si1852122pjy.100.2023.02.15.05.46.27; Wed, 15 Feb 2023 05:46:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=SM6lEK6R; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229496AbjBONfF (ORCPT + 99 others); Wed, 15 Feb 2023 08:35:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52170 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231687AbjBONe6 (ORCPT ); Wed, 15 Feb 2023 08:34:58 -0500 X-Greylist: delayed 85 seconds by postgrey-1.37 at lindbergh.monkeyblade.net; Wed, 15 Feb 2023 05:34:56 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 A06B23A92; Wed, 15 Feb 2023 05:34:56 -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 565C72147; Wed, 15 Feb 2023 13:30:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676467844; bh=cRbFAcsOeNInjJ/7aNI+flXOVb7jAlQp1y5wkLFBBeE=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=SM6lEK6RBNg0roCsqmraz/E86Mlrmp5zFPFxVPk0W/vslDtU9jZTljAGe7xmvMu+5 v1G2ot0abrwTUAkmqgKxwJFZ/H1/WR0aoseMoZ5BaG9ihYD3xc6ZTJHmVmadoXf2yf 7PEKU5DxGSPdCOEUuuyZ2jkUn4eeuqi7e4njZBeA= Received: from [192.168.211.36] (192.168.211.36) 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, 15 Feb 2023 16:34:54 +0300 Message-ID: <331371f5-6c34-65aa-f81e-c27e428b9d4e@paragon-software.com> Date: Wed, 15 Feb 2023 17:34:53 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: [PATCH 02/11] fs/ntfs3: Remove noacsrules Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.36] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757904948623875628?= X-GMAIL-MSGID: =?utf-8?q?1757904948623875628?= Currently, this option does not work properly. Its use leads to unstable results. If we figure out how to implement it without errors, we will add it later. Signed-off-by: Konstantin Komarov ---  Documentation/filesystems/ntfs3.rst | 11 -----------  fs/ntfs3/file.c                     | 11 -----------  fs/ntfs3/inode.c                    |  1 -  fs/ntfs3/namei.c                    |  1 -  fs/ntfs3/ntfs_fs.h                  |  3 ---  fs/ntfs3/super.c                    |  9 +--------  fs/ntfs3/xattr.c                    | 14 --------------  7 files changed, 1 insertion(+), 49 deletions(-)   */ diff --git a/Documentation/filesystems/ntfs3.rst b/Documentation/filesystems/ntfs3.rst index 5aa102bd72c2..f0cf05cad2ba 100644 --- a/Documentation/filesystems/ntfs3.rst +++ b/Documentation/filesystems/ntfs3.rst @@ -61,17 +61,6 @@ this table marked with no it means default is without **no**.         directories, fmask applies only to files and dmask only to directories.     * - fmask= -   * - noacsrules -     - "No access rules" mount option sets access rights for files/folders to -       777 and owner/group to root. This mount option absorbs all other -       permissions. - -       - Permissions change for files/folders will be reported as successful, -     but they will remain 777. - -       - Owner/group change will be reported as successful, butthey will stay -     as root. -     * - nohidden       - Files with the Windows-specific HIDDEN (FILE_ATTRIBUTE_HIDDEN) attribute         will not be shown under Linux. diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index d37df7376543..9cef189fc0c5 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -654,22 +654,12 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)  int ntfs3_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,            struct iattr *attr)  { -    struct super_block *sb = dentry->d_sb; -    struct ntfs_sb_info *sbi = sb->s_fs_info;      struct inode *inode = d_inode(dentry);      struct ntfs_inode *ni = ntfs_i(inode);      u32 ia_valid = attr->ia_valid;      umode_t mode = inode->i_mode;      int err; -    if (sbi->options->noacsrules) { -        /* "No access rules" - Force any changes of time etc. */ -        attr->ia_valid |= ATTR_FORCE; -        /* and disable for editing some attributes. */ -        attr->ia_valid &= ~(ATTR_UID | ATTR_GID | ATTR_MODE); -        ia_valid = attr->ia_valid; -    } -      err = setattr_prepare(mnt_userns, dentry, attr);      if (err)          goto out; @@ -1153,7 +1143,6 @@ const struct inode_operations ntfs_file_inode_operations = {      .getattr    = ntfs_getattr,      .setattr    = ntfs3_setattr,      .listxattr    = ntfs_listxattr, -    .permission    = ntfs_permission,      .get_inode_acl    = ntfs_get_acl,      .set_acl    = ntfs_set_acl,      .fiemap        = ntfs_fiemap, diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 5e06299591ed..51e342ad79fd 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -2070,7 +2070,6 @@ const struct inode_operations ntfs_link_inode_operations = {      .get_link    = ntfs_get_link,      .setattr    = ntfs3_setattr,      .listxattr    = ntfs_listxattr, -    .permission    = ntfs_permission,  };  const struct address_space_operations ntfs_aops = { diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c index 53ddea219e37..5d5fe2f1f77c 100644 --- a/fs/ntfs3/namei.c +++ b/fs/ntfs3/namei.c @@ -607,7 +607,6 @@ const struct inode_operations ntfs_dir_inode_operations = {      .rmdir        = ntfs_rmdir,      .mknod        = ntfs_mknod,      .rename        = ntfs_rename, -    .permission    = ntfs_permission,      .get_inode_acl    = ntfs_get_acl,      .set_acl    = ntfs_set_acl,      .setattr    = ntfs3_setattr, diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 2050eb3f6a5a..556b76f526cb 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -100,7 +100,6 @@ struct ntfs_mount_options {      unsigned hide_dot_files : 1; /* Set hidden flag on dot files. */      unsigned windows_names : 1; /* Disallow names forbidden by Windows. */      unsigned force : 1; /* RW mount dirty volume. */ -    unsigned noacsrules : 1; /* Exclude acs rules. */      unsigned prealloc : 1; /* Preallocate space when file is growing. */      unsigned nocase : 1; /* case insensitive. */  }; @@ -868,8 +867,6 @@ int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode,  #endif  int ntfs_acl_chmod(struct user_namespace *mnt_userns, struct dentry *dentry); -int ntfs_permission(struct user_namespace *mnt_userns, struct inode *inode, -            int mask);  ssize_t ntfs_listxattr(struct dentry *dentry, char *buffer, size_t size);  extern const struct xattr_handler *ntfs_xattr_handlers[]; diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 19d0889b131f..10c019ef7da3 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -253,7 +253,6 @@ enum Opt {      Opt_acl,      Opt_iocharset,      Opt_prealloc, -    Opt_noacsrules,      Opt_nocase,      Opt_err,  }; @@ -274,7 +273,6 @@ static const struct fs_parameter_spec ntfs_fs_parameters[] = {      fsparam_flag_no("acl",            Opt_acl),      fsparam_flag_no("showmeta",        Opt_showmeta),      fsparam_flag_no("prealloc",        Opt_prealloc), -    fsparam_flag_no("acsrules",        Opt_noacsrules),      fsparam_flag_no("nocase",        Opt_nocase),      fsparam_string("iocharset",        Opt_iocharset),      {} @@ -387,9 +385,6 @@ static int ntfs_fs_parse_param(struct fs_context *fc,      case Opt_prealloc:          opts->prealloc = result.negated ? 0 : 1;          break; -    case Opt_noacsrules: -        opts->noacsrules = result.negated ? 1 : 0; -        break;      case Opt_nocase:          opts->nocase = result.negated ? 1 : 0;          break; @@ -572,8 +567,6 @@ static int ntfs_show_options(struct seq_file *m, struct dentry *root)          seq_puts(m, ",hide_dot_files");      if (opts->force)          seq_puts(m, ",force"); -    if (opts->noacsrules) -        seq_puts(m, ",noacsrules");      if (opts->prealloc)          seq_puts(m, ",prealloc");      if (sb->s_flags & SB_POSIXACL) @@ -791,7 +784,7 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,      if (boot_sector_size != sector_size) {          ntfs_warn(              sb, -            "Different NTFS' sector size (%u) and media sector size (%u)", +            "Different NTFS sector size (%u) and media sector size (%u)",              boot_sector_size, sector_size);          dev_size += sector_size - 1;      } diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c index 3fa48c8f68d9..c42fbc56eb39 100644 --- a/fs/ntfs3/xattr.c +++ b/fs/ntfs3/xattr.c @@ -711,20 +711,6 @@ int ntfs_acl_chmod(struct user_namespace *mnt_userns, struct dentry *dentry)      return posix_acl_chmod(mnt_userns, dentry, inode->i_mode);  } -/* - * ntfs_permission - inode_operations::permission - */ -int ntfs_permission(struct user_namespace *mnt_userns, struct inode *inode, -            int mask) -{ -    if (ntfs_sb(inode->i_sb)->options->noacsrules) { -        /* "No access rules" mode - Allow all changes. */ -        return 0; -    } - -    return generic_permission(mnt_userns, inode, mask); -} -  /*   * ntfs_listxattr - inode_operations::listxattr From patchwork Wed Feb 15 13:35:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 57555 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp200851wrn; Wed, 15 Feb 2023 05:51:20 -0800 (PST) X-Google-Smtp-Source: AK7set9Ktdj1Mm3usgkNVJLUBpXDyI57mId5uFkiJIksrhUQLejnZ/QromcDdWah2uW3Zm0nL0bX X-Received: by 2002:a17:907:2054:b0:878:7530:5303 with SMTP id pg20-20020a170907205400b0087875305303mr2632582ejb.5.1676469080088; Wed, 15 Feb 2023 05:51:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676469080; cv=none; d=google.com; s=arc-20160816; b=ONq8vi4LhWTL1ztXqS5Sd/6prtQDlkJJXvyS6+qlvMcrnn4YMFbOoD9YYyaxg0BtQy lX5PUwsn4Nv7cDfKgr4J9RlsjpXDcF63XtzNEeIKaBAO8mLKBwXLvIzUBEm3FyzKqd5O iH8QUqYaBZyF+qwE0rKpfDLJOGxYjEM/ffpq2x7Rg7unvTv/Wnzvb3JA1sMcPkKgV5IW zk4JT4a2jJNxyLzTl75daRAHvo7RbFYsxgRhX4pUhU8dctEr+Uqm7fTwQxxjHEp0Rohg YzRWIKsZRIi69EKa86kPwH26kfwsx9xo+CIU0ydxda6CO/I+I0qg62NvMLI2Nmjm46QR tLrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature; bh=9YwbKHsq6zCe7UxAvvfw0U9eC4NOBc0GrYuoyaOiRsg=; b=bqBNQoHrQDJQUGzXvTuhmIDSU9kZQbtNdNJP7qyfgcm0azlS1ygiCqfOij6bdzJpMk K9kefNj10826ONXIGie1ESOqo9YI0Uygqe7WhYS8WBbUMyQ4a1C+NNZ83venWAihpWav Z5LPYhXlMRtrhFzHm3wb7Pg40cNgc2PYl5zRYxLAF/5Ie7MbLPZB08zm/U7DKkenvKdp +LfNHVpoTDWsDldz73TDsdfZuINJNjFkV+zmGyU/Q8vmNiTVeLdh2R9mf+9OsB5UDJzZ ttdxUqEgqyDRbhC22MdfaT9qg6/VH3wJEo2NUl/OpmDoRg3db1HWxaXqzlF00noITow6 9wMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=DCV2Dvw8; dkim=pass header.i=@paragon-software.com header.s=mail header.b=A5o+lDts; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wl17-20020a170907311100b008b12b7abf5csi5798488ejb.593.2023.02.15.05.50.32; Wed, 15 Feb 2023 05:51:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=DCV2Dvw8; dkim=pass header.i=@paragon-software.com header.s=mail header.b=A5o+lDts; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229765AbjBONfr (ORCPT + 99 others); Wed, 15 Feb 2023 08:35:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbjBONfp (ORCPT ); Wed, 15 Feb 2023 08:35:45 -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 3343C358D; Wed, 15 Feb 2023 05:35:41 -0800 (PST) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id E50212147; Wed, 15 Feb 2023 13:31:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676467889; bh=9YwbKHsq6zCe7UxAvvfw0U9eC4NOBc0GrYuoyaOiRsg=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=DCV2Dvw82s3o6RFPyqyYN0Tnm6u8pD6i3IJSiPZUUIXT3hcm7S3DQEb9Y1bzjjcdz LCThTW9xJt3J468JQtSS21GJ/DKuAXcBOajsvy3AOPGr7R26wX/Jihnc3ykI3Dk2O2 99JLC3TidCsoz1mdujuofcMB4u0gn/FUe5KzlJzQ= 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 4284E1E70; Wed, 15 Feb 2023 13:35:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676468139; bh=9YwbKHsq6zCe7UxAvvfw0U9eC4NOBc0GrYuoyaOiRsg=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=A5o+lDtsQrQ0900S8R3zH3VMIsH9utchJww8A5uyU3NI92M6w0w1nnJpraji5665l +Z8SdrIKWlLBh3fU5Zha0/t3ltjjYuvPyNEaExoUgGanC+ybbCMD1xiIclZaxeAvgR 6GfjVL/y9spCDnHctON3r7vcp9dfCP6QY6jN3GvU= Received: from [192.168.211.36] (192.168.211.36) 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, 15 Feb 2023 16:35:38 +0300 Message-ID: Date: Wed, 15 Feb 2023 17:35:37 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: [PATCH 03/11] fs/ntfs3: Fix ntfs_create_inode() Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.36] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757905242208975187?= X-GMAIL-MSGID: =?utf-8?q?1757905242208975187?= Previous variant creates an inode that requires update the parent directory (ea_packed_size). Operations in ntfs_create_inode have been rearranged so we insert new directory entry with correct ea_packed_size and new created inode does not require update it's parent directory. Signed-off-by: Konstantin Komarov ---  fs/ntfs3/file.c    |  2 +-  fs/ntfs3/inode.c   | 83 ++++++++++++++++++++++++----------------------  fs/ntfs3/ntfs_fs.h |  2 +-  fs/ntfs3/xattr.c   | 20 ++++++-----  4 files changed, 58 insertions(+), 49 deletions(-)      struct ntfs_sb_info *sbi = ni->mi.sbi; @@ -504,6 +505,8 @@ static noinline int ntfs_set_ea(struct inode *inode, const char *name,      if (ea_info.size_pack != size_pack)          ni->ni_flags |= NI_FLAG_UPDATE_PARENT; +    if (ea_size) +        *ea_size = ea_info.size_pack;      mark_inode_dirty(&ni->vfs_inode);  out: @@ -633,7 +636,7 @@ static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,          flags = 0;      } -    err = ntfs_set_ea(inode, name, name_len, value, size, flags, 0); +    err = ntfs_set_ea(inode, name, name_len, value, size, flags, 0, NULL);      if (err == -ENODATA && !size)          err = 0; /* Removing non existed xattr. */      if (!err) { @@ -923,7 +926,8 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler,      }      /* Deal with NTFS extended attribute. */ -    err = ntfs_set_ea(inode, name, strlen(name), value, size, flags, 0); +    err = ntfs_set_ea(inode, name, strlen(name), value, size, flags, 0, +              NULL);  out:      inode->i_ctime = current_time(inode); @@ -937,7 +941,7 @@ static noinline int ntfs_setxattr(const struct xattr_handler *handler,   *   * save uid/gid/mode in xattr   */ -int ntfs_save_wsl_perm(struct inode *inode) +int ntfs_save_wsl_perm(struct inode *inode, __le16 *ea_size)  {      int err;      __le32 value; @@ -946,26 +950,26 @@ int ntfs_save_wsl_perm(struct inode *inode)      ni_lock(ni);      value = cpu_to_le32(i_uid_read(inode));      err = ntfs_set_ea(inode, "$LXUID", sizeof("$LXUID") - 1, &value, -              sizeof(value), 0, true); /* true == already locked. */ +              sizeof(value), 0, true, ea_size);      if (err)          goto out;      value = cpu_to_le32(i_gid_read(inode));      err = ntfs_set_ea(inode, "$LXGID", sizeof("$LXGID") - 1, &value, -              sizeof(value), 0, true); +              sizeof(value), 0, true, ea_size);      if (err)          goto out;      value = cpu_to_le32(inode->i_mode);      err = ntfs_set_ea(inode, "$LXMOD", sizeof("$LXMOD") - 1, &value, -              sizeof(value), 0, true); +              sizeof(value), 0, true, ea_size);      if (err)          goto out;      if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode)) {          value = cpu_to_le32(inode->i_rdev);          err = ntfs_set_ea(inode, "$LXDEV", sizeof("$LXDEV") - 1, &value, -                  sizeof(value), 0, true); +                  sizeof(value), 0, true, ea_size);          if (err)              goto out;      } diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 9cef189fc0c5..df7b76d1c127 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -703,7 +703,7 @@ int ntfs3_setattr(struct user_namespace *mnt_userns, struct dentry *dentry,      }      if (ia_valid & (ATTR_UID | ATTR_GID | ATTR_MODE)) -        ntfs_save_wsl_perm(inode); +        ntfs_save_wsl_perm(inode, NULL);      mark_inode_dirty(inode);  out:      return err; diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 51e342ad79fd..752ad17685c0 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -1320,8 +1320,7 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,      inode_init_owner(mnt_userns, inode, dir, mode);      mode = inode->i_mode; -    inode->i_atime = inode->i_mtime = inode->i_ctime = ni->i_crtime = -        current_time(inode); +    ni->i_crtime = current_time(inode);      rec = ni->mi.mrec;      rec->hard_links = cpu_to_le16(1); @@ -1362,10 +1361,9 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,      attr->res.data_size = cpu_to_le32(dsize);      std5->cr_time = std5->m_time = std5->c_time = std5->a_time = -        kernel2nt(&inode->i_atime); +        kernel2nt(&ni->i_crtime); -    ni->std_fa = fa; -    std5->fa = fa; +    std5->fa = ni->std_fa = fa;      attr = Add2Ptr(attr, asize); @@ -1564,11 +1562,15 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,              }              asize = SIZEOF_NONRESIDENT + ALIGN(err, 8); +            /* Write non resident data. */ +            err = ntfs_sb_write_run(sbi, &ni->file.run, 0, rp, +                        nsize, 0); +            if (err) +                goto out5;          } else {              attr->res.data_off = SIZEOF_RESIDENT_LE;              attr->res.data_size = cpu_to_le32(nsize);              memcpy(Add2Ptr(attr, SIZEOF_RESIDENT), rp, nsize); -            nsize = 0;          }          /* Size of symlink equals the length of input string. */          inode->i_size = size; @@ -1589,19 +1591,8 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,      rec->used = cpu_to_le32(PtrOffset(rec, attr) + 8);      rec->next_attr_id = cpu_to_le16(aid); -    /* Step 2: Add new name in index. */ -    err = indx_insert_entry(&dir_ni->dir, dir_ni, new_de, sbi, fnd, 0); -    if (err) -        goto out6; - -    /* Unlock parent directory before ntfs_init_acl. */ -    if (!fnd) -        ni_unlock(dir_ni); -      inode->i_generation = le16_to_cpu(rec->seq); -    dir->i_mtime = dir->i_ctime = inode->i_atime; -      if (S_ISDIR(mode)) {          inode->i_op = &ntfs_dir_inode_operations;          inode->i_fop = &ntfs_dir_operations; @@ -1626,41 +1617,58 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,      if (!S_ISLNK(mode) && (sb->s_flags & SB_POSIXACL)) {          err = ntfs_init_acl(mnt_userns, inode, dir);          if (err) -            goto out7; +            goto out5;      } else  #endif      {          inode->i_flags |= S_NOSEC;      } -    /* Write non resident data. */ -    if (nsize) { -        err = ntfs_sb_write_run(sbi, &ni->file.run, 0, rp, nsize, 0); -        if (err) -            goto out7; +    /* +     * ntfs_init_acl and ntfs_save_wsl_perm update extended attribute. +     * The packed size of extended attribute is stored in direntry too. +     * 'fname' here points to inside new_de. +     */ +    ntfs_save_wsl_perm(inode, &fname->dup.ea_size); + +    /* +     * update ea_size in file_name attribute too. +     * Use ni_find_attr cause layout of MFT record may be changed +     * in ntfs_init_acl and ntfs_save_wsl_perm. +     */ +    attr = ni_find_attr(ni, NULL, NULL, ATTR_NAME, NULL, 0, NULL, NULL); +    if (attr) { +        struct ATTR_FILE_NAME *fn; + +        fn = resident_data_ex(attr, SIZEOF_ATTRIBUTE_FILENAME); +        if (fn) +            fn->dup.ea_size = fname->dup.ea_size;      } +    /* We do not need to update parent directory later */ +    ni->ni_flags &= ~NI_FLAG_UPDATE_PARENT; + +    /* Step 2: Add new name in index. */ +    err = indx_insert_entry(&dir_ni->dir, dir_ni, new_de, sbi, fnd, 0); +    if (err) +        goto out6; +      /*       * Call 'd_instantiate' after inode->i_op is set       * but before finish_open.       */      d_instantiate(dentry, inode); -    ntfs_save_wsl_perm(inode); +    /* Set original time. inode times (i_ctime) may be changed in ntfs_init_acl. */ +    inode->i_atime = inode->i_mtime = inode->i_ctime = dir->i_mtime = +        dir->i_ctime = ni->i_crtime; +      mark_inode_dirty(dir);      mark_inode_dirty(inode);      /* Normal exit. */      goto out2; -out7: - -    /* Undo 'indx_insert_entry'. */ -    if (!fnd) -        ni_lock_dir(dir_ni); -    indx_delete_entry(&dir_ni->dir, dir_ni, new_de + 1, -              le16_to_cpu(new_de->key_size), sbi); -    /* ni_unlock(dir_ni); will be called later. */  out6:      if (rp_inserted)          ntfs_remove_reparse(sbi, IO_REPARSE_TAG_SYMLINK, &new_de->ref); @@ -1682,11 +1690,11 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,      kfree(rp);  out1: -    if (err) { -        if (!fnd) -            ni_unlock(dir_ni); +    if (!fnd) +        ni_unlock(dir_ni); + +    if (err)          return ERR_PTR(err); -    }      unlock_new_inode(inode); @@ -1783,9 +1791,6 @@ void ntfs_evict_inode(struct inode *inode)  {      truncate_inode_pages_final(&inode->i_data); -    if (inode->i_nlink) -        _ni_write_inode(inode, inode_needs_sync(inode)); -      invalidate_inode_buffers(inode);      clear_inode(inode); diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 556b76f526cb..73a639716b45 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -870,7 +870,7 @@ int ntfs_acl_chmod(struct user_namespace *mnt_userns, struct dentry *dentry);  ssize_t ntfs_listxattr(struct dentry *dentry, char *buffer, size_t size);  extern const struct xattr_handler *ntfs_xattr_handlers[]; -int ntfs_save_wsl_perm(struct inode *inode); +int ntfs_save_wsl_perm(struct inode *inode, __le16 *ea_size);  void ntfs_get_wsl_perm(struct inode *inode);  /* globals from lznt.c */ diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c index c42fbc56eb39..e7a66225361d 100644 --- a/fs/ntfs3/xattr.c +++ b/fs/ntfs3/xattr.c @@ -296,7 +296,8 @@ static int ntfs_get_ea(struct inode *inode, const char *name, size_t name_len,  static noinline int ntfs_set_ea(struct inode *inode, const char *name,                  size_t name_len, const void *value, -                size_t val_size, int flags, bool locked) +                size_t val_size, int flags, bool locked, +                __le16 *ea_size)  {      struct ntfs_inode *ni = ntfs_i(inode); From patchwork Wed Feb 15 13:36:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 57556 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp201159wrn; Wed, 15 Feb 2023 05:52:02 -0800 (PST) X-Google-Smtp-Source: AK7set8QTlTbxzAdj2OOaf8zjOgOthu6zZ99/2tw164mkx8GfZSGRhoABPWMPZhlwiR8SZ8BivPH X-Received: by 2002:aa7:d9c5:0:b0:4aa:a9c7:4224 with SMTP id v5-20020aa7d9c5000000b004aaa9c74224mr2028777eds.30.1676469122159; Wed, 15 Feb 2023 05:52:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676469122; cv=none; d=google.com; s=arc-20160816; b=Yv7XaswATDjMPldPmWOiSXjldCETnaCZeCBdM/4MXs2ykoLmgvxK6f04XGlGmIIaiC A72PHSS9PXjbr6qFuSAWE/qgHwlRm7kcmZ7z7NEK2/zSdFuLI7f1L+5wxLg9ktVM5Ubc ABdlyU7bId2HV3A/i+tGE2fUMuX14tBVZv2ff5Hdq6XzXGt8q/8Odtu/zSPqA7swHIm6 /FqVvkEbnYabp+ALuDExJHpZ6svt9we4FdnjL/XTLAQ3PIqBBJw/Vf8BKjK9+M67tDTM p1A7PEiv4o4rsZ0PspoWeRyX4Gy3yUl3lL6up5d/Ue8gzLckUxM9II8LWIA2ZZfuFQ1S 0L2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=OatpAkpsqEkQhNlA8+4RSwXL5RSbK1GB/mfif8PSuXw=; b=jHyKLtuN/CsBY/eKYWVGkZ1jV9qAAETuhqxPXxFEXeut27uiqRaLJqaf9C5dri7aME SqNxKCOo/jnr4CXYkeAWY8ZvrzJ3Krv0kV9WbJH0ZWp7cWaveHrPAt/L45JyZw8zCslY vPkgypx4s91p+msrBq0iJw56w4A17I5XdaBwfU0suLNt92I7KFleRBRocRLfFs2EvYEZ aOSK6C2sWx/NeIDNiI57fFKgJmmiK1CdQ4r37wIHH+24yOIehlTnAzP9Q2b2ajb3+YKU SvXkiywCoMtFk+TKBGd7q3895oKmUeaf+rHcUfImilM1umIUyFbpyb73z1pCrnMi5lF5 7Qmg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=iAEGNCOI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o7-20020aa7dd47000000b0049e420baaeesi20742161edw.470.2023.02.15.05.51.21; Wed, 15 Feb 2023 05:52:02 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=iAEGNCOI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229844AbjBONgS (ORCPT + 99 others); Wed, 15 Feb 2023 08:36:18 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229551AbjBONgQ (ORCPT ); Wed, 15 Feb 2023 08:36:16 -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 C19DE358D; Wed, 15 Feb 2023 05:36:15 -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 7DF952147; Wed, 15 Feb 2023 13:32:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676467923; bh=OatpAkpsqEkQhNlA8+4RSwXL5RSbK1GB/mfif8PSuXw=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=iAEGNCOIRzqY/nbzXCP4Ctrra7Efo9iOlJbi0C6An8CFHbytSmWV++wz84rTlqMmh p6zCCJnU2Eaxt6xq+4+UPXt3YnnOlkUSBK9TS0HbznaWpvyZM15P4LOYZ+WahPq81y VUWSCf+xlhJ9Nlh5mwDg+yXXj4owFmYLtU8dRK7Q= Received: from [192.168.211.36] (192.168.211.36) 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, 15 Feb 2023 16:36:13 +0300 Message-ID: <75a56ed1-eafc-0a18-9c2d-db4e423c3f26@paragon-software.com> Date: Wed, 15 Feb 2023 17:36:12 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: [PATCH 04/11] fs/ntfs3: Optimization in ntfs_set_state() Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.36] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757905286647501455?= X-GMAIL-MSGID: =?utf-8?q?1757905286647501455?= The current volume flags are updated only if VOLUME_FLAG_DIRTY has been changed. Signed-off-by: Konstantin Komarov ---  fs/ntfs3/fsntfs.c | 9 +++++++--  1 file changed, 7 insertions(+), 2 deletions(-)       * Do not change state if fs was real_dirty. @@ -957,6 +958,8 @@ int ntfs_set_state(struct ntfs_sb_info *sbi, enum NTFS_DIRTY_FLAGS dirty)          goto out;      } +    info_flags = info->flags; +      switch (dirty) {      case NTFS_DIRTY_ERROR:          ntfs_notice(sbi->sb, "Mark volume as dirty due to NTFS errors"); @@ -970,8 +973,10 @@ int ntfs_set_state(struct ntfs_sb_info *sbi, enum NTFS_DIRTY_FLAGS dirty)          break;      }      /* Cache current volume flags. */ -    sbi->volume.flags = info->flags; -    mi->dirty = true; +    if (info_flags != info->flags) { +        sbi->volume.flags = info->flags; +        mi->dirty = true; +    }      err = 0;  out: diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index 342938704cfd..d888ba14237f 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -925,6 +925,7 @@ int ntfs_set_state(struct ntfs_sb_info *sbi, enum NTFS_DIRTY_FLAGS dirty)      struct VOLUME_INFO *info;      struct mft_inode *mi;      struct ntfs_inode *ni; +    __le16 info_flags;      /* From patchwork Wed Feb 15 13:36:46 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 57558 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp201757wrn; Wed, 15 Feb 2023 05:53:16 -0800 (PST) X-Google-Smtp-Source: AK7set9cwebQ8JGIHRSQV6srFD1GnNf9mdOdthtH+ApbgN44KwEXsj6T6f6waJbHe7ocaPoJltuj X-Received: by 2002:a17:906:fca9:b0:8af:370a:c1f8 with SMTP id qw9-20020a170906fca900b008af370ac1f8mr2401115ejb.23.1676469196253; Wed, 15 Feb 2023 05:53:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676469196; cv=none; d=google.com; s=arc-20160816; b=NeKdGb7gXQSQ51CYxJCn5/JXsGfT5XusZLYV6aP+/VCz2mbEhI4HDt67ItB6WSMmkM yrzzriyfnbIMXZ9EIvmFaX6kAmVVm09H1PcnR3No08+vN5/zGaq61aACFPcg6qa4EsCt MAAYCXRiKgKkTRm1ZlGK9C2AOHEWXrEh/xTwWyCkQnEY3H78ssgAwxwwSZRPrxpCu5uM 1Y62coJAXfK+s00Fs0CsUWzijiOR+RsbW3dcJ4rGoBru6SnoJAXLiIrtdtQkXXIykHAb AZzp/dRpm7rG4bmKYrbZCv6pMwhtOmcmbXCw5eWFvIZo1Fols3aDqgEN2BJ2WpWmnUML iB3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature; bh=b+LLWuFDWYTNULIicKcI1S4EHJN/4plvEY5VcSHrLWg=; b=rd4MqbooDpWBx0RBnQDhYX3qoCkFAjYg69sdFTuZj1WU1OT7xVppBeqUtQwdohin9c idHPaCh0gonLTvSFTYPMuY4zIDzxWqpZazb3NSLZ7MST6ylYNrO6sWpCF7aIqyHOISDW dR5KmUoZJp/9kBxSEHKArV2sFf4rxI8WmCiGKID5i2brKeL2vZzzHQmg51VxPVqLvNMt sMD4NolXj+lAQMv4FL1n9/1IonWFg2wd9AC4MFDb9j4Qlcbw/qdg3QwhayHoJOW+ZXaE Tj+O+y+OZ3cWldURgvSEvtouxt4RPT9Nhy8af6K+1b4dWiiO0r2C8gfJIfBN5Aln+E0P 7x/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b="Q/Yhfksb"; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ptH5fSA1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ui3-20020a170907c90300b007ae10525573si19553886ejc.671.2023.02.15.05.52.47; Wed, 15 Feb 2023 05:53:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b="Q/Yhfksb"; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ptH5fSA1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230410AbjBONgv (ORCPT + 99 others); Wed, 15 Feb 2023 08:36:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229514AbjBONgu (ORCPT ); Wed, 15 Feb 2023 08:36:50 -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 EAC2C358D; Wed, 15 Feb 2023 05:36:48 -0800 (PST) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id AE4042147; Wed, 15 Feb 2023 13:32:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676467956; bh=b+LLWuFDWYTNULIicKcI1S4EHJN/4plvEY5VcSHrLWg=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=Q/Yhfksb+qlZJt/4SxooKi0BdMWTt4rWIloAIs3pdR8jX3wuZjC6uyvFVJEygSGxA qUfQAD8VSljf5GabnWJAwMIbqa+GC5tWrNBKOuc4ArDXojXIv2GIg4qgHfGkjqsvbM RUE7iQtJBUzaiDMmsz+ntj3SX8NU96W+/1yPV/qA= 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 0E8EC1E70; Wed, 15 Feb 2023 13:36:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676468207; bh=b+LLWuFDWYTNULIicKcI1S4EHJN/4plvEY5VcSHrLWg=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=ptH5fSA1Cz8XKI6v5HdTiOH2aOVUYljEDjk4I6gFH627yI0aZPymi8pOrP5gUwlMs tW7L8ujIRq2JCs26nIJCdQ8r1U1/LsHBdzKlLxGh2FZ9x4mJ3qpflYanYe/wwE7Gdf 0EnfrqssmhRvJu5CANZTFB19MIUDtuWifUzDlQwk= Received: from [192.168.211.36] (192.168.211.36) 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, 15 Feb 2023 16:36:46 +0300 Message-ID: Date: Wed, 15 Feb 2023 17:36:46 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: [PATCH 05/11] fs/ntfs3: Undo endian changes Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.36] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757905363883547740?= X-GMAIL-MSGID: =?utf-8?q?1757905363883547740?= sbi->mft.reserved_bitmap is in-memory (not on-disk!) bitmap. Assumed cpu endian is faster than fixed endian. Signed-off-by: Konstantin Komarov ---  fs/ntfs3/fsntfs.c | 11 +++++------  1 file changed, 5 insertions(+), 6 deletions(-)              sbi->mft.next_reserved = MFT_REC_FREE; @@ -720,7 +720,7 @@ int ntfs_look_free_mft(struct ntfs_sb_info *sbi, CLST *rno, bool mft,      if (*rno >= MFT_REC_FREE)          wnd_set_used(wnd, *rno, 1);      else if (*rno >= MFT_REC_RESERVED && sbi->mft.reserved_bitmap_inited) -        __set_bit_le(*rno - MFT_REC_RESERVED, &sbi->mft.reserved_bitmap); +        __set_bit(*rno - MFT_REC_RESERVED, &sbi->mft.reserved_bitmap);  out:      if (!mft) @@ -748,7 +748,7 @@ void ntfs_mark_rec_free(struct ntfs_sb_info *sbi, CLST rno, bool is_mft)          else              wnd_set_free(wnd, rno, 1);      } else if (rno >= MFT_REC_RESERVED && sbi->mft.reserved_bitmap_inited) { -        __clear_bit_le(rno - MFT_REC_RESERVED, &sbi->mft.reserved_bitmap); +        __clear_bit(rno - MFT_REC_RESERVED, &sbi->mft.reserved_bitmap);      }      if (rno < wnd_zone_bit(wnd)) @@ -846,9 +846,8 @@ void ntfs_update_mftmirr(struct ntfs_sb_info *sbi, int wait)  {      int err;      struct super_block *sb = sbi->sb; -    u32 blocksize; +    u32 blocksize, bytes;      sector_t block1, block2; -    u32 bytes;      if (!sb)          return; diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index d888ba14237f..9ed9dd0d8edf 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -646,13 +646,13 @@ int ntfs_look_free_mft(struct ntfs_sb_info *sbi, CLST *rno, bool mft,                           NULL, 0, NULL, NULL))                      goto next; -                __clear_bit_le(ir - MFT_REC_RESERVED, +                __clear_bit(ir - MFT_REC_RESERVED,                          &sbi->mft.reserved_bitmap);              }          }          /* Scan 5 bits for zero. Bit 0 == MFT_REC_RESERVED */ -        zbit = find_next_zero_bit_le(&sbi->mft.reserved_bitmap, +        zbit = find_next_zero_bit(&sbi->mft.reserved_bitmap,                        MFT_REC_FREE, MFT_REC_RESERVED);          if (zbit >= MFT_REC_FREE) { From patchwork Wed Feb 15 13:37:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 57551 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp197554wrn; Wed, 15 Feb 2023 05:44:19 -0800 (PST) X-Google-Smtp-Source: AK7set+G5Oo8eyEZ8ZNybXhrrHc+i4I4fpZACC66DgqtpIBalTp3DcwfriLiq2RzBdcdb8clHJN6 X-Received: by 2002:a05:6a20:4285:b0:bf:8ee2:2009 with SMTP id o5-20020a056a20428500b000bf8ee22009mr3331066pzj.26.1676468659710; Wed, 15 Feb 2023 05:44:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676468659; cv=none; d=google.com; s=arc-20160816; b=M5Yx4NRfwz/cR1ABH9Ww+dZM7ZVgORbJnHzDFB5nJzFlOFfauhwxrCL/H6EDXDvVWO YOXBhZK5K+rW8gx5AkfkWZohfDSCNoH5mc44oSn29M6bLbO9hbABNJd+ZuMnBrwFVTn7 TzYLnXcH2N66p/TIvOCaBQ2CsH2z4mptJ+IkxxjEn1wGpByMid3cBXHCaub8QK6NriWF YO8kUTHvL/5GClFGKAtCz+NMBv4MkSJ+TaY0+FIMXptnuzRZYs7D4sGv7eTaJGtN/vDf 5+Dk88v3raAlYD9eiSd1t2noHlO/EOSLO94l8HWC5HmoNXbi8QAIapzNdVvsS8m0gM2v O7yA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=s+jnBTb+FEAmnBEVyyEk7i0waZIXU0NPfdQERDIaNfE=; b=BMs7qMqiCP1h885qOoDbfhdAe8O7Ux4EPCQk/7/g2PALBDGB2t3NogDk+lE7fho2l0 rxdrG3lJMtCQYG/7nnhNQJAJOlb+px/QzPeaaz30y1aJiypUpRI4VcH/lCWVUDd2pFsA NxXn3VZIu3+JPXwNPdhQFpG6UOlBsoN/s4Db6m7JhSl3oVejiFjGvV05ibiQx+Bec4EK Tzv7NAXd6b4VnGaqtjb19OOUmdsJ9F5wEFnb/3tL/51l7vmvxTNOF1fgmLAqDdNu6pky WsViC+T1J1ry4hYburVwGl4n61W9NAs14I6qwPEhwJgsNBBVrfOYEUrjjUSHh+BzE2yt 0Ayg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ndKFZlp5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f5-20020aa79685000000b005a8ee167e52si3087959pfk.325.2023.02.15.05.44.06; Wed, 15 Feb 2023 05:44:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=ndKFZlp5; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230474AbjBONh1 (ORCPT + 99 others); Wed, 15 Feb 2023 08:37:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjBONh0 (ORCPT ); Wed, 15 Feb 2023 08:37:26 -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 2B980358D; Wed, 15 Feb 2023 05:37:25 -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 D63352147; Wed, 15 Feb 2023 13:33:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676467992; bh=s+jnBTb+FEAmnBEVyyEk7i0waZIXU0NPfdQERDIaNfE=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=ndKFZlp5o5+usKaaciH36JgPDyMsCNQzIeMorpXuUXxrHaeCrx5tuzcEccSGTQwZr 8N7sIMjEzZ0wshdQifn3gEbFbZRBqU+RiYSZZgTxpp5qBmEqS+GrRb/6y4p8ZUQJJr el3CtPeW4mvu41Zlz/1+woYx27WOLOdtnDxaaXsE= Received: from [192.168.211.36] (192.168.211.36) 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, 15 Feb 2023 16:37:22 +0300 Message-ID: <3f4de192-d3f3-f2b3-2b05-8c1c027d1d8c@paragon-software.com> Date: Wed, 15 Feb 2023 17:37:22 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: [PATCH 06/11] fs/ntfs3: Undo critial modificatins to keep directory consistency Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.36] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757904801215744489?= X-GMAIL-MSGID: =?utf-8?q?1757904801215744489?= Affect xfstest 320. Signed-off-by: Konstantin Komarov ---  fs/ntfs3/index.c | 30 ++++++++++++++++++++----------  1 file changed, 20 insertions(+), 10 deletions(-)      e = fnd->level - 1 == level ? fnd->de[level] : NULL; @@ -1814,6 +1815,13 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni,          return -ENOMEM;      memcpy(up_e, sp, sp_size); +    used1 = le32_to_cpu(hdr1->used); +    hdr1_saved = kmemdup(hdr1, used1, GFP_NOFS); +    if (!hdr1_saved) { +        err = -ENOMEM; +        goto out; +    } +      if (!hdr1->flags) {          up_e->flags |= NTFS_IE_HAS_SUBNODES;          up_e->size = cpu_to_le16(sp_size + sizeof(u64)); @@ -1846,7 +1854,7 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni,      hdr_insert_head(hdr2, de_t, to_copy);      /* Remove all entries (sp including) from hdr1. */ -    used = le32_to_cpu(hdr1->used) - to_copy - sp_size; +    used = used1 - to_copy - sp_size;      memmove(de_t, Add2Ptr(sp, sp_size), used - le32_to_cpu(hdr1->de_off));      hdr1->used = cpu_to_le32(used); @@ -1876,8 +1884,6 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni,      if (!level) {          /* Insert in root. */          err = indx_insert_into_root(indx, ni, up_e, NULL, ctx, fnd, 0); -        if (err) -            goto out;      } else {          /*           * The target buffer's parent is another index buffer. @@ -1885,12 +1891,20 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni,           */          err = indx_insert_into_buffer(indx, ni, root, up_e, ctx,                            level - 1, fnd); -        if (err) -            goto out; +    } + +    if (err) { +        /* +         * Undo critical operations. +         */ +        indx_mark_free(indx, ni, new_vbn >> indx->idx2vbn_bits); +        memcpy(hdr1, hdr1_saved, used1); +        indx_write(indx, ni, n1, 0);      }  out:      kfree(up_e); +    kfree(hdr1_saved);      return err;  } @@ -1949,16 +1963,12 @@ int indx_insert_entry(struct ntfs_index *indx, struct ntfs_inode *ni,           */          err = indx_insert_into_root(indx, ni, new_de, fnd->root_de, ctx,                          fnd, undo); -        if (err) -            goto out;      } else {          /*           * Found a leaf buffer, so we'll insert the new entry into it.           */          err = indx_insert_into_buffer(indx, ni, root, new_de, ctx,                            fnd->level - 1, fnd); -        if (err) -            goto out;      }  out: diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c index 9fefeac5fe7e..5d1ec0124137 100644 --- a/fs/ntfs3/index.c +++ b/fs/ntfs3/index.c @@ -1778,10 +1778,11 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni,      struct indx_node *n1 = fnd->nodes[level];      struct INDEX_HDR *hdr1 = &n1->index->ihdr;      struct INDEX_HDR *hdr2; -    u32 to_copy, used; +    u32 to_copy, used, used1;      CLST new_vbn;      __le64 t_vbn, *sub_vbn;      u16 sp_size; +    void *hdr1_saved = NULL;      /* Try the most easy case. */ From patchwork Wed Feb 15 13:38:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 57547 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp195507wrn; Wed, 15 Feb 2023 05:39:54 -0800 (PST) X-Google-Smtp-Source: AK7set/FtBrHr1jupU8UUjiTTfEtLVjPOUlSY+9PrvF1J1brk2uYB5PbCsam2W9dLaTWY1bddldR X-Received: by 2002:a62:170a:0:b0:5a8:b082:19dc with SMTP id 10-20020a62170a000000b005a8b08219dcmr2254393pfx.11.1676468394543; Wed, 15 Feb 2023 05:39:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676468394; cv=none; d=google.com; s=arc-20160816; b=XZBaASgw+8HhpvAgGUeQTQq7HVv2VNvEKagyluZN4fZnAbkr6MR0S69orBDiQkutZS GByDPPP/K1TJaRndj/DgxivW7CbWyFUzwsExy1jjqkizfWxiQKLf3NklsyUIJk5lYW/w k8gdN6CpFYU5/kvK5PYPlJpRf59fmAR8Dj0svNtkYZiFdJ7SlpEXj/Upz12weffLzc3n M+6ieNgMw8fE8K9vP2AQ4uAJd1YiZgNQzCh0yu/gon6TK/Cyro+gT5lBBdXmP/uBwV0X AIi06wlND0AOCoGOdtvBw/F7RQ77VtAl2gFcP+Aa2GUwjpsWu0Q7G7/GTbVe5sZzi/8q VV3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature; bh=qABqCzWeJMd8lL3Bs/m2a0hwQR1+Gsb68tcyxZYiqqY=; b=h384VBTasK0RTBxggOsK47CtBnmeDxk4Fxdy6jj8/c00usVI5NZwzgykU+EGONs3O+ SJdBQ6QrOf00ibYaF3c+j3kta3jbbDH+8SoxhGS/dugyjycvI1bq28cjz/BZRZzEmsKu zAE5icR9aYM5t74Du6UmHy/PYYxpM6EbPjymkHH90PKIKyTsEugePuY04jJTCTHsMOYe //7QazdBvPXC9vmoGUhyV7EtysmB/f7DmViLeoagGm9X2IfYDhVDsrZZJaNdWqCoWsTy dPCOM3GSbsilQ8vPg8jv+tvHOPwGzDSGrURWqPEMofuwbxHhSlFdj1yl5ePI623vegzc cc3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=NeHGIHvj; dkim=pass header.i=@paragon-software.com header.s=mail header.b=Nv7Dc7iP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a5-20020aa794a5000000b005a8ddfdfbfbsi4600776pfl.30.2023.02.15.05.39.39; Wed, 15 Feb 2023 05:39:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=NeHGIHvj; dkim=pass header.i=@paragon-software.com header.s=mail header.b=Nv7Dc7iP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229793AbjBONiH (ORCPT + 99 others); Wed, 15 Feb 2023 08:38:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55538 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229460AbjBONiG (ORCPT ); Wed, 15 Feb 2023 08:38:06 -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 CE5F37D88; Wed, 15 Feb 2023 05:38:05 -0800 (PST) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 9B29A2147; Wed, 15 Feb 2023 13:33:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676468033; bh=qABqCzWeJMd8lL3Bs/m2a0hwQR1+Gsb68tcyxZYiqqY=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=NeHGIHvjmMRxaOW43o4icEh3F5LwXYbTVz8PkfLcNfmyDFe/Bt2my8KiOd43MekOu 4OF8h0WyBmidpMbwVaE0+F4Pk5fsrOXF2fI2mBi4sl4KGL7OEqRieh2rbJfABGn1Om UncOn4kcq2w/WhJyaPGf8/4FlXtE2tfnQAaYV3Ew= 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 E9C2F1E70; Wed, 15 Feb 2023 13:38:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676468283; bh=qABqCzWeJMd8lL3Bs/m2a0hwQR1+Gsb68tcyxZYiqqY=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=Nv7Dc7iPcqNQs8qB6kUQLqyB02zMfSvYFdF2EnIBuC4dF5t8n2xOm+bLgE2pqys6F +Ktcj9H4TrhZTM9nUzEO4HIvcviPQgPNFIJJaABZShaXbhoThXy7GCwYP6gqQuV96O 8YI1lf+OhKYodotlKDPFCeuahN5qrhkFl8VIYIzk= Received: from [192.168.211.36] (192.168.211.36) 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, 15 Feb 2023 16:38:03 +0300 Message-ID: <9e0dd9a4-afa8-1137-7f8b-ccec26825aa1@paragon-software.com> Date: Wed, 15 Feb 2023 17:38:02 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: [PATCH 07/11] fs/ntfs3: Remove field sbi->used.bitmap.set_tail Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.36] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757904523686188028?= X-GMAIL-MSGID: =?utf-8?q?1757904523686188028?= This field is not used in driver. Signed-off-by: Konstantin Komarov ---  fs/ntfs3/ntfs_fs.h | 1 -  fs/ntfs3/super.c   | 2 --  2 files changed, 3 deletions(-)          goto put_inode_out; diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 73a639716b45..26957dbfe471 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -163,7 +163,6 @@ struct wnd_bitmap {      size_t zone_bit;      size_t zone_end; -    bool set_tail; // Not necessary in driver.      bool inited;  }; diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 10c019ef7da3..d7bec9b28a42 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -1117,8 +1117,6 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)          goto put_inode_out;      } -    /* Not necessary. */ -    sbi->used.bitmap.set_tail = true;      err = wnd_init(&sbi->used.bitmap, sb, tt);      if (err) From patchwork Wed Feb 15 13:38:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 57550 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp197466wrn; Wed, 15 Feb 2023 05:44:09 -0800 (PST) X-Google-Smtp-Source: AK7set+meFSyMLCxumKfwKj8S+VOoarULL6DpP/i44LkSQHvlvTx98mRUaQ2F/m+sMLZj0+sqg2Q X-Received: by 2002:a17:90b:4b8b:b0:234:2627:d9b0 with SMTP id lr11-20020a17090b4b8b00b002342627d9b0mr2840305pjb.32.1676468649445; Wed, 15 Feb 2023 05:44:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676468649; cv=none; d=google.com; s=arc-20160816; b=q/6jpg1G41izZtk3YiUsRtOQzZGj2qdut0NDYOcfb6yBIdicfVTUbyUD+j8j44mJI9 03zQ3ewfVfBhlTf5EwEOlr2a8t68lUU7prNl0y8qE9WAWEyIcC9hQNx8HZnJDD8UMHLB tSc4RL5/FGyo6ODq1oyGle/QQjeTOU94Bta9sbrjgCxWfaz/F0AQuSXqTWU/7w5bDYWg nFkiNag5El73npNsgKY1NTBMMzJjh3le4AmlqNosDEI8Jajorpvxa/OBx2gxMgOlRbfk 15NExIdULpX/A1FQx7RrQ6ej4SCaWO57xpyMyYJNsxFP5cjt0/XmX/5IqMhN83xsagR2 WeUw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=v58AXW2jaHRye0+maSOsTkJ3+nH0kdM/rFc7zhel7Rc=; b=vO3zQjgCqBagXpURxO9j0g6rZy/20ULapqBCwYi7n2ibK858baaEnVfNvDKYhxSez9 qT28x5OVKcXVLhwaoRPRgq8v1yoWdnO0Cb40OEtgK5EWWFE90GF1S0r6HnQZqQmEtJyE tgWeow4jKJfP5ncZ8S8R6gRgXwzAhwcFej8Cn2YCpjyjd0CnIda4wsWLB5Em4KtbAxfn tiglxwlasIQIg53h36qhmIBhCdvrOcDtEfBQVAHkr2ir1utaj9PlF8jGKiA/tCTV3OgN aJ65kt+9i1XkOX0z57KAgrVI2vJ49jAH9p0eEQa/8y72kinStyK8pXYR6eJrf4ekK6OC xK/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b="W4yAraG/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g3-20020a17090a67c300b00233cf305f6bsi1896850pjm.111.2023.02.15.05.43.56; Wed, 15 Feb 2023 05:44:09 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b="W4yAraG/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230197AbjBONi7 (ORCPT + 99 others); Wed, 15 Feb 2023 08:38:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56518 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229642AbjBONi6 (ORCPT ); Wed, 15 Feb 2023 08:38:58 -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 701C77D88; Wed, 15 Feb 2023 05:38:57 -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 1EFC02147; Wed, 15 Feb 2023 13:34:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676468085; bh=v58AXW2jaHRye0+maSOsTkJ3+nH0kdM/rFc7zhel7Rc=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=W4yAraG/LFxRU1llz2bytqvNtGnqOkDAsNUSflnIdSqi2WB4dmyV07Vp9gmL7aBzA RLOcoQ3v00omyOCC4OtsDJzX//VF+mkYcGp8YdRXKA+jBpvUt5L+mV6diBi5Di8M9R azxBZlm0LhyBv5C1t8ozsOdC6sfk0D8cjgvL7yic= Received: from [192.168.211.36] (192.168.211.36) 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, 15 Feb 2023 16:38:55 +0300 Message-ID: <2f017ba3-78a9-211d-2a61-f8a1c90c3cab@paragon-software.com> Date: Wed, 15 Feb 2023 17:38:54 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: [PATCH 08/11] fs/ntfs3: Changed ntfs_get_acl() to use dentry Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.36] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757904790462867781?= X-GMAIL-MSGID: =?utf-8?q?1757904790462867781?= ntfs_get_acl changed to match new interface in struct inode_operations. Signed-off-by: Konstantin Komarov ---  fs/ntfs3/file.c    |  2 +-  fs/ntfs3/namei.c   |  4 ++--  fs/ntfs3/ntfs_fs.h |  3 ++-  fs/ntfs3/xattr.c   | 26 +++++++++-----------------  4 files changed, 14 insertions(+), 21 deletions(-)      size_t name_len; @@ -545,13 +550,11 @@ static struct posix_acl *ntfs_get_acl_ex(struct inode *inode, int type,          name_len = sizeof(XATTR_NAME_POSIX_ACL_DEFAULT) - 1;      } -    if (!locked) -        ni_lock(ni); +    ni_lock(ni);      err = ntfs_get_ea(inode, name, name_len, buf, PATH_MAX, &req); -    if (!locked) -        ni_unlock(ni); +    ni_unlock(ni);      /* Translate extended attribute to acl. */      if (err >= 0) { @@ -570,17 +573,6 @@ static struct posix_acl *ntfs_get_acl_ex(struct inode *inode, int type,      return acl;  } -/* - * ntfs_get_acl - inode_operations::get_acl - */ -struct posix_acl *ntfs_get_acl(struct inode *inode, int type, bool rcu) -{ -    if (rcu) -        return ERR_PTR(-ECHILD); - -    return ntfs_get_acl_ex(inode, type, 0); -} -  static noinline int ntfs_set_acl_ex(struct user_namespace *mnt_userns,                      struct inode *inode, struct posix_acl *acl,                      int type, bool init_acl) diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index df7b76d1c127..09b7931e6be3 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -1143,7 +1143,7 @@ const struct inode_operations ntfs_file_inode_operations = {      .getattr    = ntfs_getattr,      .setattr    = ntfs3_setattr,      .listxattr    = ntfs_listxattr, -    .get_inode_acl    = ntfs_get_acl, +    .get_acl    = ntfs_get_acl,      .set_acl    = ntfs_set_acl,      .fiemap        = ntfs_fiemap,  }; diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c index 5d5fe2f1f77c..8b68ead5cc1f 100644 --- a/fs/ntfs3/namei.c +++ b/fs/ntfs3/namei.c @@ -607,7 +607,7 @@ const struct inode_operations ntfs_dir_inode_operations = {      .rmdir        = ntfs_rmdir,      .mknod        = ntfs_mknod,      .rename        = ntfs_rename, -    .get_inode_acl    = ntfs_get_acl, +    .get_acl    = ntfs_get_acl,      .set_acl    = ntfs_set_acl,      .setattr    = ntfs3_setattr,      .getattr    = ntfs_getattr, @@ -620,7 +620,7 @@ const struct inode_operations ntfs_special_inode_operations = {      .setattr    = ntfs3_setattr,      .getattr    = ntfs_getattr,      .listxattr    = ntfs_listxattr, -    .get_inode_acl    = ntfs_get_acl, +    .get_acl    = ntfs_get_acl,      .set_acl    = ntfs_set_acl,  }; diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index 26957dbfe471..b7782107ce8a 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -855,7 +855,8 @@ unsigned long ntfs_names_hash(const u16 *name, size_t len, const u16 *upcase,  /* globals from xattr.c */  #ifdef CONFIG_NTFS3_FS_POSIX_ACL -struct posix_acl *ntfs_get_acl(struct inode *inode, int type, bool rcu); +struct posix_acl *ntfs_get_acl(struct user_namespace *mnt_userns, +         struct dentry *dentry, int type);  int ntfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry,           struct posix_acl *acl, int type);  int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode, diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c index e7a66225361d..95c479d7ebba 100644 --- a/fs/ntfs3/xattr.c +++ b/fs/ntfs3/xattr.c @@ -520,9 +520,14 @@ static noinline int ntfs_set_ea(struct inode *inode, const char *name,  }  #ifdef CONFIG_NTFS3_FS_POSIX_ACL -static struct posix_acl *ntfs_get_acl_ex(struct inode *inode, int type, -                     int locked) + +/* + * ntfs_get_acl - inode_operations::get_acl + */ +struct posix_acl *ntfs_get_acl(struct user_namespace *mnt_userns, +                   struct dentry *dentry, int type)  { +    struct inode *inode = d_inode(dentry);      struct ntfs_inode *ni = ntfs_i(inode);      const char *name; From patchwork Wed Feb 15 13:39:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 57549 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp197385wrn; Wed, 15 Feb 2023 05:43:58 -0800 (PST) X-Google-Smtp-Source: AK7set+Tu3W67aRmhD/p+M4DfLYKUDU8VVOo8vyM+Py8v3g4IBUuMLQGxWqGp4VpzI7FUgTqT+Kf X-Received: by 2002:a05:6a20:a298:b0:c6:d419:e557 with SMTP id a24-20020a056a20a29800b000c6d419e557mr1177698pzl.41.1676468637718; Wed, 15 Feb 2023 05:43:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676468637; cv=none; d=google.com; s=arc-20160816; b=hfRZepnOugvWtf925ieOI2xBa4ltYMOltTnAyZdu4RGP64dDUDn0SGmo4lBMPek+a9 SXIf2v/jGIqDXrebNfd1aZCHVt7I+XPILGeS9x7Z9cy0TAdGAfhGqWvZZxJa6Sz9WIic ZD3KZRhQ1UlrOdzBl5HAQDqQmzTg4NoyrGCG5kbx6D4xDlqprmTVYdBdEKFia3UFA1HR eyh3i2GD+lILk2fh9H9LxVcgXmrvfx49LyIcQmOPCtGx7YR0i9rXxUSkKUKBXbqTZYt+ s7E+PXTsenSZaKrCxQSG5Ld28grtB+9/Fgxrd/gIfZ9pacjYHgrvmRJHp+4tbX0EwzWQ r1CA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature; bh=9wqkiqZrKzwvHdcnP28A5rK4lq/9iHl1Vg0imvVpMVU=; b=0u1PvXpzrskzNjYkJqSv49XavowfhMTWW33ekuP+mJ/u5Z37/A8BmBPfSiC9r0nl// G1AiL4OjXLy5qqbV/FT/ntKPyq8Zd7lTCmIxbyVwv0g0xge5HyPaP1NPVuxGsn0B2Qq5 vhmI8cvbYdRLksMUoLvEnF9VYDQSM55MDvjkMekwfWQZkp1VNM3cNevKvuU/aH//KVdX s+CvT/mXO0ew09ILcJqRpcddSFAZRntucnwIZqUOZf7CIliIgxmD4ZG3d/NUxHTfhDI5 xEwuCGFZuBgacwNqY53SQUQhjlvDuHvz1cUNOyYY6QIuHvRC2eG+L2Kw7yUl6ymMyCak g45A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=Ia28Fr2n; dkim=pass header.i=@paragon-software.com header.s=mail header.b=qbEqalBf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v7-20020a63b947000000b004fb44542da8si17996036pgo.811.2023.02.15.05.43.43; Wed, 15 Feb 2023 05:43:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=Ia28Fr2n; dkim=pass header.i=@paragon-software.com header.s=mail header.b=qbEqalBf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231294AbjBONji (ORCPT + 99 others); Wed, 15 Feb 2023 08:39:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230422AbjBONjg (ORCPT ); Wed, 15 Feb 2023 08:39: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 E0F2B17176; Wed, 15 Feb 2023 05:39:31 -0800 (PST) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id 7BA172147; Wed, 15 Feb 2023 13:35:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676468119; bh=9wqkiqZrKzwvHdcnP28A5rK4lq/9iHl1Vg0imvVpMVU=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=Ia28Fr2nrEgu9o91Mm/j9Nk0suXbvwp5Ungw2+T/I62WuyZZxsRQYsnbeJiKDIZkW s4cSvy0NEpsRforX3ljS87lVdtjOtEH+KjpMTa7ooJPW4ynlFlPGtyalELiiKnyHXk r87EWCdPsPnKLCvtgLVFqJFdD1lD6AQeBn7g/MKQ= 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 C6A9D1E70; Wed, 15 Feb 2023 13:39:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676468369; bh=9wqkiqZrKzwvHdcnP28A5rK4lq/9iHl1Vg0imvVpMVU=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=qbEqalBfsq1XbhHoWk3MYbtRL3DCq2NLl4F+AkuHeQuHIQwYHaCas/wWEdDf0HIix 5SKMBWL2yHYWeH2Nq2328+9MD13m3JR7mmtLIy/QCwvRJTCgKxKXxO4vPsxFlb325y qFSbRK3JZpOHCfeEJFOHqoEBerOYdXP8LEW6YsE8= Received: from [192.168.211.36] (192.168.211.36) 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, 15 Feb 2023 16:39:29 +0300 Message-ID: <83fcdf79-dbb0-e693-cc66-877f3bb22eac@paragon-software.com> Date: Wed, 15 Feb 2023 17:39:28 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: [PATCH 09/11] fs/ntfs3: Code formatting and refactoring Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.36] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757904778067029217?= X-GMAIL-MSGID: =?utf-8?q?1757904778067029217?= Added minor refactoring. Added and fixed some comments. In some places, the code has been reformatted to fit into 80 columns. clang-format-12 was used to format code according kernel's .clang-format. Signed-off-by: Konstantin Komarov ---  fs/ntfs3/attrib.c  | 17 +++++-----  fs/ntfs3/bitmap.c  | 22 ++++++-------  fs/ntfs3/file.c    | 25 ++++++++-------  fs/ntfs3/frecord.c | 37 ++++++++++------------  fs/ntfs3/fslog.c   | 77 +++++++++++++++++++++++-----------------------  fs/ntfs3/fsntfs.c  | 13 ++++----  fs/ntfs3/index.c   | 28 +++++++++--------  fs/ntfs3/inode.c   | 33 ++++++++++----------  fs/ntfs3/lznt.c    | 10 +++---  fs/ntfs3/namei.c   |  4 +--  fs/ntfs3/ntfs_fs.h |  9 +++---  fs/ntfs3/record.c  |  9 +++---  fs/ntfs3/run.c     |  6 ++--  fs/ntfs3/super.c   | 70 ++++++++++++++++++++++-------------------  fs/ntfs3/xattr.c   |  4 +--  15 files changed, 186 insertions(+), 178 deletions(-) diff --git a/fs/ntfs3/attrib.c b/fs/ntfs3/attrib.c index 5e6bafb10f42..0b8bc66377db 100644 --- a/fs/ntfs3/attrib.c +++ b/fs/ntfs3/attrib.c @@ -405,8 +405,8 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,      int err = 0;      struct ntfs_sb_info *sbi = ni->mi.sbi;      u8 cluster_bits = sbi->cluster_bits; -    bool is_mft = -        ni->mi.rno == MFT_REC_MFT && type == ATTR_DATA && !name_len; +    bool is_mft = ni->mi.rno == MFT_REC_MFT && type == ATTR_DATA && +              !name_len;      u64 old_valid, old_size, old_alloc, new_alloc, new_alloc_tmp;      struct ATTRIB *attr = NULL, *attr_b;      struct ATTR_LIST_ENTRY *le, *le_b; @@ -531,11 +531,10 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,              pre_alloc = 0;              if (type == ATTR_DATA && !name_len &&                  sbi->options->prealloc) { -                pre_alloc = -                    bytes_to_cluster( -                        sbi, -                        get_pre_allocated(new_size)) - -                    new_alen; +                pre_alloc = bytes_to_cluster( +                            sbi, get_pre_allocated( +                                 new_size)) - +                        new_alen;              }              /* Get the last LCN to allocate from. */ @@ -573,8 +572,8 @@ int attr_set_size(struct ntfs_inode *ni, enum ATTR_TYPE type,              err = attr_allocate_clusters(                  sbi, run, vcn, lcn, to_allocate, &pre_alloc,                  is_mft ? ALLOCATE_MFT : ALLOCATE_DEF, &alen, -                is_mft ? 0 -                       : (sbi->record_size - +                is_mft ? 0 : +                           (sbi->record_size -                        le32_to_cpu(rec->used) + 8) /                               3 +                           1, diff --git a/fs/ntfs3/bitmap.c b/fs/ntfs3/bitmap.c index 393c726ef17a..9a6c6a09d70c 100644 --- a/fs/ntfs3/bitmap.c +++ b/fs/ntfs3/bitmap.c @@ -40,9 +40,9 @@ static struct kmem_cache *ntfs_enode_cachep;  int __init ntfs3_init_bitmap(void)  { -    ntfs_enode_cachep = -        kmem_cache_create("ntfs3_enode_cache", sizeof(struct e_node), 0, -                  SLAB_RECLAIM_ACCOUNT, NULL); +    ntfs_enode_cachep = kmem_cache_create("ntfs3_enode_cache", +                          sizeof(struct e_node), 0, +                          SLAB_RECLAIM_ACCOUNT, NULL);      return ntfs_enode_cachep ? 0 : -ENOMEM;  } @@ -286,9 +286,9 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,          if (wnd->uptodated != 1) {              /* Check bits before 'bit'. */              ib = wnd->zone_bit == wnd->zone_end || -                         bit < wnd->zone_end -                     ? 0 -                     : wnd->zone_end; +                         bit < wnd->zone_end ? +                       0 : +                       wnd->zone_end;              while (bit > ib && wnd_is_free_hlp(wnd, bit - 1, 1)) {                  bit -= 1; @@ -297,9 +297,9 @@ static void wnd_add_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len,              /* Check bits after 'end_in'. */              ib = wnd->zone_bit == wnd->zone_end || -                         end_in > wnd->zone_bit -                     ? wnd->nbits -                     : wnd->zone_bit; +                         end_in > wnd->zone_bit ? +                       wnd->nbits : +                       wnd->zone_bit;              while (end_in < ib && wnd_is_free_hlp(wnd, end_in, 1)) {                  end_in += 1; @@ -417,8 +417,8 @@ static void wnd_remove_free_ext(struct wnd_bitmap *wnd, size_t bit, size_t len)              return;          n3 = rb_first(&wnd->count_tree);          wnd->extent_max = -            n3 ? rb_entry(n3, struct e_node, count.node)->count.key -               : 0; +            n3 ? rb_entry(n3, struct e_node, count.node)->count.key : +                   0;          return;      } diff --git a/fs/ntfs3/file.c b/fs/ntfs3/file.c index 09b7931e6be3..a10a905ec7ce 100644 --- a/fs/ntfs3/file.c +++ b/fs/ntfs3/file.c @@ -22,20 +22,21 @@ static int ntfs_ioctl_fitrim(struct ntfs_sb_info *sbi, unsigned long arg)  {      struct fstrim_range __user *user_range;      struct fstrim_range range; +    struct block_device *dev;      int err;      if (!capable(CAP_SYS_ADMIN))          return -EPERM; -    if (!bdev_max_discard_sectors(sbi->sb->s_bdev)) +    dev = sbi->sb->s_bdev; +    if (!bdev_max_discard_sectors(dev))          return -EOPNOTSUPP;      user_range = (struct fstrim_range __user *)arg;      if (copy_from_user(&range, user_range, sizeof(range)))          return -EFAULT; -    range.minlen = max_t(u32, range.minlen, -                 bdev_discard_granularity(sbi->sb->s_bdev)); +    range.minlen = max_t(u32, range.minlen, bdev_discard_granularity(dev));      err = ntfs_trim_fs(sbi, &range);      if (err < 0) @@ -190,8 +191,8 @@ static int ntfs_zero_range(struct inode *inode, u64 vbo, u64 vbo_to)      for (; idx < idx_end; idx += 1, from = 0) {          page_off = (loff_t)idx << PAGE_SHIFT; -        to = (page_off + PAGE_SIZE) > vbo_to ? (vbo_to - page_off) -                             : PAGE_SIZE; +        to = (page_off + PAGE_SIZE) > vbo_to ? (vbo_to - page_off) : +                                 PAGE_SIZE;          iblock = page_off >> inode->i_blkbits;          page = find_or_create_page(mapping, idx, @@ -564,13 +565,14 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)          ni_unlock(ni);      } else {          /* Check new size. */ +        u8 cluster_bits = sbi->cluster_bits;          /* generic/213: expected -ENOSPC instead of -EFBIG. */          if (!is_supported_holes) {              loff_t to_alloc = new_size - inode_get_bytes(inode);              if (to_alloc > 0 && -                (to_alloc >> sbi->cluster_bits) > +                (to_alloc >> cluster_bits) >                      wnd_zeroes(&sbi->used.bitmap)) {                  err = -ENOSPC;                  goto out; @@ -591,7 +593,7 @@ static long ntfs_fallocate(struct file *file, int mode, loff_t vbo, loff_t len)          }          if (is_supported_holes) { -            CLST vcn = vbo >> sbi->cluster_bits; +            CLST vcn = vbo >> cluster_bits;              CLST cend = bytes_to_cluster(sbi, end);              CLST cend_v = bytes_to_cluster(sbi, ni->i_valid);              CLST lcn, clen; @@ -1049,8 +1051,8 @@ static ssize_t ntfs_file_write_iter(struct kiocb *iocb, struct iov_iter *from)      if (ret)          goto out; -    ret = is_compressed(ni) ? ntfs_compress_write(iocb, from) -                : __generic_file_write_iter(iocb, from); +    ret = is_compressed(ni) ? ntfs_compress_write(iocb, from) : +                    __generic_file_write_iter(iocb, from);  out:      inode_unlock(inode); @@ -1102,8 +1104,9 @@ static int ntfs_file_release(struct inode *inode, struct file *file)      int err = 0;      /* If we are last writer on the inode, drop the block reservation. */ -    if (sbi->options->prealloc && ((file->f_mode & FMODE_WRITE) && -                      atomic_read(&inode->i_writecount) == 1)) { +    if (sbi->options->prealloc && +        ((file->f_mode & FMODE_WRITE) && +         atomic_read(&inode->i_writecount) == 1)) {          ni_lock(ni);          down_write(&ni->file.run_lock); diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c index 9e7dfee303e8..481219f2a7cf 100644 --- a/fs/ntfs3/frecord.c +++ b/fs/ntfs3/frecord.c @@ -76,8 +76,8 @@ struct ATTR_STD_INFO *ni_std(struct ntfs_inode *ni)      const struct ATTRIB *attr;      attr = mi_find_attr(&ni->mi, NULL, ATTR_STD, NULL, 0, NULL); -    return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO)) -            : NULL; +    return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO)) : +                NULL;  }  /* @@ -91,8 +91,8 @@ struct ATTR_STD_INFO5 *ni_std5(struct ntfs_inode *ni)      attr = mi_find_attr(&ni->mi, NULL, ATTR_STD, NULL, 0, NULL); -    return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO5)) -            : NULL; +    return attr ? resident_data_ex(attr, sizeof(struct ATTR_STD_INFO5)) : +                NULL;  }  /* @@ -1439,8 +1439,8 @@ int ni_insert_nonresident(struct ntfs_inode *ni, enum ATTR_TYPE type,      int err;      CLST plen;      struct ATTRIB *attr; -    bool is_ext = -        (flags & (ATTR_FLAG_SPARSED | ATTR_FLAG_COMPRESSED)) && !svcn; +    bool is_ext = (flags & (ATTR_FLAG_SPARSED | ATTR_FLAG_COMPRESSED)) && +              !svcn;      u32 name_size = ALIGN(name_len * sizeof(short), 8);      u32 name_off = is_ext ? SIZEOF_NONRESIDENT_EX : SIZEOF_NONRESIDENT;      u32 run_off = name_off + name_size; @@ -1756,9 +1756,9 @@ int ni_new_attr_flags(struct ntfs_inode *ni, enum FILE_ATTRIBUTE new_fa)      }      /* Resize nonresident empty attribute in-place only. */ -    new_asize = (new_aflags & (ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED)) -                ? (SIZEOF_NONRESIDENT_EX + 8) -                : (SIZEOF_NONRESIDENT + 8); +    new_asize = (new_aflags & (ATTR_FLAG_COMPRESSED | ATTR_FLAG_SPARSED)) ? +                  (SIZEOF_NONRESIDENT_EX + 8) : +                  (SIZEOF_NONRESIDENT + 8);      if (!mi_resize_attr(mi, attr, new_asize - le32_to_cpu(attr->size)))          return -EOPNOTSUPP; @@ -2965,14 +2965,14 @@ bool ni_remove_name_undo(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,  {      struct ntfs_sb_info *sbi = ni->mi.sbi;      struct ATTRIB *attr; -    u16 de_key_size = de2 ? le16_to_cpu(de2->key_size) : 0; +    u16 de_key_size;      switch (undo_step) {      case 4: +        de_key_size = le16_to_cpu(de2->key_size);          if (ni_insert_resident(ni, de_key_size, ATTR_NAME, NULL, 0, -                       &attr, NULL, NULL)) { +                       &attr, NULL, NULL))              return false; -        }          memcpy(Add2Ptr(attr, SIZEOF_RESIDENT), de2 + 1, de_key_size);          mi_get_ref(&ni->mi, &de2->ref); @@ -2981,19 +2981,16 @@ bool ni_remove_name_undo(struct ntfs_inode *dir_ni, struct ntfs_inode *ni,          de2->flags = 0;          de2->res = 0; -        if (indx_insert_entry(&dir_ni->dir, dir_ni, de2, sbi, NULL, -                      1)) { +        if (indx_insert_entry(&dir_ni->dir, dir_ni, de2, sbi, NULL, 1))              return false; -        }          fallthrough;      case 2:          de_key_size = le16_to_cpu(de->key_size);          if (ni_insert_resident(ni, de_key_size, ATTR_NAME, NULL, 0, -                       &attr, NULL, NULL)) { +                       &attr, NULL, NULL))              return false; -        }          memcpy(Add2Ptr(attr, SIZEOF_RESIDENT), de + 1, de_key_size);          mi_get_ref(&ni->mi, &de->ref); @@ -3162,9 +3159,9 @@ static bool ni_update_parent(struct ntfs_inode *ni, struct NTFS_DUP_INFO *dup,              u64 data_size = le64_to_cpu(attr->nres.data_size);              __le64 valid_le; -            dup->alloc_size = is_attr_ext(attr) -                          ? attr->nres.total_size -                          : attr->nres.alloc_size; +            dup->alloc_size = is_attr_ext(attr) ? +                            attr->nres.total_size : +                            attr->nres.alloc_size;              dup->data_size = attr->nres.data_size;              if (new_valid > data_size) diff --git a/fs/ntfs3/fslog.c b/fs/ntfs3/fslog.c index bf7396447284..57762c5fe68b 100644 --- a/fs/ntfs3/fslog.c +++ b/fs/ntfs3/fslog.c @@ -827,10 +827,10 @@ static inline struct RESTART_TABLE *extend_rsttbl(struct RESTART_TABLE *tbl,      memcpy(rt + 1, tbl + 1, esize * used); -    rt->free_goal = free_goal == ~0u -                ? cpu_to_le32(~0u) -                : cpu_to_le32(sizeof(struct RESTART_TABLE) + -                          free_goal * esize); +    rt->free_goal = free_goal == ~0u ? +                      cpu_to_le32(~0u) : +                      cpu_to_le32(sizeof(struct RESTART_TABLE) + +                        free_goal * esize);      if (tbl->first_free) {          rt->first_free = tbl->first_free; @@ -1089,9 +1089,9 @@ static inline u64 base_lsn(struct ntfs_log *log,              (lsn < (lsn_to_vbo(log, h_lsn) & ~log->page_mask) ? 1 : 0))             << log->file_data_bits) +            ((((is_log_record_end(hdr) && -              h_lsn <= le64_to_cpu(hdr->record_hdr.last_end_lsn)) -                 ? le16_to_cpu(hdr->record_hdr.next_record_off) -                 : log->page_size) + +              h_lsn <= le64_to_cpu(hdr->record_hdr.last_end_lsn)) ? +                   le16_to_cpu(hdr->record_hdr.next_record_off) : +                   log->page_size) +              lsn) >>             3); @@ -1298,9 +1298,9 @@ static void log_init_pg_hdr(struct ntfs_log *log, u32 sys_page_size,      if (!log->clst_per_page)          log->clst_per_page = 1; -    log->first_page = major_ver >= 2 -                  ? 0x22 * page_size -                  : ((sys_page_size << 1) + (page_size << 1)); +    log->first_page = major_ver >= 2 ? +                    0x22 * page_size : +                    ((sys_page_size << 1) + (page_size << 1));      log->major_ver = major_ver;      log->minor_ver = minor_ver;  } @@ -1512,20 +1512,19 @@ static u32 current_log_avail(struct ntfs_log *log)       * have to compute the free range.       * If there is no oldest lsn then start at the first page of the file.       */ -    oldest_off = (log->l_flags & NTFSLOG_NO_OLDEST_LSN) -                 ? log->first_page -                 : (log->oldest_lsn_off & ~log->sys_page_mask); +    oldest_off = (log->l_flags & NTFSLOG_NO_OLDEST_LSN) ? +                   log->first_page : +                   (log->oldest_lsn_off & ~log->sys_page_mask);      /*       * We will use the next log page offset to compute the next free page.       * If we are going to reuse this page go to the next page.       * If we are at the first page then use the end of the file.       */ -    next_free_off = (log->l_flags & NTFSLOG_REUSE_TAIL) -                ? log->next_page + log->page_size -                : log->next_page == log->first_page -                      ? log->l_size -                      : log->next_page; +    next_free_off = (log->l_flags & NTFSLOG_REUSE_TAIL) ? +                      log->next_page + log->page_size : +            log->next_page == log->first_page ? log->l_size : +                                  log->next_page;      /* If the two offsets are the same then there is no available space. */      if (oldest_off == next_free_off) @@ -1535,9 +1534,9 @@ static u32 current_log_avail(struct ntfs_log *log)       * this range from the total available pages.       */      free_bytes = -        oldest_off < next_free_off -            ? log->total_avail_pages - (next_free_off - oldest_off) -            : oldest_off - next_free_off; +        oldest_off < next_free_off ? +                  log->total_avail_pages - (next_free_off - oldest_off) : +                  oldest_off - next_free_off;      free_bytes >>= log->page_bits;      return free_bytes * log->reserved; @@ -1671,8 +1670,8 @@ static int last_log_lsn(struct ntfs_log *log)      }      best_lsn1 = first_tail ? base_lsn(log, first_tail, first_file_off) : 0; -    best_lsn2 = -        second_tail ? base_lsn(log, second_tail, second_file_off) : 0; +    best_lsn2 = second_tail ? base_lsn(log, second_tail, second_file_off) : +                    0;      if (first_tail && second_tail) {          if (best_lsn1 > best_lsn2) { @@ -1767,8 +1766,8 @@ static int last_log_lsn(struct ntfs_log *log)      page_cnt = page_pos = 1; -    curpage_off = seq_base == log->seq_num ? min(log->next_page, page_off) -                           : log->next_page; +    curpage_off = seq_base == log->seq_num ? min(log->next_page, page_off) : +                               log->next_page;      wrapped_file =          curpage_off == log->first_page && @@ -1826,9 +1825,9 @@ static int last_log_lsn(struct ntfs_log *log)                  le64_to_cpu(cur_page->record_hdr.last_end_lsn) &&              ((lsn_cur >> log->file_data_bits) +               ((curpage_off < -               (lsn_to_vbo(log, lsn_cur) & ~log->page_mask)) -                  ? 1 -                  : 0)) != expected_seq) { +               (lsn_to_vbo(log, lsn_cur) & ~log->page_mask)) ? +                    1 : +                    0)) != expected_seq) {              goto check_tail;          } @@ -2642,9 +2641,10 @@ static inline bool check_index_root(const struct ATTRIB *attr,  {      bool ret;      const struct INDEX_ROOT *root = resident_data(attr); -    u8 index_bits = le32_to_cpu(root->index_block_size) >= sbi->cluster_size -                ? sbi->cluster_bits -                : SECTOR_SHIFT; +    u8 index_bits = le32_to_cpu(root->index_block_size) >= +                    sbi->cluster_size ? +                      sbi->cluster_bits : +                      SECTOR_SHIFT;      u8 block_clst = root->index_block_clst;      if (le32_to_cpu(attr->res.data_size) < sizeof(struct INDEX_ROOT) || @@ -3683,7 +3683,8 @@ static int do_action(struct ntfs_log *log, struct OPEN_ATTR_ENRTY *oe,      if (a_dirty) {          attr = oa->attr; -        err = ntfs_sb_write_run(sbi, oa->run1, vbo, buffer_le, bytes, 0); +        err = ntfs_sb_write_run(sbi, oa->run1, vbo, buffer_le, bytes, +                    0);          if (err)              goto out;      } @@ -3768,11 +3769,10 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)      if (!log)          return -ENOMEM; -    memset(&rst_info, 0, sizeof(struct restart_info)); -      log->ni = ni;      log->l_size = l_size;      log->one_page_buf = kmalloc(page_size, GFP_NOFS); +      if (!log->one_page_buf) {          err = -ENOMEM;          goto out; @@ -3783,6 +3783,7 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)      log->page_bits = blksize_bits(page_size);      /* Look for a restart area on the disk. */ +    memset(&rst_info, 0, sizeof(struct restart_info));      err = log_read_rst(log, l_size, true, &rst_info);      if (err)          goto out; @@ -3859,10 +3860,10 @@ int log_replay(struct ntfs_inode *ni, bool *initialized)      log->init_ra = !!rst_info.vbo;      /* If we have a valid page then grab a pointer to the restart area. */ -    ra2 = rst_info.valid_page -              ? Add2Ptr(rst_info.r_page, -                le16_to_cpu(rst_info.r_page->ra_off)) -              : NULL; +    ra2 = rst_info.valid_page ? +                Add2Ptr(rst_info.r_page, +                  le16_to_cpu(rst_info.r_page->ra_off)) : +                NULL;      if (rst_info.chkdsk_was_run ||          (ra2 && ra2->client_idx[1] == LFS_NO_CLIENT_LE)) { diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index 9ed9dd0d8edf..0a82b1bf3ec2 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -172,8 +172,8 @@ int ntfs_fix_post_read(struct NTFS_RECORD_HEADER *rhdr, size_t bytes,      u16 sample, fo, fn;      fo = le16_to_cpu(rhdr->fix_off); -    fn = simple ? ((bytes >> SECTOR_SHIFT) + 1) -            : le16_to_cpu(rhdr->fix_num); +    fn = simple ? ((bytes >> SECTOR_SHIFT) + 1) : +                le16_to_cpu(rhdr->fix_num);      /* Check errors. */      if ((fo & 1) || fo + fn * sizeof(short) > SECTOR_SIZE || !fn-- || @@ -849,14 +849,13 @@ void ntfs_update_mftmirr(struct ntfs_sb_info *sbi, int wait)      u32 blocksize, bytes;      sector_t block1, block2; -    if (!sb) +    /* +     * sb can be NULL here. In this case sbi->flags should be 0 too. +     */ +    if (!sb || !(sbi->flags & NTFS_FLAGS_MFTMIRR))          return;      blocksize = sb->s_blocksize; - -    if (!(sbi->flags & NTFS_FLAGS_MFTMIRR)) -        return; -      bytes = sbi->mft.recs_mirr << sbi->record_bits;      block1 = sbi->mft.lbo >> sb->s_blocksize_bits;      block2 = sbi->mft.lbo2 >> sb->s_blocksize_bits; diff --git a/fs/ntfs3/index.c b/fs/ntfs3/index.c index 5d1ec0124137..0a48d2d67219 100644 --- a/fs/ntfs3/index.c +++ b/fs/ntfs3/index.c @@ -431,8 +431,9 @@ static int scan_nres_bitmap(struct ntfs_inode *ni, struct ATTRIB *bitmap,          if (vbo + blocksize > data_size)              nbits = 8 * (data_size - vbo); -        ok = nbits > from ? (*fn)((ulong *)bh->b_data, from, nbits, ret) -                  : false; +        ok = nbits > from ? +                   (*fn)((ulong *)bh->b_data, from, nbits, ret) : +                   false;          put_bh(bh);          if (ok) { @@ -764,8 +765,7 @@ static struct NTFS_DE *hdr_find_e(const struct ntfs_index *indx,                  return NULL;              max_idx = 0; -            table_size = min(table_size * 2, -                     (int)ARRAY_SIZE(offs)); +            table_size = min(table_size * 2, (int)ARRAY_SIZE(offs));              goto fill_table;          }      } else if (diff2 < 0) { @@ -1170,8 +1170,10 @@ int indx_find(struct ntfs_index *indx, struct ntfs_inode *ni,          /* Read next level. */          err = indx_read(indx, ni, de_get_vbn(e), &node); -        if (err) +        if (err) { +            /* io error? */              return err; +        }          /* Lookup entry that is <= to the search value. */          e = hdr_find_e(indx, &node->index->ihdr, key, key_len, ctx, @@ -1673,9 +1675,9 @@ static int indx_insert_into_root(struct ntfs_index *indx, struct ntfs_inode *ni,      mi->dirty = true;      /* Create alloc and bitmap attributes (if not). */ -    err = run_is_empty(&indx->alloc_run) -              ? indx_create_allocate(indx, ni, &new_vbn) -              : indx_add_allocate(indx, ni, &new_vbn); +    err = run_is_empty(&indx->alloc_run) ? +                indx_create_allocate(indx, ni, &new_vbn) : +                indx_add_allocate(indx, ni, &new_vbn);      /* Layout of record may be changed, so rescan root. */      root = indx_get_root(indx, ni, &attr, &mi); @@ -1865,9 +1867,9 @@ indx_insert_into_buffer(struct ntfs_index *indx, struct ntfs_inode *ni,      hdr_insert_de(indx,                (*indx->cmp)(new_de + 1, le16_to_cpu(new_de->key_size),                     up_e + 1, le16_to_cpu(up_e->key_size), -                   ctx) < 0 -                  ? hdr2 -                  : hdr1, +                   ctx) < 0 ? +                    hdr2 : +                    hdr1,                new_de, NULL, ctx);      indx_mark_used(indx, ni, new_vbn >> indx->idx2vbn_bits); @@ -2337,8 +2339,8 @@ int indx_delete_entry(struct ntfs_index *indx, struct ntfs_inode *ni,              err = level ? indx_insert_into_buffer(indx, ni, root,                                    re, ctx,                                    fnd->level - 1, -                                  fnd) -                    : indx_insert_into_root(indx, ni, re, e, +                                  fnd) : +                        indx_insert_into_root(indx, ni, re, e,                                  ctx, fnd, 0);              kfree(re); diff --git a/fs/ntfs3/inode.c b/fs/ntfs3/inode.c index 752ad17685c0..f64b1e001501 100644 --- a/fs/ntfs3/inode.c +++ b/fs/ntfs3/inode.c @@ -262,8 +262,8 @@ static struct inode *ntfs_read_mft(struct inode *inode,          if (!attr->nres.alloc_size)              goto next_attr; -        run = ino == MFT_REC_BITMAP ? &sbi->used.bitmap.run -                        : &ni->file.run; +        run = ino == MFT_REC_BITMAP ? &sbi->used.bitmap.run : +                            &ni->file.run;          break;      case ATTR_ROOT: @@ -290,9 +290,9 @@ static struct inode *ntfs_read_mft(struct inode *inode,          if (err)              goto out; -        mode = sb->s_root -                   ? (S_IFDIR | (0777 & sbi->options->fs_dmask_inv)) -                   : (S_IFDIR | 0777); +        mode = sb->s_root ? +                     (S_IFDIR | (0777 & sbi->options->fs_dmask_inv)) : +                     (S_IFDIR | 0777);          goto next_attr;      case ATTR_ALLOC: @@ -449,8 +449,8 @@ static struct inode *ntfs_read_mft(struct inode *inode,          ni->std_fa &= ~FILE_ATTRIBUTE_DIRECTORY;          inode->i_op = &ntfs_file_inode_operations;          inode->i_fop = &ntfs_file_operations; -        inode->i_mapping->a_ops = -            is_compressed(ni) ? &ntfs_aops_cmpr : &ntfs_aops; +        inode->i_mapping->a_ops = is_compressed(ni) ? &ntfs_aops_cmpr : +                                    &ntfs_aops;          if (ino != MFT_REC_MFT)              init_rwsem(&ni->file.run_lock);      } else if (S_ISCHR(mode) || S_ISBLK(mode) || S_ISFIFO(mode) || @@ -786,8 +786,8 @@ static ssize_t ntfs_direct_IO(struct kiocb *iocb, struct iov_iter *iter)      }      ret = blockdev_direct_IO(iocb, inode, iter, -                 wr ? ntfs_get_block_direct_IO_W -                    : ntfs_get_block_direct_IO_R); +                 wr ? ntfs_get_block_direct_IO_W : +                        ntfs_get_block_direct_IO_R);      if (ret > 0)          end = vbo + ret; @@ -846,7 +846,7 @@ int ntfs_set_size(struct inode *inode, u64 new_size)  }  static int ntfs_resident_writepage(struct page *page, -        struct writeback_control *wbc, void *data) +                   struct writeback_control *wbc, void *data)  {      struct address_space *mapping = data;      struct ntfs_inode *ni = ntfs_i(mapping->host); @@ -887,8 +887,8 @@ int ntfs_write_begin(struct file *file, struct address_space *mapping,      *pagep = NULL;      if (is_resident(ni)) { -        struct page *page = grab_cache_page_write_begin( -            mapping, pos >> PAGE_SHIFT); +        struct page *page = +            grab_cache_page_write_begin(mapping, pos >> PAGE_SHIFT);          if (!page) {              err = -ENOMEM; @@ -920,9 +920,8 @@ int ntfs_write_begin(struct file *file, struct address_space *mapping,  /*   * ntfs_write_end - Address_space_operations::write_end.   */ -int ntfs_write_end(struct file *file, struct address_space *mapping, -           loff_t pos, u32 len, u32 copied, struct page *page, -           void *fsdata) +int ntfs_write_end(struct file *file, struct address_space *mapping, loff_t pos, +           u32 len, u32 copied, struct page *page, void *fsdata)  {      struct inode *inode = mapping->host;      struct ntfs_inode *ni = ntfs_i(inode); @@ -1605,8 +1604,8 @@ struct inode *ntfs_create_inode(struct user_namespace *mnt_userns,      } else if (S_ISREG(mode)) {          inode->i_op = &ntfs_file_inode_operations;          inode->i_fop = &ntfs_file_operations; -        inode->i_mapping->a_ops = -            is_compressed(ni) ? &ntfs_aops_cmpr : &ntfs_aops; +        inode->i_mapping->a_ops = is_compressed(ni) ? &ntfs_aops_cmpr : +                                    &ntfs_aops;          init_rwsem(&ni->file.run_lock);      } else {          inode->i_op = &ntfs_special_inode_operations; diff --git a/fs/ntfs3/lznt.c b/fs/ntfs3/lznt.c index 28f654561f27..61e161c7c567 100644 --- a/fs/ntfs3/lznt.c +++ b/fs/ntfs3/lznt.c @@ -296,8 +296,8 @@ static inline ssize_t decompress_chunk(u8 *unc, u8 *unc_end, const u8 *cmpr,   */  struct lznt *get_lznt_ctx(int level)  { -    struct lznt *r = kzalloc(level ? offsetof(struct lznt, hash) -                       : sizeof(struct lznt), +    struct lznt *r = kzalloc(level ? offsetof(struct lznt, hash) : +                           sizeof(struct lznt),                   GFP_NOFS);      if (r) @@ -392,9 +392,9 @@ ssize_t decompress_lznt(const void *cmpr, size_t cmpr_size, void *unc,              unc_use = err;          } else {              /* This chunk does not contain compressed data. */ -            unc_use = unc_chunk + LZNT_CHUNK_SIZE > unc_end -                      ? unc_end - unc_chunk -                      : LZNT_CHUNK_SIZE; +            unc_use = unc_chunk + LZNT_CHUNK_SIZE > unc_end ? +                        unc_end - unc_chunk : +                        LZNT_CHUNK_SIZE;              if (cmpr_chunk + sizeof(chunk_hdr) + unc_use >                  cmpr_end) { diff --git a/fs/ntfs3/namei.c b/fs/ntfs3/namei.c index 8b68ead5cc1f..5d5a251334a1 100644 --- a/fs/ntfs3/namei.c +++ b/fs/ntfs3/namei.c @@ -433,8 +433,8 @@ static int ntfs_atomic_open(struct inode *dir, struct dentry *dentry,      inode = ntfs_create_inode(&init_user_ns, dir, dentry, uni, mode, 0,                    NULL, 0, fnd); -    err = IS_ERR(inode) ? PTR_ERR(inode) -                : finish_open(file, dentry, ntfs_file_open); +    err = IS_ERR(inode) ? PTR_ERR(inode) : +                    finish_open(file, dentry, ntfs_file_open);      dput(d);  out2: diff --git a/fs/ntfs3/ntfs_fs.h b/fs/ntfs3/ntfs_fs.h index b7782107ce8a..9a2d965f183e 100644 --- a/fs/ntfs3/ntfs_fs.h +++ b/fs/ntfs3/ntfs_fs.h @@ -338,7 +338,7 @@ enum ntfs_inode_mutex_lock_class {  };  /* - * sturct ntfs_inode + * struct ntfs_inode   *   * Ntfs inode - extends linux inode. consists of one or more MFT inodes.   */ @@ -697,9 +697,8 @@ int ntfs_get_block(struct inode *inode, sector_t vbn,             struct buffer_head *bh_result, int create);  int ntfs_write_begin(struct file *file, struct address_space *mapping,               loff_t pos, u32 len, struct page **pagep, void **fsdata); -int ntfs_write_end(struct file *file, struct address_space *mapping, -           loff_t pos, u32 len, u32 copied, struct page *page, -           void *fsdata); +int ntfs_write_end(struct file *file, struct address_space *mapping, loff_t pos, +           u32 len, u32 copied, struct page *page, void *fsdata);  int ntfs3_write_inode(struct inode *inode, struct writeback_control *wbc);  int ntfs_sync_inode(struct inode *inode);  int ntfs_flush_inodes(struct super_block *sb, struct inode *i1, @@ -856,7 +855,7 @@ unsigned long ntfs_names_hash(const u16 *name, size_t len, const u16 *upcase,  /* globals from xattr.c */  #ifdef CONFIG_NTFS3_FS_POSIX_ACL  struct posix_acl *ntfs_get_acl(struct user_namespace *mnt_userns, -         struct dentry *dentry, int type); +                   struct dentry *dentry, int type);  int ntfs_set_acl(struct user_namespace *mnt_userns, struct dentry *dentry,           struct posix_acl *acl, int type);  int ntfs_init_acl(struct user_namespace *mnt_userns, struct inode *inode, diff --git a/fs/ntfs3/record.c b/fs/ntfs3/record.c index 0603169ee8a0..2a281cead2bc 100644 --- a/fs/ntfs3/record.c +++ b/fs/ntfs3/record.c @@ -419,10 +419,9 @@ struct ATTRIB *mi_insert_attr(struct mft_inode *mi, enum ATTR_TYPE type,      struct ntfs_sb_info *sbi = mi->sbi;      u32 used = le32_to_cpu(rec->used);      const u16 *upcase = sbi->upcase; -    int diff;      /* Can we insert mi attribute? */ -    if (used + asize > mi->sbi->record_size) +    if (used + asize > sbi->record_size)          return NULL;      /* @@ -431,7 +430,7 @@ struct ATTRIB *mi_insert_attr(struct mft_inode *mi, enum ATTR_TYPE type,       */      attr = NULL;      while ((attr = mi_enum_attr(mi, attr))) { -        diff = compare_attr(attr, type, name, name_len, upcase); +        int diff = compare_attr(attr, type, name, name_len, upcase);          if (diff < 0)              continue; @@ -442,9 +441,11 @@ struct ATTRIB *mi_insert_attr(struct mft_inode *mi, enum ATTR_TYPE type,      }      if (!attr) { -        tail = 8; /* Not used, just to suppress warning. */ +        /* Append. */ +        tail = 8;          attr = Add2Ptr(rec, used - 8);      } else { +        /* Insert before 'attr'. */          tail = used - PtrOffset(rec, attr);      } diff --git a/fs/ntfs3/run.c b/fs/ntfs3/run.c index a5af71cd8d14..47612d16c027 100644 --- a/fs/ntfs3/run.c +++ b/fs/ntfs3/run.c @@ -433,9 +433,9 @@ bool run_add_entry(struct runs_tree *run, CLST vcn, CLST lcn, CLST len,              should_add_tail = Tovcn < r->len;              if (should_add_tail) { -                tail_lcn = r->lcn == SPARSE_LCN -                           ? SPARSE_LCN -                           : (r->lcn + Tovcn); +                tail_lcn = r->lcn == SPARSE_LCN ? +                             SPARSE_LCN : +                             (r->lcn + Tovcn);                  tail_vcn = r->vcn + Tovcn;                  tail_len = r->len - Tovcn;              } diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index d7bec9b28a42..6a412826b43d 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -39,10 +39,10 @@   * To mount large volumes as ntfs one should use large cluster size (up to 2M)   * The maximum volume size in this case is 2^32 * 2^21 = 2^53 = 8P   * - *     ntfs limits, cluster size is 2M (2^31) + *     ntfs limits, cluster size is 2M (2^21)   * ----------------------------------------------------------------------------- - * | < 8P, 2^54    |  < 2^32  |  yes     |  yes   |   yes |  yes   |  yes   | - * | > 8P, 2^54    |  > 2^32  |  no      |  no    |   yes |  yes   |  yes   | + * | < 8P, 2^53    |  < 2^32  |  yes     |  yes   |   yes |  yes   |  yes   | + * | > 8P, 2^53    |  > 2^32  |  no      |  no    |   yes |  yes   |  yes   |   * ----------------------------------------------------------|------------------   *   */ @@ -115,9 +115,9 @@ void ntfs_inode_printk(struct inode *inode, const char *fmt, ...)          return;      /* Use static allocated buffer, if possible. */ -    name = atomic_dec_and_test(&s_name_buf_cnt) -               ? s_name_buf -               : kmalloc(sizeof(s_name_buf), GFP_NOFS); +    name = atomic_dec_and_test(&s_name_buf_cnt) ? +                 s_name_buf : +                 kmalloc(sizeof(s_name_buf), GFP_NOFS);      if (name) {          struct dentry *de = d_find_alias(inode); @@ -369,7 +369,8 @@ static int ntfs_fs_parse_param(struct fs_context *fc,  #ifdef CONFIG_NTFS3_FS_POSIX_ACL              fc->sb_flags |= SB_POSIXACL;  #else -            return invalf(fc, "ntfs3: Support for ACL not compiled in!"); +            return invalf( +                fc, "ntfs3: Support for ACL not compiled in!");  #endif          else              fc->sb_flags &= ~SB_POSIXACL; @@ -404,24 +405,29 @@ static int ntfs_fs_reconfigure(struct fs_context *fc)      ro_rw = sb_rdonly(sb) && !(fc->sb_flags & SB_RDONLY);      if (ro_rw && (sbi->flags & NTFS_FLAGS_NEED_REPLAY)) { -        errorf(fc, "ntfs3: Couldn't remount rw because journal is not replayed. Please umount/remount instead\n"); +        errorf(fc, +               "ntfs3: Couldn't remount rw because journal is not replayed. Please umount/remount instead\n");          return -EINVAL;      }      new_opts->nls = ntfs_load_nls(new_opts->nls_name);      if (IS_ERR(new_opts->nls)) {          new_opts->nls = NULL; -        errorf(fc, "ntfs3: Cannot load iocharset %s", new_opts->nls_name); +        errorf(fc, "ntfs3: Cannot load iocharset %s", +               new_opts->nls_name);          return -EINVAL;      }      if (new_opts->nls != sbi->options->nls) -        return invalf(fc, "ntfs3: Cannot use different iocharset when remounting!"); +        return invalf( +            fc, +            "ntfs3: Cannot use different iocharset when remounting!");      sync_filesystem(sb);      if (ro_rw && (sbi->volume.flags & VOLUME_FLAG_DIRTY) &&          !new_opts->force) { -        errorf(fc, "ntfs3: Volume is dirty and \"force\" flag is not set!"); +        errorf(fc, +               "ntfs3: Volume is dirty and \"force\" flag is not set!");          return -EINVAL;      } @@ -539,10 +545,8 @@ static int ntfs_show_options(struct seq_file *m, struct dentry *root)      struct ntfs_mount_options *opts = sbi->options;      struct user_namespace *user_ns = seq_user_ns(m); -    seq_printf(m, ",uid=%u", -          from_kuid_munged(user_ns, opts->fs_uid)); -    seq_printf(m, ",gid=%u", -          from_kgid_munged(user_ns, opts->fs_gid)); +    seq_printf(m, ",uid=%u", from_kuid_munged(user_ns, opts->fs_uid)); +    seq_printf(m, ",gid=%u", from_kgid_munged(user_ns, opts->fs_gid));      if (opts->fmask)          seq_printf(m, ",fmask=%04o", opts->fs_fmask_inv ^ 0xffff);      if (opts->dmask) @@ -699,7 +703,7 @@ static u32 true_sectors_per_clst(const struct NTFS_BOOT *boot)      if (boot->sectors_per_clusters <= 0x80)          return boot->sectors_per_clusters;      if (boot->sectors_per_clusters >= 0xf4) /* limit shift to 2MB max */ -        return 1U << -(s8)boot->sectors_per_clusters; +        return 1U << (-(s8)boot->sectors_per_clusters);      return -EINVAL;  } @@ -717,6 +721,7 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,      struct buffer_head *bh;      struct MFT_REC *rec;      u16 fn, ao; +    u8 cluster_bits;      sbi->volume.blocks = dev_size >> PAGE_SHIFT; @@ -784,7 +789,7 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,      if (boot_sector_size != sector_size) {          ntfs_warn(              sb, -            "Different NTFS sector size (%u) and media sector size (%u)", +            "Different NTFS sector size (%u) and media sector size (%u).",              boot_sector_size, sector_size);          dev_size += sector_size - 1;      } @@ -792,8 +797,8 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,      sbi->cluster_size = boot_sector_size * sct_per_clst;      sbi->cluster_bits = blksize_bits(sbi->cluster_size); -    sbi->mft.lbo = mlcn << sbi->cluster_bits; -    sbi->mft.lbo2 = mlcn2 << sbi->cluster_bits; +    sbi->mft.lbo = mlcn << cluster_bits; +    sbi->mft.lbo2 = mlcn2 << cluster_bits;      /* Compare boot's cluster and sector. */      if (sbi->cluster_size < boot_sector_size) @@ -804,7 +809,7 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,          /* No way to use ntfs_get_block in this case. */          ntfs_err(              sb, -            "Failed to mount 'cause NTFS's cluster size (%u) is less than media sector size (%u)", +            "Failed to mount 'cause NTFS's cluster size (%u) is less than media sector size (%u).",              sbi->cluster_size, sector_size);          goto out;      } @@ -840,18 +845,18 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,          gb0 = format_size_gb(dev_size, &mb0);          ntfs_warn(              sb, -            "RAW NTFS volume: Filesystem size %u.%02u Gb > volume size %u.%02u Gb. Mount in read-only", +            "RAW NTFS volume: Filesystem size %u.%02u Gb > volume size %u.%02u Gb. Mount in read-only.",              gb, mb, gb0, mb0);          sb->s_flags |= SB_RDONLY;      } -    clusters = sbi->volume.size >> sbi->cluster_bits; +    clusters = sbi->volume.size >> cluster_bits;  #ifndef CONFIG_NTFS3_64BIT_CLUSTER      /* 32 bits per cluster. */      if (clusters >> 32) {          ntfs_notice(              sb, -            "NTFS %u.%02u Gb is too big to use 32 bits per cluster", +            "NTFS %u.%02u Gb is too big to use 32 bits per cluster.",              gb, mb);          goto out;      } @@ -885,17 +890,17 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,      sbi->volume.blocks = sbi->volume.size >> sb->s_blocksize_bits;      /* Maximum size for normal files. */ -    sbi->maxbytes = (clusters << sbi->cluster_bits) - 1; +    sbi->maxbytes = (clusters << cluster_bits) - 1;  #ifdef CONFIG_NTFS3_64BIT_CLUSTER -    if (clusters >= (1ull << (64 - sbi->cluster_bits))) +    if (clusters >= (1ull << (64 - cluster_bits)))          sbi->maxbytes = -1;      sbi->maxbytes_sparse = -1;      sb->s_maxbytes = MAX_LFS_FILESIZE;  #else      /* Maximum size for sparse file. */ -    sbi->maxbytes_sparse = (1ull << (sbi->cluster_bits + 32)) - 1; -    sb->s_maxbytes = 0xFFFFFFFFull << sbi->cluster_bits; +    sbi->maxbytes_sparse = (1ull << (cluster_bits + 32)) - 1; +    sb->s_maxbytes = 0xFFFFFFFFull << cluster_bits;  #endif      /* @@ -903,7 +908,7 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,       * It would be nice if we are able to allocate 1/8 of       * total clusters for MFT but not more then 512 MB.       */ -    sbi->zone_max = min_t(CLST, 0x20000000 >> sbi->cluster_bits, clusters >> 3); +    sbi->zone_max = min_t(CLST, 0x20000000 >> cluster_bits, clusters >> 3);      err = 0; @@ -1433,7 +1438,7 @@ static const struct fs_context_operations ntfs_context_ops = {  };  /* - * ntfs_init_fs_context - Initialize spi and opts + * ntfs_init_fs_context - Initialize sbi and opts   *   * This will called when mount/remount. We will first initialize   * options so that if remount we can use just that. @@ -1506,7 +1511,8 @@ static int __init init_ntfs_fs(void)      if (IS_ENABLED(CONFIG_NTFS3_FS_POSIX_ACL))          pr_info("ntfs3: Enabled Linux POSIX ACLs support\n");      if (IS_ENABLED(CONFIG_NTFS3_64BIT_CLUSTER)) -        pr_notice("ntfs3: Warning: Activated 64 bits per cluster. Windows does not support this\n"); +        pr_notice( +            "ntfs3: Warning: Activated 64 bits per cluster. Windows does not support this\n");      if (IS_ENABLED(CONFIG_NTFS3_LZX_XPRESS))          pr_info("ntfs3: Read-only LZX/Xpress compression included\n"); @@ -1549,7 +1555,9 @@ MODULE_DESCRIPTION("ntfs3 read/write filesystem");  MODULE_INFO(behaviour, "Enabled Linux POSIX ACLs support");  #endif  #ifdef CONFIG_NTFS3_64BIT_CLUSTER -MODULE_INFO(cluster, "Warning: Activated 64 bits per cluster. Windows does not support this"); +MODULE_INFO( +    cluster, +    "Warning: Activated 64 bits per cluster. Windows does not support this");  #endif  #ifdef CONFIG_NTFS3_LZX_XPRESS  MODULE_INFO(compression, "Read-only lzx/xpress compression included"); diff --git a/fs/ntfs3/xattr.c b/fs/ntfs3/xattr.c index 95c479d7ebba..0a6d2ec8c340 100644 --- a/fs/ntfs3/xattr.c +++ b/fs/ntfs3/xattr.c @@ -23,8 +23,8 @@  static inline size_t unpacked_ea_size(const struct EA_FULL *ea)  { -    return ea->size ? le32_to_cpu(ea->size) -            : ALIGN(struct_size(ea, name, +    return ea->size ? le32_to_cpu(ea->size) : +                ALIGN(struct_size(ea, name,                          1 + ea->name_len +                              le16_to_cpu(ea->elength)),                  4); From patchwork Wed Feb 15 13:39:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 57557 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp201661wrn; Wed, 15 Feb 2023 05:53:03 -0800 (PST) X-Google-Smtp-Source: AK7set8rECdbJ1STgpw+bXhmWFPN8ymZgG2tBAKLoETokl3l2wpt5bswwK32dQwGezK/QCObn5ll X-Received: by 2002:aa7:c6d7:0:b0:4ac:54d4:b011 with SMTP id b23-20020aa7c6d7000000b004ac54d4b011mr1831762eds.21.1676469183165; Wed, 15 Feb 2023 05:53:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676469183; cv=none; d=google.com; s=arc-20160816; b=OQ0kucxKHeIYKbKaSqDraoTzvLqsXpZzGcbnogu/kSqrL3k4uWf0nymn+pbobuna4h UnbBT2EnOdmQ59AjlTNR8OwU3LRkwhSAZi7XFPei/WaiQeufz7qnY1chRPYwtsSDqPa8 lTmGTbYWj41V0UFaalOX7TO1dbiMIvOl0eM6hOyX3a+Y5CymeVhXcmx4aFw5CgNjDq/a +Yc+SLALxjdkwGDo4b7XMBhh5dIAJpdPbNl86cGHcfMGZCjwf5mI+lFk+j2FBuHlC9Z3 NtyVwH9C+wJjafSSIyKhCkIeIULkITfP7mLOLaaj5/7CcgDk7AHObYa+cfRuGRn0Q4HZ 1Eiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature; bh=rB9oY1q3nHZkv8dcWTH7MJPs0yxT5yMPWcoRYJN6cPo=; b=WJSzC+jV7M1Ql8FqXHo5YYcD+/Qibt1AgFU5eMue4qZFzVxLYAu+D/u3vCaAPlGT6W TNIYtOzwwKccg54aQJuFsRnRttuQb8RIE5ScuBM3ZFv4kf+3YzEmm6Crb7GmyDYUdsc/ UhbSx1s3jreACTTXmwKJpTzvHKqXOvXZ8+xq8xkmJz2A6X55Hqub0PI3gZPGLoU3S6Vo tys4yquno8Wu792P92uIpi1OcBMzLSTeg2sd8sRGuk4BgAq6fExgHDTolFQRXyHXPtLU pN7t3W2bALb6tIBbFgAuw1fo2QfXpjxarGWo2rRldXpi//WxJH3mupkCmGADqQSlc56Q EPmQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b="cn/LgCeq"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b21-20020aa7df95000000b004acbde6ba79si13185074edy.324.2023.02.15.05.52.39; Wed, 15 Feb 2023 05:53:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b="cn/LgCeq"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229516AbjBONkI (ORCPT + 99 others); Wed, 15 Feb 2023 08:40:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57466 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjBONkH (ORCPT ); Wed, 15 Feb 2023 08:40:07 -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 033EB17176; Wed, 15 Feb 2023 05:40: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 9EA59214E; Wed, 15 Feb 2023 13:35:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676468148; bh=rB9oY1q3nHZkv8dcWTH7MJPs0yxT5yMPWcoRYJN6cPo=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=cn/LgCeql+gT9wllgjxGK/meqSHPBA+zy76Kk67JJ9quCUT8HpNBYuHa9A6eGrnr+ EVOphhOgRmHkX8fZqsmB4/OgHRWFXezDR+Ng6RRmNiJW0APD2RuDWahNLcxnACTlPs wVvPpX9sN+e+uhQ7g4bhxjSJ9zLBwy9CU/jPrIDY= Received: from [192.168.211.36] (192.168.211.36) 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, 15 Feb 2023 16:39:58 +0300 Message-ID: <6551ad6b-9d90-edc3-920c-347a43216cd3@paragon-software.com> Date: Wed, 15 Feb 2023 17:39:57 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: [PATCH 10/11] fs/ntfs3: Add missed "nocase" in ntfs_show_options Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.36] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757905350416055451?= X-GMAIL-MSGID: =?utf-8?q?1757905350416055451?= Sort processing ntfs3's mount options in same order they declared. Signed-off-by: Konstantin Komarov ---  fs/ntfs3/super.c | 40 +++++++++++++++++++++-------------------  1 file changed, 21 insertions(+), 19 deletions(-) @@ -364,6 +364,9 @@ static int ntfs_fs_parse_param(struct fs_context *fc,      case Opt_windows_names:          opts->windows_names = result.negated ? 0 : 1;          break; +    case Opt_showmeta: +        opts->showmeta = result.negated ? 0 : 1; +        break;      case Opt_acl:          if (!result.negated)  #ifdef CONFIG_NTFS3_FS_POSIX_ACL @@ -375,9 +378,6 @@ static int ntfs_fs_parse_param(struct fs_context *fc,          else              fc->sb_flags &= ~SB_POSIXACL;          break; -    case Opt_showmeta: -        opts->showmeta = result.negated ? 0 : 1; -        break;      case Opt_iocharset:          kfree(opts->nls_name);          opts->nls_name = param->string; @@ -547,34 +547,36 @@ static int ntfs_show_options(struct seq_file *m, struct dentry *root)      seq_printf(m, ",uid=%u", from_kuid_munged(user_ns, opts->fs_uid));      seq_printf(m, ",gid=%u", from_kgid_munged(user_ns, opts->fs_gid)); -    if (opts->fmask) -        seq_printf(m, ",fmask=%04o", opts->fs_fmask_inv ^ 0xffff);      if (opts->dmask)          seq_printf(m, ",dmask=%04o", opts->fs_dmask_inv ^ 0xffff); -    if (opts->nls) -        seq_printf(m, ",iocharset=%s", opts->nls->charset); -    else -        seq_puts(m, ",iocharset=utf8"); +    if (opts->fmask) +        seq_printf(m, ",fmask=%04o", opts->fs_fmask_inv ^ 0xffff);      if (opts->sys_immutable)          seq_puts(m, ",sys_immutable");      if (opts->discard)          seq_puts(m, ",discard"); +    if (opts->force) +        seq_puts(m, ",force");      if (opts->sparse)          seq_puts(m, ",sparse"); -    if (opts->showmeta) -        seq_puts(m, ",showmeta");      if (opts->nohidden)          seq_puts(m, ",nohidden"); -    if (opts->windows_names) -        seq_puts(m, ",windows_names");      if (opts->hide_dot_files)          seq_puts(m, ",hide_dot_files"); -    if (opts->force) -        seq_puts(m, ",force"); -    if (opts->prealloc) -        seq_puts(m, ",prealloc"); +    if (opts->windows_names) +        seq_puts(m, ",windows_names"); +    if (opts->showmeta) +        seq_puts(m, ",showmeta");      if (sb->s_flags & SB_POSIXACL)          seq_puts(m, ",acl"); +    if (opts->nls) +        seq_printf(m, ",iocharset=%s", opts->nls->charset); +    else +        seq_puts(m, ",iocharset=utf8"); +    if (opts->prealloc) +        seq_puts(m, ",prealloc"); +    if (opts->nocase) +        seq_puts(m, ",nocase");      return 0;  } diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 6a412826b43d..521ce31d67a1 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -270,11 +270,11 @@ static const struct fs_parameter_spec ntfs_fs_parameters[] = {      fsparam_flag_no("hidden",        Opt_nohidden),      fsparam_flag_no("hide_dot_files",    Opt_hide_dot_files),      fsparam_flag_no("windows_names",    Opt_windows_names), -    fsparam_flag_no("acl",            Opt_acl),      fsparam_flag_no("showmeta",        Opt_showmeta), +    fsparam_flag_no("acl",            Opt_acl), +    fsparam_string("iocharset",        Opt_iocharset),      fsparam_flag_no("prealloc",        Opt_prealloc),      fsparam_flag_no("nocase",        Opt_nocase), -    fsparam_string("iocharset",        Opt_iocharset),      {}  }; From patchwork Wed Feb 15 13:40:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Konstantin Komarov X-Patchwork-Id: 57564 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp202139wrn; Wed, 15 Feb 2023 05:54:03 -0800 (PST) X-Google-Smtp-Source: AK7set+wzUwodlq2hror9rCvvyBiPkE62BzuEBBG2RlEuJiqIuxI3fgNg7vTRr8++6FFHPZ0vljc X-Received: by 2002:aa7:cd08:0:b0:4a2:3637:5be2 with SMTP id b8-20020aa7cd08000000b004a236375be2mr2453390edw.39.1676469243661; Wed, 15 Feb 2023 05:54:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676469243; cv=none; d=google.com; s=arc-20160816; b=lZmxNi2hmFG3Inngg/cy4vqGEqtWriSN7pT55q3TK34A3+WlBIZ4uokMvgRlrzasGm 9eGK15E3Gq1PZEFNTJ185fe7XKMkHqGt7P195/YGV4bIoWw8F5sCgzQWLfW+AljuN5/z v1itWYCZY7zH3W+HHYb93NCsrIgpjYlbRxnm/svojHuGL4SR8ANYuouSvkV2t2SXm0CX RytQn6xR1T8Bgp3xacHtYnbJp7+er3ott75scl4VF9UVpjGMSo+1cZR+2IyWLv2+4ben 9B6t/Knd3UHCxMOIGxr4cN4MNpwdh75yyWZxvEL1B/2GCvl6WMtEL8FQ50rZt7BBGaBZ qrvA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:references :cc:to:from:content-language:subject:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature; bh=usEtSMeyYHIotqRXwOxKAue/XOIiNzAb2X5xWL5CEHs=; b=KIMnY54MazjwcnMrt8K9I2vASNGnL+XNj6xTEJXMy2Rxy6AE8dEPGFH5hcP8/VUx7H wKva9JT+rfHa+oEAN94sIBOCNWaoWTL/vpQZdYzuMs6CLQYQ0FUA1ZX2M2YBWfQmXtnz ubb68bZTgTaNZ10BAnBvnqRsfL91/AWRmevBDsmdcgiVkoQdEa4m8f2F3yyF2XHTRNVF TzRdH+O0ucst6Gm70Dm9e56bWE51kYBOPEwPvuiNam0N4kDmPL8KL4j1uGiEQnCEJ+st zk+gPOGUf1Gwx/wuJOr5RTW9g+FIWtX2j+Ldrj5SSRB1TvY+mdhnF8WXwPVDt39FdsB5 DeEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=EvLNcaib; dkim=pass header.i=@paragon-software.com header.s=mail header.b=iShuC2vN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l17-20020aa7cad1000000b004ab15dd69fdsi20490555edt.494.2023.02.15.05.53.40; Wed, 15 Feb 2023 05:54:03 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@paragon-software.com header.s=mail header.b=EvLNcaib; dkim=pass header.i=@paragon-software.com header.s=mail header.b=iShuC2vN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=paragon-software.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229630AbjBONkt (ORCPT + 99 others); Wed, 15 Feb 2023 08:40:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58520 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229552AbjBONkq (ORCPT ); Wed, 15 Feb 2023 08:40:46 -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 EC5E239BA7; Wed, 15 Feb 2023 05:40:32 -0800 (PST) Received: from relayfre-01.paragon-software.com (unknown [172.30.72.12]) by relayaws-01.paragon-software.com (Postfix) with ESMTPS id A6769214E; Wed, 15 Feb 2023 13:36:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676468180; bh=usEtSMeyYHIotqRXwOxKAue/XOIiNzAb2X5xWL5CEHs=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=EvLNcaibd1xUrg3e27fMIGoIUwE91WtIo38z+Jbkhq3ssj459GNS2nJUK2LRr6bQt 1BxZKj09/ACU3rLC74LodHWsNLyxi+MBA4pAM0/ue8IrvSjOjvs924IC0kQupzPpO2 OWDcVyQ3GKstUv6Gi/ppbtZd4CV/9zymLxEqQQPA= 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 0CEA31E70; Wed, 15 Feb 2023 13:40:31 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paragon-software.com; s=mail; t=1676468431; bh=usEtSMeyYHIotqRXwOxKAue/XOIiNzAb2X5xWL5CEHs=; h=Date:Subject:From:To:CC:References:In-Reply-To; b=iShuC2vNW9lGaviqam1oMitCEJxghHzmEpT82bYltbqSz2yEBgdo4Ugb1ycGkGcE1 vUtp925KMDlb8D3ZSMhOmCjBfOFqwiBMNhqI5bFqvG7Zo3x8uF2BK9JpQzFFu6QESl CZZAuzILkXtwCXlMNESk9tj1CKqJU5Da/hspyoNQ= Received: from [192.168.211.36] (192.168.211.36) 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, 15 Feb 2023 16:40:30 +0300 Message-ID: <48ebd481-dc1f-66fc-6888-5e82fd14af6e@paragon-software.com> Date: Wed, 15 Feb 2023 17:40:29 +0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.7.2 Subject: [PATCH 11/11] fs/ntfs3: Print details about mount fails Content-Language: en-US From: Konstantin Komarov To: CC: Linux Kernel Mailing List , References: In-Reply-To: X-Originating-IP: [192.168.211.36] X-ClientProxiedBy: vdlg-exch-02.paragon-software.com (172.30.1.105) To vdlg-exch-02.paragon-software.com (172.30.1.105) X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757905413457098654?= X-GMAIL-MSGID: =?utf-8?q?1757905413457098654?= Added error mesages with error codes. Minor refactoring and code formatting. Signed-off-by: Konstantin Komarov ---  fs/ntfs3/frecord.c |   2 +-  fs/ntfs3/fsntfs.c  |  40 +++++------  fs/ntfs3/super.c   | 172 +++++++++++++++++++++++++++------------------  3 files changed, 122 insertions(+), 92 deletions(-)      } @@ -796,15 +829,15 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,          dev_size += sector_size - 1;      } -    sbi->cluster_size = boot_sector_size * sct_per_clst; -    sbi->cluster_bits = blksize_bits(sbi->cluster_size); -      sbi->mft.lbo = mlcn << cluster_bits;      sbi->mft.lbo2 = mlcn2 << cluster_bits;      /* Compare boot's cluster and sector. */ -    if (sbi->cluster_size < boot_sector_size) +    if (sbi->cluster_size < boot_sector_size) { +        ntfs_err(sb, "Invalid bytes per cluster (%u).", +             sbi->cluster_size);          goto out; +    }      /* Compare boot's cluster and media sector. */      if (sbi->cluster_size < sector_size) { @@ -816,28 +849,11 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,          goto out;      } -    sbi->cluster_mask = sbi->cluster_size - 1; -    sbi->cluster_mask_inv = ~(u64)sbi->cluster_mask; -    sbi->record_size = record_size = boot->record_size < 0 -                         ? 1 << (-boot->record_size) -                         : (u32)boot->record_size -                               << sbi->cluster_bits; - -    if (record_size > MAXIMUM_BYTES_PER_MFT || record_size < SECTOR_SIZE) -        goto out; - -    sbi->record_bits = blksize_bits(record_size); -    sbi->attr_size_tr = (5 * record_size >> 4); // ~320 bytes -      sbi->max_bytes_per_attr =          record_size - ALIGN(MFTRECORD_FIXUP_OFFSET_1, 8) -          ALIGN(((record_size >> SECTOR_SHIFT) * sizeof(short)), 8) -          ALIGN(sizeof(enum ATTR_TYPE), 8); -    sbi->index_size = boot->index_size < 0 -                  ? 1u << (-boot->index_size) -                  : (u32)boot->index_size << sbi->cluster_bits; -      sbi->volume.ser_num = le64_to_cpu(boot->serial_num);      /* Warning if RAW volume. */ @@ -928,6 +944,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      int err;      struct ntfs_sb_info *sbi = sb->s_fs_info;      struct block_device *bdev = sb->s_bdev; +    struct ntfs_mount_options *options;      struct inode *inode;      struct ntfs_inode *ni;      size_t i, tt, bad_len, bad_frags; @@ -942,7 +959,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      ref.high = 0;      sbi->sb = sb; -    sbi->options = fc->fs_private; +    sbi->options = options = fc->fs_private;      fc->fs_private = NULL;      sb->s_flags |= SB_NODIRATIME;      sb->s_magic = 0x7366746e; // "ntfs" @@ -950,12 +967,12 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      sb->s_export_op = &ntfs_export_ops;      sb->s_time_gran = NTFS_TIME_GRAN; // 100 nsec      sb->s_xattr = ntfs_xattr_handlers; -    sb->s_d_op = sbi->options->nocase ? &ntfs_dentry_ops : NULL; +    sb->s_d_op = options->nocase ? &ntfs_dentry_ops : NULL; -    sbi->options->nls = ntfs_load_nls(sbi->options->nls_name); -    if (IS_ERR(sbi->options->nls)) { -        sbi->options->nls = NULL; -        errorf(fc, "Cannot load nls %s", sbi->options->nls_name); +    options->nls = ntfs_load_nls(options->nls_name); +    if (IS_ERR(options->nls)) { +        options->nls = NULL; +        errorf(fc, "Cannot load nls %s", options->nls_name);          err = -EINVAL;          goto out;      } @@ -980,8 +997,8 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      ref.seq = cpu_to_le16(MFT_REC_VOL);      inode = ntfs_iget5(sb, &ref, &NAME_VOLUME);      if (IS_ERR(inode)) { -        ntfs_err(sb, "Failed to load $Volume.");          err = PTR_ERR(inode); +        ntfs_err(sb, "Failed to load $Volume (%d).", err);          goto out;      } @@ -1007,13 +1024,9 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      }      attr = ni_find_attr(ni, attr, NULL, ATTR_VOL_INFO, NULL, 0, NULL, NULL); -    if (!attr || is_attr_ext(attr)) { -        err = -EINVAL; -        goto put_inode_out; -    } - -    info = resident_data_ex(attr, SIZEOF_ATTRIBUTE_VOLUME_INFO); -    if (!info) { +    if (!attr || is_attr_ext(attr) || +        !(info = resident_data_ex(attr, SIZEOF_ATTRIBUTE_VOLUME_INFO))) { +        ntfs_err(sb, "$Volume is corrupted.");          err = -EINVAL;          goto put_inode_out;      } @@ -1028,13 +1041,13 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      ref.seq = cpu_to_le16(MFT_REC_MIRR);      inode = ntfs_iget5(sb, &ref, &NAME_MIRROR);      if (IS_ERR(inode)) { -        ntfs_err(sb, "Failed to load $MFTMirr.");          err = PTR_ERR(inode); +        ntfs_err(sb, "Failed to load $MFTMirr (%d).", err);          goto out;      } -    sbi->mft.recs_mirr = -        ntfs_up_cluster(sbi, inode->i_size) >> sbi->record_bits; +    sbi->mft.recs_mirr = ntfs_up_cluster(sbi, inode->i_size) >> +                 sbi->record_bits;      iput(inode); @@ -1043,8 +1056,8 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      ref.seq = cpu_to_le16(MFT_REC_LOG);      inode = ntfs_iget5(sb, &ref, &NAME_LOGFILE);      if (IS_ERR(inode)) { -        ntfs_err(sb, "Failed to load \x24LogFile.");          err = PTR_ERR(inode); +        ntfs_err(sb, "Failed to load \x24LogFile (%d).", err);          goto out;      } @@ -1064,7 +1077,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)              goto out;          }      } else if (sbi->volume.flags & VOLUME_FLAG_DIRTY) { -        if (!sb_rdonly(sb) && !sbi->options->force) { +        if (!sb_rdonly(sb) && !options->force) {              ntfs_warn(                  sb,                  "volume is dirty and \"force\" flag is not set!"); @@ -1079,8 +1092,8 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      inode = ntfs_iget5(sb, &ref, &NAME_MFT);      if (IS_ERR(inode)) { -        ntfs_err(sb, "Failed to load $MFT.");          err = PTR_ERR(inode); +        ntfs_err(sb, "Failed to load $MFT (%d).", err);          goto out;      } @@ -1095,8 +1108,10 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)          goto put_inode_out;      err = ni_load_all_mi(ni); -    if (err) +    if (err) { +        ntfs_err(sb, "Failed to load $MFT's subrecords (%d).", err);          goto put_inode_out; +    }      sbi->mft.ni = ni; @@ -1105,8 +1120,8 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      ref.seq = cpu_to_le16(MFT_REC_BITMAP);      inode = ntfs_iget5(sb, &ref, &NAME_BITMAP);      if (IS_ERR(inode)) { -        ntfs_err(sb, "Failed to load $Bitmap.");          err = PTR_ERR(inode); +        ntfs_err(sb, "Failed to load $Bitmap (%d).", err);          goto out;      } @@ -1120,20 +1135,25 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      /* Check bitmap boundary. */      tt = sbi->used.bitmap.nbits;      if (inode->i_size < bitmap_size(tt)) { +        ntfs_err(sb, "$Bitmap is corrupted.");          err = -EINVAL;          goto put_inode_out;      }      err = wnd_init(&sbi->used.bitmap, sb, tt); -    if (err) +    if (err) { +        ntfs_err(sb, "Failed to initialize $Bitmap (%d).", err);          goto put_inode_out; +    }      iput(inode);      /* Compute the MFT zone. */      err = ntfs_refresh_zone(sbi); -    if (err) +    if (err) { +        ntfs_err(sb, "Failed to initialize MFT zone (%d).", err);          goto out; +    }      /* Load $BadClus. */      ref.low = cpu_to_le32(MFT_REC_BADCLUST); @@ -1178,8 +1198,8 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      ref.seq = cpu_to_le16(MFT_REC_ATTR);      inode = ntfs_iget5(sb, &ref, &NAME_ATTRDEF);      if (IS_ERR(inode)) { -        ntfs_err(sb, "Failed to load $AttrDef -> %d", err);          err = PTR_ERR(inode); +        ntfs_err(sb, "Failed to load $AttrDef (%d)", err);          goto out;      } @@ -1208,6 +1228,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)          if (IS_ERR(page)) {              err = PTR_ERR(page); +            ntfs_err(sb, "Failed to read $AttrDef (%d).", err);              goto put_inode_out;          }          memcpy(Add2Ptr(t, done), page_address(page), @@ -1215,6 +1236,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)          ntfs_unmap_page(page);          if (!idx && ATTR_STD != t->type) { +            ntfs_err(sb, "$AttrDef is corrupted.");              err = -EINVAL;              goto put_inode_out;          } @@ -1249,13 +1271,14 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      ref.seq = cpu_to_le16(MFT_REC_UPCASE);      inode = ntfs_iget5(sb, &ref, &NAME_UPCASE);      if (IS_ERR(inode)) { -        ntfs_err(sb, "Failed to load $UpCase.");          err = PTR_ERR(inode); +        ntfs_err(sb, "Failed to load $UpCase (%d).", err);          goto out;      }      if (inode->i_size != 0x10000 * sizeof(short)) {          err = -EINVAL; +        ntfs_err(sb, "$UpCase is corrupted.");          goto put_inode_out;      } @@ -1266,6 +1289,7 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)          if (IS_ERR(page)) {              err = PTR_ERR(page); +            ntfs_err(sb, "Failed to read $UpCase (%d).", err);              goto put_inode_out;          } @@ -1291,23 +1315,31 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      if (is_ntfs3(sbi)) {          /* Load $Secure. */          err = ntfs_security_init(sbi); -        if (err) +        if (err) { +            ntfs_err(sb, "Failed to initialize $Secure (%d).", err);              goto out; +        }          /* Load $Extend. */          err = ntfs_extend_init(sbi); -        if (err) +        if (err) { +            ntfs_warn(sb, "Failed to initialize $Extend.");              goto load_root; +        } -        /* Load $Extend\$Reparse. */ +        /* Load $Extend/$Reparse. */          err = ntfs_reparse_init(sbi); -        if (err) +        if (err) { +            ntfs_warn(sb, "Failed to initialize $Extend/$Reparse.");              goto load_root; +        } -        /* Load $Extend\$ObjId. */ +        /* Load $Extend/$ObjId. */          err = ntfs_objid_init(sbi); -        if (err) +        if (err) { +            ntfs_warn(sb, "Failed to initialize $Extend/$ObjId.");              goto load_root; +        }      }  load_root: @@ -1316,8 +1348,8 @@ static int ntfs_fill_super(struct super_block *sb, struct fs_context *fc)      ref.seq = cpu_to_le16(MFT_REC_ROOT);      inode = ntfs_iget5(sb, &ref, &NAME_ROOT);      if (IS_ERR(inode) || !inode->i_op) { -        ntfs_err(sb, "Failed to load root."); -        err = IS_ERR(inode) ? PTR_ERR(inode) : -EINVAL; +        err = PTR_ERR(inode); +        ntfs_err(sb, "Failed to load root (%d).", err);          goto out;      } diff --git a/fs/ntfs3/frecord.c b/fs/ntfs3/frecord.c index 481219f2a7cf..2bfcf1a989c9 100644 --- a/fs/ntfs3/frecord.c +++ b/fs/ntfs3/frecord.c @@ -3360,7 +3360,7 @@ int ni_write_inode(struct inode *inode, int sync, const char *hint)      ni_unlock(ni);      if (err) { -        ntfs_err(sb, "%s r=%lx failed, %d.", hint, inode->i_ino, err); +        ntfs_inode_err(inode, "%s failed, %d.", hint, err);          ntfs_set_state(sbi, NTFS_DIRTY_ERROR);          return err;      } diff --git a/fs/ntfs3/fsntfs.c b/fs/ntfs3/fsntfs.c index 0a82b1bf3ec2..28cc421102e5 100644 --- a/fs/ntfs3/fsntfs.c +++ b/fs/ntfs3/fsntfs.c @@ -223,7 +223,7 @@ int ntfs_extend_init(struct ntfs_sb_info *sbi)      inode = ntfs_iget5(sb, &ref, &NAME_EXTEND);      if (IS_ERR(inode)) {          err = PTR_ERR(inode); -        ntfs_err(sb, "Failed to load $Extend."); +        ntfs_err(sb, "Failed to load $Extend (%d).", err);          inode = NULL;          goto out;      } @@ -282,7 +282,7 @@ int ntfs_loadlog_and_replay(struct ntfs_inode *ni, struct ntfs_sb_info *sbi)      /* Check for 4GB. */      if (ni->vfs_inode.i_size >= 0x100000000ull) { -        ntfs_err(sb, "\x24LogFile is too big"); +        ntfs_err(sb, "\x24LogFile is large than 4G.");          err = -EINVAL;          goto out;      } @@ -1863,7 +1863,7 @@ int ntfs_security_init(struct ntfs_sb_info *sbi)      inode = ntfs_iget5(sb, &ref, &NAME_SECURE);      if (IS_ERR(inode)) {          err = PTR_ERR(inode); -        ntfs_err(sb, "Failed to load $Secure."); +        ntfs_err(sb, "Failed to load $Secure (%d).", err);          inode = NULL;          goto out;      } @@ -1874,45 +1874,43 @@ int ntfs_security_init(struct ntfs_sb_info *sbi)      attr = ni_find_attr(ni, NULL, &le, ATTR_ROOT, SDH_NAME,                  ARRAY_SIZE(SDH_NAME), NULL, NULL); -    if (!attr) { -        err = -EINVAL; -        goto out; -    } - -    if(!(root_sdh = resident_data_ex(attr, sizeof(struct INDEX_ROOT))) || +    if (!attr || +        !(root_sdh = resident_data_ex(attr, sizeof(struct INDEX_ROOT))) ||          root_sdh->type != ATTR_ZERO ||          root_sdh->rule != NTFS_COLLATION_TYPE_SECURITY_HASH ||          offsetof(struct INDEX_ROOT, ihdr) + -            le32_to_cpu(root_sdh->ihdr.used) > -            le32_to_cpu(attr->res.data_size)) { +                le32_to_cpu(root_sdh->ihdr.used) > +            le32_to_cpu(attr->res.data_size)) { +        ntfs_err(sb, "$Secure::$SDH is corrupted.");          err = -EINVAL;          goto out;      }      err = indx_init(indx_sdh, sbi, attr, INDEX_MUTEX_SDH); -    if (err) +    if (err) { +        ntfs_err(sb, "Failed to initialize $Secure::$SDH (%d).", err);          goto out; +    }      attr = ni_find_attr(ni, attr, &le, ATTR_ROOT, SII_NAME,                  ARRAY_SIZE(SII_NAME), NULL, NULL); -    if (!attr) { -        err = -EINVAL; -        goto out; -    } - -    if(!(root_sii = resident_data_ex(attr, sizeof(struct INDEX_ROOT))) || +    if (!attr || +        !(root_sii = resident_data_ex(attr, sizeof(struct INDEX_ROOT))) ||          root_sii->type != ATTR_ZERO ||          root_sii->rule != NTFS_COLLATION_TYPE_UINT ||          offsetof(struct INDEX_ROOT, ihdr) + -            le32_to_cpu(root_sii->ihdr.used) > -            le32_to_cpu(attr->res.data_size)) { +                le32_to_cpu(root_sii->ihdr.used) > +            le32_to_cpu(attr->res.data_size)) { +        ntfs_err(sb, "$Secure::$SII is corrupted.");          err = -EINVAL;          goto out;      }      err = indx_init(indx_sii, sbi, attr, INDEX_MUTEX_SII); -    if (err) +    if (err) { +        ntfs_err(sb, "Failed to initialize $Secure::$SII (%d).", err);          goto out; +    }      fnd_sii = fnd_get();      if (!fnd_sii) { diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c index 521ce31d67a1..e0f78b306f15 100644 --- a/fs/ntfs3/super.c +++ b/fs/ntfs3/super.c @@ -734,48 +734,81 @@ static int ntfs_init_from_boot(struct super_block *sb, u32 sector_size,      err = -EINVAL;      boot = (struct NTFS_BOOT *)bh->b_data; -    if (memcmp(boot->system_id, "NTFS    ", sizeof("NTFS    ") - 1)) +    if (memcmp(boot->system_id, "NTFS    ", sizeof("NTFS    ") - 1)) { +        ntfs_err(sb, "Boot's signature is not NTFS.");          goto out; +    }      /* 0x55AA is not mandaroty. Thanks Maxim Suhanov*/      /*if (0x55 != boot->boot_magic[0] || 0xAA != boot->boot_magic[1])       *    goto out;       */ -    boot_sector_size = (u32)boot->bytes_per_sector[1] << 8; -    if (boot->bytes_per_sector[0] || boot_sector_size < SECTOR_SIZE || +    boot_sector_size = ((u32)boot->bytes_per_sector[1] << 8) | +               boot->bytes_per_sector[0]; +    if (boot_sector_size < SECTOR_SIZE ||          !is_power_of_2(boot_sector_size)) { +        ntfs_err(sb, "Invalid bytes per sector %u.", boot_sector_size);          goto out;      }      /* cluster size: 512, 1K, 2K, 4K, ... 2M */      sct_per_clst = true_sectors_per_clst(boot); -    if ((int)sct_per_clst < 0) -        goto out; -    if (!is_power_of_2(sct_per_clst)) +    if ((int)sct_per_clst < 0 || !is_power_of_2(sct_per_clst)) { +        ntfs_err(sb, "Invalid sectors per cluster %u.", sct_per_clst);          goto out; +    } + +    sbi->cluster_size = boot_sector_size * sct_per_clst; +    sbi->cluster_bits = cluster_bits = blksize_bits(sbi->cluster_size); +    sbi->cluster_mask = sbi->cluster_size - 1; +    sbi->cluster_mask_inv = ~(u64)sbi->cluster_mask;      mlcn = le64_to_cpu(boot->mft_clst);      mlcn2 = le64_to_cpu(boot->mft2_clst);      sectors = le64_to_cpu(boot->sectors_per_volume); -    if (mlcn * sct_per_clst >= sectors) +    if (mlcn * sct_per_clst >= sectors || mlcn2 * sct_per_clst >= sectors) { +        ntfs_err( +            sb, +            "Start of MFT 0x%llx (0x%llx) is out of volume 0x%llx.", +            mlcn, mlcn2, sectors);          goto out; +    } -    if (mlcn2 * sct_per_clst >= sectors) -        goto out; +    sbi->record_size = record_size = +        boot->record_size < 0 ? 1 << (-boot->record_size) : +                          (u32)boot->record_size << cluster_bits; +    sbi->record_bits = blksize_bits(record_size); +    sbi->attr_size_tr = (5 * record_size >> 4); // ~320 bytes      /* Check MFT record size. */ -    if ((boot->record_size < 0 && -         SECTOR_SIZE > (2U << (-boot->record_size))) || -        (boot->record_size >= 0 && !is_power_of_2(boot->record_size))) { +    if (record_size < SECTOR_SIZE || !is_power_of_2(record_size)) { +        ntfs_err(sb, "Invalid bytes per MFT record %u (%d).", +             record_size, boot->record_size); +        goto out; +    } + +    if (record_size > MAXIMUM_BYTES_PER_MFT) { +        ntfs_err(sb, "Unsupported bytes per MFT record %u.", +             record_size);          goto out;      } +    sbi->index_size = boot->index_size < 0 ? +                    1u << (-boot->index_size) : +                    (u32)boot->index_size << cluster_bits; +      /* Check index record size. */ -    if ((boot->index_size < 0 && -         SECTOR_SIZE > (2U << (-boot->index_size))) || -        (boot->index_size >= 0 && !is_power_of_2(boot->index_size))) { +    if (sbi->index_size < SECTOR_SIZE || !is_power_of_2(sbi->index_size)) { +        ntfs_err(sb, "Invalid bytes per index %u(%d).", sbi->index_size, +             boot->index_size); +        goto out; +    } + +    if (sbi->index_size > MAXIMUM_BYTES_PER_INDEX) { +        ntfs_err(sb, "Unsupported bytes per index %u.", +             sbi->index_size);          goto out;