xref: /haiku/src/add-ons/kernel/file_systems/xfs/Extent.cpp (revision 21258e2674226d6aa732321b6f8494841895af5f)
1 /*
2  * Copyright 2020, Shubham Bhagat, shubhambhagat111@yahoo.com
3  * All rights reserved. Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "Extent.h"
8 
9 
10 Extent::Extent(Inode* inode)
11 	:
12 	fInode(inode)
13 {
14 }
15 
16 
17 void
18 Extent::FillMapEntry(void* pointerToMap)
19 {
20 	uint64 firstHalf = *((uint64*)pointerToMap);
21 	uint64 secondHalf = *((uint64*)pointerToMap + 1);
22 		//dividing the 128 bits into 2 parts.
23 	firstHalf = B_BENDIAN_TO_HOST_INT64(firstHalf);
24 	secondHalf = B_BENDIAN_TO_HOST_INT64(secondHalf);
25 	fMap->br_state = (firstHalf >> 63);
26 	fMap->br_startoff = (firstHalf & MASK(63)) >> 9;
27 	fMap->br_startblock = ((firstHalf & MASK(9)) << 43) | (secondHalf >> 21);
28 	fMap->br_blockcount = (secondHalf & MASK(21));
29 	TRACE("Extent::Init: startoff:(%ld), startblock:(%ld), blockcount:(%ld),"
30 			"state:(%d)\n",
31 		fMap->br_startoff,
32 		fMap->br_startblock,
33 		fMap->br_blockcount,
34 		fMap->br_state
35 		);
36 }
37 
38 
39 status_t
40 Extent::Init()
41 {
42 	fMap = new(std::nothrow) ExtentMapEntry;
43 	if (fMap == NULL)
44 		return B_NO_MEMORY;
45 
46 	ASSERT(BlockType() == true);
47 	void* pointerToMap = DIR_DFORK_PTR(fInode->Buffer());
48 	FillMapEntry(pointerToMap);
49 
50 	return B_NOT_SUPPORTED;
51 }
52 
53 
54 ExtentBlockTail*
55 Extent::BlockTail(ExtentDataHeader* header)
56 {
57 	return (ExtentBlockTail*)
58 		((char*)header + fInode->DirBlockSize() - sizeof(ExtentBlockTail));
59 }
60 
61 
62 ExtentLeafEntry*
63 Extent::BlockFirstLeaf(ExtentBlockTail* tail)
64 {
65 	return (ExtentLeafEntry*)tail - B_BENDIAN_TO_HOST_INT32(tail->count);
66 }
67 
68 
69 bool
70 Extent::BlockType()
71 {
72 	bool status = true;
73 	if (fInode->NoOfBlocks() != 1)
74 		status = false;
75 	if (fInode->Size() != fInode->DirBlockSize())
76 		status = false;
77 	return status;
78 }
79 
80