Received: by 2002:ab2:1149:0:b0:1f3:1f8c:d0c6 with SMTP id z9csp2466808lqz; Tue, 2 Apr 2024 20:36:17 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUAuxyKORQRZvW3nc6t8CzLL5zl+GtpYnSbV6m/ot5nMBAq2ne+nxOuxojOq1YTwy2gEJie3uaso9He3D1Q2r6WGWd5g/Vt0ztfF6TkEQ== X-Google-Smtp-Source: AGHT+IF4b6xntNU593wY8V+1UxFu38dQKKGfbHrqD1PyYnCxXhOY02VoAD9buyTFmDsqyU88hODX X-Received: by 2002:a05:620a:5816:b0:78b:e8f8:660 with SMTP id wm22-20020a05620a581600b0078be8f80660mr5577530qkn.11.1712115377445; Tue, 02 Apr 2024 20:36:17 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712115377; cv=pass; d=google.com; s=arc-20160816; b=HDctsURFlJney2oplsPuAvneZauQPoGLHGI5FED1QTnllzKyu2IRoG7EWgu4L/ZLdv Z5vByBFI1efTkm0YyqqQIWSz1QaJ/Vkw0vT2IWTd9mEQvjWtGa0J63tiz40qjpa7N82H gDVnYTebFfyK2daYMLtmlQJ5oHDtO1S2ZNHuPi1740Dfw7MI3bRON+YK8r9V6Bw2emYe TMWLjuV6V4clYm2GNqNeV7YISdXuKL7WC0LcRiBWtdW/NqVUxraA0u/6ly08MWxrZRPh +89YcqaEfbOGlkXiFmBMENjzsjT399iPOYst+FdSV+QocchaEJQs8CqkAK/v00l24oOg /FBg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=SWAAnrFfdFPRrmRzoKr3vWa6N3+wq/l6WNS7I+c7wOE=; fh=ox++7A8yAJwV7L7WW9rN9jXxvkgDSL3rCldPnpw2nqQ=; b=aZnxvLbi/WTt9Nbr4IAwDlR/CG9BiTHjImVEGUt0PIzVxgjpANcK8iBUScC5TAsAy6 39Xzo2u1zjMEnSrCSGhMhkVTjfPNgCWBOmjMoqg3ES8TXJ6xx2lVUALioHyItSl0/n7G epGTnKF1RMxMp+qP1BZC5zlne8rsXlmAn2wBfpjTVUmaZz0VDmqrg+xIxqNMN1ImAtDj IRKK75v2vmsxrzRYPwpii+ThP39S85VIlTKN5qNB8qr0Po4ju8TNXhH1iORUVHrleEQN 7xCSWaqR6kzKX3zdt0lQ9j0A5f5bxWfDi11EJTwrW4pIj4acFUQJTqaAxa0SdZLoCFJv ajBg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aClhbdbd; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-ext4+bounces-1836-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1836-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id u21-20020a05620a085500b0078a472fab46si13411772qku.622.2024.04.02.20.36.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Apr 2024 20:36:17 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-ext4+bounces-1836-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=aClhbdbd; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-ext4+bounces-1836-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-ext4+bounces-1836-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 2FCB31C22184 for ; Wed, 3 Apr 2024 03:36:17 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 2900F3E498; Wed, 3 Apr 2024 03:36:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="aClhbdbd" X-Original-To: linux-ext4@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9AF8F1BC58; Wed, 3 Apr 2024 03:36:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712115369; cv=none; b=BxQf39fmNQ+j33jd0sABQUehXrnPiZLGqz3lVfTp2EtaMFEj6+TdgOEu+fT5vr7cHhfZ+uu8yfYG9Z7N14c4z++YjWNFqmtB3MYqB+uYMePNl9Im8+1bB7ZzHVUcC+tcBbx1Em1iR7YJheNQdRBHXs62cnDtmE9jRsRNElyI6Sw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712115369; c=relaxed/simple; bh=Rmvd8nlsaI+hpmRh1qnteVgeuRcBm6ZauEhHSFcq6qc=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=sWy5eXdZ/ieqlIOmqp8WBr/2rAnCt2VT/PFtakXmU8IUjswD6a3J9Xl++rs5lnR5TCZPxqjerAYIMgIBJz8QsWq94dEz4AL2HYUwczU7GA9DF6OvL4dbiQjEYlsN6XDIcMssQ1QiSldkauqqVQC2I4sLSUQqt4C9CRXvUgK5Urw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=aClhbdbd; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id A77CAC433C7; Wed, 3 Apr 2024 03:36:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1712115369; bh=Rmvd8nlsaI+hpmRh1qnteVgeuRcBm6ZauEhHSFcq6qc=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=aClhbdbdUf0PRV3ksSMgIogl99uV9A3aanVVmXIJTYMgzeQe7UdHa57D7dp0enHK0 Bq3g2NIrcPWaAzf+D46JyigoOz7R3no2zA8R63og4SeSqjn3Dy3eaMZHsW8yxSr2b5 JSYOCRkyDyF3Ywij6dcVjcGzD1bjej/hedtdhyLb4KrV1Uoa96z1NL8bOIFvgrRJIH oKkfML9kvNkFJcaZI4vpdS2Le/IVLxnlc9uY8btzW9S7X25LGXMqGil4jKKvknVnUM ASgAdFe1+TiSuqR6xeGWwFvqM96Qxvnk7nnRQJg4k0W+NuVh+gyApkIsszv4TjvdVE yfSgnpwRoZBtA== Date: Tue, 2 Apr 2024 20:36:07 -0700 From: Eric Biggers To: Eugen Hristev Cc: tytso@mit.edu, adilger.kernel@dilger.ca, linux-ext4@vger.kernel.org, jaegeuk@kernel.org, chao@kernel.org, linux-f2fs-devel@lists.sourceforge.net, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, kernel@collabora.com, viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz, krisman@suse.de, Gabriel Krisman Bertazi Subject: Re: [PATCH v15 3/9] libfs: Introduce case-insensitive string comparison helper Message-ID: <20240403033607.GE2576@sol.localdomain> References: <20240402154842.508032-1-eugen.hristev@collabora.com> <20240402154842.508032-4-eugen.hristev@collabora.com> Precedence: bulk X-Mailing-List: linux-ext4@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240402154842.508032-4-eugen.hristev@collabora.com> On Tue, Apr 02, 2024 at 06:48:36PM +0300, Eugen Hristev wrote: > +int generic_ci_match(const struct inode *parent, > + const struct qstr *name, > + const struct qstr *folded_name, > + const u8 *de_name, u32 de_name_len) > +{ > + const struct super_block *sb = parent->i_sb; > + const struct unicode_map *um = sb->s_encoding; > + struct fscrypt_str decrypted_name = FSTR_INIT(NULL, de_name_len); > + struct qstr dirent = QSTR_INIT(de_name, de_name_len); > + int res = 0, match = 0; > + > + if (IS_ENCRYPTED(parent)) { > + const struct fscrypt_str encrypted_name = > + FSTR_INIT((u8 *) de_name, de_name_len); > + > + if (WARN_ON_ONCE(!fscrypt_has_encryption_key(parent))) > + return -EINVAL; > + > + decrypted_name.name = kmalloc(de_name_len, GFP_KERNEL); > + if (!decrypted_name.name) > + return -ENOMEM; > + res = fscrypt_fname_disk_to_usr(parent, 0, 0, &encrypted_name, > + &decrypted_name); > + if (res < 0) > + goto out; > + dirent.name = decrypted_name.name; > + dirent.len = decrypted_name.len; > + } > + > + /* > + * Attempt a case-sensitive match first. It is cheaper and > + * should cover most lookups, including all the sane > + * applications that expect a case-sensitive filesystem. > + */ > + if (folded_name->name) { > + if (dirent.len == folded_name->len && > + !memcmp(folded_name->name, dirent.name, dirent.len)) { > + match = 1; > + goto out; > + } > + res = utf8_strncasecmp_folded(um, folded_name, &dirent); > + } else { > + if (dirent.len == name->len && > + !memcmp(name->name, dirent.name, dirent.len) && > + (!sb_has_strict_encoding(sb) || !utf8_validate(um, name))) { > + match = 1; > + goto out; > + } > + res = utf8_strncasecmp(um, name, &dirent); > + } The 'match' variable is unnecessary because setting res=0 achieves the same effect. - Eric