mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-12-13 01:40:36 +00:00
lsblk: Port to Core::Stream
This commit is contained in:
parent
8d7179766a
commit
03a3b6f91c
Notes:
sideshowbarker
2024-07-17 04:16:26 +09:00
Author: https://github.com/AtkinsSJ Commit: https://github.com/SerenityOS/serenity/commit/03a3b6f91c Pull-request: https://github.com/SerenityOS/serenity/pull/15244 Reviewed-by: https://github.com/davidot ✅ Reviewed-by: https://github.com/demostanis
1 changed files with 33 additions and 13 deletions
|
@ -9,7 +9,7 @@
|
|||
#include <AK/StringView.h>
|
||||
#include <LibCore/ArgsParser.h>
|
||||
#include <LibCore/DirIterator.h>
|
||||
#include <LibCore/File.h>
|
||||
#include <LibCore/Stream.h>
|
||||
#include <LibCore/System.h>
|
||||
#include <LibMain/Main.h>
|
||||
|
||||
|
@ -37,25 +37,45 @@ ErrorOr<int> serenity_main(Main::Arguments arguments)
|
|||
|
||||
while (di.has_next()) {
|
||||
auto dir = di.next_path();
|
||||
auto command_set_file = Core::File::construct(String::formatted("/sys/devices/storage/{}/command_set", dir));
|
||||
if (!command_set_file->open(Core::OpenMode::ReadOnly)) {
|
||||
dbgln("Error: Could not open {}: {}", command_set_file->name(), command_set_file->error_string());
|
||||
auto command_set_filename = String::formatted("/sys/devices/storage/{}/command_set", dir);
|
||||
auto command_set_file = Core::Stream::File::open(command_set_filename, Core::Stream::OpenMode::Read);
|
||||
if (command_set_file.is_error()) {
|
||||
dbgln("Error: Could not open {}: {}", command_set_filename, command_set_file.error());
|
||||
continue;
|
||||
}
|
||||
auto last_lba_file = Core::File::construct(String::formatted("/sys/devices/storage/{}/last_lba", dir));
|
||||
if (!last_lba_file->open(Core::OpenMode::ReadOnly)) {
|
||||
dbgln("Error: Could not open {}: {}", last_lba_file->name(), last_lba_file->error_string());
|
||||
auto last_lba_filename = String::formatted("/sys/devices/storage/{}/last_lba", dir);
|
||||
auto last_lba_file = Core::Stream::File::open(last_lba_filename, Core::Stream::OpenMode::Read);
|
||||
if (last_lba_file.is_error()) {
|
||||
dbgln("Error: Could not open {}: {}", last_lba_filename, last_lba_file.error());
|
||||
continue;
|
||||
}
|
||||
auto sector_size_file = Core::File::construct(String::formatted("/sys/devices/storage/{}/sector_size", dir));
|
||||
if (!sector_size_file->open(Core::OpenMode::ReadOnly)) {
|
||||
dbgln("Error: Could not open {}: {}", sector_size_file->name(), sector_size_file->error_string());
|
||||
auto sector_size_filename = String::formatted("/sys/devices/storage/{}/sector_size", dir);
|
||||
auto sector_size_file = Core::Stream::File::open(sector_size_filename, Core::Stream::OpenMode::Read);
|
||||
if (sector_size_file.is_error()) {
|
||||
dbgln("Error: Could not open {}: {}", sector_size_filename, sector_size_file.error());
|
||||
continue;
|
||||
}
|
||||
|
||||
String command_set = StringView(command_set_file->read_all().bytes());
|
||||
String last_lba = StringView(last_lba_file->read_all().bytes());
|
||||
String sector_size = StringView(sector_size_file->read_all().bytes());
|
||||
auto maybe_command_set = command_set_file.value()->read_all();
|
||||
if (maybe_command_set.is_error()) {
|
||||
dbgln("Error: Could not read {}: {}", command_set_filename, maybe_command_set.error());
|
||||
continue;
|
||||
}
|
||||
String command_set = StringView(maybe_command_set.value().bytes());
|
||||
|
||||
auto maybe_last_lba = last_lba_file.value()->read_all();
|
||||
if (maybe_last_lba.is_error()) {
|
||||
dbgln("Error: Could not read {}: {}", last_lba_filename, maybe_last_lba.error());
|
||||
continue;
|
||||
}
|
||||
String last_lba = StringView(maybe_last_lba.value().bytes());
|
||||
|
||||
auto maybe_sector_size = sector_size_file.value()->read_all();
|
||||
if (maybe_sector_size.is_error()) {
|
||||
dbgln("Error: Could not read {}: {}", sector_size_filename, maybe_sector_size.error());
|
||||
continue;
|
||||
}
|
||||
String sector_size = StringView(maybe_sector_size.value().bytes());
|
||||
|
||||
outln(format_row, dir, command_set, sector_size, last_lba);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue