Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp4155084imw; Thu, 7 Jul 2022 13:45:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tyrVPoLjk72kHfoU/cn6KAI5xoJVVFrjX5HfN5ThVigkhijyLYqqWaCG+EuKRN3Mg3xPWN X-Received: by 2002:a17:903:1c4:b0:16b:7928:95ce with SMTP id e4-20020a17090301c400b0016b792895cemr53591437plh.158.1657226748609; Thu, 07 Jul 2022 13:45:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657226748; cv=none; d=google.com; s=arc-20160816; b=Ull1zqt1uVwNcyxraB0jQ8586K0z0xmZLz976RNl1pHIRG1RjJb+JKvql1XxxSUTXM BhfembW8FgUcTn6jF1NlT7AmRTekFopquP75yCZPT2qpXfiEM7c763SERcM5nHJsrLnx fRbZ4XTU7JzyfSu/ksgHgxKMNmsTeUyVC0/+UpbYfLR6hN62FGOQZBRqS0k3NKNgepEd tm85rcOCVORNerPLuYfK/q00gS+z+koGyBoaR7wUrufSuUg11NVJ7qIBHpWFn9S7aIrG I/uXACUdwC4os+dnJzQ7Cw4rndi73hDgkND7F1eGR4R11TY3myatJ8AuLG2P9W4C3mAj tSoA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:dkim-signature :from; bh=LF4hMg/LLcakbwr13SInW0HTDM2oP5BElL1hTUJSTno=; b=scPEDWKBX3b/kGz5etG1GUCjY+bMAt/NZIzKzCZuORQxazEmJXvXqnA5Yq84bo+GYd DcqHK0b5H61ZbvXoQ6aaUjO3CGMbq/80/8EAEa4DJ3WvQP6U2TDNF6ycDF7+xksRaD1l Gu5/urpF/2wyYRmkc3oTAo6rpQ6PzwtIzPZYhDs4e8vH15Xc1QuX81kv4PeYeoCdLhAg WvB/9qin6oR0bc93Fh34ntrzasqOcI/XDDTqswb2PLo7l+tkff6qrmfjdlxaLjOq7nbu LsNrz2auSFHSL+qrXoXPKZFR5zKkcvSN+6R28X9F8t0GxC7palQ3vztppWAr8XpmXFDy TWDg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bacher09.org header.s=reg header.b=xuuMvAb7; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qe14-20020a17090b4f8e00b001ef28c41c82si24822649pjb.166.2022.07.07.13.45.28; Thu, 07 Jul 2022 13:45:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4-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=@bacher09.org header.s=reg header.b=xuuMvAb7; spf=pass (google.com: domain of linux-ext4-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-ext4-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235891AbiGGUmI (ORCPT + 99 others); Thu, 7 Jul 2022 16:42:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231875AbiGGUmI (ORCPT ); Thu, 7 Jul 2022 16:42:08 -0400 Received: from root.slava.cc (root.slava.cc [168.119.137.110]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 30B9D1D322 for ; Thu, 7 Jul 2022 13:42:07 -0700 (PDT) From: Slava Bacherikov DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bacher09.org; s=reg; t=1657226524; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=LF4hMg/LLcakbwr13SInW0HTDM2oP5BElL1hTUJSTno=; b=xuuMvAb7uyhnFDIYOqWkGqrp4KYbCUYWmz1+re7fRfLRXyTi3wQTpeLJU7mr1MFj8i2jML V+fkTlolhkMcE73U90z0g7S2od7mbNPv1l5lB9EI/hrLFC5ZASrhOBuDVAgBZq8zE2bY5g /4G99jS0TDaAb5DyVkVlpJhy1mc+I7Y= To: ebiggers@kernel.org Cc: tytso@mit.edu, linux-ext4@vger.kernel.org, krisman@collabora.com, Slava Bacherikov Subject: [PATCH] tune2fs: allow disabling casefold feature Date: Thu, 7 Jul 2022 23:41:37 +0300 Message-Id: <20220707204137.71311-1-slava@bacher09.org> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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, T_SCC_BODY_TEXT_LINE 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-ext4@vger.kernel.org Casefold can be safely disabled if there are no directories with +F attribute ( EXT4_CASEFOLD_FL ). This checks all inodes for that flag and in case there isn't any, it disables casefold FS feature. When FS has directories with +F attributes, user could convert these directories, probably by mounting FS and executing some script or by doing it manually. Afterwards, it would be possible to disable casefold FS flag via tune2fs. Signed-off-by: Slava Bacherikov --- misc/tune2fs.8.in | 6 ++++-- misc/tune2fs.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 57 insertions(+), 3 deletions(-) diff --git a/misc/tune2fs.8.in b/misc/tune2fs.8.in index 628dcdc0..dcf108c1 100644 --- a/misc/tune2fs.8.in +++ b/misc/tune2fs.8.in @@ -593,8 +593,10 @@ Enable the file system to be larger than 2^32 blocks. .TP .B casefold Enable support for file system level casefolding. -.B Tune2fs -currently only supports setting this file system feature. +The option can be cleared only if filesystem has no +directories with +.B F +attribute. .TP .B dir_index Use hashed b-trees to speed up lookups for large directories. diff --git a/misc/tune2fs.c b/misc/tune2fs.c index 6c162ba5..a8355619 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -204,7 +204,8 @@ static __u32 clear_ok_features[3] = { EXT4_FEATURE_INCOMPAT_FLEX_BG | EXT4_FEATURE_INCOMPAT_MMP | EXT4_FEATURE_INCOMPAT_64BIT | - EXT4_FEATURE_INCOMPAT_CSUM_SEED, + EXT4_FEATURE_INCOMPAT_CSUM_SEED | + EXT4_FEATURE_INCOMPAT_CASEFOLD, /* R/O compat */ EXT2_FEATURE_RO_COMPAT_LARGE_FILE | EXT4_FEATURE_RO_COMPAT_HUGE_FILE| @@ -1020,6 +1021,41 @@ out: return retval; } +static int has_casefold_inode(ext2_filsys fs) +{ + int length = EXT2_INODE_SIZE(fs->super); + struct ext2_inode *inode = NULL; + ext2_inode_scan scan; + errcode_t retval; + ext2_ino_t ino; + int found_casefold = 0; + + retval = ext2fs_get_mem(length, &inode); + if (retval) + fatal_err(retval, "while allocating memory"); + + retval = ext2fs_open_inode_scan(fs, 0, &scan); + if (retval) + fatal_err(retval, "while opening inode scan"); + + do { + retval = ext2fs_get_next_inode_full(scan, &ino, inode, length); + if (retval) + fatal_err(retval, "while getting next inode"); + if (!ino) + break; + + if(inode->i_flags & EXT4_CASEFOLD_FL) { + found_casefold = 1; + break; + } + } while(1); + + ext2fs_free_mem(&inode); + ext2fs_close_inode_scan(scan); + return found_casefold; +} + static errcode_t disable_uninit_bg(ext2_filsys fs, __u32 csum_feature_flag) { struct ext2_group_desc *gd; @@ -1554,6 +1590,22 @@ mmp_error: enabling_casefold = 1; } + if (FEATURE_OFF(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_CASEFOLD)) { + if (mount_flags & EXT2_MF_MOUNTED) { + fputs(_("The casefold feature may only be disabled when " + "the filesystem is unmounted.\n"), stderr); + return 1; + } + if (has_casefold_inode(fs)) { + fputs(_("The casefold feature can't be cleared when " + "there are inodes with +F flag.\n"), stderr); + return 1; + } + fs->super->s_encoding = 0; + fs->super->s_encoding_flags = 0; + enabling_casefold = 0; + } + if (FEATURE_ON(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_CSUM_SEED)) { if (!ext2fs_has_feature_metadata_csum(sb)) {