Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp263210ybi; Tue, 16 Jul 2019 20:15:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwIhhwmR4zLFd8ilDF4mf9mbYSd5cpZ/8sPHOsN5X32gtS3AQSAHCXe2gyKAPl0NGlnpMzY X-Received: by 2002:a63:c342:: with SMTP id e2mr37575336pgd.79.1563333320237; Tue, 16 Jul 2019 20:15:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563333320; cv=none; d=google.com; s=arc-20160816; b=n6HHPxjytaNdWiWWDub9z61FHeM7V3M364yoT/xx8zCdP/V2oV5KHeQ2KJ6iIDN0Oa vd7SCvWmmoSjS6G0vvf+vNus8Evhghc6SnbikTV0KWWjSQCjomQPP9xXYYUhsKWGGWRl XZToEqOSIMy6OnPez3uxe4TKhSFq9KvpNclLQcJnmZyVcuq4f25a7Z1u8Xy/5vnclqLf gGd6SVa7sIuNCVnit1p6mVb15VVHVJwyJPVnZGaPNHNN366d1/HnPcg+wsaE6hSybMyo /CW5XbgIL6kKs81PAIybmv+pFCrLqRasFpxF7UzlWq3yKbBZe3/1HT+SOyIKXzGouNAo 1L+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:from:subject:references :mime-version:message-id:in-reply-to:date:dkim-signature; bh=sfxj1LqI62EQGhoHu67r5S8ba42Kgfd5TKOjUX/FZ0M=; b=M0yS7NwzJ8LcQetoPot90Ysg20nrs40ViPCgaVjnHSHwG9BVfOH3uO2NzfwTOtvk4n 5QUHcT3mJ+y3fahma42VfdukGK/K4F2tcD4nu4+5SmMk33ERbb4XdCzEOwD4iYjwYVKf 367CtRFPFkkOLzO9gOnnMeBPrq1IkeeWeZ1pl+IL6mLmMypWqE6GyORg3DJwKgUScCjx 1XmDINuRV4cw8IZT6OH6m6xF8sORRLSp9DnMq6GPjUKfn3t+25CfwncjLVJwZcU7AsXB vodzPjAICJ2TRPZRQbeXcb1FF0h+/7a4cm6wOo4RkKousrE2vxDfgL4/rVrchxHLTKq+ BY6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jtVEHyQs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e96si20965070plb.123.2019.07.16.20.15.04; Tue, 16 Jul 2019 20:15:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=jtVEHyQs; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728711AbfGQDOm (ORCPT + 99 others); Tue, 16 Jul 2019 23:14:42 -0400 Received: from mail-vs1-f74.google.com ([209.85.217.74]:45232 "EHLO mail-vs1-f74.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728081AbfGQDOk (ORCPT ); Tue, 16 Jul 2019 23:14:40 -0400 Received: by mail-vs1-f74.google.com with SMTP id v20so5107720vsi.12 for ; Tue, 16 Jul 2019 20:14:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=sfxj1LqI62EQGhoHu67r5S8ba42Kgfd5TKOjUX/FZ0M=; b=jtVEHyQsk0IYcqIWAMHWH+7G9XgP+7K9OB9v6Nn1JakiKEOocsmt5xD6WcB7QnClqe OPVN1SoqAm94Acp/XEX9gsiKE/b72unEo8EKH8mLmo2KWkpusfDkexGWODEphBNOLZwO Gb1hwkz4hmGZq9XCS2aeTrL+dwSEcyuIswQfMfBMG+/fB/5RuFvnP5i5J60XwLzSF17s BC0xTb5dva+4ubjuWeZ5kV7U63YNIDM9OVs4j0XOw/4+LTbSaRaaziK9h9wqEKUAJJz0 bRASSWwy15iJTt+OrLJgDi0FojX/tgYnwRSghgIzM9fMLwnXJDb4zw/pOnTOuR036wDe qB5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=sfxj1LqI62EQGhoHu67r5S8ba42Kgfd5TKOjUX/FZ0M=; b=Tjj6dqgeT/GVei3HPgH2q3/uXE9H/g0ZlmUCiwSDAJYBSil7MD0MEFbff6f7eD1e3+ HVk8ZsptdKeOACsSjde+vWpthqjHSmbx/valDqGpKTyvZSh2GcGpvAARAZQDwQVK+qMk 3uVrMF1NzXFSq0Ga8JZowM+PGkvh1UOomZ82Hu41gOa2Ntw9Yiy3t1VWD63C8lmTyguW 96rWOcQaHnCQy37dQ9Z0Nhz1Tgc3RiX0u7SMMm6inQMJwTM2Jv+32fxp1tz+MrG2UwTs 4mb8FF3NxrCvPKYMRDgqzUkAUxGMj7OmtCwJvZmDiKhjW72Zk1VoISdgFqB5r+dLkfJo YQNA== X-Gm-Message-State: APjAAAU60pQj6h07rc4fZdS2IEpwbpY1eRDaYQ3pCpd6ra29egtHwDuc Eh9gFyHkzKMjAJF+6ykcD71HZqrutsQ= X-Received: by 2002:a1f:3244:: with SMTP id y65mr13886749vky.77.1563333279643; Tue, 16 Jul 2019 20:14:39 -0700 (PDT) Date: Tue, 16 Jul 2019 20:14:07 -0700 In-Reply-To: <20190717031408.114104-1-drosen@google.com> Message-Id: <20190717031408.114104-2-drosen@google.com> Mime-Version: 1.0 References: <20190717031408.114104-1-drosen@google.com> X-Mailer: git-send-email 2.22.0.510.g264f2c817a-goog Subject: [PATCH v2 1/2] f2fs: include charset encoding information in the superblock From: Daniel Rosenberg To: Jaegeuk Kim , Chao Yu , Jonathan Corbet , linux-f2fs-devel@lists.sourceforge.net Cc: linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-fsdevel@vger.kernel.org, kernel-team@android.com, Daniel Rosenberg Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add charset encoding to f2fs to support casefolding. It is modeled after the same feature introduced in commit c83ad55eaa91 ("ext4: include charset encoding information in the superblock") Currently this is not compatible with encryption, similar to the current ext4 imlpementation. This will change in the future. From the ext4 patch: """ The s_encoding field stores a magic number indicating the encoding format and version used globally by file and directory names in the filesystem. The s_encoding_flags defines policies for using the charset encoding, like how to handle invalid sequences. The magic number is mapped to the exact charset table, but the mapping is specific to ext4. Since we don't have any commitment to support old encodings, the only encoding I am supporting right now is utf8-12.1.0. The current implementation prevents the user from enabling encoding and per-directory encryption on the same filesystem at the same time. The incompatibility between these features lies in how we do efficient directory searches when we cannot be sure the encryption of the user provided fname will match the actual hash stored in the disk without decrypting every directory entry, because of normalization cases. My quickest solution is to simply block the concurrent use of these features for now, and enable it later, once we have a better solution. """ Signed-off-by: Daniel Rosenberg --- fs/f2fs/f2fs.h | 6 +++ fs/f2fs/super.c | 81 +++++++++++++++++++++++++++++++++++++++++ include/linux/f2fs_fs.h | 9 ++++- 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h index 17382da7f0bd9..c6c7904572d0d 100644 --- a/fs/f2fs/f2fs.h +++ b/fs/f2fs/f2fs.h @@ -153,6 +153,7 @@ struct f2fs_mount_info { #define F2FS_FEATURE_LOST_FOUND 0x0200 #define F2FS_FEATURE_VERITY 0x0400 /* reserved */ #define F2FS_FEATURE_SB_CHKSUM 0x0800 +#define F2FS_FEATURE_CASEFOLD 0x1000 #define __F2FS_HAS_FEATURE(raw_super, mask) \ ((raw_super->feature & cpu_to_le32(mask)) != 0) @@ -1169,6 +1170,10 @@ struct f2fs_sb_info { int valid_super_block; /* valid super block no */ unsigned long s_flag; /* flags for sbi */ struct mutex writepages; /* mutex for writepages() */ +#ifdef CONFIG_UNICODE + struct unicode_map *s_encoding; + __u16 s_encoding_flags; +#endif #ifdef CONFIG_BLK_DEV_ZONED unsigned int blocks_per_blkz; /* F2FS blocks per zone */ @@ -3562,6 +3567,7 @@ F2FS_FEATURE_FUNCS(quota_ino, QUOTA_INO); F2FS_FEATURE_FUNCS(inode_crtime, INODE_CRTIME); F2FS_FEATURE_FUNCS(lost_found, LOST_FOUND); F2FS_FEATURE_FUNCS(sb_chksum, SB_CHKSUM); +F2FS_FEATURE_FUNCS(casefold, CASEFOLD); #ifdef CONFIG_BLK_DEV_ZONED static inline bool f2fs_blkz_is_seq(struct f2fs_sb_info *sbi, int devi, diff --git a/fs/f2fs/super.c b/fs/f2fs/super.c index 6de6cda440315..7927071ef5e95 100644 --- a/fs/f2fs/super.c +++ b/fs/f2fs/super.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "f2fs.h" #include "node.h" @@ -222,6 +223,36 @@ void f2fs_printk(struct f2fs_sb_info *sbi, const char *fmt, ...) va_end(args); } +#ifdef CONFIG_UNICODE +static const struct f2fs_sb_encodings { + __u16 magic; + char *name; + char *version; +} f2fs_sb_encoding_map[] = { + {F2FS_ENC_UTF8_12_1, "utf8", "12.1.0"}, +}; + +static int f2fs_sb_read_encoding(const struct f2fs_super_block *sb, + const struct f2fs_sb_encodings **encoding, + __u16 *flags) +{ + __u16 magic = le16_to_cpu(sb->s_encoding); + int i; + + for (i = 0; i < ARRAY_SIZE(f2fs_sb_encoding_map); i++) + if (magic == f2fs_sb_encoding_map[i].magic) + break; + + if (i >= ARRAY_SIZE(f2fs_sb_encoding_map)) + return -EINVAL; + + *encoding = &f2fs_sb_encoding_map[i]; + *flags = le16_to_cpu(sb->s_encoding_flags); + + return 0; +} +#endif + static inline void limit_reserve_root(struct f2fs_sb_info *sbi) { block_t limit = min((sbi->user_block_count << 1) / 1000, @@ -798,6 +829,13 @@ static int parse_options(struct super_block *sb, char *options) return -EINVAL; } #endif +#ifndef CONFIG_UNICODE + if (f2fs_sb_has_casefold(sbi)) { + f2fs_err(sbi, + "Filesystem with casefold feature cannot be mounted without CONFIG_UNICODE"); + return -EINVAL; + } +#endif if (F2FS_IO_SIZE_BITS(sbi) && !test_opt(sbi, LFS)) { f2fs_err(sbi, "Should set mode=lfs with %uKB-sized IO", @@ -1089,6 +1127,9 @@ static void f2fs_put_super(struct super_block *sb) destroy_percpu_info(sbi); for (i = 0; i < NR_PAGE_TYPE; i++) kvfree(sbi->write_io[i]); +#ifdef CONFIG_UNICODE + utf8_unload(sbi->s_encoding); +#endif kvfree(sbi); } @@ -3126,6 +3167,42 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) sb->s_maxbytes = sbi->max_file_blocks << le32_to_cpu(raw_super->log_blocksize); sb->s_max_links = F2FS_LINK_MAX; +#ifdef CONFIG_UNICODE + if (f2fs_sb_has_casefold(sbi) && !sbi->s_encoding) { + const struct f2fs_sb_encodings *encoding_info; + struct unicode_map *encoding; + __u16 encoding_flags; + + if (f2fs_sb_has_encrypt(sbi)) { + f2fs_err(sbi, + "Can't mount with encoding and encryption"); + goto free_options; + } + + if (f2fs_sb_read_encoding(raw_super, &encoding_info, + &encoding_flags)) { + f2fs_err(sbi, + "Encoding requested by superblock is unknown"); + goto free_options; + } + + encoding = utf8_load(encoding_info->version); + if (IS_ERR(encoding)) { + f2fs_err(sbi, + "can't mount with superblock charset: %s-%s " + "not supported by the kernel. flags: 0x%x.", + encoding_info->name, encoding_info->version, + encoding_flags); + goto free_options; + } + f2fs_info(sbi, "Using encoding defined by superblock: " + "%s-%s with flags 0x%hx", encoding_info->name, + encoding_info->version?:"\b", encoding_flags); + + sbi->s_encoding = encoding; + sbi->s_encoding_flags = encoding_flags; + } +#endif #ifdef CONFIG_QUOTA sb->dq_op = &f2fs_quota_operations; @@ -3477,6 +3554,10 @@ static int f2fs_fill_super(struct super_block *sb, void *data, int silent) free_bio_info: for (i = 0; i < NR_PAGE_TYPE; i++) kvfree(sbi->write_io[i]); + +#ifdef CONFIG_UNICODE + utf8_unload(sbi->s_encoding); +#endif free_options: #ifdef CONFIG_QUOTA for (i = 0; i < MAXQUOTAS; i++) diff --git a/include/linux/f2fs_fs.h b/include/linux/f2fs_fs.h index 65559900d4d76..b7c9c7f721339 100644 --- a/include/linux/f2fs_fs.h +++ b/include/linux/f2fs_fs.h @@ -36,6 +36,11 @@ #define F2FS_MAX_QUOTAS 3 +#define F2FS_ENC_UTF8_12_1 1 +#define F2FS_ENC_STRICT_MODE_FL (1 << 0) +#define f2fs_has_strict_mode(sbi) \ + (sbi->s_encoding_flags & F2FS_ENC_STRICT_MODE_FL) + #define F2FS_IO_SIZE(sbi) (1 << F2FS_OPTION(sbi).write_io_size_bits) /* Blocks */ #define F2FS_IO_SIZE_KB(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 2)) /* KB */ #define F2FS_IO_SIZE_BYTES(sbi) (1 << (F2FS_OPTION(sbi).write_io_size_bits + 12)) /* B */ @@ -109,7 +114,9 @@ struct f2fs_super_block { struct f2fs_device devs[MAX_DEVICES]; /* device list */ __le32 qf_ino[F2FS_MAX_QUOTAS]; /* quota inode numbers */ __u8 hot_ext_count; /* # of hot file extension */ - __u8 reserved[310]; /* valid reserved region */ + __le16 s_encoding; /* Filename charset encoding */ + __le16 s_encoding_flags; /* Filename charset encoding flags */ + __u8 reserved[306]; /* valid reserved region */ __le32 crc; /* checksum of superblock */ } __packed; -- 2.22.0.510.g264f2c817a-goog