vmbfs/
protocol.rs

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