bfs: split checkfs code into FileSystemVisitor and CheckVisitor

Another FileSystemVisitor implementation will be used for resizing

Change-Id: I2d5f47dcbefb4c76834487b194a99c6f5ae7de50
Reviewed-on: https://review.haiku-os.org/c/923
Reviewed-by: Jérôme Duval <[email protected]>
This commit is contained in:
ahenriksson
2019-02-19 18:44:43 +00:00
committed by waddlesplash
parent 8497a2cc28
commit aa7750382a
11 changed files with 1353 additions and 964 deletions
@@ -7,6 +7,7 @@
//! file system interface to Haiku's vnode layer
#include "CheckVisitor.h"
#include "Debug.h"
#include "Volume.h"
#include "Inode.h"
@@ -672,12 +673,18 @@ bfs_ioctl(fs_volume* _volume, fs_vnode* _node, void* _cookie, uint32 cmd,
case BFS_IOCTL_START_CHECKING:
{
// start checking
BlockAllocator& allocator = volume->Allocator();
check_control control;
if (user_memcpy(&control, buffer, sizeof(check_control)) != B_OK)
return B_BAD_ADDRESS;
status_t status = volume->CreateCheckVisitor();
if (status != B_OK)
return status;
status_t status = allocator.StartChecking(&control);
CheckVisitor* checker = volume->CheckVisitor();
if (user_memcpy(&checker->Control(), buffer,
sizeof(check_control)) != B_OK) {
return B_BAD_ADDRESS;
}
status = checker->StartBitmapPass();
if (status == B_OK) {
file_cookie* cookie = (file_cookie*)_cookie;
cookie->open_mode |= BFS_OPEN_MODE_CHECKING;
@@ -688,28 +695,51 @@ bfs_ioctl(fs_volume* _volume, fs_vnode* _node, void* _cookie, uint32 cmd,
case BFS_IOCTL_STOP_CHECKING:
{
// stop checking
BlockAllocator& allocator = volume->Allocator();
check_control control;
CheckVisitor* checker = volume->CheckVisitor();
if (checker == NULL)
return B_NO_INIT;
status_t status = checker->StopChecking();
status_t status = allocator.StopChecking(&control);
if (status == B_OK) {
file_cookie* cookie = (file_cookie*)_cookie;
cookie->open_mode &= ~BFS_OPEN_MODE_CHECKING;
status = user_memcpy(buffer, &checker->Control(),
sizeof(check_control));
}
if (status == B_OK)
status = user_memcpy(buffer, &control, sizeof(check_control));
volume->DeleteCheckVisitor();
volume->SetCheckingThread(-1);
return status;
}
case BFS_IOCTL_CHECK_NEXT_NODE:
{
// check next
BlockAllocator& allocator = volume->Allocator();
check_control control;
CheckVisitor* checker = volume->CheckVisitor();
if (checker == NULL)
return B_NO_INIT;
status_t status = allocator.CheckNextNode(&control);
if (status == B_OK)
status = user_memcpy(buffer, &control, sizeof(check_control));
volume->SetCheckingThread(find_thread(NULL));
checker->Control().errors = 0;
status_t status = checker->Next();
if (status == B_ENTRY_NOT_FOUND) {
checker->Control().status = B_ENTRY_NOT_FOUND;
// tells StopChecking() that we finished the pass
if (checker->Pass() == BFS_CHECK_PASS_BITMAP) {
if (checker->WriteBackCheckBitmap() == B_OK)
status = checker->StartIndexPass();
}
}
if (status == B_OK) {
status = user_memcpy(buffer, &checker->Control(),
sizeof(check_control));
}
return status;
}
@@ -1508,7 +1538,8 @@ bfs_free_cookie(fs_volume* _volume, fs_vnode* _node, void* _cookie)
if ((cookie->open_mode & BFS_OPEN_MODE_CHECKING) != 0) {
// "chkbfs" exited abnormally, so we have to stop it here...
FATAL(("check process was aborted!\n"));
volume->Allocator().StopChecking(NULL);
volume->CheckVisitor()->StopChecking();
volume->DeleteCheckVisitor();
}
if ((cookie->open_mode & O_NOCACHE) != 0 && inode->FileCache() != NULL)