feat: disconnect Bluetooth devices, flush disks on shutdown/reboot, display progress in login.elf window
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
|
||||
#include "FsProbe.hpp"
|
||||
#include <Drivers/Storage/Gpt.hpp>
|
||||
#include <Drivers/Storage/BlockDevice.hpp>
|
||||
#include <Terminal/Terminal.hpp>
|
||||
#include <Libraries/Memory.hpp>
|
||||
|
||||
@@ -195,4 +196,43 @@ namespace Fs::FsProbe {
|
||||
return unmounted;
|
||||
}
|
||||
|
||||
int SyncAndUnmountAll() {
|
||||
// 1. Flush every block device's volatile write cache to media. FAT32 and
|
||||
// ext2 are write-through, so file data already reached the device; the
|
||||
// flush makes the device commit it to non-volatile storage.
|
||||
int devCount = Drivers::Storage::GetBlockDeviceCount();
|
||||
for (int i = 0; i < devCount; i++) {
|
||||
const auto* dev = Drivers::Storage::GetBlockDevice(i);
|
||||
if (dev && dev->Flush) {
|
||||
dev->Flush(dev->Ctx);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Cleanly unmount every disk-backed VFS drive. The ramdisk has no
|
||||
// backing block device (GetBlockDeviceForDrive < 0) and is left
|
||||
// mounted so the rest of userspace keeps running until power-off.
|
||||
int drives[Vfs::MaxDrives];
|
||||
int n = Vfs::VfsDriveList(drives, Vfs::MaxDrives);
|
||||
int unmounted = 0;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
int driveNum = drives[i];
|
||||
if (GetBlockDeviceForDrive(driveNum) < 0) continue;
|
||||
|
||||
if (Vfs::UnregisterDrive(driveNum) == 0) {
|
||||
unmounted++;
|
||||
for (int p = 0; p < Drivers::Storage::Gpt::MaxPartitions; p++) {
|
||||
if (g_mounted[p] && g_driveForPart[p] == driveNum) {
|
||||
g_mounted[p] = false;
|
||||
g_driveForPart[p] = -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Kt::KernelLogStream(Kt::OK, "FsProbe") << "Synced and unmounted "
|
||||
<< unmounted << " disk-backed volume(s) for power-off";
|
||||
return unmounted;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user