xref: /haiku/src/add-ons/kernel/file_systems/xfs/Attribute.cpp (revision 4a55cc230cf7566cadcbb23b1928eefff8aea9a2)
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 		LeafAttribute* leafAttr = new(std::nothrow) LeafAttribute(inode);
30 		if (leafAttr == NULL)
31 			return NULL;
32 
33 		status_t status = leafAttr->Init();
34 
35 		if (status == B_OK)
36 			return leafAttr;
37 		delete leafAttr;
38 
39 		NodeAttribute* nodeAttr = new(std::nothrow) NodeAttribute(inode);
40 		if (nodeAttr == NULL)
41 			return NULL;
42 
43 		status = nodeAttr->Init();
44 
45 		if (status == B_OK)
46 			return nodeAttr;
47 		delete nodeAttr;
48 
49 		// Invalid format in extents return NULL
50 		return NULL;
51 	}
52 
53 	// Invalid format
54 	return NULL;
55 }