stat.rb (1157B)
1 # Copyright (C) 2007 Kris Maglione 2 # See PERMISSIONS 3 4 module R9P 5 class Stat <Serial 6 module Constants 7 DMDIR =0x80000000 8 DMAPPEND =0x40000000 9 DMEXCL =0x20000000 10 DMMOUNT =0x10000000 11 DMAUTH =0x08000000 12 DMTMP =0x04000000 13 DMSYMLINK =0x02000000 14 DMDEVICE =0x00800000 15 DMNAMEDPIPE =0x00200000 16 DMSOCKET =0x00100000 17 DMSETUID =0x00080000 18 DMSETGID =0x00040000 19 end 20 include Constants 21 22 class Mode <Serial 23 field :mode, :dword 24 alias_method :to_i, :mode 25 def to_s 26 modes = 'rwxrwxrwx' 27 0.upto(8) { |i| 28 if mode&(1 << i) == 0 29 modes[-i-1] = '-' 30 end 31 } 32 if mode&Stat::DMDIR > 0 33 'd' 34 elsif mode&Stat::DMAPPEND > 0 35 'a' 36 else 37 '-' 38 end + modes 39 end 40 end 41 42 field :size, :word, :size, 2 43 field :type, :word 44 field :dev, :dword 45 field :qid, Qid 46 field :mode, Mode 47 field :atime, :dword 48 field :atime, :dword 49 field :length, :qword 50 field :name, :word, :string 51 field :uid, :word, :string 52 field :gid, :word, :string 53 field :muid, :word, :string 54 55 def self.from_data(data) 56 list = [] 57 while data.length > 0 58 list << new(data) 59 end 60 list 61 end 62 end 63 end