Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix short name? #375

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,4 @@ dependencies {
api project(':httpserver')
api project(':storageprovider')
api project(':javafs')
api project(':libusbcommunication')
}
7 changes: 1 addition & 6 deletions libaums/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -14,10 +13,6 @@ configurations {
javadocDeps
}

junitJacoco {
jacocoVersion = "0.8.6"
}

android {
compileSdkVersion 30
buildToolsVersion '30.0.3'
Expand Down Expand Up @@ -59,7 +54,7 @@ android {
path "CMakeLists.txt"
}
}
ndkVersion '22.0.70260617'
ndkVersion '22.0.7026061'
}

dependencies {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,34 @@ 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)

if (read != transferLength) {
throw IOException("Unexpected command size (" + read + ") on response to "
+ command)
}

tmpBuffer.flip()
inBuffer.limit(inBuffer.position() + transferLength)
inBuffer.put(tmpBuffer)
} else {
written = 0
do {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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
Expand All @@ -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]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 == '&'

Expand Down Expand Up @@ -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: ShortName): Boolean {
var contain = false
for (temp in shortNames) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
}

Expand Down