Created
April 12, 2020 18:29
-
-
Save jaredrummler/4d28bd6904a40a4477a06734ede02d86 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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