hyperv_ic_protocol/
vss.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4//! Protocol definitions for the VSS (Volume Shadow Service) IC.
5
6#![allow(missing_docs)]
7
8use crate::Version;
9use guid::Guid;
10use open_enum::open_enum;
11use zerocopy::FromBytes;
12use zerocopy::Immutable;
13use zerocopy::IntoBytes;
14use zerocopy::KnownLayout;
15
16pub const VSS_VERSION_WIN8: Version = Version::new(4, 0);
17pub const VSS_VERSION_WINBLUE: Version = Version::new(5, 0);
18pub const VSS_VERSION_THRESHOLD: Version = Version::new(6, 0);
19pub const VSS_VERSION_THRESHOLD_UR1: Version = Version::new(7, 0);
20
21pub const MAX_VHD_COUNT: usize = 260;
22
23#[repr(C)]
24#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
25pub struct VssMessage {
26    pub header: VssHeader,
27    pub reserved: [u8; 7],
28    pub data: [u8; 24],
29}
30
31#[repr(C)]
32#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
33pub struct VssHeader {
34    pub operation: Operation,
35    pub reserved: [u8; 7],
36}
37
38open_enum! {
39    #[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
40    pub enum Operation: u8 {
41        CREATE = 0,
42        DELETE = 1,
43        CHECK_HOT_BACKUP = 2,
44        GET_DIRECT_MAPPED_DEVICES_INFO = 3,
45        // Messages below this are only valid for message version >= 4.0
46        BACKUP_COMPLETE = 4,
47        // Messages below this are only valid for message version >= 5.0
48        FREEZE_APPLICATIONS = 5,
49        THAW_APPLICATIONS = 6,
50        AUTO_RECOVER = 7,
51        // Messages below this are only valid for message version >= 6.0
52        QUERY_GUEST_CLUSTER_INFORMATION = 8,
53    }
54}
55
56#[repr(C)]
57#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
58pub struct MessageCheckHotBackup {
59    pub flags: u32,
60}
61
62#[repr(C)]
63#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
64pub struct MessageCreate {
65    pub snapshot_set_id: Guid,
66}
67
68#[repr(C)]
69#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
70pub struct MessageCreateV2 {
71    pub snapshot_set_id: Guid,
72    pub backup_type: u32,
73}
74
75#[repr(C)]
76#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
77pub struct MessageDelete {
78    pub snapshot_set_id: Guid,
79}
80
81#[repr(C)]
82#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
83pub struct MessageDirectMappedDevicesInfo {
84    pub flags: u32,
85}
86
87#[repr(C)]
88#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
89pub struct MessageCheckHotBackupComplete {
90    pub flags: u32,
91}
92
93#[repr(C)]
94#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
95pub struct MessageThawApplications {
96    pub flags: u32,
97}
98
99/// For freeze and autorecover.
100#[repr(C)]
101#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
102pub struct Message2 {
103    pub header: VssHeader,
104    pub backup_type: u32,
105    pub flags: u32,
106    pub lun_count: u32,
107    pub luns: [LunInfo; MAX_VHD_COUNT],
108}
109
110#[repr(C)]
111#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
112pub struct Message2Ex {
113    pub header: VssHeader,
114    pub backup_type: u32,
115    pub flags: u32,
116    pub lun_count: u32,
117    pub luns: [LunInfo; MAX_VHD_COUNT],
118    pub shadow_luns: [LunInfo; MAX_VHD_COUNT],
119}
120
121#[repr(C)]
122#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
123pub struct Message3 {
124    pub header: VssHeader,
125    pub cluster_id: Guid,
126    pub cluster_size: u32,
127    pub lun_count: u32,
128    pub shared_luns: [LunInfo; MAX_VHD_COUNT],
129    pub shared_lun_status: [u32; MAX_VHD_COUNT],
130}
131
132#[repr(C)]
133#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
134pub struct Message3Ex {
135    pub header: VssHeader,
136    pub cluster_id: Guid,
137    pub cluster_size: u32,
138    pub lun_count: u32,
139    pub shared_luns: [LunInfo; MAX_VHD_COUNT],
140    pub shared_lun_status: [u32; MAX_VHD_COUNT],
141    pub last_move_time: u64,
142}
143
144#[repr(C)]
145#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
146pub struct LunInfo {
147    pub bus_type: u8,
148    pub reserved: [u8; 3],
149    pub controller: Guid,
150    pub port: u8,
151    pub target: u8,
152    pub lun: u8,
153    pub reserved2: u8,
154}