mirror of
https://github.com/trezor/trezor-firmware.git
synced 2025-02-15 17:12:04 +00:00
core/modtrezorio: enable LFN+Unicode in FatFS
This commit is contained in:
parent
aa8d14c0ea
commit
d40b7c0385
@ -131,6 +131,7 @@ if EVERYTHING:
|
|||||||
# modtrezorio
|
# modtrezorio
|
||||||
SOURCE_MOD += [
|
SOURCE_MOD += [
|
||||||
'embed/extmod/modtrezorio/ff.c',
|
'embed/extmod/modtrezorio/ff.c',
|
||||||
|
'embed/extmod/modtrezorio/ffunicode.c',
|
||||||
'embed/extmod/modtrezorio/modtrezorio.c',
|
'embed/extmod/modtrezorio/modtrezorio.c',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -126,6 +126,7 @@ if EVERYTHING:
|
|||||||
# modtrezorio
|
# modtrezorio
|
||||||
SOURCE_MOD += [
|
SOURCE_MOD += [
|
||||||
'embed/extmod/modtrezorio/ff.c',
|
'embed/extmod/modtrezorio/ff.c',
|
||||||
|
'embed/extmod/modtrezorio/ffunicode.c',
|
||||||
'embed/extmod/modtrezorio/modtrezorio.c',
|
'embed/extmod/modtrezorio/modtrezorio.c',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
@ -107,7 +107,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
#define FF_USE_LFN 0
|
#define FF_USE_LFN 1
|
||||||
#define FF_MAX_LFN 255
|
#define FF_MAX_LFN 255
|
||||||
/* The FF_USE_LFN switches the support for LFN (long file name).
|
/* The FF_USE_LFN switches the support for LFN (long file name).
|
||||||
/
|
/
|
||||||
@ -127,7 +127,7 @@
|
|||||||
/ ff_memfree() in ffsystem.c, need to be added to the project. */
|
/ ff_memfree() in ffsystem.c, need to be added to the project. */
|
||||||
|
|
||||||
|
|
||||||
#define FF_LFN_UNICODE 0
|
#define FF_LFN_UNICODE 2
|
||||||
/* This option switches the character encoding on the API when LFN is enabled.
|
/* This option switches the character encoding on the API when LFN is enabled.
|
||||||
/
|
/
|
||||||
/ 0: ANSI/OEM in current CP (TCHAR = char)
|
/ 0: ANSI/OEM in current CP (TCHAR = char)
|
||||||
|
15599
core/embed/extmod/modtrezorio/ffunicode.c
Normal file
15599
core/embed/extmod/modtrezorio/ffunicode.c
Normal file
File diff suppressed because it is too large
Load Diff
@ -16,83 +16,89 @@ class TestTrezorIoFatfs(unittest.TestCase):
|
|||||||
self.fs.unmount()
|
self.fs.unmount()
|
||||||
self.sd.power(False)
|
self.sd.power(False)
|
||||||
|
|
||||||
|
def _filename(self, suffix=""):
|
||||||
|
return "FILE%s.TXT" % suffix
|
||||||
|
|
||||||
|
def _dirname(self, suffix=""):
|
||||||
|
return "TREZOR%s" % suffix
|
||||||
|
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
# test just the stuff in setup and teardown
|
# test just the stuff in setup and teardown
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def test_mkdir(self):
|
def test_mkdir(self):
|
||||||
self.fs.mkdir("/TREZOR")
|
self.fs.mkdir("/%s" % self._dirname())
|
||||||
s = self.fs.stat("/TREZOR")
|
s = self.fs.stat("/%s" % self._dirname())
|
||||||
self.assertEqual(s, (0, "---d-", "TREZOR"))
|
self.assertEqual(s, (0, "---d-", self._dirname()))
|
||||||
|
|
||||||
def test_listdir(self):
|
def test_listdir(self):
|
||||||
self.fs.mkdir("/DIR")
|
self.fs.mkdir("/%s" % self._dirname())
|
||||||
with self.fs.open("/FILE.TXT", "w") as f:
|
with self.fs.open("/%s" % self._filename(), "w") as f:
|
||||||
f.write(bytearray(b"test"))
|
f.write(bytearray(b"test"))
|
||||||
with self.fs.open("/DIR/FILE2.TXT", "w") as f:
|
with self.fs.open("/%s/%s" % (self._dirname(), self._filename("2")), "w") as f:
|
||||||
f.write(bytearray(b"testtest"))
|
f.write(bytearray(b"testtest"))
|
||||||
l = [e for e in self.fs.listdir("/")]
|
l = [e for e in self.fs.listdir("/")]
|
||||||
self.assertEqual(l, [(0, "---d-", "DIR"), (4, "----a", "FILE.TXT")])
|
self.assertEqual(l, [(0, "---d-", self._dirname()), (4, "----a", self._filename())])
|
||||||
l = [e for e in self.fs.listdir("/DIR")]
|
l = [e for e in self.fs.listdir("/%s" % self._dirname())]
|
||||||
self.assertEqual(l, [(8, "----a", "FILE2.TXT")])
|
self.assertEqual(l, [(8, "----a", self._filename("2"))])
|
||||||
|
|
||||||
def test_unlink(self):
|
def test_unlink(self):
|
||||||
self.fs.mkdir("/DIR")
|
self.fs.mkdir("/%s" % self._dirname())
|
||||||
with self.fs.open("/FILE.TXT", "w") as f:
|
with self.fs.open("/%s" % self._filename(), "w") as f:
|
||||||
f.write(bytearray(b"test"))
|
f.write(bytearray(b"test"))
|
||||||
s = self.fs.stat("/DIR")
|
s = self.fs.stat("/%s" % self._dirname())
|
||||||
self.assertEqual(s, (0, "---d-", "DIR"))
|
self.assertEqual(s, (0, "---d-", self._dirname()))
|
||||||
s = self.fs.stat("/FILE.TXT")
|
s = self.fs.stat("/%s" % self._filename())
|
||||||
self.assertEqual(s, (4, "----a", "FILE.TXT"))
|
self.assertEqual(s, (4, "----a", self._filename()))
|
||||||
self.fs.unlink("/DIR")
|
self.fs.unlink("/%s" % self._dirname())
|
||||||
self.fs.unlink("/FILE.TXT")
|
self.fs.unlink("/%s" % self._filename())
|
||||||
with self.assertRaises(OSError):
|
with self.assertRaises(OSError):
|
||||||
self.fs.stat("/DIR")
|
self.fs.stat("/%s" % self._dirname())
|
||||||
with self.assertRaises(OSError):
|
with self.assertRaises(OSError):
|
||||||
self.assertRaises(self.fs.stat("/FILE.TXT"))
|
self.assertRaises(self.fs.stat("/%s" % self._filename()))
|
||||||
|
|
||||||
def test_rename(self):
|
def test_rename(self):
|
||||||
self.fs.mkdir("/DIR")
|
self.fs.mkdir("/%s" % self._dirname())
|
||||||
with self.fs.open("/FILE.TXT", "w") as f:
|
with self.fs.open("/%s" % self._filename(), "w") as f:
|
||||||
f.write(bytearray(b"test"))
|
f.write(bytearray(b"test"))
|
||||||
s = self.fs.stat("/DIR")
|
s = self.fs.stat("/%s" % self._dirname())
|
||||||
self.assertEqual(s, (0, "---d-", "DIR"))
|
self.assertEqual(s, (0, "---d-", self._dirname()))
|
||||||
s = self.fs.stat("/FILE.TXT")
|
s = self.fs.stat("/%s" % self._filename())
|
||||||
self.assertEqual(s, (4, "----a", "FILE.TXT"))
|
self.assertEqual(s, (4, "----a", self._filename()))
|
||||||
self.fs.rename("/DIR", "/DIR2")
|
self.fs.rename("/%s" % self._dirname(), "/%s" % self._dirname("2"))
|
||||||
self.fs.rename("/FILE.TXT", "/FILE2.TXT")
|
self.fs.rename("/%s" % self._filename(), "/%s" % self._filename("2"))
|
||||||
with self.assertRaises(OSError):
|
with self.assertRaises(OSError):
|
||||||
self.fs.stat("/DIR")
|
self.fs.stat("/%s" % self._dirname())
|
||||||
with self.assertRaises(OSError):
|
with self.assertRaises(OSError):
|
||||||
self.assertRaises(self.fs.stat("/FILE.TXT"))
|
self.assertRaises(self.fs.stat("/%s" % self._filename()))
|
||||||
s = self.fs.stat("/DIR2")
|
s = self.fs.stat("/%s" % self._dirname("2"))
|
||||||
self.assertEqual(s, (0, "---d-", "DIR2"))
|
self.assertEqual(s, (0, "---d-", self._dirname("2")))
|
||||||
s = self.fs.stat("/FILE2.TXT")
|
s = self.fs.stat("/%s" % self._filename("2"))
|
||||||
self.assertEqual(s, (4, "----a", "FILE2.TXT"))
|
self.assertEqual(s, (4, "----a", self._filename("2")))
|
||||||
|
|
||||||
def test_open_rw(self):
|
def test_open_rw(self):
|
||||||
with self.fs.open("/FILE.TXT", "w") as f:
|
with self.fs.open("/%s" % self._filename(), "w") as f:
|
||||||
f.write(bytearray(b"test"))
|
f.write(bytearray(b"test"))
|
||||||
with self.fs.open("/FILE.TXT", "r") as f:
|
with self.fs.open("/%s" % self._filename(), "r") as f:
|
||||||
b = bytearray(100)
|
b = bytearray(100)
|
||||||
r = f.read(b)
|
r = f.read(b)
|
||||||
self.assertEqual(r, 4)
|
self.assertEqual(r, 4)
|
||||||
self.assertEqual(bytes(b[:4]), b"test")
|
self.assertEqual(bytes(b[:4]), b"test")
|
||||||
|
|
||||||
def test_open_a(self):
|
def test_open_a(self):
|
||||||
with self.fs.open("/FILE.TXT", "w") as f:
|
with self.fs.open("/%s" % self._filename(), "w") as f:
|
||||||
f.write(bytearray(b"test" * 200))
|
f.write(bytearray(b"test" * 200))
|
||||||
with self.fs.open("/FILE.TXT", "a") as f:
|
with self.fs.open("/%s" % self._filename(), "a") as f:
|
||||||
f.seek(800)
|
f.seek(800)
|
||||||
f.write(bytearray(b"TEST" * 200))
|
f.write(bytearray(b"TEST" * 200))
|
||||||
with self.fs.open("/FILE.TXT", "r") as f:
|
with self.fs.open("/%s" % self._filename(), "r") as f:
|
||||||
b = bytearray(2000)
|
b = bytearray(2000)
|
||||||
r = f.read(b)
|
r = f.read(b)
|
||||||
self.assertEqual(r, 1600)
|
self.assertEqual(r, 1600)
|
||||||
self.assertEqual(bytes(b[:1600]), b"test" * 200 + b"TEST" * 200)
|
self.assertEqual(bytes(b[:1600]), b"test" * 200 + b"TEST" * 200)
|
||||||
|
|
||||||
def test_seek(self):
|
def test_seek(self):
|
||||||
with self.fs.open("/FILE.TXT", "w+") as f:
|
with self.fs.open("/%s" % self._filename(), "w+") as f:
|
||||||
f.write(bytearray(b"test" * 10))
|
f.write(bytearray(b"test" * 10))
|
||||||
f.seek(2)
|
f.seek(2)
|
||||||
b = bytearray(8)
|
b = bytearray(8)
|
||||||
@ -101,15 +107,24 @@ class TestTrezorIoFatfs(unittest.TestCase):
|
|||||||
self.assertEqual(bytes(b[:8]), b"sttestte")
|
self.assertEqual(bytes(b[:8]), b"sttestte")
|
||||||
|
|
||||||
def test_truncate(self):
|
def test_truncate(self):
|
||||||
with self.fs.open("/FILE.TXT", "w") as f:
|
with self.fs.open("/%s" % self._filename(), "w") as f:
|
||||||
f.write(bytearray(b"test" * 100))
|
f.write(bytearray(b"test" * 100))
|
||||||
s = self.fs.stat("/FILE.TXT")
|
s = self.fs.stat("/%s" % self._filename())
|
||||||
self.assertEqual(s, (400, "----a", "FILE.TXT"))
|
self.assertEqual(s, (400, "----a", self._filename()))
|
||||||
with self.fs.open("/FILE.TXT", "a") as f:
|
with self.fs.open("/%s" % self._filename(), "a") as f:
|
||||||
f.seek(111)
|
f.seek(111)
|
||||||
f.truncate()
|
f.truncate()
|
||||||
s = self.fs.stat("/FILE.TXT")
|
s = self.fs.stat("/%s" % self._filename())
|
||||||
self.assertEqual(s, (111, "----a", "FILE.TXT"))
|
self.assertEqual(s, (111, "----a", self._filename()))
|
||||||
|
|
||||||
|
|
||||||
|
class TestTrezorIoFatfsLfn(TestTrezorIoFatfs):
|
||||||
|
|
||||||
|
def _filename(self, suffix=""):
|
||||||
|
return "reallylongfilename%s.textfile" % suffix
|
||||||
|
|
||||||
|
def _dirname(self, suffix=""):
|
||||||
|
return "reallylongdirname%s" % suffix
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user