From c3f10b4674ea41e67f9f97190c36265af6879f7c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Thu, 29 May 2003 01:02:18 +0000 Subject: [PATCH] Added a simple magic field mechanism to make chkbfs calls a little more safe. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3381 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/file_systems/bfs/BlockAllocator.cpp | 17 +++++++++++++++-- .../kernel/file_systems/bfs/BlockAllocator.h | 1 + .../kernel/file_systems/bfs/bfs_control.h | 4 ++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp index cf13c1bd49..5a6c642910 100644 --- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp @@ -642,10 +642,23 @@ BlockAllocator::Free(Transaction *transaction, block_run run) // the "chkbfs" command +bool +BlockAllocator::IsValidCheckControl(check_control *control) +{ + if (control == NULL + || control->magic != BFS_IOCTL_CHECK_MAGIC) { + FATAL(("invalid check_control (%p)!\n", control)); + return false; + } + + return true; +} + + status_t BlockAllocator::StartChecking(check_control *control) { - if (control == NULL) + if (!IsValidCheckControl(control)) return B_BAD_VALUE; status_t status = fLock.Lock(); @@ -771,7 +784,7 @@ BlockAllocator::StopChecking(check_control *control) status_t BlockAllocator::CheckNextNode(check_control *control) { - if (control == NULL) + if (!IsValidCheckControl(control)) return B_BAD_VALUE; check_cookie *cookie = (check_cookie *)control->cookie; diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h index ffd47d50b5..e023a5f83a 100644 --- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h +++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.h @@ -44,6 +44,7 @@ class BlockAllocator { status_t CheckInode(Inode *inode, check_control *control = NULL); private: + bool IsValidCheckControl(check_control *control); bool CheckBitmapIsUsedAt(off_t block) const; void SetCheckBitmapAt(off_t block); diff --git a/src/add-ons/kernel/file_systems/bfs/bfs_control.h b/src/add-ons/kernel/file_systems/bfs/bfs_control.h index b4a9da8574..858aa54a0f 100644 --- a/src/add-ons/kernel/file_systems/bfs/bfs_control.h +++ b/src/add-ons/kernel/file_systems/bfs/bfs_control.h @@ -34,6 +34,7 @@ extern "C" { * BFS_IOCTL_START_CHECKING is called */ struct check_control { + uint32 magic; uint32 flags; char name[B_FILE_NAME_LENGTH]; vnode_id inode; @@ -69,4 +70,7 @@ struct check_control { #define BFS_WRONG_TYPE 16 #define BFS_NAMES_DONT_MATCH 32 +/* check control magic value */ +#define BFS_IOCTL_CHECK_MAGIC 'BChk' + #endif /* BFS_CONTROL_H */