mirror of
https://github.com/trezor/trezor-firmware.git
synced 2024-11-13 19:18:56 +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
|
||||
SOURCE_MOD += [
|
||||
'embed/extmod/modtrezorio/ff.c',
|
||||
'embed/extmod/modtrezorio/ffunicode.c',
|
||||
'embed/extmod/modtrezorio/modtrezorio.c',
|
||||
]
|
||||
|
||||
|
@ -126,6 +126,7 @@ if EVERYTHING:
|
||||
# modtrezorio
|
||||
SOURCE_MOD += [
|
||||
'embed/extmod/modtrezorio/ff.c',
|
||||
'embed/extmod/modtrezorio/ffunicode.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
|
||||
/* 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. */
|
||||
|
||||
|
||||
#define FF_LFN_UNICODE 0
|
||||
#define FF_LFN_UNICODE 2
|
||||
/* This option switches the character encoding on the API when LFN is enabled.
|
||||
/
|
||||
/ 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.sd.power(False)
|
||||
|
||||
def _filename(self, suffix=""):
|
||||
return "FILE%s.TXT" % suffix
|
||||
|
||||
def _dirname(self, suffix=""):
|
||||
return "TREZOR%s" % suffix
|
||||
|
||||
def test_basic(self):
|
||||
# test just the stuff in setup and teardown
|
||||
pass
|
||||
|
||||
def test_mkdir(self):
|
||||
self.fs.mkdir("/TREZOR")
|
||||
s = self.fs.stat("/TREZOR")
|
||||
self.assertEqual(s, (0, "---d-", "TREZOR"))
|
||||
self.fs.mkdir("/%s" % self._dirname())
|
||||
s = self.fs.stat("/%s" % self._dirname())
|
||||
self.assertEqual(s, (0, "---d-", self._dirname()))
|
||||
|
||||
def test_listdir(self):
|
||||
self.fs.mkdir("/DIR")
|
||||
with self.fs.open("/FILE.TXT", "w") as f:
|
||||
self.fs.mkdir("/%s" % self._dirname())
|
||||
with self.fs.open("/%s" % self._filename(), "w") as f:
|
||||
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"))
|
||||
l = [e for e in self.fs.listdir("/")]
|
||||
self.assertEqual(l, [(0, "---d-", "DIR"), (4, "----a", "FILE.TXT")])
|
||||
l = [e for e in self.fs.listdir("/DIR")]
|
||||
self.assertEqual(l, [(8, "----a", "FILE2.TXT")])
|
||||
self.assertEqual(l, [(0, "---d-", self._dirname()), (4, "----a", self._filename())])
|
||||
l = [e for e in self.fs.listdir("/%s" % self._dirname())]
|
||||
self.assertEqual(l, [(8, "----a", self._filename("2"))])
|
||||
|
||||
def test_unlink(self):
|
||||
self.fs.mkdir("/DIR")
|
||||
with self.fs.open("/FILE.TXT", "w") as f:
|
||||
self.fs.mkdir("/%s" % self._dirname())
|
||||
with self.fs.open("/%s" % self._filename(), "w") as f:
|
||||
f.write(bytearray(b"test"))
|
||||
s = self.fs.stat("/DIR")
|
||||
self.assertEqual(s, (0, "---d-", "DIR"))
|
||||
s = self.fs.stat("/FILE.TXT")
|
||||
self.assertEqual(s, (4, "----a", "FILE.TXT"))
|
||||
self.fs.unlink("/DIR")
|
||||
self.fs.unlink("/FILE.TXT")
|
||||
s = self.fs.stat("/%s" % self._dirname())
|
||||
self.assertEqual(s, (0, "---d-", self._dirname()))
|
||||
s = self.fs.stat("/%s" % self._filename())
|
||||
self.assertEqual(s, (4, "----a", self._filename()))
|
||||
self.fs.unlink("/%s" % self._dirname())
|
||||
self.fs.unlink("/%s" % self._filename())
|
||||
with self.assertRaises(OSError):
|
||||
self.fs.stat("/DIR")
|
||||
self.fs.stat("/%s" % self._dirname())
|
||||
with self.assertRaises(OSError):
|
||||
self.assertRaises(self.fs.stat("/FILE.TXT"))
|
||||
self.assertRaises(self.fs.stat("/%s" % self._filename()))
|
||||
|
||||
def test_rename(self):
|
||||
self.fs.mkdir("/DIR")
|
||||
with self.fs.open("/FILE.TXT", "w") as f:
|
||||
self.fs.mkdir("/%s" % self._dirname())
|
||||
with self.fs.open("/%s" % self._filename(), "w") as f:
|
||||
f.write(bytearray(b"test"))
|
||||
s = self.fs.stat("/DIR")
|
||||
self.assertEqual(s, (0, "---d-", "DIR"))
|
||||
s = self.fs.stat("/FILE.TXT")
|
||||
self.assertEqual(s, (4, "----a", "FILE.TXT"))
|
||||
self.fs.rename("/DIR", "/DIR2")
|
||||
self.fs.rename("/FILE.TXT", "/FILE2.TXT")
|
||||
s = self.fs.stat("/%s" % self._dirname())
|
||||
self.assertEqual(s, (0, "---d-", self._dirname()))
|
||||
s = self.fs.stat("/%s" % self._filename())
|
||||
self.assertEqual(s, (4, "----a", self._filename()))
|
||||
self.fs.rename("/%s" % self._dirname(), "/%s" % self._dirname("2"))
|
||||
self.fs.rename("/%s" % self._filename(), "/%s" % self._filename("2"))
|
||||
with self.assertRaises(OSError):
|
||||
self.fs.stat("/DIR")
|
||||
self.fs.stat("/%s" % self._dirname())
|
||||
with self.assertRaises(OSError):
|
||||
self.assertRaises(self.fs.stat("/FILE.TXT"))
|
||||
s = self.fs.stat("/DIR2")
|
||||
self.assertEqual(s, (0, "---d-", "DIR2"))
|
||||
s = self.fs.stat("/FILE2.TXT")
|
||||
self.assertEqual(s, (4, "----a", "FILE2.TXT"))
|
||||
self.assertRaises(self.fs.stat("/%s" % self._filename()))
|
||||
s = self.fs.stat("/%s" % self._dirname("2"))
|
||||
self.assertEqual(s, (0, "---d-", self._dirname("2")))
|
||||
s = self.fs.stat("/%s" % self._filename("2"))
|
||||
self.assertEqual(s, (4, "----a", self._filename("2")))
|
||||
|
||||
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"))
|
||||
with self.fs.open("/FILE.TXT", "r") as f:
|
||||
with self.fs.open("/%s" % self._filename(), "r") as f:
|
||||
b = bytearray(100)
|
||||
r = f.read(b)
|
||||
self.assertEqual(r, 4)
|
||||
self.assertEqual(bytes(b[:4]), b"test")
|
||||
|
||||
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))
|
||||
with self.fs.open("/FILE.TXT", "a") as f:
|
||||
with self.fs.open("/%s" % self._filename(), "a") as f:
|
||||
f.seek(800)
|
||||
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)
|
||||
r = f.read(b)
|
||||
self.assertEqual(r, 1600)
|
||||
self.assertEqual(bytes(b[:1600]), b"test" * 200 + b"TEST" * 200)
|
||||
|
||||
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.seek(2)
|
||||
b = bytearray(8)
|
||||
@ -101,15 +107,24 @@ class TestTrezorIoFatfs(unittest.TestCase):
|
||||
self.assertEqual(bytes(b[:8]), b"sttestte")
|
||||
|
||||
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))
|
||||
s = self.fs.stat("/FILE.TXT")
|
||||
self.assertEqual(s, (400, "----a", "FILE.TXT"))
|
||||
with self.fs.open("/FILE.TXT", "a") as f:
|
||||
s = self.fs.stat("/%s" % self._filename())
|
||||
self.assertEqual(s, (400, "----a", self._filename()))
|
||||
with self.fs.open("/%s" % self._filename(), "a") as f:
|
||||
f.seek(111)
|
||||
f.truncate()
|
||||
s = self.fs.stat("/FILE.TXT")
|
||||
self.assertEqual(s, (111, "----a", "FILE.TXT"))
|
||||
s = self.fs.stat("/%s" % self._filename())
|
||||
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__":
|
||||
|
Loading…
Reference in New Issue
Block a user