forked from SerenityOS/serenity
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Kernel: Ignore dirfd if absolute path is given in VFS-related syscalls
To be able to do this, we add a new class called CustodyBase, which can be resolved on-demand internally in the VirtualFileSystem resolving path code. When being resolved, CustodyBase will return a known custody if it was constructed with such, if that's not the case it will provide the root custody if the original path is absolute. Lastly, if that's not the case as well, it will resolve the given dirfd to provide a Custody object.
- Loading branch information
1 parent
1e4a78e
commit ecc9c54
Showing
23 changed files
with
157 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
/* | ||
* Copyright (c) 2024, Liav A. <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#include <Kernel/FileSystem/CustodyBase.h> | ||
#include <Kernel/FileSystem/VirtualFileSystem.h> | ||
#include <Kernel/Library/KLexicalPath.h> | ||
#include <Kernel/Tasks/Process.h> | ||
|
||
namespace Kernel { | ||
|
||
ErrorOr<NonnullRefPtr<Custody>> CustodyBase::resolve() const | ||
{ | ||
if (m_base) | ||
return *m_base; | ||
if (KLexicalPath::is_absolute(m_path)) | ||
return VirtualFileSystem::the().root_custody(); | ||
return Process::current().custody_for_dirfd({}, m_dirfd); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2024, Liav A. <[email protected]> | ||
* | ||
* SPDX-License-Identifier: BSD-2-Clause | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include <AK/Error.h> | ||
#include <AK/RefPtr.h> | ||
#include <AK/StringView.h> | ||
#include <Kernel/FileSystem/Custody.h> | ||
|
||
namespace Kernel { | ||
|
||
class CustodyBase { | ||
public: | ||
CustodyBase(int dirfd, StringView path) | ||
: m_path(path) | ||
, m_dirfd(dirfd) | ||
{ | ||
} | ||
|
||
CustodyBase(NonnullRefPtr<Custody> base) | ||
: m_base(base) | ||
{ | ||
} | ||
|
||
CustodyBase(Custody& base) | ||
: m_base(base) | ||
{ | ||
} | ||
|
||
CustodyBase(Custody const& base) | ||
: m_base(base) | ||
{ | ||
} | ||
|
||
ErrorOr<NonnullRefPtr<Custody>> resolve() const; | ||
|
||
private: | ||
RefPtr<Custody> const m_base; | ||
StringView m_path; | ||
int m_dirfd { -1 }; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.