1/*
2 * Copyright 2001-2010, Haiku Inc. All rights reserved.
3 * This file may be used under the terms of the MIT License.
4 *
5 * Authors:
6 *		Janito V. Ferreira Filho
7 */
8
9
10#include "InodeJournal.h"
11
12#include <new>
13
14#include <fs_cache.h>
15
16#include "HashRevokeManager.h"
17
18
19//#define TRACE_EXT2
20#ifdef TRACE_EXT2
21#	define TRACE(x...) dprintf("\33[34mext2:\33[0m " x)
22#else
23#	define TRACE(x...) ;
24#endif
25
26
27InodeJournal::InodeJournal(Inode* inode)
28	:
29	Journal(),
30	fInode(inode)
31{
32	if (inode == NULL)
33		fInitStatus = B_BAD_DATA;
34	else {
35		Volume* volume = inode->GetVolume();
36
37		fFilesystemVolume = volume;
38		fFilesystemBlockCache = volume->BlockCache();
39		fJournalVolume = volume;
40		fJournalBlockCache = volume->BlockCache();
41
42		if (inode->HasFileCache())
43			inode->DeleteFileCache();
44
45		fInitStatus = B_OK;
46
47		TRACE("InodeJournal::InodeJournal(): Inode's file cache disabled "
48			"successfully\n");
49		HashRevokeManager* revokeManager = new(std::nothrow)
50			HashRevokeManager(volume->Has64bitFeature());
51		TRACE("InodeJournal::InodeJournal(): Allocated a hash revoke "
52			"manager at %p\n", revokeManager);
53
54		if (revokeManager == NULL) {
55			TRACE("InodeJournal::InodeJournal(): Insufficient memory to "
56				"create the hash revoke manager\n");
57			fInitStatus = B_NO_MEMORY;
58		} else {
59			fInitStatus = revokeManager->Init();
60
61			if (fInitStatus == B_OK) {
62				fRevokeManager = revokeManager;
63				fInitStatus = _LoadSuperBlock();
64			} else
65				delete revokeManager;
66		}
67	}
68}
69
70
71InodeJournal::~InodeJournal()
72{
73}
74
75
76status_t
77InodeJournal::InitCheck()
78{
79	if (fInitStatus != B_OK)
80		TRACE("InodeJournal: Initialization error\n");
81	return fInitStatus;
82}
83
84
85status_t
86InodeJournal::MapBlock(off_t logical, fsblock_t& physical)
87{
88	TRACE("InodeJournal::MapBlock()\n");
89	return fInode->FindBlock(logical * fBlockSize, physical);
90}
91