@@ -35,47 +35,17 @@ Inode& TmpFS::root_inode()
35
35
return *m_root_inode;
36
36
}
37
37
38
- void TmpFS::register_inode (TmpFSInode& inode)
39
- {
40
- VERIFY (inode.identifier ().fsid () == fsid ());
41
-
42
- Inode::all_instances ().with ([&](auto &) {
43
- auto index = inode.identifier ().index ();
44
- m_inodes.set (index, &inode);
45
- });
46
- }
47
-
48
- void TmpFS::unregister_inode (InodeIdentifier identifier)
49
- {
50
- VERIFY (identifier.fsid () == fsid ());
51
-
52
- Inode::all_instances ().with ([&](auto &) {
53
- m_inodes.remove (identifier.index ());
54
- });
55
- }
56
-
57
38
unsigned TmpFS::next_inode_index ()
58
39
{
59
40
MutexLocker locker (m_lock);
60
41
61
42
return m_next_inode_index++;
62
43
}
63
44
64
- ErrorOr<NonnullRefPtr<Inode>> TmpFS::get_inode (InodeIdentifier identifier) const
65
- {
66
- return Inode::all_instances ().with ([&](auto &) -> ErrorOr<NonnullRefPtr<Inode>> {
67
- VERIFY (identifier.fsid () == fsid ());
68
- auto it = m_inodes.find (identifier.index ());
69
- if (it == m_inodes.end ())
70
- return ENOENT;
71
- return *it->value ;
72
- });
73
- }
74
-
75
- TmpFSInode::TmpFSInode (TmpFS& fs, const InodeMetadata& metadata, InodeIdentifier parent)
45
+ TmpFSInode::TmpFSInode (TmpFS& fs, const InodeMetadata& metadata, WeakPtr<TmpFSInode> parent)
76
46
: Inode(fs, fs.next_inode_index())
77
47
, m_metadata(metadata)
78
- , m_parent(parent)
48
+ , m_parent(move( parent) )
79
49
{
80
50
m_metadata.inode = identifier ();
81
51
}
@@ -84,11 +54,9 @@ TmpFSInode::~TmpFSInode()
84
54
{
85
55
}
86
56
87
- ErrorOr<NonnullRefPtr<TmpFSInode>> TmpFSInode::try_create (TmpFS& fs, InodeMetadata const & metadata, InodeIdentifier parent)
57
+ ErrorOr<NonnullRefPtr<TmpFSInode>> TmpFSInode::try_create (TmpFS& fs, InodeMetadata const & metadata, WeakPtr<TmpFSInode> parent)
88
58
{
89
- auto inode = TRY (adopt_nonnull_ref_or_enomem (new (nothrow) TmpFSInode (fs, metadata, parent)));
90
- fs.register_inode (inode);
91
- return inode;
59
+ return adopt_nonnull_ref_or_enomem (new (nothrow) TmpFSInode (fs, metadata, move (parent)));
92
60
}
93
61
94
62
ErrorOr<NonnullRefPtr<TmpFSInode>> TmpFSInode::try_create_root (TmpFS& fs)
@@ -99,7 +67,7 @@ ErrorOr<NonnullRefPtr<TmpFSInode>> TmpFSInode::try_create_root(TmpFS& fs)
99
67
metadata.ctime = now;
100
68
metadata.mtime = now;
101
69
metadata.mode = S_IFDIR | S_ISVTX | 0777 ;
102
- return try_create (fs, metadata, { fs. fsid (), 1 });
70
+ return try_create (fs, metadata, {});
103
71
}
104
72
105
73
InodeMetadata TmpFSInode::metadata () const
@@ -117,7 +85,8 @@ ErrorOr<void> TmpFSInode::traverse_as_directory(Function<ErrorOr<void>(FileSyste
117
85
return ENOTDIR;
118
86
119
87
TRY (callback ({ " ." , identifier (), 0 }));
120
- TRY (callback ({ " .." , m_parent, 0 }));
88
+ if (auto parent = m_parent.strong_ref ())
89
+ TRY (callback ({ " .." , parent->identifier (), 0 }));
121
90
122
91
for (auto & child : m_children) {
123
92
TRY (callback ({ child.name ->view (), child.inode ->identifier (), 0 }));
@@ -194,8 +163,11 @@ ErrorOr<NonnullRefPtr<Inode>> TmpFSInode::lookup(StringView name)
194
163
195
164
if (name == " ." )
196
165
return *this ;
197
- if (name == " .." )
198
- return fs ().get_inode (m_parent);
166
+ if (name == " .." ) {
167
+ if (auto parent = m_parent.strong_ref ())
168
+ return parent.release_nonnull ();
169
+ return ENOENT;
170
+ }
199
171
200
172
auto * child = find_child_by_name (name);
201
173
if (!child)
@@ -260,7 +232,7 @@ ErrorOr<NonnullRefPtr<Inode>> TmpFSInode::create_child(StringView name, mode_t m
260
232
metadata.ctime = now;
261
233
metadata.mtime = now;
262
234
263
- auto child = TRY (TmpFSInode::try_create (fs (), metadata, identifier () ));
235
+ auto child = TRY (TmpFSInode::try_create (fs (), metadata, * this ));
264
236
TRY (add_child (*child, name, mode));
265
237
return child;
266
238
}
@@ -365,9 +337,4 @@ ErrorOr<void> TmpFSInode::set_mtime(time_t t)
365
337
return {};
366
338
}
367
339
368
- void TmpFSInode::remove_from_secondary_lists ()
369
- {
370
- fs ().unregister_inode (identifier ());
371
- }
372
-
373
340
}
0 commit comments