2020-01-18 11:38:21 +03:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2018-2020, Andreas Kling <kling@serenityos.org>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright notice, this
|
|
|
|
* list of conditions and the following disclaimer.
|
|
|
|
*
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
|
|
* and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
|
|
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
|
|
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
|
|
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-06-21 19:58:45 +03:00
|
|
|
#include <AK/RefCounted.h>
|
2019-08-11 16:56:39 +03:00
|
|
|
#include <AK/RefPtr.h>
|
2020-01-28 22:42:27 +03:00
|
|
|
#include <AK/String.h>
|
|
|
|
#include <Kernel/FileSystem/InodeIdentifier.h>
|
2019-02-25 22:47:56 +03:00
|
|
|
#include <Kernel/KResult.h>
|
2019-05-28 12:53:16 +03:00
|
|
|
#include <Kernel/Lock.h>
|
2020-01-28 22:42:27 +03:00
|
|
|
#include <Kernel/UnixTypes.h>
|
2018-10-10 12:53:07 +03:00
|
|
|
|
2020-02-16 03:27:42 +03:00
|
|
|
namespace Kernel {
|
|
|
|
|
2019-07-03 22:17:35 +03:00
|
|
|
static const u32 mepoch = 476763780;
|
2018-10-10 12:53:07 +03:00
|
|
|
|
2018-12-19 23:18:28 +03:00
|
|
|
class Inode;
|
2019-06-07 10:36:51 +03:00
|
|
|
class FileDescription;
|
2019-02-14 17:55:19 +03:00
|
|
|
class LocalSocket;
|
2019-01-16 14:57:07 +03:00
|
|
|
class VMObject;
|
2018-10-27 01:14:24 +03:00
|
|
|
|
2019-06-21 16:29:31 +03:00
|
|
|
class FS : public RefCounted<FS> {
|
2019-02-28 23:51:59 +03:00
|
|
|
friend class Inode;
|
2019-05-28 12:53:16 +03:00
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
public:
|
2018-11-15 19:13:10 +03:00
|
|
|
virtual ~FS();
|
2018-10-10 12:53:07 +03:00
|
|
|
|
2019-01-23 07:38:54 +03:00
|
|
|
unsigned fsid() const { return m_fsid; }
|
2019-07-03 22:17:35 +03:00
|
|
|
static FS* from_fsid(u32);
|
2018-12-20 02:39:29 +03:00
|
|
|
static void sync();
|
2019-06-16 12:49:39 +03:00
|
|
|
static void lock_all();
|
2018-10-10 12:53:07 +03:00
|
|
|
|
|
|
|
virtual bool initialize() = 0;
|
2018-11-15 17:36:35 +03:00
|
|
|
virtual const char* class_name() const = 0;
|
2020-06-24 23:35:56 +03:00
|
|
|
virtual NonnullRefPtr<Inode> root_inode() const = 0;
|
2019-12-15 21:33:39 +03:00
|
|
|
virtual bool supports_watchers() const { return false; }
|
2018-10-10 12:53:07 +03:00
|
|
|
|
2018-12-19 23:56:45 +03:00
|
|
|
bool is_readonly() const { return m_readonly; }
|
|
|
|
|
2019-02-21 16:48:00 +03:00
|
|
|
virtual unsigned total_block_count() const { return 0; }
|
|
|
|
virtual unsigned free_block_count() const { return 0; }
|
|
|
|
virtual unsigned total_inode_count() const { return 0; }
|
|
|
|
virtual unsigned free_inode_count() const { return 0; }
|
|
|
|
|
2019-08-11 16:56:39 +03:00
|
|
|
virtual KResult prepare_to_unmount() const { return KSuccess; }
|
|
|
|
|
2019-09-10 22:04:27 +03:00
|
|
|
// FIXME: This data structure is very clunky and unpleasant. Replace it with something nicer.
|
2018-10-10 12:53:07 +03:00
|
|
|
struct DirectoryEntry {
|
2019-07-03 22:17:35 +03:00
|
|
|
DirectoryEntry(const char* name, InodeIdentifier, u8 file_type);
|
2019-12-09 19:45:40 +03:00
|
|
|
DirectoryEntry(const char* name, size_t name_length, InodeIdentifier, u8 file_type);
|
2018-11-13 02:17:30 +03:00
|
|
|
char name[256];
|
2019-12-09 19:45:40 +03:00
|
|
|
size_t name_length { 0 };
|
2018-10-10 12:53:07 +03:00
|
|
|
InodeIdentifier inode;
|
2019-07-03 22:17:35 +03:00
|
|
|
u8 file_type { 0 };
|
2018-10-10 12:53:07 +03:00
|
|
|
};
|
|
|
|
|
2020-05-26 10:35:11 +03:00
|
|
|
virtual void flush_writes() { }
|
2019-04-25 23:05:53 +03:00
|
|
|
|
2020-05-18 21:46:47 +03:00
|
|
|
size_t block_size() const { return m_block_size; }
|
2019-08-11 11:09:36 +03:00
|
|
|
|
2020-04-06 11:54:21 +03:00
|
|
|
virtual bool is_file_backed() const { return false; }
|
2019-08-17 12:17:36 +03:00
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
protected:
|
2018-11-15 19:13:10 +03:00
|
|
|
FS();
|
2018-10-10 12:53:07 +03:00
|
|
|
|
2020-05-18 21:46:47 +03:00
|
|
|
void set_block_size(size_t);
|
2019-08-11 11:09:36 +03:00
|
|
|
|
2019-05-02 04:28:20 +03:00
|
|
|
mutable Lock m_lock { "FS" };
|
2019-02-28 23:51:59 +03:00
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
private:
|
2019-01-23 07:38:54 +03:00
|
|
|
unsigned m_fsid { 0 };
|
2020-05-18 21:46:47 +03:00
|
|
|
size_t m_block_size { 0 };
|
2018-12-19 23:56:45 +03:00
|
|
|
bool m_readonly { false };
|
2018-10-10 12:53:07 +03:00
|
|
|
};
|
|
|
|
|
2018-12-03 02:20:00 +03:00
|
|
|
inline FS* InodeIdentifier::fs()
|
2018-10-10 12:53:07 +03:00
|
|
|
{
|
2018-12-03 02:20:00 +03:00
|
|
|
return FS::from_fsid(m_fsid);
|
2018-10-10 12:53:07 +03:00
|
|
|
}
|
|
|
|
|
2018-12-03 02:20:00 +03:00
|
|
|
inline const FS* InodeIdentifier::fs() const
|
2018-10-10 12:53:07 +03:00
|
|
|
{
|
2018-12-03 02:20:00 +03:00
|
|
|
return FS::from_fsid(m_fsid);
|
2018-10-10 12:53:07 +03:00
|
|
|
}
|
|
|
|
|
2020-02-16 03:27:42 +03:00
|
|
|
}
|
|
|
|
|
2018-10-10 12:53:07 +03:00
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
template<>
|
2020-02-16 03:27:42 +03:00
|
|
|
struct Traits<Kernel::InodeIdentifier> : public GenericTraits<Kernel::InodeIdentifier> {
|
|
|
|
static unsigned hash(const Kernel::InodeIdentifier& inode) { return pair_int_hash(inode.fsid(), inode.index()); }
|
2018-10-10 12:53:07 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|