vmgs_resources/
lib.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Resources for VMGS files.
5
6#![forbid(unsafe_code)]
7
8use mesh::MeshPayload;
9use vm_resource::Resource;
10use vm_resource::ResourceId;
11use vm_resource::kind::DiskHandleKind;
12use vm_resource::kind::NonVolatileStoreKind;
13use vmgs_format::FileId;
14
15/// A handle to an individual file within a VMGS file.
16#[derive(MeshPayload)]
17pub struct VmgsFileHandle {
18    /// The file ID.
19    ///
20    /// FUTURE: figure out how to give this the nice type.
21    pub file_id: u32,
22    /// Whether the file is encrypted.
23    pub encrypted: bool,
24}
25
26impl VmgsFileHandle {
27    /// Returns a new handle to the given file.
28    pub fn new(file_id: FileId, encrypted: bool) -> Self {
29        Self {
30            file_id: file_id.0,
31            encrypted,
32        }
33    }
34}
35
36impl ResourceId<NonVolatileStoreKind> for VmgsFileHandle {
37    const ID: &'static str = "vmgs";
38}
39
40/// Virtual machine guest state resource
41#[derive(MeshPayload, Debug)]
42pub enum VmgsResource {
43    /// Use disk to store guest state
44    Disk(Resource<DiskHandleKind>),
45    /// Use disk to store guest state, reformatting if corrupted.
46    ReprovisionOnFailure(Resource<DiskHandleKind>),
47    /// Format and use disk to store guest state
48    Reprovision(Resource<DiskHandleKind>),
49    /// Store guest state in memory
50    Ephemeral,
51}