[PATCH] warn users of inaccessible file names (2 of 4)

[email protected] Mon, 8 Mar 2004 17:04:45 -0600
Newsgroups gmane.comp.file-systems.jfs.patches
Message-ID <[email protected]>
# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2004/03/08 13:24:03-06:00 [email protected] 
#   JFS: warn users of inaccessible file names
#   
#   When no iocharset is specified, the default action is to trivially
#   map each byte into the low order of the 16-bit unicode character.
#   If an existing name exists that has a non-zero high order byte, the
#   file will be inaccessible without remounting with iocharset set to
#   a charset that supports the character.
#   
#   This patch will cause a warning to be issued to the syslog (no more
#   than five times) suggesting that the volume be mounted with
#   iocharset=utf8 in order to access the file.
# 
diff -Nru a/fs/jfs/jfs_unicode.c b/fs/jfs/jfs_unicode.c
--- a/fs/jfs/jfs_unicode.c	Mon Mar  8 17:02:09 2004
+++ b/fs/jfs/jfs_unicode.c	Mon Mar  8 17:02:09 2004
@@ -34,6 +34,8 @@
 {
 	int i;
 	int outlen = 0;
+	static int warn_again = 5;	/* Only warn up to 5 times total */
+	int warn = !!warn_again;	/* once per string */
 
 	if (codepage) {
 		for (i = 0; (i < len) && from[i]; i++) {
@@ -48,8 +50,22 @@
 				to[outlen++] = '?';
 		}
 	} else {
-		for (i = 0; (i < len) && from[i]; i++)
-			to[i] = (char) (le16_to_cpu(from[i]));
+		for (i = 0; (i < len) && from[i]; i++) {
+			if (le16_to_cpu(from[i]) & 0xff00) {
+				if (warn) {
+					warn--;
+					warn_again--;
+					printk(KERN_ERR
+			"non-latin1 character 0x%x found in JFS file name\n", 
+		       			       le16_to_cpu(from[i]));
+					printk(KERN_ERR
+				"mount with iocharset=utf8 to access\n");
+				}
+				to[i] = '?';
+			}
+			else
+				to[i] = (char) (le16_to_cpu(from[i]));
+		}
 		outlen = i;
 	}
 	to[outlen] = 0;