fallocate 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/{README.rdoc → README.markdown} +21 -6
- data/VERSION +1 -1
- data/fallocate.gemspec +6 -4
- data/lib/fallocate.rb +4 -13
- data/lib/fallocate/18.rb +19 -0
- data/lib/fallocate/19.rb +15 -0
- metadata +7 -5
@@ -1,8 +1,24 @@
|
|
1
|
-
|
1
|
+
# fallocate
|
2
2
|
|
3
|
-
|
3
|
+
Pure-Ruby FFI bindings to
|
4
|
+
[posix_fallocate](http://www.kernel.org/doc/man-pages/online/pages/man3/posix_fallocate.3.html)
|
4
5
|
|
5
|
-
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
require 'fallocate'
|
10
|
+
|
11
|
+
File.open 'some/file', 'w' do |f|
|
12
|
+
f.allocate 0, 1024 * 1024 * 1024
|
13
|
+
end
|
14
|
+
```
|
15
|
+
|
16
|
+
## Requirements
|
17
|
+
|
18
|
+
Right now, fallocate raises a FFI exception at loading time if
|
19
|
+
`posix_fallocate` isn't available in `libc`.
|
20
|
+
|
21
|
+
## Contributing to fallocate
|
6
22
|
|
7
23
|
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
24
|
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
@@ -12,8 +28,7 @@ Description goes here.
|
|
12
28
|
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
29
|
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
30
|
|
15
|
-
|
31
|
+
## Copyright
|
16
32
|
|
17
|
-
Copyright (c) 2012 Victor Costan. See LICENSE.txt for
|
18
|
-
further details.
|
33
|
+
Copyright (c) 2012 Victor Costan. See LICENSE.txt for further details.
|
19
34
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/fallocate.gemspec
CHANGED
@@ -5,27 +5,29 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "fallocate"
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Victor Costan"]
|
12
|
-
s.date = "2012-
|
12
|
+
s.date = "2012-08-08"
|
13
13
|
s.description = "fallocate is a fast method for allocating real disk\n space for files"
|
14
14
|
s.email = "victor@costan.us"
|
15
15
|
s.extra_rdoc_files = [
|
16
16
|
"LICENSE.txt",
|
17
|
-
"README.
|
17
|
+
"README.markdown"
|
18
18
|
]
|
19
19
|
s.files = [
|
20
20
|
".document",
|
21
21
|
"Gemfile",
|
22
22
|
"Gemfile.lock",
|
23
23
|
"LICENSE.txt",
|
24
|
-
"README.
|
24
|
+
"README.markdown",
|
25
25
|
"Rakefile",
|
26
26
|
"VERSION",
|
27
27
|
"fallocate.gemspec",
|
28
28
|
"lib/fallocate.rb",
|
29
|
+
"lib/fallocate/18.rb",
|
30
|
+
"lib/fallocate/19.rb",
|
29
31
|
"test/helper.rb",
|
30
32
|
"test/test_fallocate.rb"
|
31
33
|
]
|
data/lib/fallocate.rb
CHANGED
@@ -9,18 +9,9 @@ module Fallocate
|
|
9
9
|
attach_function :posix_fallocate, [:int, :off_t, :off_t], :int
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
# so that writes to that region will not fail due to out-of-space errors.
|
17
|
-
#
|
18
|
-
# @param [Integer] offset the 0-based offset of the region's starting byte
|
19
|
-
# @param [Integer] length the region's length, in bytes
|
20
|
-
def allocate(offset = 0, length)
|
21
|
-
errno = Fallocate.posix_fallocate fileno, offset, length
|
22
|
-
return if errno == 0
|
23
|
-
raise SystemCallError.new(errno)
|
24
|
-
end
|
12
|
+
if RUBY_VERSION >= '1.9'
|
13
|
+
require 'fallocate/19.rb'
|
14
|
+
else
|
15
|
+
require 'fallocate/18.rb'
|
25
16
|
end
|
26
17
|
|
data/lib/fallocate/18.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
class File
|
2
|
+
# Ensures there is enough disk space for writing to a file.
|
3
|
+
#
|
4
|
+
# This method asks the filesystem to allocate disk blocks for a file region,
|
5
|
+
# so that writes to that region will not fail due to out-of-space errors.
|
6
|
+
#
|
7
|
+
# @param [Integer] offset the 0-based offset of the region's starting byte
|
8
|
+
# @param [Integer] length the region's length, in bytes
|
9
|
+
def allocate(offset, length = nil)
|
10
|
+
unless length
|
11
|
+
length = offset
|
12
|
+
offset = 0
|
13
|
+
end
|
14
|
+
|
15
|
+
errno = Fallocate.posix_fallocate fileno, offset, length
|
16
|
+
return if errno == 0
|
17
|
+
raise SystemCallError.new(errno)
|
18
|
+
end
|
19
|
+
end
|
data/lib/fallocate/19.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
class File
|
2
|
+
# Ensures there is enough disk space for writing to a file.
|
3
|
+
#
|
4
|
+
# This method asks the filesystem to allocate disk blocks for a file region,
|
5
|
+
# so that writes to that region will not fail due to out-of-space errors.
|
6
|
+
#
|
7
|
+
# @param [Integer] offset the 0-based offset of the region's starting byte
|
8
|
+
# @param [Integer] length the region's length, in bytes
|
9
|
+
def allocate(offset = 0, length)
|
10
|
+
errno = Fallocate.posix_fallocate fileno, offset, length
|
11
|
+
return if errno == 0
|
12
|
+
raise SystemCallError.new(errno)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fallocate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -114,17 +114,19 @@ executables: []
|
|
114
114
|
extensions: []
|
115
115
|
extra_rdoc_files:
|
116
116
|
- LICENSE.txt
|
117
|
-
- README.
|
117
|
+
- README.markdown
|
118
118
|
files:
|
119
119
|
- .document
|
120
120
|
- Gemfile
|
121
121
|
- Gemfile.lock
|
122
122
|
- LICENSE.txt
|
123
|
-
- README.
|
123
|
+
- README.markdown
|
124
124
|
- Rakefile
|
125
125
|
- VERSION
|
126
126
|
- fallocate.gemspec
|
127
127
|
- lib/fallocate.rb
|
128
|
+
- lib/fallocate/18.rb
|
129
|
+
- lib/fallocate/19.rb
|
128
130
|
- test/helper.rb
|
129
131
|
- test/test_fallocate.rb
|
130
132
|
homepage: http://github.com/pwnall/fallocate
|
@@ -142,7 +144,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
142
144
|
version: '0'
|
143
145
|
segments:
|
144
146
|
- 0
|
145
|
-
hash:
|
147
|
+
hash: 1490748833886583460
|
146
148
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
149
|
none: false
|
148
150
|
requirements:
|