From 882e74b2191c059a9226cbd8bcb51c97da36247c Mon Sep 17 00:00:00 2001 From: Benji Dial Date: Fri, 12 Jan 2024 20:39:21 -0500 Subject: rewrite file system layer --- include/mercury/kernel/vfile.hpp | 62 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 include/mercury/kernel/vfile.hpp (limited to 'include/mercury/kernel/vfile.hpp') diff --git a/include/mercury/kernel/vfile.hpp b/include/mercury/kernel/vfile.hpp new file mode 100644 index 0000000..43dff96 --- /dev/null +++ b/include/mercury/kernel/vfile.hpp @@ -0,0 +1,62 @@ +#ifndef MERCURY_KERNEL_VFILE_HPP +#define MERCURY_KERNEL_VFILE_HPP + +#include +#include + +//TODO: mounts points. +//maybe a two-way map between mount points and targets? one mount point per +//target and vice versa. only directories may be mount points, and only file +//system roots (which must be directories) may be targets. + +namespace mercury::kernel::vfile { + + //a canon path contains no . or empty directory names, and + //contains no .. except for at the start of a relative path. + struct canon_path { + + bool absolute; + unsigned parent_count; + utility::vector segments; + + canon_path() : absolute(false), parent_count(0), segments(8) {} + + void parent(); + void rel(const canon_path &r); + + utility::string to_string(bool trailing_slash) const; + + }; + + void canonize_path(const utility::string &name, canon_path &out); + + struct vfile { + + //on followed symlinks, path is the source of the symlink and the + //rest of these are the target. in any case, path should be absolute. + canon_path path; + storage::block_device *bd; + storage::dir_entry dir_entry; + + //TODO: instead of passing root, use saved mount points. + storage::fs_result follow_symlinks( + const vfile &root, std::optional &out) const; + + //dir_entry.type is assumed to be directory. + storage::fs_result get_child( + std::optional &out, const utility::string &name) const; + //dir_entry.type is assumed to be directory. out must be empty on entry. + storage::fs_result get_children(utility::vector &out) const; + + }; + + //path must be absolute. follows symlinks on all but the last node. + //relative_to should be a directory to do the lookup inside; e.g., + //if relative_to is /a/b and path is c, then out becomes /a/b/c. + //TODO: instead of passing root, use saved mount points. + storage::fs_result lookup_path( + const vfile &root, const canon_path &path, std::optional &out); + +} + +#endif -- cgit v1.2.3