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/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 { 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..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 @@ -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(".").toUpperCase(Locale.ROOT), + newName.substringAfter(".", "").toUpperCase(Locale.ROOT) + ) + } + + 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(".").toUpperCase(Locale.ROOT), + name.substringAfter(".", "").toUpperCase(Locale.ROOT) + ) + 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(".").toUpperCase(Locale.ROOT), + name.substringAfter(".", "").toUpperCase(Locale.ROOT) + ) + 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) { 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) + } } }