Hi,

the attached patch replaces the potentially non-D-characters in the 8.3
format file name with underscores (to be consistent with what HelenOS
FAT server does). While this conversion appears to work, the patch
reveals that the long file names with non-ASCII characters as created by
the mkfat.py script don't seem right. For example, leaving a file name
such as 'žížala' somewhere under uspace/dist creates a rather bogus
entry in the initrd.img.

I also made some changes to the FAT server to allow viewing the short
file names when the file system is mounted with the 'nolfn' mount option.

lp:~jakub/helenos/fs

The problem with non-ASCII file names is best viewed when the file
system is mounted with default = no mount options. And of course, having
bogus unicode long file names results in having incorrect short names
(misplaced underscores) too.

Can someone better versed in Python take a look at this?

Thanks,
Jakub

=== modified file 'tools/mkfat.py'
--- tools/mkfat.py	2012-03-29 07:56:17 +0000
+++ tools/mkfat.py	2012-04-09 17:15:24 +0000
@@ -182,10 +182,22 @@
 # keep track of "number" when creating a short fname from a LFN.
 name83_list = []
 
+def is_ascii(char):
+	return ord(char) >= 0 and ord(char) <= 255
+
+def is_d_char(char):
+	return char.isalnum() or char == '_'
+
+def encode_sfn_part(part):
+	encoded = part
+	for i in range(len(encoded)) :
+		if not (is_ascii(encoded[i]) and is_d_char(encoded[i])):
+			encoded = encoded[:i] + '_' + encoded[i + 1:]
+	return encoded.upper()
+
 def name83(fname):
 	"Create a 8.3 name for the given fname"
 
-	# FIXME: filter illegal characters
 	parts = fname.split('.')
 	
 	name = ''
@@ -209,7 +221,7 @@
 		lfn = True
 
 	if (lfn == False) :
-		return (name.ljust(8)[0:8], ext.ljust(3)[0:3], False)
+		return (encode_sfn_part(name).ljust(8)[0:8], encode_sfn_part(ext).ljust(3)[0:3], False)
 
 	# For filenames with multiple extensions, we treat the last one
 	# as the actual extension. The rest of the filename is stripped
@@ -217,6 +229,9 @@
 	for _name in parts[1:-1]:
 		name = name + _name		
 
+	name = encode_sfn_part(name)
+	ext = encode_sfn_part(ext)
+
 	global name83_list
 	for number in range(1, 10000) :
 		number_str = '~' + str(number)
@@ -266,9 +281,6 @@
 	
 	dir_entry.name, dir_entry.ext, lfn = name83(name)
 
-	dir_entry.name = dir_entry.name.upper().encode('ascii')
-	dir_entry.ext = dir_entry.ext.upper().encode('ascii')
-
 	if (directory):
 		dir_entry.attr = 0x30
 	else:

_______________________________________________
HelenOS-devel mailing list
[email protected]
http://lists.modry.cz/cgi-bin/listinfo/helenos-devel

Reply via email to