github.com/SagerNet/gvisor@v0.0.0-20210707092255-7731c139d75c/pkg/p9/messages.go (about) 1 // Copyright 2018 The gVisor Authors. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package p9 16 17 import ( 18 "fmt" 19 "math" 20 21 "github.com/SagerNet/gvisor/pkg/fd" 22 ) 23 24 // ErrInvalidMsgType is returned when an unsupported message type is found. 25 type ErrInvalidMsgType struct { 26 MsgType 27 } 28 29 // Error returns a useful string. 30 func (e *ErrInvalidMsgType) Error() string { 31 return fmt.Sprintf("invalid message type: %d", e.MsgType) 32 } 33 34 // message is a generic 9P message. 35 type message interface { 36 encoder 37 fmt.Stringer 38 39 // Type returns the message type number. 40 Type() MsgType 41 } 42 43 // payloader is a special message which may include an inline payload. 44 type payloader interface { 45 // FixedSize returns the size of the fixed portion of this message. 46 FixedSize() uint32 47 48 // Payload returns the payload for sending. 49 Payload() []byte 50 51 // SetPayload returns the decoded message. 52 // 53 // This is going to be total message size - FixedSize. But this should 54 // be validated during decode, which will be called after SetPayload. 55 SetPayload([]byte) 56 } 57 58 // filer is a message capable of passing a file. 59 type filer interface { 60 // FilePayload returns the file payload. 61 FilePayload() *fd.FD 62 63 // SetFilePayload sets the file payload. 64 SetFilePayload(*fd.FD) 65 } 66 67 // filePayload embeds a File object. 68 type filePayload struct { 69 File *fd.FD 70 } 71 72 // FilePayload returns the file payload. 73 func (f *filePayload) FilePayload() *fd.FD { 74 return f.File 75 } 76 77 // SetFilePayload sets the received file. 78 func (f *filePayload) SetFilePayload(file *fd.FD) { 79 f.File = file 80 } 81 82 // Tversion is a version request. 83 type Tversion struct { 84 // MSize is the message size to use. 85 MSize uint32 86 87 // Version is the version string. 88 // 89 // For this implementation, this must be 9P2000.L. 90 Version string 91 } 92 93 // decode implements encoder.decode. 94 func (t *Tversion) decode(b *buffer) { 95 t.MSize = b.Read32() 96 t.Version = b.ReadString() 97 } 98 99 // encode implements encoder.encode. 100 func (t *Tversion) encode(b *buffer) { 101 b.Write32(t.MSize) 102 b.WriteString(t.Version) 103 } 104 105 // Type implements message.Type. 106 func (*Tversion) Type() MsgType { 107 return MsgTversion 108 } 109 110 // String implements fmt.Stringer. 111 func (t *Tversion) String() string { 112 return fmt.Sprintf("Tversion{MSize: %d, Version: %s}", t.MSize, t.Version) 113 } 114 115 // Rversion is a version response. 116 type Rversion struct { 117 // MSize is the negotiated size. 118 MSize uint32 119 120 // Version is the negotiated version. 121 Version string 122 } 123 124 // decode implements encoder.decode. 125 func (r *Rversion) decode(b *buffer) { 126 r.MSize = b.Read32() 127 r.Version = b.ReadString() 128 } 129 130 // encode implements encoder.encode. 131 func (r *Rversion) encode(b *buffer) { 132 b.Write32(r.MSize) 133 b.WriteString(r.Version) 134 } 135 136 // Type implements message.Type. 137 func (*Rversion) Type() MsgType { 138 return MsgRversion 139 } 140 141 // String implements fmt.Stringer. 142 func (r *Rversion) String() string { 143 return fmt.Sprintf("Rversion{MSize: %d, Version: %s}", r.MSize, r.Version) 144 } 145 146 // Tflush is a flush request. 147 type Tflush struct { 148 // OldTag is the tag to wait on. 149 OldTag Tag 150 } 151 152 // decode implements encoder.decode. 153 func (t *Tflush) decode(b *buffer) { 154 t.OldTag = b.ReadTag() 155 } 156 157 // encode implements encoder.encode. 158 func (t *Tflush) encode(b *buffer) { 159 b.WriteTag(t.OldTag) 160 } 161 162 // Type implements message.Type. 163 func (*Tflush) Type() MsgType { 164 return MsgTflush 165 } 166 167 // String implements fmt.Stringer. 168 func (t *Tflush) String() string { 169 return fmt.Sprintf("Tflush{OldTag: %d}", t.OldTag) 170 } 171 172 // Rflush is a flush response. 173 type Rflush struct { 174 } 175 176 // decode implements encoder.decode. 177 func (*Rflush) decode(*buffer) { 178 } 179 180 // encode implements encoder.encode. 181 func (*Rflush) encode(*buffer) { 182 } 183 184 // Type implements message.Type. 185 func (*Rflush) Type() MsgType { 186 return MsgRflush 187 } 188 189 // String implements fmt.Stringer. 190 func (r *Rflush) String() string { 191 return "RFlush{}" 192 } 193 194 // Twalk is a walk request. 195 type Twalk struct { 196 // FID is the FID to be walked. 197 FID FID 198 199 // NewFID is the resulting FID. 200 NewFID FID 201 202 // Names are the set of names to be walked. 203 Names []string 204 } 205 206 // decode implements encoder.decode. 207 func (t *Twalk) decode(b *buffer) { 208 t.FID = b.ReadFID() 209 t.NewFID = b.ReadFID() 210 n := b.Read16() 211 t.Names = t.Names[:0] 212 for i := 0; i < int(n); i++ { 213 t.Names = append(t.Names, b.ReadString()) 214 } 215 } 216 217 // encode implements encoder.encode. 218 func (t *Twalk) encode(b *buffer) { 219 b.WriteFID(t.FID) 220 b.WriteFID(t.NewFID) 221 b.Write16(uint16(len(t.Names))) 222 for _, name := range t.Names { 223 b.WriteString(name) 224 } 225 } 226 227 // Type implements message.Type. 228 func (*Twalk) Type() MsgType { 229 return MsgTwalk 230 } 231 232 // String implements fmt.Stringer. 233 func (t *Twalk) String() string { 234 return fmt.Sprintf("Twalk{FID: %d, NewFID: %d, Names: %v}", t.FID, t.NewFID, t.Names) 235 } 236 237 // Rwalk is a walk response. 238 type Rwalk struct { 239 // QIDs are the set of QIDs returned. 240 QIDs []QID 241 } 242 243 // decode implements encoder.decode. 244 func (r *Rwalk) decode(b *buffer) { 245 n := b.Read16() 246 r.QIDs = r.QIDs[:0] 247 for i := 0; i < int(n); i++ { 248 var q QID 249 q.decode(b) 250 r.QIDs = append(r.QIDs, q) 251 } 252 } 253 254 // encode implements encoder.encode. 255 func (r *Rwalk) encode(b *buffer) { 256 b.Write16(uint16(len(r.QIDs))) 257 for i := range r.QIDs { 258 r.QIDs[i].encode(b) 259 } 260 } 261 262 // Type implements message.Type. 263 func (*Rwalk) Type() MsgType { 264 return MsgRwalk 265 } 266 267 // String implements fmt.Stringer. 268 func (r *Rwalk) String() string { 269 return fmt.Sprintf("Rwalk{QIDs: %v}", r.QIDs) 270 } 271 272 // Tclunk is a close request. 273 type Tclunk struct { 274 // FID is the FID to be closed. 275 FID FID 276 } 277 278 // decode implements encoder.decode. 279 func (t *Tclunk) decode(b *buffer) { 280 t.FID = b.ReadFID() 281 } 282 283 // encode implements encoder.encode. 284 func (t *Tclunk) encode(b *buffer) { 285 b.WriteFID(t.FID) 286 } 287 288 // Type implements message.Type. 289 func (*Tclunk) Type() MsgType { 290 return MsgTclunk 291 } 292 293 // String implements fmt.Stringer. 294 func (t *Tclunk) String() string { 295 return fmt.Sprintf("Tclunk{FID: %d}", t.FID) 296 } 297 298 // Rclunk is a close response. 299 type Rclunk struct { 300 } 301 302 // decode implements encoder.decode. 303 func (*Rclunk) decode(*buffer) { 304 } 305 306 // encode implements encoder.encode. 307 func (*Rclunk) encode(*buffer) { 308 } 309 310 // Type implements message.Type. 311 func (*Rclunk) Type() MsgType { 312 return MsgRclunk 313 } 314 315 // String implements fmt.Stringer. 316 func (r *Rclunk) String() string { 317 return "Rclunk{}" 318 } 319 320 // Tsetattrclunk is a setattr+close request. 321 type Tsetattrclunk struct { 322 // FID is the FID to change. 323 FID FID 324 325 // Valid is the set of bits which will be used. 326 Valid SetAttrMask 327 328 // SetAttr is the set request. 329 SetAttr SetAttr 330 } 331 332 // decode implements encoder.decode. 333 func (t *Tsetattrclunk) decode(b *buffer) { 334 t.FID = b.ReadFID() 335 t.Valid.decode(b) 336 t.SetAttr.decode(b) 337 } 338 339 // encode implements encoder.encode. 340 func (t *Tsetattrclunk) encode(b *buffer) { 341 b.WriteFID(t.FID) 342 t.Valid.encode(b) 343 t.SetAttr.encode(b) 344 } 345 346 // Type implements message.Type. 347 func (*Tsetattrclunk) Type() MsgType { 348 return MsgTsetattrclunk 349 } 350 351 // String implements fmt.Stringer. 352 func (t *Tsetattrclunk) String() string { 353 return fmt.Sprintf("Tsetattrclunk{FID: %d, Valid: %v, SetAttr: %s}", t.FID, t.Valid, t.SetAttr) 354 } 355 356 // Rsetattrclunk is a setattr+close response. 357 type Rsetattrclunk struct { 358 } 359 360 // decode implements encoder.decode. 361 func (*Rsetattrclunk) decode(*buffer) { 362 } 363 364 // encode implements encoder.encode. 365 func (*Rsetattrclunk) encode(*buffer) { 366 } 367 368 // Type implements message.Type. 369 func (*Rsetattrclunk) Type() MsgType { 370 return MsgRsetattrclunk 371 } 372 373 // String implements fmt.Stringer. 374 func (r *Rsetattrclunk) String() string { 375 return "Rsetattrclunk{}" 376 } 377 378 // Tremove is a remove request. 379 // 380 // This will eventually be replaced by Tunlinkat. 381 type Tremove struct { 382 // FID is the FID to be removed. 383 FID FID 384 } 385 386 // decode implements encoder.decode. 387 func (t *Tremove) decode(b *buffer) { 388 t.FID = b.ReadFID() 389 } 390 391 // encode implements encoder.encode. 392 func (t *Tremove) encode(b *buffer) { 393 b.WriteFID(t.FID) 394 } 395 396 // Type implements message.Type. 397 func (*Tremove) Type() MsgType { 398 return MsgTremove 399 } 400 401 // String implements fmt.Stringer. 402 func (t *Tremove) String() string { 403 return fmt.Sprintf("Tremove{FID: %d}", t.FID) 404 } 405 406 // Rremove is a remove response. 407 type Rremove struct { 408 } 409 410 // decode implements encoder.decode. 411 func (*Rremove) decode(*buffer) { 412 } 413 414 // encode implements encoder.encode. 415 func (*Rremove) encode(*buffer) { 416 } 417 418 // Type implements message.Type. 419 func (*Rremove) Type() MsgType { 420 return MsgRremove 421 } 422 423 // String implements fmt.Stringer. 424 func (r *Rremove) String() string { 425 return "Rremove{}" 426 } 427 428 // Rlerror is an error response. 429 // 430 // Note that this replaces the error code used in 9p. 431 type Rlerror struct { 432 Error uint32 433 } 434 435 // decode implements encoder.decode. 436 func (r *Rlerror) decode(b *buffer) { 437 r.Error = b.Read32() 438 } 439 440 // encode implements encoder.encode. 441 func (r *Rlerror) encode(b *buffer) { 442 b.Write32(r.Error) 443 } 444 445 // Type implements message.Type. 446 func (*Rlerror) Type() MsgType { 447 return MsgRlerror 448 } 449 450 // String implements fmt.Stringer. 451 func (r *Rlerror) String() string { 452 return fmt.Sprintf("Rlerror{Error: %d}", r.Error) 453 } 454 455 // Tauth is an authentication request. 456 type Tauth struct { 457 // AuthenticationFID is the FID to attach the authentication result. 458 AuthenticationFID FID 459 460 // UserName is the user to attach. 461 UserName string 462 463 // AttachName is the attach name. 464 AttachName string 465 466 // UserID is the numeric identifier for UserName. 467 UID UID 468 } 469 470 // decode implements encoder.decode. 471 func (t *Tauth) decode(b *buffer) { 472 t.AuthenticationFID = b.ReadFID() 473 t.UserName = b.ReadString() 474 t.AttachName = b.ReadString() 475 t.UID = b.ReadUID() 476 } 477 478 // encode implements encoder.encode. 479 func (t *Tauth) encode(b *buffer) { 480 b.WriteFID(t.AuthenticationFID) 481 b.WriteString(t.UserName) 482 b.WriteString(t.AttachName) 483 b.WriteUID(t.UID) 484 } 485 486 // Type implements message.Type. 487 func (*Tauth) Type() MsgType { 488 return MsgTauth 489 } 490 491 // String implements fmt.Stringer. 492 func (t *Tauth) String() string { 493 return fmt.Sprintf("Tauth{AuthFID: %d, UserName: %s, AttachName: %s, UID: %d", t.AuthenticationFID, t.UserName, t.AttachName, t.UID) 494 } 495 496 // Rauth is an authentication response. 497 // 498 // encode and decode are inherited directly from QID. 499 type Rauth struct { 500 QID 501 } 502 503 // Type implements message.Type. 504 func (*Rauth) Type() MsgType { 505 return MsgRauth 506 } 507 508 // String implements fmt.Stringer. 509 func (r *Rauth) String() string { 510 return fmt.Sprintf("Rauth{QID: %s}", r.QID) 511 } 512 513 // Tattach is an attach request. 514 type Tattach struct { 515 // FID is the FID to be attached. 516 FID FID 517 518 // Auth is the embedded authentication request. 519 // 520 // See client.Attach for information regarding authentication. 521 Auth Tauth 522 } 523 524 // decode implements encoder.decode. 525 func (t *Tattach) decode(b *buffer) { 526 t.FID = b.ReadFID() 527 t.Auth.decode(b) 528 } 529 530 // encode implements encoder.encode. 531 func (t *Tattach) encode(b *buffer) { 532 b.WriteFID(t.FID) 533 t.Auth.encode(b) 534 } 535 536 // Type implements message.Type. 537 func (*Tattach) Type() MsgType { 538 return MsgTattach 539 } 540 541 // String implements fmt.Stringer. 542 func (t *Tattach) String() string { 543 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) 544 } 545 546 // Rattach is an attach response. 547 type Rattach struct { 548 QID 549 } 550 551 // Type implements message.Type. 552 func (*Rattach) Type() MsgType { 553 return MsgRattach 554 } 555 556 // String implements fmt.Stringer. 557 func (r *Rattach) String() string { 558 return fmt.Sprintf("Rattach{QID: %s}", r.QID) 559 } 560 561 // Tlopen is an open request. 562 type Tlopen struct { 563 // FID is the FID to be opened. 564 FID FID 565 566 // Flags are the open flags. 567 Flags OpenFlags 568 } 569 570 // decode implements encoder.decode. 571 func (t *Tlopen) decode(b *buffer) { 572 t.FID = b.ReadFID() 573 t.Flags = b.ReadOpenFlags() 574 } 575 576 // encode implements encoder.encode. 577 func (t *Tlopen) encode(b *buffer) { 578 b.WriteFID(t.FID) 579 b.WriteOpenFlags(t.Flags) 580 } 581 582 // Type implements message.Type. 583 func (*Tlopen) Type() MsgType { 584 return MsgTlopen 585 } 586 587 // String implements fmt.Stringer. 588 func (t *Tlopen) String() string { 589 return fmt.Sprintf("Tlopen{FID: %d, Flags: %v}", t.FID, t.Flags) 590 } 591 592 // Rlopen is a open response. 593 type Rlopen struct { 594 // QID is the file's QID. 595 QID QID 596 597 // IoUnit is the recommended I/O unit. 598 IoUnit uint32 599 600 filePayload 601 } 602 603 // decode implements encoder.decode. 604 func (r *Rlopen) decode(b *buffer) { 605 r.QID.decode(b) 606 r.IoUnit = b.Read32() 607 } 608 609 // encode implements encoder.encode. 610 func (r *Rlopen) encode(b *buffer) { 611 r.QID.encode(b) 612 b.Write32(r.IoUnit) 613 } 614 615 // Type implements message.Type. 616 func (*Rlopen) Type() MsgType { 617 return MsgRlopen 618 } 619 620 // String implements fmt.Stringer. 621 func (r *Rlopen) String() string { 622 return fmt.Sprintf("Rlopen{QID: %s, IoUnit: %d, File: %v}", r.QID, r.IoUnit, r.File) 623 } 624 625 // Tlcreate is a create request. 626 type Tlcreate struct { 627 // FID is the parent FID. 628 // 629 // This becomes the new file. 630 FID FID 631 632 // Name is the file name to create. 633 Name string 634 635 // Mode is the open mode (O_RDWR, etc.). 636 // 637 // Note that flags like O_TRUNC are ignored, as is O_EXCL. All 638 // create operations are exclusive. 639 OpenFlags OpenFlags 640 641 // Permissions is the set of permission bits. 642 Permissions FileMode 643 644 // GID is the group ID to use for creating the file. 645 GID GID 646 } 647 648 // decode implements encoder.decode. 649 func (t *Tlcreate) decode(b *buffer) { 650 t.FID = b.ReadFID() 651 t.Name = b.ReadString() 652 t.OpenFlags = b.ReadOpenFlags() 653 t.Permissions = b.ReadPermissions() 654 t.GID = b.ReadGID() 655 } 656 657 // encode implements encoder.encode. 658 func (t *Tlcreate) encode(b *buffer) { 659 b.WriteFID(t.FID) 660 b.WriteString(t.Name) 661 b.WriteOpenFlags(t.OpenFlags) 662 b.WritePermissions(t.Permissions) 663 b.WriteGID(t.GID) 664 } 665 666 // Type implements message.Type. 667 func (*Tlcreate) Type() MsgType { 668 return MsgTlcreate 669 } 670 671 // String implements fmt.Stringer. 672 func (t *Tlcreate) String() string { 673 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) 674 } 675 676 // Rlcreate is a create response. 677 // 678 // The encode, decode, etc. methods are inherited from Rlopen. 679 type Rlcreate struct { 680 Rlopen 681 } 682 683 // Type implements message.Type. 684 func (*Rlcreate) Type() MsgType { 685 return MsgRlcreate 686 } 687 688 // String implements fmt.Stringer. 689 func (r *Rlcreate) String() string { 690 return fmt.Sprintf("Rlcreate{QID: %s, IoUnit: %d, File: %v}", r.QID, r.IoUnit, r.File) 691 } 692 693 // Tsymlink is a symlink request. 694 type Tsymlink struct { 695 // Directory is the directory FID. 696 Directory FID 697 698 // Name is the new in the directory. 699 Name string 700 701 // Target is the symlink target. 702 Target string 703 704 // GID is the owning group. 705 GID GID 706 } 707 708 // decode implements encoder.decode. 709 func (t *Tsymlink) decode(b *buffer) { 710 t.Directory = b.ReadFID() 711 t.Name = b.ReadString() 712 t.Target = b.ReadString() 713 t.GID = b.ReadGID() 714 } 715 716 // encode implements encoder.encode. 717 func (t *Tsymlink) encode(b *buffer) { 718 b.WriteFID(t.Directory) 719 b.WriteString(t.Name) 720 b.WriteString(t.Target) 721 b.WriteGID(t.GID) 722 } 723 724 // Type implements message.Type. 725 func (*Tsymlink) Type() MsgType { 726 return MsgTsymlink 727 } 728 729 // String implements fmt.Stringer. 730 func (t *Tsymlink) String() string { 731 return fmt.Sprintf("Tsymlink{DirectoryFID: %d, Name: %s, Target: %s, GID: %d}", t.Directory, t.Name, t.Target, t.GID) 732 } 733 734 // Rsymlink is a symlink response. 735 type Rsymlink struct { 736 // QID is the new symlink's QID. 737 QID QID 738 } 739 740 // decode implements encoder.decode. 741 func (r *Rsymlink) decode(b *buffer) { 742 r.QID.decode(b) 743 } 744 745 // encode implements encoder.encode. 746 func (r *Rsymlink) encode(b *buffer) { 747 r.QID.encode(b) 748 } 749 750 // Type implements message.Type. 751 func (*Rsymlink) Type() MsgType { 752 return MsgRsymlink 753 } 754 755 // String implements fmt.Stringer. 756 func (r *Rsymlink) String() string { 757 return fmt.Sprintf("Rsymlink{QID: %s}", r.QID) 758 } 759 760 // Tlink is a link request. 761 type Tlink struct { 762 // Directory is the directory to contain the link. 763 Directory FID 764 765 // FID is the target. 766 Target FID 767 768 // Name is the new source name. 769 Name string 770 } 771 772 // decode implements encoder.decode. 773 func (t *Tlink) decode(b *buffer) { 774 t.Directory = b.ReadFID() 775 t.Target = b.ReadFID() 776 t.Name = b.ReadString() 777 } 778 779 // encode implements encoder.encode. 780 func (t *Tlink) encode(b *buffer) { 781 b.WriteFID(t.Directory) 782 b.WriteFID(t.Target) 783 b.WriteString(t.Name) 784 } 785 786 // Type implements message.Type. 787 func (*Tlink) Type() MsgType { 788 return MsgTlink 789 } 790 791 // String implements fmt.Stringer. 792 func (t *Tlink) String() string { 793 return fmt.Sprintf("Tlink{DirectoryFID: %d, TargetFID: %d, Name: %s}", t.Directory, t.Target, t.Name) 794 } 795 796 // Rlink is a link response. 797 type Rlink struct { 798 } 799 800 // Type implements message.Type. 801 func (*Rlink) Type() MsgType { 802 return MsgRlink 803 } 804 805 // decode implements encoder.decode. 806 func (*Rlink) decode(*buffer) { 807 } 808 809 // encode implements encoder.encode. 810 func (*Rlink) encode(*buffer) { 811 } 812 813 // String implements fmt.Stringer. 814 func (r *Rlink) String() string { 815 return "Rlink{}" 816 } 817 818 // Trenameat is a rename request. 819 type Trenameat struct { 820 // OldDirectory is the source directory. 821 OldDirectory FID 822 823 // OldName is the source file name. 824 OldName string 825 826 // NewDirectory is the target directory. 827 NewDirectory FID 828 829 // NewName is the new file name. 830 NewName string 831 } 832 833 // decode implements encoder.decode. 834 func (t *Trenameat) decode(b *buffer) { 835 t.OldDirectory = b.ReadFID() 836 t.OldName = b.ReadString() 837 t.NewDirectory = b.ReadFID() 838 t.NewName = b.ReadString() 839 } 840 841 // encode implements encoder.encode. 842 func (t *Trenameat) encode(b *buffer) { 843 b.WriteFID(t.OldDirectory) 844 b.WriteString(t.OldName) 845 b.WriteFID(t.NewDirectory) 846 b.WriteString(t.NewName) 847 } 848 849 // Type implements message.Type. 850 func (*Trenameat) Type() MsgType { 851 return MsgTrenameat 852 } 853 854 // String implements fmt.Stringer. 855 func (t *Trenameat) String() string { 856 return fmt.Sprintf("TrenameAt{OldDirectoryFID: %d, OldName: %s, NewDirectoryFID: %d, NewName: %s}", t.OldDirectory, t.OldName, t.NewDirectory, t.NewName) 857 } 858 859 // Rrenameat is a rename response. 860 type Rrenameat struct { 861 } 862 863 // decode implements encoder.decode. 864 func (*Rrenameat) decode(*buffer) { 865 } 866 867 // encode implements encoder.encode. 868 func (*Rrenameat) encode(*buffer) { 869 } 870 871 // Type implements message.Type. 872 func (*Rrenameat) Type() MsgType { 873 return MsgRrenameat 874 } 875 876 // String implements fmt.Stringer. 877 func (r *Rrenameat) String() string { 878 return "Rrenameat{}" 879 } 880 881 // Tunlinkat is an unlink request. 882 type Tunlinkat struct { 883 // Directory is the originating directory. 884 Directory FID 885 886 // Name is the name of the entry to unlink. 887 Name string 888 889 // Flags are extra flags (e.g. O_DIRECTORY). These are not interpreted by p9. 890 Flags uint32 891 } 892 893 // decode implements encoder.decode. 894 func (t *Tunlinkat) decode(b *buffer) { 895 t.Directory = b.ReadFID() 896 t.Name = b.ReadString() 897 t.Flags = b.Read32() 898 } 899 900 // encode implements encoder.encode. 901 func (t *Tunlinkat) encode(b *buffer) { 902 b.WriteFID(t.Directory) 903 b.WriteString(t.Name) 904 b.Write32(t.Flags) 905 } 906 907 // Type implements message.Type. 908 func (*Tunlinkat) Type() MsgType { 909 return MsgTunlinkat 910 } 911 912 // String implements fmt.Stringer. 913 func (t *Tunlinkat) String() string { 914 return fmt.Sprintf("Tunlinkat{DirectoryFID: %d, Name: %s, Flags: 0x%X}", t.Directory, t.Name, t.Flags) 915 } 916 917 // Runlinkat is an unlink response. 918 type Runlinkat struct { 919 } 920 921 // decode implements encoder.decode. 922 func (*Runlinkat) decode(*buffer) { 923 } 924 925 // encode implements encoder.encode. 926 func (*Runlinkat) encode(*buffer) { 927 } 928 929 // Type implements message.Type. 930 func (*Runlinkat) Type() MsgType { 931 return MsgRunlinkat 932 } 933 934 // String implements fmt.Stringer. 935 func (r *Runlinkat) String() string { 936 return "Runlinkat{}" 937 } 938 939 // Trename is a rename request. 940 // 941 // Note that this generally isn't used anymore, and ideally all rename calls 942 // should Trenameat below. 943 type Trename struct { 944 // FID is the FID to rename. 945 FID FID 946 947 // Directory is the target directory. 948 Directory FID 949 950 // Name is the new file name. 951 Name string 952 } 953 954 // decode implements encoder.decode. 955 func (t *Trename) decode(b *buffer) { 956 t.FID = b.ReadFID() 957 t.Directory = b.ReadFID() 958 t.Name = b.ReadString() 959 } 960 961 // encode implements encoder.encode. 962 func (t *Trename) encode(b *buffer) { 963 b.WriteFID(t.FID) 964 b.WriteFID(t.Directory) 965 b.WriteString(t.Name) 966 } 967 968 // Type implements message.Type. 969 func (*Trename) Type() MsgType { 970 return MsgTrename 971 } 972 973 // String implements fmt.Stringer. 974 func (t *Trename) String() string { 975 return fmt.Sprintf("Trename{FID: %d, DirectoryFID: %d, Name: %s}", t.FID, t.Directory, t.Name) 976 } 977 978 // Rrename is a rename response. 979 type Rrename struct { 980 } 981 982 // decode implements encoder.decode. 983 func (*Rrename) decode(*buffer) { 984 } 985 986 // encode implements encoder.encode. 987 func (*Rrename) encode(*buffer) { 988 } 989 990 // Type implements message.Type. 991 func (*Rrename) Type() MsgType { 992 return MsgRrename 993 } 994 995 // String implements fmt.Stringer. 996 func (r *Rrename) String() string { 997 return "Rrename{}" 998 } 999 1000 // Treadlink is a readlink request. 1001 type Treadlink struct { 1002 // FID is the symlink. 1003 FID FID 1004 } 1005 1006 // decode implements encoder.decode. 1007 func (t *Treadlink) decode(b *buffer) { 1008 t.FID = b.ReadFID() 1009 } 1010 1011 // encode implements encoder.encode. 1012 func (t *Treadlink) encode(b *buffer) { 1013 b.WriteFID(t.FID) 1014 } 1015 1016 // Type implements message.Type. 1017 func (*Treadlink) Type() MsgType { 1018 return MsgTreadlink 1019 } 1020 1021 // String implements fmt.Stringer. 1022 func (t *Treadlink) String() string { 1023 return fmt.Sprintf("Treadlink{FID: %d}", t.FID) 1024 } 1025 1026 // Rreadlink is a readlink response. 1027 type Rreadlink struct { 1028 // Target is the symlink target. 1029 Target string 1030 } 1031 1032 // decode implements encoder.decode. 1033 func (r *Rreadlink) decode(b *buffer) { 1034 r.Target = b.ReadString() 1035 } 1036 1037 // encode implements encoder.encode. 1038 func (r *Rreadlink) encode(b *buffer) { 1039 b.WriteString(r.Target) 1040 } 1041 1042 // Type implements message.Type. 1043 func (*Rreadlink) Type() MsgType { 1044 return MsgRreadlink 1045 } 1046 1047 // String implements fmt.Stringer. 1048 func (r *Rreadlink) String() string { 1049 return fmt.Sprintf("Rreadlink{Target: %s}", r.Target) 1050 } 1051 1052 // Tread is a read request. 1053 type Tread struct { 1054 // FID is the FID to read. 1055 FID FID 1056 1057 // Offset indicates the file offset. 1058 Offset uint64 1059 1060 // Count indicates the number of bytes to read. 1061 Count uint32 1062 } 1063 1064 // decode implements encoder.decode. 1065 func (t *Tread) decode(b *buffer) { 1066 t.FID = b.ReadFID() 1067 t.Offset = b.Read64() 1068 t.Count = b.Read32() 1069 } 1070 1071 // encode implements encoder.encode. 1072 func (t *Tread) encode(b *buffer) { 1073 b.WriteFID(t.FID) 1074 b.Write64(t.Offset) 1075 b.Write32(t.Count) 1076 } 1077 1078 // Type implements message.Type. 1079 func (*Tread) Type() MsgType { 1080 return MsgTread 1081 } 1082 1083 // String implements fmt.Stringer. 1084 func (t *Tread) String() string { 1085 return fmt.Sprintf("Tread{FID: %d, Offset: %d, Count: %d}", t.FID, t.Offset, t.Count) 1086 } 1087 1088 // Rread is the response for a Tread. 1089 type Rread struct { 1090 // Data is the resulting data. 1091 Data []byte 1092 } 1093 1094 // decode implements encoder.decode. 1095 // 1096 // Data is automatically decoded via Payload. 1097 func (r *Rread) decode(b *buffer) { 1098 count := b.Read32() 1099 if count != uint32(len(r.Data)) { 1100 b.markOverrun() 1101 } 1102 } 1103 1104 // encode implements encoder.encode. 1105 // 1106 // Data is automatically encoded via Payload. 1107 func (r *Rread) encode(b *buffer) { 1108 b.Write32(uint32(len(r.Data))) 1109 } 1110 1111 // Type implements message.Type. 1112 func (*Rread) Type() MsgType { 1113 return MsgRread 1114 } 1115 1116 // FixedSize implements payloader.FixedSize. 1117 func (*Rread) FixedSize() uint32 { 1118 return 4 1119 } 1120 1121 // Payload implements payloader.Payload. 1122 func (r *Rread) Payload() []byte { 1123 return r.Data 1124 } 1125 1126 // SetPayload implements payloader.SetPayload. 1127 func (r *Rread) SetPayload(p []byte) { 1128 r.Data = p 1129 } 1130 1131 // String implements fmt.Stringer. 1132 func (r *Rread) String() string { 1133 return fmt.Sprintf("Rread{len(Data): %d}", len(r.Data)) 1134 } 1135 1136 // Twrite is a write request. 1137 type Twrite struct { 1138 // FID is the FID to read. 1139 FID FID 1140 1141 // Offset indicates the file offset. 1142 Offset uint64 1143 1144 // Data is the data to be written. 1145 Data []byte 1146 } 1147 1148 // decode implements encoder.decode. 1149 func (t *Twrite) decode(b *buffer) { 1150 t.FID = b.ReadFID() 1151 t.Offset = b.Read64() 1152 count := b.Read32() 1153 if count != uint32(len(t.Data)) { 1154 b.markOverrun() 1155 } 1156 } 1157 1158 // encode implements encoder.encode. 1159 // 1160 // This uses the buffer payload to avoid a copy. 1161 func (t *Twrite) encode(b *buffer) { 1162 b.WriteFID(t.FID) 1163 b.Write64(t.Offset) 1164 b.Write32(uint32(len(t.Data))) 1165 } 1166 1167 // Type implements message.Type. 1168 func (*Twrite) Type() MsgType { 1169 return MsgTwrite 1170 } 1171 1172 // FixedSize implements payloader.FixedSize. 1173 func (*Twrite) FixedSize() uint32 { 1174 return 16 1175 } 1176 1177 // Payload implements payloader.Payload. 1178 func (t *Twrite) Payload() []byte { 1179 return t.Data 1180 } 1181 1182 // SetPayload implements payloader.SetPayload. 1183 func (t *Twrite) SetPayload(p []byte) { 1184 t.Data = p 1185 } 1186 1187 // String implements fmt.Stringer. 1188 func (t *Twrite) String() string { 1189 return fmt.Sprintf("Twrite{FID: %v, Offset %d, len(Data): %d}", t.FID, t.Offset, len(t.Data)) 1190 } 1191 1192 // Rwrite is the response for a Twrite. 1193 type Rwrite struct { 1194 // Count indicates the number of bytes successfully written. 1195 Count uint32 1196 } 1197 1198 // decode implements encoder.decode. 1199 func (r *Rwrite) decode(b *buffer) { 1200 r.Count = b.Read32() 1201 } 1202 1203 // encode implements encoder.encode. 1204 func (r *Rwrite) encode(b *buffer) { 1205 b.Write32(r.Count) 1206 } 1207 1208 // Type implements message.Type. 1209 func (*Rwrite) Type() MsgType { 1210 return MsgRwrite 1211 } 1212 1213 // String implements fmt.Stringer. 1214 func (r *Rwrite) String() string { 1215 return fmt.Sprintf("Rwrite{Count: %d}", r.Count) 1216 } 1217 1218 // Tmknod is a mknod request. 1219 type Tmknod struct { 1220 // Directory is the parent directory. 1221 Directory FID 1222 1223 // Name is the device name. 1224 Name string 1225 1226 // Mode is the device mode and permissions. 1227 Mode FileMode 1228 1229 // Major is the device major number. 1230 Major uint32 1231 1232 // Minor is the device minor number. 1233 Minor uint32 1234 1235 // GID is the device GID. 1236 GID GID 1237 } 1238 1239 // decode implements encoder.decode. 1240 func (t *Tmknod) decode(b *buffer) { 1241 t.Directory = b.ReadFID() 1242 t.Name = b.ReadString() 1243 t.Mode = b.ReadFileMode() 1244 t.Major = b.Read32() 1245 t.Minor = b.Read32() 1246 t.GID = b.ReadGID() 1247 } 1248 1249 // encode implements encoder.encode. 1250 func (t *Tmknod) encode(b *buffer) { 1251 b.WriteFID(t.Directory) 1252 b.WriteString(t.Name) 1253 b.WriteFileMode(t.Mode) 1254 b.Write32(t.Major) 1255 b.Write32(t.Minor) 1256 b.WriteGID(t.GID) 1257 } 1258 1259 // Type implements message.Type. 1260 func (*Tmknod) Type() MsgType { 1261 return MsgTmknod 1262 } 1263 1264 // String implements fmt.Stringer. 1265 func (t *Tmknod) String() string { 1266 return fmt.Sprintf("Tmknod{DirectoryFID: %d, Name: %s, Mode: 0o%o, Major: %d, Minor: %d, GID: %d}", t.Directory, t.Name, t.Mode, t.Major, t.Minor, t.GID) 1267 } 1268 1269 // Rmknod is a mknod response. 1270 type Rmknod struct { 1271 // QID is the resulting QID. 1272 QID QID 1273 } 1274 1275 // decode implements encoder.decode. 1276 func (r *Rmknod) decode(b *buffer) { 1277 r.QID.decode(b) 1278 } 1279 1280 // encode implements encoder.encode. 1281 func (r *Rmknod) encode(b *buffer) { 1282 r.QID.encode(b) 1283 } 1284 1285 // Type implements message.Type. 1286 func (*Rmknod) Type() MsgType { 1287 return MsgRmknod 1288 } 1289 1290 // String implements fmt.Stringer. 1291 func (r *Rmknod) String() string { 1292 return fmt.Sprintf("Rmknod{QID: %s}", r.QID) 1293 } 1294 1295 // Tmkdir is a mkdir request. 1296 type Tmkdir struct { 1297 // Directory is the parent directory. 1298 Directory FID 1299 1300 // Name is the new directory name. 1301 Name string 1302 1303 // Permissions is the set of permission bits. 1304 Permissions FileMode 1305 1306 // GID is the owning group. 1307 GID GID 1308 } 1309 1310 // decode implements encoder.decode. 1311 func (t *Tmkdir) decode(b *buffer) { 1312 t.Directory = b.ReadFID() 1313 t.Name = b.ReadString() 1314 t.Permissions = b.ReadPermissions() 1315 t.GID = b.ReadGID() 1316 } 1317 1318 // encode implements encoder.encode. 1319 func (t *Tmkdir) encode(b *buffer) { 1320 b.WriteFID(t.Directory) 1321 b.WriteString(t.Name) 1322 b.WritePermissions(t.Permissions) 1323 b.WriteGID(t.GID) 1324 } 1325 1326 // Type implements message.Type. 1327 func (*Tmkdir) Type() MsgType { 1328 return MsgTmkdir 1329 } 1330 1331 // String implements fmt.Stringer. 1332 func (t *Tmkdir) String() string { 1333 return fmt.Sprintf("Tmkdir{DirectoryFID: %d, Name: %s, Permissions: 0o%o, GID: %d}", t.Directory, t.Name, t.Permissions, t.GID) 1334 } 1335 1336 // Rmkdir is a mkdir response. 1337 type Rmkdir struct { 1338 // QID is the resulting QID. 1339 QID QID 1340 } 1341 1342 // decode implements encoder.decode. 1343 func (r *Rmkdir) decode(b *buffer) { 1344 r.QID.decode(b) 1345 } 1346 1347 // encode implements encoder.encode. 1348 func (r *Rmkdir) encode(b *buffer) { 1349 r.QID.encode(b) 1350 } 1351 1352 // Type implements message.Type. 1353 func (*Rmkdir) Type() MsgType { 1354 return MsgRmkdir 1355 } 1356 1357 // String implements fmt.Stringer. 1358 func (r *Rmkdir) String() string { 1359 return fmt.Sprintf("Rmkdir{QID: %s}", r.QID) 1360 } 1361 1362 // Tgetattr is a getattr request. 1363 type Tgetattr struct { 1364 // FID is the FID to get attributes for. 1365 FID FID 1366 1367 // AttrMask is the set of attributes to get. 1368 AttrMask AttrMask 1369 } 1370 1371 // decode implements encoder.decode. 1372 func (t *Tgetattr) decode(b *buffer) { 1373 t.FID = b.ReadFID() 1374 t.AttrMask.decode(b) 1375 } 1376 1377 // encode implements encoder.encode. 1378 func (t *Tgetattr) encode(b *buffer) { 1379 b.WriteFID(t.FID) 1380 t.AttrMask.encode(b) 1381 } 1382 1383 // Type implements message.Type. 1384 func (*Tgetattr) Type() MsgType { 1385 return MsgTgetattr 1386 } 1387 1388 // String implements fmt.Stringer. 1389 func (t *Tgetattr) String() string { 1390 return fmt.Sprintf("Tgetattr{FID: %d, AttrMask: %s}", t.FID, t.AttrMask) 1391 } 1392 1393 // Rgetattr is a getattr response. 1394 type Rgetattr struct { 1395 // Valid indicates which fields are valid. 1396 Valid AttrMask 1397 1398 // QID is the QID for this file. 1399 QID 1400 1401 // Attr is the set of attributes. 1402 Attr Attr 1403 } 1404 1405 // decode implements encoder.decode. 1406 func (r *Rgetattr) decode(b *buffer) { 1407 r.Valid.decode(b) 1408 r.QID.decode(b) 1409 r.Attr.decode(b) 1410 } 1411 1412 // encode implements encoder.encode. 1413 func (r *Rgetattr) encode(b *buffer) { 1414 r.Valid.encode(b) 1415 r.QID.encode(b) 1416 r.Attr.encode(b) 1417 } 1418 1419 // Type implements message.Type. 1420 func (*Rgetattr) Type() MsgType { 1421 return MsgRgetattr 1422 } 1423 1424 // String implements fmt.Stringer. 1425 func (r *Rgetattr) String() string { 1426 return fmt.Sprintf("Rgetattr{Valid: %v, QID: %s, Attr: %s}", r.Valid, r.QID, r.Attr) 1427 } 1428 1429 // Tsetattr is a setattr request. 1430 type Tsetattr struct { 1431 // FID is the FID to change. 1432 FID FID 1433 1434 // Valid is the set of bits which will be used. 1435 Valid SetAttrMask 1436 1437 // SetAttr is the set request. 1438 SetAttr SetAttr 1439 } 1440 1441 // decode implements encoder.decode. 1442 func (t *Tsetattr) decode(b *buffer) { 1443 t.FID = b.ReadFID() 1444 t.Valid.decode(b) 1445 t.SetAttr.decode(b) 1446 } 1447 1448 // encode implements encoder.encode. 1449 func (t *Tsetattr) encode(b *buffer) { 1450 b.WriteFID(t.FID) 1451 t.Valid.encode(b) 1452 t.SetAttr.encode(b) 1453 } 1454 1455 // Type implements message.Type. 1456 func (*Tsetattr) Type() MsgType { 1457 return MsgTsetattr 1458 } 1459 1460 // String implements fmt.Stringer. 1461 func (t *Tsetattr) String() string { 1462 return fmt.Sprintf("Tsetattr{FID: %d, Valid: %v, SetAttr: %s}", t.FID, t.Valid, t.SetAttr) 1463 } 1464 1465 // Rsetattr is a setattr response. 1466 type Rsetattr struct { 1467 } 1468 1469 // decode implements encoder.decode. 1470 func (*Rsetattr) decode(*buffer) { 1471 } 1472 1473 // encode implements encoder.encode. 1474 func (*Rsetattr) encode(*buffer) { 1475 } 1476 1477 // Type implements message.Type. 1478 func (*Rsetattr) Type() MsgType { 1479 return MsgRsetattr 1480 } 1481 1482 // String implements fmt.Stringer. 1483 func (r *Rsetattr) String() string { 1484 return "Rsetattr{}" 1485 } 1486 1487 // Tallocate is an allocate request. This is an extension to 9P protocol, not 1488 // present in the 9P2000.L standard. 1489 type Tallocate struct { 1490 FID FID 1491 Mode AllocateMode 1492 Offset uint64 1493 Length uint64 1494 } 1495 1496 // decode implements encoder.decode. 1497 func (t *Tallocate) decode(b *buffer) { 1498 t.FID = b.ReadFID() 1499 t.Mode.decode(b) 1500 t.Offset = b.Read64() 1501 t.Length = b.Read64() 1502 } 1503 1504 // encode implements encoder.encode. 1505 func (t *Tallocate) encode(b *buffer) { 1506 b.WriteFID(t.FID) 1507 t.Mode.encode(b) 1508 b.Write64(t.Offset) 1509 b.Write64(t.Length) 1510 } 1511 1512 // Type implements message.Type. 1513 func (*Tallocate) Type() MsgType { 1514 return MsgTallocate 1515 } 1516 1517 // String implements fmt.Stringer. 1518 func (t *Tallocate) String() string { 1519 return fmt.Sprintf("Tallocate{FID: %d, Offset: %d, Length: %d}", t.FID, t.Offset, t.Length) 1520 } 1521 1522 // Rallocate is an allocate response. 1523 type Rallocate struct { 1524 } 1525 1526 // decode implements encoder.decode. 1527 func (*Rallocate) decode(*buffer) { 1528 } 1529 1530 // encode implements encoder.encode. 1531 func (*Rallocate) encode(*buffer) { 1532 } 1533 1534 // Type implements message.Type. 1535 func (*Rallocate) Type() MsgType { 1536 return MsgRallocate 1537 } 1538 1539 // String implements fmt.Stringer. 1540 func (r *Rallocate) String() string { 1541 return "Rallocate{}" 1542 } 1543 1544 // Tlistxattr is a listxattr request. 1545 type Tlistxattr struct { 1546 // FID refers to the file on which to list xattrs. 1547 FID FID 1548 1549 // Size is the buffer size for the xattr list. 1550 Size uint64 1551 } 1552 1553 // decode implements encoder.decode. 1554 func (t *Tlistxattr) decode(b *buffer) { 1555 t.FID = b.ReadFID() 1556 t.Size = b.Read64() 1557 } 1558 1559 // encode implements encoder.encode. 1560 func (t *Tlistxattr) encode(b *buffer) { 1561 b.WriteFID(t.FID) 1562 b.Write64(t.Size) 1563 } 1564 1565 // Type implements message.Type. 1566 func (*Tlistxattr) Type() MsgType { 1567 return MsgTlistxattr 1568 } 1569 1570 // String implements fmt.Stringer. 1571 func (t *Tlistxattr) String() string { 1572 return fmt.Sprintf("Tlistxattr{FID: %d, Size: %d}", t.FID, t.Size) 1573 } 1574 1575 // Rlistxattr is a listxattr response. 1576 type Rlistxattr struct { 1577 // Xattrs is a list of extended attribute names. 1578 Xattrs []string 1579 } 1580 1581 // decode implements encoder.decode. 1582 func (r *Rlistxattr) decode(b *buffer) { 1583 n := b.Read16() 1584 r.Xattrs = r.Xattrs[:0] 1585 for i := 0; i < int(n); i++ { 1586 r.Xattrs = append(r.Xattrs, b.ReadString()) 1587 } 1588 } 1589 1590 // encode implements encoder.encode. 1591 func (r *Rlistxattr) encode(b *buffer) { 1592 b.Write16(uint16(len(r.Xattrs))) 1593 for _, x := range r.Xattrs { 1594 b.WriteString(x) 1595 } 1596 } 1597 1598 // Type implements message.Type. 1599 func (*Rlistxattr) Type() MsgType { 1600 return MsgRlistxattr 1601 } 1602 1603 // String implements fmt.Stringer. 1604 func (r *Rlistxattr) String() string { 1605 return fmt.Sprintf("Rlistxattr{Xattrs: %v}", r.Xattrs) 1606 } 1607 1608 // Txattrwalk walks extended attributes. 1609 type Txattrwalk struct { 1610 // FID is the FID to check for attributes. 1611 FID FID 1612 1613 // NewFID is the new FID associated with the attributes. 1614 NewFID FID 1615 1616 // Name is the attribute name. 1617 Name string 1618 } 1619 1620 // decode implements encoder.decode. 1621 func (t *Txattrwalk) decode(b *buffer) { 1622 t.FID = b.ReadFID() 1623 t.NewFID = b.ReadFID() 1624 t.Name = b.ReadString() 1625 } 1626 1627 // encode implements encoder.encode. 1628 func (t *Txattrwalk) encode(b *buffer) { 1629 b.WriteFID(t.FID) 1630 b.WriteFID(t.NewFID) 1631 b.WriteString(t.Name) 1632 } 1633 1634 // Type implements message.Type. 1635 func (*Txattrwalk) Type() MsgType { 1636 return MsgTxattrwalk 1637 } 1638 1639 // String implements fmt.Stringer. 1640 func (t *Txattrwalk) String() string { 1641 return fmt.Sprintf("Txattrwalk{FID: %d, NewFID: %d, Name: %s}", t.FID, t.NewFID, t.Name) 1642 } 1643 1644 // Rxattrwalk is a xattrwalk response. 1645 type Rxattrwalk struct { 1646 // Size is the size of the extended attribute. 1647 Size uint64 1648 } 1649 1650 // decode implements encoder.decode. 1651 func (r *Rxattrwalk) decode(b *buffer) { 1652 r.Size = b.Read64() 1653 } 1654 1655 // encode implements encoder.encode. 1656 func (r *Rxattrwalk) encode(b *buffer) { 1657 b.Write64(r.Size) 1658 } 1659 1660 // Type implements message.Type. 1661 func (*Rxattrwalk) Type() MsgType { 1662 return MsgRxattrwalk 1663 } 1664 1665 // String implements fmt.Stringer. 1666 func (r *Rxattrwalk) String() string { 1667 return fmt.Sprintf("Rxattrwalk{Size: %d}", r.Size) 1668 } 1669 1670 // Txattrcreate prepare to set extended attributes. 1671 type Txattrcreate struct { 1672 // FID is input/output parameter, it identifies the file on which 1673 // extended attributes will be set but after successful Rxattrcreate 1674 // it is used to write the extended attribute value. 1675 FID FID 1676 1677 // Name is the attribute name. 1678 Name string 1679 1680 // Size of the attribute value. When the FID is clunked it has to match 1681 // the number of bytes written to the FID. 1682 AttrSize uint64 1683 1684 // Linux setxattr(2) flags. 1685 Flags uint32 1686 } 1687 1688 // decode implements encoder.decode. 1689 func (t *Txattrcreate) decode(b *buffer) { 1690 t.FID = b.ReadFID() 1691 t.Name = b.ReadString() 1692 t.AttrSize = b.Read64() 1693 t.Flags = b.Read32() 1694 } 1695 1696 // encode implements encoder.encode. 1697 func (t *Txattrcreate) encode(b *buffer) { 1698 b.WriteFID(t.FID) 1699 b.WriteString(t.Name) 1700 b.Write64(t.AttrSize) 1701 b.Write32(t.Flags) 1702 } 1703 1704 // Type implements message.Type. 1705 func (*Txattrcreate) Type() MsgType { 1706 return MsgTxattrcreate 1707 } 1708 1709 // String implements fmt.Stringer. 1710 func (t *Txattrcreate) String() string { 1711 return fmt.Sprintf("Txattrcreate{FID: %d, Name: %s, AttrSize: %d, Flags: %d}", t.FID, t.Name, t.AttrSize, t.Flags) 1712 } 1713 1714 // Rxattrcreate is a xattrcreate response. 1715 type Rxattrcreate struct { 1716 } 1717 1718 // decode implements encoder.decode. 1719 func (r *Rxattrcreate) decode(*buffer) { 1720 } 1721 1722 // encode implements encoder.encode. 1723 func (r *Rxattrcreate) encode(*buffer) { 1724 } 1725 1726 // Type implements message.Type. 1727 func (*Rxattrcreate) Type() MsgType { 1728 return MsgRxattrcreate 1729 } 1730 1731 // String implements fmt.Stringer. 1732 func (r *Rxattrcreate) String() string { 1733 return "Rxattrcreate{}" 1734 } 1735 1736 // Tgetxattr is a getxattr request. 1737 type Tgetxattr struct { 1738 // FID refers to the file for which to get xattrs. 1739 FID FID 1740 1741 // Name is the xattr to get. 1742 Name string 1743 1744 // Size is the buffer size for the xattr to get. 1745 Size uint64 1746 } 1747 1748 // decode implements encoder.decode. 1749 func (t *Tgetxattr) decode(b *buffer) { 1750 t.FID = b.ReadFID() 1751 t.Name = b.ReadString() 1752 t.Size = b.Read64() 1753 } 1754 1755 // encode implements encoder.encode. 1756 func (t *Tgetxattr) encode(b *buffer) { 1757 b.WriteFID(t.FID) 1758 b.WriteString(t.Name) 1759 b.Write64(t.Size) 1760 } 1761 1762 // Type implements message.Type. 1763 func (*Tgetxattr) Type() MsgType { 1764 return MsgTgetxattr 1765 } 1766 1767 // String implements fmt.Stringer. 1768 func (t *Tgetxattr) String() string { 1769 return fmt.Sprintf("Tgetxattr{FID: %d, Name: %s, Size: %d}", t.FID, t.Name, t.Size) 1770 } 1771 1772 // Rgetxattr is a getxattr response. 1773 type Rgetxattr struct { 1774 // Value is the extended attribute value. 1775 Value string 1776 } 1777 1778 // decode implements encoder.decode. 1779 func (r *Rgetxattr) decode(b *buffer) { 1780 r.Value = b.ReadString() 1781 } 1782 1783 // encode implements encoder.encode. 1784 func (r *Rgetxattr) encode(b *buffer) { 1785 b.WriteString(r.Value) 1786 } 1787 1788 // Type implements message.Type. 1789 func (*Rgetxattr) Type() MsgType { 1790 return MsgRgetxattr 1791 } 1792 1793 // String implements fmt.Stringer. 1794 func (r *Rgetxattr) String() string { 1795 return fmt.Sprintf("Rgetxattr{Value: %s}", r.Value) 1796 } 1797 1798 // Tsetxattr sets extended attributes. 1799 type Tsetxattr struct { 1800 // FID refers to the file on which to set xattrs. 1801 FID FID 1802 1803 // Name is the attribute name. 1804 Name string 1805 1806 // Value is the attribute value. 1807 Value string 1808 1809 // Linux setxattr(2) flags. 1810 Flags uint32 1811 } 1812 1813 // decode implements encoder.decode. 1814 func (t *Tsetxattr) decode(b *buffer) { 1815 t.FID = b.ReadFID() 1816 t.Name = b.ReadString() 1817 t.Value = b.ReadString() 1818 t.Flags = b.Read32() 1819 } 1820 1821 // encode implements encoder.encode. 1822 func (t *Tsetxattr) encode(b *buffer) { 1823 b.WriteFID(t.FID) 1824 b.WriteString(t.Name) 1825 b.WriteString(t.Value) 1826 b.Write32(t.Flags) 1827 } 1828 1829 // Type implements message.Type. 1830 func (*Tsetxattr) Type() MsgType { 1831 return MsgTsetxattr 1832 } 1833 1834 // String implements fmt.Stringer. 1835 func (t *Tsetxattr) String() string { 1836 return fmt.Sprintf("Tsetxattr{FID: %d, Name: %s, Value: %s, Flags: %d}", t.FID, t.Name, t.Value, t.Flags) 1837 } 1838 1839 // Rsetxattr is a setxattr response. 1840 type Rsetxattr struct { 1841 } 1842 1843 // decode implements encoder.decode. 1844 func (r *Rsetxattr) decode(*buffer) { 1845 } 1846 1847 // encode implements encoder.encode. 1848 func (r *Rsetxattr) encode(*buffer) { 1849 } 1850 1851 // Type implements message.Type. 1852 func (*Rsetxattr) Type() MsgType { 1853 return MsgRsetxattr 1854 } 1855 1856 // String implements fmt.Stringer. 1857 func (r *Rsetxattr) String() string { 1858 return "Rsetxattr{}" 1859 } 1860 1861 // Tremovexattr is a removexattr request. 1862 type Tremovexattr struct { 1863 // FID refers to the file on which to set xattrs. 1864 FID FID 1865 1866 // Name is the attribute name. 1867 Name string 1868 } 1869 1870 // decode implements encoder.decode. 1871 func (t *Tremovexattr) decode(b *buffer) { 1872 t.FID = b.ReadFID() 1873 t.Name = b.ReadString() 1874 } 1875 1876 // encode implements encoder.encode. 1877 func (t *Tremovexattr) encode(b *buffer) { 1878 b.WriteFID(t.FID) 1879 b.WriteString(t.Name) 1880 } 1881 1882 // Type implements message.Type. 1883 func (*Tremovexattr) Type() MsgType { 1884 return MsgTremovexattr 1885 } 1886 1887 // String implements fmt.Stringer. 1888 func (t *Tremovexattr) String() string { 1889 return fmt.Sprintf("Tremovexattr{FID: %d, Name: %s}", t.FID, t.Name) 1890 } 1891 1892 // Rremovexattr is a removexattr response. 1893 type Rremovexattr struct { 1894 } 1895 1896 // decode implements encoder.decode. 1897 func (r *Rremovexattr) decode(*buffer) { 1898 } 1899 1900 // encode implements encoder.encode. 1901 func (r *Rremovexattr) encode(*buffer) { 1902 } 1903 1904 // Type implements message.Type. 1905 func (*Rremovexattr) Type() MsgType { 1906 return MsgRremovexattr 1907 } 1908 1909 // String implements fmt.Stringer. 1910 func (r *Rremovexattr) String() string { 1911 return "Rremovexattr{}" 1912 } 1913 1914 // Treaddir is a readdir request. 1915 type Treaddir struct { 1916 // Directory is the directory FID to read. 1917 Directory FID 1918 1919 // Offset is the offset to read at. 1920 Offset uint64 1921 1922 // Count is the number of bytes to read. 1923 Count uint32 1924 } 1925 1926 // decode implements encoder.decode. 1927 func (t *Treaddir) decode(b *buffer) { 1928 t.Directory = b.ReadFID() 1929 t.Offset = b.Read64() 1930 t.Count = b.Read32() 1931 } 1932 1933 // encode implements encoder.encode. 1934 func (t *Treaddir) encode(b *buffer) { 1935 b.WriteFID(t.Directory) 1936 b.Write64(t.Offset) 1937 b.Write32(t.Count) 1938 } 1939 1940 // Type implements message.Type. 1941 func (*Treaddir) Type() MsgType { 1942 return MsgTreaddir 1943 } 1944 1945 // String implements fmt.Stringer. 1946 func (t *Treaddir) String() string { 1947 return fmt.Sprintf("Treaddir{DirectoryFID: %d, Offset: %d, Count: %d}", t.Directory, t.Offset, t.Count) 1948 } 1949 1950 // Rreaddir is a readdir response. 1951 type Rreaddir struct { 1952 // Count is the byte limit. 1953 // 1954 // This should always be set from the Treaddir request. 1955 Count uint32 1956 1957 // Entries are the resulting entries. 1958 // 1959 // This may be constructed in decode. 1960 Entries []Dirent 1961 1962 // payload is the encoded payload. 1963 // 1964 // This is constructed by encode. 1965 payload []byte 1966 } 1967 1968 // decode implements encoder.decode. 1969 func (r *Rreaddir) decode(b *buffer) { 1970 r.Count = b.Read32() 1971 entriesBuf := buffer{data: r.payload} 1972 r.Entries = r.Entries[:0] 1973 for { 1974 var d Dirent 1975 d.decode(&entriesBuf) 1976 if entriesBuf.isOverrun() { 1977 // Couldn't decode a complete entry. 1978 break 1979 } 1980 r.Entries = append(r.Entries, d) 1981 } 1982 } 1983 1984 // encode implements encoder.encode. 1985 func (r *Rreaddir) encode(b *buffer) { 1986 entriesBuf := buffer{} 1987 payloadSize := 0 1988 for _, d := range r.Entries { 1989 d.encode(&entriesBuf) 1990 if len(entriesBuf.data) > int(r.Count) { 1991 break 1992 } 1993 payloadSize = len(entriesBuf.data) 1994 } 1995 r.Count = uint32(payloadSize) 1996 r.payload = entriesBuf.data[:payloadSize] 1997 b.Write32(r.Count) 1998 } 1999 2000 // Type implements message.Type. 2001 func (*Rreaddir) Type() MsgType { 2002 return MsgRreaddir 2003 } 2004 2005 // FixedSize implements payloader.FixedSize. 2006 func (*Rreaddir) FixedSize() uint32 { 2007 return 4 2008 } 2009 2010 // Payload implements payloader.Payload. 2011 func (r *Rreaddir) Payload() []byte { 2012 return r.payload 2013 } 2014 2015 // SetPayload implements payloader.SetPayload. 2016 func (r *Rreaddir) SetPayload(p []byte) { 2017 r.payload = p 2018 } 2019 2020 // String implements fmt.Stringer. 2021 func (r *Rreaddir) String() string { 2022 return fmt.Sprintf("Rreaddir{Count: %d, Entries: %s}", r.Count, r.Entries) 2023 } 2024 2025 // Tfsync is an fsync request. 2026 type Tfsync struct { 2027 // FID is the fid to sync. 2028 FID FID 2029 } 2030 2031 // decode implements encoder.decode. 2032 func (t *Tfsync) decode(b *buffer) { 2033 t.FID = b.ReadFID() 2034 } 2035 2036 // encode implements encoder.encode. 2037 func (t *Tfsync) encode(b *buffer) { 2038 b.WriteFID(t.FID) 2039 } 2040 2041 // Type implements message.Type. 2042 func (*Tfsync) Type() MsgType { 2043 return MsgTfsync 2044 } 2045 2046 // String implements fmt.Stringer. 2047 func (t *Tfsync) String() string { 2048 return fmt.Sprintf("Tfsync{FID: %d}", t.FID) 2049 } 2050 2051 // Rfsync is an fsync response. 2052 type Rfsync struct { 2053 } 2054 2055 // decode implements encoder.decode. 2056 func (*Rfsync) decode(*buffer) { 2057 } 2058 2059 // encode implements encoder.encode. 2060 func (*Rfsync) encode(*buffer) { 2061 } 2062 2063 // Type implements message.Type. 2064 func (*Rfsync) Type() MsgType { 2065 return MsgRfsync 2066 } 2067 2068 // String implements fmt.Stringer. 2069 func (r *Rfsync) String() string { 2070 return "Rfsync{}" 2071 } 2072 2073 // Tstatfs is a stat request. 2074 type Tstatfs struct { 2075 // FID is the root. 2076 FID FID 2077 } 2078 2079 // decode implements encoder.decode. 2080 func (t *Tstatfs) decode(b *buffer) { 2081 t.FID = b.ReadFID() 2082 } 2083 2084 // encode implements encoder.encode. 2085 func (t *Tstatfs) encode(b *buffer) { 2086 b.WriteFID(t.FID) 2087 } 2088 2089 // Type implements message.Type. 2090 func (*Tstatfs) Type() MsgType { 2091 return MsgTstatfs 2092 } 2093 2094 // String implements fmt.Stringer. 2095 func (t *Tstatfs) String() string { 2096 return fmt.Sprintf("Tstatfs{FID: %d}", t.FID) 2097 } 2098 2099 // Rstatfs is the response for a Tstatfs. 2100 type Rstatfs struct { 2101 // FSStat is the stat result. 2102 FSStat FSStat 2103 } 2104 2105 // decode implements encoder.decode. 2106 func (r *Rstatfs) decode(b *buffer) { 2107 r.FSStat.decode(b) 2108 } 2109 2110 // encode implements encoder.encode. 2111 func (r *Rstatfs) encode(b *buffer) { 2112 r.FSStat.encode(b) 2113 } 2114 2115 // Type implements message.Type. 2116 func (*Rstatfs) Type() MsgType { 2117 return MsgRstatfs 2118 } 2119 2120 // String implements fmt.Stringer. 2121 func (r *Rstatfs) String() string { 2122 return fmt.Sprintf("Rstatfs{FSStat: %v}", r.FSStat) 2123 } 2124 2125 // Tflushf is a flush file request, not to be confused with Tflush. 2126 type Tflushf struct { 2127 // FID is the FID to be flushed. 2128 FID FID 2129 } 2130 2131 // decode implements encoder.decode. 2132 func (t *Tflushf) decode(b *buffer) { 2133 t.FID = b.ReadFID() 2134 } 2135 2136 // encode implements encoder.encode. 2137 func (t *Tflushf) encode(b *buffer) { 2138 b.WriteFID(t.FID) 2139 } 2140 2141 // Type implements message.Type. 2142 func (*Tflushf) Type() MsgType { 2143 return MsgTflushf 2144 } 2145 2146 // String implements fmt.Stringer. 2147 func (t *Tflushf) String() string { 2148 return fmt.Sprintf("Tflushf{FID: %d}", t.FID) 2149 } 2150 2151 // Rflushf is a flush file response. 2152 type Rflushf struct { 2153 } 2154 2155 // decode implements encoder.decode. 2156 func (*Rflushf) decode(*buffer) { 2157 } 2158 2159 // encode implements encoder.encode. 2160 func (*Rflushf) encode(*buffer) { 2161 } 2162 2163 // Type implements message.Type. 2164 func (*Rflushf) Type() MsgType { 2165 return MsgRflushf 2166 } 2167 2168 // String implements fmt.Stringer. 2169 func (*Rflushf) String() string { 2170 return "Rflushf{}" 2171 } 2172 2173 // Twalkgetattr is a walk request. 2174 type Twalkgetattr struct { 2175 // FID is the FID to be walked. 2176 FID FID 2177 2178 // NewFID is the resulting FID. 2179 NewFID FID 2180 2181 // Names are the set of names to be walked. 2182 Names []string 2183 } 2184 2185 // decode implements encoder.decode. 2186 func (t *Twalkgetattr) decode(b *buffer) { 2187 t.FID = b.ReadFID() 2188 t.NewFID = b.ReadFID() 2189 n := b.Read16() 2190 t.Names = t.Names[:0] 2191 for i := 0; i < int(n); i++ { 2192 t.Names = append(t.Names, b.ReadString()) 2193 } 2194 } 2195 2196 // encode implements encoder.encode. 2197 func (t *Twalkgetattr) encode(b *buffer) { 2198 b.WriteFID(t.FID) 2199 b.WriteFID(t.NewFID) 2200 b.Write16(uint16(len(t.Names))) 2201 for _, name := range t.Names { 2202 b.WriteString(name) 2203 } 2204 } 2205 2206 // Type implements message.Type. 2207 func (*Twalkgetattr) Type() MsgType { 2208 return MsgTwalkgetattr 2209 } 2210 2211 // String implements fmt.Stringer. 2212 func (t *Twalkgetattr) String() string { 2213 return fmt.Sprintf("Twalkgetattr{FID: %d, NewFID: %d, Names: %v}", t.FID, t.NewFID, t.Names) 2214 } 2215 2216 // Rwalkgetattr is a walk response. 2217 type Rwalkgetattr struct { 2218 // Valid indicates which fields are valid in the Attr below. 2219 Valid AttrMask 2220 2221 // Attr is the set of attributes for the last QID (the file walked to). 2222 Attr Attr 2223 2224 // QIDs are the set of QIDs returned. 2225 QIDs []QID 2226 } 2227 2228 // decode implements encoder.decode. 2229 func (r *Rwalkgetattr) decode(b *buffer) { 2230 r.Valid.decode(b) 2231 r.Attr.decode(b) 2232 n := b.Read16() 2233 r.QIDs = r.QIDs[:0] 2234 for i := 0; i < int(n); i++ { 2235 var q QID 2236 q.decode(b) 2237 r.QIDs = append(r.QIDs, q) 2238 } 2239 } 2240 2241 // encode implements encoder.encode. 2242 func (r *Rwalkgetattr) encode(b *buffer) { 2243 r.Valid.encode(b) 2244 r.Attr.encode(b) 2245 b.Write16(uint16(len(r.QIDs))) 2246 for i := range r.QIDs { 2247 r.QIDs[i].encode(b) 2248 } 2249 } 2250 2251 // Type implements message.Type. 2252 func (*Rwalkgetattr) Type() MsgType { 2253 return MsgRwalkgetattr 2254 } 2255 2256 // String implements fmt.Stringer. 2257 func (r *Rwalkgetattr) String() string { 2258 return fmt.Sprintf("Rwalkgetattr{Valid: %s, Attr: %s, QIDs: %v}", r.Valid, r.Attr, r.QIDs) 2259 } 2260 2261 // Tucreate is a Tlcreate message that includes a UID. 2262 type Tucreate struct { 2263 Tlcreate 2264 2265 // UID is the UID to use as the effective UID in creation messages. 2266 UID UID 2267 } 2268 2269 // decode implements encoder.decode. 2270 func (t *Tucreate) decode(b *buffer) { 2271 t.Tlcreate.decode(b) 2272 t.UID = b.ReadUID() 2273 } 2274 2275 // encode implements encoder.encode. 2276 func (t *Tucreate) encode(b *buffer) { 2277 t.Tlcreate.encode(b) 2278 b.WriteUID(t.UID) 2279 } 2280 2281 // Type implements message.Type. 2282 func (t *Tucreate) Type() MsgType { 2283 return MsgTucreate 2284 } 2285 2286 // String implements fmt.Stringer. 2287 func (t *Tucreate) String() string { 2288 return fmt.Sprintf("Tucreate{Tlcreate: %v, UID: %d}", &t.Tlcreate, t.UID) 2289 } 2290 2291 // Rucreate is a file creation response. 2292 type Rucreate struct { 2293 Rlcreate 2294 } 2295 2296 // Type implements message.Type. 2297 func (*Rucreate) Type() MsgType { 2298 return MsgRucreate 2299 } 2300 2301 // String implements fmt.Stringer. 2302 func (r *Rucreate) String() string { 2303 return fmt.Sprintf("Rucreate{%v}", &r.Rlcreate) 2304 } 2305 2306 // Tumkdir is a Tmkdir message that includes a UID. 2307 type Tumkdir struct { 2308 Tmkdir 2309 2310 // UID is the UID to use as the effective UID in creation messages. 2311 UID UID 2312 } 2313 2314 // decode implements encoder.decode. 2315 func (t *Tumkdir) decode(b *buffer) { 2316 t.Tmkdir.decode(b) 2317 t.UID = b.ReadUID() 2318 } 2319 2320 // encode implements encoder.encode. 2321 func (t *Tumkdir) encode(b *buffer) { 2322 t.Tmkdir.encode(b) 2323 b.WriteUID(t.UID) 2324 } 2325 2326 // Type implements message.Type. 2327 func (t *Tumkdir) Type() MsgType { 2328 return MsgTumkdir 2329 } 2330 2331 // String implements fmt.Stringer. 2332 func (t *Tumkdir) String() string { 2333 return fmt.Sprintf("Tumkdir{Tmkdir: %v, UID: %d}", &t.Tmkdir, t.UID) 2334 } 2335 2336 // Rumkdir is a umkdir response. 2337 type Rumkdir struct { 2338 Rmkdir 2339 } 2340 2341 // Type implements message.Type. 2342 func (*Rumkdir) Type() MsgType { 2343 return MsgRumkdir 2344 } 2345 2346 // String implements fmt.Stringer. 2347 func (r *Rumkdir) String() string { 2348 return fmt.Sprintf("Rumkdir{%v}", &r.Rmkdir) 2349 } 2350 2351 // Tumknod is a Tmknod message that includes a UID. 2352 type Tumknod struct { 2353 Tmknod 2354 2355 // UID is the UID to use as the effective UID in creation messages. 2356 UID UID 2357 } 2358 2359 // decode implements encoder.decode. 2360 func (t *Tumknod) decode(b *buffer) { 2361 t.Tmknod.decode(b) 2362 t.UID = b.ReadUID() 2363 } 2364 2365 // encode implements encoder.encode. 2366 func (t *Tumknod) encode(b *buffer) { 2367 t.Tmknod.encode(b) 2368 b.WriteUID(t.UID) 2369 } 2370 2371 // Type implements message.Type. 2372 func (t *Tumknod) Type() MsgType { 2373 return MsgTumknod 2374 } 2375 2376 // String implements fmt.Stringer. 2377 func (t *Tumknod) String() string { 2378 return fmt.Sprintf("Tumknod{Tmknod: %v, UID: %d}", &t.Tmknod, t.UID) 2379 } 2380 2381 // Rumknod is a umknod response. 2382 type Rumknod struct { 2383 Rmknod 2384 } 2385 2386 // Type implements message.Type. 2387 func (*Rumknod) Type() MsgType { 2388 return MsgRumknod 2389 } 2390 2391 // String implements fmt.Stringer. 2392 func (r *Rumknod) String() string { 2393 return fmt.Sprintf("Rumknod{%v}", &r.Rmknod) 2394 } 2395 2396 // Tusymlink is a Tsymlink message that includes a UID. 2397 type Tusymlink struct { 2398 Tsymlink 2399 2400 // UID is the UID to use as the effective UID in creation messages. 2401 UID UID 2402 } 2403 2404 // decode implements encoder.decode. 2405 func (t *Tusymlink) decode(b *buffer) { 2406 t.Tsymlink.decode(b) 2407 t.UID = b.ReadUID() 2408 } 2409 2410 // encode implements encoder.encode. 2411 func (t *Tusymlink) encode(b *buffer) { 2412 t.Tsymlink.encode(b) 2413 b.WriteUID(t.UID) 2414 } 2415 2416 // Type implements message.Type. 2417 func (t *Tusymlink) Type() MsgType { 2418 return MsgTusymlink 2419 } 2420 2421 // String implements fmt.Stringer. 2422 func (t *Tusymlink) String() string { 2423 return fmt.Sprintf("Tusymlink{Tsymlink: %v, UID: %d}", &t.Tsymlink, t.UID) 2424 } 2425 2426 // Rusymlink is a usymlink response. 2427 type Rusymlink struct { 2428 Rsymlink 2429 } 2430 2431 // Type implements message.Type. 2432 func (*Rusymlink) Type() MsgType { 2433 return MsgRusymlink 2434 } 2435 2436 // String implements fmt.Stringer. 2437 func (r *Rusymlink) String() string { 2438 return fmt.Sprintf("Rusymlink{%v}", &r.Rsymlink) 2439 } 2440 2441 // Tlconnect is a connect request. 2442 type Tlconnect struct { 2443 // FID is the FID to be connected. 2444 FID FID 2445 2446 // Flags are the connect flags. 2447 Flags ConnectFlags 2448 } 2449 2450 // decode implements encoder.decode. 2451 func (t *Tlconnect) decode(b *buffer) { 2452 t.FID = b.ReadFID() 2453 t.Flags = b.ReadConnectFlags() 2454 } 2455 2456 // encode implements encoder.encode. 2457 func (t *Tlconnect) encode(b *buffer) { 2458 b.WriteFID(t.FID) 2459 b.WriteConnectFlags(t.Flags) 2460 } 2461 2462 // Type implements message.Type. 2463 func (*Tlconnect) Type() MsgType { 2464 return MsgTlconnect 2465 } 2466 2467 // String implements fmt.Stringer. 2468 func (t *Tlconnect) String() string { 2469 return fmt.Sprintf("Tlconnect{FID: %d, Flags: %v}", t.FID, t.Flags) 2470 } 2471 2472 // Rlconnect is a connect response. 2473 type Rlconnect struct { 2474 filePayload 2475 } 2476 2477 // decode implements encoder.decode. 2478 func (r *Rlconnect) decode(*buffer) {} 2479 2480 // encode implements encoder.encode. 2481 func (r *Rlconnect) encode(*buffer) {} 2482 2483 // Type implements message.Type. 2484 func (*Rlconnect) Type() MsgType { 2485 return MsgRlconnect 2486 } 2487 2488 // String implements fmt.Stringer. 2489 func (r *Rlconnect) String() string { 2490 return fmt.Sprintf("Rlconnect{File: %v}", r.File) 2491 } 2492 2493 // Tchannel creates a new channel. 2494 type Tchannel struct { 2495 // ID is the channel ID. 2496 ID uint32 2497 2498 // Control is 0 if the Rchannel response should provide the flipcall 2499 // component of the channel, and 1 if the Rchannel response should 2500 // provide the fdchannel component of the channel. 2501 Control uint32 2502 } 2503 2504 // decode implements encoder.decode. 2505 func (t *Tchannel) decode(b *buffer) { 2506 t.ID = b.Read32() 2507 t.Control = b.Read32() 2508 } 2509 2510 // encode implements encoder.encode. 2511 func (t *Tchannel) encode(b *buffer) { 2512 b.Write32(t.ID) 2513 b.Write32(t.Control) 2514 } 2515 2516 // Type implements message.Type. 2517 func (*Tchannel) Type() MsgType { 2518 return MsgTchannel 2519 } 2520 2521 // String implements fmt.Stringer. 2522 func (t *Tchannel) String() string { 2523 return fmt.Sprintf("Tchannel{ID: %d, Control: %d}", t.ID, t.Control) 2524 } 2525 2526 // Rchannel is the channel response. 2527 type Rchannel struct { 2528 Offset uint64 2529 Length uint64 2530 filePayload 2531 } 2532 2533 // decode implements encoder.decode. 2534 func (r *Rchannel) decode(b *buffer) { 2535 r.Offset = b.Read64() 2536 r.Length = b.Read64() 2537 } 2538 2539 // encode implements encoder.encode. 2540 func (r *Rchannel) encode(b *buffer) { 2541 b.Write64(r.Offset) 2542 b.Write64(r.Length) 2543 } 2544 2545 // Type implements message.Type. 2546 func (*Rchannel) Type() MsgType { 2547 return MsgRchannel 2548 } 2549 2550 // String implements fmt.Stringer. 2551 func (r *Rchannel) String() string { 2552 return fmt.Sprintf("Rchannel{Offset: %d, Length: %d}", r.Offset, r.Length) 2553 } 2554 2555 // Tmultigetattr is a multi-getattr request. 2556 type Tmultigetattr struct { 2557 // FID is the FID to be walked. 2558 FID FID 2559 2560 // Names are the set of names to be walked. 2561 Names []string 2562 } 2563 2564 // decode implements encoder.decode. 2565 func (t *Tmultigetattr) decode(b *buffer) { 2566 t.FID = b.ReadFID() 2567 n := b.Read16() 2568 t.Names = t.Names[:0] 2569 for i := 0; i < int(n); i++ { 2570 t.Names = append(t.Names, b.ReadString()) 2571 } 2572 } 2573 2574 // encode implements encoder.encode. 2575 func (t *Tmultigetattr) encode(b *buffer) { 2576 b.WriteFID(t.FID) 2577 b.Write16(uint16(len(t.Names))) 2578 for _, name := range t.Names { 2579 b.WriteString(name) 2580 } 2581 } 2582 2583 // Type implements message.Type. 2584 func (*Tmultigetattr) Type() MsgType { 2585 return MsgTmultigetattr 2586 } 2587 2588 // String implements fmt.Stringer. 2589 func (t *Tmultigetattr) String() string { 2590 return fmt.Sprintf("Tmultigetattr{FID: %d, Names: %v}", t.FID, t.Names) 2591 } 2592 2593 // Rmultigetattr is a multi-getattr response. 2594 type Rmultigetattr struct { 2595 // Stats are the set of FullStat returned for each of the names in the 2596 // request. 2597 Stats []FullStat 2598 } 2599 2600 // decode implements encoder.decode. 2601 func (r *Rmultigetattr) decode(b *buffer) { 2602 n := b.Read16() 2603 r.Stats = r.Stats[:0] 2604 for i := 0; i < int(n); i++ { 2605 var fs FullStat 2606 fs.decode(b) 2607 r.Stats = append(r.Stats, fs) 2608 } 2609 } 2610 2611 // encode implements encoder.encode. 2612 func (r *Rmultigetattr) encode(b *buffer) { 2613 b.Write16(uint16(len(r.Stats))) 2614 for i := range r.Stats { 2615 r.Stats[i].encode(b) 2616 } 2617 } 2618 2619 // Type implements message.Type. 2620 func (*Rmultigetattr) Type() MsgType { 2621 return MsgRmultigetattr 2622 } 2623 2624 // String implements fmt.Stringer. 2625 func (r *Rmultigetattr) String() string { 2626 return fmt.Sprintf("Rmultigetattr{Stats: %v}", r.Stats) 2627 } 2628 2629 const maxCacheSize = 3 2630 2631 // msgFactory is used to reduce allocations by caching messages for reuse. 2632 type msgFactory struct { 2633 create func() message 2634 cache chan message 2635 } 2636 2637 // msgRegistry indexes all message factories by type. 2638 var msgRegistry registry 2639 2640 type registry struct { 2641 factories [math.MaxUint8 + 1]msgFactory 2642 2643 // largestFixedSize is computed so that given some message size M, you can 2644 // compute the maximum payload size (e.g. for Twrite, Rread) with 2645 // M-largestFixedSize. You could do this individual on a per-message basis, 2646 // but it's easier to compute a single maximum safe payload. 2647 largestFixedSize uint32 2648 } 2649 2650 // get returns a new message by type. 2651 // 2652 // An error is returned in the case of an unknown message. 2653 // 2654 // This takes, and ignores, a message tag so that it may be used directly as a 2655 // lookupTagAndType function for recv (by design). 2656 func (r *registry) get(_ Tag, t MsgType) (message, error) { 2657 entry := &r.factories[t] 2658 if entry.create == nil { 2659 return nil, &ErrInvalidMsgType{t} 2660 } 2661 2662 select { 2663 case msg := <-entry.cache: 2664 return msg, nil 2665 default: 2666 return entry.create(), nil 2667 } 2668 } 2669 2670 func (r *registry) put(msg message) { 2671 if p, ok := msg.(payloader); ok { 2672 p.SetPayload(nil) 2673 } 2674 if f, ok := msg.(filer); ok { 2675 f.SetFilePayload(nil) 2676 } 2677 2678 entry := &r.factories[msg.Type()] 2679 select { 2680 case entry.cache <- msg: 2681 default: 2682 } 2683 } 2684 2685 // register registers the given message type. 2686 // 2687 // This may cause panic on failure and should only be used from init. 2688 func (r *registry) register(t MsgType, fn func() message) { 2689 if int(t) >= len(r.factories) { 2690 panic(fmt.Sprintf("message type %d is too large. It must be smaller than %d", t, len(r.factories))) 2691 } 2692 if r.factories[t].create != nil { 2693 panic(fmt.Sprintf("duplicate message type %d: first is %T, second is %T", t, r.factories[t].create(), fn())) 2694 } 2695 r.factories[t] = msgFactory{ 2696 create: fn, 2697 cache: make(chan message, maxCacheSize), 2698 } 2699 2700 if size := calculateSize(fn()); size > r.largestFixedSize { 2701 r.largestFixedSize = size 2702 } 2703 } 2704 2705 func calculateSize(m message) uint32 { 2706 if p, ok := m.(payloader); ok { 2707 return p.FixedSize() 2708 } 2709 var dataBuf buffer 2710 m.encode(&dataBuf) 2711 return uint32(len(dataBuf.data)) 2712 } 2713 2714 func init() { 2715 msgRegistry.register(MsgRlerror, func() message { return &Rlerror{} }) 2716 msgRegistry.register(MsgTstatfs, func() message { return &Tstatfs{} }) 2717 msgRegistry.register(MsgRstatfs, func() message { return &Rstatfs{} }) 2718 msgRegistry.register(MsgTlopen, func() message { return &Tlopen{} }) 2719 msgRegistry.register(MsgRlopen, func() message { return &Rlopen{} }) 2720 msgRegistry.register(MsgTlcreate, func() message { return &Tlcreate{} }) 2721 msgRegistry.register(MsgRlcreate, func() message { return &Rlcreate{} }) 2722 msgRegistry.register(MsgTsymlink, func() message { return &Tsymlink{} }) 2723 msgRegistry.register(MsgRsymlink, func() message { return &Rsymlink{} }) 2724 msgRegistry.register(MsgTmknod, func() message { return &Tmknod{} }) 2725 msgRegistry.register(MsgRmknod, func() message { return &Rmknod{} }) 2726 msgRegistry.register(MsgTrename, func() message { return &Trename{} }) 2727 msgRegistry.register(MsgRrename, func() message { return &Rrename{} }) 2728 msgRegistry.register(MsgTreadlink, func() message { return &Treadlink{} }) 2729 msgRegistry.register(MsgRreadlink, func() message { return &Rreadlink{} }) 2730 msgRegistry.register(MsgTgetattr, func() message { return &Tgetattr{} }) 2731 msgRegistry.register(MsgRgetattr, func() message { return &Rgetattr{} }) 2732 msgRegistry.register(MsgTsetattr, func() message { return &Tsetattr{} }) 2733 msgRegistry.register(MsgRsetattr, func() message { return &Rsetattr{} }) 2734 msgRegistry.register(MsgTlistxattr, func() message { return &Tlistxattr{} }) 2735 msgRegistry.register(MsgRlistxattr, func() message { return &Rlistxattr{} }) 2736 msgRegistry.register(MsgTxattrwalk, func() message { return &Txattrwalk{} }) 2737 msgRegistry.register(MsgRxattrwalk, func() message { return &Rxattrwalk{} }) 2738 msgRegistry.register(MsgTxattrcreate, func() message { return &Txattrcreate{} }) 2739 msgRegistry.register(MsgRxattrcreate, func() message { return &Rxattrcreate{} }) 2740 msgRegistry.register(MsgTgetxattr, func() message { return &Tgetxattr{} }) 2741 msgRegistry.register(MsgRgetxattr, func() message { return &Rgetxattr{} }) 2742 msgRegistry.register(MsgTsetxattr, func() message { return &Tsetxattr{} }) 2743 msgRegistry.register(MsgRsetxattr, func() message { return &Rsetxattr{} }) 2744 msgRegistry.register(MsgTremovexattr, func() message { return &Tremovexattr{} }) 2745 msgRegistry.register(MsgRremovexattr, func() message { return &Rremovexattr{} }) 2746 msgRegistry.register(MsgTreaddir, func() message { return &Treaddir{} }) 2747 msgRegistry.register(MsgRreaddir, func() message { return &Rreaddir{} }) 2748 msgRegistry.register(MsgTfsync, func() message { return &Tfsync{} }) 2749 msgRegistry.register(MsgRfsync, func() message { return &Rfsync{} }) 2750 msgRegistry.register(MsgTlink, func() message { return &Tlink{} }) 2751 msgRegistry.register(MsgRlink, func() message { return &Rlink{} }) 2752 msgRegistry.register(MsgTmkdir, func() message { return &Tmkdir{} }) 2753 msgRegistry.register(MsgRmkdir, func() message { return &Rmkdir{} }) 2754 msgRegistry.register(MsgTrenameat, func() message { return &Trenameat{} }) 2755 msgRegistry.register(MsgRrenameat, func() message { return &Rrenameat{} }) 2756 msgRegistry.register(MsgTunlinkat, func() message { return &Tunlinkat{} }) 2757 msgRegistry.register(MsgRunlinkat, func() message { return &Runlinkat{} }) 2758 msgRegistry.register(MsgTversion, func() message { return &Tversion{} }) 2759 msgRegistry.register(MsgRversion, func() message { return &Rversion{} }) 2760 msgRegistry.register(MsgTauth, func() message { return &Tauth{} }) 2761 msgRegistry.register(MsgRauth, func() message { return &Rauth{} }) 2762 msgRegistry.register(MsgTattach, func() message { return &Tattach{} }) 2763 msgRegistry.register(MsgRattach, func() message { return &Rattach{} }) 2764 msgRegistry.register(MsgTflush, func() message { return &Tflush{} }) 2765 msgRegistry.register(MsgRflush, func() message { return &Rflush{} }) 2766 msgRegistry.register(MsgTwalk, func() message { return &Twalk{} }) 2767 msgRegistry.register(MsgRwalk, func() message { return &Rwalk{} }) 2768 msgRegistry.register(MsgTread, func() message { return &Tread{} }) 2769 msgRegistry.register(MsgRread, func() message { return &Rread{} }) 2770 msgRegistry.register(MsgTwrite, func() message { return &Twrite{} }) 2771 msgRegistry.register(MsgRwrite, func() message { return &Rwrite{} }) 2772 msgRegistry.register(MsgTclunk, func() message { return &Tclunk{} }) 2773 msgRegistry.register(MsgRclunk, func() message { return &Rclunk{} }) 2774 msgRegistry.register(MsgTremove, func() message { return &Tremove{} }) 2775 msgRegistry.register(MsgRremove, func() message { return &Rremove{} }) 2776 msgRegistry.register(MsgTflushf, func() message { return &Tflushf{} }) 2777 msgRegistry.register(MsgRflushf, func() message { return &Rflushf{} }) 2778 msgRegistry.register(MsgTwalkgetattr, func() message { return &Twalkgetattr{} }) 2779 msgRegistry.register(MsgRwalkgetattr, func() message { return &Rwalkgetattr{} }) 2780 msgRegistry.register(MsgTucreate, func() message { return &Tucreate{} }) 2781 msgRegistry.register(MsgRucreate, func() message { return &Rucreate{} }) 2782 msgRegistry.register(MsgTumkdir, func() message { return &Tumkdir{} }) 2783 msgRegistry.register(MsgRumkdir, func() message { return &Rumkdir{} }) 2784 msgRegistry.register(MsgTumknod, func() message { return &Tumknod{} }) 2785 msgRegistry.register(MsgRumknod, func() message { return &Rumknod{} }) 2786 msgRegistry.register(MsgTusymlink, func() message { return &Tusymlink{} }) 2787 msgRegistry.register(MsgRusymlink, func() message { return &Rusymlink{} }) 2788 msgRegistry.register(MsgTlconnect, func() message { return &Tlconnect{} }) 2789 msgRegistry.register(MsgRlconnect, func() message { return &Rlconnect{} }) 2790 msgRegistry.register(MsgTallocate, func() message { return &Tallocate{} }) 2791 msgRegistry.register(MsgRallocate, func() message { return &Rallocate{} }) 2792 msgRegistry.register(MsgTsetattrclunk, func() message { return &Tsetattrclunk{} }) 2793 msgRegistry.register(MsgRsetattrclunk, func() message { return &Rsetattrclunk{} }) 2794 msgRegistry.register(MsgTmultigetattr, func() message { return &Tmultigetattr{} }) 2795 msgRegistry.register(MsgRmultigetattr, func() message { return &Rmultigetattr{} }) 2796 msgRegistry.register(MsgTchannel, func() message { return &Tchannel{} }) 2797 msgRegistry.register(MsgRchannel, func() message { return &Rchannel{} }) 2798 }