From patchwork Mon Dec 26 14:21:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36622 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp935164wrt; Mon, 26 Dec 2022 06:23:27 -0800 (PST) X-Google-Smtp-Source: AMrXdXu47cpJ5kwhAQKTl46R9FBKN/8NUlpU6SZkjjmVinkdayhGZvSJEDlLxubNoS8umDVirP1M X-Received: by 2002:aa7:921a:0:b0:576:de1:cd32 with SMTP id 26-20020aa7921a000000b005760de1cd32mr20999208pfo.0.1672064607642; Mon, 26 Dec 2022 06:23:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064607; cv=none; d=google.com; s=arc-20160816; b=yxw/UdRprnuoeX/eBM88faOkUIdskYL6q+yzRp852BPMCJLurAvBvR20oQJLOov3NF r/HZUnuDHmrHHKBI0udzwQcM8BQs/J4/65cJrVymzaNRdOYhQAKDyl+AVQQdEkuGKXtu TYHP4k4IVMTNSwSiwz6CWYFwNB0R1TWoKiTY9J+RDTqK9SbWoCRQbQw7qy1QvcK0W7Ys xvwrQqDhMr6tujkBwJf8HsdTzRFdLUAQPe/s6jX4KzN3NbMYFppv0Z6t5p1gpfPGpi3Y b3KsdyX1pD7mKmf40n2weqZ2IqMmI7K7/0f1Iqn5UAHa2PP8xsRo9v2F1JhDbJgs+itj rb2g== 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:to:from :dkim-signature; bh=4V57qv/a7EiE2ppaRG/HyKZfTTXYQY+IxWwnoxavQ/8=; b=g9XEOvnXPuBmo7OG/KjW7ZV4S4Kee+UjQX+78Cx1yNSlCyqXqSu8cjW72mCJVa3sBA lkhUe8kyp016EFEh4PYKMMh/EhsFOUPhDwWd2jq9vtdtOyB/qY9ftiPMAiTYjATKLJkA NYBvnhO1wR781lvfDM2RvrsofdnnAyTFfUHPg2WWjrsgB2mbASYq1D3laIHo/rJHwAxk 7y2bVNXkEQ507udEtvFO48GjVB+kAOP8iDAeVxZEmhULX2wsTC01K1kXY41sHT8kR27T G8xSvCKZNvVX6gxgGt+UnE7KHs+Brc52pNFiRukYhbfOhWF6CD4EW0xREy/06Wtsvgcg E/nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=fxaBgKBU; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r28-20020aa7989c000000b005810f268678si4099178pfl.165.2022.12.26.06.23.15; Mon, 26 Dec 2022 06:23:27 -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=@kernel.org header.s=k20201202 header.b=fxaBgKBU; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231954AbiLZOWK (ORCPT + 99 others); Mon, 26 Dec 2022 09:22:10 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229568AbiLZOWF (ORCPT ); Mon, 26 Dec 2022 09:22:05 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BED411140; Mon, 26 Dec 2022 06:22:04 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4C9DC60E16; Mon, 26 Dec 2022 14:22:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 57260C433F0; Mon, 26 Dec 2022 14:22:03 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064523; bh=+iN0Mmisxx535Wrdu3nGmwSoR4sCrIL6dvBb31QghsE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=fxaBgKBUOjxEifZXzIHKavSrzqT4XX0H1ndS42m2r4CDPpQyo6npRkR0RrBwlVTW5 Vjr/NW77j/sgtdxZ2bttJm5DXQMYqX//OQwM5IIWXQL7/wMyhkDWaudLae5d0m8Jz/ 2e++wXrdHcc4sLwcEd0vCAN3aX9ZpZj4nnrs0RH6h62DiL3X7Zpi+Nc1f4vxMT10BG EC8DMCpenOPsU/lffuSNAx9k4daYC7FyakkBBVmPFsjl9pCgNAwB77/SzaMevnkhCo SKBqrBSkjUiG53YI2wiP9oED5K4iHk2R5KoPvM47cfbB0S58OTj5GLvO1nbw3Sq7R4 oRR0LsAiwQ0CA== Received: by pali.im (Postfix) id 16AC19E4; Mon, 26 Dec 2022 15:22:01 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 01/18] fat: Fix iocharset=utf8 mount option Date: Mon, 26 Dec 2022 15:21:33 +0100 Message-Id: <20221226142150.13324-2-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286818085657126?= X-GMAIL-MSGID: =?utf-8?q?1753286818085657126?= Currently iocharset=utf8 mount option is broken and error is printed to dmesg when it is used. To use UTF-8 as iocharset, it is required to use utf8=1 mount option. Fix iocharset=utf8 mount option to use be equivalent to the utf8=1 mount option and remove printing error from dmesg. FAT by definition is case-insensitive but current Linux implementation is case-sensitive for non-ASCII characters when UTF-8 is used. This patch does not change this UTF-8 behavior. Only more comments in fat_utf8_strnicmp() function are added about it. After this patch iocharset=utf8 starts working, so there is no need to have separate config option FAT_DEFAULT_UTF8 as FAT_DEFAULT_IOCHARSET for utf8 also starts working. So remove redundant config option FAT_DEFAULT_UTF8. Signed-off-by: Pali Rohár --- Documentation/filesystems/vfat.rst | 13 ++----------- fs/fat/Kconfig | 19 +------------------ fs/fat/dir.c | 17 +++++++---------- fs/fat/fat.h | 22 ++++++++++++++++++++++ fs/fat/inode.c | 28 +++++++++++----------------- fs/fat/namei_vfat.c | 26 +++++++++++++++++++------- 6 files changed, 62 insertions(+), 63 deletions(-) diff --git a/Documentation/filesystems/vfat.rst b/Documentation/filesystems/vfat.rst index 760a4d83fdf9..28cacba7bb9a 100644 --- a/Documentation/filesystems/vfat.rst +++ b/Documentation/filesystems/vfat.rst @@ -65,19 +65,10 @@ VFAT MOUNT OPTIONS in Unicode format, but Unix for the most part doesn't know how to deal with Unicode. By default, FAT_DEFAULT_IOCHARSET setting is used. - - There is also an option of doing UTF-8 translations - with the utf8 option. - -.. note:: ``iocharset=utf8`` is not recommended. If unsure, you should consider - the utf8 option instead. + **utf8** is supported too and recommended to use. **utf8=** - UTF-8 is the filesystem safe version of Unicode that - is used by the console. It can be enabled or disabled - for the filesystem with this option. - If 'uni_xlate' gets set, UTF-8 gets disabled. - By default, FAT_DEFAULT_UTF8 setting is used. + Alias for ``iocharset=utf8`` mount option. **uni_xlate=** Translate unhandled Unicode characters to special diff --git a/fs/fat/Kconfig b/fs/fat/Kconfig index 238cc55f84c4..e98aaa3bb55b 100644 --- a/fs/fat/Kconfig +++ b/fs/fat/Kconfig @@ -93,29 +93,12 @@ config FAT_DEFAULT_IOCHARSET like FAT to use. It should probably match the character set that most of your FAT filesystems use, and can be overridden with the "iocharset" mount option for FAT filesystems. - Note that "utf8" is not recommended for FAT filesystems. - If unsure, you shouldn't set "utf8" here - select the next option - instead if you would like to use UTF-8 encoded file names by default. + "utf8" is supported too and recommended to use. See for more information. Enable any character sets you need in File Systems/Native Language Support. -config FAT_DEFAULT_UTF8 - bool "Enable FAT UTF-8 option by default" - depends on VFAT_FS - default n - help - Set this if you would like to have "utf8" mount option set - by default when mounting FAT filesystems. - - Even if you say Y here can always disable UTF-8 for - particular mount by adding "utf8=0" to mount options. - - Say Y if you use UTF-8 encoding for file names, N otherwise. - - See for more information. - config FAT_KUNIT_TEST tristate "Unit Tests for FAT filesystems" if !KUNIT_ALL_TESTS depends on KUNIT && FAT_FS diff --git a/fs/fat/dir.c b/fs/fat/dir.c index 00235b8a1823..15166b0c4a6e 100644 --- a/fs/fat/dir.c +++ b/fs/fat/dir.c @@ -33,11 +33,6 @@ #define FAT_MAX_UNI_CHARS ((MSDOS_SLOTS - 1) * 13 + 1) #define FAT_MAX_UNI_SIZE (FAT_MAX_UNI_CHARS * sizeof(wchar_t)) -static inline unsigned char fat_tolower(unsigned char c) -{ - return ((c >= 'A') && (c <= 'Z')) ? c+32 : c; -} - static inline loff_t fat_make_i_pos(struct super_block *sb, struct buffer_head *bh, struct msdos_dir_entry *de) @@ -258,10 +253,12 @@ static inline int fat_name_match(struct msdos_sb_info *sbi, if (a_len != b_len) return 0; - if (sbi->options.name_check != 's') - return !nls_strnicmp(sbi->nls_io, a, b, a_len); - else + if (sbi->options.name_check == 's') return !memcmp(a, b, a_len); + else if (sbi->options.utf8) + return !fat_utf8_strnicmp(a, b, a_len); + else + return !nls_strnicmp(sbi->nls_io, a, b, a_len); } enum { PARSE_INVALID = 1, PARSE_NOT_LONGNAME, PARSE_EOF, }; @@ -384,7 +381,7 @@ static int fat_parse_short(struct super_block *sb, de->lcase & CASE_LOWER_BASE); if (chl <= 1) { if (!isvfat) - ptname[i] = nocase ? c : fat_tolower(c); + ptname[i] = nocase ? c : fat_ascii_to_lower(c); i++; if (c != ' ') { name_len = i; @@ -421,7 +418,7 @@ static int fat_parse_short(struct super_block *sb, if (chl <= 1) { k++; if (!isvfat) - ptname[i] = nocase ? c : fat_tolower(c); + ptname[i] = nocase ? c : fat_ascii_to_lower(c); i++; if (c != ' ') { name_len = i; diff --git a/fs/fat/fat.h b/fs/fat/fat.h index a415c02ede39..6b0a6041c8d7 100644 --- a/fs/fat/fat.h +++ b/fs/fat/fat.h @@ -311,6 +311,28 @@ static inline void fatwchar_to16(__u8 *dst, const wchar_t *src, size_t len) #endif } +static inline unsigned char fat_ascii_to_lower(unsigned char c) +{ + return ((c >= 'A') && (c <= 'Z')) ? c+32 : c; +} + +static inline int fat_utf8_strnicmp(const unsigned char *a, + const unsigned char *b, + int len) +{ + int i; + + /* + * FIXME: UTF-8 doesn't provide FAT semantics + * Case-insensitive support is only for 7-bit ASCII characters + */ + for (i = 0; i < len; i++) { + if (fat_ascii_to_lower(a[i]) != fat_ascii_to_lower(b[i])) + return 1; + } + return 0; +} + /* fat/cache.c */ extern void fat_cache_inval_inode(struct inode *inode); extern int fat_get_cluster(struct inode *inode, int cluster, diff --git a/fs/fat/inode.c b/fs/fat/inode.c index d99b8549ec8f..818c9c37b419 100644 --- a/fs/fat/inode.c +++ b/fs/fat/inode.c @@ -956,7 +956,9 @@ static int fat_show_options(struct seq_file *m, struct dentry *root) /* strip "cp" prefix from displayed option */ seq_printf(m, ",codepage=%s", &sbi->nls_disk->charset[2]); if (isvfat) { - if (sbi->nls_io) + if (opts->utf8) + seq_puts(m, ",iocharset=utf8"); + else if (sbi->nls_io) seq_printf(m, ",iocharset=%s", sbi->nls_io->charset); switch (opts->shortname) { @@ -993,8 +995,6 @@ static int fat_show_options(struct seq_file *m, struct dentry *root) if (opts->nocase) seq_puts(m, ",nocase"); } else { - if (opts->utf8) - seq_puts(m, ",utf8"); if (opts->unicode_xlate) seq_puts(m, ",uni_xlate"); if (!opts->numtail) @@ -1156,8 +1156,6 @@ static int parse_options(struct super_block *sb, char *options, int is_vfat, opts->errors = FAT_ERRORS_RO; *debug = 0; - opts->utf8 = IS_ENABLED(CONFIG_FAT_DEFAULT_UTF8) && is_vfat; - if (!options) goto out; @@ -1318,10 +1316,14 @@ static int parse_options(struct super_block *sb, char *options, int is_vfat, | VFAT_SFN_CREATE_WIN95; break; case Opt_utf8_no: /* 0 or no or false */ - opts->utf8 = 0; + fat_reset_iocharset(opts); break; case Opt_utf8_yes: /* empty or 1 or yes or true */ - opts->utf8 = 1; + fat_reset_iocharset(opts); + iocharset = kstrdup("utf8", GFP_KERNEL); + if (!iocharset) + return -ENOMEM; + opts->iocharset = iocharset; break; case Opt_uni_xl_no: /* 0 or no or false */ opts->unicode_xlate = 0; @@ -1359,18 +1361,11 @@ static int parse_options(struct super_block *sb, char *options, int is_vfat, } out: - /* UTF-8 doesn't provide FAT semantics */ - if (!strcmp(opts->iocharset, "utf8")) { - fat_msg(sb, KERN_WARNING, "utf8 is not a recommended IO charset" - " for FAT filesystems, filesystem will be " - "case sensitive!"); - } + opts->utf8 = !strcmp(opts->iocharset, "utf8") && is_vfat; /* If user doesn't specify allow_utime, it's initialized from dmask. */ if (opts->allow_utime == (unsigned short)-1) opts->allow_utime = ~opts->fs_dmask & (S_IWGRP | S_IWOTH); - if (opts->unicode_xlate) - opts->utf8 = 0; if (opts->nfs == FAT_NFS_NOSTALE_RO) { sb->s_flags |= SB_RDONLY; sb->s_export_op = &fat_export_ops_nostale; @@ -1828,8 +1823,7 @@ int fat_fill_super(struct super_block *sb, void *data, int silent, int isvfat, goto out_fail; } - /* FIXME: utf8 is using iocharset for upper/lower conversion */ - if (sbi->options.isvfat) { + if (sbi->options.isvfat && !sbi->options.utf8) { sbi->nls_io = load_nls(sbi->options.iocharset); if (!sbi->nls_io) { fat_msg(sb, KERN_ERR, "IO charset %s not found", diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c index 21620054e1c4..5c585e79d863 100644 --- a/fs/fat/namei_vfat.c +++ b/fs/fat/namei_vfat.c @@ -134,6 +134,7 @@ static int vfat_hash(const struct dentry *dentry, struct qstr *qstr) static int vfat_hashi(const struct dentry *dentry, struct qstr *qstr) { struct nls_table *t = MSDOS_SB(dentry->d_sb)->nls_io; + int utf8 = MSDOS_SB(dentry->d_sb)->options.utf8; const unsigned char *name; unsigned int len; unsigned long hash; @@ -142,8 +143,17 @@ static int vfat_hashi(const struct dentry *dentry, struct qstr *qstr) len = vfat_striptail_len(qstr); hash = init_name_hash(dentry); - while (len--) - hash = partial_name_hash(nls_tolower(t, *name++), hash); + if (utf8) { + /* + * FIXME: UTF-8 doesn't provide FAT semantics + * Case-insensitive support is only for 7-bit ASCII characters + */ + while (len--) + hash = partial_name_hash(fat_ascii_to_lower(*name++), hash); + } else { + while (len--) + hash = partial_name_hash(nls_tolower(t, *name++), hash); + } qstr->hash = end_name_hash(hash); return 0; @@ -156,16 +166,18 @@ static int vfat_cmpi(const struct dentry *dentry, unsigned int len, const char *str, const struct qstr *name) { struct nls_table *t = MSDOS_SB(dentry->d_sb)->nls_io; + int utf8 = MSDOS_SB(dentry->d_sb)->options.utf8; unsigned int alen, blen; /* A filename cannot end in '.' or we treat it like it has none */ alen = vfat_striptail_len(name); blen = __vfat_striptail_len(len, str); - if (alen == blen) { - if (nls_strnicmp(t, name->name, str, alen) == 0) - return 0; - } - return 1; + if (alen != blen) + return 1; + else if (utf8) + return fat_utf8_strnicmp(name->name, str, alen); + else + return nls_strnicmp(t, name->name, str, alen); } /* From patchwork Mon Dec 26 14:21:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36624 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp935170wrt; Mon, 26 Dec 2022 06:23:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXt2x7bEX8ezUO9bwCkH/PF3+BPgvTOhrAYjDkkitWx7LUZ/DgdhsAGy2AKiceqP8alge3Bh X-Received: by 2002:a05:6a20:4929:b0:a3:218a:c761 with SMTP id ft41-20020a056a20492900b000a3218ac761mr19784602pzb.5.1672064609389; Mon, 26 Dec 2022 06:23:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064609; cv=none; d=google.com; s=arc-20160816; b=zslJUMjMOf5duNe92kU/TlGJCIuEy4gZbv9Nyri1GDo/4OtCZ4hx92j1qvw9C+s1I3 CY9E6w1t+IgaxUMiEWIDd2rm1pFPi3ri5KH5jRkz5+y2Vmxeu0C50Q80ng2O9119N/6O M128B/foS97bTc/pSXn0D7/gLPx4pktCc4qCI5NZk7vm6RgtD2x5Gfw9BW3Qsv1CK13r lTs1yUHmfxec0mnuOgNfQsmgCiT1jIyyvFa+f/GiBZ0GzsuuBDIVoS4S4VIVCzdSLFYF FKOwKJacrkUHyWWri6tEZ9qUl7Ap7PZgNulQaJybpXtSS1SyTtttKQ7wQfHFVjBdnN7w Wu5w== 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:to:from :dkim-signature; bh=gM0A1RKPObxIv7uC6clriFUFFYjgYQDepx03XR8wsv0=; b=AOnjx9tvElyeAIlYFy9fF+iaAdAs5fDjTSwfgKWeBCeMIUNx1p/VUr1AkNESpkTxpH 5NgREASdxu07u83IKdz++n30lFySqfHxDzPmxvLfikt9p9ByiYUUfJee6P13rNkP0Ain wzZ0rsMhINlrf1TPo1sD5cQqLMF850JzoRJNQRFCHSfDsF8z1QzduacG3iaDbivFhd9j rh8SJPcY8drFSVmbBWRZ7uDG08Xa3AWAfp4NczLvnagcG2Zjatza3hBZNMjv1U8UqAxb HCuMtY5PmZnWPB4QDO4BalsIgITZduAzFtQ6XCAhDgP1EGUmHfqOmQ6VJ9GMCcguPFhP daew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=N7GrMIig; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p66-20020a634245000000b0047071cc77f8si11826547pga.803.2022.12.26.06.23.16; Mon, 26 Dec 2022 06:23: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=@kernel.org header.s=k20201202 header.b=N7GrMIig; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232004AbiLZOWO (ORCPT + 99 others); Mon, 26 Dec 2022 09:22:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39100 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231609AbiLZOWG (ORCPT ); Mon, 26 Dec 2022 09:22:06 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D4982182; Mon, 26 Dec 2022 06:22:05 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 3ABD160EA0; Mon, 26 Dec 2022 14:22:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 77E67C4339B; Mon, 26 Dec 2022 14:22:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064524; bh=BEzrRcBKQ+GZ/U+aeCEg9n4Pdy0ikdO5wXFWpAtXmSg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=N7GrMIigC6HxWNrAVct3befoFSSCxU8We3pVOw0O7RzGrspOaLS7OpPHudv168XAA 25iLUs0PGQXhlSEnFpoMuteXkAvUDuXi2F3q5Ilj3JLvHTC0foaYVDx8XDUHW+FfEn lqCyqB5hNS+kNb4YFZ9eV4RnkF0iFaa4JEVF30ZkqOMn2UQsHeJ+XlEW0A0kdXjKtc Xnn089Q0lcPPNDHVVs8gb8ZCLt1Gr/wpy2bnawgEal9zvN7aQIAwzliJYz0B7WrevK JgvI5+UbqzqVfOzTHbOeRJ2Ud40GRBYxGQlvQ1bcYt2Piyv+6jvwF/w1hr47ANYy2v ugCvYxfnZppOg== Received: by pali.im (Postfix) id 46DDAA32; Mon, 26 Dec 2022 15:22:02 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 02/18] hfsplus: Add iocharset= mount option as alias for nls= Date: Mon, 26 Dec 2022 15:21:34 +0100 Message-Id: <20221226142150.13324-3-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286819857708190?= X-GMAIL-MSGID: =?utf-8?q?1753286819857708190?= Other fs drivers are using iocharset= mount option for specifying charset. So add it also for hfsplus and mark old nls= mount option as deprecated. Signed-off-by: Pali Rohár --- Documentation/filesystems/hfsplus.rst | 3 +++ fs/hfsplus/options.c | 7 ++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Documentation/filesystems/hfsplus.rst b/Documentation/filesystems/hfsplus.rst index f02f4f5fc020..171805304cc2 100644 --- a/Documentation/filesystems/hfsplus.rst +++ b/Documentation/filesystems/hfsplus.rst @@ -50,6 +50,9 @@ When mounting an HFSPlus filesystem, the following options are accepted: or locked. Use at your own risk. nls=cccc + Deprecated alias for ``iocharset=`` mount option. + + iocharset=cccc Encoding to use when presenting file names. diff --git a/fs/hfsplus/options.c b/fs/hfsplus/options.c index c94a58762ad6..d3dc0d4ba77f 100644 --- a/fs/hfsplus/options.c +++ b/fs/hfsplus/options.c @@ -23,6 +23,7 @@ enum { opt_creator, opt_type, opt_umask, opt_uid, opt_gid, opt_part, opt_session, opt_nls, + opt_iocharset, opt_nodecompose, opt_decompose, opt_barrier, opt_nobarrier, opt_force, opt_err @@ -37,6 +38,7 @@ static const match_table_t tokens = { { opt_part, "part=%u" }, { opt_session, "session=%u" }, { opt_nls, "nls=%s" }, + { opt_iocharset, "iocharset=%s" }, { opt_decompose, "decompose" }, { opt_nodecompose, "nodecompose" }, { opt_barrier, "barrier" }, @@ -170,6 +172,9 @@ int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi) } break; case opt_nls: + pr_warn("option nls= is deprecated, use iocharset=\n"); + fallthrough; + case opt_iocharset: if (sbi->nls) { pr_err("unable to change nls mapping\n"); return 0; @@ -234,7 +239,7 @@ int hfsplus_show_options(struct seq_file *seq, struct dentry *root) if (sbi->session >= 0) seq_printf(seq, ",session=%u", sbi->session); if (sbi->nls) - seq_printf(seq, ",nls=%s", sbi->nls->charset); + seq_printf(seq, ",iocharset=%s", sbi->nls->charset); if (test_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags)) seq_puts(seq, ",nodecompose"); if (test_bit(HFSPLUS_SB_NOBARRIER, &sbi->flags)) From patchwork Mon Dec 26 14:21:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36627 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp935397wrt; Mon, 26 Dec 2022 06:24:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXsO9PbmuXhhLKRQbegLgZ0QLbOM8dXpx5R5yyVbAqOeSm7yzfoer7v77qQ4VnmtNCVb9nxS X-Received: by 2002:a05:6a20:a59c:b0:a2:17a6:3e86 with SMTP id bc28-20020a056a20a59c00b000a217a63e86mr23622372pzb.55.1672064640641; Mon, 26 Dec 2022 06:24:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064640; cv=none; d=google.com; s=arc-20160816; b=wN/muCfK2m+fHBdlLsuPCUBkcPbguSrwpxXpi5furmZSGPNCHJme5gbycdUJKd7KL4 dm4UI62mFoIWislO0Jl/o1nmu9g7tflHiPXTamyP5hgFRLSEYnmf9Oq2fc/iROXEynZs cT0NQGV6a1Pbkr6ePO+mniolKHFmwXQqAAqf85oLeva/7CICa4ouizNb0g4o0QEztGTg 4GQd5uRCVZ7+jj/Dv1Oyu5NQLsZT2H+RPamcDjfuaVmYmNO0UElF2iHAqz9nbDS4c8S0 vL5+cQ5WEv2kLtC/KijVXzDVlMVZ24khNfYkIWWaNu2VOal/rYFaE1cBtsyUGdIniFjE 6ZGw== 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:to:from :dkim-signature; bh=ci2JDB5RZe5RHEnjxZtPaL+9YHnyub83xJqNOcuna4c=; b=jhyqERMjoZqWyY/60khQxuRocCPpZNio/qf9yM0ZqSsPGEHNlebDpxDYdIfymRYkUJ Rdtr75O64wE4kR/PmLoRQvP15BiiPT6uskGwpX/Wq40Ac6kMO2/1Siibzs97OMORZT3A mytsGCcc9WREKSS0oA+CXg/2anWeaJKM46N6nxRweQGX6G/bVRjSsVLUIu4KE2cqZ9+E 4nB4W/3KvSIxbXQan/MyOk2USTqYjXn85TuOcogTU12FR/MdINWFWXHs+lOw8vIgO2zC rNt7g+ES6DPAhoZP+73JEuBaz+z8WZ16/uRwmyqA81GX16t5Xv1edLStW8NrauFDFm4h Cpew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=FW4Apmw9; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f8-20020a6547c8000000b004785ae0770dsi12191919pgs.327.2022.12.26.06.23.47; Mon, 26 Dec 2022 06:24:00 -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=@kernel.org header.s=k20201202 header.b=FW4Apmw9; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232182AbiLZOWx (ORCPT + 99 others); Mon, 26 Dec 2022 09:22:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229580AbiLZOWI (ORCPT ); Mon, 26 Dec 2022 09:22:08 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D79022616; Mon, 26 Dec 2022 06:22:06 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 8ED78B80D3B; Mon, 26 Dec 2022 14:22:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 005B0C433F2; Mon, 26 Dec 2022 14:22:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064524; bh=ZrKrntGH0WofuwsAtdP0jIQ8uCLZbrmm0J3jNna5drc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=FW4Apmw9ZjRYOfjahl9pzNoc+QFOhJinA5x6Ij2t0JIhlYF/TlSqgb9XIBbyK9Tdz iw/0yyFmCyK6zTIP/BUuPm8egQPs30Yxse+X9XZ+HEjgaVGlaiHeGqQEolsQiQcFXU wdmU+RkiyVzZ9Mi52Y5raowONK2gp3utyAAoTRhHkfTIK6EaV+ngVjqK6mmgke/I7W k7VtigVCtMeCrXr/hNlYwovyQDcXLhkaReHuVQorcboQsAN68VYK6yme+Sqwwi8/0a jy8NTat8PJ5NQz8W05JfMewVtsNT93b1P8QCB9bqNJROsDDLqVVsmCJ0mZ4qCpCVMO duGDzzDCik72w== Received: by pali.im (Postfix) id AD3BB9D7; Mon, 26 Dec 2022 15:22:03 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 03/18] ntfs: Undeprecate iocharset= mount option Date: Mon, 26 Dec 2022 15:21:35 +0100 Message-Id: <20221226142150.13324-4-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286852966357378?= X-GMAIL-MSGID: =?utf-8?q?1753286852966357378?= Other fs drivers are using iocharset= mount option for specifying charset. So mark iocharset= mount option as preferred and deprecate nls= mount option. Signed-off-by: Pali Rohár --- Documentation/filesystems/ntfs.rst | 5 ++--- fs/ntfs/inode.c | 2 +- fs/ntfs/super.c | 13 ++++--------- fs/ntfs/unistr.c | 3 ++- 4 files changed, 9 insertions(+), 14 deletions(-) diff --git a/Documentation/filesystems/ntfs.rst b/Documentation/filesystems/ntfs.rst index 5bb093a26485..51784141b56a 100644 --- a/Documentation/filesystems/ntfs.rst +++ b/Documentation/filesystems/ntfs.rst @@ -109,10 +109,9 @@ mount command (man 8 mount, also see man 5 fstab), the NTFS driver supports the following mount options: ======================= ======================================================= -iocharset=name Deprecated option. Still supported but please use - nls=name in the future. See description for nls=name. +nls=name Alias for ``iocharset=`` mount option. -nls=name Character set to use when returning file names. +iocharset=name Character set to use when returning file names. Unlike VFAT, NTFS suppresses names that contain unconvertible characters. Note that most character sets contain insufficient characters to represent all diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index 08c659332e26..2ab071c4560d 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -2314,7 +2314,7 @@ int ntfs_show_options(struct seq_file *sf, struct dentry *root) seq_printf(sf, ",fmask=0%o", vol->fmask); seq_printf(sf, ",dmask=0%o", vol->dmask); } - seq_printf(sf, ",nls=%s", vol->nls_map->charset); + seq_printf(sf, ",iocharset=%s", vol->nls_map->charset); if (NVolCaseSensitive(vol)) seq_printf(sf, ",case_sensitive"); if (NVolShowSystemFiles(vol)) diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c index 001f4e053c85..55762abdc22a 100644 --- a/fs/ntfs/super.c +++ b/fs/ntfs/super.c @@ -192,11 +192,6 @@ static bool parse_options(ntfs_volume *vol, char *opt) ntfs_warning(vol->sb, "Ignoring obsolete option %s.", p); else if (!strcmp(p, "nls") || !strcmp(p, "iocharset")) { - if (!strcmp(p, "iocharset")) - ntfs_warning(vol->sb, "Option iocharset is " - "deprecated. Please use " - "option nls= in " - "the future."); if (!v || !*v) goto needs_arg; use_utf8: @@ -218,10 +213,10 @@ static bool parse_options(ntfs_volume *vol, char *opt) } else if (!strcmp(p, "utf8")) { bool val = false; ntfs_warning(vol->sb, "Option utf8 is no longer " - "supported, using option nls=utf8. Please " - "use option nls=utf8 in the future and " - "make sure utf8 is compiled either as a " - "module or into the kernel."); + "supported, using option iocharset=utf8. " + "Please use option iocharset=utf8 in the " + "future and make sure utf8 is compiled " + "either as a module or into the kernel."); if (!v || !*v) val = true; else if (!simple_getbool(v, &val)) diff --git a/fs/ntfs/unistr.c b/fs/ntfs/unistr.c index a6b6c64f14a9..75a7f73bccdd 100644 --- a/fs/ntfs/unistr.c +++ b/fs/ntfs/unistr.c @@ -372,7 +372,8 @@ retry: wc = nls->uni2char(le16_to_cpu(ins[i]), ns + o, conversion_err: ntfs_error(vol->sb, "Unicode name contains characters that cannot be " "converted to character set %s. You might want to " - "try to use the mount option nls=utf8.", nls->charset); + "try to use the mount option iocharset=utf8.", + nls->charset); if (ns != *outs) kfree(ns); if (wc != -ENAMETOOLONG) From patchwork Mon Dec 26 14:21:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36623 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp935167wrt; Mon, 26 Dec 2022 06:23:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXsQ/Im0MIOBextUNRQvMZsEtL34TRYdK7QH4T3E1qo1QUWlGkj5xkPw4GQ5dtIL5lt9akrf X-Received: by 2002:a17:90b:2688:b0:225:f8ce:5cd8 with SMTP id pl8-20020a17090b268800b00225f8ce5cd8mr2714865pjb.4.1672064608954; Mon, 26 Dec 2022 06:23:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064608; cv=none; d=google.com; s=arc-20160816; b=Rab6Fj5F6EVgbBv7x7g0JaI3P/2KedwWXGdS1f7WeyzqXWOlLG50MYIezeT6jeiITq fRmZ+EOQtPSRHYUzyp4yvuS9LJVf8wpf2OKaHKLt0G3ZSpPTHOW7MgoUHvV8tXiVRyjp iUYfKVZeQyspINy9strikTZ+w30qUcCqGZcNpucQeaWdmC9CYqdlBR6ZLixtIYKMe7QJ i4A6d9rnqXCdIJ+sAg1U/y0tqHwT3Uw6JMbHZnliG6Am1xl+U/1YI1qVjXaVo7rmWAGP pFjLw2cykjqCeVQYUpPs9cZKPCwpkQFiqwW9PRy173VA9VEkFK+Pjuo65dk+U3TCeprZ 5oEQ== 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:to:from :dkim-signature; bh=Gd1qQSioLg92DUimnR82AShrP0C1CTLKjwh7IQOpFqc=; b=M0JwIgCIw/dR7PCulA/qyr96Qhzk9hYsSCAhz0VI4l8CRPRqjbhYMZkxEDeopUjNpp vHyZGGiMQ+FpLWbO1ktflCtxQy4Bw5wDqKCqnA9Ltkmtdpmtf7SXNky/FPbV1dHx+E/O x1UAbxv1z8a5tmIEBd+vW3sSo6gKKfGAAWYwfnQ9hjDf6CD8oW2pwVQR8V/l6Q06hD2O Jrl7WFMbaNpdyaM90C3igT6ZXwMZN9hbEjA1JrJqvd1XqE0fENshgb77xhfhXeD1KQL+ Q5GYu9nL/LQzhnvngADUAVEbS01QKZEUzxnf+PVJ/feZlnJvfvPO4n+l9eAHojklgLml 1pdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=E4k5OXvy; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id p12-20020a17090a428c00b00219404caaeasi14639544pjg.164.2022.12.26.06.23.16; Mon, 26 Dec 2022 06:23:28 -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=@kernel.org header.s=k20201202 header.b=E4k5OXvy; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230520AbiLZOWT (ORCPT + 99 others); Mon, 26 Dec 2022 09:22:19 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231614AbiLZOWG (ORCPT ); Mon, 26 Dec 2022 09:22:06 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F6B91140; Mon, 26 Dec 2022 06:22:06 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E0F4560EB4; Mon, 26 Dec 2022 14:22:05 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2F842C433D2; Mon, 26 Dec 2022 14:22:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064525; bh=22S317lWg8AbLm/4T86Rzeza0QVf8ZdO+6YLdtwviT0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=E4k5OXvypcw8JKWNx6C4dSUgCG2CsGTlxUbLraGkrXVSvF8AMAD7gX7KnyZDbc3uX ZsNzjvKiPxDxG+oR5TopbMGilH1sUH3bokqsnBHlqzkz4AQKh7/B9WXFNeej/reQya dU1Mnq6X+mGX9sykpmVkUki7ScBWs84ONjlv1qoJm0t7e79xu6cZNjMWpFMdd3vkwz UjJRhFH5fv+TqT8wdZI5Tw/E6K/zVf0vNVX4NLda6wj+29s3ruxs9Tya/z86tEjBE+ rwVylYF+UiX3jen7J7X3chKLADzrU7lT2hxuBJSNwCHwCwa6bpWJSQgoDQpm+LrrLt Mb4naxRegkZ+g== Received: by pali.im (Postfix) id DED229D7; Mon, 26 Dec 2022 15:22:04 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 04/18] ntfs: Fix error processing when load_nls() fails Date: Mon, 26 Dec 2022 15:21:36 +0100 Message-Id: <20221226142150.13324-5-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286819493376491?= X-GMAIL-MSGID: =?utf-8?q?1753286819493376491?= Ensure that specified charset in iocharset= mount option is used. On error correctly propagate error code back to the caller. Signed-off-by: Pali Rohár --- fs/ntfs/super.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c index 55762abdc22a..b4f26035e750 100644 --- a/fs/ntfs/super.c +++ b/fs/ntfs/super.c @@ -94,7 +94,7 @@ static bool parse_options(ntfs_volume *vol, char *opt) umode_t fmask = (umode_t)-1, dmask = (umode_t)-1; int mft_zone_multiplier = -1, on_errors = -1; int show_sys_files = -1, case_sensitive = -1, disable_sparse = -1; - struct nls_table *nls_map = NULL, *old_nls; + struct nls_table *nls_map = NULL; /* I am lazy... (-8 */ #define NTFS_GETOPT_WITH_DEFAULT(option, variable, default_value) \ @@ -195,20 +195,12 @@ static bool parse_options(ntfs_volume *vol, char *opt) if (!v || !*v) goto needs_arg; use_utf8: - old_nls = nls_map; + unload_nls(nls_map); nls_map = load_nls(v); if (!nls_map) { - if (!old_nls) { - ntfs_error(vol->sb, "NLS character set " - "%s not found.", v); - return false; - } - ntfs_error(vol->sb, "NLS character set %s not " - "found. Using previous one %s.", - v, old_nls->charset); - nls_map = old_nls; - } else /* nls_map */ { - unload_nls(old_nls); + ntfs_error(vol->sb, "NLS character set " + "%s not found.", v); + return false; } } else if (!strcmp(p, "utf8")) { bool val = false; From patchwork Mon Dec 26 14:21:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36626 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp935393wrt; Mon, 26 Dec 2022 06:24:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXseg9sgAg9ejUStDiPUzBqMX2YUClA+09fgy5nX0tcLPkl9Jdzu9MfRiEwcozmAFUAMnS7q X-Received: by 2002:a17:903:18b:b0:186:e378:91cf with SMTP id z11-20020a170903018b00b00186e37891cfmr30225196plg.37.1672064640213; Mon, 26 Dec 2022 06:24:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064640; cv=none; d=google.com; s=arc-20160816; b=BuVd/yE/syH0zK7yH5GFpn0HNVHa1mX1mRnzx/UgYJNMREoADRYHfIOZNbyHEv12ea Jz/lrgJxjgy9c7ciP5TUUdwI3Ik4asjTQpTp64ZDY5K9VOC9huxTHxeIEjU3RL2sWEVi UnX2i1mtP3x3480CygEZIVdHEOubmUuN2guxWMT41Lbc9dqsxfatjMKsczoY8GCLFSaO oxnaZosCL1QiFtB1aYKXhYZngXb5lz4MV6UqPrGq1FvGj+74iYSCTHtrAbaAa40A47W2 XWAgEI9zKsiy1/T1Itv2GJl2X7ExRm1lFk+SnfcvarSZotnMbYEALlanJntT8Zoa0/09 mkXw== 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:to:from :dkim-signature; bh=KywKEEZ6BXdLepfsftu36blI/hVu70rnpqO9tl4n2PQ=; b=e3kS5aDmTywpMvbqvRcavPvMqFhra27R/mrvg8+ss63QfStHLVT2oMCxAN4N6uEVOP EAKphSt0iZU7BVazRxcrO4a5bKCGsGxWOQ/A6QP1Lr0zK++0S+/Yp6OBkYSV91EHPJ6S h+rCwrAVNJaDHJ19QSj2ErSZVRvZpJFsjSkXPJQzGBGckvBaqSOCEzfGxJu0v5KABpA5 BsJQ0L6RMdIf36AZuJ493mQ4AwASaINk7AvoBNdheJDGudWtRtsCwqDI9iDJHy2zvNFm 4qLzZG4mA2PBsdwu8d0uWP0b3KRd+f1nlqHodNe4NCMs8Mt1pEoWFGCGpnU37YZmV892 +8nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="BtF/0hhH"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s9-20020a170902c64900b00191ffe197bbsi10338071pls.212.2022.12.26.06.23.47; Mon, 26 Dec 2022 06:24:00 -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=@kernel.org header.s=k20201202 header.b="BtF/0hhH"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232223AbiLZOWz (ORCPT + 99 others); Mon, 26 Dec 2022 09:22:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231935AbiLZOWK (ORCPT ); Mon, 26 Dec 2022 09:22:10 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 718F0262D; Mon, 26 Dec 2022 06:22:09 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 1C31FB80D42; Mon, 26 Dec 2022 14:22:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A9EA4C433D2; Mon, 26 Dec 2022 14:22:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064526; bh=ONMvtrjl0bWB4AJ/38sMd2FmiCDCBw+bnetddn3dC24=; h=From:To:Subject:Date:In-Reply-To:References:From; b=BtF/0hhHi7VDPuh08/nofWycrKkja0tYnSt9ZU1A049aN/GJy21ObSnDwEwMD2iCM 93ORyhD0HbbugTIyy62xetc+3pR6P9jADZXJKGu3XfBkY04qNSHxWLK+jEqO8dNax9 kcBgBevZ7IoV1tmQIhSXsy+WTTFoKKE910vIxllHEulPCLiG+Cf2cjt1LXplFtfopP Rsml4vweLF5idhuSWLsluFqQA/8vPBuEH0TzTvghg4L3QEY28s5+x6zAqkiRMyLCJm LfHApyp/MSrXItoCw5ijEpjQayVrmZNJOT5lbYO5G7SWc2PDpzmaHtBCR6xjqdkF+U r58o+Uruxdt2Q== Received: by pali.im (Postfix) id 63BF99D7; Mon, 26 Dec 2022 15:22:06 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 05/18] befs: Fix printing iocharset= mount option Date: Mon, 26 Dec 2022 15:21:37 +0100 Message-Id: <20221226142150.13324-6-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286851987596863?= X-GMAIL-MSGID: =?utf-8?q?1753286851987596863?= Mount option is named iocharset= and not charset= Signed-off-by: Pali Rohár --- fs/befs/linuxvfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c index 32749fcee090..f983852ba863 100644 --- a/fs/befs/linuxvfs.c +++ b/fs/befs/linuxvfs.c @@ -777,7 +777,7 @@ static int befs_show_options(struct seq_file *m, struct dentry *root) seq_printf(m, ",gid=%u", from_kgid_munged(&init_user_ns, opts->gid)); if (opts->iocharset) - seq_printf(m, ",charset=%s", opts->iocharset); + seq_printf(m, ",iocharset=%s", opts->iocharset); if (opts->debug) seq_puts(m, ",debug"); return 0; From patchwork Mon Dec 26 14:21:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36625 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp935391wrt; Mon, 26 Dec 2022 06:24:00 -0800 (PST) X-Google-Smtp-Source: AMrXdXsWG7/TyTv2snmWAmcTpRpkiSdCDUBasvKbapb2bLk/VSogqckoCGGqbFtcde9uOcRIBboo X-Received: by 2002:a05:6a20:3b22:b0:af:cede:8dee with SMTP id c34-20020a056a203b2200b000afcede8deemr21105929pzh.35.1672064640222; Mon, 26 Dec 2022 06:24:00 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064640; cv=none; d=google.com; s=arc-20160816; b=DLegBj/MGxcKuSDn91cAzM0ogVjoLwy3zQ7RdS51kzgpk9924ivHsA+eii83dtH4Bo GLAtQM7+rIHtt38QXKnTuGSdFyU+3WTvFFF+rOgAOuYrWnfwo/ZYZjC15KFXNqxJs0n/ DYBED2Cy4T/J6mrzlT91o5fKhZGDhfIanAmIHRdj5kIQh2LzoUXaPAE2OKBywHem1PR7 Yg4e6wUqbket9yULmcCaUR2SZjZpHQWoW0ROAxIdjWazDD8THhL4+2O76fIZaUEO1Bze sP2RRavBF2kybvr71ZOrtSNGRrEX5j/QzUEkhPjEQ54f/qugpy40+NHdQfz+V75lAGPF 53Zg== 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:to:from :dkim-signature; bh=LbnArp/Y0UQrurgqJvDl683E2eOgfoyDxSesZf6O2Dc=; b=Kl8fMAM/2K6s16MrtR3/CbyLe7mnCcxqqhNlnE9TOp8jqpJd2rM6qNTH4DHzEiXqdR ypTUdf1pAsXl05ijRJtQbpMQSVN6jDk4Z9hym1GJGM5CHp3T2WMDxst0WNJ1LaCaxWdW dOMYH160Hk/2CrciCSp3eIs6G9d09xCVOf3SwUBj3vR9qgkNMXEPk1fh+geAVn/yhLAQ mk5Fnyi7Qz3pJTTPV2aZv1Hb1Q0pVuJHGT5H1ey51ofJssVdB0u+ML0AoiAACzu6omsh +3WXHraM77k3srEZzjiBHzc80VRyP1+wlD6mgskJt62mXUasOhRD548nEXKSqqgIFknG PlqA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=pW2+TFrb; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 73-20020a63004c000000b004615836deeasi11454645pga.860.2022.12.26.06.23.47; Mon, 26 Dec 2022 06:24:00 -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=@kernel.org header.s=k20201202 header.b=pW2+TFrb; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232138AbiLZOWu (ORCPT + 99 others); Mon, 26 Dec 2022 09:22:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39118 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231896AbiLZOWJ (ORCPT ); Mon, 26 Dec 2022 09:22:09 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECE8A2613; Mon, 26 Dec 2022 06:22:08 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 728FB60EB1; Mon, 26 Dec 2022 14:22:08 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B26BEC433F0; Mon, 26 Dec 2022 14:22:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064527; bh=7z2lZ+Be7RkuOUgzW/6Khhu+Fp4b8cIx0oWTtjIwGLE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=pW2+TFrbcj9Y/de7k5L+kL7JaFTjxs8ZabMRJesm96TzLOlfKyD2ZU68GdwWD8OXT /MkTbPYx6x8/RdXTBHi3KPZQxXa8UGIALdcDx5R4UUCAIeGxc5H3qa0eefxO9C/Jd9 p6VIQ9PDX11m451GS7nAbpjNoq02pEoNbs7obTnCtto51IJC/LsXKGSoIa/p3oigPD SLjqwoOadzlBmO6fGa6k6SBurFCHiz+fFOrARIv28c5D32lF8h6Tan2asFNhWWAZmq GN/kH9H2zR240mg+LXhnncrZFZ0qrN76B7p4mgr/FFafhpqv3pN5093qKOle7exmNL rLQ12nQGwmE7g== Received: by pali.im (Postfix) id 6D4ED9D7; Mon, 26 Dec 2022 15:22:07 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 06/18] befs: Rename enum value Opt_charset to Opt_iocharset to match mount option Date: Mon, 26 Dec 2022 15:21:38 +0100 Message-Id: <20221226142150.13324-7-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286852261161812?= X-GMAIL-MSGID: =?utf-8?q?1753286852261161812?= Mount option is named iocharset= and not charset= Signed-off-by: Pali Rohár --- fs/befs/linuxvfs.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c index f983852ba863..5c66550f7933 100644 --- a/fs/befs/linuxvfs.c +++ b/fs/befs/linuxvfs.c @@ -677,13 +677,13 @@ static struct dentry *befs_get_parent(struct dentry *child) } enum { - Opt_uid, Opt_gid, Opt_charset, Opt_debug, Opt_err, + Opt_uid, Opt_gid, Opt_iocharset, Opt_debug, Opt_err, }; static const match_table_t befs_tokens = { {Opt_uid, "uid=%d"}, {Opt_gid, "gid=%d"}, - {Opt_charset, "iocharset=%s"}, + {Opt_iocharset, "iocharset=%s"}, {Opt_debug, "debug"}, {Opt_err, NULL} }; @@ -744,7 +744,7 @@ parse_options(char *options, struct befs_mount_options *opts) opts->gid = gid; opts->use_gid = 1; break; - case Opt_charset: + case Opt_iocharset: kfree(opts->iocharset); opts->iocharset = match_strdup(&args[0]); if (!opts->iocharset) { From patchwork Mon Dec 26 14:21:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36634 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp935782wrt; Mon, 26 Dec 2022 06:24:54 -0800 (PST) X-Google-Smtp-Source: AMrXdXsWf9nmwIbbvzTtzIxf28cORyERbrKlmQ98ab2JPWvSPSll6+56q6BFkOMZ9BiAXYmE9qh3 X-Received: by 2002:a05:6a21:e302:b0:a3:d6:8795 with SMTP id cb2-20020a056a21e30200b000a300d68795mr24653526pzc.17.1672064694184; Mon, 26 Dec 2022 06:24:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064694; cv=none; d=google.com; s=arc-20160816; b=aFZB6VXec1+e8XTh4NfgetfdXd1fNJSJlPXGuZACArgDtCN3xpNjS7+4FHJ5O3ok47 ao51+s10ivQZ95MWyown/NVgTa1IQUoxUiW6WvwY0EyniXdD8xztrogbia81P9O5eVxl J2SkY0LkZpfZ6oXReMSq4aUERMPDQR1HN7rZBvHJu6feKFamZYZMXl+andROoFau835X Fo1edrf5Rmn8BP/nwDxfujRPPTfC4Qn0OSfu1FM9yqUnv/EUVMOewEjBB63zA5gWUD51 weaOHuO/c/ldiZPaVQleBsy6Kpoj6zMLMX24awuMx/bVqSz+x1TdRePTzQoF7YSginL2 nI+w== 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:to:from :dkim-signature; bh=ceu7rm0zpGm/GJmhTlhx/aTfbFxYH6EaTcvQWJG9vJc=; b=xQ4LNiyJF0rDbRIhtLOaG0GEdaSjlUgdLMUeMo6CdBIu4TVbfE4Y6BNBKdTlEVSN9o eQuBKc1vQB/ZZTMYppP1bh+IoAg1Ypx2D/g0+aBzFtDVvZbyBKM/EfgzMQi4H7qP1604 y8zOxro+lXqFo/zyWDGaUIqjOgu2aqKOg30CXJd8nNRn19EnmkaVm6q6QsGXWaH7Be5V webeEgUnn7zoE3lMBTI7s3QScmGKKr0Wf3DBhPBC9ofjL6O0aZewtdzyahX9sU8SGGKi wWMrEA+hRke60dBgfs6XQOUOTQnzrBiGg0JDFukpPLjRU5QqEH4wX2G2ZM7QOlavWkv3 NBdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ITEyGudT; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f8-20020a056a001ac800b0056618176fd4si11897364pfv.148.2022.12.26.06.24.42; Mon, 26 Dec 2022 06:24: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=@kernel.org header.s=k20201202 header.b=ITEyGudT; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232299AbiLZOXE (ORCPT + 99 others); Mon, 26 Dec 2022 09:23:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39188 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231937AbiLZOWK (ORCPT ); Mon, 26 Dec 2022 09:22:10 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E1A295FCB; Mon, 26 Dec 2022 06:22:09 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 7D3D560EB7; Mon, 26 Dec 2022 14:22:09 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BFEEEC433D2; Mon, 26 Dec 2022 14:22:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064528; bh=n/8YydJ79H6S/fefunn6cS5wD6zvjrcaM37T3x4SMFw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ITEyGudTisy0cXAFBX6UA/0uO8IzKYmzwqZmTQfwsyU8qEjXxS8veri/7DHQtx2gE f/tC2MgveyNb4XnH2FXKEdpsxvf0aRkDnVAxTWvupN+x1TjHuDV6d0thwMxGap08hI mhkLBcN4s1dGvBHaM8AXziWJmTsKjlGE9eh2yuKx5056rBktL8OPI2ahK0J/RATzMy kGSGHNn/LeVBL6ZSVkSWPT2pK7fVoiDv9f6SIEyMjV31bk5PW1uuSNMvGFGOp5s8mK orIdD72HFP9XOkFHttlHqr+6DnRcNYGpQ207uuDc7fQtdj4tK2WM60BdcScb3TW3Bv Ne+0cPnSDicFQ== Received: by pali.im (Postfix) id 7BAC69D7; Mon, 26 Dec 2022 15:22:08 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 07/18] befs: Fix error processing when load_nls() fails Date: Mon, 26 Dec 2022 15:21:39 +0100 Message-Id: <20221226142150.13324-8-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286908402000368?= X-GMAIL-MSGID: =?utf-8?q?1753286908402000368?= Ensure that specified charset in iocharset= mount option is used. On error correctly propagate error code back to the caller. Signed-off-by: Pali Rohár --- fs/befs/linuxvfs.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c index 5c66550f7933..8d2954e3afd6 100644 --- a/fs/befs/linuxvfs.c +++ b/fs/befs/linuxvfs.c @@ -913,10 +913,9 @@ befs_fill_super(struct super_block *sb, void *data, int silent) befs_sb->mount_opts.iocharset); befs_sb->nls = load_nls(befs_sb->mount_opts.iocharset); if (!befs_sb->nls) { - befs_warning(sb, "Cannot load nls %s" - " loading default nls", + befs_error(sb, "Cannot load nls %s", befs_sb->mount_opts.iocharset); - befs_sb->nls = load_nls_default(); + goto unacquire_priv_sbp; } /* load default nls if none is specified in mount options */ } else { From patchwork Mon Dec 26 14:21:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36628 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp935406wrt; Mon, 26 Dec 2022 06:24:01 -0800 (PST) X-Google-Smtp-Source: AMrXdXtYPIrjDeUgNzMCpaTU1gpn1QO1mFlGFEZM3nuNDNXAWN52diH9J6CxeBtdfZv6KJegp6m+ X-Received: by 2002:a05:6a00:1f06:b0:581:366b:ca63 with SMTP id be6-20020a056a001f0600b00581366bca63mr2398698pfb.34.1672064641499; Mon, 26 Dec 2022 06:24:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064641; cv=none; d=google.com; s=arc-20160816; b=qZAtVYJITtxwr3EgHL5HffK0JgfIrq3aoI/Fn1toS65ZHTuHqOP4kqEoxtPfJ+k+c1 zo7FKtI2+tnJ329ueUmIt/viyolmL4P0ehXkZedbCIpHMzMlGuoDLIqrZCxlqSC6owwT PxmpwP2Xhhe58/drmJy2spiaGwLqxHwTlNsqsN5CKS11mrmHRteNc5R2jdAB6cjLb6Dx SgIRXmq5Vifz04gdbAtetF1jaZy55mpySbNWN6fuZ3SIsHyKJa/sX/oNG5dFME+C9Uj2 h5Q7QuoXB95+v8VdV351cWVYRKl8CBmFVwxVBZ0JWQXxpLTL3QSh3EXuJm4btWEVclFm dLAw== 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:to:from :dkim-signature; bh=rlNb/H2YpHsECRI7gjFepw+qr8opoFiXmh8kD2T2QDk=; b=wfVw11yOH/tfoYj3CNSnY/cnyHFglKfPyezNuyJZyTjlwCWzeWxuOlKSV9A4oF2ItP JrxQH/1P5/R9ve6YhC4eNhuT+nyYHMOny8C4ZNtcZkuwhVTbja+doScqFfBO/t2fDA7W HhKSM3ESj+bbIR/GXxOOPssmtbdQOZemL820JcX9XnGVhfz6eY+eECdWRO4tLkQZ/h/o cYMU6/oTh4WsRHp1w2iUWxL7LEV5j1VJcz/0yAKixGD4fSN8AL6dsA8WXwtkh1Pyagud GOCzPFFugeBDcqzbQp46qFZuicfhSfE8Jg+nQR5E4va+ZyTe7KKUa0DLtBu/ZUuC5Mt/ 84tQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="eN/lw5Dn"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id j3-20020a056a00174300b005787fd98b5fsi10776916pfc.274.2022.12.26.06.23.48; Mon, 26 Dec 2022 06:24:01 -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=@kernel.org header.s=k20201202 header.b="eN/lw5Dn"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232258AbiLZOW6 (ORCPT + 99 others); Mon, 26 Dec 2022 09:22:58 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39998 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230358AbiLZOWj (ORCPT ); Mon, 26 Dec 2022 09:22:39 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66E336387; Mon, 26 Dec 2022 06:22:12 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 24AA1B80D41; Mon, 26 Dec 2022 14:22:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C373CC433D2; Mon, 26 Dec 2022 14:22:09 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064529; bh=7SbfW9t2WEOzR8seGOYlZoIpmGQJDZj+robHHxNPvMg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=eN/lw5DnxdvYfY0ODuXLEVKk8TMiNQffzO157TNdgCyeYz3E1NQeWT+hcL+xZUwli 7SaS/CIG27kC5rvFtpnF69r70+2rhebnA/a8xvi6+a6ET8vR3BlMzqv+nd79m4Ctk5 HluUDpyMZ/J5cqCFLcLt005Koh/fhIIR1w+zSYRYBAFX2LeYqEqktySGVlYvhbiTeF 8qgaOW5dCRQkxY1QtcIyHGzT9NubIRCv3O2rPBzyhOLN2rbzxWVeKrAuX03CQzt6Qh Py1b9O3qYmaPBWcXE3fFmfng/+yEamTujxOXSUaKLvSHoolgw/axd9uTisp+6frJ3S SOqSEAybfSZCg== Received: by pali.im (Postfix) id 7E7D49D7; Mon, 26 Dec 2022 15:22:09 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 08/18] befs: Allow to use native UTF-8 mode Date: Mon, 26 Dec 2022 15:21:40 +0100 Message-Id: <20221226142150.13324-9-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286853385574307?= X-GMAIL-MSGID: =?utf-8?q?1753286853385574307?= befs driver already has a code which avoids usage of NLS when befs_sb->nls is not set. But befs_fill_super() always set befs_sb->nls, so activating native UTF-8 is not possible. Fix it by not setting befs_sb->nls when iocharset is set to utf8. So now after this cgange mount option iocharset=utf8 activates usage of native UTF-8 code path in befs driver. Signed-off-by: Pali Rohár --- fs/befs/linuxvfs.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c index 8d2954e3afd6..e5400123d33f 100644 --- a/fs/befs/linuxvfs.c +++ b/fs/befs/linuxvfs.c @@ -769,6 +769,7 @@ static int befs_show_options(struct seq_file *m, struct dentry *root) { struct befs_sb_info *befs_sb = BEFS_SB(root->d_sb); struct befs_mount_options *opts = &befs_sb->mount_opts; + struct nls_table *nls = befs_sb->nls; if (!uid_eq(opts->uid, GLOBAL_ROOT_UID)) seq_printf(m, ",uid=%u", @@ -776,8 +777,10 @@ static int befs_show_options(struct seq_file *m, struct dentry *root) if (!gid_eq(opts->gid, GLOBAL_ROOT_GID)) seq_printf(m, ",gid=%u", from_kgid_munged(&init_user_ns, opts->gid)); - if (opts->iocharset) - seq_printf(m, ",iocharset=%s", opts->iocharset); + if (nls) + seq_printf(m, ",iocharset=%s", nls->charset); + else + seq_puts(m, ",iocharset=utf8"); if (opts->debug) seq_puts(m, ",debug"); return 0; @@ -815,6 +818,7 @@ befs_fill_super(struct super_block *sb, void *data, int silent) const unsigned long sb_block = 0; const off_t x86_sb_off = 512; int blocksize; + const char *p; sb->s_fs_info = kzalloc(sizeof(*befs_sb), GFP_KERNEL); if (sb->s_fs_info == NULL) @@ -907,8 +911,11 @@ befs_fill_super(struct super_block *sb, void *data, int silent) goto unacquire_priv_sbp; } + p = befs_sb->mount_opts.iocharset ? befs_sb->mount_opts.iocharset : CONFIG_NLS_DEFAULT; + if (strcmp(p, "utf8") == 0) { + befs_debug(sb, "Using native UTF-8 without nls"); /* load nls library */ - if (befs_sb->mount_opts.iocharset) { + } else if (befs_sb->mount_opts.iocharset) { befs_debug(sb, "Loading nls: %s", befs_sb->mount_opts.iocharset); befs_sb->nls = load_nls(befs_sb->mount_opts.iocharset); From patchwork Mon Dec 26 14:21:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36629 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp935411wrt; Mon, 26 Dec 2022 06:24:02 -0800 (PST) X-Google-Smtp-Source: AMrXdXvnNApk7Kc1mmW3qbe/p9VYxJ5eG2boaEv444UCZoWiEovE1kSePFb8cn9CGmhJj+DT5goH X-Received: by 2002:a05:6a00:bca:b0:581:4ab0:abcd with SMTP id x10-20020a056a000bca00b005814ab0abcdmr1439405pfu.14.1672064642165; Mon, 26 Dec 2022 06:24:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064642; cv=none; d=google.com; s=arc-20160816; b=k+VlnKIg7jw2h9VMwBrwfK4ghYyeCenDnRDDITfiqZvmFM6+yw2/PcIYNxpw0AIosc s5JpML2DWdTRoRmQJCGZ5r/ZSI788dgdt0iftySmLO5l0+YVK/Jr/vOy+eRvJ2XJ7ozj /tqgQEgFr63y6moiO9dDjtimcunXjJ1x+AtLoNrdIigqpKGMNlzsP9ozuacfTtQgC1ZF IIWS4B7Ftt9bf2QQrC+sc8lcFEzRw1Os7CQoXiMXuZu9/9qTDWpKZmXuHbpVUtg+gC1f WamabWcEFBM7nLUpRoAGP9n9vY31yV6soIk12aCezfALxXSuDsWzo8q57UZLy3ix0Ccd FpXg== 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:to:from :dkim-signature; bh=vIQ9MnokPhKi52SKyUlpj47RS/HXqiFKM0jytnsflH8=; b=ar5XRkrvXInraPdOO8QG9HVqa/JCc67kRwYCalxS/zhjsSJhy8wPx+ZRot9VotU9Z3 oDBWZS6Ua9W3EiiW/JPhs0W05nppmCQF6bw09zX8JpysJMFMBJWCToTqstPl46J6+jHK gVJE22Krs/k727xyEyYVGy4wzCZnIU+oi2QQiZmcp4l6ZsYCdoMseltWQsphDw7CNwzL cO4TsrD4UDjro+B/WGaG0DMrUxxJDTovCwRrYYpmV2TJOuN6Nan3sEityi+W3g4UALga 9uHMeZ/vx3Tro+5seC6tptzmoW1wHfM7O7GGSdCZwdmsbKN9UDnoZoeAXKQKdvCFhSap sX5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="bXPSBq/b"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f8-20020a056a001ac800b0056618176fd4si11897364pfv.148.2022.12.26.06.23.49; Mon, 26 Dec 2022 06:24: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=@kernel.org header.s=k20201202 header.b="bXPSBq/b"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232288AbiLZOXC (ORCPT + 99 others); Mon, 26 Dec 2022 09:23:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229880AbiLZOWj (ORCPT ); Mon, 26 Dec 2022 09:22:39 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 344736355; Mon, 26 Dec 2022 06:22:12 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id B9D3B60ECE; Mon, 26 Dec 2022 14:22:11 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3ACBC4339B; Mon, 26 Dec 2022 14:22:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064531; bh=e4FwSq1/2Vygd9UHJiO4l6thoqlGGbMWoa45GXTb6aQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=bXPSBq/bP7mDyKk/wd7W2JTWVlPXVT2RboTFlj9iSVPG35ulA+hgbCALFNyvoXpAK Yzx7mAKXyDpUHW94zb7wQL8yTchXrjXuuat00MS5ai8YUUD0012uIT4a5QiKrben11 NiCBuc4j+WeR06kzqsy28JXcIIE6y+D28+aE+zwpIREYdOSEgPGowa1iHU/YDo8dzW EDUPDrgHTcuWSdij1wFlpD7SH5tOX3XQmKdIqRVayV6bWYMjfxjNz2Z7B7fMS4XACc N5+iICo51y3MEYVCT6SMx5h1Hb+Klz6/2ZgMj20wf0bPyTD31iHliqfFx2bD/geecu dLKaXbfGnsmnw== Received: by pali.im (Postfix) id 8CD359D7; Mon, 26 Dec 2022 15:22:10 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 09/18] hfs: Explicitly set hsb->nls_disk when hsb->nls_io is set Date: Mon, 26 Dec 2022 15:21:41 +0100 Message-Id: <20221226142150.13324-10-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286854520406848?= X-GMAIL-MSGID: =?utf-8?q?1753286854520406848?= It does not make any sense to set hsb->nls_io (NLS iocharset used between VFS and hfs driver) when hsb->nls_disk (NLS codepage used between hfs driver and disk) is not set. Reverse engineering driver code shown what is doing in this special case: When codepage was not defined but iocharset was then hfs driver copied 8bit character from disk directly to 16bit unicode wchar_t type. Which means it did conversion from Latin1 (ISO-8859-1) to Unicode because first 256 Unicode code points matches 8bit ISO-8859-1 codepage table. So when iocharset was specified and codepage not, then codepage used implicit value "iso8859-1". So when hsb->nls_disk is not set and hsb->nls_io is then explicitly set hsb->nls_disk to "iso8859-1". Such setup is obviously incompatible with Mac OS systems as they do not support iso8859-1 encoding for hfs. So print warning into dmesg about this fact. After this change hsb->nls_disk is always set, so remove code paths for case when hsb->nls_disk was not set as they are not needed anymore. Signed-off-by: Pali Rohár --- fs/hfs/super.c | 31 +++++++++++++++++++++++++++++++ fs/hfs/trans.c | 38 ++++++++++++++------------------------ 2 files changed, 45 insertions(+), 24 deletions(-) diff --git a/fs/hfs/super.c b/fs/hfs/super.c index 6764afa98a6f..cea19ed06bce 100644 --- a/fs/hfs/super.c +++ b/fs/hfs/super.c @@ -351,6 +351,37 @@ static int parse_options(char *options, struct hfs_sb_info *hsb) } } + if (hsb->nls_io && !hsb->nls_disk) { + /* + * Previous version of hfs driver did something unexpected: + * When codepage was not defined but iocharset was then + * hfs driver copied 8bit character from disk directly to + * 16bit unicode wchar_t type. Which means it did conversion + * from Latin1 (ISO-8859-1) to Unicode because first 256 + * Unicode code points matches 8bit ISO-8859-1 codepage table. + * So when iocharset was specified and codepage not, then + * codepage used implicit value "iso8859-1". + * + * To not change this previous default behavior as some users + * may depend on it, we load iso8859-1 NLS table explicitly + * to simplify code and make it more reable what happens. + * + * In context of hfs driver it is really strange to use + * ISO-8859-1 codepage table for storing data to disk, but + * nothing forbids it. Just it is highly incompatible with + * Mac OS systems. So via pr_warn() inform user that this + * is not probably what he wants. + */ + pr_warn("iocharset was specified but codepage not, " + "using default codepage=iso8859-1\n"); + pr_warn("this default codepage=iso8859-1 is incompatible with " + "Mac OS systems and may be changed in the future"); + hsb->nls_disk = load_nls("iso8859-1"); + if (!hsb->nls_disk) { + pr_err("unable to load iso8859-1 codepage\n"); + return 0; + } + } if (hsb->nls_disk && !hsb->nls_io) { hsb->nls_io = load_nls_default(); if (!hsb->nls_io) { diff --git a/fs/hfs/trans.c b/fs/hfs/trans.c index fdb0edb8a607..dbf535d52d37 100644 --- a/fs/hfs/trans.c +++ b/fs/hfs/trans.c @@ -48,18 +48,13 @@ int hfs_mac2asc(struct super_block *sb, char *out, const struct hfs_name *in) wchar_t ch; while (srclen > 0) { - if (nls_disk) { - size = nls_disk->char2uni(src, srclen, &ch); - if (size <= 0) { - ch = '?'; - size = 1; - } - src += size; - srclen -= size; - } else { - ch = *src++; - srclen--; + size = nls_disk->char2uni(src, srclen, &ch); + if (size <= 0) { + ch = '?'; + size = 1; } + src += size; + srclen -= size; if (ch == '/') ch = ':'; size = nls_io->uni2char(ch, dst, dstlen); @@ -119,20 +114,15 @@ void hfs_asc2mac(struct super_block *sb, struct hfs_name *out, const struct qstr srclen -= size; if (ch == ':') ch = '/'; - if (nls_disk) { - size = nls_disk->uni2char(ch, dst, dstlen); - if (size < 0) { - if (size == -ENAMETOOLONG) - goto out; - *dst = '?'; - size = 1; - } - dst += size; - dstlen -= size; - } else { - *dst++ = ch > 0xff ? '?' : ch; - dstlen--; + size = nls_disk->uni2char(ch, dst, dstlen); + if (size < 0) { + if (size == -ENAMETOOLONG) + goto out; + *dst = '?'; + size = 1; } + dst += size; + dstlen -= size; } } else { char ch; From patchwork Mon Dec 26 14:21:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36630 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp935483wrt; Mon, 26 Dec 2022 06:24:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXsBI0KrEZig2gC16r7zFbLAxNxzuBtbkJ/30iHYc5JVpiy9VG7LnSPEVrWt53N1pVr59opD X-Received: by 2002:a17:902:f7d3:b0:189:c57c:e048 with SMTP id h19-20020a170902f7d300b00189c57ce048mr18436320plw.27.1672064650962; Mon, 26 Dec 2022 06:24:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064650; cv=none; d=google.com; s=arc-20160816; b=xpljF7FJxfjfSyVHHAqkkYQp8ZVctAxM70DNlPL7oq/u9Rtysral70+tp3cG5zTcbG rVeoMvhKPwJXcbfU9AO3pus5/fImZhvOlWAHgx2wHxBRT6u0qCogtN82CnGT54xFetEM tzs/8VT6ePO3jCaTmocBTe4qEUv0iXwUl1VsRgvvcUdBJon+W+/TM+o41vI41RceRhQu Jwq2AsT6+Wu/DpLxON0fpdc+eI6ZikVbbNpXNpZPOIZq4KHbQHlUbrZUHXJ+pOLrPa3U 5KWTExq3h8phaddsRNgXcVhVVpJOVrMo+msMdndF6oUD64WA/cj2o8a4PUhked3263zN 4+BQ== 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:to:from :dkim-signature; bh=moFyKzKiRS792TVYHk/a6QpyU+oK5idvR2lLvDiIdvo=; b=BcKjl5kJu+Cq5fl/ovfLvKUZBYRRGSXxEU46be5TI5oi7mYXY8KFbNpVdclRmDspEz itibDVW7A0MlMk8lxCMAPvtYK5upWIMJoP04JYBBABNHgPQm1jeoJyPNg6PCH2dceERp jIBagrgZkoXaU1DidND2aOy1XYbBlHrF9gCBWj5nK0iO8E0dxMefbjCHePgqiglYZjnH XiQ5b3jwgg0/ORmf96P3jQWbqSzv5zBzcJE60xYOBrS8Fi5hQOHnIWwhTfXC+y9YgePE izMaFtlIRbpxmNocdhc3Jnag45VXZjIOf0L+aMDgRsvkDsNpZ2IhzEm6Dj/rXErsv3LI XB2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=Up4OAqH5; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l5-20020a170902e2c500b00180556e1b6bsi10410341plc.609.2022.12.26.06.23.55; Mon, 26 Dec 2022 06:24:10 -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=@kernel.org header.s=k20201202 header.b=Up4OAqH5; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232320AbiLZOXH (ORCPT + 99 others); Mon, 26 Dec 2022 09:23:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40002 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232030AbiLZOWj (ORCPT ); Mon, 26 Dec 2022 09:22:39 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 29CBD2608; Mon, 26 Dec 2022 06:22:13 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id BB22A60EB5; Mon, 26 Dec 2022 14:22:12 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3473C433D2; Mon, 26 Dec 2022 14:22:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064532; bh=Xsp3m3OsW4jVnQPkMQLxfCHZ/XiAut6pdb2ruAApCB4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Up4OAqH55iaCAJw883S9943eBNly3aIMlynhdSIFfKbVseamKeJfQH0MxLPkAHuPa 0RO+8XOWxMOAchvnruly8oZKaVEQHv93la8lc8DwyAqnDlp/+ol3zsBzwGycA5kTs3 PiipsjZFO53qGXeQAlkyrZ2Iet0frsmuqAA9GT26/1kj2XkqsT9ysgskuXT64p/YCW NdTkq630GuiyNhUfa+c2ohwTj+LBm3CEJKAf/qfyCBgrckS9wp2z+abpEpNKo+7RC4 qzXqOV8xr4EQF3Y0KwHx44xvTMy2W5MYRu++4b1Ux+ux6ypyB58J8MsaHiompDhxdR lLWkEteZYAALA== Received: by pali.im (Postfix) id 8C8A49D7; Mon, 26 Dec 2022 15:22:11 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 10/18] hfs: Do not use broken utf8 NLS table for iocharset=utf8 mount option Date: Mon, 26 Dec 2022 15:21:42 +0100 Message-Id: <20221226142150.13324-11-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286863723977308?= X-GMAIL-MSGID: =?utf-8?q?1753286863723977308?= NLS table for utf8 is broken and cannot be fixed. So instead of broken utf8 nls functions char2uni() and uni2char() use functions utf8_to_utf32() and utf32_to_utf8() which implements correct encoding and decoding between Unicode code points and UTF-8 sequence. When iochatset=utf8 is used then set hsb->nls_io to NULL and use it for distinguish between the fact if NLS table or native UTF-8 functions should be used. Signed-off-by: Pali Rohár --- fs/hfs/super.c | 33 ++++++++++++++++++++++----------- fs/hfs/trans.c | 24 ++++++++++++++++++++---- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/fs/hfs/super.c b/fs/hfs/super.c index cea19ed06bce..5a63df41da05 100644 --- a/fs/hfs/super.c +++ b/fs/hfs/super.c @@ -149,10 +149,13 @@ static int hfs_show_options(struct seq_file *seq, struct dentry *root) seq_printf(seq, ",part=%u", sbi->part); if (sbi->session >= 0) seq_printf(seq, ",session=%u", sbi->session); - if (sbi->nls_disk) + if (sbi->nls_disk) { seq_printf(seq, ",codepage=%s", sbi->nls_disk->charset); - if (sbi->nls_io) - seq_printf(seq, ",iocharset=%s", sbi->nls_io->charset); + if (sbi->nls_io) + seq_printf(seq, ",iocharset=%s", sbi->nls_io->charset); + else + seq_puts(seq, ",iocharset=utf8"); + } if (sbi->s_quiet) seq_printf(seq, ",quiet"); return 0; @@ -225,6 +228,7 @@ static int parse_options(char *options, struct hfs_sb_info *hsb) char *p; substring_t args[MAX_OPT_ARGS]; int tmp, token; + bool have_iocharset; /* initialize the sb with defaults */ hsb->s_uid = current_uid(); @@ -239,6 +243,8 @@ static int parse_options(char *options, struct hfs_sb_info *hsb) if (!options) return 1; + have_iocharset = false; + while ((p = strsep(&options, ",")) != NULL) { if (!*p) continue; @@ -332,18 +338,22 @@ static int parse_options(char *options, struct hfs_sb_info *hsb) kfree(p); break; case opt_iocharset: - if (hsb->nls_io) { + if (have_iocharset) { pr_err("unable to change iocharset\n"); return 0; } p = match_strdup(&args[0]); - if (p) - hsb->nls_io = load_nls(p); - if (!hsb->nls_io) { - pr_err("unable to load iocharset \"%s\"\n", p); - kfree(p); + if (!p) return 0; + if (strcmp(p, "utf8") != 0) { + hsb->nls_io = load_nls(p); + if (!hsb->nls_io) { + pr_err("unable to load iocharset \"%s\"\n", p); + kfree(p); + return 0; + } } + have_iocharset = true; kfree(p); break; default: @@ -351,7 +361,7 @@ static int parse_options(char *options, struct hfs_sb_info *hsb) } } - if (hsb->nls_io && !hsb->nls_disk) { + if (have_iocharset && !hsb->nls_disk) { /* * Previous version of hfs driver did something unexpected: * When codepage was not defined but iocharset was then @@ -382,7 +392,8 @@ static int parse_options(char *options, struct hfs_sb_info *hsb) return 0; } } - if (hsb->nls_disk && !hsb->nls_io) { + if (hsb->nls_disk && + !have_iocharset && strcmp(CONFIG_NLS_DEFAULT, "utf8") != 0) { hsb->nls_io = load_nls_default(); if (!hsb->nls_io) { pr_err("unable to load default iocharset\n"); diff --git a/fs/hfs/trans.c b/fs/hfs/trans.c index dbf535d52d37..01f37b395f10 100644 --- a/fs/hfs/trans.c +++ b/fs/hfs/trans.c @@ -44,7 +44,7 @@ int hfs_mac2asc(struct super_block *sb, char *out, const struct hfs_name *in) srclen = HFS_NAMELEN; dst = out; dstlen = HFS_MAX_NAMELEN; - if (nls_io) { + if (nls_disk) { wchar_t ch; while (srclen > 0) { @@ -57,7 +57,12 @@ int hfs_mac2asc(struct super_block *sb, char *out, const struct hfs_name *in) srclen -= size; if (ch == '/') ch = ':'; - size = nls_io->uni2char(ch, dst, dstlen); + if (nls_io) + size = nls_io->uni2char(ch, dst, dstlen); + else if (dstlen > 0) + size = utf32_to_utf8(ch, dst, dstlen); + else + size = -ENAMETOOLONG; if (size < 0) { if (size == -ENAMETOOLONG) goto out; @@ -101,11 +106,22 @@ void hfs_asc2mac(struct super_block *sb, struct hfs_name *out, const struct qstr srclen = in->len; dst = out->name; dstlen = HFS_NAMELEN; - if (nls_io) { + if (nls_disk) { wchar_t ch; + unicode_t u; while (srclen > 0 && dstlen > 0) { - size = nls_io->char2uni(src, srclen, &ch); + if (nls_io) + size = nls_io->char2uni(src, srclen, &ch); + else { + size = utf8_to_utf32(src, srclen, &u); + if (size >= 0) { + if (u <= MAX_WCHAR_T) + ch = u; + else + size = -EINVAL; + } + } if (size < 0) { ch = '?'; size = 1; From patchwork Mon Dec 26 14:21:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36632 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp935577wrt; Mon, 26 Dec 2022 06:24:24 -0800 (PST) X-Google-Smtp-Source: AMrXdXuDwWSGF9VJ6CTXLIAuS0BRlwYmrvDQuNCkBOr3gimuqaNVhVgwSh539tqTl6ft+vDrv1t6 X-Received: by 2002:a05:6a20:d819:b0:b2:3b40:32b1 with SMTP id iv25-20020a056a20d81900b000b23b4032b1mr22450894pzb.57.1672064663890; Mon, 26 Dec 2022 06:24:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064663; cv=none; d=google.com; s=arc-20160816; b=HVb+SJfogpCxnsdkWyQfBwGYxOJn0XK7QW6sYF+JDx6PyV4ZToRaim80LqUp849axw r5IeGPUvhC/vFDpgHgiXML8LCRyfKUYfd02T0FjhIatCma4AFIUvg8IKqzt3I/N9CkR2 PqsACPwrhe3VcLk9Y1BAtwWE6SyhwQDOi57frOoB9iAXcdaKY4PDADIYUUo9Ace9WdPk tejJcrTUF/xQYEfvyoDIFoq5EUzaPyFLGWLsYKxBJIHoNVWP1nusAeLJLYRqJj2MAfOU stgIf88+dtPDwVVdo6iSP5s+tmEXAixZ0DzdV6mhwKcIImmfLXzXpR9bU2Uivosam/5q Q++g== 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:to:from :dkim-signature; bh=X4Tjri0bpjl6+3YTehB44rO7d2yTB3OmstzEJiq8eKU=; b=qZwLri22nA0UEimcubPCHEZt7ud2SyMssd0xGfPkSTrzZhym+jQBsLaKyk/adYliXt KzwrEk6Ul178iDTdAZ/6ypr+ndLwxWxv9GKoRQYzHC18EBef3pgq4irOoCHD2Dv6do/Q ckh3klwcyr93t+VhXG0H/kfHWQPB85x6Gh+ZzllL+auUS0mkZALZVSuHR+X+rdu8yZxj 5a/ONfpuzzPcdrZadGv3tYsHgtSlJC+1i3MOjmoza3UBCmN3F6zpiC6GBqbXp0lobnoo OZGfhBBHzxDe2qW3N4tuVG2CIIcKX91/GhFeRwSHiW5ftas1FVeeXlFLjlUdgVVa9rSL 5EkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=S3ViSU88; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i24-20020a635418000000b004788ef3025asi11883050pgb.438.2022.12.26.06.24.10; Mon, 26 Dec 2022 06:24:23 -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=@kernel.org header.s=k20201202 header.b=S3ViSU88; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232334AbiLZOXJ (ORCPT + 99 others); Mon, 26 Dec 2022 09:23:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232042AbiLZOWk (ORCPT ); Mon, 26 Dec 2022 09:22:40 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EA453626F; Mon, 26 Dec 2022 06:22:14 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id DC8AA60EBD; Mon, 26 Dec 2022 14:22:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id F32A9C433EF; Mon, 26 Dec 2022 14:22:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064533; bh=y7MXoqLkJePjPQXj3TFzpaNKan0GSNj9EZYy1FjI9g4=; h=From:To:Subject:Date:In-Reply-To:References:From; b=S3ViSU88TaCehP3ML1X9O0tbfUFnzVxZAaKgV1lWa4jeRpmGD7Yo8jaoIGA84PNL7 L0JMUibflgJbT3PuFYAEM7tLDxz8lY/TNmxgQd8IB4j0ScHQf1H8HTmitora8vDBiV 6NKhpgoaNEHDmgDZI/0BgjB/Xw92r9UOLjsC8i8kSKfXQwr3+/CI6wpTuIrlLXdOqg 90g0hWvdyFlXX06PJWdSDJXhG4DfhNhn6hlhkEP+gvkKFSuGORNmP3M4KRsci/4Cx5 2B7t0F5CStktntNVl049TvyQmvSaVXbf32PqNmBdznjno2ekvADz/+YlmSDbws9wPh 7f4LbuEO54lIA== Received: by pali.im (Postfix) id AE1A99D7; Mon, 26 Dec 2022 15:22:12 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 11/18] hfsplus: Do not use broken utf8 NLS table for iocharset=utf8 mount option Date: Mon, 26 Dec 2022 15:21:43 +0100 Message-Id: <20221226142150.13324-12-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286877010438474?= X-GMAIL-MSGID: =?utf-8?q?1753286877010438474?= NLS table for utf8 is broken and cannot be fixed. So instead of broken utf8 nls functions char2uni() and uni2char() use functions utf8_to_utf32() and utf32_to_utf8() which implements correct encoding and decoding between Unicode code points and UTF-8 sequence. Note that this fs driver does not support full Unicode range, specially UTF-16 surrogate pairs are unsupported. This patch does not change this limitation and support for UTF-16 surrogate pairs stay unimplemented. When iochatset=utf8 is used then set sbi->nls to NULL and use it for distinguish between the fact if NLS table or native UTF-8 functions should be used. Signed-off-by: Pali Rohár --- fs/hfsplus/dir.c | 7 +++++-- fs/hfsplus/options.c | 32 ++++++++++++++++++-------------- fs/hfsplus/super.c | 7 +------ fs/hfsplus/unicode.c | 31 ++++++++++++++++++++++++++++--- fs/hfsplus/xattr.c | 20 +++++++++++++------- fs/hfsplus/xattr_security.c | 6 ++++-- 6 files changed, 69 insertions(+), 34 deletions(-) diff --git a/fs/hfsplus/dir.c b/fs/hfsplus/dir.c index 84714bbccc12..b19cb6c34dd2 100644 --- a/fs/hfsplus/dir.c +++ b/fs/hfsplus/dir.c @@ -144,7 +144,9 @@ static int hfsplus_readdir(struct file *file, struct dir_context *ctx) err = hfs_find_init(HFSPLUS_SB(sb)->cat_tree, &fd); if (err) return err; - strbuf = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_MAX_STRLEN + 1, GFP_KERNEL); + len = (HFSPLUS_SB(sb)->nls ? NLS_MAX_CHARSET_SIZE : 4) * + HFSPLUS_MAX_STRLEN + 1; + strbuf = kmalloc(len, GFP_KERNEL); if (!strbuf) { err = -ENOMEM; goto out; @@ -203,7 +205,8 @@ static int hfsplus_readdir(struct file *file, struct dir_context *ctx) hfs_bnode_read(fd.bnode, &entry, fd.entryoffset, fd.entrylength); type = be16_to_cpu(entry.type); - len = NLS_MAX_CHARSET_SIZE * HFSPLUS_MAX_STRLEN; + len = (HFSPLUS_SB(sb)->nls ? NLS_MAX_CHARSET_SIZE : 4) * + HFSPLUS_MAX_STRLEN; err = hfsplus_uni2asc(sb, &fd.key->cat.name, strbuf, &len); if (err) goto out; diff --git a/fs/hfsplus/options.c b/fs/hfsplus/options.c index d3dc0d4ba77f..ede7776d1da9 100644 --- a/fs/hfsplus/options.c +++ b/fs/hfsplus/options.c @@ -104,6 +104,9 @@ int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi) char *p; substring_t args[MAX_OPT_ARGS]; int tmp, token; + bool have_iocharset; + + have_iocharset = false; if (!input) goto done; @@ -175,20 +178,24 @@ int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi) pr_warn("option nls= is deprecated, use iocharset=\n"); fallthrough; case opt_iocharset: - if (sbi->nls) { + if (have_iocharset) { pr_err("unable to change nls mapping\n"); return 0; } p = match_strdup(&args[0]); - if (p) - sbi->nls = load_nls(p); - if (!sbi->nls) { - pr_err("unable to load nls mapping \"%s\"\n", - p); - kfree(p); + if (!p) return 0; + if (strcmp(p, "utf8") != 0) { + sbi->nls = load_nls(p); + if (!sbi->nls) { + pr_err("unable to load nls mapping " + "\"%s\"\n", p); + kfree(p); + return 0; + } } kfree(p); + have_iocharset = true; break; case opt_decompose: clear_bit(HFSPLUS_SB_NODECOMPOSE, &sbi->flags); @@ -211,13 +218,10 @@ int hfsplus_parse_options(char *input, struct hfsplus_sb_info *sbi) } done: - if (!sbi->nls) { - /* try utf8 first, as this is the old default behaviour */ - sbi->nls = load_nls("utf8"); - if (!sbi->nls) - sbi->nls = load_nls_default(); - if (!sbi->nls) - return 0; + if (!have_iocharset) { + /* use utf8, as this is the old default behaviour */ + pr_debug("using native UTF-8 without nls\n"); + /* no sbi->nls means that native UTF-8 code is used */ } return 1; diff --git a/fs/hfsplus/super.c b/fs/hfsplus/super.c index 122ed89ebf9f..8a66a77ad3e1 100644 --- a/fs/hfsplus/super.c +++ b/fs/hfsplus/super.c @@ -403,11 +403,7 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent) /* temporarily use utf8 to correctly find the hidden dir below */ nls = sbi->nls; - sbi->nls = load_nls("utf8"); - if (!sbi->nls) { - pr_err("unable to load nls for utf8\n"); - goto out_unload_nls; - } + sbi->nls = NULL; /* Grab the volume header */ if (hfsplus_read_wrapper(sb)) { @@ -585,7 +581,6 @@ static int hfsplus_fill_super(struct super_block *sb, void *data, int silent) } } - unload_nls(sbi->nls); sbi->nls = nls; return 0; diff --git a/fs/hfsplus/unicode.c b/fs/hfsplus/unicode.c index 73342c925a4b..dc9be40d049f 100644 --- a/fs/hfsplus/unicode.c +++ b/fs/hfsplus/unicode.c @@ -190,7 +190,12 @@ int hfsplus_uni2asc(struct super_block *sb, c0 = ':'; break; } - res = nls->uni2char(c0, op, len); + if (nls) + res = nls->uni2char(c0, op, len); + else if (len > 0) + res = utf32_to_utf8(c0, op, len); + else + res = -ENAMETOOLONG; if (res < 0) { if (res == -ENAMETOOLONG) goto out; @@ -233,7 +238,12 @@ int hfsplus_uni2asc(struct super_block *sb, cc = c0; } done: - res = nls->uni2char(cc, op, len); + if (nls) + res = nls->uni2char(cc, op, len); + else if (len > 0) + res = utf32_to_utf8(cc, op, len); + else + res = -ENAMETOOLONG; if (res < 0) { if (res == -ENAMETOOLONG) goto out; @@ -256,7 +266,22 @@ int hfsplus_uni2asc(struct super_block *sb, static inline int asc2unichar(struct super_block *sb, const char *astr, int len, wchar_t *uc) { - int size = HFSPLUS_SB(sb)->nls->char2uni(astr, len, uc); + struct nls_table *nls = HFSPLUS_SB(sb)->nls; + unicode_t u; + int size; + + if (nls) + size = nls->char2uni(astr, len, uc); + else { + size = utf8_to_utf32(astr, len, &u); + if (size >= 0) { + /* TODO: Add support for UTF-16 surrogate pairs */ + if (u <= MAX_WCHAR_T) + *uc = u; + else + size = -EINVAL; + } + } if (size <= 0) { *uc = '?'; size = 1; diff --git a/fs/hfsplus/xattr.c b/fs/hfsplus/xattr.c index 49891b12c415..607f46b3d0f3 100644 --- a/fs/hfsplus/xattr.c +++ b/fs/hfsplus/xattr.c @@ -422,11 +422,13 @@ int hfsplus_setxattr(struct inode *inode, const char *name, const void *value, size_t size, int flags, const char *prefix, size_t prefixlen) { + int xattr_name_len; char *xattr_name; int res; - xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, - GFP_KERNEL); + xattr_name_len = (HFSPLUS_SB(inode->i_sb)->nls ? NLS_MAX_CHARSET_SIZE : 4) * + HFSPLUS_ATTR_MAX_STRLEN + 1; + xattr_name = kmalloc(xattr_name_len, GFP_KERNEL); if (!xattr_name) return -ENOMEM; strcpy(xattr_name, prefix); @@ -578,9 +580,11 @@ ssize_t hfsplus_getxattr(struct inode *inode, const char *name, { int res; char *xattr_name; + int xattr_name_len; - xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, - GFP_KERNEL); + xattr_name_len = (HFSPLUS_SB(inode->i_sb)->nls ? NLS_MAX_CHARSET_SIZE : 4) * + HFSPLUS_ATTR_MAX_STRLEN + 1; + xattr_name = kmalloc(xattr_name_len, GFP_KERNEL); if (!xattr_name) return -ENOMEM; @@ -699,8 +703,9 @@ ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size) return err; } - strbuf = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + - XATTR_MAC_OSX_PREFIX_LEN + 1, GFP_KERNEL); + xattr_name_len = (HFSPLUS_SB(inode->i_sb)->nls ? NLS_MAX_CHARSET_SIZE : 4) * + HFSPLUS_ATTR_MAX_STRLEN + XATTR_MAC_OSX_PREFIX_LEN + 1; + strbuf = kmalloc(xattr_name_len, GFP_KERNEL); if (!strbuf) { res = -ENOMEM; goto out; @@ -732,7 +737,8 @@ ssize_t hfsplus_listxattr(struct dentry *dentry, char *buffer, size_t size) if (be32_to_cpu(attr_key.cnid) != inode->i_ino) goto end_listxattr; - xattr_name_len = NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN; + xattr_name_len = (HFSPLUS_SB(inode->i_sb)->nls ? NLS_MAX_CHARSET_SIZE : 4) * + HFSPLUS_ATTR_MAX_STRLEN; if (hfsplus_uni2asc(inode->i_sb, (const struct hfsplus_unistr *)&fd.key->attr.key_name, strbuf, &xattr_name_len)) { diff --git a/fs/hfsplus/xattr_security.c b/fs/hfsplus/xattr_security.c index c1c7a16cbf21..b4b45c796ef4 100644 --- a/fs/hfsplus/xattr_security.c +++ b/fs/hfsplus/xattr_security.c @@ -38,11 +38,13 @@ static int hfsplus_initxattrs(struct inode *inode, void *fs_info) { const struct xattr *xattr; + int xattr_name_len; char *xattr_name; int err = 0; - xattr_name = kmalloc(NLS_MAX_CHARSET_SIZE * HFSPLUS_ATTR_MAX_STRLEN + 1, - GFP_KERNEL); + xattr_name_len = (HFSPLUS_SB(inode->i_sb)->nls ? NLS_MAX_CHARSET_SIZE : 4) * + HFSPLUS_ATTR_MAX_STRLEN + 1; + xattr_name = kmalloc(xattr_name_len, GFP_KERNEL); if (!xattr_name) return -ENOMEM; for (xattr = xattr_array; xattr->name != NULL; xattr++) { From patchwork Mon Dec 26 14:21:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36631 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp935486wrt; Mon, 26 Dec 2022 06:24:11 -0800 (PST) X-Google-Smtp-Source: AMrXdXtSjbXcYo9Y9Dab3IoatWUb4mQWhDiy6qv7Syyq7nMVoL3UfyVwV9uK5Z1MSC5uuiSEOygh X-Received: by 2002:a17:90a:ec03:b0:223:fbeb:f1eb with SMTP id l3-20020a17090aec0300b00223fbebf1ebmr20472418pjy.4.1672064651278; Mon, 26 Dec 2022 06:24:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064651; cv=none; d=google.com; s=arc-20160816; b=Lg4AIJM7oYUoh+/28pZqz8J8cU7WRI6MwqKLLybZqudg+yXY7mbDi/XCSKTF35Vpro 9FRBI4bn0UGc3KQ33INebasJeDhfI4fbb55pUj+2K5DYiyLvdR4ymaQnk8TWP836fNPH 11hB2G8XbWbu9DukhgaRYQx2VJWHa1JwkCe7s+fVA3h/HtW3biAxpBS/BvHa0zcuBVFr J7fjO0k+TtC9t2feGe2PSPtma6o13atgyLO/N+UNQ+s39V0qnXzl/GzaM7bCiox6ch6l yQJjUpk39bEMHr0076oF+WYR7HiL8DHrgzNEzz5PV0kgeO+4KWKXsKpWF29RLyYuk857 h5+Q== 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:to:from :dkim-signature; bh=2tVQnL+/ABsvxQwaGLH03NlHqKtaC0ctIFrv3JllskU=; b=WSDfbvHeixa0TNgWW5o7Fn/DtNnv7cB6tkGAnDXaI5cHNGa0tKXlmQWTY/bLfbd0m3 L/0MIHdjZt1EyH1/IYnG/YfQZbPfX4FysLju0ef0B3c2olWg2EVlpCTmy+t68RYoZMX2 HUxf7aua1mqP56MI2DY2FfRaRynDkKLfsL1vLtATzBMpDgyliWqbEqBOHjlNsYTVhrh4 FKsfPc+s8G6AuVON6S5b+ZFKGJT0EU+2ZEe/73aVLiBxbsIjg1jSYJlnRtXfiqnyd+NR H+Y14A1N3fu8N8Ei1wxhLjFctJAxnh77rsi++VmTdgoEanJGOLj6WdUb+P6dH1IPnCov PX1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=nAKwOBNQ; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nu9-20020a17090b1b0900b00210d1aeabc1si15907316pjb.188.2022.12.26.06.23.55; Mon, 26 Dec 2022 06:24:11 -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=@kernel.org header.s=k20201202 header.b=nAKwOBNQ; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232350AbiLZOXN (ORCPT + 99 others); Mon, 26 Dec 2022 09:23:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40024 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232047AbiLZOWk (ORCPT ); Mon, 26 Dec 2022 09:22:40 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73AC06178; Mon, 26 Dec 2022 06:22:15 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0BD0560EBB; Mon, 26 Dec 2022 14:22:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 23E69C433D2; Mon, 26 Dec 2022 14:22:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064534; bh=MTbJQXmNYIn3aIarKGddxE1E8WlMgp5B50dVxH4DJ4Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=nAKwOBNQge72LJf3BR6bK0gFclV7iB2LTO/ZPBjQ6PXtoHYu8uiBLepZmf33P9IOj 4LntY2IUWK6Q7NqH0RyXZI42XK5PqaaOsRnbg9Y0LPZlF222iMalDK3PsW4xLDl//j 7sS4MCexxoHY65fiXFNmzotdf1+VOIxwMVqUZkPQejJ7eh5QTq7yTWnFUA8Tg8iELD mhFR5xRn9KgjQup7u8tT6jm1yAJStxUKJDw14cMRemu+pPVg2/WgXaWLEFiZ1rLzHE 3Jy4UtensntSs+1cPmpSVS3b0wtZ3f0o5aT8X/m4GnFcHQym06PJ/5C0QLmoU1RYOW 5hKB5J97xCu9g== Received: by pali.im (Postfix) id D1E989D7; Mon, 26 Dec 2022 15:22:13 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 12/18] jfs: Remove custom iso8859-1 implementation Date: Mon, 26 Dec 2022 15:21:44 +0100 Message-Id: <20221226142150.13324-13-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286863602697628?= X-GMAIL-MSGID: =?utf-8?q?1753286863602697628?= When iocharset= mount option is not specified or when is set to iocharset=none then jfs driver uses its own custom iso8895-1 encoding implementation. NLS already provides iso8895-1 module, so use it instead of custom jfs iso8859-1 implementation. Signed-off-by: Pali Rohár --- fs/jfs/jfs_unicode.c | 14 +------------- fs/jfs/super.c | 29 +++++++++++++++++++---------- 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/fs/jfs/jfs_unicode.c b/fs/jfs/jfs_unicode.c index 0c1e9027245a..1d0f65d13b58 100644 --- a/fs/jfs/jfs_unicode.c +++ b/fs/jfs/jfs_unicode.c @@ -33,13 +33,8 @@ int jfs_strfromUCS_le(char *to, const __le16 * from, NLS_MAX_CHARSET_SIZE); if (charlen > 0) outlen += charlen; - else + else { to[outlen++] = '?'; - } - } else { - for (i = 0; (i < len) && from[i]; i++) { - if (unlikely(le16_to_cpu(from[i]) & 0xff00)) { - to[i] = '?'; if (unlikely(warn)) { warn--; warn_again--; @@ -49,12 +44,8 @@ int jfs_strfromUCS_le(char *to, const __le16 * from, printk(KERN_ERR "mount with iocharset=utf8 to access\n"); } - } - else - to[i] = (char) (le16_to_cpu(from[i])); } - outlen = i; } to[outlen] = 0; return outlen; @@ -84,9 +75,6 @@ static int jfs_strtoUCS(wchar_t * to, const unsigned char *from, int len, return charlen; } } - } else { - for (i = 0; (i < len) && from[i]; i++) - to[i] = (wchar_t) from[i]; } to[i] = 0; diff --git a/fs/jfs/super.c b/fs/jfs/super.c index d2f82cb7db1b..a2bb3d5d3f69 100644 --- a/fs/jfs/super.c +++ b/fs/jfs/super.c @@ -231,7 +231,7 @@ static const match_table_t tokens = { }; static int parse_options(char *options, struct super_block *sb, s64 *newLVSize, - int *flag) + int *flag, int remount) { void *nls_map = (void *)-1; /* -1: no change; NULL: none */ char *p; @@ -263,14 +263,14 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize, case Opt_iocharset: if (nls_map && nls_map != (void *) -1) unload_nls(nls_map); - if (!strcmp(args[0].from, "none")) - nls_map = NULL; - else { + /* compatibility alias none means ISO-8859-1 */ + if (strcmp(args[0].from, "none") == 0) + nls_map = load_nls("iso8859-1"); + else nls_map = load_nls(args[0].from); - if (!nls_map) { - pr_err("JFS: charset not found\n"); - goto cleanup; - } + if (!nls_map) { + pr_err("JFS: charset not found\n"); + goto cleanup; } break; case Opt_resize: @@ -409,6 +409,15 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize, } } + if (!remount && nls_map == (void *) -1) { + /* Previously default NLS table was ISO-8859-1 */ + nls_map = load_nls("iso8859-1"); + if (!nls_map) { + pr_err("JFS: iso8859-1 charset not found\n"); + goto cleanup; + } + } + if (nls_map != (void *) -1) { /* Discard old (if remount) */ unload_nls(sbi->nls_tab); @@ -430,7 +439,7 @@ static int jfs_remount(struct super_block *sb, int *flags, char *data) int ret; sync_filesystem(sb); - if (!parse_options(data, sb, &newLVSize, &flag)) + if (!parse_options(data, sb, &newLVSize, &flag, 1)) return -EINVAL; if (newLVSize) { @@ -508,7 +517,7 @@ static int jfs_fill_super(struct super_block *sb, void *data, int silent) /* initialize the mount flag and determine the default error handler */ flag = JFS_ERR_REMOUNT_RO; - if (!parse_options((char *) data, sb, &newLVSize, &flag)) + if (!parse_options((char *) data, sb, &newLVSize, &flag, 0)) goto out_kfree; sbi->flag = flag; From patchwork Mon Dec 26 14:21:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36633 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp935652wrt; Mon, 26 Dec 2022 06:24:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXu9BRGlBX4W4uPP+ehpVQHBltDhXVvu37Ll0sThyDyQCcCA+UjnzN/a1OsOexE3y2WPdD7Q X-Received: by 2002:a17:902:ff0f:b0:192:4887:f7b9 with SMTP id f15-20020a170902ff0f00b001924887f7b9mr22099270plj.17.1672064677973; Mon, 26 Dec 2022 06:24:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064677; cv=none; d=google.com; s=arc-20160816; b=mKhExmIAHlFeKj8cS5Vk08v93ocPsJRfAF+ZSci3lYy/VkDx06btnnRUViply6fViJ 9V/VsLhOG0SG0412L05MJfEKCzk7ba2MO2Ae7q7eyIi4hTor0gL2/vcnFcpT4qY4Mpiq Kl0WwWfGFHVsqBBVkrqB/6tdggqelKWDzbnyMYOwsljsHoXPfVz7sx+M4UX+zMQqNF2O RPLTQzqp3ZJ5WhbEAnhF/8aAB5y0vXg5A6r3Ayw7Ov0L+QVkwMzSUKs/4a0SFFsBpIXx Tj3j5T0jF1ZBnnMioE4VRhn2/ea1HGXqaQNwSV5VCmGpzVOr4S8PVyjjJ3cQD2h26rgN D97g== 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:to:from :dkim-signature; bh=BwnTyzNV8I/bIU+cBVO+pE3+gBQjJaZOKh3deLlu/7I=; b=GY+/UN1Bh6DJ3LNfwNcOZDe3BUFd4lCM3v63ss30udAEkSnYoGLP9fgzElmLfMhyVE R9CeccrmwYDBsAMcWJZp7h/2nWTC3pW3xJZADik0S5oO6diRh8/qc7gX/5CgRTYpxyRE blpgaFBYCfAQY1306Mh1+U2p3fh9ljGo4TlJXY7kGq4L1gENO8zPNPFYHZSnbvEgxJ2I ipnXM6GDHntAWhIi7NIYA7pqayxgc9tymh1/y4ariK7wQtGxDQLmaUiSFLscuJwJy9Ds Y2ItvIWLFYiDkdd8u3eS9P8jZZd+D/J4MoliiOxWbBDPoJ0VbxMhCq0L/cth2kX7hM6S RHqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=k1C6pep7; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id y3-20020a17090322c300b00179ec1d9eb4si12715436plg.112.2022.12.26.06.24.25; Mon, 26 Dec 2022 06:24:37 -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=@kernel.org header.s=k20201202 header.b=k1C6pep7; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232372AbiLZOXP (ORCPT + 99 others); Mon, 26 Dec 2022 09:23:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39148 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232056AbiLZOWk (ORCPT ); Mon, 26 Dec 2022 09:22:40 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A3AF63BF; Mon, 26 Dec 2022 06:22:16 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 26BC760EB5; Mon, 26 Dec 2022 14:22:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3DDD4C433F2; Mon, 26 Dec 2022 14:22:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064535; bh=KTlaKtoc30smqwDFYdlWnFXEn9JLsGy9kBhgPLFkugI=; h=From:To:Subject:Date:In-Reply-To:References:From; b=k1C6pep7mjb2vxyhmR6RmjD5TxwJDJwot8DuSPJBJDV53ijpJR+rV1MBrf7h3cb6m me7Pg6aNRllW0ZdOkLjWFHwaqfLeK8FixgI8Lx9frkhm8Sz/qPflhrh1HrDSZR1KZ5 Yj7LUS4AdmfbcvFn88aAEZmGxv+mlpNPtAa/cv4CKXt3VjW687mqwFX0Tuk/r5DrB6 zY5bk1RoDqtWT5rYh/oIZr+vl4bHQO/fg9xySFujE/B5pvIbJrJi8m+ci3q1N818jj rIWMcCC2am4zCGZDtMhvUJWbhz6CE/2B9XB0p4kL3gxo7YjZXJf7Slpjd3mPm0exA1 kGWP5cEi4dzEQ== Received: by pali.im (Postfix) id E8E4C9D7; Mon, 26 Dec 2022 15:22:14 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 13/18] jfs: Fix buffer overflow in jfs_strfromUCS_le() function Date: Mon, 26 Dec 2022 15:21:45 +0100 Message-Id: <20221226142150.13324-14-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286891728388799?= X-GMAIL-MSGID: =?utf-8?q?1753286891728388799?= Function jfs_strfromUCS_le() writes to unknown offset in buffer allocated by __get_free_page(GFP_KERNEL). So it cannot expects that there is least NLS_MAX_CHARSET_SIZE bytes space before end of that buffer. Fix this issue by add a new parameter maxlen for jfs_strfromUCS_le() function. And use it for passing remaining size of buffer to prevent buffer overflow in kernel. Signed-off-by: Pali Rohár --- fs/jfs/jfs_dtree.c | 13 ++++++++++--- fs/jfs/jfs_unicode.c | 6 +++--- fs/jfs/jfs_unicode.h | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/fs/jfs/jfs_dtree.c b/fs/jfs/jfs_dtree.c index 92b7c533407c..a09c9bc46351 100644 --- a/fs/jfs/jfs_dtree.c +++ b/fs/jfs/jfs_dtree.c @@ -2715,6 +2715,7 @@ int jfs_readdir(struct file *file, struct dir_context *ctx) int d_namleft, len, outlen; unsigned long dirent_buf; char *name_ptr; + int maxlen; u32 dir_index; int do_index = 0; uint loop_count = 0; @@ -2937,7 +2938,10 @@ int jfs_readdir(struct file *file, struct dir_context *ctx) } /* copy the name of head/only segment */ - outlen = jfs_strfromUCS_le(name_ptr, d->name, len, + maxlen = PAGE_SIZE - sizeof(struct jfs_dirent) - + (name_ptr - jfs_dirent->name); + outlen = jfs_strfromUCS_le(name_ptr, maxlen, + d->name, len, codepage); jfs_dirent->name_len = outlen; @@ -2957,8 +2961,11 @@ int jfs_readdir(struct file *file, struct dir_context *ctx) goto skip_one; } len = min(d_namleft, DTSLOTDATALEN); - outlen = jfs_strfromUCS_le(name_ptr, t->name, - len, codepage); + maxlen = PAGE_SIZE - sizeof(struct jfs_dirent) - + (name_ptr - jfs_dirent->name); + outlen = jfs_strfromUCS_le(name_ptr, maxlen, + t->name, len, + codepage); jfs_dirent->name_len += outlen; next = t->next; diff --git a/fs/jfs/jfs_unicode.c b/fs/jfs/jfs_unicode.c index 1d0f65d13b58..2db923872bf1 100644 --- a/fs/jfs/jfs_unicode.c +++ b/fs/jfs/jfs_unicode.c @@ -16,7 +16,7 @@ * FUNCTION: Convert little-endian unicode string to character string * */ -int jfs_strfromUCS_le(char *to, const __le16 * from, +int jfs_strfromUCS_le(char *to, int maxlen, const __le16 * from, int len, struct nls_table *codepage) { int i; @@ -25,12 +25,12 @@ int jfs_strfromUCS_le(char *to, const __le16 * from, int warn = !!warn_again; /* once per string */ if (codepage) { - for (i = 0; (i < len) && from[i]; i++) { + for (i = 0; (i < len) && from[i] && outlen < maxlen-1; i++) { int charlen; charlen = codepage->uni2char(le16_to_cpu(from[i]), &to[outlen], - NLS_MAX_CHARSET_SIZE); + maxlen-1-outlen); if (charlen > 0) outlen += charlen; else { diff --git a/fs/jfs/jfs_unicode.h b/fs/jfs/jfs_unicode.h index 9db62d047daa..8b5c74315e07 100644 --- a/fs/jfs/jfs_unicode.h +++ b/fs/jfs/jfs_unicode.h @@ -19,7 +19,7 @@ typedef struct { extern signed char UniUpperTable[512]; extern UNICASERANGE UniUpperRange[]; extern int get_UCSname(struct component_name *, struct dentry *); -extern int jfs_strfromUCS_le(char *, const __le16 *, int, struct nls_table *); +extern int jfs_strfromUCS_le(char *, int, const __le16 *, int, struct nls_table *); #define free_UCSname(COMP) kfree((COMP)->name) From patchwork Mon Dec 26 14:21:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36635 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp935861wrt; Mon, 26 Dec 2022 06:25:03 -0800 (PST) X-Google-Smtp-Source: AMrXdXv9GAjYwXZiBRYsen97x+c9YL84C8QAIbCEWCdi/ApuAVnE0qRTa55m9bOXzYIyr0pdoB6A X-Received: by 2002:a17:902:aa8e:b0:191:4575:48aa with SMTP id d14-20020a170902aa8e00b00191457548aamr19075993plr.11.1672064703240; Mon, 26 Dec 2022 06:25:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064703; cv=none; d=google.com; s=arc-20160816; b=0Wp/NlDDdEZD/HgvqsECw9mAP7y7in8hWGsn7PqV1M2L2JV5SnpSkWeGkAccyP2yWA Rhoc8V+XM25/SEiTGKZH3ch1PUVBwxAt2/r54wjCEfnLInHGuFMWhWq9lOJ47uZ9T75e a1Uh/Dx3SgfmlsvDR+AANkl2sxH4xqBI1ZCnc2ULqRWcazVvkyLVF4BQBzdIYISFW+vX XS9eIJ09k58xT8Dm3HnBZa5rlsgLdmGhz/d5PLla5hVXudbHt1kRRM+zlFBzKR8oczjJ MIX114fzjpWqLnlGeiAR6RyqgRjAI0qbfytN08eb9EGjIEJkEOoJsQF1+gdao7EWqAPl 4UcQ== 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:to:from :dkim-signature; bh=bfEqdlPniHeQegWMRx7tq5haZbjbMz/mCb6tJYDRlKs=; b=D2Y/d/KMy9/SKpoLL02egGIfSzmpghNdOecKQAHH84OmJo5viTzX6VXR/FVCzhrpzc kfFBMEPz5rtX3nLX30Sl7B6+Uc/Y8D/jst5zdOQFSR3mavVR37N2NZapuBP+Bz/4DhXv aWd/kb9Icj1rILMDxZXCVDH6bY/9uBpWpudLj2ixDtti7R2zdiT93Sk/trxznacOhp7k 7P60YShdbePi4StNCQrysNmBhDkw4lZGGfY5QIp8XL0kqvMZeZuwNe2rlfJ+LzttG/J3 Hf7Xq1C+vLeotxbpLxYPCmgspr4pBffEPMAkpP2CDSTTzky6HMZbbp+yXCZfrfNiVlPR tkUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=efntnbsb; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s15-20020a170902ea0f00b0018965226454si12654304plg.501.2022.12.26.06.24.51; Mon, 26 Dec 2022 06:25: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=@kernel.org header.s=k20201202 header.b=efntnbsb; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232083AbiLZOXV (ORCPT + 99 others); Mon, 26 Dec 2022 09:23:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232082AbiLZOWm (ORCPT ); Mon, 26 Dec 2022 09:22:42 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C38E63DE; Mon, 26 Dec 2022 06:22:17 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 2AB7760ECC; Mon, 26 Dec 2022 14:22:17 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 44A37C433D2; Mon, 26 Dec 2022 14:22:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064536; bh=UK6BsAqbMHD2yEk56WVb4gYlz7RwyfUXM7sbl2vvPCA=; h=From:To:Subject:Date:In-Reply-To:References:From; b=efntnbsbXMUd/3GVdPWgMJrVdE4PvcR0ghBC55RqUJ4rPHQlXrJMXeykHqg94BVpB hu2ZGUq8HkJSJnELi0aFA0lGyrMRBKpN+N3VjxBZq6OEW1vrHiVQun4Hhm2c6algSG 8fh6m1xxtDXfE38s3iwstylP1uwUkLdJEtfKPZY6XcEKjnJzCtr0SN+BPTpyiHwI5J 44uZ8tYtcuRDPT0WXsPT34PpSRjG+5roeG9qcYMnjMFfLmyk5HE1RHWxi+P+iRGlGx W+wkKS7UAwKqhk8UvHsm5Ltkew/N9vQ6WAzRtLJod71xGKcxsd5OJ286VWej6f4UQV ZJmdCwwMPQHPQ== Received: by pali.im (Postfix) id F1EC09D7; Mon, 26 Dec 2022 15:22:15 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 14/18] jfs: Do not use broken utf8 NLS table for iocharset=utf8 mount option Date: Mon, 26 Dec 2022 15:21:46 +0100 Message-Id: <20221226142150.13324-15-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286918440953497?= X-GMAIL-MSGID: =?utf-8?q?1753286918440953497?= NLS table for utf8 is broken and cannot be fixed. So instead of broken utf8 nls functions char2uni() and uni2char() use functions utf8s_to_utf16s() and utf16s_to_utf8s() which implements correct conversion between UTF-16 and UTF-8. These functions implements also correct processing of UTF-16 surrogate pairs and therefore after this change jfs driver would be able to correctly handle also file names with 4-byte UTF-8 sequences. When iochatset=utf8 is used then set sbi->nls_tab to NULL and use it for distinguish between the fact if NLS table or native UTF-8 functions should be used. Signed-off-by: Pali Rohár --- fs/jfs/jfs_unicode.c | 17 +++++++++++++++-- fs/jfs/super.c | 24 +++++++++++++++--------- 2 files changed, 30 insertions(+), 11 deletions(-) diff --git a/fs/jfs/jfs_unicode.c b/fs/jfs/jfs_unicode.c index 2db923872bf1..0b0b80063a98 100644 --- a/fs/jfs/jfs_unicode.c +++ b/fs/jfs/jfs_unicode.c @@ -46,6 +46,9 @@ int jfs_strfromUCS_le(char *to, int maxlen, const __le16 * from, } } } + } else { + outlen = utf16s_to_utf8s((const wchar_t *)from, len, + UTF16_LITTLE_ENDIAN, to, maxlen-1); } to[outlen] = 0; return outlen; @@ -61,6 +64,7 @@ static int jfs_strtoUCS(wchar_t * to, const unsigned char *from, int len, struct nls_table *codepage) { int charlen; + int outlen; int i; if (codepage) { @@ -75,10 +79,19 @@ static int jfs_strtoUCS(wchar_t * to, const unsigned char *from, int len, return charlen; } } + outlen = i; + } else { + outlen = utf8s_to_utf16s(from, len, UTF16_LITTLE_ENDIAN, + to, len); + if (outlen < 1) { + jfs_err("jfs_strtoUCS: utf8s_to_utf16s returned %d.", + outlen); + return outlen; + } } - to[i] = 0; - return i; + to[outlen] = 0; + return outlen; } /* diff --git a/fs/jfs/super.c b/fs/jfs/super.c index a2bb3d5d3f69..f26460147b62 100644 --- a/fs/jfs/super.c +++ b/fs/jfs/super.c @@ -261,16 +261,20 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize, /* Don't do anything ;-) */ break; case Opt_iocharset: - if (nls_map && nls_map != (void *) -1) + if (nls_map && nls_map != (void *) -1) { unload_nls(nls_map); - /* compatibility alias none means ISO-8859-1 */ - if (strcmp(args[0].from, "none") == 0) - nls_map = load_nls("iso8859-1"); - else - nls_map = load_nls(args[0].from); - if (!nls_map) { - pr_err("JFS: charset not found\n"); - goto cleanup; + nls_map = NULL; + } + if (strcmp(args[0].from, "utf8") != 0) { + /* compatibility alias none means ISO-8859-1 */ + if (strcmp(args[0].from, "none") == 0) + nls_map = load_nls("iso8859-1"); + else + nls_map = load_nls(args[0].from); + if (!nls_map) { + pr_err("JFS: charset not found\n"); + goto cleanup; + } } break; case Opt_resize: @@ -713,6 +717,8 @@ static int jfs_show_options(struct seq_file *seq, struct dentry *root) seq_printf(seq, ",discard=%u", sbi->minblks_trim); if (sbi->nls_tab) seq_printf(seq, ",iocharset=%s", sbi->nls_tab->charset); + else + seq_puts(seq, ",iocharset=utf8"); if (sbi->flag & JFS_ERR_CONTINUE) seq_printf(seq, ",errors=continue"); if (sbi->flag & JFS_ERR_PANIC) From patchwork Mon Dec 26 14:21:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36636 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp936008wrt; Mon, 26 Dec 2022 06:25:29 -0800 (PST) X-Google-Smtp-Source: AMrXdXsd/OQN0Pd9jiyDPPLcu0DT+t+cguIUBopq1byeoYnD+chhixs8WamdQB38VDdz2R1N1Fe9 X-Received: by 2002:a17:90b:2688:b0:225:f8ce:5cd8 with SMTP id pl8-20020a17090b268800b00225f8ce5cd8mr2720921pjb.4.1672064729563; Mon, 26 Dec 2022 06:25:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064729; cv=none; d=google.com; s=arc-20160816; b=EEdeAj/MvvwjIV8MkRPagFCKupwUGnEjfzrJunVpJdXOx9i2CV3mEJr+/0pe4oGqsY 1iYCPsBX4auiPIbHubozvlYdaAduT/+fnTqG+gxnns3dpytAEWjQsKKL/zVNdVd3xHpk CJmPuNsRuAx1Y2w4zbkJRl4YycbiBQEtxC1WLgoxffFTLdGV914dxXiduQvkgD+qt74r DaW4/w75Wuw+phx4eAr2+uqeN/BjeXG7QtiK/v90M6Zhp2jDJEdiB5/Sd9F/7FY9355P pv6j9jRN8UnoCJ32UG6fVGj/YZX/JLOZ/Qk25n9hkKkKHri8ghJiYUD/l2kNwQFnyVXQ 9dTA== 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:to:from :dkim-signature; bh=ovAPluK+FZaOPjm1vYrV40xUC7fin6Ot2B+M4QpC7jc=; b=mePStP8g6XRuaJrriab6AzZ9eCBkwYqRaMXZWhbBY9ZgL8ji7rH7MMIybHgJtLBUM4 Cr1NhKvPeZbGEpH4nW+QuwhzBb+Gk3MFtPYZlGb0oArA0hoiB1AzXbhr4B+eM1RKu7kJ 5IlkZdbxmJDl88SwYdw/cVWMekpQ4trjCE/vnkb7f9my02f+o8u+h6MS2r2d0mAJ4TUB LROq5SWRhVOyvi3SgGXb6ED3cUh8KQDT4kI4FFX08f5AHt++9APJe2GGvgM9gdt7bhZA +zU34g2aouWhRhLEpIlA5GEo6WjkPkzQJOiatdvsZSoqOtNG3pCuCApFC0xfxnZubXaC I45w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=A7as4con; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nu9-20020a17090b1b0900b00210d1aeabc1si15907316pjb.188.2022.12.26.06.25.17; Mon, 26 Dec 2022 06:25: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=@kernel.org header.s=k20201202 header.b=A7as4con; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232112AbiLZOX0 (ORCPT + 99 others); Mon, 26 Dec 2022 09:23:26 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232102AbiLZOWn (ORCPT ); Mon, 26 Dec 2022 09:22:43 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 993C363F4; Mon, 26 Dec 2022 06:22:20 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 0675BB80D40; Mon, 26 Dec 2022 14:22:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 51663C433D2; Mon, 26 Dec 2022 14:22:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064537; bh=RK9DOOb9HQTHiFbnB9yl27BsQqt4tsB/kdDZtxluKjg=; h=From:To:Subject:Date:In-Reply-To:References:From; b=A7as4conG80j3KTRyKa+pZqH2p0+HLcM2KRFTFrHeRHtwwEh0B3ScNLvlE5gT4QUH 8/C3yU+iAcX7YjDaj9Ax2VnfevhCUw7yKVg6agLFv2tIavN2uYUuiXgrJEuPBEDSaN 0WJLfE9fKshKT4R7zs+sVGwxdBh39MdfdfmgRTQPE8j9peTJWxIj7H+DY078+Mht6y 5zY25iRlomgxKTKRQZgDx3E/Q2ZW1lsTglJE2ZZbrsdHh8AQB/NJcD34MLXljLhbD4 wsCXF73UKZTVw369GLBx1RysIjZo+kgOTOoU3rnaYYkBimlp+HQRtuDtTqfgu1Nuke PozOaVpfexFtg== Received: by pali.im (Postfix) id 0C7F39D7; Mon, 26 Dec 2022 15:22:17 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 15/18] ntfs: Do not use broken utf8 NLS table for iocharset=utf8 mount option Date: Mon, 26 Dec 2022 15:21:47 +0100 Message-Id: <20221226142150.13324-16-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286945588662621?= X-GMAIL-MSGID: =?utf-8?q?1753286945588662621?= NLS table for utf8 is broken and cannot be fixed. So instead of broken utf8 nls functions char2uni() and uni2char() use functions utf8s_to_utf16s() and utf16s_to_utf8s() which implements correct conversion between UTF-16 and UTF-8. These functions implements also correct processing of UTF-16 surrogate pairs and therefore after this change ntfs driver would be able to correctly handle also file names with 4-byte UTF-8 sequences. When iochatset=utf8 is used then set vol->nls_map to NULL and use it for distinguish between the fact if NLS table or native UTF-8 functions should be used. Signed-off-by: Pali Rohár --- fs/ntfs/dir.c | 6 ++++-- fs/ntfs/inode.c | 5 ++++- fs/ntfs/super.c | 41 ++++++++++++++++++++++++----------------- fs/ntfs/unistr.c | 28 +++++++++++++++++++++++++--- 4 files changed, 57 insertions(+), 23 deletions(-) diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c index cd96083a12c8..035582b92aa2 100644 --- a/fs/ntfs/dir.c +++ b/fs/ntfs/dir.c @@ -1034,7 +1034,8 @@ static inline int ntfs_filldir(ntfs_volume *vol, } name_len = ntfs_ucstonls(vol, (ntfschar*)&ie->key.file_name.file_name, ie->key.file_name.file_name_length, &name, - NTFS_MAX_NAME_LEN * NLS_MAX_CHARSET_SIZE + 1); + NTFS_MAX_NAME_LEN * + (vol->nls_map ? NLS_MAX_CHARSET_SIZE : 4) + 1); if (name_len <= 0) { ntfs_warning(vol->sb, "Skipping unrepresentable inode 0x%llx.", (long long)MREF_LE(ie->data.dir.indexed_file)); @@ -1118,7 +1119,8 @@ static int ntfs_readdir(struct file *file, struct dir_context *actor) * Allocate a buffer to store the current name being processed * converted to format determined by current NLS. */ - name = kmalloc(NTFS_MAX_NAME_LEN * NLS_MAX_CHARSET_SIZE + 1, GFP_NOFS); + name = kmalloc(NTFS_MAX_NAME_LEN * + (vol->nls_map ? NLS_MAX_CHARSET_SIZE : 4) + 1, GFP_NOFS); if (unlikely(!name)) { err = -ENOMEM; goto err_out; diff --git a/fs/ntfs/inode.c b/fs/ntfs/inode.c index 2ab071c4560d..795b5495a897 100644 --- a/fs/ntfs/inode.c +++ b/fs/ntfs/inode.c @@ -2314,7 +2314,10 @@ int ntfs_show_options(struct seq_file *sf, struct dentry *root) seq_printf(sf, ",fmask=0%o", vol->fmask); seq_printf(sf, ",dmask=0%o", vol->dmask); } - seq_printf(sf, ",iocharset=%s", vol->nls_map->charset); + if (vol->nls_map) + seq_printf(sf, ",iocharset=%s", vol->nls_map->charset); + else + seq_puts(sf, ",iocharset=utf8"); if (NVolCaseSensitive(vol)) seq_printf(sf, ",case_sensitive"); if (NVolShowSystemFiles(vol)) diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c index b4f26035e750..b15cd92a9dad 100644 --- a/fs/ntfs/super.c +++ b/fs/ntfs/super.c @@ -84,7 +84,7 @@ static int simple_getbool(char *s, bool *setval) * * Parse the recognized options in @opt for the ntfs volume described by @vol. */ -static bool parse_options(ntfs_volume *vol, char *opt) +static bool parse_options(ntfs_volume *vol, char *opt, int remount) { char *p, *v, *ov; static char *utf8 = "utf8"; @@ -95,6 +95,7 @@ static bool parse_options(ntfs_volume *vol, char *opt) int mft_zone_multiplier = -1, on_errors = -1; int show_sys_files = -1, case_sensitive = -1, disable_sparse = -1; struct nls_table *nls_map = NULL; + int have_iocharset = 0; /* I am lazy... (-8 */ #define NTFS_GETOPT_WITH_DEFAULT(option, variable, default_value) \ @@ -196,12 +197,16 @@ static bool parse_options(ntfs_volume *vol, char *opt) goto needs_arg; use_utf8: unload_nls(nls_map); - nls_map = load_nls(v); - if (!nls_map) { - ntfs_error(vol->sb, "NLS character set " - "%s not found.", v); - return false; + nls_map = NULL; + if (strcmp(v, "utf8") != 0) { + nls_map = load_nls(v); + if (!nls_map) { + ntfs_error(vol->sb, "NLS character set " + "%s not found.", v); + return false; + } } + have_iocharset = 1; } else if (!strcmp(p, "utf8")) { bool val = false; ntfs_warning(vol->sb, "Option utf8 is no longer " @@ -241,25 +246,27 @@ static bool parse_options(ntfs_volume *vol, char *opt) return false; } } - if (nls_map) { - if (vol->nls_map && vol->nls_map != nls_map) { + if (have_iocharset) { + if (remount && vol->nls_map != nls_map) { ntfs_error(vol->sb, "Cannot change NLS character set " "on remount."); return false; - } /* else (!vol->nls_map) */ - ntfs_debug("Using NLS character set %s.", nls_map->charset); - vol->nls_map = nls_map; - } else /* (!nls_map) */ { - if (!vol->nls_map) { + } else if (!remount) { + ntfs_debug("Using NLS character set %s.", + nls_map ? nls_map->charset : "utf8"); + vol->nls_map = nls_map; + } + } else if (!remount) { + if (strcmp(CONFIG_NLS_DEFAULT, "utf8") != 0) { vol->nls_map = load_nls_default(); if (!vol->nls_map) { ntfs_error(vol->sb, "Failed to load default " "NLS character set."); return false; } - ntfs_debug("Using default NLS character set (%s).", - vol->nls_map->charset); } + ntfs_debug("Using default NLS character set (%s).", + vol->nls_map ? vol->nls_map->charset : "utf8"); } if (mft_zone_multiplier != -1) { if (vol->mft_zone_multiplier && vol->mft_zone_multiplier != @@ -534,7 +541,7 @@ static int ntfs_remount(struct super_block *sb, int *flags, char *opt) // TODO: Deal with *flags. - if (!parse_options(vol, opt)) + if (!parse_options(vol, opt, 1)) return -EINVAL; ntfs_debug("Done."); @@ -2732,7 +2739,7 @@ static int ntfs_fill_super(struct super_block *sb, void *opt, const int silent) NVolSetSparseEnabled(vol); /* Important to get the mount options dealt with now. */ - if (!parse_options(vol, (char*)opt)) + if (!parse_options(vol, (char*)opt, 0)) goto err_out_now; /* We support sector sizes up to the PAGE_SIZE. */ diff --git a/fs/ntfs/unistr.c b/fs/ntfs/unistr.c index 75a7f73bccdd..c52141265f99 100644 --- a/fs/ntfs/unistr.c +++ b/fs/ntfs/unistr.c @@ -254,6 +254,17 @@ int ntfs_nlstoucs(const ntfs_volume *vol, const char *ins, if (likely(ins)) { ucs = kmem_cache_alloc(ntfs_name_cache, GFP_NOFS); if (likely(ucs)) { + if (!nls) { + wc_len = utf8s_to_utf16s(ins, ins_len, + UTF16_LITTLE_ENDIAN, + (wchar_t *)ucs, + NTFS_MAX_NAME_LEN); + if (wc_len < 0 || wc_len >= NTFS_MAX_NAME_LEN) + goto name_err; + ucs[wc_len] = 0; + *outs = ucs; + return o; + } for (i = o = 0; i < ins_len; i += wc_len) { wc_len = nls->char2uni(ins + i, ins_len - i, &wc); @@ -283,7 +294,7 @@ int ntfs_nlstoucs(const ntfs_volume *vol, const char *ins, if (wc_len < 0) { ntfs_error(vol->sb, "Name using character set %s contains " "characters that cannot be converted to " - "Unicode.", nls->charset); + "Unicode.", nls ? nls->charset : "utf8"); i = -EILSEQ; } else /* if (o >= NTFS_MAX_NAME_LEN) */ { ntfs_error(vol->sb, "Name is too long (maximum length for a " @@ -335,11 +346,22 @@ int ntfs_ucstonls(const ntfs_volume *vol, const ntfschar *ins, goto conversion_err; } if (!ns) { - ns_len = ins_len * NLS_MAX_CHARSET_SIZE; + ns_len = ins_len * (nls ? NLS_MAX_CHARSET_SIZE : 4); ns = kmalloc(ns_len + 1, GFP_NOFS); if (!ns) goto mem_err_out; } + if (!nls) { + o = utf16s_to_utf8s((const wchar_t *)ins, ins_len, + UTF16_LITTLE_ENDIAN, ns, ns_len); + if (o >= ns_len) { + wc = -ENAMETOOLONG; + goto conversion_err; + } + ns[o] = 0; + *outs = ns; + return o; + } for (i = o = 0; i < ins_len; i++) { retry: wc = nls->uni2char(le16_to_cpu(ins[i]), ns + o, ns_len - o); @@ -373,7 +395,7 @@ retry: wc = nls->uni2char(le16_to_cpu(ins[i]), ns + o, ntfs_error(vol->sb, "Unicode name contains characters that cannot be " "converted to character set %s. You might want to " "try to use the mount option iocharset=utf8.", - nls->charset); + nls ? nls->charset : "utf8"); if (ns != *outs) kfree(ns); if (wc != -ENAMETOOLONG) From patchwork Mon Dec 26 14:21:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36639 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp936687wrt; Mon, 26 Dec 2022 06:26:58 -0800 (PST) X-Google-Smtp-Source: AMrXdXvfWPDE59qfQG8KOLiiQXk8J5OAq1KCYCwF3e/veAuJzMUAXdqa5683TrXpY+xHj5oPxGXu X-Received: by 2002:a05:6402:1298:b0:461:75f1:9254 with SMTP id w24-20020a056402129800b0046175f19254mr16359592edv.2.1672064818320; Mon, 26 Dec 2022 06:26:58 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064818; cv=none; d=google.com; s=arc-20160816; b=mrFjoHhQJrl8gaJHVOXDeHizUw5/sA8YJkBJBy7z2Qr+hNQsc/+CD64dQ6qBxycwiL LU0vDZY9+l94YRo7ZGSjUcr9p/e3IlPITe0HeanzCcCQdn4cx/q7CwQRjdeG5urDGPLn xMkiuZdOqOF9sJ0oTxzDeR8GRAZJrWITNUHziI+xLVUi4dfm5/ptduNI+lBBDr57diSl 9zYgaDzRexeVJXTZD7cXxYImwG6xlGWxm/qvdcHJbOHXoDHQ/WHc+lMzQDRL/bEVjtsP GdyJWWo9wzPt828gUIgH64Tm76rh3LrKqMYEbeuDvGiAGaSpXtXlC23/YCc6CLvzihN5 0+Qg== 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:to:from :dkim-signature; bh=nGAEkuN8Pz1SWXAdKNK9d9pZZPNH7hdrCFRMfPpyujg=; b=ItIguJSmRuyq+qdrqP/c7xSN5w1O7RO55XM6IGu7Hna1NyysZUFaGoT3SJ5Y2N+nOA peDipjvoj9dSCjJgFmbmDjG2w8TxlLExHBxhc2m3uV1iGxT+WwRahEFzA0ZBenmlsv5N yx2xFqvW9mG7/G7A+KwlxTj07uCJicN3Y5YU3Vn0muLRuWdn24cYYl9SaXZ9zr0M0DFP zhfecAr8NUNRwj6YIRL+eHQWkHQR5WJxSUZtXZvz0LCw57HJjZct8jg3Dpg+qmKA8h8r eEX9hx0ljmyjzOJo4SuStivKxYYhNXG71acHR5W6/tIF3FHYvj5gCdNAm2k4oQ8CNi7F d+HA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=TywsxGyp; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dz10-20020a0564021d4a00b0047b79b99e52si9858364edb.567.2022.12.26.06.26.33; Mon, 26 Dec 2022 06:26:58 -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=@kernel.org header.s=k20201202 header.b=TywsxGyp; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232157AbiLZOXo (ORCPT + 99 others); Mon, 26 Dec 2022 09:23:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232039AbiLZOWo (ORCPT ); Mon, 26 Dec 2022 09:22:44 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5E1D263A8; Mon, 26 Dec 2022 06:22:21 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id E10B8B80C02; Mon, 26 Dec 2022 14:22:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5ED7AC433F0; Mon, 26 Dec 2022 14:22:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064538; bh=fCynkXJ2ApONoQQC/ojXHkaREg+LG2l1GbUTcOSrgdM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TywsxGype9uslbISt9pHvZte/7BFs4KYX5tGNNHq6Gup5Au/egJh7ajRWW3I5ZY6Q dNfGRf9udc6MGdngo3llDZgMSBEXVBbCV8dA/hlX3gRFavc1BrO/Kp3IKliFEjPAFL 1KvJTFn/9E+la6xGnkOkAu2oJJB2kvshIF/swsc6BufW1QvXw9vpZD+mXHVM69klHw 4aLnUwBp/aHUw2sDfrITGtGlVVvQHLgvPAKuIx1lt20P7xTRAGAiKpkdtqYn8LJUef oVMbChNvkmBGKIonMuxEPSwToZQRH0hnn7xKYy4NeWiawDHyYfsC0+oQuZG2dkxgLk XdDQgRcxyvCtw== Received: by pali.im (Postfix) id 1AAC69D7; Mon, 26 Dec 2022 15:22:18 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 16/18] cifs: Do not use broken utf8 NLS table for iocharset=utf8 mount option Date: Mon, 26 Dec 2022 15:21:48 +0100 Message-Id: <20221226142150.13324-17-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753287039009727608?= X-GMAIL-MSGID: =?utf-8?q?1753287039009727608?= NLS table for utf8 is broken and cannot be fixed. So instead of broken utf8 nls functions char2uni() and uni2char() use functions utf8s_to_utf16s() and utf16s_to_utf8s() which implements correct conversion between UTF-16 and UTF-8. When iochatset=utf8 is used then set ctx->iocharset to NULL and use it for distinguish between the fact if NLS table or native UTF-8 functions should be used. Signed-off-by: Pali Rohár --- fs/cifs/cifs_unicode.c | 128 +++++++++++++++++++++++++++-------------- fs/cifs/cifs_unicode.h | 2 +- fs/cifs/cifsfs.c | 2 + fs/cifs/connect.c | 8 ++- fs/cifs/dir.c | 28 +++++++-- fs/cifs/winucase.c | 14 +++-- 6 files changed, 124 insertions(+), 58 deletions(-) diff --git a/fs/cifs/cifs_unicode.c b/fs/cifs/cifs_unicode.c index e7582dd79179..94b861e666e3 100644 --- a/fs/cifs/cifs_unicode.c +++ b/fs/cifs/cifs_unicode.c @@ -130,20 +130,17 @@ cifs_mapchar(char *target, const __u16 *from, const struct nls_table *cp, convert_sfu_char(src_char, target)) return len; - /* if character not one of seven in special remap set */ - len = cp->uni2char(src_char, target, NLS_MAX_CHARSET_SIZE); - if (len <= 0) - goto surrogate_pair; - - return len; + if (cp) { + /* if character not one of seven in special remap set */ + len = cp->uni2char(src_char, target, NLS_MAX_CHARSET_SIZE); + if (len <= 0) + goto unknown; + } else { + len = utf16s_to_utf8s(from, 3, UTF16_LITTLE_ENDIAN, target, 6); + if (len <= 0) + goto unknown; + } -surrogate_pair: - /* convert SURROGATE_PAIR and IVS */ - if (strcmp(cp->charset, "utf8")) - goto unknown; - len = utf16s_to_utf8s(from, 3, UTF16_LITTLE_ENDIAN, target, 6); - if (len <= 0) - goto unknown; return len; unknown: @@ -239,6 +236,37 @@ cifs_from_utf16(char *to, const __le16 *from, int tolen, int fromlen, return outlen; } +static int cifs_utf8s_to_utf16s(const char *s, int inlen, __le16 *pwcs) +{ + __le16 *op; + int size; + unicode_t u; + + op = pwcs; + while (inlen > 0 && *s) { + if (*s & 0x80) { + size = utf8_to_utf32(s, inlen, &u); + if (size <= 0) { + u = 0x003f; /* A question mark */ + size = 1; + } + s += size; + inlen -= size; + if (u >= 0x10000) { + u -= 0x10000; + *op++ = __cpu_to_le16(0xd800 | ((u >> 10) & 0x03ff)); + *op++ = __cpu_to_le16(0xdc00 | (u & 0x03ff)); + } else { + *op++ = __cpu_to_le16(u); + } + } else { + *op++ = __cpu_to_le16(*s++); + inlen--; + } + } + return op - pwcs; +} + /* * NAME: cifs_strtoUTF16() * @@ -254,24 +282,14 @@ cifs_strtoUTF16(__le16 *to, const char *from, int len, wchar_t wchar_to; /* needed to quiet sparse */ /* special case for utf8 to handle no plane0 chars */ - if (!strcmp(codepage->charset, "utf8")) { + if (!codepage) { /* * convert utf8 -> utf16, we assume we have enough space * as caller should have assumed conversion does not overflow - * in destination len is length in wchar_t units (16bits) - */ - i = utf8s_to_utf16s(from, len, UTF16_LITTLE_ENDIAN, - (wchar_t *) to, len); - - /* if success terminate and exit */ - if (i >= 0) - goto success; - /* - * if fails fall back to UCS encoding as this - * function should not return negative values - * currently can fail only if source contains - * invalid encoded characters + * in destination len is length in __le16 units */ + i = cifs_utf8s_to_utf16s(from, len, to); + goto success; } for (i = 0; len && *from; i++, from += charlen, len -= charlen) { @@ -502,25 +520,29 @@ cifsConvertToUTF16(__le16 *target, const char *source, int srclen, * as they use backslash as separator. */ if (dst_char == 0) { - charlen = cp->char2uni(source + i, srclen - i, &tmp); - dst_char = cpu_to_le16(tmp); - - /* - * if no match, use question mark, which at least in - * some cases serves as wild card - */ - if (charlen > 0) - goto ctoUTF16; - - /* convert SURROGATE_PAIR */ - if (strcmp(cp->charset, "utf8") || !wchar_to) - goto unknown; - if (*(source + i) & 0x80) { - charlen = utf8_to_utf32(source + i, 6, &u); - if (charlen < 0) + if (cp) { + charlen = cp->char2uni(source + i, srclen - i, &tmp); + dst_char = cpu_to_le16(tmp); + + /* + * if no match, use question mark, which at least in + * some cases serves as wild card + */ + if (charlen > 0) + goto ctoUTF16; + else goto unknown; - } else + } + + /* UTF-8 to UTF-16 conversion */ + + if (!wchar_to) goto unknown; + + charlen = utf8_to_utf32(source + i, 6, &u); + if (charlen < 0) + goto unknown; + ret = utf8s_to_utf16s(source + i, charlen, UTF16_LITTLE_ENDIAN, wchar_to, 6); @@ -589,8 +611,26 @@ cifs_local_to_utf16_bytes(const char *from, int len, { int charlen; int i; + int outlen; + unicode_t u_to; wchar_t wchar_to; + if (!codepage) { + outlen = 0; + for (i = 0; len && *from; i++, from += charlen, len -= charlen) { + charlen = utf8_to_utf32(from, len, &u_to); + /* Failed conversion defaults to a question mark */ + if (charlen < 1) { + charlen = 1; + outlen += 2; + } else if (u_to <= 0xFFFF) + outlen += 2; + else + outlen += 4; + } + return outlen; + } + for (i = 0; len && *from; i++, from += charlen, len -= charlen) { charlen = codepage->char2uni(from, len, &wchar_to); /* Failed conversion defaults to a question mark */ diff --git a/fs/cifs/cifs_unicode.h b/fs/cifs/cifs_unicode.h index 80b3d845419f..b9a3290faaf7 100644 --- a/fs/cifs/cifs_unicode.h +++ b/fs/cifs/cifs_unicode.h @@ -106,7 +106,7 @@ extern __le16 *cifs_strndup_to_utf16(const char *src, const int maxlen, int remap); #endif -wchar_t cifs_toupper(wchar_t in); +unicode_t cifs_toupper(unicode_t in); /* * UniStrcat: Concatenate the second string to the first diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c index 10e00c624922..1537bc8bb698 100644 --- a/fs/cifs/cifsfs.c +++ b/fs/cifs/cifsfs.c @@ -591,6 +591,8 @@ cifs_show_options(struct seq_file *s, struct dentry *root) cifs_sb->ctx->dir_mode); if (cifs_sb->ctx->iocharset) seq_printf(s, ",iocharset=%s", cifs_sb->ctx->iocharset); + else + seq_puts(s, ",iocharset=utf8"); if (tcon->seal) seq_puts(s, ",seal"); else if (tcon->ses->server->ignore_signature) diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c index d371259d6808..fb841a7baef6 100644 --- a/fs/cifs/connect.c +++ b/fs/cifs/connect.c @@ -2676,7 +2676,11 @@ compare_mount_options(struct super_block *sb, struct cifs_mnt_data *mnt_data) old->ctx->dir_mode != new->ctx->dir_mode) return 0; - if (strcmp(old->local_nls->charset, new->local_nls->charset)) + if (old->local_nls && !new->local_nls) + return 0; + if (!old->local_nls && new->local_nls) + return 0; + if (old->local_nls && new->local_nls && strcmp(old->local_nls->charset, new->local_nls->charset)) return 0; if (old->ctx->acregmax != new->ctx->acregmax) @@ -3162,7 +3166,7 @@ int cifs_setup_cifs_sb(struct cifs_sb_info *cifs_sb) if (ctx->iocharset == NULL) { /* load_nls_default cannot return null */ cifs_sb->local_nls = load_nls_default(); - } else { + } else if (strcmp(ctx->iocharset, "utf8") != 0) { cifs_sb->local_nls = load_nls(ctx->iocharset); if (cifs_sb->local_nls == NULL) { cifs_dbg(VFS, "CIFS mount error: iocharset %s not found\n", diff --git a/fs/cifs/dir.c b/fs/cifs/dir.c index ad4208bf1e32..83deba65e188 100644 --- a/fs/cifs/dir.c +++ b/fs/cifs/dir.c @@ -804,16 +804,22 @@ static int cifs_ci_hash(const struct dentry *dentry, struct qstr *q) { struct nls_table *codepage = CIFS_SB(dentry->d_sb)->local_nls; unsigned long hash; + unicode_t u; wchar_t c; int i, charlen; hash = init_name_hash(dentry); for (i = 0; i < q->len; i += charlen) { - charlen = codepage->char2uni(&q->name[i], q->len - i, &c); + if (codepage) { + charlen = codepage->char2uni(&q->name[i], q->len - i, &c); + if (likely(charlen > 0)) + u = c; + } else + charlen = utf8_to_utf32(&q->name[i], q->len - i, &u); /* error out if we can't convert the character */ if (unlikely(charlen < 0)) return charlen; - hash = partial_name_hash(cifs_toupper(c), hash); + hash = partial_name_hash(cifs_toupper(u), hash); } q->hash = end_name_hash(hash); @@ -824,6 +830,7 @@ static int cifs_ci_compare(const struct dentry *dentry, unsigned int len, const char *str, const struct qstr *name) { struct nls_table *codepage = CIFS_SB(dentry->d_sb)->local_nls; + unicode_t u1, u2; wchar_t c1, c2; int i, l1, l2; @@ -837,9 +844,18 @@ static int cifs_ci_compare(const struct dentry *dentry, return 1; for (i = 0; i < len; i += l1) { - /* Convert characters in both strings to UTF-16. */ - l1 = codepage->char2uni(&str[i], len - i, &c1); - l2 = codepage->char2uni(&name->name[i], name->len - i, &c2); + /* Convert characters in both strings to UTF-32. */ + if (codepage) { + l1 = codepage->char2uni(&str[i], len - i, &c1); + l2 = codepage->char2uni(&name->name[i], name->len - i, &c2); + if (likely(l1 > 0)) + u1 = c1; + if (likely(l2 > 0)) + u2 = c2; + } else { + l1 = utf8_to_utf32(&str[i], len - i, &u1); + l2 = utf8_to_utf32(&name->name[i], name->len - i, &u2); + } /* * If we can't convert either character, just declare it to @@ -860,7 +876,7 @@ static int cifs_ci_compare(const struct dentry *dentry, return 1; /* Now compare uppercase versions of these characters */ - if (cifs_toupper(c1) != cifs_toupper(c2)) + if (cifs_toupper(u1) != cifs_toupper(u2)) return 1; } diff --git a/fs/cifs/winucase.c b/fs/cifs/winucase.c index 2f075b5b50df..b3647b35a7e1 100644 --- a/fs/cifs/winucase.c +++ b/fs/cifs/winucase.c @@ -17,7 +17,7 @@ #include -wchar_t cifs_toupper(wchar_t in); /* quiet sparse */ +unicode_t cifs_toupper(unicode_t in); /* quiet sparse */ static const wchar_t t2_00[256] = { 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, @@ -615,20 +615,24 @@ static const wchar_t *const toplevel[256] = { }; /** - * cifs_toupper - convert a wchar_t from lower to uppercase + * cifs_toupper - convert a unicode_t from lower to uppercase * @in: character to convert from lower to uppercase * - * This function consults the static tables above to convert a wchar_t from + * This function consults the static tables above to convert a unicode_t from * lower to uppercase. In the event that there is no mapping, the original * "in" character is returned. */ -wchar_t -cifs_toupper(wchar_t in) +unicode_t +cifs_toupper(unicode_t in) { unsigned char idx; const wchar_t *tbl; wchar_t out; + /* cifs_toupper table has only defines for plane-0 */ + if (in > 0xffff) + return in; + /* grab upper byte */ idx = (in & 0xff00) >> 8; From patchwork Mon Dec 26 14:21:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36638 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp936362wrt; Mon, 26 Dec 2022 06:26:13 -0800 (PST) X-Google-Smtp-Source: AMrXdXscrWm3enaLedJ1BAra+l65lcUbum0rADyotD+PdotgQPQFnUfCSbZZC7+88yW260G/1Rto X-Received: by 2002:a17:90a:b10b:b0:225:cc25:802f with SMTP id z11-20020a17090ab10b00b00225cc25802fmr10692238pjq.28.1672064773678; Mon, 26 Dec 2022 06:26:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064773; cv=none; d=google.com; s=arc-20160816; b=ynjZM96WMgijT8s2mVntY9BmsJ00YrsSt3fU/7yydsx/yhw8l3m+PVztLPm7M2g3rd TTAWrXUhXs11OLVb5cPFOTV7PAs7D3Mx43INfjrzylOg+C/Re54+XBrAFR8ggdmPY/cP 3xqxgAe3L8p7mNK0izw2oVF1Qxn4XaiLjO9zIu7tpTa+1AKKbVGGO0RDwKtqMN7qvUWB +M7aHHl0tc0F9biudaOyJKUq735Yh75RHaRwyU5WBkn68kmSddn/c72Qns7hcqwTV1/Y TdbsZBS9uzdAAgpwm7aAam9nyAZwX5mZ2POSG6meMaxZyi3RCMnRw34lAiOev4f6EmoK RKLQ== 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:to:from :dkim-signature; bh=STz6tu8sQBqbB/qMacyBAxgYCovYcl+zbYl5FoNDI9c=; b=OBFBQS9g0uC+IMaYj6cg5gUo9qQrfVqR+jciRQyEHmyYjC7h2cG9ma+iCsUWM+M4c/ E8H6Ap8re61y8bM4ymoRpwLg0QBGiAXFYmknpQvJKViIg+2DyEM83WfEQrO/t6HZ760r vN9EIU0UrUGAqf3VSwzI3sv2mKkUtHR19Y/PNTZAPYwdOZSuKqXkcHHXI2ikprpGK1Gu 4Rx1pd93qToB8p/EJQmgH49q1CdCMtGrKH6ebGNGLlVf8/2Ugw6P9PKG1Q9gTg6snZOQ 251nG19ARanVlEpBQzQzry0KL6RPl8suawr3WnWhYoeTFR2IowR0MAGEkzfCI/7mi4up ziEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=qrZ66dr2; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nu9-20020a17090b1b0900b00210d1aeabc1si15907316pjb.188.2022.12.26.06.26.02; Mon, 26 Dec 2022 06:26:13 -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=@kernel.org header.s=k20201202 header.b=qrZ66dr2; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232135AbiLZOXb (ORCPT + 99 others); Mon, 26 Dec 2022 09:23:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232103AbiLZOWn (ORCPT ); Mon, 26 Dec 2022 09:22:43 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C72236404; Mon, 26 Dec 2022 06:22:20 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 4E37A60EC4; Mon, 26 Dec 2022 14:22:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6962AC433F1; Mon, 26 Dec 2022 14:22:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064539; bh=C9hpYs5SfjcSEusd2O4PwIN/sol9PZlsNg0ce4muq9s=; h=From:To:Subject:Date:In-Reply-To:References:From; b=qrZ66dr2mYGyXJ9dpyMUaNCLPxhIlaRWjTHgoAyF1lEmGiF1AJYUsM6NaZqbcFx2w 7iJMyDNL/grtQhmS59x3ND4/dpiaBtDMPKoUeARpwTTtB+ETaTFN6aUqWUaRIkquw7 zwzqy4o+GgFBqFSjIvRCajWdCSfZ/+GpzuXo87Wg7Du+iwhe13CvkF0e6y48ueZ+sX R+b8cGcvZ1ZCJ6xt0gJb3iQmQLGKMtdgSdeI5Lfmnd4qAICxRaRCEfPDiR7l4tM6ld jYyBH2ygLjy5X7Xv7yQ5/HV9Q3trWHLryksVqYLDC9OOk3D15QtkxcsZ0UwoqstCk8 5JpDY7kEq+b1w== Received: by pali.im (Postfix) id 251389D7; Mon, 26 Dec 2022 15:22:19 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 17/18] cifs: Remove usage of load_nls_default() calls Date: Mon, 26 Dec 2022 15:21:49 +0100 Message-Id: <20221226142150.13324-18-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286992270106129?= X-GMAIL-MSGID: =?utf-8?q?1753286992270106129?= cifs functions will use UTF-8 encoding when nls_table is set to NULL. So there is no need to load "dummy" NLS table for some operations. On few places in dfs_cache replace utf8 nls by utf8_to_utf32() function which converts UTF-8 sequence to unicode code points (stored as type unicode_t). This should fix handling of (UTF-16) CIFS paths with UTF-16 surrogare pairs, which utf8 nls module cannot handle. Signed-off-by: Pali Rohár --- fs/cifs/cifssmb.c | 8 ++------ fs/cifs/dfs_cache.c | 24 ++++++++---------------- fs/cifs/smb2pdu.c | 18 ++++-------------- 3 files changed, 14 insertions(+), 36 deletions(-) diff --git a/fs/cifs/cifssmb.c b/fs/cifs/cifssmb.c index 23f10e0d6e7e..3db882fdc21d 100644 --- a/fs/cifs/cifssmb.c +++ b/fs/cifs/cifssmb.c @@ -69,7 +69,6 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) int rc; struct cifs_ses *ses; struct TCP_Server_Info *server; - struct nls_table *nls_codepage; int retries; /* @@ -147,8 +146,6 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) } spin_unlock(&ses->chan_lock); - nls_codepage = load_nls_default(); - /* * Recheck after acquire mutex. If another thread is negotiating * and the server never sends an answer the socket will be closed @@ -182,7 +179,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) mutex_lock(&ses->session_mutex); rc = cifs_negotiate_protocol(0, ses, server); if (!rc) - rc = cifs_setup_session(0, ses, server, nls_codepage); + rc = cifs_setup_session(0, ses, server, NULL); /* do we need to reconnect tcon? */ if (rc || !tcon->need_reconnect) { @@ -192,7 +189,7 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) skip_sess_setup: cifs_mark_open_files_invalid(tcon); - rc = cifs_tree_connect(0, tcon, nls_codepage); + rc = cifs_tree_connect(0, tcon, NULL); mutex_unlock(&ses->session_mutex); cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc); @@ -228,7 +225,6 @@ cifs_reconnect_tcon(struct cifs_tcon *tcon, int smb_command) rc = -EAGAIN; } - unload_nls(nls_codepage); return rc; } diff --git a/fs/cifs/dfs_cache.c b/fs/cifs/dfs_cache.c index 43ad1176dcb9..4794f2cf721a 100644 --- a/fs/cifs/dfs_cache.c +++ b/fs/cifs/dfs_cache.c @@ -66,8 +66,6 @@ static struct workqueue_struct *dfscache_wq __read_mostly; static int cache_ttl; static DEFINE_SPINLOCK(cache_ttl_lock); -static struct nls_table *cache_cp; - /* * Number of entries in the cache */ @@ -173,14 +171,14 @@ char *dfs_cache_canonical_path(const char *path, const struct nls_table *cp, int if (!path || strlen(path) < 3 || (*path != '\\' && *path != '/')) return ERR_PTR(-EINVAL); - if (unlikely(strcmp(cp->charset, cache_cp->charset))) { + if (unlikely(cp)) { tmp = (char *)cifs_strndup_to_utf16(path, strlen(path), &plen, cp, remap); if (!tmp) { cifs_dbg(VFS, "%s: failed to convert path to utf16\n", __func__); return ERR_PTR(-EINVAL); } - npath = cifs_strndup_from_utf16(tmp, plen, true, cache_cp); + npath = cifs_strndup_from_utf16(tmp, plen, true, NULL); kfree(tmp); if (!npath) { @@ -392,9 +390,6 @@ int dfs_cache_init(void) INIT_HLIST_HEAD(&cache_htable[i]); atomic_set(&cache_count, 0); - cache_cp = load_nls("utf8"); - if (!cache_cp) - cache_cp = load_nls_default(); cifs_dbg(FYI, "%s: initialized DFS referral cache\n", __func__); return 0; @@ -408,11 +403,11 @@ static int cache_entry_hash(const void *data, int size, unsigned int *hash) { int i, clen; const unsigned char *s = data; - wchar_t c; + unicode_t c; unsigned int h = 0; for (i = 0; i < size; i += clen) { - clen = cache_cp->char2uni(&s[i], size - i, &c); + clen = utf8_to_utf32(&s[i], size - i, &c); if (unlikely(clen < 0)) { cifs_dbg(VFS, "%s: can't convert char\n", __func__); return clen; @@ -601,14 +596,14 @@ static int add_cache_entry_locked(struct dfs_info3_param *refs, int numrefs) static bool dfs_path_equal(const char *s1, int len1, const char *s2, int len2) { int i, l1, l2; - wchar_t c1, c2; + unicode_t c1, c2; if (len1 != len2) return false; for (i = 0; i < len1; i += l1) { - l1 = cache_cp->char2uni(&s1[i], len1 - i, &c1); - l2 = cache_cp->char2uni(&s2[i], len2 - i, &c2); + l1 = utf8_to_utf32(&s1[i], len1 - i, &c1); + l2 = utf8_to_utf32(&s2[i], len2 - i, &c2); if (unlikely(l1 < 0 && l2 < 0)) { if (s1[i] != s2[i]) return false; @@ -698,7 +693,6 @@ static struct cache_entry *lookup_cache_entry(const char *path) void dfs_cache_destroy(void) { cancel_delayed_work_sync(&refresh_task); - unload_nls(cache_cp); free_mount_group_list(); flush_cache_ents(); kmem_cache_destroy(cache_slab); @@ -744,11 +738,9 @@ static int get_dfs_referral(const unsigned int xid, struct cifs_ses *ses, const if (!ses || !ses->server || !ses->server->ops->get_dfs_refer) return -EOPNOTSUPP; - if (unlikely(!cache_cp)) - return -EINVAL; cifs_dbg(FYI, "%s: ipc=%s referral=%s\n", __func__, ses->tcon_ipc->tree_name, path); - rc = ses->server->ops->get_dfs_refer(xid, ses, path, refs, numrefs, cache_cp, + rc = ses->server->ops->get_dfs_refer(xid, ses, path, refs, numrefs, NULL, NO_MAP_UNI_RSVD); if (!rc) { struct dfs_info3_param *ref = *refs; diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c index a5695748a89b..3dc69787ae17 100644 --- a/fs/cifs/smb2pdu.c +++ b/fs/cifs/smb2pdu.c @@ -144,7 +144,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, struct TCP_Server_Info *server) { int rc = 0; - struct nls_table *nls_codepage; struct cifs_ses *ses; int retries; @@ -250,8 +249,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, tcon->ses->chans_need_reconnect, tcon->need_reconnect); - nls_codepage = load_nls_default(); - /* * Recheck after acquire mutex. If another thread is negotiating * and the server never sends an answer the socket will be closed @@ -284,7 +281,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, mutex_lock(&ses->session_mutex); rc = cifs_negotiate_protocol(0, ses, server); if (!rc) { - rc = cifs_setup_session(0, ses, server, nls_codepage); + rc = cifs_setup_session(0, ses, server, NULL); if ((rc == -EACCES) && !tcon->retry) { mutex_unlock(&ses->session_mutex); rc = -EHOSTDOWN; @@ -309,7 +306,7 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, if (tcon->use_persistent) tcon->need_reopen_files = true; - rc = cifs_tree_connect(0, tcon, nls_codepage); + rc = cifs_tree_connect(0, tcon, NULL); mutex_unlock(&ses->session_mutex); cifs_dbg(FYI, "reconnect tcon rc = %d\n", rc); @@ -345,7 +342,6 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon, rc = -EAGAIN; } failed: - unload_nls(nls_codepage); return rc; } @@ -503,12 +499,10 @@ build_encrypt_ctxt(struct smb2_encryption_neg_context *pneg_ctxt) static unsigned int build_netname_ctxt(struct smb2_netname_neg_context *pneg_ctxt, char *hostname) { - struct nls_table *cp = load_nls_default(); - pneg_ctxt->ContextType = SMB2_NETNAME_NEGOTIATE_CONTEXT_ID; /* copy up to max of first 100 bytes of server name to NetName field */ - pneg_ctxt->DataLength = cpu_to_le16(2 * cifs_strtoUTF16(pneg_ctxt->NetName, hostname, 100, cp)); + pneg_ctxt->DataLength = cpu_to_le16(2 * cifs_strtoUTF16(pneg_ctxt->NetName, hostname, 100, NULL)); /* context size is DataLength + minimal smb2_neg_context */ return ALIGN(le16_to_cpu(pneg_ctxt->DataLength) + sizeof(struct smb2_neg_context), 8); } @@ -2568,7 +2562,6 @@ alloc_path_with_tree_prefix(__le16 **out_path, int *out_size, int *out_len, const char *treename, const __le16 *path) { int treename_len, path_len; - struct nls_table *cp; const __le16 sep[] = {cpu_to_le16('\\'), cpu_to_le16(0x0000)}; /* @@ -2595,8 +2588,7 @@ alloc_path_with_tree_prefix(__le16 **out_path, int *out_size, int *out_len, if (!*out_path) return -ENOMEM; - cp = load_nls_default(); - cifs_strtoUTF16(*out_path, treename, treename_len, cp); + cifs_strtoUTF16(*out_path, treename, treename_len, NULL); /* Do not append the separator if the path is empty */ if (path[0] != cpu_to_le16(0x0000)) { @@ -2604,8 +2596,6 @@ alloc_path_with_tree_prefix(__le16 **out_path, int *out_size, int *out_len, UniStrcat(*out_path, path); } - unload_nls(cp); - return 0; } From patchwork Mon Dec 26 14:21:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Pali_Roh=C3=A1r?= X-Patchwork-Id: 36637 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4e01:0:0:0:0:0 with SMTP id p1csp936093wrt; Mon, 26 Dec 2022 06:25:39 -0800 (PST) X-Google-Smtp-Source: AMrXdXuU1IRiQBN6ibdNvH6Nm1/Tq6MNGZ5tKmTenfzC2uTcdJJMQyDzKrUoP89hVEYh4OM5q/tR X-Received: by 2002:a62:1d0e:0:b0:57f:ef11:acf8 with SMTP id d14-20020a621d0e000000b0057fef11acf8mr20540251pfd.2.1672064739498; Mon, 26 Dec 2022 06:25:39 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1672064739; cv=none; d=google.com; s=arc-20160816; b=c7ZZlaJYxOHakJnaEAsZvcy2fJN33TN+Uc+Nao2zgq4cKg7tlkDqf73xuFSyh9PHI8 C6Y7mzbtpsRpmOOLbrv1VWfafR4SyVe776ry0Zxsc4uCvGC8KdGpACHB0X0KhmnCJwkB vHyPrZnmc+//Iy66tqDsS7ZcxQ3CiQHLg7vPnzJjtix1nI89OLGcnaD9UUbRkD2L0/Em ZzQZ15d8P4kEJ4g7LD+5hATZ3Jzqh2cEJgfIiRAjRlde17ZaQT7j9HBDV21johmrHV3i dUrjshU/zRB/EdjJec/wkWQ+vhBoEIqlAje+6aZmJrf7q0+CMrwUyRcnWzzTlSCxD+TP i/2A== 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:to:from :dkim-signature; bh=pT1w13WRj/5/yfjG/wb5E2nqI1RS/1mqmtLQDjEc2vU=; b=js5hedmpOZE0Zg47sYhn0IJKNdqBwTxn17pwY4Z2lOiDJ1qvZGXZla026CmoWGTs9a h5pOdwWNuf4XHCOEkp5tZRTw7tSeFnbD559RiGQ1Y0doLyGxhE6bRq5cLMMij8IPeEaA /9DuYAZ3H9xJY0R1v3rFB68Xj4zWMSWwC7566sv7/9vhJt4VHAGGcEAiU4fotIKG6kNC CHuFYTDHHqrrCenk+RlZT9zh+WW+Bfj7JLLtyy4OOjuutKX2JiXwpOdK70IDmnfRXErJ ZB1VZgXo4tb+n/WzFg8r7yVRi+MsO2JE6UkZlDcHcFiPsitG7TH8Gs1HUbf5t+4jBRBz 1caA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=tYsbgvlg; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f8-20020a056a001ac800b0056618176fd4si11897364pfv.148.2022.12.26.06.25.27; Mon, 26 Dec 2022 06:25:39 -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=@kernel.org header.s=k20201202 header.b=tYsbgvlg; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232148AbiLZOXh (ORCPT + 99 others); Mon, 26 Dec 2022 09:23:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40116 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232040AbiLZOWo (ORCPT ); Mon, 26 Dec 2022 09:22:44 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6E136302; Mon, 26 Dec 2022 06:22:21 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 5EF6360EB3; Mon, 26 Dec 2022 14:22:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72CF0C433F1; Mon, 26 Dec 2022 14:22:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1672064540; bh=5u2bH7VJtM/e+LvuxtpQp+PsRT4F9kDqvViUS/4AlLc=; h=From:To:Subject:Date:In-Reply-To:References:From; b=tYsbgvlgOJaF8H1SdFzVwT/R2HizKskvG/7ePvtZ1Zah8Nowv0dae2/QH1uUXQEqN tX4oe095AgKLScJipg2QqH6fNYTdZPSsTR0sYqL/rSidlPk6T0S7zfLoTVNYWh65nG zuZYflHj8oifrjrkkGFs9qvR7uvaXg0ZiRsEK+oaBK/3425Ow6YEgPrqkj3OvCty7+ J0F/0Nw1OTfl5g4GFaxoQXERgnMDONqMT3jkeLy4zuNVil9TnTAV0R6SM7irCbfJ81 kvQ/bXiol65QJi1ZruhYHP+0nhxUyS8O1Zdk72l1CUaWTszATm4fxQLZIxpCKc/1Vw rJiMOl47B5OIw== Received: by pali.im (Postfix) id 2D6729D7; Mon, 26 Dec 2022 15:22:20 +0100 (CET) From: =?utf-8?q?Pali_Roh=C3=A1r?= To: linux-fsdevel@vger.kernel.org, linux-ntfs-dev@lists.sourceforge.net, linux-cifs@vger.kernel.org, jfs-discussion@lists.sourceforge.net, linux-kernel@vger.kernel.org, Alexander Viro , Jan Kara , "Theodore Y . Ts'o" , Anton Altaparmakov , OGAWA Hirofumi , Luis de Bethencourt , Salah Triki , Steve French , Paulo Alcantara , Ronnie Sahlberg , Shyam Prasad N , Tom Talpey , Dave Kleikamp , Andrew Morton , Pavel Machek , Christoph Hellwig , Kari Argillander , Viacheslav Dubeyko Subject: [RFC PATCH v2 18/18] nls: Drop broken nls_utf8 module Date: Mon, 26 Dec 2022 15:21:50 +0100 Message-Id: <20221226142150.13324-19-pali@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20221226142150.13324-1-pali@kernel.org> References: <20221226142150.13324-1-pali@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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?1753286956573619638?= X-GMAIL-MSGID: =?utf-8?q?1753286956573619638?= NLS table for utf8 is broken and cannot be fixed. Now that all filesystems are using utf8s_to_utf16s()/utf16s_to_utf8s() functions for converting between UTF-8 and UTF-16, and functions utf8_to_utf32()/utf32_to_utf8() for converting between UTF-8 and Unicode code points, there is no need to have this broken utf8 NLS module in kernel tree anymore. There is no user of this utf8 NLS module, so completely drop it, Signed-off-by: Pali Rohár --- fs/nls/Kconfig | 9 ------- fs/nls/Makefile | 1 - fs/nls/nls_utf8.c | 67 ----------------------------------------------- 3 files changed, 77 deletions(-) delete mode 100644 fs/nls/nls_utf8.c diff --git a/fs/nls/Kconfig b/fs/nls/Kconfig index c7857e36adbb..8f82cf30a493 100644 --- a/fs/nls/Kconfig +++ b/fs/nls/Kconfig @@ -608,13 +608,4 @@ config NLS_MAC_TURKISH If unsure, say Y. -config NLS_UTF8 - tristate "NLS UTF-8" - help - If you want to display filenames with native language characters - from the Microsoft FAT file system family or from JOLIET CD-ROMs - correctly on the screen, you need to include the appropriate - input/output character sets. Say Y here for the UTF-8 encoding of - the Unicode/ISO9646 universal character set. - endif # NLS diff --git a/fs/nls/Makefile b/fs/nls/Makefile index ac54db297128..e573db7fc173 100644 --- a/fs/nls/Makefile +++ b/fs/nls/Makefile @@ -42,7 +42,6 @@ obj-$(CONFIG_NLS_ISO8859_14) += nls_iso8859-14.o obj-$(CONFIG_NLS_ISO8859_15) += nls_iso8859-15.o obj-$(CONFIG_NLS_KOI8_R) += nls_koi8-r.o obj-$(CONFIG_NLS_KOI8_U) += nls_koi8-u.o nls_koi8-ru.o -obj-$(CONFIG_NLS_UTF8) += nls_utf8.o obj-$(CONFIG_NLS_MAC_CELTIC) += mac-celtic.o obj-$(CONFIG_NLS_MAC_CENTEURO) += mac-centeuro.o obj-$(CONFIG_NLS_MAC_CROATIAN) += mac-croatian.o diff --git a/fs/nls/nls_utf8.c b/fs/nls/nls_utf8.c deleted file mode 100644 index afcfbc4a14db..000000000000 --- a/fs/nls/nls_utf8.c +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Module for handling utf8 just like any other charset. - * By Urban Widmark 2000 - */ - -#include -#include -#include -#include -#include - -static unsigned char identity[256]; - -static int uni2char(wchar_t uni, unsigned char *out, int boundlen) -{ - int n; - - if (boundlen <= 0) - return -ENAMETOOLONG; - - n = utf32_to_utf8(uni, out, boundlen); - if (n < 0) { - *out = '?'; - return -EINVAL; - } - return n; -} - -static int char2uni(const unsigned char *rawstring, int boundlen, wchar_t *uni) -{ - int n; - unicode_t u; - - n = utf8_to_utf32(rawstring, boundlen, &u); - if (n < 0 || u > MAX_WCHAR_T) { - *uni = 0x003f; /* ? */ - return -EINVAL; - } - *uni = (wchar_t) u; - return n; -} - -static struct nls_table table = { - .charset = "utf8", - .uni2char = uni2char, - .char2uni = char2uni, - .charset2lower = identity, /* no conversion */ - .charset2upper = identity, -}; - -static int __init init_nls_utf8(void) -{ - int i; - for (i=0; i<256; i++) - identity[i] = i; - - return register_nls(&table); -} - -static void __exit exit_nls_utf8(void) -{ - unregister_nls(&table); -} - -module_init(init_nls_utf8) -module_exit(exit_nls_utf8) -MODULE_LICENSE("Dual BSD/GPL");