1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
|
#!/usr/bin/env python
# lib9p/idl/2010-9P2000.L.9p.gen - Generate definitions of 9P2000.L messages
import sys
print(
f"# lib9p/idl/2010-9P2000.L.9p - Generated by `{' '.join(sys.argv)}`. DO NOT EDIT!"
)
errnos: dict[str, tuple[int, str]] = {}
with open(sys.argv[1], "r", encoding="utf-8") as fh:
for line in fh:
if line.startswith("#"):
print(line)
continue
_num, _name, _desc = line.split(maxsplit=2)
errnos[_name] = (int(_num), _desc.strip())
print(
"""
# lib9p/idl/2010-9P2000.L.9p - Definitions of 9P2000.L messages
#
# Copyright (C) 2024-2025 Luke T. Shumaker <lukeshu@lukeshu.com>
# SPDX-License-Identifier: AGPL-3.0-or-later
# "9P2000.L" Linux extension
# https://github.com/chaos/diod/blob/master/protocol.md
# https://github.com/chaos/diod/blob/master/src/libnpfs/protocol.h
version "9P2000.L"
# low-level types ##############################################################
from ./2002-9P2000.9p import tag, fid, s, qt, qid
from ./2005-9P2000.u.9p import nuid, errno
# BUG: The definitions of errno are not defined in the 9P2000.L
# protocol spec, and Linux kernel errno values vary by architecture.
# Most architectures share a "generic" list, but a handful (as of
# Linux v6.14, Alpha, MIPS, PA-RISC, PowerPC, and SPARC) have their
# own numbers. This IDL file lists the generic numbers.
#
# https://github.com/chaos/diod/issues/35
""".strip()
)
prefix = "num errno += "
namelen = max(len(name) for name in errnos)
numlen = max(len(str(num)) for (num, desc) in errnos.values())
for name, (num, desc) in errnos.items():
print(f'{prefix}"L_{name:<{namelen}} = {num:>{numlen}}" # {desc}')
prefix = " " * len(prefix)
print()
print(
"""
num super_magic = 4
# See <linux/magic.h> (linux.git include/uapi/linux/magic.h).
#
# To quote `util-linux.git:include/statfs_magic.h`:
# "Unfortunately, Linux kernel header file <linux/magic.h> is
# incomplete mess and kernel returns by statfs f_type many numbers
# that are nowhere specified (in API)."
#
# util-linux <statfs_magic.h> is also incomplete. As is the
# statfs(2) man-page.
#
# I'm working on a patchset to the kernel to get <linux/magic.h>
# to be complete, but in the mean-time I'm just not going to
# bother with putting a list here.
#
# TODO
"V9FS_MAGIC=0x01021997"
# "L"inux "O"pen flags (flags to pass to Tlopen and Tlcreate)
#
# The values are not specified in in protocol.md, but are specified in
# protocol.h (and are different than the Linux kernel's values, which
# vary by architecture).
bitfield lo = 4
"bit 0=num(MODE)" # low bit of the 2-bit RDONLY/WRONLY/RDWR/NOACCESS enum
"bit 1=num(MODE)" # high bit of the 2-bit RDONLY/WRONLY/RDWR/NOACCESS enum
#"bit 2=unused"
#"bit 3=unused"
#"bit 4=unused"
#"bit 5=unused"
"bit 6=CREATE"
"bit 7=EXCL"
"bit 8=NOCTTY"
"bit 9=TRUNC"
"bit 10=APPEND"
"bit 11=NONBLOCK"
"bit 12=DSYNC"
"bit 13=BSD_FASYNC"
"bit 14=DIRECT"
"bit 15=LARGEFILE"
"bit 16=DIRECTORY"
"bit 17=NOFOLLOW"
"bit 18=NOATIME"
"bit 19=CLOEXEC"
"bit 20=SYNC"
"num(MODE) RDONLY = 0"
"num(MODE) WRONLY = 1"
"num(MODE) RDWR = 2"
"num(MODE) NOACCESS = 3"
"mask FLAG = 0b111111111111111000000"
# "D"irentry "T"ype
#
# These match the Linux kernel's values.
num dt = 1
"UNKNOWN = 0"
"PIPE = 1"
"CHAR_DEV = 2"
"DIRECTORY = 4"
"BLOCK_DEV = 6" # proof it's not a bitfield
"REGULAR = 8"
"SYMLINK = 10" # proof it's not a bitfield
"SOCKET = 12" # proof it's not a bitfield
"_WHITEOUT = 14" # proof it's not a bitfield
# Mode
#
# These match the Linux kernel's values. Why is this 32-bits wide
# instead of just 16? Who knows?
bitfield mode = 4
#...
"bit 15=num(FMT)" # bit of the 4-bit FMT_ enum
"bit 14=num(FMT)" # bit of the 4-bit FMT_ enum
"bit 13=num(FMT)" # bit of the 4-bit FMT_ enum
"bit 12=num(FMT)" # bit of the 4-bit FMT_ enum
#...
"bit 11=PERM_SETGROUP"
"bit 10=PERM_SETUSER"
"bit 9=PERM_STICKY"
"bit 8=PERM_OWNER_R"
"bit 7=PERM_OWNER_W"
"bit 6=PERM_OWNER_X"
"bit 5=PERM_GROUP_R"
"bit 4=PERM_GROUP_W"
"bit 3=PERM_GROUP_X"
"bit 2=PERM_OTHER_R"
"bit 1=PERM_OTHER_W"
"bit 0=PERM_OTHER_X"
"num(FMT) PIPE = dt.PIPE<<12"
"num(FMT) CHAR_DEV = dt.CHAR_DEV<<12"
"num(FMT) DIRECTORY = dt.DIRECTORY<<12"
"num(FMT) BLOCK_DEV = dt.BLOCK_DEV<<12"
"num(FMT) REGULAR = dt.REGULAR<<12"
"num(FMT) SYMLINK = dt.SYMLINK<<12"
"num(FMT) SOCKET = dt.SOCKET<<12"
"mask PERM = 07777" # PERM_*
# A boolean value that is for some reason 4 bytes wide.
num b4 = 4
"FALSE=0"
"TRUE=1"
# all other values are true also
bitfield getattr = 8
"bit 0=MODE"
"bit 1=NLINK"
"bit 2=UID"
"bit 3=GID"
"bit 4=RDEV"
"bit 5=ATIME"
"bit 6=MTIME"
"bit 7=CTIME"
"bit 8=INO"
"bit 9=SIZE"
"bit 10=BLOCKS"
"bit 11=BTIME"
"bit 12=GEN"
"bit 13=DATA_VERSION"
"alias BASIC=0x000007ff" # Mask for fields up to BLOCKS
"alias ALL =0x00003fff" # Mask for All fields above
bitfield setattr = 4
"bit 0=MODE"
"bit 1=UID"
"bit 2=GID"
"bit 3=SIZE"
"bit 4=ATIME"
"bit 5=MTIME"
"bit 6=CTIME"
"bit 7=ATIME_SET"
"bit 8=MTIME_SET"
num lock_type = 1
"RDLCK=0"
"WRLCK=1"
"UNLCK=2"
bitfield lock_flags = 4
"bit 0=BLOCK"
"bit 1=RECLAIM"
num lock_status = 1
"SUCCESS=0"
"BLOCKED=1"
"ERROR=2"
"GRACE=3"
# 9P2000 Operations (.L subset) ################################################
from ./2002-9P2000.9p import Tversion, Rversion
from ./2002-9P2000.9p import Tflush, Rflush
from ./2002-9P2000.9p import Twalk, Rwalk
from ./2002-9P2000.9p import Tread, Rread, Twrite, Rwrite
from ./2002-9P2000.9p import Tclunk, Rclunk
from ./2002-9P2000.9p import Tremove, Rremove
# 9P2000.u Operations (.L subset) ##############################################
from ./2005-9P2000.u.9p import Tattach, Rattach, Tauth, Rauth
# 9P2000.L Operations ##########################################################
#msg Tlerror = "size[4,val=end-&size] typ[1,val=6] tag[tag] illegal" # analogous to 106/Terror
msg Rlerror = "size[4,val=end-&size] typ[1,val=7] tag[tag] errnum[errno]" # analogous to 107/Rerror
msg Tstatfs = "size[4,val=end-&size] typ[1,val=8] tag[tag] fid[fid]"
msg Rstatfs = "size[4,val=end-&size] typ[1,val=9] tag[tag]" # Description | statfs | statvfs
"type[super_magic]" # Type of filesystem | f_type | -
"bsize[4]" # Block size in bytes | f_bsize | f_bsize
# - # Fragment size in bytes | f_frsize (since Linux 2.6) | f_frsize
"blocks[8]" # Size of FS in f_frsize units | f_blocks | f_blocks
"bfree[8]" # Number of free blocks | f_bfree | f_bfree
"bavail[8]" # Number of free blocks for unprivileged users | f_bavail | b_avail
"files[8]" # Number of inodes | f_files | f_files
"ffree[8]" # Number of free inodes | f_ffree | f_ffree
# - # Number of free inodes for unprivileged users | - | f_favail
"fsid[8]" # Filesystem instance ID | f_fsid | f_fsid
# - # Mount flags | f_flags (since Linux 2.6.36) | f_flag
"namelen[4]" # Maximum filename length | f_namemax | f_namemax
msg Tlopen = "size[4,val=end-&size] typ[1,val=12] tag[tag] fid[fid] flags[lo]" # analogous to 112/Topen
msg Rlopen = "size[4,val=end-&size] typ[1,val=13] tag[tag] qid[qid] iounit[4]" # analogous to 113/Ropen
msg Tlcreate = "size[4,val=end-&size] typ[1,val=14] tag[tag] fid[fid] name[s] flags[lo] mode[mode] gid[nuid]" # analogous to 114/Tcreate
msg Rlcreate = "size[4,val=end-&size] typ[1,val=15] tag[tag] qid[qid] iounit[4]" # analogous to 115/Rcreate
msg Tsymlink = "size[4,val=end-&size] typ[1,val=16] tag[tag] fid[fid] name[s] symtgt[s] gid[nuid]"
msg Rsymlink = "size[4,val=end-&size] typ[1,val=17] tag[tag] qid[qid]"
msg Tmknod = "size[4,val=end-&size] typ[1,val=18] tag[tag] dfid[fid] name[s] mode[mode] major[4] minor[4] gid[nuid]"
msg Rmknod = "size[4,val=end-&size] typ[1,val=19] tag[tag] qid[qid]"
msg Trename = "size[4,val=end-&size] typ[1,val=20] tag[tag] fid[fid] dfid[fid] name[s]"
msg Rrename = "size[4,val=end-&size] typ[1,val=21] tag[tag]"
msg Treadlink = "size[4,val=end-&size] typ[1,val=22] tag[tag] fid[fid]"
msg Rreadlink = "size[4,val=end-&size] typ[1,val=23] tag[tag] target[s]"
msg Tgetattr = "size[4,val=end-&size] typ[1,val=24] tag[tag] fid[fid] request_mask[getattr]"
msg Rgetattr = "size[4,val=end-&size] typ[1,val=25] tag[tag] valid[getattr] qid[qid] mode[mode] uid[nuid] gid[nuid] nlink[8]"
"rdev[8] filesize[8] blksize[8] blocks[8]"
"atime_sec[8] atime_nsec[8] mtime_sec[8] mtime_nsec[8]"
"ctime_sec[8] ctime_nsec[8] btime_sec[8] btime_nsec[8]"
"gen[8] data_version[8]"
msg Tsetattr = "size[4,val=end-&size] typ[1,val=26] tag[tag] fid[fid] valid[setattr] mode[mode] uid[nuid] gid[nuid] filesize[8] atime_sec[8] atime_nsec[8] mtime_sec[8] mtime_nsec[8]"
msg Rsetattr = "size[4,val=end-&size] typ[1,val=27] tag[tag]"
#...
msg Txattrwalk = "size[4,val=end-&size] typ[1,val=30] tag[tag] fid[fid] newfid[fid] name[s]"
msg Rxattrwalk = "size[4,val=end-&size] typ[1,val=31] tag[tag] attr_size[8]"
msg Txattrcreate = "size[4,val=end-&size] typ[1,val=32] tag[tag] fid[fid] name[s] attr_size[8] flags[4]"
msg Rxattrcreate = "size[4,val=end-&size] typ[1,val=33] tag[tag]"
#...
msg Treaddir = "size[4,val=end-&size] typ[1,val=40] tag[tag] fid[fid] offset[8] count[4]"
msg Rreaddir = "size[4,val=end-&size] typ[1,val=41] tag[tag] count[4] count*(data[1])" # data is "qid[qid] offset[8] type[dt] name[s]"
#...
msg Tfsync = "size[4,val=end-&size] typ[1,val=50] tag[tag] fid[fid] datasync[b4]"
msg Rfsync = "size[4,val=end-&size] typ[1,val=51] tag[tag]"
msg Tlock = "size[4,val=end-&size] typ[1,val=52] tag[tag] fid[fid] type[lock_type] flags[lock_flags] start[8] length[8] proc_id[4] client_id[s]"
msg Rlock = "size[4,val=end-&size] typ[1,val=53] tag[tag] status[lock_status]"
msg Tgetlock = "size[4,val=end-&size] typ[1,val=54] tag[tag] fid[fid] type[lock_type] start[8] length[8] proc_id[4] client_id[s]"
msg Rgetlock = "size[4,val=end-&size] typ[1,val=55] tag[tag] type[lock_type] start[8] length[8] proc_id[4] client_id[s]"
# ...
msg Tlink = "size[4,val=end-&size] typ[1,val=70] tag[tag] dfid[fid] fid[fid] name[s]"
msg Rlink = "size[4,val=end-&size] typ[1,val=71] tag[tag]"
msg Tmkdir = "size[4,val=end-&size] typ[1,val=72] tag[tag] dfid[fid] name[s] mode[mode] gid[nuid]"
msg Rmkdir = "size[4,val=end-&size] typ[1,val=73] tag[tag] qid[qid]"
msg Trenameat = "size[4,val=end-&size] typ[1,val=74] tag[tag] olddirfid[fid] oldname[s] newdirfid[fid] newname[s]"
msg Rrenameat = "size[4,val=end-&size] typ[1,val=75] tag[tag]"
msg Tunlinkat = "size[4,val=end-&size] typ[1,val=76] tag[tag] dirfd[fid] name[s] flags[4]"
msg Runlinkat = "size[4,val=end-&size] typ[1,val=77] tag[tag]"
""".strip()
)
|