xref: /haiku/src/add-ons/kernel/file_systems/packagefs/nodes/Node.cpp (revision fc7456e9b1ec38c941134ed6d01c438cf289381e)
1 /*
2  * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include "Node.h"
8 
9 #include <stdlib.h>
10 #include <string.h>
11 
12 #include <AutoLocker.h>
13 #include <lock.h>
14 
15 #include "DebugSupport.h"
16 #include "Directory.h"
17 #include "EmptyAttributeDirectoryCookie.h"
18 
19 
20 static rw_lock sParentChangeLock = RW_LOCK_INITIALIZER("packagefs node parent change");
21 
22 
23 DEFINE_INLINE_REFERENCEABLE_METHODS(Node, fReferenceable);
24 
25 
26 Node::Node(ino_t id)
27 	:
28 	fID(id),
29 	fParent(NULL),
30 	fName(),
31 	fFlags(0)
32 {
33 }
34 
35 
36 Node::~Node()
37 {
38 }
39 
40 
41 BReference<Directory>
42 Node::GetParent() const
43 {
44 	ReadLocker parentChangeLocker(sParentChangeLock);
45 	if (fParent == NULL)
46 		return NULL;
47 	return BReference<Directory>(fParent, false);
48 }
49 
50 
51 void
52 Node::_SetParent(Directory* parent)
53 {
54 	WriteLocker parentChangeLocker(sParentChangeLock);
55 	fParent = parent;
56 }
57 
58 
59 status_t
60 Node::Init(const String& name)
61 {
62 	fName = name;
63 	fFlags = 0;
64 	return B_OK;
65 }
66 
67 
68 void
69 Node::SetID(ino_t id)
70 {
71 	fID = id;
72 }
73 
74 
75 status_t
76 Node::VFSInit(dev_t deviceID)
77 {
78 	fFlags |= NODE_FLAG_KNOWN_TO_VFS;
79 	return B_OK;
80 }
81 
82 
83 void
84 Node::VFSUninit()
85 {
86 	fFlags &= ~(uint32)NODE_FLAG_KNOWN_TO_VFS;
87 }
88 
89 
90 uid_t
91 Node::UserID() const
92 {
93 	return 0;
94 }
95 
96 
97 gid_t
98 Node::GroupID() const
99 {
100 	return 0;
101 }
102 
103 
104 status_t
105 Node::OpenAttributeDirectory(AttributeDirectoryCookie*& _cookie)
106 {
107 	AttributeDirectoryCookie* cookie
108 		= new(std::nothrow) EmptyAttributeDirectoryCookie;
109 	if (cookie == NULL)
110 		return B_NO_MEMORY;
111 
112 	_cookie = cookie;
113 	return B_OK;
114 }
115 
116 
117 status_t
118 Node::OpenAttribute(const StringKey& name, int openMode,
119 	AttributeCookie*& _cookie)
120 {
121 	return B_ENTRY_NOT_FOUND;
122 }
123 
124 
125 status_t
126 Node::IndexAttribute(AttributeIndexer* indexer)
127 {
128 	return B_NOT_SUPPORTED;
129 }
130 
131 
132 void*
133 Node::IndexCookieForAttribute(const StringKey& name) const
134 {
135 	return NULL;
136 }
137