2024-02-23 21:32:32 +00:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2024 shadPS4 Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2023-11-19 08:22:46 +00:00
|
|
|
#pragma once
|
2024-02-14 22:52:57 +00:00
|
|
|
|
|
|
|
#include <atomic>
|
2023-11-19 08:22:46 +00:00
|
|
|
#include <mutex>
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2024-02-23 21:32:32 +00:00
|
|
|
#include "common/io_file.h"
|
2023-11-19 08:22:46 +00:00
|
|
|
|
|
|
|
namespace Core::FileSys {
|
|
|
|
|
|
|
|
class MntPoints {
|
2024-02-23 20:57:57 +00:00
|
|
|
public:
|
2023-11-19 08:22:46 +00:00
|
|
|
struct MntPair {
|
|
|
|
std::string host_path;
|
2024-02-23 20:57:57 +00:00
|
|
|
std::string guest_path; // e.g /app0/
|
2023-11-19 08:22:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
MntPoints() = default;
|
|
|
|
virtual ~MntPoints() = default;
|
2024-02-27 22:10:34 +00:00
|
|
|
|
|
|
|
void Mount(const std::filesystem::path& host_folder, const std::string& guest_folder);
|
|
|
|
void Unmount(const std::string& path);
|
|
|
|
void UnmountAll();
|
|
|
|
std::string GetHostDirectory(const std::string& guest_directory);
|
|
|
|
std::string GetHostFile(const std::string& guest_file);
|
2023-11-19 08:22:46 +00:00
|
|
|
|
2024-02-23 20:57:57 +00:00
|
|
|
private:
|
2023-11-19 08:22:46 +00:00
|
|
|
std::vector<MntPair> m_mnt_pairs;
|
|
|
|
std::mutex m_mutex;
|
|
|
|
};
|
|
|
|
|
2024-06-20 15:09:40 +00:00
|
|
|
struct DirEntry {
|
|
|
|
std::string name;
|
|
|
|
bool isFile;
|
|
|
|
};
|
|
|
|
|
2023-11-19 08:22:46 +00:00
|
|
|
struct File {
|
2024-02-27 22:10:34 +00:00
|
|
|
std::atomic_bool is_opened{};
|
|
|
|
std::atomic_bool is_directory{};
|
2023-11-19 08:22:46 +00:00
|
|
|
std::string m_host_name;
|
|
|
|
std::string m_guest_name;
|
2024-02-27 22:10:34 +00:00
|
|
|
Common::FS::IOFile f;
|
2024-06-20 15:09:40 +00:00
|
|
|
std::vector<DirEntry> dirents;
|
2023-11-19 08:22:46 +00:00
|
|
|
u32 dirents_index;
|
|
|
|
std::mutex m_mutex;
|
|
|
|
};
|
2024-02-27 22:10:34 +00:00
|
|
|
|
2023-11-19 08:22:46 +00:00
|
|
|
class HandleTable {
|
2024-02-23 20:57:57 +00:00
|
|
|
public:
|
2024-02-27 22:10:34 +00:00
|
|
|
HandleTable() = default;
|
|
|
|
virtual ~HandleTable() = default;
|
|
|
|
|
|
|
|
int CreateHandle();
|
|
|
|
void DeleteHandle(int d);
|
|
|
|
File* GetFile(int d);
|
2023-11-19 08:22:46 +00:00
|
|
|
File* getFile(const std::string& host_name);
|
|
|
|
|
2024-02-23 20:57:57 +00:00
|
|
|
private:
|
2023-11-19 08:22:46 +00:00
|
|
|
std::vector<File*> m_files;
|
|
|
|
std::mutex m_mutex;
|
|
|
|
};
|
|
|
|
|
2024-02-23 20:57:57 +00:00
|
|
|
} // namespace Core::FileSys
|