-
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.
- Loading branch information
Showing
13 changed files
with
242 additions
and
505 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
53 changes: 0 additions & 53 deletions
53
common/include/common/filesystem/filesystem_mount_points.hpp
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,5 +1,6 @@ | ||
module; | ||
/** | ||
* file_descriptors.hpp | ||
* filesystem.cpp2 | ||
* | ||
* Copyright (C) 2024 Mateusz Stadnik <[email protected]> | ||
* | ||
|
@@ -18,26 +19,17 @@ | |
* <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
export module yasboot.filesystem; | ||
|
||
#include <bitset> | ||
#include <cstdint> | ||
yasboot: namespace = { | ||
fs: namespace = { | ||
|
||
namespace yasboot::fs | ||
{ | ||
export FileSystem: @interface type = { | ||
mount: (inout this) -> std::expected<void, i32>; | ||
open: (inout this, path: std::string_view, flags: i32) -> std::expected<i8, i8>; | ||
has_fd: (this, fd: i32) -> bool; | ||
read_file: (inout this, fd: i32, buffer: std::span<u8>) -> i32; | ||
} | ||
|
||
class FileDescriptors | ||
{ | ||
public: | ||
static FileDescriptors &get(); | ||
|
||
int8_t allocate(); | ||
void release(int8_t fd); | ||
|
||
private: | ||
FileDescriptors(); | ||
|
||
std::bitset<8> file_descriptors_; | ||
}; | ||
|
||
} // namespace yasboot::fs | ||
} // namespace fs | ||
} // namespace yasboot |
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,92 @@ | ||
module; | ||
/** | ||
* filesystem_mount_points.cpp | ||
* | ||
* Copyright (C) 2024 Mateusz Stadnik <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation, either version | ||
* 3 of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be | ||
* useful, but WITHOUT ANY WARRANTY; without even the implied | ||
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR | ||
* PURPOSE. See the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General | ||
* Public License along with this program. If not, see | ||
* <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include <map> | ||
#include <memory> | ||
#include <string> | ||
#include <string_view> | ||
#include <utility> | ||
|
||
export module yasboot.filesystem.filesystem_mount_points; | ||
|
||
import yasboot.filesystem; | ||
|
||
export namespace yasboot::fs { | ||
class FileSystemMountPoints { | ||
public: | ||
using MountPoints = std::map<std::string, std::unique_ptr<FileSystem>>; | ||
|
||
int register_mount_point(std::string_view path, | ||
std::unique_ptr<FileSystem> filesystem); | ||
|
||
std::pair<FileSystem *, std::string_view> | ||
get_mount_point(std::string_view pathname); | ||
|
||
const FileSystem *get_filesystem_for_fd(int fd) const; | ||
|
||
static FileSystemMountPoints &get(); | ||
|
||
private: | ||
FileSystemMountPoints() = default; | ||
MountPoints mount_points_; | ||
}; | ||
|
||
} // namespace yasboot::fs | ||
|
||
namespace yasboot::fs { | ||
|
||
int FileSystemMountPoints::register_mount_point( | ||
std::string_view path, std::unique_ptr<FileSystem> filesystem) { | ||
if (mount_points_.count(std::string(path))) { | ||
return -1; | ||
} | ||
|
||
mount_points_.emplace(std::string(path), std::move(filesystem)); | ||
return 0; | ||
} | ||
|
||
FileSystemMountPoints &FileSystemMountPoints::get() { | ||
static FileSystemMountPoints instance; | ||
return instance; | ||
} | ||
|
||
std::pair<FileSystem *, std::string_view> | ||
FileSystemMountPoints::get_mount_point(std::string_view pathname) { | ||
std::pair<FileSystem *, std::string_view> result{}; | ||
for (const auto &[path, filesystem] : mount_points_) { | ||
if (pathname.starts_with(path) && path.size() > result.second.size()) { | ||
result = std::make_pair(filesystem.get(), pathname.substr(path.size())); | ||
} | ||
} | ||
|
||
return result; | ||
} | ||
|
||
const FileSystem *FileSystemMountPoints::get_filesystem_for_fd(int fd) const { | ||
for (const auto &[path, fs] : mount_points_) { | ||
if (fs->has_fd(fd)) { | ||
return fs.get(); | ||
} | ||
} | ||
return nullptr; | ||
} | ||
|
||
} // namespace yasboot::fs |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.