From 28887533bb64db318e74c38cd9c0ad6d0bb2ced2 Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 3 May 2019 13:16:29 -0400 Subject: [PATCH] Rename the feature "fname_encoding" to be "casefold". Also change mke2fs so that the encoding and encoding flags are specified in mke2fs.conf in the fs_types and defaults stanzas instead of the options stanza. Signed-off-by: Theodore Ts'o --- e2fsck/unix.c | 2 +- lib/e2p/encoding.c | 2 ++ lib/e2p/feature.c | 4 ++- lib/e2p/ls.c | 2 +- lib/ext2fs/ext2_fs.h | 4 +-- lib/ext2fs/ext2fs.h | 2 +- lib/ext2fs/initialize.c | 2 +- lib/ext2fs/openfs.c | 2 +- misc/chattr.1.in | 2 +- misc/ext4.5.in | 2 +- misc/mke2fs.8.in | 6 ++-- misc/mke2fs.c | 64 ++++++++++++++++++++--------------------- misc/mke2fs.conf.5.in | 15 +++++++--- misc/tune2fs.c | 2 +- 14 files changed, 60 insertions(+), 51 deletions(-) diff --git a/e2fsck/unix.c b/e2fsck/unix.c index 7c24f2e31..37fca0f18 100644 --- a/e2fsck/unix.c +++ b/e2fsck/unix.c @@ -1784,7 +1784,7 @@ print_unsupp_features: goto get_newer; } - if (ext2fs_has_feature_fname_encoding(sb) && !fs->encoding) { + if (ext2fs_has_feature_casefold(sb) && !fs->encoding) { log_err(ctx, _("%s has unsupported encoding: %0x\n"), ctx->filesystem_name, sb->s_encoding); goto get_newer; diff --git a/lib/e2p/encoding.c b/lib/e2p/encoding.c index ccd9582e5..24266fcd2 100644 --- a/lib/e2p/encoding.c +++ b/lib/e2p/encoding.c @@ -90,6 +90,8 @@ int e2p_str2encoding_flags(int encoding, char *param, __u16 *flags) const struct enc_flags *fl; unsigned int i, neg = 0; + if (encoding != EXT4_ENC_UTF8_12_1) + return -EINVAL; while (f) { neg = 0; if (!strncmp("no", f, 2)) { diff --git a/lib/e2p/feature.c b/lib/e2p/feature.c index ded87f561..117acf25c 100644 --- a/lib/e2p/feature.c +++ b/lib/e2p/feature.c @@ -109,7 +109,9 @@ static struct feature feature_list[] = { "inline_data"}, { E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_ENCRYPT, "encrypt"}, - { E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_FNAME_ENCODING, + { E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_CASEFOLD, + "casefold"}, + { E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_CASEFOLD, "fname_encoding"}, { 0, 0, 0 }, }; diff --git a/lib/e2p/ls.c b/lib/e2p/ls.c index 11e7415be..5a4461781 100644 --- a/lib/e2p/ls.c +++ b/lib/e2p/ls.c @@ -470,7 +470,7 @@ void list_super2(struct ext2_super_block * sb, FILE *f) if (ext2fs_has_feature_csum_seed(sb)) fprintf(f, "Checksum seed: 0x%08x\n", sb->s_checksum_seed); - if (ext2fs_has_feature_fname_encoding(sb)) + if (ext2fs_has_feature_casefold(sb)) fprintf(f, "Character encoding: %s\n", e2p_encoding2str(sb->s_encoding)); } diff --git a/lib/ext2fs/ext2_fs.h b/lib/ext2fs/ext2_fs.h index ffcacafe8..cbb44bdb6 100644 --- a/lib/ext2fs/ext2_fs.h +++ b/lib/ext2fs/ext2_fs.h @@ -849,7 +849,7 @@ struct ext2_super_block { #define EXT4_FEATURE_INCOMPAT_LARGEDIR 0x4000 /* >2GB or 3-lvl htree */ #define EXT4_FEATURE_INCOMPAT_INLINE_DATA 0x8000 /* data in inode */ #define EXT4_FEATURE_INCOMPAT_ENCRYPT 0x10000 -#define EXT4_FEATURE_INCOMPAT_FNAME_ENCODING 0x20000 +#define EXT4_FEATURE_INCOMPAT_CASEFOLD 0x20000 #define EXT4_FEATURE_COMPAT_FUNCS(name, ver, flagname) \ static inline int ext2fs_has_feature_##name(struct ext2_super_block *sb) \ @@ -943,7 +943,7 @@ EXT4_FEATURE_INCOMPAT_FUNCS(csum_seed, 4, CSUM_SEED) EXT4_FEATURE_INCOMPAT_FUNCS(largedir, 4, LARGEDIR) EXT4_FEATURE_INCOMPAT_FUNCS(inline_data, 4, INLINE_DATA) EXT4_FEATURE_INCOMPAT_FUNCS(encrypt, 4, ENCRYPT) -EXT4_FEATURE_INCOMPAT_FUNCS(fname_encoding, 4, FNAME_ENCODING) +EXT4_FEATURE_INCOMPAT_FUNCS(casefold, 4, CASEFOLD) #define EXT2_FEATURE_COMPAT_SUPP 0 #define EXT2_FEATURE_INCOMPAT_SUPP (EXT2_FEATURE_INCOMPAT_FILETYPE| \ diff --git a/lib/ext2fs/ext2fs.h b/lib/ext2fs/ext2fs.h index 5cbee6e0d..c3be2c5c8 100644 --- a/lib/ext2fs/ext2fs.h +++ b/lib/ext2fs/ext2fs.h @@ -642,7 +642,7 @@ typedef struct ext2_icount *ext2_icount_t; EXT4_FEATURE_INCOMPAT_64BIT|\ EXT4_FEATURE_INCOMPAT_INLINE_DATA|\ EXT4_FEATURE_INCOMPAT_ENCRYPT|\ - EXT4_FEATURE_INCOMPAT_FNAME_ENCODING|\ + EXT4_FEATURE_INCOMPAT_CASEFOLD|\ EXT4_FEATURE_INCOMPAT_CSUM_SEED|\ EXT4_FEATURE_INCOMPAT_LARGEDIR) diff --git a/lib/ext2fs/initialize.c b/lib/ext2fs/initialize.c index daff4b3c1..96ec1cffd 100644 --- a/lib/ext2fs/initialize.c +++ b/lib/ext2fs/initialize.c @@ -190,7 +190,7 @@ errcode_t ext2fs_initialize(const char *name, int flags, assign_field(s_encoding); assign_field(s_encoding_flags); - if (ext2fs_has_feature_fname_encoding(param)) + if (ext2fs_has_feature_casefold(param)) fs->encoding = ext2fs_load_nls_table(param->s_encoding); if (super->s_feature_incompat & ~EXT2_LIB_FEATURE_INCOMPAT_SUPP) { diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c index 3e229b9e0..51b54a449 100644 --- a/lib/ext2fs/openfs.c +++ b/lib/ext2fs/openfs.c @@ -501,7 +501,7 @@ errcode_t ext2fs_open2(const char *name, const char *io_options, ext2fs_set_feature_shared_blocks(fs->super); } - if (ext2fs_has_feature_fname_encoding(fs->super)) + if (ext2fs_has_feature_casefold(fs->super)) fs->encoding = ext2fs_load_nls_table(fs->super->s_encoding); fs->flags &= ~EXT2_FLAG_NOFREE_ON_ERROR; diff --git a/misc/chattr.1.in b/misc/chattr.1.in index 5949d0966..1c9e89646 100644 --- a/misc/chattr.1.in +++ b/misc/chattr.1.in @@ -123,7 +123,7 @@ although it can be displayed by A directory with the 'F' attribute set indicates that all the path lookups inside that directory are made in a case-insensitive fashion. This attribute can only be changed in empty directories on file systems -with the fname_encoding feature enabled. +with the casefold feature enabled. .PP A file with the 'i' attribute cannot be modified: it cannot be deleted or renamed, no link can be created to this file, most of the file's diff --git a/misc/ext4.5.in b/misc/ext4.5.in index 2a8ce1e2f..01dab48a4 100644 --- a/misc/ext4.5.in +++ b/misc/ext4.5.in @@ -151,7 +151,7 @@ can be specified using the .B \-G option. .TP -.B fname_encoding +.B casefold .br This ext4 feature provides file system level character encoding support for directories with the casefold (+F) flag enabled. This feature is diff --git a/misc/mke2fs.8.in b/misc/mke2fs.8.in index 7162494ac..5bcee25ec 100644 --- a/misc/mke2fs.8.in +++ b/misc/mke2fs.8.in @@ -280,9 +280,9 @@ option is still accepted for backwards compatibility, but is deprecated. The following extended options are supported: .RS 1.2i .TP -.BI fname_encoding= encoding-name +.BI encoding= encoding-name Enable the -.I fname_encoding +.I casefold feature in the super block and set .I encoding-name as the encoding to be used. If @@ -291,7 +291,7 @@ is not specified, the encoding defined in .BR mke2fs.conf (5) is used. .TP -.BI fname_encoding_flags= encoding-flags +.BI encoding_flags= encoding-flags Define parameters for file name character encoding operations. If a flag is not changed using this parameter, its default value is used. .I encoding-flags diff --git a/misc/mke2fs.c b/misc/mke2fs.c index be3586cf7..91523609e 100644 --- a/misc/mke2fs.c +++ b/misc/mke2fs.c @@ -1058,15 +1058,10 @@ static void parse_extended_opts(struct ext2_super_block *param, } } else if (!strcmp(token, "android_sparse")) { android_sparse_file = 1; - } else if (!strcmp(token, "fname_encoding")) { + } else if (!strcmp(token, "encoding")) { if (!arg) { - profile_get_string(profile, "options", - "fname_encoding", 0, 0, - &arg); - if (!arg) { - r_usage++; - continue; - } + r_usage++; + continue; } encoding = e2p_str2encoding(arg); @@ -1076,8 +1071,8 @@ static void parse_extended_opts(struct ext2_super_block *param, continue; } param->s_encoding = encoding; - ext2fs_set_feature_fname_encoding(param); - } else if (!strcmp(token, "fname_encoding_flags")) { + ext2fs_set_feature_casefold(param); + } else if (!strcmp(token, "encoding_flags")) { if (!arg) { r_usage++; continue; @@ -1107,8 +1102,8 @@ static void parse_extended_opts(struct ext2_super_block *param, "\ttest_fs\n" "\tdiscard\n" "\tnodiscard\n" - "\tfname_encoding=\n" - "\tfname_encoding_flags=\n" + "\encoding=\n" + "\tencoding_flags=\n" "\tquotatype=\n\n"), badopt ? badopt : ""); free(buf); @@ -1120,7 +1115,7 @@ static void parse_extended_opts(struct ext2_super_block *param, "multiple of stride %u.\n\n"), param->s_raid_stripe_width, param->s_raid_stride); - if (ext2fs_has_feature_fname_encoding(param)) { + if (ext2fs_has_feature_casefold(param)) { param->s_encoding_flags = e2p_get_encoding_flags(param->s_encoding); @@ -1160,7 +1155,7 @@ static __u32 ok_features[3] = { EXT4_FEATURE_INCOMPAT_64BIT| EXT4_FEATURE_INCOMPAT_INLINE_DATA| EXT4_FEATURE_INCOMPAT_ENCRYPT | - EXT4_FEATURE_INCOMPAT_FNAME_ENCODING | + EXT4_FEATURE_INCOMPAT_CASEFOLD | EXT4_FEATURE_INCOMPAT_CSUM_SEED | EXT4_FEATURE_INCOMPAT_LARGEDIR, /* R/O compat */ @@ -1567,8 +1562,6 @@ static void PRS(int argc, char *argv[]) int use_bsize; char *newpath; int pathlen = sizeof(PATH_SET) + 1; - char *encoding_name = NULL; - int encoding; if (oldpath) pathlen += strlen(oldpath); @@ -2077,7 +2070,7 @@ profile_error: ext2fs_clear_feature_huge_file(&fs_param); ext2fs_clear_feature_metadata_csum(&fs_param); ext2fs_clear_feature_ea_inode(&fs_param); - ext2fs_clear_feature_fname_encoding(&fs_param); + ext2fs_clear_feature_casefold(&fs_param); } edit_feature(fs_features ? fs_features : tmp, &fs_param.s_feature_compat); @@ -2393,24 +2386,29 @@ profile_error: if (packed_meta_blocks) journal_location = 0; - if (ext2fs_has_feature_fname_encoding(&fs_param)) { - profile_get_string(profile, "options", "fname_encoding", - 0, 0, &encoding_name); - if (!encoding_name) { - com_err(program_name, 0, "%s", - _("Filename encoding type must be specified\n" - "Use -E fname_encoding= instead")); - exit(1); - } - encoding = e2p_str2encoding(encoding_name); + if (ext2fs_has_feature_casefold(&fs_param)) { + char *ef, *en = get_string_from_profile(fs_types, + "encoding", "utf8"); + int encoding = e2p_str2encoding(en); + if (encoding < 0) { - com_err(program_name, 0, "%s", - _("Unknown default filename encoding\n" - "Use -E fname_encoding= instead")); + com_err(program_name, 0, + _("Unknown filename encoding from profile: %s"), + en); exit(1); } fs_param.s_encoding = encoding; - fs_param.s_encoding_flags = e2p_get_encoding_flags(encoding); + ef = get_string_from_profile(fs_types, "encoding_flags", NULL); + if (ef) { + if (e2p_str2encoding_flags(encoding, ef, + &fs_param.s_encoding_flags) < 0) { + com_err(program_name, 0, + _("Unknown encoding flags from profile: %s"), ef); + exit(1); + } + } else + fs_param.s_encoding_flags = + e2p_get_encoding_flags(encoding); } /* Get options from profile */ @@ -2457,10 +2455,10 @@ profile_error: } } - if (ext2fs_has_feature_fname_encoding(&fs_param) && + if (ext2fs_has_feature_casefold(&fs_param) && ext2fs_has_feature_encrypt(&fs_param)) { com_err(program_name, 0, "%s", - _("The encrypt and encoding features are not " + _("The encrypt and casefold features are not " "compatible.\nThey can not be both enabled " "simultaneously.\n")); exit (1); diff --git a/misc/mke2fs.conf.5.in b/misc/mke2fs.conf.5.in index cdebf08cf..08bb94888 100644 --- a/misc/mke2fs.conf.5.in +++ b/misc/mke2fs.conf.5.in @@ -97,10 +97,6 @@ The following relations are defined in the .I [options] stanza. .TP -.I fname_encoding -This relation defines the file name encoding to be used by mke2fs, in -case the user doesn't specify an encoding in the command line. -.TP .I proceed_delay If this relation is set to a positive integer, then mke2fs will wait @@ -522,6 +518,17 @@ to false, this step will always be skipped, which can be useful if it is known that the disk has been previously erased, or if the user programs that will have access to the huge files are trusted to not reveal stale data. +.TP +.I encoding +This relation defines the file name encoding to be used if the casefold +feature is enabled. Currently the only valid encoding is utf8-12.1 or +utf8, which requests the most recent Unicode version; since 12.1 is the only +available Unicode version, utf8 and utf8-12.1 have the same result. +.I encoding_flags +This relation defines encoding-specific flags. For utf8 encodings, the +only available flag is strict, which will cause attempts to create file +names containing invalid Unicode characters to be rejected by the +kernel. Strict mode is not enabled by default. .SH THE [devices] STANZA Each tag in the .I [devices] diff --git a/misc/tune2fs.c b/misc/tune2fs.c index fbdf78a8f..7d2d38d7d 100644 --- a/misc/tune2fs.c +++ b/misc/tune2fs.c @@ -1401,7 +1401,7 @@ mmp_error: } if (FEATURE_ON(E2P_FEATURE_INCOMPAT, EXT4_FEATURE_INCOMPAT_ENCRYPT)) { - if (ext2fs_has_feature_fname_encoding(sb)) { + if (ext2fs_has_feature_casefold(sb)) { fputs(_("Cannot enable encrypt feature on filesystems " "with the encoding feature enabled.\n"), stderr); -- 2.39.2