lkml.org 
[lkml]   [1999]   [May]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subjectsmbfs: simple codepage hack (w/ patch)

Hello smb maintainer, hello list.

As far as I understand the smbfs code makes no attempt to convert the
filenames from the dos codepage format they arrive from the server to
something understandable by linux userspace programs. This for example
makes ls display the wonderful filename åäö as ???.

There are some nls/codepage stuff used by (at least) vfat. Now that I have
re-invented parts of that conversion I think I understand how I could use
them. (I played with those at first but they were not a magic wand that
made all my problems disappear :).

I'm thinking of doing the conversions cp850 -> unicode -> iso8859-1
(configurable to other pages of course) and reversed for the other
direction. This is similar to the samba settings needed for its smbclient
(and therefore I'm guessing similar to what it does).

Is this the way it's supposed to be done? Should it be enough to simply
convert to unicode? I tried that at first and it didn't work (although
there were some things I did that couldn't possibly work).

Or is this something that is already being worked on?

Only briefly tested with smbfs as a module, NT4 as smb server, client
codepage 850. Diff against Linux 2.2.7 is attached. If anyone tries this
I'd love to know.

/Urban

---
Urban Widmark urban@svenskatest.se
Svenska Test AB +46 90 71 71 23
--- linux-ide/fs/smbfs/proc.c Wed Nov 4 06:56:58 1998
+++ linux/fs/smbfs/proc.c Tue May 4 22:39:23 1999
@@ -7,6 +7,8 @@
* 28/06/96 - Fixed long file name support (smb_proc_readdir_long) by Yuri Per
* 28/09/97 - Fixed smb_d_path [now smb_build_path()] to be non-recursive
* by Riccardo Facchetti
+ * 04/05/99 - Added simple filename conversions for dos codepage 850
+ * by Urban Widmark
*/

#include <linux/types.h>
@@ -30,6 +32,14 @@
/* #define SMBFS_DEBUG_VERBOSE 1 */
/* #define pr_debug printk */

+/*
+ * Define to activate codepage hack
+ *
+ * Only works for infolevel 259 and 'smb_decode_long_dirent' ...
+ * In other words: it works for me (NT4 servers), it may work for you
+ */
+#define SMBFS_CODEPAGES 1 /* */
+
#define SMB_VWV(packet) ((packet) + SMB_HEADER_LEN)
#define SMB_CMD(packet) (*(packet+8))
#define SMB_WC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xe6, 0xc6, 0xf4, 0xf6, 0xf2, 0xfb, 0xf9,
+ 0xff, 0xd6, 0xdc, 0xf8, 0xa3, 0xd8, 0xd7, 0x9f,
+ 0xe1, 0xed, 0xf3, 0xfa, 0xf1, 0xd1, 0xaa, 0xba,
+ 0xbf, 0xae, 0xac, 0xbd, 0xbc, 0xa1, 0xab, 0xbb,
+ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xc1, 0xc2, 0xc0,
+ 0xa9, 0xb9, 0xba, 0xbb, 0xbc, 0xa2, 0xa5, 0xbf,
+
+ /* 192 */
+ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xe3, 0xc3,
+ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xa4,
+ 0xf0, 0xd0, 0xca, 0xcb, 0xc8, 0xd5, 0xcd, 0xce,
+ 0xcf, 0xd9, 0xda, 0xdb, 0xdc, 0xa6, 0xcc, 0xdf,
+ 0xd3, 0xdf, 0xd4, 0xd2, 0xf5, 0xd5, 0xb5, 0xfe,
+ 0xde, 0xda, 0xdb, 0xd9, 0xfd, 0xdd, 0xaf, 0xb4,
+ 0xad, 0xb1, 0xf2, 0xbe, 0xb6, 0xa7, 0xf7, 0xb8,
+ 0xb0, 0xa8, 0xb7, 0xb9, 0xb3, 0xb2, 0xfe, 0xa0
+};
+
+
+/*
+ * Codepage conversions.
+ *
+ * Note: upper & lower conversions won't work for these chars
+ */
+static void remap_chars(unsigned char *buf, int len, unsigned char *codepage)
+{
+ while(len-- > 0) {
+ unsigned char *s = buf++;
+ if(*s < 0x80)
+ continue;
+ *s = codepage[*s - 0x80];
+ }
+}
+#endif
+
/*****************************************************************************/
/* */
/* Encoding/Decoding section */
@@ -162,6 +236,10 @@
if (server->opt.protocol <= SMB_PROTOCOL_COREPLUS)
str_upper(start, buf - start);

+#ifdef SMBFS_CODEPAGES
+ remap_chars(start, buf - start, iso8859_1_to_cp850);
+#endif
+
return buf;
}

@@ -1472,6 +1550,11 @@
if (len && entry->name[len-1] == '\0')
len--;
entry->len = len;
+
+#ifdef SMBFS_CODEPAGES
+ remap_chars(&entry->name[0], len, cp850_to_iso8859_1);
+#endif
+
#ifdef SMBFS_DEBUG_VERBOSE
printk("smb_decode_long_dirent: info 259 at %p, len=%d, name=%s\n",
p, len, entry->name);
\
 
 \ /
  Last update: 2005-03-22 13:51    [W:0.048 / U:0.808 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site