Class: FuseFS::StatsHelper
- Inherits:
-
Object
- Object
- FuseFS::StatsHelper
- Defined in:
- lib/fuse/fusedir.rb
Overview
Helper for filesystem accounting
Instance Attribute Summary collapse
-
#max_nodes ⇒ Integer
Maximum number of (virtual) inodes.
-
#max_space ⇒ Integer
Size of filesystem in bytes.
-
#nodes ⇒ Integer
readonly
Used inodes (typically count of files and directories).
-
#space ⇒ Integer
readonly
Used space in bytes.
-
#strict ⇒ Boolean
If set true, adjustments that cause space/nodes to exceed the maximums will raise ENOSPC (no space left on device).
Instance Method Summary collapse
-
#adjust(delta_space, delta_nodes = 0) ⇒ void
Adjust accumlated statistics.
-
#initialize(max_space = nil, max_nodes = nil, strict = false) ⇒ StatsHelper
constructor
A new instance of StatsHelper.
- #to_statistics(free_space = nil, free_nodes = nil) ⇒ Object
Constructor Details
#initialize(max_space = nil, max_nodes = nil, strict = false) ⇒ StatsHelper
Returns a new instance of StatsHelper.
26 27 28 29 30 31 32 |
# File 'lib/fuse/fusedir.rb', line 26 def initialize(max_space=nil,max_nodes=nil,strict=false) @nodes = 0 @space = 0 @max_space = max_space @max_nodes = max_nodes @strict = strict end |
Instance Attribute Details
#max_nodes ⇒ Integer
Returns maximum number of (virtual) inodes.
9 10 11 |
# File 'lib/fuse/fusedir.rb', line 9 def max_nodes @max_nodes end |
#max_space ⇒ Integer
Returns size of filesystem in bytes.
7 8 9 |
# File 'lib/fuse/fusedir.rb', line 7 def max_space @max_space end |
#nodes ⇒ Integer (readonly)
Returns used inodes (typically count of files and directories).
20 21 22 |
# File 'lib/fuse/fusedir.rb', line 20 def nodes @nodes end |
#space ⇒ Integer (readonly)
Returns used space in bytes.
17 18 19 |
# File 'lib/fuse/fusedir.rb', line 17 def space @space end |
#strict ⇒ Boolean
If set true, adjustments that cause space/nodes to exceed the maximums will raise ENOSPC (no space left on device)
14 15 16 |
# File 'lib/fuse/fusedir.rb', line 14 def strict @strict end |
Instance Method Details
#adjust(delta_space, delta_nodes = 0) ⇒ void
This method returns an undefined value.
Adjust accumlated statistics
40 41 42 43 44 |
# File 'lib/fuse/fusedir.rb', line 40 def adjust(delta_space,delta_nodes=0) @nodes += delta_nodes @space += delta_space raise Errno::ENOSPC if @strict && ( @nodes > @max_nodes || @space > @max_space ) end |
#to_statistics ⇒ Array<Integer> #to_statistics(free_space, free_nodes) ⇒ Array<Integer>
53 54 55 56 57 |
# File 'lib/fuse/fusedir.rb', line 53 def to_statistics(free_space=nil,free_nodes=nil) total_space = free_space ? space + free_space : max_space total_nodes = free_nodes ? nodes + free_nodes : max_nodes [ @space, @nodes, total_space, total_nodes ] end |