[6s] Allow 6s to know about filesystems

Added a j6_proto_vfs_tag/_get_tag pair of messages to the VFS protocol
to allow filesystems to label themselves, and gave 6s the concept of
current fs and current working directory.
This commit is contained in:
Justin C. Miller
2024-04-30 22:23:04 -07:00
parent 29332cbd45
commit eb62588b79
10 changed files with 195 additions and 43 deletions

View File

@@ -8,4 +8,6 @@ enum j6_proto_vfs_tag
{
j6_proto_vfs_load = j6_proto_base_first_proto_id,
j6_proto_vfs_file,
};
j6_proto_vfs_get_tag,
j6_proto_vfs_tag,
};

View File

@@ -13,7 +13,13 @@ class API client
public:
/// Constructor.
/// \arg vfs_mb Handle to the VFS service's mailbox
client(j6_handle_t vfs_mb);
client(j6_handle_t vfs_mb = 0);
/// Copy constructor
client(const client& c);
/// Check if this client's handle is valid
inline bool valid() const { return m_service != j6_handle_invalid; }
/// Load a file into a VMA
/// \arg path Path of the file to load
@@ -21,8 +27,13 @@ public:
/// \arg size [out] Size of the file
j6_status_t load_file(char *path, j6_handle_t &vma, size_t &size);
/// Get fs tag
/// \arg tag [out] The filesystem's tag
/// \arg size [inout] Size of the input buffer, length of the returned string
j6_status_t get_tag(char *tag, size_t &len);
private:
j6_handle_t m_service;
};
} // namespace j6::proto::vfs
} // namespace j6::proto::vfs

View File

@@ -1,3 +1,4 @@
#include "j6/types.h"
#include <j6/errors.h>
#include <j6/protocols/vfs.hh>
#include <j6/syscalls.h>
@@ -12,6 +13,11 @@ client::client(j6_handle_t vfs_mb) :
{
}
client::client(const client& c) :
m_service {c.m_service}
{
}
inline size_t simple_strlen(const char *s) { size_t n = 0; while (s && *s) s++, n++; return n; }
j6_status_t
@@ -61,5 +67,31 @@ client::load_file(char *path, j6_handle_t &vma, size_t &size)
}
j6_status_t
client::get_tag(char *tag, size_t &len)
{
if (len < sizeof(j6_status_t))
return j6_err_insufficient;
uint64_t message_tag = j6_proto_vfs_get_tag;
size_t handle_count = 0;
size_t in_len = 0;
j6_status_t s = j6_mailbox_call(m_service, &message_tag,
tag, &in_len, len, nullptr, &handle_count, 0);
if (s != j6_status_ok)
return s;
if (message_tag == j6_proto_base_status)
return *reinterpret_cast<j6_status_t*>(tag); // contains a status
if (message_tag != j6_proto_vfs_tag)
return j6_err_unexpected;
len = in_len;
return j6_status_ok; // data is now in `tag` and `len`
}
} // namespace j6::proto::vfs
#endif // __j6kernel