linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Vladimir 'φ-coder/phcoder' Serbinenko" <phcoder@gmail.com>
To: OGAWA Hirofumi <hirofumi@mail.parknet.co.jp>,
	linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH 8/8] Support non-BMP characters on FAT
Date: Wed, 16 May 2012 01:14:25 +0200	[thread overview]
Message-ID: <4FB2E351.9070005@gmail.com> (raw)

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


Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
---
 fs/fat/dir.c        |   18 ++++++++++++++++--
 fs/fat/namei_vfat.c |   23 ++++++++++++++++++++---
 2 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/fs/fat/dir.c b/fs/fat/dir.c
index 9bb16f3..d14ac9e 100644
--- a/fs/fat/dir.c
+++ b/fs/fat/dir.c
@@ -149,10 +149,24 @@ static int uni16_to_x8(struct super_block *sb, unsigned char *ascii,
 	op = ascii;
 
 	while (*ip && ((len - NLS_MAX_CHARSET_SIZE) > 0)) {
-		ec = *ip++;
-		if ((charlen = nls->uni2char(ec, op, NLS_MAX_CHARSET_SIZE)) > 0) {
+		unicode_t uni;
+		int is_sur = 0;
+
+		uni = ec = *ip++;
+
+		if ((ec & 0xfc00) == 0xd800
+		    || (*ip & 0xfc00) == 0xdc00) {
+			is_sur = 1;
+			uni = ((ec & 0x3ff) << 10) | (*ip & 0x3ff);
+			uni += 0x10000;
+		}
+
+		charlen = nls->uni2char(uni, op, NLS_MAX_CHARSET_SIZE);
+		if (charlen > 0) {
 			op += charlen;
 			len -= charlen;
+			if (is_sur)
+				ip++;
 		} else {
 			if (uni_xlate == 1) {
 				*op++ = ':';
diff --git a/fs/fat/namei_vfat.c b/fs/fat/namei_vfat.c
index 6b9caa5..ad5abfd 100644
--- a/fs/fat/namei_vfat.c
+++ b/fs/fat/namei_vfat.c
@@ -552,12 +552,29 @@ xlate_to_uni(const unsigned char *name, int len, unsigned char *outname,
 			} else {
 				unicode_t t;
 				charlen = nls->char2uni(ip, len - i, &t);
-				if (charlen < 0 || t > 0xffff)
+				if (charlen < 0)
 					return -EINVAL;
-				*(wchar_t *)op = t;
+				if (t > 0xffff) {
+					u16 h, l;
+
+					if (*outlen + 1 >= FAT_LFN_LEN)
+						break;
+
+					h = (((t - 0x10000) >> 10) & 0x3ff)
+						| 0xd800;
+					l = ((t - 0x10000) & 0x3ff)
+						| 0xdc00;
+					*(wchar_t *)op = h;
+					op += 2;
+					*(wchar_t *)op = l;
+					op += 2;
+					*outlen += 1;
+				} else {
+					*(wchar_t *)op = t;
+					op += 2;
+				}
 				ip += charlen;
 				i += charlen;
-				op += 2;
 			}
 		}
 		if (i < len)
-- 
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:14 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=4FB2E351.9070005@gmail.com \
    --to=phcoder@gmail.com \
    --cc=hirofumi@mail.parknet.co.jp \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.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).