Class: FFI::Stat
- Inherits:
-
Object
- Object
- FFI::Stat
- Extended by:
- Library
- Includes:
- StructWrapper
- Defined in:
- lib/ffi/stat.rb,
lib/ffi/stat/native.rb,
lib/ffi/stat/constants.rb,
lib/ffi/stat/time_spec.rb
Overview
Ruby representation of stat.h struct
Defined Under Namespace
Classes: TimeSpec
Constant Summary collapse
- S_IFMT =
File type mask
0o170000
- S_IFIFO =
FIFO
0o010000
- S_IFCHR =
Character device
0o020000
- S_IFDIR =
Directory
0o040000
- S_IFBLK =
Block device
0o060000
- S_IFREG =
Regular file
0o100000
- S_IFLNK =
Symbolic link
0o120000
- S_IFSOCK =
Socket
0o140000
- S_ISUID =
SetUID
0o004000
- S_ISGID =
SetGID
0o002000
- S_ISVTX =
Sticky Bit
0o001000
Instance Attribute Summary collapse
-
#atime ⇒ Time
Time of last access.
-
#mode ⇒ Integer
File mode (type | perms).
-
#mtime ⇒ Time
Time of last modification.
-
#nlink ⇒ Integer
Number of links.
-
#size ⇒ Integer
Size of file in bytes.
-
#uid ⇒ Integer
Owner user id.
Attributes included from StructWrapper
Class Method Summary collapse
- .dir(**fields) ⇒ Stat (also: directory)
- .file(**fields) ⇒ Stat
- .from(file, stat = new(), follow: false) ⇒ Stat
- .fstat(file, stat = new()) ⇒ Stat
- .lstat(file, stat = new()) ⇒ Stat
- .stat(file, stat = new()) ⇒ Stat
- .symlink(**fields) ⇒ Stat
Instance Method Summary collapse
-
#dir(mode:, nlink: 3, uid: Process.uid, gid: Process.gid, **args) ⇒ self
(also: #directory)
Fill content for a directory.
- #directory? ⇒ Boolean
-
#file(mode:, size:, nlink: 1, uid: Process.uid, gid: Process.gid, **args) ⇒ self
Fill content for a regular file.
- #file? ⇒ Boolean
-
#from(file, follow: true) ⇒ self
Fill attributes from file (using native LIBC calls).
-
#fstat(fileno) ⇒ self
Fill attributes from file descriptor.
-
#lstat(path) ⇒ self
Fill attributes from file path, without following links.
-
#mask(mask = S_ISUID, **overrides) ⇒ Object
Apply permissions mask to mode.
- #setgid? ⇒ Boolean
- #setuid? ⇒ Boolean
-
#stat(path) ⇒ self
Fill attributes from file, following links.
- #sticky? ⇒ Boolean
-
#symlink(size:, mode: 0o777, nlink: 1, uid: Process.uid, gid: Process.gid, **args) ⇒ self
Fill content for a symbolic link.
- #symlink? ⇒ Boolean
Methods included from StructWrapper
Methods included from FFI::StructWrapper::ClassMethods
Methods included from Accessors::ClassMethods
#attr_accessor, #attr_reader, #attr_writer, #ffi_attr_accessor, #ffi_attr_reader, #ffi_attr_reader_method, #ffi_attr_readers, #ffi_attr_writer, #ffi_attr_writer_method, #ffi_attr_writers, #ffi_bitflag_accessor, #ffi_bitflag_reader, #ffi_bitflag_writer, #ffi_public_attr_readers, #ffi_public_attr_writers
Methods included from Accessors
#ffi_attr_fill, #ffi_attr_reader_member, #ffi_attr_writer_member, #fill, #inspect, #to_h
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class FFI::StructWrapper
Instance Attribute Details
#atime ⇒ Time
Returns time of last access.
|
# File 'lib/ffi/stat.rb', line 41
|
#mode ⇒ Integer
Returns file mode (type | perms).
|
# File 'lib/ffi/stat.rb', line 19
|
#mtime ⇒ Time
Returns time of last modification.
|
# File 'lib/ffi/stat.rb', line 44
|
#nlink ⇒ Integer
Returns number of links.
|
# File 'lib/ffi/stat.rb', line 25
|
#size ⇒ Integer
Returns size of file in bytes.
|
# File 'lib/ffi/stat.rb', line 22
|
#uid ⇒ Integer
Returns owner user id.
|
# File 'lib/ffi/stat.rb', line 28
|
Class Method Details
.fstat(file, stat = new()) ⇒ Stat
205 |
# File 'lib/ffi/stat.rb', line 205 %i[from stat lstat fstat].each { |m| define_method(m) { |file, stat = new, **args| stat.send(m, file, **args) } } |
.symlink(**fields) ⇒ Stat
183 |
# File 'lib/ffi/stat.rb', line 183 %i[file dir symlink].each { |m| define_method(m) { |stat = new, **args| stat.send(m, **args) } } |
Instance Method Details
#dir(mode:, nlink: 3, uid: Process.uid, gid: Process.gid, **args) ⇒ self Also known as: directory
Fill content for a directory
78 79 80 81 |
# File 'lib/ffi/stat.rb', line 78 def dir(mode:, nlink: 3, uid: Process.uid, gid: Process.gid, **args) mode = ((S_IFDIR & S_IFMT) | (mode & 0o777)) fill(mode: mode, uid: uid, gid: gid, nlink: nlink, **args) end |
#directory? ⇒ Boolean
147 148 149 |
# File 'lib/ffi/stat.rb', line 147 def directory? mode & S_IFDIR != 0 end |
#file(mode:, size:, nlink: 1, uid: Process.uid, gid: Process.gid, **args) ⇒ self
Fill content for a regular file
66 67 68 69 |
# File 'lib/ffi/stat.rb', line 66 def file(mode:, size:, nlink: 1, uid: Process.uid, gid: Process.gid, **args) mode = ((S_IFREG & S_IFMT) | (mode & 0o777)) fill(mode: mode, size: size, nlink: nlink, uid: uid, gid: gid, **args) end |
#from(file, follow: true) ⇒ self
Fill attributes from file (using native LIBC calls)
100 101 102 103 104 105 106 |
# File 'lib/ffi/stat.rb', line 100 def from(file, follow: true) return fstat(file) if file.is_a?(Integer) return stat(file.to_s) if follow lstat(file.to_s) end |
#fstat(fileno) ⇒ self
Fill attributes from file descriptor
126 127 128 129 130 131 132 133 |
# File 'lib/ffi/stat.rb', line 126 %i[stat lstat fstat].each do |m| define_method(m) do |file| res = self.class.send("native_#{m}", (m == :fstat ? file.to_i : file.to_s), native) raise SystemCallError.new('', FFI::LastError.error) unless res.zero? self end end |
#lstat(path) ⇒ self
Fill attributes from file path, without following links
|
# File 'lib/ffi/stat.rb', line 114
|
#mask(mask = S_ISUID, **overrides) ⇒ Object
Apply permissions mask to mode
139 140 141 |
# File 'lib/ffi/stat.rb', line 139 def mask(mask = S_ISUID, **overrides) fill(mode: mode & (~mask), **overrides) end |
#setgid? ⇒ Boolean
155 156 157 |
# File 'lib/ffi/stat.rb', line 155 def setgid? mode & S_ISGID != 0 end |
#setuid? ⇒ Boolean
151 152 153 |
# File 'lib/ffi/stat.rb', line 151 def setuid? mode & S_ISUID != 0 end |
#stat(path) ⇒ self
Fill attributes from file, following links
|
# File 'lib/ffi/stat.rb', line 108
|
#sticky? ⇒ Boolean
159 160 161 |
# File 'lib/ffi/stat.rb', line 159 def sticky? mode & S_ISVTX != 0 end |
#symlink(size:, mode: 0o777, nlink: 1, uid: Process.uid, gid: Process.gid, **args) ⇒ self
Fill content for a symbolic link
91 92 93 94 |
# File 'lib/ffi/stat.rb', line 91 def symlink(size:, mode: 0o777, nlink: 1, uid: Process.uid, gid: Process.gid, **args) mode = ((S_IFLNK & S_IFMT) | (mode & 0o777)) fill(mode: mode, nlink: nlink, size: size, uid: uid, gid: gid, **args) end |
#symlink? ⇒ Boolean
163 164 165 |
# File 'lib/ffi/stat.rb', line 163 def symlink? mode & S_IFLNK != 0 end |