Method: NFS::Handler#convert_attrs

Defined in:
lib/nfs/handler.rb

#convert_attrs(attrs) ⇒ Object

Convert Ruby Stat object to an NFS fattr

[View source]

140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
# File 'lib/nfs/handler.rb', line 140

def convert_attrs(attrs)
  type = :NFNON
  mode = attrs.mode

  if attrs.file?
    type = :NFREG
    mode |= NFS::MODE_REG
  elsif attrs.directory?
    type = :NFDIR
    mode |= NFS::MODE_DIR
  elsif attrs.blockdev?
    type = :NFBLK
    mode |= NFS::MODE_BLK
  elsif attrs.chardev?
    type = :NFCHR
    mode |= NFS::MODE_CHR
  elsif attrs.symlink?
    type = :NFLNK
    mode |= NFS::MODE_LNK
  elsif attrs.socket?
    type = :NFSOCK
    mode |= NFS::MODE_SOCK
  end

  {
    type: type,
    mode: mode,
    nlink: attrs.nlink,
    uid: attrs.uid,
    gid: attrs.gid,
    size: attrs.size,
    blocksize: attrs.blksize,
    rdev: attrs.rdev,
    blocks: attrs.blocks,
    fsid: @fsid,
    fileid: attrs.ino,
    atime: {
      seconds: attrs.atime.tv_sec,
      useconds: attrs.atime.tv_usec
    },
    mtime: {
      seconds: attrs.mtime.tv_sec,
      useconds: attrs.mtime.tv_usec
    },
    ctime: {
      seconds: attrs.ctime.tv_sec,
      useconds: attrs.ctime.tv_usec
    }
  }
end