From 20513148d66a48ba8ef5db0fff7f515286fd874a Mon Sep 17 00:00:00 2001 From: patrickraguin Date: Fri, 23 Jul 2021 11:22:37 +0200 Subject: [PATCH 1/4] Fix bulkInTransfer error : Could not read from device, result == -1 errno 0 --- app/build.gradle | 1 - libaums/build.gradle | 7 +------ .../github/mjdev/libaums/usb/JellyBeanMr2Communication.kt | 5 ++++- 3 files changed, 5 insertions(+), 8 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 744f3612..67ab2525 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -34,5 +34,4 @@ dependencies { api project(':httpserver') api project(':storageprovider') api project(':javafs') - api project(':libusbcommunication') } diff --git a/libaums/build.gradle b/libaums/build.gradle index 146d98f3..98c947b1 100644 --- a/libaums/build.gradle +++ b/libaums/build.gradle @@ -2,7 +2,6 @@ apply plugin: 'com.android.library' apply plugin: 'kotlin-android' apply plugin: 'kotlin-android-extensions' apply plugin: 'org.jetbrains.dokka' -apply plugin: "com.vanniktech.android.junit.jacoco" ext { artifact = 'libaums' @@ -14,10 +13,6 @@ configurations { javadocDeps } -junitJacoco { - jacocoVersion = "0.8.6" -} - android { compileSdkVersion 30 buildToolsVersion '30.0.3' @@ -59,7 +54,7 @@ android { path "CMakeLists.txt" } } - ndkVersion '22.0.70260617' + ndkVersion '22.0.7026061' } dependencies { diff --git a/libaums/src/main/java/com/github/mjdev/libaums/usb/JellyBeanMr2Communication.kt b/libaums/src/main/java/com/github/mjdev/libaums/usb/JellyBeanMr2Communication.kt index 175d5214..a1d23f08 100644 --- a/libaums/src/main/java/com/github/mjdev/libaums/usb/JellyBeanMr2Communication.kt +++ b/libaums/src/main/java/com/github/mjdev/libaums/usb/JellyBeanMr2Communication.kt @@ -52,7 +52,10 @@ internal class JellyBeanMr2Communication( if (result == -1) { when (ErrNo.errno) { EPIPE -> throw PipeException() - else -> throw IOException("Could not read from device, result == -1 errno " + ErrNo.errno + " " + ErrNo.errstr) + else -> { + this.clearFeatureHalt(inEndpoint) + throw IOException("Could not read from device, result == -1 errno " + ErrNo.errno + " " + ErrNo.errstr) + } } } From 9e3f63db65e6c85e54b0d4c61fa3a0655721c420 Mon Sep 17 00:00:00 2001 From: Patrick Raguin Date: Wed, 1 Sep 2021 17:45:00 +0200 Subject: [PATCH 2/4] Fix the limitation of 64 files per directory --- .../libaums/driver/scsi/ScsiBlockDevice.kt | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/libaums/src/main/java/com/github/mjdev/libaums/driver/scsi/ScsiBlockDevice.kt b/libaums/src/main/java/com/github/mjdev/libaums/driver/scsi/ScsiBlockDevice.kt index 56b92be1..ef790e7f 100644 --- a/libaums/src/main/java/com/github/mjdev/libaums/driver/scsi/ScsiBlockDevice.kt +++ b/libaums/src/main/java/com/github/mjdev/libaums/driver/scsi/ScsiBlockDevice.kt @@ -255,18 +255,23 @@ class ScsiBlockDevice(private val usbCommunication: UsbCommunication, private va } var transferLength = command.dCbwDataTransferLength - inBuffer.clear() - inBuffer.limit(transferLength) +// inBuffer.clear() +// inBuffer.limit(transferLength) var read = 0 if (transferLength > 0) { if (command.direction == Direction.IN) { + val tmpBuffer = ByteBuffer.allocate(transferLength) + do { - read += usbCommunication.bulkInTransfer(inBuffer) +// read += usbCommunication.bulkInTransfer(inBuffer) + read += usbCommunication.bulkInTransfer(tmpBuffer) if (command.bCbwDynamicSize) { - transferLength = command.dynamicSizeFromPartialResponse(inBuffer) - inBuffer.limit(transferLength) +// transferLength = command.dynamicSizeFromPartialResponse(inBuffer) +// inBuffer.limit(transferLength) + transferLength = command.dynamicSizeFromPartialResponse(tmpBuffer) + tmpBuffer.limit(transferLength) } } while (read < transferLength) @@ -274,6 +279,10 @@ class ScsiBlockDevice(private val usbCommunication: UsbCommunication, private va throw IOException("Unexpected command size (" + read + ") on response to " + command) } + + tmpBuffer.flip() + inBuffer.limit(inBuffer.position() + transferLength) + inBuffer.put(tmpBuffer) } else { written = 0 do { From d969f5ae160cbbe1f78ee06875b5c22b7728549e Mon Sep 17 00:00:00 2001 From: Patrick Raguin Date: Tue, 21 Sep 2021 19:30:56 +0200 Subject: [PATCH 3/4] Fix 8.3 filename --- .../mjdev/libaums/fs/fat32/FatDirectory.kt | 49 ++++++++++++++++--- .../libaums/fs/fat32/ShortNameGenerator.kt | 11 ++++- 2 files changed, 53 insertions(+), 7 deletions(-) diff --git a/libaums/src/main/java/com/github/mjdev/libaums/fs/fat32/FatDirectory.kt b/libaums/src/main/java/com/github/mjdev/libaums/fs/fat32/FatDirectory.kt index 3ff06fd5..8bc8e00b 100644 --- a/libaums/src/main/java/com/github/mjdev/libaums/fs/fat32/FatDirectory.kt +++ b/libaums/src/main/java/com/github/mjdev/libaums/fs/fat32/FatDirectory.kt @@ -249,8 +249,18 @@ internal constructor( return removeEntry(lfnEntry) - lfnEntry.setName(newName, - ShortNameGenerator.generateShortName(newName, shortNameMap.keys)) + + val isLfn = ShortNameGenerator.filenameIsLfn(newName) + val shortName: ShortName = if (isLfn) { + ShortNameGenerator.generateShortName(newName, shortNameMap.keys) + } else { + ShortName( + newName.substringBefore(".").uppercase(), + newName.substringAfter(".", "").uppercase() + ) + } + + lfnEntry.setName(newName, shortName) addEntry(lfnEntry, lfnEntry.actualEntry) write() } @@ -306,9 +316,21 @@ internal constructor( init() // initialise the directory before creating files - val shortName = ShortNameGenerator.generateShortName(name, shortNameMap.keys) - val entry = FatLfnDirectoryEntry(name, shortName) + val isLfn = ShortNameGenerator.filenameIsLfn(name) + val entry: FatLfnDirectoryEntry + val shortName: ShortName + if (isLfn) { + shortName = ShortNameGenerator.generateShortName(name, shortNameMap.keys) + entry = FatLfnDirectoryEntry(name, shortName) + } else { + shortName = ShortName( + name.substringBefore(".").uppercase(), + name.substringAfter(".", "").uppercase() + ) + entry = FatLfnDirectoryEntry(if (name == shortName.string) null else name, shortName) + } + // alloc completely new chain val newStartCluster = fat.alloc(arrayOf(), 1)[0] entry.startCluster = newStartCluster @@ -330,9 +352,24 @@ internal constructor( init() // initialise the directory before creating files - val shortName = ShortNameGenerator.generateShortName(name, shortNameMap.keys) + val isLfn = ShortNameGenerator.filenameIsLfn(name) + + val entry: FatLfnDirectoryEntry + val shortName: ShortName + + if (isLfn) { + // LongFileName + shortName = ShortNameGenerator.generateShortName(name, shortNameMap.keys) + entry = FatLfnDirectoryEntry(name, shortName) + } else { + // ShortFileName + shortName = ShortName( + name.substringBefore(".").uppercase(), + name.substringAfter(".", "").uppercase() + ) + entry = FatLfnDirectoryEntry(if (name == shortName.string) null else name, shortName) + } - val entry = FatLfnDirectoryEntry(name, shortName) entry.setDirectory() // alloc completely new chain val newStartCluster = fat.alloc(arrayOf(), 1)[0] diff --git a/libaums/src/main/java/com/github/mjdev/libaums/fs/fat32/ShortNameGenerator.kt b/libaums/src/main/java/com/github/mjdev/libaums/fs/fat32/ShortNameGenerator.kt index 041b11bf..d2617d05 100644 --- a/libaums/src/main/java/com/github/mjdev/libaums/fs/fat32/ShortNameGenerator.kt +++ b/libaums/src/main/java/com/github/mjdev/libaums/fs/fat32/ShortNameGenerator.kt @@ -40,7 +40,7 @@ internal object ShortNameGenerator { private fun isValidChar(c: Char): Boolean { if (c in '0'..'9') return true - return if (c in 'A'..'Z') true else c == '$' || c == '%' || c == '\'' || c == '-' || c == '_' || c == '@' || c == '~' + return if ((c in 'A'..'Z') || (c in 'a'..'z')) true else c == '$' || c == '%' || c == '\'' || c == '-' || c == '_' || c == '@' || c == '~' || c == '`' || c == '!' || c == '(' || c == ')' || c == '{' || c == '}' || c == '^' || c == '#' || c == '&' @@ -199,6 +199,15 @@ internal object ShortNameGenerator { return result } + fun filenameIsLfn(filename: String): Boolean { + + val namePart = filename.substringBefore(".") + val extPart = filename.substringAfter(".", "") + + return namePart.length > 8 || extPart.length > 3 || containsInvalidChars(namePart) || containsInvalidChars(extPart) + + } + private fun containShortName(shortNames: Collection, shortName: ShortName): Boolean { var contain = false for (temp in shortNames) { From 2bcb154c8071f68de8dbc9c159dd3a7856935d19 Mon Sep 17 00:00:00 2001 From: Patrick Raguin Date: Tue, 21 Sep 2021 19:45:31 +0200 Subject: [PATCH 4/4] (re) Fix 8.3 filename --- .../github/mjdev/libaums/fs/fat32/FatDirectory.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/libaums/src/main/java/com/github/mjdev/libaums/fs/fat32/FatDirectory.kt b/libaums/src/main/java/com/github/mjdev/libaums/fs/fat32/FatDirectory.kt index 8bc8e00b..a4ec4c33 100644 --- a/libaums/src/main/java/com/github/mjdev/libaums/fs/fat32/FatDirectory.kt +++ b/libaums/src/main/java/com/github/mjdev/libaums/fs/fat32/FatDirectory.kt @@ -255,8 +255,8 @@ internal constructor( ShortNameGenerator.generateShortName(newName, shortNameMap.keys) } else { ShortName( - newName.substringBefore(".").uppercase(), - newName.substringAfter(".", "").uppercase() + newName.substringBefore(".").toUpperCase(Locale.ROOT), + newName.substringAfter(".", "").toUpperCase(Locale.ROOT) ) } @@ -325,8 +325,8 @@ internal constructor( entry = FatLfnDirectoryEntry(name, shortName) } else { shortName = ShortName( - name.substringBefore(".").uppercase(), - name.substringAfter(".", "").uppercase() + name.substringBefore(".").toUpperCase(Locale.ROOT), + name.substringAfter(".", "").toUpperCase(Locale.ROOT) ) entry = FatLfnDirectoryEntry(if (name == shortName.string) null else name, shortName) } @@ -364,8 +364,8 @@ internal constructor( } else { // ShortFileName shortName = ShortName( - name.substringBefore(".").uppercase(), - name.substringAfter(".", "").uppercase() + name.substringBefore(".").toUpperCase(Locale.ROOT), + name.substringAfter(".", "").toUpperCase(Locale.ROOT) ) entry = FatLfnDirectoryEntry(if (name == shortName.string) null else name, shortName) }