vmbfs/
protocol.rs

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4#![allow(dead_code)]
5
6use bitfield_struct::bitfield;
7use guid::Guid;
8use open_enum::open_enum;
9use zerocopy::FromBytes;
10use zerocopy::Immutable;
11use zerocopy::IntoBytes;
12use zerocopy::KnownLayout;
13use zerocopy::little_endian::U64 as u64_le;
14
15pub const INTERFACE_TYPE: Guid = guid::guid!("c376c1c3-d276-48d2-90a9-c04748072c60");
16pub const IMC_INSTANCE: Guid = guid::guid!("c4e5e7d1-d748-4afc-979d-683167910a55");
17pub const _BOOT_INSTANCE: Guid = guid::guid!("c63c9bdf-5fa5-4208-b03f-6b458b365592");
18
19pub const MAX_MESSAGE_SIZE: usize = 12288;
20pub const MAX_READ_SIZE: usize =
21    MAX_MESSAGE_SIZE - size_of::<MessageHeader>() - size_of::<ReadFileResponse>();
22
23open_enum! {
24    #[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
25    pub enum Version: u32 {
26        WIN10 = 0x00010000,
27    }
28}
29
30open_enum! {
31    #[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
32    pub enum MessageType: u32 {
33        INVALID = 0,
34        VERSION_REQUEST = 1,
35        VERSION_RESPONSE = 2,
36        GET_FILE_INFO_REQUEST = 3,
37        GET_FILE_INFO_RESPONSE = 4,
38        READ_FILE_REQUEST = 5,
39        READ_FILE_RESPONSE = 6,
40        READ_FILE_RDMA_REQUEST = 7,
41        READ_FILE_RDMA_RESPONSE = 8,
42    }
43}
44
45#[bitfield(u32)]
46#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
47pub struct FileInfoFlags {
48    pub directory: bool,
49    pub rdma_capable: bool,
50    #[bits(30)]
51    _reserved: u32,
52}
53
54#[repr(C)]
55#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
56pub struct MessageHeader {
57    pub message_type: MessageType,
58    pub reserved: u32,
59}
60
61#[repr(C)]
62#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
63pub struct VersionRequest {
64    pub requested_version: Version,
65}
66
67open_enum! {
68    #[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
69    pub enum VersionStatus: u32 {
70        SUPPORTED = 0,
71        UNSUPPORTED = 1,
72    }
73}
74
75#[repr(C)]
76#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
77pub struct VersionResponse {
78    pub status: VersionStatus,
79}
80
81#[repr(C)]
82#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
83pub struct GetFileInfoRequest {
84    // Followed by a UTF-16 file path.
85}
86
87open_enum! {
88    #[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
89    pub enum Status: u32 {
90        SUCCESS = 0,
91        NOT_FOUND = 1,
92        END_OF_FILE = 2,
93        ERROR = 3,
94    }
95}
96
97#[repr(C)]
98#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
99pub struct GetFileInfoResponse {
100    pub status: Status,
101    pub flags: FileInfoFlags,
102    pub file_size: u64,
103}
104
105#[repr(C)]
106#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
107pub struct ReadFileRequest {
108    pub byte_count: u32,
109    pub offset: u64_le,
110    // Followed by a UTF-16 file path.
111}
112
113#[repr(C)]
114#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
115pub struct ReadFileResponse {
116    pub status: Status,
117    // Followed by the data.
118}
119
120#[repr(C)]
121#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
122pub struct ReadFileRdmaRequest {
123    pub handle: u32,
124    pub byte_count: u32,
125    pub file_offset: u64,
126    pub token_offset: u64,
127    // Followed by a UTF-16 file path.
128}
129
130#[repr(C)]
131#[derive(IntoBytes, Immutable, KnownLayout, FromBytes)]
132pub struct ReadFileRdmaResponse {
133    pub status: Status,
134    pub byte_count: u32,
135}