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
This commit is contained in:
@@ -642,10 +642,23 @@ BlockAllocator::Free(Transaction *transaction, block_run run)
|
|||||||
// the "chkbfs" command
|
// 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
|
status_t
|
||||||
BlockAllocator::StartChecking(check_control *control)
|
BlockAllocator::StartChecking(check_control *control)
|
||||||
{
|
{
|
||||||
if (control == NULL)
|
if (!IsValidCheckControl(control))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
status_t status = fLock.Lock();
|
status_t status = fLock.Lock();
|
||||||
@@ -771,7 +784,7 @@ BlockAllocator::StopChecking(check_control *control)
|
|||||||
status_t
|
status_t
|
||||||
BlockAllocator::CheckNextNode(check_control *control)
|
BlockAllocator::CheckNextNode(check_control *control)
|
||||||
{
|
{
|
||||||
if (control == NULL)
|
if (!IsValidCheckControl(control))
|
||||||
return B_BAD_VALUE;
|
return B_BAD_VALUE;
|
||||||
|
|
||||||
check_cookie *cookie = (check_cookie *)control->cookie;
|
check_cookie *cookie = (check_cookie *)control->cookie;
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class BlockAllocator {
|
|||||||
status_t CheckInode(Inode *inode, check_control *control = NULL);
|
status_t CheckInode(Inode *inode, check_control *control = NULL);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
bool IsValidCheckControl(check_control *control);
|
||||||
bool CheckBitmapIsUsedAt(off_t block) const;
|
bool CheckBitmapIsUsedAt(off_t block) const;
|
||||||
void SetCheckBitmapAt(off_t block);
|
void SetCheckBitmapAt(off_t block);
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ extern "C" {
|
|||||||
* BFS_IOCTL_START_CHECKING is called
|
* BFS_IOCTL_START_CHECKING is called
|
||||||
*/
|
*/
|
||||||
struct check_control {
|
struct check_control {
|
||||||
|
uint32 magic;
|
||||||
uint32 flags;
|
uint32 flags;
|
||||||
char name[B_FILE_NAME_LENGTH];
|
char name[B_FILE_NAME_LENGTH];
|
||||||
vnode_id inode;
|
vnode_id inode;
|
||||||
@@ -69,4 +70,7 @@ struct check_control {
|
|||||||
#define BFS_WRONG_TYPE 16
|
#define BFS_WRONG_TYPE 16
|
||||||
#define BFS_NAMES_DONT_MATCH 32
|
#define BFS_NAMES_DONT_MATCH 32
|
||||||
|
|
||||||
|
/* check control magic value */
|
||||||
|
#define BFS_IOCTL_CHECK_MAGIC 'BChk'
|
||||||
|
|
||||||
#endif /* BFS_CONTROL_H */
|
#endif /* BFS_CONTROL_H */
|
||||||
|
|||||||
Reference in New Issue
Block a user