forked from google/gvisor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
messages.go
2271 lines (1854 loc) · 47.3 KB
/
messages.go
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
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2018 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package p9
import (
"fmt"
"reflect"
"gvisor.googlesource.com/gvisor/pkg/fd"
)
// ErrInvalidMsgType is returned when an unsupported message type is found.
type ErrInvalidMsgType struct {
MsgType
}
// Error returns a useful string.
func (e *ErrInvalidMsgType) Error() string {
return fmt.Sprintf("invalid message type: %d", e.MsgType)
}
// message is a generic 9P message.
type message interface {
encoder
fmt.Stringer
// Type returns the message type number.
Type() MsgType
}
// payloader is a special message which may include an inline payload.
type payloader interface {
// FixedSize returns the size of the fixed portion of this message.
FixedSize() uint32
// Payload returns the payload for sending.
Payload() []byte
// SetPayload returns the decoded message.
//
// This is going to be total message size - FixedSize. But this should
// be validated during Decode, which will be called after SetPayload.
SetPayload([]byte)
}
// filer is a message capable of passing a file.
type filer interface {
// FilePayload returns the file payload.
FilePayload() *fd.FD
// SetFilePayload sets the file payload.
SetFilePayload(*fd.FD)
}
// Tversion is a version request.
type Tversion struct {
// MSize is the message size to use.
MSize uint32
// Version is the version string.
//
// For this implementation, this must be 9P2000.L.
Version string
}
// Decode implements encoder.Decode.
func (t *Tversion) Decode(b *buffer) {
t.MSize = b.Read32()
t.Version = b.ReadString()
}
// Encode implements encoder.Encode.
func (t *Tversion) Encode(b *buffer) {
b.Write32(t.MSize)
b.WriteString(t.Version)
}
// Type implements message.Type.
func (*Tversion) Type() MsgType {
return MsgTversion
}
// String implements fmt.Stringer.
func (t *Tversion) String() string {
return fmt.Sprintf("Tversion{MSize: %d, Version: %s}", t.MSize, t.Version)
}
// Rversion is a version response.
type Rversion struct {
// MSize is the negotiated size.
MSize uint32
// Version is the negotiated version.
Version string
}
// Decode implements encoder.Decode.
func (r *Rversion) Decode(b *buffer) {
r.MSize = b.Read32()
r.Version = b.ReadString()
}
// Encode implements encoder.Encode.
func (r *Rversion) Encode(b *buffer) {
b.Write32(r.MSize)
b.WriteString(r.Version)
}
// Type implements message.Type.
func (*Rversion) Type() MsgType {
return MsgRversion
}
// String implements fmt.Stringer.
func (r *Rversion) String() string {
return fmt.Sprintf("Rversion{MSize: %d, Version: %s}", r.MSize, r.Version)
}
// Tflush is a flush request.
type Tflush struct {
// OldTag is the tag to wait on.
OldTag Tag
}
// Decode implements encoder.Decode.
func (t *Tflush) Decode(b *buffer) {
t.OldTag = b.ReadTag()
}
// Encode implements encoder.Encode.
func (t *Tflush) Encode(b *buffer) {
b.WriteTag(t.OldTag)
}
// Type implements message.Type.
func (*Tflush) Type() MsgType {
return MsgTflush
}
// String implements fmt.Stringer.
func (t *Tflush) String() string {
return fmt.Sprintf("Tflush{OldTag: %d}", t.OldTag)
}
// Rflush is a flush response.
type Rflush struct {
}
// Decode implements encoder.Decode.
func (*Rflush) Decode(b *buffer) {
}
// Encode implements encoder.Encode.
func (*Rflush) Encode(b *buffer) {
}
// Type implements message.Type.
func (*Rflush) Type() MsgType {
return MsgRflush
}
// String implements fmt.Stringer.
func (r *Rflush) String() string {
return fmt.Sprintf("RFlush{}")
}
// Twalk is a walk request.
type Twalk struct {
// FID is the FID to be walked.
FID FID
// NewFID is the resulting FID.
NewFID FID
// Names are the set of names to be walked.
Names []string
}
// Decode implements encoder.Decode.
func (t *Twalk) Decode(b *buffer) {
t.FID = b.ReadFID()
t.NewFID = b.ReadFID()
n := b.Read16()
for i := 0; i < int(n); i++ {
t.Names = append(t.Names, b.ReadString())
}
}
// Encode implements encoder.Encode.
func (t *Twalk) Encode(b *buffer) {
b.WriteFID(t.FID)
b.WriteFID(t.NewFID)
b.Write16(uint16(len(t.Names)))
for _, name := range t.Names {
b.WriteString(name)
}
}
// Type implements message.Type.
func (*Twalk) Type() MsgType {
return MsgTwalk
}
// String implements fmt.Stringer.
func (t *Twalk) String() string {
return fmt.Sprintf("Twalk{FID: %d, NewFID: %d, Names: %v}", t.FID, t.NewFID, t.Names)
}
// Rwalk is a walk response.
type Rwalk struct {
// QIDs are the set of QIDs returned.
QIDs []QID
}
// Decode implements encoder.Decode.
func (r *Rwalk) Decode(b *buffer) {
n := b.Read16()
for i := 0; i < int(n); i++ {
var q QID
q.Decode(b)
r.QIDs = append(r.QIDs, q)
}
}
// Encode implements encoder.Encode.
func (r *Rwalk) Encode(b *buffer) {
b.Write16(uint16(len(r.QIDs)))
for _, q := range r.QIDs {
q.Encode(b)
}
}
// Type implements message.Type.
func (*Rwalk) Type() MsgType {
return MsgRwalk
}
// String implements fmt.Stringer.
func (r *Rwalk) String() string {
return fmt.Sprintf("Rwalk{QIDs: %v}", r.QIDs)
}
// Tclunk is a close request.
type Tclunk struct {
// FID is the FID to be closed.
FID FID
}
// Decode implements encoder.Decode.
func (t *Tclunk) Decode(b *buffer) {
t.FID = b.ReadFID()
}
// Encode implements encoder.Encode.
func (t *Tclunk) Encode(b *buffer) {
b.WriteFID(t.FID)
}
// Type implements message.Type.
func (*Tclunk) Type() MsgType {
return MsgTclunk
}
// String implements fmt.Stringer.
func (t *Tclunk) String() string {
return fmt.Sprintf("Tclunk{FID: %d}", t.FID)
}
// Rclunk is a close response.
type Rclunk struct {
}
// Decode implements encoder.Decode.
func (*Rclunk) Decode(b *buffer) {
}
// Encode implements encoder.Encode.
func (*Rclunk) Encode(b *buffer) {
}
// Type implements message.Type.
func (*Rclunk) Type() MsgType {
return MsgRclunk
}
// String implements fmt.Stringer.
func (r *Rclunk) String() string {
return fmt.Sprintf("Rclunk{}")
}
// Tremove is a remove request.
//
// This will eventually be replaced by Tunlinkat.
type Tremove struct {
// FID is the FID to be removed.
FID FID
}
// Decode implements encoder.Decode.
func (t *Tremove) Decode(b *buffer) {
t.FID = b.ReadFID()
}
// Encode implements encoder.Encode.
func (t *Tremove) Encode(b *buffer) {
b.WriteFID(t.FID)
}
// Type implements message.Type.
func (*Tremove) Type() MsgType {
return MsgTremove
}
// String implements fmt.Stringer.
func (t *Tremove) String() string {
return fmt.Sprintf("Tremove{FID: %d}", t.FID)
}
// Rremove is a remove response.
type Rremove struct {
}
// Decode implements encoder.Decode.
func (*Rremove) Decode(b *buffer) {
}
// Encode implements encoder.Encode.
func (*Rremove) Encode(b *buffer) {
}
// Type implements message.Type.
func (*Rremove) Type() MsgType {
return MsgRremove
}
// String implements fmt.Stringer.
func (r *Rremove) String() string {
return fmt.Sprintf("Rremove{}")
}
// Rlerror is an error response.
//
// Note that this replaces the error code used in 9p.
type Rlerror struct {
Error uint32
}
// Decode implements encoder.Decode.
func (r *Rlerror) Decode(b *buffer) {
r.Error = b.Read32()
}
// Encode implements encoder.Encode.
func (r *Rlerror) Encode(b *buffer) {
b.Write32(r.Error)
}
// Type implements message.Type.
func (*Rlerror) Type() MsgType {
return MsgRlerror
}
// String implements fmt.Stringer.
func (r *Rlerror) String() string {
return fmt.Sprintf("Rlerror{Error: %d}", r.Error)
}
// Tauth is an authentication request.
type Tauth struct {
// AuthenticationFID is the FID to attach the authentication result.
AuthenticationFID FID
// UserName is the user to attach.
UserName string
// AttachName is the attach name.
AttachName string
// UserID is the numeric identifier for UserName.
UID UID
}
// Decode implements encoder.Decode.
func (t *Tauth) Decode(b *buffer) {
t.AuthenticationFID = b.ReadFID()
t.UserName = b.ReadString()
t.AttachName = b.ReadString()
t.UID = b.ReadUID()
}
// Encode implements encoder.Encode.
func (t *Tauth) Encode(b *buffer) {
b.WriteFID(t.AuthenticationFID)
b.WriteString(t.UserName)
b.WriteString(t.AttachName)
b.WriteUID(t.UID)
}
// Type implements message.Type.
func (*Tauth) Type() MsgType {
return MsgTauth
}
// String implements fmt.Stringer.
func (t *Tauth) String() string {
return fmt.Sprintf("Tauth{AuthFID: %d, UserName: %s, AttachName: %s, UID: %d", t.AuthenticationFID, t.UserName, t.AttachName, t.UID)
}
// Rauth is an authentication response.
//
// Encode, Decode and Length are inherited directly from QID.
type Rauth struct {
QID
}
// Type implements message.Type.
func (*Rauth) Type() MsgType {
return MsgRauth
}
// String implements fmt.Stringer.
func (r *Rauth) String() string {
return fmt.Sprintf("Rauth{QID: %s}", r.QID)
}
// Tattach is an attach request.
type Tattach struct {
// FID is the FID to be attached.
FID FID
// Auth is the embedded authentication request.
//
// See client.Attach for information regarding authentication.
Auth Tauth
}
// Decode implements encoder.Decode.
func (t *Tattach) Decode(b *buffer) {
t.FID = b.ReadFID()
t.Auth.Decode(b)
}
// Encode implements encoder.Encode.
func (t *Tattach) Encode(b *buffer) {
b.WriteFID(t.FID)
t.Auth.Encode(b)
}
// Type implements message.Type.
func (*Tattach) Type() MsgType {
return MsgTattach
}
// String implements fmt.Stringer.
func (t *Tattach) String() string {
return fmt.Sprintf("Tattach{FID: %d, AuthFID: %d, UserName: %s, AttachName: %s, UID: %d}", t.FID, t.Auth.AuthenticationFID, t.Auth.UserName, t.Auth.AttachName, t.Auth.UID)
}
// Rattach is an attach response.
type Rattach struct {
QID
}
// Type implements message.Type.
func (*Rattach) Type() MsgType {
return MsgRattach
}
// String implements fmt.Stringer.
func (r *Rattach) String() string {
return fmt.Sprintf("Rattach{QID: %s}", r.QID)
}
// Tlopen is an open request.
type Tlopen struct {
// FID is the FID to be opened.
FID FID
// Flags are the open flags.
Flags OpenFlags
}
// Decode implements encoder.Decode.
func (t *Tlopen) Decode(b *buffer) {
t.FID = b.ReadFID()
t.Flags = b.ReadOpenFlags()
}
// Encode implements encoder.Encode.
func (t *Tlopen) Encode(b *buffer) {
b.WriteFID(t.FID)
b.WriteOpenFlags(t.Flags)
}
// Type implements message.Type.
func (*Tlopen) Type() MsgType {
return MsgTlopen
}
// String implements fmt.Stringer.
func (t *Tlopen) String() string {
return fmt.Sprintf("Tlopen{FID: %d, Flags: %v}", t.FID, t.Flags)
}
// Rlopen is a open response.
type Rlopen struct {
// QID is the file's QID.
QID QID
// IoUnit is the recommended I/O unit.
IoUnit uint32
// File may be attached via the socket.
//
// This is an extension specific to this package.
File *fd.FD
}
// Decode implements encoder.Decode.
func (r *Rlopen) Decode(b *buffer) {
r.QID.Decode(b)
r.IoUnit = b.Read32()
}
// Encode implements encoder.Encode.
func (r *Rlopen) Encode(b *buffer) {
r.QID.Encode(b)
b.Write32(r.IoUnit)
}
// Type implements message.Type.
func (*Rlopen) Type() MsgType {
return MsgRlopen
}
// FilePayload returns the file payload.
func (r *Rlopen) FilePayload() *fd.FD {
return r.File
}
// SetFilePayload sets the received file.
func (r *Rlopen) SetFilePayload(file *fd.FD) {
r.File = file
}
// String implements fmt.Stringer.
func (r *Rlopen) String() string {
return fmt.Sprintf("Rlopen{QID: %s, IoUnit: %d, File: %v}", r.QID, r.IoUnit, r.File)
}
// Tlcreate is a create request.
type Tlcreate struct {
// FID is the parent FID.
//
// This becomes the new file.
FID FID
// Name is the file name to create.
Name string
// Mode is the open mode (O_RDWR, etc.).
//
// Note that flags like O_TRUNC are ignored, as is O_EXCL. All
// create operations are exclusive.
OpenFlags OpenFlags
// Permissions is the set of permission bits.
Permissions FileMode
// GID is the group ID to use for creating the file.
GID GID
}
// Decode implements encoder.Decode.
func (t *Tlcreate) Decode(b *buffer) {
t.FID = b.ReadFID()
t.Name = b.ReadString()
t.OpenFlags = b.ReadOpenFlags()
t.Permissions = b.ReadPermissions()
t.GID = b.ReadGID()
}
// Encode implements encoder.Encode.
func (t *Tlcreate) Encode(b *buffer) {
b.WriteFID(t.FID)
b.WriteString(t.Name)
b.WriteOpenFlags(t.OpenFlags)
b.WritePermissions(t.Permissions)
b.WriteGID(t.GID)
}
// Type implements message.Type.
func (*Tlcreate) Type() MsgType {
return MsgTlcreate
}
// String implements fmt.Stringer.
func (t *Tlcreate) String() string {
return fmt.Sprintf("Tlcreate{FID: %d, Name: %s, OpenFlags: %s, Permissions: 0o%o, GID: %d}", t.FID, t.Name, t.OpenFlags, t.Permissions, t.GID)
}
// Rlcreate is a create response.
//
// The Encode, Decode, etc. methods are inherited from Rlopen.
type Rlcreate struct {
Rlopen
}
// Type implements message.Type.
func (*Rlcreate) Type() MsgType {
return MsgRlcreate
}
// String implements fmt.Stringer.
func (r *Rlcreate) String() string {
return fmt.Sprintf("Rlcreate{QID: %s, IoUnit: %d, File: %v}", r.QID, r.IoUnit, r.File)
}
// Tsymlink is a symlink request.
type Tsymlink struct {
// Directory is the directory FID.
Directory FID
// Name is the new in the directory.
Name string
// Target is the symlink target.
Target string
// GID is the owning group.
GID GID
}
// Decode implements encoder.Decode.
func (t *Tsymlink) Decode(b *buffer) {
t.Directory = b.ReadFID()
t.Name = b.ReadString()
t.Target = b.ReadString()
t.GID = b.ReadGID()
}
// Encode implements encoder.Encode.
func (t *Tsymlink) Encode(b *buffer) {
b.WriteFID(t.Directory)
b.WriteString(t.Name)
b.WriteString(t.Target)
b.WriteGID(t.GID)
}
// Type implements message.Type.
func (*Tsymlink) Type() MsgType {
return MsgTsymlink
}
// String implements fmt.Stringer.
func (t *Tsymlink) String() string {
return fmt.Sprintf("Tsymlink{DirectoryFID: %d, Name: %s, Target: %s, GID: %d}", t.Directory, t.Name, t.Target, t.GID)
}
// Rsymlink is a symlink response.
type Rsymlink struct {
// QID is the new symlink's QID.
QID QID
}
// Decode implements encoder.Decode.
func (r *Rsymlink) Decode(b *buffer) {
r.QID.Decode(b)
}
// Encode implements encoder.Encode.
func (r *Rsymlink) Encode(b *buffer) {
r.QID.Encode(b)
}
// Type implements message.Type.
func (*Rsymlink) Type() MsgType {
return MsgRsymlink
}
// String implements fmt.Stringer.
func (r *Rsymlink) String() string {
return fmt.Sprintf("Rsymlink{QID: %s}", r.QID)
}
// Tlink is a link request.
type Tlink struct {
// Directory is the directory to contain the link.
Directory FID
// FID is the target.
Target FID
// Name is the new source name.
Name string
}
// Decode implements encoder.Decode.
func (t *Tlink) Decode(b *buffer) {
t.Directory = b.ReadFID()
t.Target = b.ReadFID()
t.Name = b.ReadString()
}
// Encode implements encoder.Encode.
func (t *Tlink) Encode(b *buffer) {
b.WriteFID(t.Directory)
b.WriteFID(t.Target)
b.WriteString(t.Name)
}
// Type implements message.Type.
func (*Tlink) Type() MsgType {
return MsgTlink
}
// String implements fmt.Stringer.
func (t *Tlink) String() string {
return fmt.Sprintf("Tlink{DirectoryFID: %d, TargetFID: %d, Name: %s}", t.Directory, t.Target, t.Name)
}
// Rlink is a link response.
type Rlink struct {
}
// Type implements message.Type.
func (*Rlink) Type() MsgType {
return MsgRlink
}
// Decode implements encoder.Decode.
func (*Rlink) Decode(b *buffer) {
}
// Encode implements encoder.Encode.
func (*Rlink) Encode(b *buffer) {
}
// String implements fmt.Stringer.
func (r *Rlink) String() string {
return fmt.Sprintf("Rlink{}")
}
// Trenameat is a rename request.
type Trenameat struct {
// OldDirectory is the source directory.
OldDirectory FID
// OldName is the source file name.
OldName string
// NewDirectory is the target directory.
NewDirectory FID
// NewName is the new file name.
NewName string
}
// Decode implements encoder.Decode.
func (t *Trenameat) Decode(b *buffer) {
t.OldDirectory = b.ReadFID()
t.OldName = b.ReadString()
t.NewDirectory = b.ReadFID()
t.NewName = b.ReadString()
}
// Encode implements encoder.Encode.
func (t *Trenameat) Encode(b *buffer) {
b.WriteFID(t.OldDirectory)
b.WriteString(t.OldName)
b.WriteFID(t.NewDirectory)
b.WriteString(t.NewName)
}
// Type implements message.Type.
func (*Trenameat) Type() MsgType {
return MsgTrenameat
}
// String implements fmt.Stringer.
func (t *Trenameat) String() string {
return fmt.Sprintf("TrenameAt{OldDirectoryFID: %d, OldName: %s, NewDirectoryFID: %d, NewName: %s}", t.OldDirectory, t.OldName, t.NewDirectory, t.NewName)
}
// Rrenameat is a rename response.
type Rrenameat struct {
}
// Decode implements encoder.Decode.
func (*Rrenameat) Decode(b *buffer) {
}
// Encode implements encoder.Encode.
func (*Rrenameat) Encode(b *buffer) {
}
// Type implements message.Type.
func (*Rrenameat) Type() MsgType {
return MsgRrenameat
}
// String implements fmt.Stringer.
func (r *Rrenameat) String() string {
return fmt.Sprintf("Rrenameat{}")
}
// Tunlinkat is an unlink request.
type Tunlinkat struct {
// Directory is the originating directory.
Directory FID
// Name is the name of the entry to unlink.
Name string
// Flags are extra flags (e.g. O_DIRECTORY). These are not interpreted by p9.
Flags uint32
}
// Decode implements encoder.Decode.
func (t *Tunlinkat) Decode(b *buffer) {
t.Directory = b.ReadFID()
t.Name = b.ReadString()
t.Flags = b.Read32()
}
// Encode implements encoder.Encode.
func (t *Tunlinkat) Encode(b *buffer) {
b.WriteFID(t.Directory)
b.WriteString(t.Name)
b.Write32(t.Flags)
}
// Type implements message.Type.
func (*Tunlinkat) Type() MsgType {
return MsgTunlinkat
}
// String implements fmt.Stringer.
func (t *Tunlinkat) String() string {
return fmt.Sprintf("Tunlinkat{DirectoryFID: %d, Name: %s, Flags: 0x%X}", t.Directory, t.Name, t.Flags)
}
// Runlinkat is an unlink response.
type Runlinkat struct {
}
// Decode implements encoder.Decode.
func (*Runlinkat) Decode(b *buffer) {
}
// Encode implements encoder.Encode.
func (*Runlinkat) Encode(b *buffer) {
}
// Type implements message.Type.
func (*Runlinkat) Type() MsgType {
return MsgRunlinkat
}
// String implements fmt.Stringer.
func (r *Runlinkat) String() string {
return fmt.Sprintf("Runlinkat{}")
}
// Trename is a rename request.
//
// Note that this generally isn't used anymore, and ideally all rename calls
// should Trenameat below.
type Trename struct {
// FID is the FID to rename.
FID FID
// Directory is the target directory.
Directory FID
// Name is the new file name.
Name string
}
// Decode implements encoder.Decode.
func (t *Trename) Decode(b *buffer) {
t.FID = b.ReadFID()
t.Directory = b.ReadFID()
t.Name = b.ReadString()
}
// Encode implements encoder.Encode.
func (t *Trename) Encode(b *buffer) {
b.WriteFID(t.FID)
b.WriteFID(t.Directory)
b.WriteString(t.Name)
}
// Type implements message.Type.
func (*Trename) Type() MsgType {
return MsgTrename
}
// String implements fmt.Stringer.
func (t *Trename) String() string {
return fmt.Sprintf("Trename{FID: %d, DirectoryFID: %d, Name: %s}", t.FID, t.Directory, t.Name)
}
// Rrename is a rename response.
type Rrename struct {
}
// Decode implements encoder.Decode.
func (*Rrename) Decode(b *buffer) {
}
// Encode implements encoder.Encode.
func (*Rrename) Encode(b *buffer) {
}
// Type implements message.Type.
func (*Rrename) Type() MsgType {
return MsgRrename
}
// String implements fmt.Stringer.
func (r *Rrename) String() string {
return fmt.Sprintf("Rrename{}")
}
// Treadlink is a readlink request.
type Treadlink struct {
// FID is the symlink.
FID FID
}
// Decode implements encoder.Decode.
func (t *Treadlink) Decode(b *buffer) {
t.FID = b.ReadFID()
}
// Encode implements encoder.Encode.
func (t *Treadlink) Encode(b *buffer) {
b.WriteFID(t.FID)
}
// Type implements message.Type.
func (*Treadlink) Type() MsgType {
return MsgTreadlink
}
// String implements fmt.Stringer.
func (t *Treadlink) String() string {
return fmt.Sprintf("Treadlink{FID: %d}", t.FID)
}
// Rreadlink is a readlink response.
type Rreadlink struct {
// Target is the symlink target.
Target string
}
// Decode implements encoder.Decode.
func (r *Rreadlink) Decode(b *buffer) {
r.Target = b.ReadString()
}
// Encode implements encoder.Encode.
func (r *Rreadlink) Encode(b *buffer) {
b.WriteString(r.Target)
}
// Type implements message.Type.
func (*Rreadlink) Type() MsgType {
return MsgRreadlink
}
// String implements fmt.Stringer.
func (r *Rreadlink) String() string {
return fmt.Sprintf("Rreadlink{Target: %s}", r.Target)
}
// Tread is a read request.
type Tread struct {
// FID is the FID to read.
FID FID
// Offset indicates the file offset.
Offset uint64
// Count indicates the number of bytes to read.
Count uint32
}