Class: File

Inherits:
Object
  • Object
show all
Defined in:
lib/fallocate/18.rb,
lib/fallocate/19.rb

Instance Method Summary collapse

Instance Method Details

#allocate(offset = 0, length) ⇒ Object

Ensures there is enough disk space for writing to a file.

This method asks the filesystem to allocate disk blocks for a file region, so that writes to that region will not fail due to out-of-space errors.

Parameters:

  • offset (Integer) (defaults to: 0)

    the 0-based offset of the region’s starting byte

  • length (Integer)

    the region’s length, in bytes

Raises:

  • (SystemCallError)


9
10
11
12
13
14
15
16
17
18
# File 'lib/fallocate/18.rb', line 9

def allocate(offset, length = nil)
  unless length
    length = offset
    offset = 0
  end
  
  errno = Fallocate.posix_fallocate fileno, offset, length
  return if errno == 0
  raise SystemCallError.new(errno)
end