diff --git a/src/add-ons/kernel/file_systems/bfs/Journal.cpp b/src/add-ons/kernel/file_systems/bfs/Journal.cpp index a5a656f0a5..364dca68d9 100644 --- a/src/add-ons/kernel/file_systems/bfs/Journal.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Journal.cpp @@ -355,16 +355,7 @@ Journal::~Journal() status_t Journal::InitCheck() { - // TODO: this logic won't work whenever the size of the pending transaction - // equals the size of the log (happens with the original BFS only) - if (fVolume->LogStart() != fVolume->LogEnd()) { - if (fVolume->SuperBlock().flags != SUPER_BLOCK_DISK_DIRTY) - FATAL(("log_start and log_end differ, but disk is marked clean - trying to replay log...\n")); - - return ReplayLog(); - } - - return B_OK; + return fLock.InitCheck(); } @@ -493,8 +484,16 @@ Journal::_ReplayRunArray(int32 *_start) status_t Journal::ReplayLog() { + // TODO: this logic won't work whenever the size of the pending transaction + // equals the size of the log (happens with the original BFS only) + if (fVolume->LogStart() == fVolume->LogEnd()) + return B_OK; + 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")); + int32 start = fVolume->LogStart(); int32 lastStart = -1; while (true) { diff --git a/src/add-ons/kernel/file_systems/bfs/Lock.h b/src/add-ons/kernel/file_systems/bfs/Lock.h index 7626bbbe92..23880741cf 100644 --- a/src/add-ons/kernel/file_systems/bfs/Lock.h +++ b/src/add-ons/kernel/file_systems/bfs/Lock.h @@ -1,5 +1,5 @@ /* - * Copyright 2001-2007, Axel Dörfler, axeld@pinc-software.de. + * Copyright 2001-2008, Axel Dörfler, axeld@pinc-software.de. * This file may be used under the terms of the MIT License. */ #ifndef LOCK_H @@ -48,7 +48,7 @@ class Semaphore { { if (fSemaphore < B_OK) return fSemaphore; - + return B_OK; } @@ -62,7 +62,7 @@ class Semaphore { return B_OK; #endif } - + status_t Unlock() { #ifdef USE_BENAPHORE @@ -109,7 +109,7 @@ class Locker { }; -//**** Recursive Lock +// #pragma mark - Recursive Lock class RecursiveLock { public: @@ -125,6 +125,14 @@ class RecursiveLock { { } + status_t InitCheck() const + { + if (fSemaphore < B_OK) + return fSemaphore; + + return B_OK; + } + status_t LockWithTimeout(bigtime_t timeout) { thread_id thread = find_thread(NULL); @@ -277,7 +285,7 @@ class ReadWriteLock { { if (fSemaphore < B_OK) return fSemaphore; - + return B_OK; } @@ -363,7 +371,7 @@ class ReadWriteLock { { if (fSemaphore < B_OK) return fSemaphore; - + return B_OK; } @@ -543,7 +551,7 @@ class SimpleLock { break; if (current == thisThread) break; - + snooze(time); } diff --git a/src/add-ons/kernel/file_systems/bfs/Volume.cpp b/src/add-ons/kernel/file_systems/bfs/Volume.cpp index 20bd4e2021..3b5fe2298e 100644 --- a/src/add-ons/kernel/file_systems/bfs/Volume.cpp +++ b/src/add-ons/kernel/file_systems/bfs/Volume.cpp @@ -363,13 +363,23 @@ Volume::Mount(const char *deviceName, uint32 flags) if (fJournal == NULL) return B_NO_MEMORY; - // replaying the log is the first thing we will do on this disk status_t status = fJournal->InitCheck(); if (status < B_OK) { FATAL(("could not initialize journal: %s!\n", strerror(status))); return status; } + // replaying the log is the first thing we will do on this disk + status = fJournal->ReplayLog(); + if (status < B_OK) { + FATAL(("Replaying log failed, data may be corrupted, volume read-only.\n")); + fFlags |= VOLUME_READ_ONLY; + // TODO: if this is the boot volume, Bootscript will assume this + // is a CD... + // TODO: it would be nice to have a user visible alert instead + // of letting him just find this in the syslog. + } + status = fBlockAllocator.Initialize(); if (status < B_OK) { FATAL(("could not initialize block bitmap allocator!\n"));