xref: /haiku/src/add-ons/kernel/file_systems/ufs2/Inode.cpp (revision 5889cb5e7e8e7bfea6072ddfe881f55d364a0cf0)
1 /*
2  * Copyright 2020 Suhel Mehta, mehtasuhel@gmail.com
3  * Copyright 2008-2010, Axel Dörfler, axeld@pinc-software.de.
4  * All rights reserved. Distributed under the terms of the MIT License.
5  */
6 
7 #include "Inode.h"
8 
9 #ifdef TRACE_ufs2
10 #define TRACE(x...) dprintf("\33[34mufs2:\33[0m " x)
11 #else
12 #define TRACE(x...) ;
13 #endif
14 #define ERROR(x...) dprintf("\33[34mufs2:\33[0m " x)
15 
16 
17 Inode::Inode(Volume* volume, ino_t id)
18 	:
19 	fVolume(volume),
20 	fID(id),
21 	fCache(NULL),
22 	fMap(NULL)
23 {
24 	rw_lock_init(&fLock, "ufs2 inode");
25 
26 	fInitStatus = B_OK;//UpdateNodeFromDisk();
27 	if (fInitStatus == B_OK) {
28 		if (!IsDirectory() && !IsSymLink()) {
29 			fCache = file_cache_create(fVolume->ID(), ID(), Size());
30 			fMap = file_map_create(fVolume->ID(), ID(), Size());
31 		}
32 	}
33 	int fd = fVolume->Device();
34 	ufs2_super_block* superblock = (ufs2_super_block* )&fVolume->SuperBlock();
35 	int64_t fs_block = ino_to_fsba(superblock, id);
36 	int64_t offset_in_block = ino_to_fsbo(superblock, id);
37 	int64_t offset = fs_block * MINBSIZE + offset_in_block * 256;
38 
39 	if (read_pos(fd, offset, (void*)&fNode, sizeof(fNode)) != sizeof(fNode))
40 		ERROR("Inode::Inode(): IO Error\n");
41 
42 
43 }
44 
45 
46 Inode::Inode(Volume* volume, ino_t id, const ufs2_inode& item)
47 	:
48 	fVolume(volume),
49 	fID(id),
50 	fCache(NULL),
51 	fMap(NULL),
52 	fInitStatus(B_OK),
53 	fNode(item)
54 {
55 	if (!IsDirectory() && !IsSymLink()) {
56 		fCache = file_cache_create(fVolume->ID(), ID(), Size());
57 		fMap = file_map_create(fVolume->ID(), ID(), Size());
58 	}
59 }
60 
61 
62 Inode::Inode(Volume* volume)
63 	:
64 	fVolume(volume),
65 	fID(0),
66 	fCache(NULL),
67 	fMap(NULL),
68 	fInitStatus(B_NO_INIT)
69 {
70 	rw_lock_init(&fLock, "ufs2 inode");
71 }
72 
73 
74 Inode::~Inode()
75 {
76 	TRACE("Inode destructor\n");
77 	file_cache_delete(FileCache());
78 	file_map_delete(Map());
79 	TRACE("Inode destructor: Done\n");
80 }
81 
82 
83 status_t
84 Inode::InitCheck()
85 {
86 	return fInitStatus;
87 }
88