summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/mercury/kernel/fs/tarfs.hpp15
-rw-r--r--include/mercury/kernel/storage.hpp19
-rw-r--r--include/mercury/kernel/utility.hpp21
3 files changed, 42 insertions, 13 deletions
diff --git a/include/mercury/kernel/fs/tarfs.hpp b/include/mercury/kernel/fs/tarfs.hpp
index 41773ee..64ee481 100644
--- a/include/mercury/kernel/fs/tarfs.hpp
+++ b/include/mercury/kernel/fs/tarfs.hpp
@@ -12,9 +12,9 @@ namespace mercury::kernel::fs {
storage::io_result next_node(storage::node_id_t &node);
//name_buf must be at least 255 chars long.
- storage::io_result read_name(storage::node_id_t node, char *name_buf, size_t &name_len_out);
+ storage::io_result read_name(storage::node_id_t node, char *name_buf, unsigned &name_len_out);
//len <= 12
- storage::io_result read_num(uint64_t offset, size_t len, uint64_t &out);
+ storage::io_result read_num(uint64_t offset, unsigned len, uint64_t &out);
public:
tarfs_instance(storage::block_device *bd);
@@ -25,11 +25,16 @@ namespace mercury::kernel::fs {
storage::io_result get_next_child(
storage::node_id_t node, storage::node_id_t &out, storage::directory_iter_t &iter) override;
storage::io_result get_child(
- storage::node_id_t node, storage::node_id_t &out, const char *name, size_t name_len) override;
- storage::io_result get_name_length(storage::node_id_t node, size_t &length_out) override;
- storage::io_result get_name(storage::node_id_t node, char *buffer, size_t &length_out) override;
+ storage::node_id_t node, storage::node_id_t &out, const char *name, unsigned name_len) override;
+ storage::io_result get_name_length(storage::node_id_t node, unsigned &length_out) override;
+ storage::io_result get_name(storage::node_id_t node, char *buffer, unsigned &length_out) override;
storage::io_result get_file_length(storage::node_id_t node, uint64_t &length_out) override;
storage::io_result get_file_type(storage::node_id_t node, storage::file_type &out) override;
+ storage::io_result resize_file(storage::node_id_t node, uint64_t new_length) override;
+ storage::io_result read_bytes_from_file(
+ storage::node_id_t node, uint64_t start, uint64_t count, void *into) override;
+ storage::io_result write_bytes_into_file(
+ storage::node_id_t node, uint64_t start, uint64_t count, const void *from) override;
};
diff --git a/include/mercury/kernel/storage.hpp b/include/mercury/kernel/storage.hpp
index 1374766..0df0829 100644
--- a/include/mercury/kernel/storage.hpp
+++ b/include/mercury/kernel/storage.hpp
@@ -38,19 +38,22 @@ namespace mercury::kernel::storage {
//first child of this node. get_next_child gets the child after the child
//represented by the value of iter passed in, and changes iter to represent
//that next child. for an empty directory node, get_first_child returns
- //io_result::out_of_bounds. when iter represents the last child of a node,
- //get_next_child also returns io_result::out_of_bounds.
+ //io_result::not_found. when iter represents the last child of a node,
+ //get_next_child also returns io_result::not_found.
virtual io_result get_first_child(node_id_t node, node_id_t &out, directory_iter_t &iter_out) = 0;
virtual io_result get_next_child(node_id_t node, node_id_t &out, directory_iter_t &iter) = 0;
- virtual io_result get_child(node_id_t node, node_id_t &out, const char *name, size_t name_len) = 0;
+ virtual io_result get_child(node_id_t node, node_id_t &out, const char *name, unsigned name_len) = 0;
- virtual io_result get_name_length(node_id_t node, size_t &length_out) = 0;
+ virtual io_result get_name_length(node_id_t node, unsigned &length_out) = 0;
//buffer is assumed to be long enough - call get_name_length first.
- virtual io_result get_name(node_id_t node, char *buffer, size_t &length_out) = 0;
-
+ virtual io_result get_name(node_id_t node, char *buffer, unsigned &length_out) = 0;
virtual io_result get_file_length(node_id_t node, uint64_t &length_out) = 0;
-
virtual io_result get_file_type(node_id_t node, file_type &out) = 0;
+
+ virtual io_result resize_file(node_id_t node, uint64_t new_length) = 0;
+ virtual io_result read_bytes_from_file(node_id_t node, uint64_t start, uint64_t count, void *into) = 0;
+ virtual io_result write_bytes_into_file(node_id_t node, uint64_t start, uint64_t count, const void *from) = 0;
+
};
class block_device {
@@ -112,7 +115,7 @@ namespace mercury::kernel::storage {
};
- void canonize_path(const char *str, size_t len, canon_path &out);
+ void canonize_path(const char *str, unsigned len, canon_path &out);
//path must be absolute.
io_result mount_device(block_device *bd, const canon_path &path, file_system_mounter mounter);
diff --git a/include/mercury/kernel/utility.hpp b/include/mercury/kernel/utility.hpp
index f12101a..1648e67 100644
--- a/include/mercury/kernel/utility.hpp
+++ b/include/mercury/kernel/utility.hpp
@@ -29,6 +29,27 @@ namespace mercury::kernel::utility {
return len;
}
+ //if c appears in str, this returns the index of the last time it appears.
+ //otherwise, this returns len.
+ static inline unsigned find_last(const char *str, unsigned len, char c) {
+ for (unsigned i = len; i > 0; --i)
+ if (str[i - 1] == c)
+ return i - 1;
+ return len;
+ }
+
+ //str1 starts with str2
+ static inline bool starts_with(
+ const char *str1, unsigned str1_len, const char *str2, unsigned str2_len
+ ) {
+ if (str1_len < str2_len)
+ return false;
+ for (unsigned i = 0; i < str2_len; ++i)
+ if (str1[i] != str2[i])
+ return false;
+ return true;
+ }
+
template <class value_t>
struct list {