rstyx 0.3.1 → 0.3.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -24,7 +24,7 @@
24
24
  # Copyright:: Copyright (c) 2005,2006 Rafael R. Sevilla
25
25
  # License:: GNU Lesser General Public License
26
26
  #
27
- # $Id: messages.rb 229 2007-08-10 08:03:58Z dido $
27
+ # $Id: messages.rb 242 2007-09-13 08:05:57Z dido $
28
28
  #
29
29
 
30
30
  require 'rstyx/errors'
@@ -36,16 +36,25 @@ module RStyx
36
36
  # Class representing the server's view of a file.
37
37
  #
38
38
  class Qid
39
- attr_accessor :qtype, :version, :path
39
+ ##
40
+ # The type of the file (directory, etc.) represented as a bit vector
41
+ # corresponding to the high 8 bits of the file's mode word.
42
+ attr_accessor :qtype
43
+ ##
44
+ # Version number for given path
45
+ attr_accessor :version
46
+ ##
47
+ # The file server's unique identification for the file
48
+ attr_accessor :path
40
49
 
41
50
  QID_LENGTH = 13 # size of a Qid
42
51
 
43
52
  ##
44
53
  # Create a new Qid object.
45
54
  #
46
- # +type+:: [Fixnum] the type of file (directory, append only file, etc.)
47
- # +version+:: [Fixnum] the version number of the file
48
- # +path+:: [Fixnum] a 64-bit integer that should be unique among all
55
+ # _type_:: [Fixnum] the type of file (directory, append only file, etc.)
56
+ # _version_:: [Fixnum] the version number of the file
57
+ # _path_:: [Fixnum] a 64-bit integer that should be unique among all
49
58
  # files being served
50
59
  #
51
60
  def initialize(type, version, path)
@@ -55,7 +64,7 @@ module RStyx
55
64
  end
56
65
 
57
66
  ##
58
- # Equality
67
+ # Test if two qid's are the same.
59
68
  #
60
69
  def ==(x)
61
70
  return(self.to_bytes == x.to_bytes)
@@ -75,7 +84,7 @@ module RStyx
75
84
  ##
76
85
  # Decode a serialized Qid from its byte string representation
77
86
  #
78
- # +msgbytes+:: [String] the byte string representation of the qid
87
+ # _msgbytes_:: [String] the byte string representation of the qid
79
88
  # return value:: [Qid] the Qid represented by the byte string.
80
89
  # raises:: StyxException if the string cannot be decoded as a Qid
81
90
  #
@@ -105,10 +114,47 @@ module RStyx
105
114
  # stat message). See Inferno man page stat(5) for more details.
106
115
  #
107
116
  class Stat
108
- attr_accessor :size, :dtype, :dev, :qid, :mode, :atime, :mtime
109
- attr_accessor :length, :name, :uid, :gid, :muid
117
+ ##
118
+ # Total byte count of the following data
119
+ attr_accessor :size
120
+ ##
121
+ # For kernel use
122
+ attr_accessor :dtype
123
+ ##
124
+ # For kernel use
125
+ attr_accessor :dev
126
+ ##
127
+ # The Qid of the file represented by the stat object
128
+ attr_accessor :qid
129
+ ##
130
+ # Permissions and flags
131
+ attr_accessor :mode
132
+ ##
133
+ # Last access time
134
+ attr_accessor :atime
135
+ ##
136
+ # Last modification time
137
+ attr_accessor :mtime
138
+ ##
139
+ # Length of the file in bytes
140
+ attr_accessor :length
141
+ ##
142
+ # File name; must be / if the file is the root directory of the server
143
+ attr_accessor :name
144
+ ##
145
+ # Owner name
146
+ #
147
+ attr_accessor :uid
148
+ ##
149
+ # Group name
150
+ attr_accessor :gid
151
+ ##
152
+ # Name of the user who last modified the file
153
+ attr_accessor :muid
110
154
 
111
- def self.strextract(str, offset)
155
+ ##
156
+ # Internal function for extrating strings
157
+ def self.strextract(str, offset) # :nodoc:
112
158
  length = (str[offset..(offset + 1)].unpack("v"))[0]
113
159
  if length.nil?
114
160
  raise StyxException.new("invalid string, no length found")
@@ -148,10 +194,10 @@ module RStyx
148
194
  ##
149
195
  # Unserialize a Stat
150
196
  #
151
- # +bytes+:: [String] serialized string representation of a Stat
197
+ # _bytes_:: [String] serialized string representation of a Stat
152
198
  # return value:: [Stat] the Stat corresponding to the
153
199
  # passed string
154
- # raises:: StyxException if +bytes+ cannot be properly decoded as
200
+ # raises:: StyxException if _bytes_ cannot be properly decoded as
155
201
  # a Stat
156
202
  #
157
203
  def self.from_bytes(bytes)
@@ -213,14 +259,21 @@ module RStyx
213
259
  # Base class of a Styx message.
214
260
  #
215
261
  class StyxMessage
262
+ ##
263
+ # A hash indexed by the field names giving the field values.
264
+ #
216
265
  attr_accessor :fieldvals
266
+ ##
267
+ # A Hash indexed by the class of the message and its identifier
268
+ # number.
269
+ #
217
270
  MESSAGE_IDS = {}
218
271
 
219
272
  ##
220
273
  # Add a field to the StyxMessage. Used by subclasses to define
221
- # the message field. The +name+ should be a Symbol that gives
274
+ # the message field. The _name_ should be a Symbol that gives
222
275
  # the name of the field (preferably the canonical name given in the
223
- # Inferno manual page intro(5)), and the type may be:
276
+ # Inferno manual page intro(5)), and the _type_ may be:
224
277
  #
225
278
  # 1. Any valid format string used by String#unpack or Array#pack.
226
279
  # 2. Cstr, which is a UTF-8 string, which will be serialized as
@@ -236,15 +289,21 @@ module RStyx
236
289
  # a standard Ruby string.
237
290
  # 4. Qid, which deserializes into a Qid object instance and is
238
291
  # serialized into a 13-byte binary representation.
239
- # 5. QidList, which deserializes into an array of Qids and is
240
- # serialized into a two-byte unsigned count of Qids followed
241
- # by the serialized representations of each of the Qids.
292
+ # 5. QidList, which deserializes into an array of Qid objects and is
293
+ # serialized into a two-byte unsigned count of Qid objects followed
294
+ # by the serialized representations of each of the Qid objects.
242
295
  # 6. ULongLong, which deserializes into a Ruby Fixnum and is
243
296
  # serialized into a 64-bit little-endian value.
244
297
  # 7. Stat, which deserializes into a Stat object instance and is
245
298
  # serialized into the stat format described in the Inferno
246
299
  # man page stat(5). See the Stat class for more details.
247
300
  #
301
+ # This method will cause the (sub)class which uses it to have
302
+ # its inherited copy of StyxMessage#fields to receive the name
303
+ # and type declaration, and it will create attribute reader
304
+ # and writer methods of the form _name_ and _name_= to be added
305
+ # to the class.
306
+ #
248
307
  def self.add_field(name, type)
249
308
  self.fields << [name, type]
250
309
 
@@ -260,7 +319,9 @@ module RStyx
260
319
  end
261
320
 
262
321
  ##
263
- # The fields of the Styx message.
322
+ # The fields of the Styx message, which consists of an array of
323
+ # arrays consisting of the field name and the field type (see
324
+ # StyxMessage#add_field for more details).
264
325
  #
265
326
  def self.fields
266
327
  # Default fields (excluding the size[4] field)
@@ -270,6 +331,12 @@ module RStyx
270
331
  ##
271
332
  # Create a new StyxMessage class. This takes a hash of field
272
333
  # names and values, and this is put into a hash.
334
+ #
335
+ # _fieldvals_:: A hash of field values. These values need not be
336
+ # only the values of defined, for the message,
337
+ # but only the values actually defined may be directly
338
+ # accessed and will be serialized.
339
+ #
273
340
  def initialize(fieldvals={})
274
341
  ident = MESSAGE_IDS[self.class]
275
342
  @fieldvals = {:ident=>ident}.merge(fieldvals)
@@ -284,14 +351,15 @@ module RStyx
284
351
  end
285
352
 
286
353
  ##
287
- # Return the tag of the message
354
+ # Return the tag of the message.
288
355
  #
289
356
  def tag
290
357
  return(@fieldvals[:tag])
291
358
  end
292
359
 
293
360
  ##
294
- # Set the tag of the message
361
+ # Set the tag of the message.
362
+ #
295
363
  def tag=(t)
296
364
  return(@fieldvals[:tag] = t)
297
365
  end
@@ -300,6 +368,10 @@ module RStyx
300
368
  # Deserialize a byte string into a StyxMessage subclass of some
301
369
  # kind.
302
370
  #
371
+ # _str_:: A byte string representing a Styx message
372
+ # return value:: The StyxMessage subclass instance represented by _str_
373
+ # raises:: StyxException if there was some error decoding _str_
374
+ #
303
375
  def self.from_bytes(str)
304
376
  origlength = str.length
305
377
  # get the length, identifier, and the rest of the string
@@ -361,7 +433,10 @@ module RStyx
361
433
  end
362
434
 
363
435
  ##
364
- # Serialize a Styx message subclass into a byte string.
436
+ # Serialize a Styx message subclass instance into a byte string.
437
+ #
438
+ # returns:: The serialized String representation of the Styx message
439
+ # subclass instance.
365
440
  #
366
441
  def to_bytes
367
442
  str = ""
@@ -417,6 +492,8 @@ module RStyx
417
492
 
418
493
  ##
419
494
  # Convert a Styx message into a human-readable string.
495
+ #
496
+ # returns:: The Styx message instance converted to a string.
420
497
  def to_s
421
498
  # First, start with the Styx message class name
422
499
  str = "(" + self.class.to_s.split("::")[-1]
@@ -435,16 +512,33 @@ module RStyx
435
512
 
436
513
  ##
437
514
  # Class representing a Tversion message sent by a Styx client.
515
+ # See Inferno's version(5) for more details.
516
+ #
517
+ # === Fields
518
+ #
519
+ # _msize_:: The client-suggested message size, that is the maximum
520
+ # length in bytes that it will ever generate or expect to
521
+ # receive in a single Styx message.
522
+ # _version_:: The version string identifying the level of the protocol
523
+ # supported by the client.
438
524
  #
439
525
  class Tversion < StyxMessage
440
526
  StyxMessage::MESSAGE_IDS[Tversion] = 100
441
- #
442
527
  add_field(:msize, 'V')
443
528
  add_field(:version, 'Cstr')
444
529
  end
445
530
 
446
531
  ##
447
532
  # Class representing an Rversion message sent by a Styx server.
533
+ # See Inferno's version(5) for more details.
534
+ #
535
+ # === Fields
536
+ #
537
+ # _msize_:: The server's maximum message size, that is the maximum
538
+ # length in bytes that it will ever generate or expect to
539
+ # receive in a single Styx message.
540
+ # _version_:: The version string identifying the level of the protocol
541
+ # supported by the server.
448
542
  #
449
543
  class Rversion < StyxMessage
450
544
  StyxMessage::MESSAGE_IDS[Rversion] = 101
@@ -454,6 +548,13 @@ module RStyx
454
548
 
455
549
  ##
456
550
  # Class representing a Tauth message sent by a Styx client.
551
+ # See Inferno's attach(5) for more details.
552
+ #
553
+ # === Fields
554
+ #
555
+ # _afid_:: New fid to be established for the authentication protocol
556
+ # _uname_:: The user name to authenticate as
557
+ # _aname_:: The file tree to access
457
558
  #
458
559
  class Tauth < StyxMessage
459
560
  StyxMessage::MESSAGE_IDS[Tauth] = 102
@@ -464,6 +565,12 @@ module RStyx
464
565
 
465
566
  ##
466
567
  # Class representing an Rauth message sent by a Styx server.
568
+ # See Inferno's attach(5) for more details.
569
+ #
570
+ # === Fields
571
+ #
572
+ # _aqid_:: a Qid defining a file of type QTAUTH that may be read and
573
+ # written as per the authentication protocol.
467
574
  #
468
575
  class Rauth < StyxMessage
469
576
  StyxMessage::MESSAGE_IDS[Rauth] = 103
@@ -472,6 +579,14 @@ module RStyx
472
579
 
473
580
  ##
474
581
  # Class representing a Tattach message sent by a Styx client.
582
+ # See Inferno's attach(5) for more details.
583
+ #
584
+ # === Fields
585
+ #
586
+ # _fid_:: The fid to establish as the root of the server.
587
+ # _afid_:: The (optional) afid established by the authentication protocol.
588
+ # _uname_:: The user name authenticated against
589
+ # _aname_:: The file tree to access
475
590
  #
476
591
  class Tattach < StyxMessage
477
592
  StyxMessage::MESSAGE_IDS[Tattach] = 104
@@ -483,6 +598,12 @@ module RStyx
483
598
 
484
599
  ##
485
600
  # Class representing an Rattach message sent by a Styx server.
601
+ # See Inferno's attach(5) for more details.
602
+ #
603
+ # === Fields
604
+ #
605
+ # _qid_:: The Qid of the root of the file server on a successful
606
+ # attach.
486
607
  #
487
608
  class Rattach < StyxMessage
488
609
  StyxMessage::MESSAGE_IDS[Rattach] = 105
@@ -502,6 +623,11 @@ module RStyx
502
623
 
503
624
  ##
504
625
  # Class representing an Rerror message sent by a Styx server.
626
+ # See Inferno's error(5) for more details.
627
+ #
628
+ # === Fields
629
+ #
630
+ # _ename_:: The error string describing the failure of the transaction.
505
631
  #
506
632
  class Rerror < StyxMessage
507
633
  StyxMessage::MESSAGE_IDS[Rerror] = 107
@@ -510,6 +636,11 @@ module RStyx
510
636
 
511
637
  ##
512
638
  # Class representing a Tflush message sent by a Styx client.
639
+ # See Inferno's flush(5) for more details.
640
+ #
641
+ # === Fields
642
+ #
643
+ # _oldtag_:: the tag of the message to flush
513
644
  #
514
645
  class Tflush < StyxMessage
515
646
  StyxMessage::MESSAGE_IDS[Tflush] = 108
@@ -518,6 +649,7 @@ module RStyx
518
649
 
519
650
  ##
520
651
  # Class representing an Rflush message sent by a Styx server.
652
+ # See Inferno's flush(5) for more details.
521
653
  #
522
654
  class Rflush < StyxMessage
523
655
  StyxMessage::MESSAGE_IDS[Rflush] = 109
@@ -525,6 +657,13 @@ module RStyx
525
657
 
526
658
  ##
527
659
  # Class representing a Twalk message sent by a Styx client.
660
+ # See Inferno's walk(5) for more details.
661
+ #
662
+ # === Fields
663
+ #
664
+ # _fid_:: The existing fid to start the walk from
665
+ # _newfid_:: The new fid to assign to the file walked to
666
+ # _wnames_:: A list of path elements to walk to
528
667
  #
529
668
  class Twalk < StyxMessage
530
669
  StyxMessage::MESSAGE_IDS[Twalk] = 110
@@ -532,10 +671,18 @@ module RStyx
532
671
  add_field(:newfid, "V")
533
672
  add_field(:wnames, "CstrList")
534
673
 
674
+ ##
675
+ # Set the _wnames_ field of the Twalk message by specifying
676
+ # a path name _str_ instead of an array of path elements.
677
+ #
535
678
  def path=(str)
536
679
  @fieldvals[:wnames] = str.split(File::SEPARATOR)
537
680
  end
538
681
 
682
+ ##
683
+ # Return the path name representation of the Twalk message's
684
+ # _wname_s.
685
+ #
539
686
  def path
540
687
  return(@fieldvals[:wnames].join(File::SEPARATOR))
541
688
  end
@@ -543,6 +690,12 @@ module RStyx
543
690
 
544
691
  ##
545
692
  # Class representing an Rwalk message sent by a Styx server.
693
+ # See Inferno's walk(5) for more details.
694
+ #
695
+ # === Fields
696
+ #
697
+ # _qids_:: The qid's corresponding to the path elements walked to
698
+ # in response to the Twalk
546
699
  #
547
700
  class Rwalk < StyxMessage
548
701
  StyxMessage::MESSAGE_IDS[Rwalk] = 111
@@ -551,6 +704,12 @@ module RStyx
551
704
 
552
705
  ##
553
706
  # Class representing a Topen message sent by a Styx client.
707
+ # See Inferno's open(5) for more details.
708
+ #
709
+ # === Fields
710
+ #
711
+ # _fid_:: The fid of the file to open
712
+ # _mode_:: The open mode
554
713
  #
555
714
  class Topen < StyxMessage
556
715
  StyxMessage::MESSAGE_IDS[Topen] = 112
@@ -560,6 +719,14 @@ module RStyx
560
719
 
561
720
  ##
562
721
  # Class representing an Ropen message sent by a Styx server.
722
+ # See Inferno's open(5) for more details.
723
+ #
724
+ # === Fields
725
+ #
726
+ # _qid_:: The Qid representing the file that was opened
727
+ # _iounit_:: The maximum number of bytes guaranteed to be read from and
728
+ # written to the file without breaking the transfer into
729
+ # multiple messages.
563
730
  #
564
731
  class Ropen < StyxMessage
565
732
  StyxMessage::MESSAGE_IDS[Ropen] = 113
@@ -569,6 +736,14 @@ module RStyx
569
736
 
570
737
  ##
571
738
  # Class representing a Tcreate message sent by a Styx client.
739
+ # See Inferno's open(5) for more details.
740
+ #
741
+ # === Fields
742
+ #
743
+ # _fid_:: The fid of the file to open
744
+ # _name_:: The name of the file to create
745
+ # _perm_:: The permissions bitmask of the file to be created
746
+ # _mode_:: The open mode after file creation
572
747
  #
573
748
  class Tcreate < StyxMessage
574
749
  StyxMessage::MESSAGE_IDS[Tcreate] = 114
@@ -580,6 +755,14 @@ module RStyx
580
755
 
581
756
  ##
582
757
  # Class representing an Rcreate message sent by a Styx server.
758
+ # See Inferno's open(5) for more details.
759
+ #
760
+ # === Fields
761
+ #
762
+ # _qid_:: The Qid representing the file that was created
763
+ # _iounit_:: The maximum number of bytes guaranteed to be read from and
764
+ # written to the file without breaking the transfer into
765
+ # multiple messages.
583
766
  #
584
767
  class Rcreate < StyxMessage
585
768
  StyxMessage::MESSAGE_IDS[Rcreate] = 115
@@ -589,6 +772,13 @@ module RStyx
589
772
 
590
773
  ##
591
774
  # Class representing a Tread message sent by a Styx client.
775
+ # See Inferno's read(5) for more details.
776
+ #
777
+ # === Fields
778
+ #
779
+ # _fid_:: The fid of the file to read from
780
+ # _offset_:: The offset into the file to read from
781
+ # _count_:: The number of bytes to read from the file
592
782
  #
593
783
  class Tread < StyxMessage
594
784
  StyxMessage::MESSAGE_IDS[Tread] = 116
@@ -599,6 +789,11 @@ module RStyx
599
789
 
600
790
  ##
601
791
  # Class representing an Rread message sent by a Styx server.
792
+ # See Inferno's read(5) for more details.
793
+ #
794
+ # === Fields
795
+ #
796
+ # _data_:: the data read from the file
602
797
  #
603
798
  class Rread < StyxMessage
604
799
  StyxMessage::MESSAGE_IDS[Rread] = 117
@@ -612,6 +807,14 @@ module RStyx
612
807
  ##
613
808
  # Class representing a Twrite message sent by a Styx client.
614
809
  #
810
+ # See Inferno's read(5) for more details.
811
+ #
812
+ # === Fields
813
+ #
814
+ # _fid_:: The fid of the file to write to
815
+ # _offset_:: The offset into the file to write to
816
+ # _data_:: The data to be written to that offset
817
+ #
615
818
  class Twrite < StyxMessage
616
819
  StyxMessage::MESSAGE_IDS[Twrite] = 118
617
820
  add_field(:fid, "V")
@@ -621,6 +824,11 @@ module RStyx
621
824
 
622
825
  ##
623
826
  # Class representing an Rwrite message sent by a Styx server.
827
+ # See Inferno's read(5) for more details.
828
+ #
829
+ # === Fields
830
+ #
831
+ # _count_:: The number of bytes successfully written to the file
624
832
  #
625
833
  class Rwrite < StyxMessage
626
834
  StyxMessage::MESSAGE_IDS[Rwrite] = 119
@@ -629,6 +837,11 @@ module RStyx
629
837
 
630
838
  ##
631
839
  # Class representing a Tclunk message sent by a Styx client.
840
+ # See Inferno's clunk(5) for more details.
841
+ #
842
+ # === Fields
843
+ #
844
+ # _fid_:: The fid to clunk
632
845
  #
633
846
  class Tclunk < StyxMessage
634
847
  StyxMessage::MESSAGE_IDS[Tclunk] = 120
@@ -637,6 +850,7 @@ module RStyx
637
850
 
638
851
  ##
639
852
  # Class representing an Rclunk message sent by a Styx server.
853
+ # See Inferno's clunk(5) for more details.
640
854
  #
641
855
  class Rclunk < StyxMessage
642
856
  StyxMessage::MESSAGE_IDS[Rclunk] = 121
@@ -644,6 +858,11 @@ module RStyx
644
858
 
645
859
  ##
646
860
  # Class representing a Tremove message sent by a Styx client.
861
+ # See Inferno's remove(5) for more details.
862
+ #
863
+ # === Fields
864
+ #
865
+ # _fid_:: The fid to remove
647
866
  #
648
867
  class Tremove < StyxMessage
649
868
  StyxMessage::MESSAGE_IDS[Tremove] = 122
@@ -652,6 +871,7 @@ module RStyx
652
871
 
653
872
  ##
654
873
  # Class representing an Rremove message sent by a Styx server.
874
+ # See Inferno's remove(5) for more details.
655
875
  #
656
876
  class Rremove < StyxMessage
657
877
  StyxMessage::MESSAGE_IDS[Rremove] = 123
@@ -659,6 +879,11 @@ module RStyx
659
879
 
660
880
  ##
661
881
  # Class representing a Tstat message sent by a Styx client.
882
+ # See Inferno's stat(5) for more details.
883
+ #
884
+ # === Fields
885
+ #
886
+ # _fid_:: The fid to receive stat information
662
887
  #
663
888
  class Tstat < StyxMessage
664
889
  StyxMessage::MESSAGE_IDS[Tstat] = 124
@@ -667,6 +892,11 @@ module RStyx
667
892
 
668
893
  ##
669
894
  # Class representing an Rstat message sent by a Styx server.
895
+ # See Inferno's stat(5) for more details.
896
+ #
897
+ # === Fields
898
+ #
899
+ # _stat_:: the Stat corresponding to the file queried
670
900
  #
671
901
  class Rstat < StyxMessage
672
902
  StyxMessage::MESSAGE_IDS[Rstat] = 125
@@ -675,6 +905,12 @@ module RStyx
675
905
 
676
906
  ##
677
907
  # Class representing a Twstat message sent by a Styx client.
908
+ # See Inferno's stat(5) for more details.
909
+ #
910
+ # === Fields
911
+ #
912
+ # _fid_:: The fid to change stat information
913
+ # _stat_:: the Stat information to write to the file
678
914
  #
679
915
  class Twstat < StyxMessage
680
916
  StyxMessage::MESSAGE_IDS[Twstat] = 126
@@ -684,6 +920,7 @@ module RStyx
684
920
 
685
921
  ##
686
922
  # Class representing an Rwstat message sent by a Styx server.
923
+ # See Inferno's stat(5) for more details.
687
924
  #
688
925
  class Rwstat < StyxMessage
689
926
  StyxMessage::MESSAGE_IDS[Rwstat] = 127