From 66ae5b2d993e457764f5c72d2ea9ea604068187f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Axel=20D=C3=B6rfler?= Date: Fri, 26 Jun 2009 15:03:42 +0000 Subject: [PATCH] * The block allocator will no longer try to fix a missing allocation on a read-only volume. This fixes bug #3432. * Journal::ReplayLog() will now return an error on a read-only device, rendering read-only dirty volumes unmountable. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@31255 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../file_systems/bfs/BlockAllocator.cpp | 20 ++++++++++++------- .../kernel/file_systems/bfs/Journal.cpp | 14 +++++++++---- .../kernel/file_systems/bfs/Volume.cpp | 6 +++--- 3 files changed, 26 insertions(+), 14 deletions(-) diff --git a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp index af6a3cdb37..c6654d6fbc 100644 --- a/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp +++ b/src/add-ons/kernel/file_systems/bfs/BlockAllocator.cpp @@ -684,14 +684,20 @@ BlockAllocator::_Initialize(BlockAllocator* allocator) uint32 reservedBlocks = volume->Log().Start() + volume->Log().Length(); if (allocator->CheckBlocks(0, reservedBlocks) != B_OK) { - Transaction transaction(volume, 0); - if (groups[0].Allocate(transaction, 0, reservedBlocks) != B_OK) { - FATAL(("could not allocate reserved space for block " - "bitmap/log!\n")); - volume->Panic(); + if (volume->IsReadOnly()) { + FATAL(("Space for block bitmap or log area is not reserved " + "(volume is mounted read-only)!\n")); } else { - transaction.Done(); - FATAL(("space for block bitmap or log area was not reserved!\n")); + Transaction transaction(volume, 0); + if (groups[0].Allocate(transaction, 0, reservedBlocks) != B_OK) { + FATAL(("Could not allocate reserved space for block " + "bitmap/log!\n")); + volume->Panic(); + } else { + transaction.Done(); + FATAL(("Space for block bitmap or log area was not " + "reserved!\n")); + } } } diff --git a/src/add-ons/kernel/file_systems/bfs/Journal.cpp b/src/add-ons/kernel/file_systems/bfs/Journal.cpp index 24ef97b88f..bb06909511 100644 --- a/src/add-ons/kernel/file_systems/bfs/Journal.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Journal.cpp @@ -559,8 +559,13 @@ Journal::ReplayLog() INFORM(("Replay log, disk was not correctly unmounted...\n")); - if (fVolume->SuperBlock().flags != SUPER_BLOCK_DISK_DIRTY) - INFORM(("log_start and log_end differ, but disk is marked clean - trying to replay log...\n")); + if (fVolume->SuperBlock().flags != SUPER_BLOCK_DISK_DIRTY) { + INFORM(("log_start and log_end differ, but disk is marked clean - " + "trying to replay log...\n")); + } + + if (fVolume->IsReadOnly()) + return B_READ_ONLY_DEVICE; int32 start = fVolume->LogStart(); int32 lastStart = -1; @@ -576,8 +581,9 @@ Journal::ReplayLog() lastStart = start; status_t status = _ReplayRunArray(&start); - if (status < B_OK) { - FATAL(("replaying log entry from %d failed: %s\n", (int)start, strerror(status))); + if (status != B_OK) { + FATAL(("replaying log entry from %d failed: %s\n", (int)start, + strerror(status))); return B_ERROR; } start = start % fLogSize; diff --git a/src/add-ons/kernel/file_systems/bfs/Volume.cpp b/src/add-ons/kernel/file_systems/bfs/Volume.cpp index d971307213..a60b7e9bb8 100644 --- a/src/add-ons/kernel/file_systems/bfs/Volume.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Volume.cpp @@ -344,7 +344,7 @@ Volume::Mount(const char* deviceName, uint32 flags) // check if the device size is large enough to hold the file system off_t diskSize; - if (opener.GetSize(&diskSize) < B_OK) + if (opener.GetSize(&diskSize) != B_OK) RETURN_ERROR(B_ERROR); if (diskSize < (NumBlocks() << BlockShift())) RETURN_ERROR(B_BAD_VALUE); @@ -368,7 +368,7 @@ Volume::Mount(const char* deviceName, uint32 flags) // replaying the log is the first thing we will do on this disk status = fJournal->ReplayLog(); - if (status < B_OK) { + if (status != B_OK) { FATAL(("Replaying log failed, data may be corrupted, volume " "read-only.\n")); fFlags |= VOLUME_READ_ONLY; @@ -379,7 +379,7 @@ Volume::Mount(const char* deviceName, uint32 flags) } status = fBlockAllocator.Initialize(); - if (status < B_OK) { + if (status != B_OK) { FATAL(("could not initialize block bitmap allocator!\n")); return status; }