2020-01-18 09:38:21 +01:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
*
|
2021-04-22 01:24:48 -07:00
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
2020-01-18 09:38:21 +01:00
|
|
|
*/
|
|
|
|
|
2019-05-30 18:58:59 +02:00
|
|
|
#include <AK/StringBuilder.h>
|
2020-03-23 13:45:10 +01:00
|
|
|
#include <AK/StringView.h>
|
2020-02-16 02:15:33 +01:00
|
|
|
#include <AK/Vector.h>
|
2019-05-30 17:46:08 +02:00
|
|
|
#include <Kernel/FileSystem/Custody.h>
|
|
|
|
#include <Kernel/FileSystem/Inode.h>
|
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
namespace Kernel {
|
|
|
|
|
2020-01-11 18:25:26 +03:00
|
|
|
Custody::Custody(Custody* parent, const StringView& name, Inode& inode, int mount_flags)
|
2019-05-30 17:46:08 +02:00
|
|
|
: m_parent(parent)
|
|
|
|
, m_name(name)
|
|
|
|
, m_inode(inode)
|
2020-01-11 18:25:26 +03:00
|
|
|
, m_mount_flags(mount_flags)
|
2019-05-30 17:46:08 +02:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
Custody::~Custody()
|
|
|
|
{
|
|
|
|
}
|
2019-05-30 18:58:59 +02:00
|
|
|
|
|
|
|
String Custody::absolute_path() const
|
|
|
|
{
|
2020-01-10 23:09:58 +01:00
|
|
|
if (!parent())
|
|
|
|
return "/";
|
2019-05-30 18:58:59 +02:00
|
|
|
Vector<const Custody*, 32> custody_chain;
|
|
|
|
for (auto* custody = this; custody; custody = custody->parent())
|
|
|
|
custody_chain.append(custody);
|
|
|
|
StringBuilder builder;
|
|
|
|
for (int i = custody_chain.size() - 2; i >= 0; --i) {
|
|
|
|
builder.append('/');
|
|
|
|
builder.append(custody_chain[i]->name().characters());
|
|
|
|
}
|
|
|
|
return builder.to_string();
|
|
|
|
}
|
2019-05-31 15:22:52 +02:00
|
|
|
|
2020-05-28 17:56:25 +03:00
|
|
|
bool Custody::is_readonly() const
|
|
|
|
{
|
|
|
|
if (m_mount_flags & MS_RDONLY)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
return m_inode->fs().is_readonly();
|
|
|
|
}
|
|
|
|
|
2020-02-16 01:27:42 +01:00
|
|
|
}
|