xref: /haiku/src/add-ons/kernel/file_systems/xfs/Attribute.cpp (revision 13581b3d2a71545960b98fefebc5225b5bf29072)
1 /*
2  * Copyright 2022, Raghav Sharma, raghavself28@gmail.com
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "Attribute.h"
8 
9 #include "LeafAttribute.h"
10 #include "NodeAttribute.h"
11 #include "ShortAttribute.h"
12 
13 
14 Attribute::~Attribute()
15 {
16 }
17 
18 
19 Attribute*
20 Attribute::Init(Inode* inode)
21 {
22 	if (inode->AttrFormat() == XFS_DINODE_FMT_LOCAL) {
23 		TRACE("Attribute:Init: LOCAL\n");
24 		ShortAttribute* shortAttr = new(std::nothrow) ShortAttribute(inode);
25 		return shortAttr;
26 	}
27 	if (inode->AttrFormat() == XFS_DINODE_FMT_EXTENTS) {
28 		TRACE("Attribute::Init: EXTENTS\n");
29 		// check if Inode has extents or not?
30 		if (inode->AttrExtentsCount() == 0)
31 			return NULL;
32 
33 		LeafAttribute* leafAttr = new(std::nothrow) LeafAttribute(inode);
34 		if (leafAttr == NULL)
35 			return NULL;
36 
37 		status_t status = leafAttr->Init();
38 
39 		if (status == B_OK)
40 			return leafAttr;
41 		delete leafAttr;
42 
43 		NodeAttribute* nodeAttr = new(std::nothrow) NodeAttribute(inode);
44 		if (nodeAttr == NULL)
45 			return NULL;
46 
47 		status = nodeAttr->Init();
48 
49 		if (status == B_OK)
50 			return nodeAttr;
51 		delete nodeAttr;
52 
53 		// Invalid format in extents return NULL
54 		return NULL;
55 	}
56 
57 	// Invalid format
58 	return NULL;
59 }