/* * This source code is released into the public domain. */ module; #include #include #include export module liblfvm:disk_config; import nihil; import nihil.ucl; import :context; namespace lfvm { /* * Represents a disk which can be attached to the VM. */ export struct disk_config { /* * The name of this disk. The name is arbitrary, it doesn't need * to match the filename. */ [[nodiscard]] auto name(this disk_config const &) -> std::string_view; /* * The on-disk filename of this disk. This is verified to exist * at creation time, but it may not exist later, e.g. if the user * deletes the file. */ [[nodiscard]] auto path(this disk_config const &) -> std::filesystem::path const &; /* * Check if the disk's backing file exists. */ [[nodiscard]] auto exists(this disk_config const &) -> bool; /* * Serialize a disk to a UCL string. */ [[nodiscard]] auto serialize(this disk_config const &) -> std::expected; /* * Deserialize a UCL string into a disk. */ [[nodiscard]] static auto deserialize(std::string_view) -> std::expected; private: friend auto make_disk_config(std::string_view, std::string_view) -> std::expected; disk_config(std::string_view name, std::filesystem::path path); std::string m_name; std::filesystem::path m_path; }; /* * Create a new disk from a name and path. */ export [[nodiscard]] auto make_disk_config(std::string_view name, std::string_view path) -> std::expected; /* * Load an existing disk. */ export [[nodiscard]] auto disk_load(context const &, std::string_view name) -> std::expected; /* * Save a new disk. */ export [[nodiscard]] auto disk_create(context const &, disk_config const &) -> std::expected; /* * Save an existing disk. */ export [[nodiscard]] auto disk_save(context const &, disk_config const &) -> std::expected; /* * List existing disks. */ export [[nodiscard]] auto disk_list(context const &) -> std::expected, nihil::error>; } // namespace lfvm