From patchwork Thu Jun 6 19:31:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gabriel Krisman Bertazi X-Patchwork-Id: 10980339 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B157792A for ; Thu, 6 Jun 2019 19:31:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 95F2F289D1 for ; Thu, 6 Jun 2019 19:31:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 89438289D4; Thu, 6 Jun 2019 19:31:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI,UNPARSEABLE_RELAY autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20599289D1 for ; Thu, 6 Jun 2019 19:31:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726369AbfFFTbw (ORCPT ); Thu, 6 Jun 2019 15:31:52 -0400 Received: from bhuna.collabora.co.uk ([46.235.227.227]:60352 "EHLO bhuna.collabora.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726077AbfFFTbw (ORCPT ); Thu, 6 Jun 2019 15:31:52 -0400 Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: krisman) with ESMTPSA id 37662283DB8 From: Gabriel Krisman Bertazi To: tytso@mit.edu Cc: fstests@vger.kernel.org, linux-ext4@vger.kernel.org, Gabriel Krisman Bertazi Subject: [PATCH v2 1/2] common/casefold: Add infrastructure to test filename casefold feature Date: Thu, 6 Jun 2019 15:31:37 -0400 Message-Id: <20190606193138.25852-1-krisman@collabora.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: fstests-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: fstests@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add a set of basic helper functions to simplify the testing of casefolding capable filesystems. Signed-off-by: Gabriel Krisman Bertazi --- common/casefold | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 common/casefold diff --git a/common/casefold b/common/casefold new file mode 100644 index 000000000000..34c1d4ae1af1 --- /dev/null +++ b/common/casefold @@ -0,0 +1,108 @@ +#----------------------------------------------------------------------- +# +# Common functions for testing filename casefold feature +# +#----------------------------------------------------------------------- +# Copyright (c) 2018 Collabora, Ltd. All Rights Reserved. +# +# Author: Gabriel Krisman Bertazi +# +# This program is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it would be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write the Free Software Foundation, +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +#----------------------------------------------------------------------- + +_has_casefold_feature_kernel_support() { + case $FSTYP in + ext4) + test -f '/sys/fs/ext4/features/casefold' + ;; + *) + # defaults to unsupported + false + ;; + esac +} + +_require_casefold_support() { + if ! _has_casefold_feature_kernel_support ; then + _notrun "$FSTYP does not support casefold feature" + fi + + if ! _scratch_mkfs_casefold &>>seqres.full; then + _notrun "$FSTYP userspace tools do not support casefold" + fi + + # Make sure the kernel can mount a filesystem with the encoding + # defined by the userspace tools. This will fail if + # the userspace tool used a more recent encoding than the one + # supported in kernel space. + if ! _try_scratch_mount &>>seqres.full; then + _notrun \ + "kernel can't mount filesystem using the encoding set by userspace" + fi + _scratch_unmount +} + +_scratch_mkfs_casefold () { + case $FSTYP in + ext4) + _scratch_mkfs -O casefold $* + ;; + *) + _notrun "Don't know how to mkfs with casefold support on $FSTYP" + ;; + esac +} + +_scratch_mkfs_casefold_strict () { + case $FSTYP in + ext4) + _scratch_mkfs -O casefold -E encoding_flags=strict + ;; + *) + _notrun \ + "Don't know how to mkfs with casefold-strict support on $FSTYP" + ;; + esac +} + +_casefold_check_exact_name () { + # To get the exact disk name, we need some method that does a + # getdents() on the parent directory, such that we don't get + # normalized/casefolded results. 'Find' works ok. + basedir=$1 + exact_name=$2 + find ${basedir} | grep -q ${exact_name} +} + +_try_set_casefold_attr () { + chattr +F "${1}" &>/dev/null +} + +_try_unset_casefold_attr () { + chattr -F "${1}" &>/dev/null +} + +_set_casefold_attr () { + _try_set_casefold_attr "${1}" || \ + _fail "Unable to set casefold attribute on ${1}" +} + +_unset_casefold_attr () { + _try_unset_casefold_attr "${1}" || \ + _fail "Unable to unset casefold attribute on ${1}" +} + +_is_casefolded_dir () { + lsattr -ld "${1}" | grep -q "Casefold" +}