master
h 274 lines 5.93 KB
Raw
1 // Copyright (C) Microsoft Corporation. All rights reserved.
2 #pragma once
3
4 namespace p9fs {
5
6 constexpr std::string_view ProtocolVersionL{"9P2000.L"};
7 constexpr std::string_view ProtocolVersionW{"9P2000.W"};
8
9 // The plan9 message type. Messages starting with T are request messages, and
10 // messages starting with R are response messages. The response message is always
11 // one plus the request message.
12 enum class MessageType : UINT8
13 {
14 Tlerror = 6,
15 Rlerror,
16 Tstatfs = 8,
17 Rstatfs,
18 Tlopen = 12,
19 Rlopen,
20 Tlcreate = 14,
21 Rlcreate,
22 Tsymlink = 16,
23 Rsymlink,
24 Tmknod = 18,
25 Rmknod,
26 Trename = 20,
27 Rrename,
28 Treadlink = 22,
29 Rreadlink,
30 Tgetattr = 24,
31 Rgetattr,
32 Tsetattr = 26,
33 Rsetattr,
34 Txattrwalk = 30,
35 Rxattrwalk,
36 Txattrcreate = 32,
37 Rxattrcreate,
38 Treaddir = 40,
39 Rreaddir,
40 Tfsync = 50,
41 Rfsync,
42 Tlock = 52,
43 Rlock,
44 Tgetlock = 54,
45 Rgetlock,
46 Tlink = 70,
47 Rlink,
48 Tmkdir = 72,
49 Rmkdir,
50 Trenameat = 74,
51 Rrenameat,
52 Tunlinkat = 76,
53 Runlinkat,
54 Tversion = 100,
55 Rversion,
56 Tauth = 102,
57 Rauth,
58 Tattach = 104,
59 Rattach,
60 Terror = 106,
61 Rerror,
62 Tflush = 108,
63 Rflush,
64 Twalk = 110,
65 Rwalk,
66 Topen = 112,
67 Ropen,
68 Tcreate = 114,
69 Rcreate,
70 Tread = 116,
71 Rread,
72 Twrite = 118,
73 Rwrite,
74 Tclunk = 120,
75 Rclunk,
76 Tremove = 122,
77 Rremove,
78 Tstat = 124,
79 Rstat,
80 Twstat = 126,
81 Rwstat,
82 // 9P2000.W messages:
83 // N.B. 9P2000.W is a currently unofficial extension to 9P2000.L which includes some messages
84 // used by the Windows Plan 9 redirector for improved functionality and performance.
85 Taccess = 128,
86 Raccess,
87 Twreaddir = 130,
88 Rwreaddir,
89 Twopen = 132,
90 Rwopen
91 };
92
93 // The type of the file, as indicated in a Qid.
94 enum class QidType : UINT8
95 {
96 File = 0x00,
97 Link = 0x01,
98 Symlink = 0x02,
99 Temp = 0x04,
100 Auth = 0x08,
101 MountPoint = 0x10,
102 Exclusive = 0x20,
103 Append = 0x40,
104 Directory = 0x80
105 };
106
107 DEFINE_ENUM_FLAG_OPERATORS(QidType);
108
109 // A type representing a unique file identifier. On Linux, the path is used as
110 // the inode number.
111 struct Qid
112 {
113 UINT64 Path;
114 UINT32 Version;
115 QidType Type;
116 };
117
118 // File system attributes, used in statfs
119 struct StatFsResult
120 {
121 UINT32 Type;
122 UINT32 BlockSize;
123 UINT64 Blocks;
124 UINT64 BlocksFree;
125 UINT64 BlocksAvailable;
126 UINT64 Files;
127 UINT64 FilesFree;
128 UINT64 FsId;
129 UINT32 NameLength;
130 };
131
132 // Linux file attributes, used in getattr and setattr.
133 struct StatResult
134 {
135 UINT32 Mode;
136 UINT32 Uid;
137 UINT32 Gid;
138 UINT64 NLink;
139 UINT64 RDev;
140 UINT64 Size;
141 UINT64 BlockSize;
142 UINT64 Blocks;
143 UINT64 AtimeSec;
144 UINT64 AtimeNsec;
145 UINT64 MtimeSec;
146 UINT64 MtimeNsec;
147 UINT64 CtimeSec;
148 UINT64 CtimeNsec;
149 };
150
151 // Wire size of the StatResult structure.
152 // N.B. Can't use sizeof(StatResult) because it contains padding.
153 constexpr UINT32 StatResultSize = (3 * sizeof(UINT32)) + (11 * sizeof(UINT64));
154
155 constexpr UINT32 TagOffset = sizeof(UINT32) + sizeof(UINT8);
156 constexpr UINT32 HeaderSize = sizeof(UINT32) + sizeof(UINT8) + sizeof(UINT16);
157 constexpr UINT32 QidSize = sizeof(UINT8) + sizeof(UINT32) + sizeof(UINT64);
158 constexpr UINT32 NoFid = ~0u;
159
160 // The "diod" server requires the max IO buffer to be at least 24 bytes smaller than the negotiated
161 // message size. While our Plan 9 server does not require it, it's used just in case.
162 constexpr UINT32 IoHeaderSize = 24;
163
164 // High bits for file modes. The low bits are used
165 // for permission bits.
166 constexpr UINT32 ModeDirectory = 040000;
167 constexpr UINT32 ModeRegularFile = 0100000;
168
169 // Bitmask of valid attributes for getattr requests.
170 constexpr UINT32 GetAttrMode = 0x1;
171 constexpr UINT32 GetAttrNlink = 0x2;
172 constexpr UINT32 GetAttrUid = 0x4;
173 constexpr UINT32 GetAttrGid = 0x8;
174 constexpr UINT32 GetAttrRdev = 0x10;
175 constexpr UINT32 GetAttrAtime = 0x20;
176 constexpr UINT32 GetAttrMtime = 0x40;
177 constexpr UINT32 GetAttrCtime = 0x80;
178 constexpr UINT32 GetAttrIno = 0x100;
179 constexpr UINT32 GetAttrSize = 0x200;
180 constexpr UINT32 GetAttrBlocks = 0x400;
181 constexpr UINT32 GetAttrBtime = 0x800;
182 constexpr UINT32 GetAttrGen = 0x1000;
183 constexpr UINT32 GetAttrDataVersion = 0x2000;
184
185 // Bitmask of valid attributes for setattr requests.
186 constexpr UINT32 SetAttrMode = 0x1;
187 constexpr UINT32 SetAttrUid = 0x2;
188 constexpr UINT32 SetAttrGid = 0x4;
189 constexpr UINT32 SetAttrSize = 0x8;
190 constexpr UINT32 SetAttrAtime = 0x10;
191 constexpr UINT32 SetAttrMtime = 0x20;
192 constexpr UINT32 SetAttrCtime = 0x40;
193 constexpr UINT32 SetAttrAtimeSet = 0x80;
194 constexpr UINT32 SetAttrMtimeSet = 0x100;
195
196 // Flags for the lopen and create messages.
197 // N.B. These may not be identical to Linux open flags on all platforms.
198 enum class OpenFlags
199 {
200 ReadOnly = 0,
201 WriteOnly = 01,
202 ReadWrite = 02,
203 NoAccess = 03,
204 AccessMask = 03,
205 Create = 0100,
206 Exclusive = 0200,
207 NoCTTY = 0400,
208 Truncate = 01000,
209 Append = 02000,
210 NonBlock = 04000,
211 DSync = 010000,
212 FAsync = 00020000,
213 Direct = 00040000,
214 LargeFile = 00100000,
215 Directory = 0200000,
216 NoFollow = 00400000,
217 NoAccessTime = 01000000,
218 CloseOnExec = 02000000,
219 Sync = 04000000
220 };
221
222 DEFINE_ENUM_FLAG_OPERATORS(OpenFlags);
223
224 // File lock types
225 enum class LockType
226 {
227 ReadLock,
228 WriteLock,
229 Unlock
230 };
231
232 // Status values returned by the lock message.
233 enum class LockStatus
234 {
235 Success,
236 Blocked,
237 Error,
238 Grace
239 };
240
241 enum class AccessFlags
242 {
243 Ok = 0,
244 Execute = 1,
245 Write = 2,
246 Read = 4,
247 Delete = 8,
248 All = Execute | Write | Read | Delete
249 };
250
251 DEFINE_ENUM_FLAG_OPERATORS(AccessFlags);
252
253 // Flags for the wopen message.
254 enum class WOpenFlags
255 {
256 None = 0,
257 DeleteAccess = 0x1,
258 NonDirectoryFile = 0x2,
259 OpenSymlink = 0x4,
260 };
261
262 DEFINE_ENUM_FLAG_OPERATORS(WOpenFlags);
263
264 // Status values returned by the wopen message.
265 enum class WOpenStatus : UINT8
266 {
267 Opened,
268 Created,
269 ParentNotFound,
270 NotFound,
271 Stopped,
272 };
273
274 } // namespace p9fs