linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: Dave Kleikamp <shaggy@kernel.org>,
	jfs-discussion@lists.sourceforge.net,
	linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org
Subject: [PATCH 3/8] Support non-BMP characters in JFS.
Date: Wed, 16 May 2012 01:03:23 +0200	[thread overview]
Message-ID: <4FB2E0BB.8080906@gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2354 bytes --]


Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
---
 fs/jfs/jfs_unicode.c |   30 ++++++++++++++++++++++++------
 1 file changed, 24 insertions(+), 6 deletions(-)

diff --git a/fs/jfs/jfs_unicode.c b/fs/jfs/jfs_unicode.c
index 2d70cf1..70f667a 100644
--- a/fs/jfs/jfs_unicode.c
+++ b/fs/jfs/jfs_unicode.c
@@ -34,14 +34,23 @@ int jfs_strfromUCS_le(char *to, const __le16 * from,
 {
 	int i;
 	int outlen = 0;
+	int step;
 	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++) {
+		for (i = 0; (i < len) && from[i]; ) {
 			int charlen;
+			unicode_t uni;
+			step = utf16s_to_unicode(from + i, len - i,
+						 UTF16_LITTLE_ENDIAN,
+						 &uni);
+			if (!step)
+				break;
+			i += step;
+
 			charlen =
-			    codepage->uni2char(le16_to_cpu(from[i]),
+			    codepage->uni2char(uni,
 					       &to[outlen],
 					       NLS_MAX_CHARSET_SIZE);
 			if (charlen > 0)
@@ -86,18 +95,26 @@ static int jfs_strtoUCS(wchar_t * to, const unsigned char *from, int len,
 	int i;
 
 	if (codepage) {
-		for (i = 0; len && *from; i++, from += charlen, len -= charlen)
+		for (i = 0; len && *from; from += charlen, len -= charlen)
 		{
 			unicode_t uni;
+			int step;
 			charlen = codepage->char2uni(from, len, &uni);
-			to[i] = uni;
-			if (charlen < 1 || uni > 0xffff) {
+			if (charlen < 1) {
 				jfs_err("jfs_strtoUCS: char2uni returned %d.",
 					charlen);
 				jfs_err("charset = %s, char = 0x%x",
 					codepage->charset, *from);
 				return charlen;
 			}
+			step = unicode_to_utf16s(uni, UTF16_HOST_ENDIAN,
+					       to + i, MAX_UTF16_PER_UNICODE);
+			if (step < 0) {
+				jfs_err("jfs_strtoUCS: unicode_to_utf16s returned %d.",
+					step);
+				return step;
+			}
+			i += step;
 		}
 	} else {
 		for (i = 0; (i < len) && from[i]; i++)
@@ -123,7 +140,8 @@ int get_UCSname(struct component_name * uniName, struct dentry *dentry)
 		return -ENAMETOOLONG;
 
 	uniName->name =
-	    kmalloc((length + 1) * sizeof(wchar_t), GFP_NOFS);
+	    kmalloc((length * MAX_UTF16_PER_UNICODE + 1) * sizeof(wchar_t),
+		    GFP_NOFS);
 
 	if (uniName->name == NULL)
 		return -ENOMEM;
-- 
1.7.10

-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 294 bytes --]

                 reply	other threads:[~2012-05-15 23:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4FB2E0BB.8080906@gmail.com \
    --to=phcoder@gmail.com \
    --cc=jfs-discussion@lists.sourceforge.net \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=shaggy@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).