Skip to contentSkip to conversation

fat: add config option to set UTF-8 mount option by default

PATCH In review Maciej S. Szmigiero 4 participants 7 messages Mar 8, 2016 – Mar 23, 2016

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 fat: add config option to set UTF-8 mount option by default

FAT has long supported its own default file name encoding config setting, separate from CONFIG_NLS_DEFAULT.

However, if UTF-8 encoded file names are desired FAT character set should not be set to utf8 since this would make file names case sensitive even if case insensitive matching is requested.
Instead, "utf8" mount options should be provided to enable UTF-8 file names in FAT file system.

Unfortunately, there was no possibility to set the default value of this option so on UTF-8 system "utf8" mount option had to be added manually to most FAT mounts.

This patch adds config option to set such default value.

---
Changes from v1: use IS_ENABLED() macro to simplify code

 Documentation/filesystems/vfat.txt |  7 ++++---
 fs/fat/Kconfig                     | 18 +++++++++++++++++-
 fs/fat/inode.c                     |  4 +++-
 3 files changed, 24 insertions(+), 5 deletions(-)
Documentation/filesystems/vfat.txt +4 -3
index 223c32171dcc..cf51360e3a9f 100644
@@ -56,9 +56,10 @@ iocharset=<name> -- Character set to use for converting between the
 		 you should consider the following option instead.
 
 utf8=<bool>   -- UTF-8 is the filesystem safe version of Unicode that
-		 is used by the console.  It can be enabled for the
-		 filesystem with this option. If 'uni_xlate' gets set,
-		 UTF-8 gets disabled.
+		 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.
 
 uni_xlate=<bool> -- Translate unhandled Unicode characters to special
 		 escaped sequences.  This would let you backup and
fs/fat/Kconfig +17 -1
index 182f9ffe2b51..3ff1772f612e 100644
@@ -93,8 +93,24 @@ config FAT_DEFAULT_IOCHARSET
 	  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.
+	  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.
 	  See <file:Documentation/filesystems/vfat.txt> 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 <file:Documentation/filesystems/vfat.txt> for more information.
fs/fat/inode.c +3 -1
index a5599052116c..226281068a46 100644
@@ -1127,7 +1127,7 @@ static int parse_options(struct super_block *sb, char *options, int is_vfat,
 	}
 	opts->name_check = 'n';
 	opts->quiet = opts->showexec = opts->sys_immutable = opts->dotsOK =  0;
-	opts->utf8 = opts->unicode_xlate = 0;
+	opts->unicode_xlate = 0;
 	opts->numtail = 1;
 	opts->usefree = opts->nocase = 0;
 	opts->tz_set = 0;
@@ -1135,6 +1135,8 @@ 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;
 
maintainer Acked-by on v2 1/1
#1 lore raw
Quoted 10 lines · Maciej S. Szmigiero

FAT has long supported its own default file name encoding config setting, separate from CONFIG_NLS_DEFAULT.

However, if UTF-8 encoded file names are desired FAT character set should not be set to utf8 since this would make file names case sensitive even if case insensitive matching is requested.
Instead, "utf8" mount options should be provided to enable UTF-8 file names in FAT file system.

Quoted 7 lines

Unfortunately, there was no possibility to set the default value of this option so on UTF-8 system "utf8" mount option had to be added manually to most FAT mounts.

This patch adds config option to set such default value.

Quoted 78 lines

---
Changes from v1: use IS_ENABLED() macro to simplify code

 Documentation/filesystems/vfat.txt |  7 ++++---
 fs/fat/Kconfig                     | 18 +++++++++++++++++-
 fs/fat/inode.c                     |  4 +++-
 3 files changed, 24 insertions(+), 5 deletions(-)
Documentation/filesystems/vfat.txt +4 -3
index 223c32171dcc..cf51360e3a9f 100644
@@ -56,9 +56,10 @@ iocharset=<name> -- Character set to use for converting between the
 		 you should consider the following option instead.
 
 utf8=<bool>   -- UTF-8 is the filesystem safe version of Unicode that
-		 is used by the console.  It can be enabled for the
-		 filesystem with this option. If 'uni_xlate' gets set,
-		 UTF-8 gets disabled.
+		 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.
 
 uni_xlate=<bool> -- Translate unhandled Unicode characters to special
 		 escaped sequences.  This would let you backup and
fs/fat/Kconfig +17 -1
index 182f9ffe2b51..3ff1772f612e 100644
@@ -93,8 +93,24 @@ config FAT_DEFAULT_IOCHARSET
 	  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.
+	  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.
 	  See <file:Documentation/filesystems/vfat.txt> 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 <file:Documentation/filesystems/vfat.txt> for more information.
fs/fat/inode.c +3 -1
index a5599052116c..226281068a46 100644
@@ -1127,7 +1127,7 @@ static int parse_options(struct super_block *sb, char *options, int is_vfat,
 	}
 	opts->name_check = 'n';
 	opts->quiet = opts->showexec = opts->sys_immutable = opts->dotsOK =  0;
-	opts->utf8 = opts->unicode_xlate = 0;
+	opts->unicode_xlate = 0;
 	opts->numtail = 1;
 	opts->usefree = opts->nocase = 0;
 	opts->tz_set = 0;
@@ -1135,6 +1135,8 @@ 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;
 
Signature · 1 line
OGAWA Hirofumi <[email protected]>
#2 lore raw
In reply to Maciej S. Szmigiero
Quoted 36 lines · Maciej S. Szmigiero

FAT has long supported its own default file name encoding config setting, separate from CONFIG_NLS_DEFAULT.

However, if UTF-8 encoded file names are desired FAT character set should not be set to utf8 since this would make file names case sensitive even if case insensitive matching is requested.
Instead, "utf8" mount options should be provided to enable UTF-8 file names in FAT file system.

Unfortunately, there was no possibility to set the default value of this option so on UTF-8 system "utf8" mount option had to be added manually to most FAT mounts.

This patch adds config option to set such default value.

fs/fat/Kconfig +7 -1
@@ -93,8 +93,24 @@ config FAT_DEFAULT_IOCHARSET
          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.
+         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.
          See <file:Documentation/filesystems/vfat.txt> 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

fs/fat/Kconfig config FAT_DEFAULT_IOCHARSET · line 116

Quoted 10 lines
fs/fat/Kconfig +10 -0
+       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 <file:Documentation/filesystems/vfat.txt> for more information.

What's the recommended value of CONFIG_FAT_DEFAULT_UTF8 for a (distro) defconfig?

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#3 lore raw
Quoted 43 lines · Geert Uytterhoeven
Quoted 41 lines · Maciej S. Szmigiero

FAT has long supported its own default file name encoding config setting, separate from CONFIG_NLS_DEFAULT.

However, if UTF-8 encoded file names are desired FAT character set should not be set to utf8 since this would make file names case sensitive even if case insensitive matching is requested.
Instead, "utf8" mount options should be provided to enable UTF-8 file names in FAT file system.

Unfortunately, there was no possibility to set the default value of this option so on UTF-8 system "utf8" mount option had to be added manually to most FAT mounts.

This patch adds config option to set such default value.

fs/fat/Kconfig +12 -1
@@ -93,8 +93,24 @@ config FAT_DEFAULT_IOCHARSET
          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.
+         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.
          See <file:Documentation/filesystems/vfat.txt> 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
Quoted 8 lines

fs/fat/Kconfig config FAT_DEFAULT_IOCHARSET · line 116

Quoted 5 lines
fs/fat/Kconfig +5 -0
+         particular mount by adding "utf8=0" to mount options.
+
+         Say Y if you use UTF-8 encoding for file names, N otherwise.
+
+         See <file:Documentation/filesystems/vfat.txt> for more information.

What's the recommended value of CONFIG_FAT_DEFAULT_UTF8 for a (distro) defconfig?

Yes, I'm curious about this as well. My initial assumption is to leave it off, given that if you turn it on when it wasn't previously it will change the behavior. I would also assume that is why it is marked as default n.

josh

#4 lore raw
Quoted 54 lines · Josh Boyer
Quoted 43 lines · Geert Uytterhoeven
Quoted 41 lines · Maciej S. Szmigiero

FAT has long supported its own default file name encoding config setting, separate from CONFIG_NLS_DEFAULT.

However, if UTF-8 encoded file names are desired FAT character set should not be set to utf8 since this would make file names case sensitive even if case insensitive matching is requested.
Instead, "utf8" mount options should be provided to enable UTF-8 file names in FAT file system.

Unfortunately, there was no possibility to set the default value of this option so on UTF-8 system "utf8" mount option had to be added manually to most FAT mounts.

This patch adds config option to set such default value.

fs/fat/Kconfig +12 -1
@@ -93,8 +93,24 @@ config FAT_DEFAULT_IOCHARSET
          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.
+         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.
          See <file:Documentation/filesystems/vfat.txt> 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
Quoted 8 lines

fs/fat/Kconfig config FAT_DEFAULT_IOCHARSET · line 116

Quoted 5 lines
fs/fat/Kconfig +5 -0
+         particular mount by adding "utf8=0" to mount options.
+
+         Say Y if you use UTF-8 encoding for file names, N otherwise.
+
+         See <file:Documentation/filesystems/vfat.txt> for more information.

What's the recommended value of CONFIG_FAT_DEFAULT_UTF8 for a (distro) defconfig?

Quoted 4 lines

Yes, I'm curious about this as well. My initial assumption is to leave it off, given that if you turn it on when it wasn't previously it will change the behavior. I would also assume that is why it is marked as default n.

"default n" is superfluous, as all options default to "n" in the absence of a default specifier.

Gr{oetje,eeting}s,

Geert

--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- [email protected]

In personal conversations with technical people, I call myself a hacker. But when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds

#5 lore raw
Quoted 55 lines · Geert Uytterhoeven
Quoted 54 lines · Josh Boyer
Quoted 51 lines · Geert Uytterhoeven
Quoted 36 lines · Maciej S. Szmigiero

FAT has long supported its own default file name encoding config setting, separate from CONFIG_NLS_DEFAULT.

However, if UTF-8 encoded file names are desired FAT character set should not be set to utf8 since this would make file names case sensitive even if case insensitive matching is requested.
Instead, "utf8" mount options should be provided to enable UTF-8 file names in FAT file system.

Unfortunately, there was no possibility to set the default value of this option so on UTF-8 system "utf8" mount option had to be added manually to most FAT mounts.

This patch adds config option to set such default value.

fs/fat/Kconfig +7 -1
@@ -93,8 +93,24 @@ config FAT_DEFAULT_IOCHARSET
          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.
+         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.
          See <file:Documentation/filesystems/vfat.txt> 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

fs/fat/Kconfig config FAT_DEFAULT_IOCHARSET · line 116

Quoted 10 lines
fs/fat/Kconfig +10 -0
+       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 <file:Documentation/filesystems/vfat.txt> for more information.

What's the recommended value of CONFIG_FAT_DEFAULT_UTF8 for a (distro) defconfig?

Quoted 7 lines
Quoted 4 lines

Yes, I'm curious about this as well. My initial assumption is to leave it off, given that if you turn it on when it wasn't previously it will change the behavior. I would also assume that is why it is marked as default n.

"default n" is superfluous, as all options default to "n" in the absence of a default specifier.

Yes, I know that. I meant that I assumed the patch author knows that too, and included it anyway as a helpful indicator that it shouldn't be turned on in most cases. At any rate, your question still stands and it would be nice to get an answer.

josh

#6 lore raw
Quoted 62 lines · Josh Boyer
Quoted 60 lines · Geert Uytterhoeven
Quoted 58 lines · Josh Boyer
Quoted 43 lines · Geert Uytterhoeven
Quoted 41 lines · Maciej S. Szmigiero

FAT has long supported its own default file name encoding config setting, separate from CONFIG_NLS_DEFAULT.

However, if UTF-8 encoded file names are desired FAT character set should not be set to utf8 since this would make file names case sensitive even if case insensitive matching is requested.
Instead, "utf8" mount options should be provided to enable UTF-8 file names in FAT file system.

Unfortunately, there was no possibility to set the default value of this option so on UTF-8 system "utf8" mount option had to be added manually to most FAT mounts.

This patch adds config option to set such default value.

fs/fat/Kconfig +12 -1
@@ -93,8 +93,24 @@ config FAT_DEFAULT_IOCHARSET
          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.
+         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.
          See <file:Documentation/filesystems/vfat.txt> 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
Quoted 8 lines

fs/fat/Kconfig config FAT_DEFAULT_IOCHARSET · line 116

Quoted 5 lines
fs/fat/Kconfig +5 -0
+         particular mount by adding "utf8=0" to mount options.
+
+         Say Y if you use UTF-8 encoding for file names, N otherwise.
+
+         See <file:Documentation/filesystems/vfat.txt> for more information.

What's the recommended value of CONFIG_FAT_DEFAULT_UTF8 for a (distro) defconfig?

Yes, I'm curious about this as well. My initial assumption is to leave it off, given that if you turn it on when it wasn't previously it will change the behavior. I would also assume that is why it is marked as default n.

Quoted 7 lines
Quoted 2 lines

"default n" is superfluous, as all options default to "n" in the absence of a default specifier.

Yes, I know that. I meant that I assumed the patch author knows that too, and included it anyway as a helpful indicator that it shouldn't be turned on in most cases. At any rate, your question still stands and it would be nice to get an answer.

The default is 'n' here for compatibility with older .configs, and to be consistent with the main FS NLS option (CONFIG_NLS_DEFAULT) since it also defaults to non-UTF-8 encoding.

If file names are UTF-8 encoded then if FAT filesystems were always mounted with utf8 mount option, or with CONFIG_FAT_DEFAULT_IOCHARSET or "iocharset" mount option set to "utf8" (not recommended,
but I've seen for example Knoppix doing it) then with this options set there is effectively no change in functionality.

If file names are UTF-8 encoded but none of conditions described in the previous paragraph were true then UTF-8 file names were reinterpreted as CONFIG_FAT_DEFAULT_IOCHARSET (by default iso8859-1) then converted into UTF-16 for storage.

While this usually worked it weren't correct: file names containing characters outside ASCII had them replaced with some garbage when accessing such FS with UTF-8 correctly enabled (for example with this option set) or on Windows.

However, if such conditions (UTF-8 file names but non-UTF-8 FAT mount options) were present for a long time then it has to be taken into consideration that there are likely at least a few file systems with file names encoded in such way and it would be good not to change it suddenly when people update their kernels.

Quoted 1 line

josh

Maciej