Skip to content

Instantly share code, notes, and snippets.

@jaredrummler
Created April 12, 2020 18:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jaredrummler/4d28bd6904a40a4477a06734ede02d86 to your computer and use it in GitHub Desktop.
Save jaredrummler/4d28bd6904a40a4477a06734ede02d86 to your computer and use it in GitHub Desktop.
import java.io.File
import java.util.regex.Matcher
import java.util.regex.Pattern
fun String.toFile() = File(this)
operator fun Matcher.get(group: Int): String = group(group)!!
data class MountPoint(
val device: String,
val point: String,
val system: String,
val dump: String,
val option: String,
val fsk1: String,
val fsk2: String
) {
companion object {
private const val PROC_MOUNTS = "/proc/mounts"
fun read() = mutableListOf<MountPoint>().apply {
val pattern = Pattern.compile(
"^(\\S+)\\s+(\\S+)\\s+(\\S+)\\s+(([a-z]+)[,\\S+]+)[\\s]*(\\d)?[\\s]*(\\d)?\$"
// device point system option dump fsk fsk
)
PROC_MOUNTS.toFile().useLines { lines ->
lines.forEach { line ->
val matcher =
pattern.matcher(line).takeIf { it.matches() } ?: return@forEach
add(matcher.run {
MountPoint(
device = this[1],
point = this[2],
system = this[3],
dump = this[4],
option = this[5],
fsk1 = this[6],
fsk2 = this[7]
)
})
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment