rbfuse 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6a0d1118c9329e3ec753ac6bd9da1ac618948f8a
4
+ data.tar.gz: 30ee683619facf6d3db12d37338123226095d9fc
5
+ SHA512:
6
+ metadata.gz: 50b6b556187414ded4435a9d0e8b3f4267e7376b20bf7a4fb940ae5b55c761d7191fa7483071665a59ead6fe5cf15c9050d52d1391e6e97067d09ad6ca397e6c
7
+ data.tar.gz: e82dcca262036420062a2d80d6074ed656b3e0dc3aaafd542c7bea75b55e67863966bf58f52c506b89b71c36851e4fd84dfc9886710b2354d16fa36eca79d7c8
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ mkmf.log
12
+
13
+ *.swp
14
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2.3
4
+ before_install: gem install bundler -v 1.10.6
@@ -0,0 +1,13 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
4
+
5
+ We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion.
6
+
7
+ Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
8
+
9
+ Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
10
+
11
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
12
+
13
+ This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ # source 'https://rubygems.org'
2
+ source 'https://ruby.taobao.org'
3
+
4
+ # Specify your gem's dependencies in rbfuse.gemspec
5
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 jiangzhi.xie
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,42 @@
1
+ # RBfuse
2
+
3
+ Ruby FUSE, with [FFI](https://github.com/ffi/ffi)
4
+
5
+ ## Require
6
+
7
+ * fuse or osxfuse 2.x
8
+ * ruby 2.x
9
+
10
+ ## Installation
11
+
12
+
13
+ ```ruby
14
+ gem 'rbfuse'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+ Or install it yourself as:
22
+
23
+ $ gem install rbfuse
24
+
25
+ ## Usage
26
+
27
+ see examples/hello
28
+
29
+ ## TODO
30
+
31
+ * interface test
32
+ * linux testing & fix
33
+
34
+ ## Contributing
35
+
36
+ Bug reports and pull requests are welcome on GitHub at https://github.com/xjz19901211/rubyfuse. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
37
+
38
+
39
+ ## License
40
+
41
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
42
+
data/README.zh-cn.md ADDED
@@ -0,0 +1,44 @@
1
+ # RBfuse
2
+
3
+ 简单的使用 [FFI](https://github.com/ffi/ffi) 实现的 FUSE ruby 库
4
+
5
+ 目前只是一个玩具项目,没有测试,暂时只有 OSX 上可以使用
6
+
7
+ ## Require
8
+
9
+ * fuse or osxfuse 2.x
10
+ * ruby 2.x
11
+
12
+ ## Installation
13
+
14
+
15
+ ```ruby
16
+ gem 'rbfuse'
17
+ ```
18
+
19
+ And then execute:
20
+
21
+ $ bundle
22
+
23
+ Or install it yourself as:
24
+
25
+ $ gem install rbfuse
26
+
27
+ ## Usage
28
+
29
+ See examples/hello
30
+
31
+ ## TODO
32
+
33
+ * 各种接口的测试
34
+ * Linux 接口的测试与修复
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/xjz19901211/rubyfuse. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](contributor-covenant.org) code of conduct.
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
44
+
data/Rakefile ADDED
@@ -0,0 +1,5 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rbfuse"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
data/examples/hello ADDED
@@ -0,0 +1,117 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "rbfuse"
5
+ require 'pry'
6
+
7
+
8
+ default_str = 'hello fuse'
9
+ file_system = {
10
+ '/hello' => "hello fuse.\nfirst file."
11
+ }
12
+
13
+ FO = RBFuse::FuseOperations.new
14
+
15
+ # get file attr
16
+ FO[:getattr] = Proc.new do |path, s_pointer|
17
+ stbuf = RBFuse::Stat.new(s_pointer)
18
+
19
+ case path
20
+ when '/'
21
+ stbuf[:st_mode] = RBFuse::Stat::S_IFDIR | 0755
22
+ stbuf[:st_nlink] = 2
23
+ 0
24
+ else
25
+ if file_system[path]
26
+ stbuf[:st_mode] = RBFuse::Stat::S_IFREG | 0666
27
+ stbuf[:st_nlink] = 1
28
+ stbuf[:st_size] = file_system[path].length
29
+ 0
30
+ else
31
+ -Errno::ENOENT::Errno
32
+ end
33
+ end
34
+ end
35
+
36
+ # read dir
37
+ FO[:readdir] = Proc.new do |path, buf, filter, offset, file_info|
38
+ case path
39
+ when '/'
40
+ filter.call(buf, ".", nil, 0)
41
+ filter.call(buf, "..", nil, 0)
42
+ file_system.each do |fpath, data|
43
+ filter.call(buf, fpath[1..-1], nil, 0)
44
+ end
45
+ 0
46
+ else
47
+ -Errno::ENOENT::Errno
48
+ end
49
+ end
50
+
51
+ FO[:open] = Proc.new do |path, file_info|
52
+ 0
53
+ end
54
+
55
+ # read file
56
+ FO[:read] = Proc.new do |path, buf, size, offset, file_info|
57
+ if data = file_system[path]
58
+ len = data.length
59
+
60
+ if offset < len
61
+ ((offset + size > len) ? len - offset : size).tap do |size|
62
+ buf.write_string(data[offset...(offset + size)])
63
+ end
64
+ else
65
+ 0
66
+ end
67
+ else
68
+ -Errno::ENOENT::Errno
69
+ end
70
+ end
71
+
72
+ # write data
73
+ FO[:write] = Proc.new do |path, buf, size, offset, file_info|
74
+ data = (file_system[path] ||= '')
75
+
76
+ if offset > data.length
77
+ -Errno::EINVAL::Errno
78
+ elsif offset == data.length
79
+ file_system[path] += buf.read_string_length(size)
80
+ size
81
+ else
82
+ end_index = [size. data.length].min
83
+ file_system[path][offset...end_index] = buf.read_string_length(size)
84
+ size
85
+ end
86
+ end
87
+
88
+ FO[:truncate] = Proc.new do |path, size|
89
+ file_system[path] = file_system[path][0...size]
90
+ 0
91
+ end
92
+
93
+ # create file
94
+ FO[:mknod] = Proc.new do |path, mode, rdev|
95
+ file_system[path] = ''
96
+ 0
97
+ end
98
+
99
+ # remove file
100
+ FO[:unlink] = Proc.new do |path|
101
+ file_system.delete(path)
102
+ 0
103
+ end
104
+
105
+ # permission
106
+ FO[:access] = Proc.new {|path, mask| 0 }
107
+
108
+ FO[:release] = Proc.new {|path, file_info| 0 }
109
+
110
+ ARGV.unshift(__FILE__)
111
+ ARGV.push('-s') unless ARGV.include?('-s')
112
+ ARGV.push('-f') unless ARGV.include?('-f')
113
+ argv = FFI::MemoryPointer.new(:string, ARGV.length)
114
+ argv.write_array_of_pointer(ARGV.map {|s| FFI::MemoryPointer.from_string(s) })
115
+
116
+ RBFuse.fuse_main(ARGV.length, argv, FO, nil)
117
+
@@ -0,0 +1,13 @@
1
+ module RBFuse
2
+ class FuseBuf < FFI::Struct
3
+
4
+ layout(
5
+ :size, :size_t,
6
+ :fuse_buf_flags, RBFuse::FuseEnum::FUSE_BUF_FLAGS,
7
+ :mem, :pointer,
8
+ :fd, :int,
9
+ :pos, :off_t
10
+ )
11
+ end
12
+ end
13
+
@@ -0,0 +1,11 @@
1
+ module RBFuse
2
+ class FuseBufvec < FFI::Struct
3
+ layout(
4
+ :count, :size_t,
5
+ :idx, :size_t,
6
+ :off, :size_t,
7
+ :buf, [FuseBuf, 1]
8
+ )
9
+ end
10
+ end
11
+
@@ -0,0 +1,19 @@
1
+ module RBFuse
2
+ class FuseConnInfo < FFI::Struct
3
+
4
+ # https://github.com/libfuse/libfuse/blob/fuse_2_9_4/include/fuse_common.h#L140
5
+ layout(
6
+ :proto_major, :uint,
7
+ :proto_minor, :uint,
8
+ :async_read, :uint,
9
+ :max_write, :uint,
10
+ :max_readahead, :uint,
11
+ :capable, :uint,
12
+ :want, :uint,
13
+ :max_background, :uint,
14
+ :congestion_threshold, :uint,
15
+ :reserved, [:uint, 23]
16
+ )
17
+ end
18
+ end
19
+
@@ -0,0 +1,16 @@
1
+ module RBFuse
2
+ ENUMS = {
3
+ fuse_buf_flags: enum(
4
+ :fuse_buf_is_fd, (1 << 1),
5
+ :fuse_buf_fd_seed, (1 << 2),
6
+ :fuse_buf_fd_retry, (1 << 3)
7
+ )
8
+ }
9
+
10
+ module FuseEnum
11
+ RBFuse::ENUMS.each do |key, data|
12
+ self.const_set(key.upcase, data)
13
+ end
14
+ end
15
+ end
16
+
@@ -0,0 +1,20 @@
1
+ module RBFuse
2
+ class FuseFileInfo < FFI::Struct
3
+
4
+ # https://github.com/libfuse/libfuse/blob/fuse_2_9_4/include/fuse_common.h#L45
5
+ layout(
6
+ :flags, :int,
7
+ :fh_old, :ulong,
8
+ :writepage, :int,
9
+ :direct_io, :uint, 1,
10
+ :keep_cache, :uint, 1,
11
+ :flush, :uint, 1,
12
+ :nonseekable, :uint, 1,
13
+ :flock_release, :uint, 1,
14
+ :padding, :uint, 27,
15
+ :fh, :uint64,
16
+ :lock_owner, :uint64
17
+ )
18
+ end
19
+ end
20
+
@@ -0,0 +1,61 @@
1
+ module RBFuse
2
+ class FuseOperations < FFI::Struct
3
+ # https://github.com/libfuse/libfuse/blob/fuse_2_9_4/include/fuse.h#L88
4
+ layout(
5
+ :getattr, callback([:string, :pointer], :int),
6
+ :readlink, callback([:string, :string, :size_t], :int),
7
+ :getdir, callback([:string, :string, :uint], :int), # define types
8
+ :mknod, callback([:string, :mode_t, :dev_t], :int),
9
+ :mkdir, callback([:string, :mode_t], :int),
10
+ :unlink, callback([:string], :int),
11
+ :rmdir, callback([:string], :int),
12
+ :symlink, callback([:string, :string], :int),
13
+ :rename, callback([:string, :string], :int),
14
+ :link, callback([:string, :string], :int),
15
+ :chmod, callback([:string, :mode_t], :int),
16
+ :chown, callback([:string, :uid_t, :gid_t], :int),
17
+ :truncate, callback([:string, :off_t], :int),
18
+ :utime, callback([:string, Utimbuf.ptr], :int),
19
+ :open, callback([:string, FuseFileInfo.ptr], :int),
20
+ :read, callback([:string, :pointer, :size_t, :off_t, FuseFileInfo.ptr], :int),
21
+ :write, callback([:string, :pointer, :size_t, :off_t, FuseFileInfo.ptr], :int),
22
+ :statfs, callback([:string, Statvfs.ptr], :int),
23
+ :flush, callback([:string, FuseFileInfo.ptr], :int),
24
+ :release, callback([:string, FuseFileInfo.ptr], :int),
25
+ :fsync, callback([:string, :int, FuseFileInfo.ptr], :int),
26
+ :setxattr, callback([:string, :string, :string, :size_t, :int], :int),
27
+ :getxattr, callback([:string, :string, :string, :size_t], :int),
28
+ :listxattr, callback([:string, :string, :size_t], :int),
29
+ :removexattr, callback([:string, :string], :int),
30
+ :opendir, callback([:string, FuseFileInfo.ptr], :int),
31
+ :readdir, callback([:string, :pointer, :fuse_fill_dir_t, :off_t, FuseFileInfo.ptr], :int),
32
+ :releasedir, callback([:string, FuseFileInfo.ptr], :int),
33
+ :fsyncdir, callback([:string, :int, FuseFileInfo.ptr], :int),
34
+ :init, callback([FuseConnInfo.ptr], :void),
35
+ :destroy, callback([:pointer], :void),
36
+ :access, callback([:string, :int], :int),
37
+ :create, callback([:string, :mode_t, FuseFileInfo.ptr], :int),
38
+ :ftruncate, callback([:string, :off_t, FuseFileInfo.ptr], :int),
39
+ :fgetattr, callback([:string, Stat.ptr, FuseFileInfo.ptr], :int),
40
+ # :lock, callback([:string, FuseFileInfo.ptr, :int, Flock.ptr], :int),
41
+ :lock, callback([:string, FuseFileInfo.ptr, :int, :pointer], :int),
42
+ # :utimens, callback([:string, Timespec.ptr], :int),
43
+ :utimens, callback([:string, :pointer], :int),
44
+ :bmap, callback([:string, :size_t, :uint64], :int),
45
+
46
+ :flag_nullpath_ok, :uint, 1,
47
+ :flag_nopath, :uint, 1,
48
+ :flag_utime_omit_ok, :uint, 1,
49
+ :flag_reserved, :uint, 29,
50
+
51
+ :ioctl, callback([:string, :int, :pointer, FuseFileInfo.ptr, :uint, :pointer], :int),
52
+ # :poll, callback([:string, FuseFileInfo.ptr, FusePollhandle.ptr, :uint], :int),
53
+ :poll, callback([:string, FuseFileInfo.ptr, :pointer, :uint], :int),
54
+ :write_buf, callback([:string, FuseBufvec.ptr, :off_t, FuseFileInfo.ptr], :int),
55
+ :read_buf, callback([:string, :pointer, :size_t, :off_t, FuseFileInfo.ptr], :int),
56
+ :flock, callback([:string, FuseFileInfo.ptr, :int], :int),
57
+ :fallocate, callback([:string, :int, :off_t, :off_t, FuseFileInfo.ptr], :int)
58
+ )
59
+ end
60
+ end
61
+
@@ -0,0 +1,4 @@
1
+ module RBFuse
2
+ callback :fuse_fill_dir_t, [:pointer, :string, Stat.ptr, :off_t], :int
3
+ end
4
+
@@ -0,0 +1,3 @@
1
+ module RBFuse
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,9 @@
1
+ module RBFuse
2
+ module Fcntl
3
+ O_RDONLY = 0x0000 # open for reading only
4
+ O_WRONLY = 0x0001 # open for writing only
5
+ O_RDWR = 0x0002 # open for reading and writing
6
+ O_ACCMODE = 0x0003 # mask for above modes
7
+ end
8
+ end
9
+
@@ -0,0 +1,68 @@
1
+ module RBFuse
2
+ class Stat < FFI::Struct
3
+
4
+ # http://man7.org/linux/man-pages/man2/stat.2.html
5
+ layout(
6
+ :st_dev, :dev_t,
7
+ :st_mode, :mode_t,
8
+ :st_nlink, :nlink_t,
9
+ :st_ino, :ino_t,
10
+ :st_uid, :uid_t,
11
+ :st_gid, :gid_t,
12
+ :st_rdev, :dev_t,
13
+ :st_atimespec, RBFuse::Timespec,
14
+ :st_mtimespec, RBFuse::Timespec,
15
+ :st_ctimespec, RBFuse::Timespec,
16
+ :st_birthtimespec, RBFuse::Timespec,
17
+ :st_size, :off_t,
18
+ :st_blocks, :blkcnt_t,
19
+ :st_blksize, :blksize_t,
20
+ :st_flags, :uint32_t,
21
+ :st_gen, :uint32_t
22
+ # :st_lspare, :int32_t,
23
+ # :st_qspare, [:int64_t, 2]
24
+ )
25
+
26
+ # https://developer.apple.com/library/mac/documentation/Darwin/Reference/ManPages/man2/unlink.2.html#//apple_ref/doc/man/2/unlink
27
+ # st_mode bits
28
+ S_IFMT = 0170000 # type of file
29
+ S_IFIFO = 0010000 # named pipe (fifo)
30
+ S_IFCHR = 0020000 # character special
31
+ S_IFDIR = 0040000 # directory
32
+ S_IFBLK = 0060000 # block special
33
+ S_IFREG = 0100000 # regular
34
+ S_IFLNK = 0120000 # symbolic link
35
+ S_IFSOCK = 0140000 # socket
36
+ S_IFWHT = 0160000 # whiteout
37
+ S_ISUID = 0004000 # set user id on execution
38
+ S_ISGID = 0002000 # set group id on execution
39
+ S_ISVTX = 0001000 # save swapped text even after use
40
+ S_IRUSR = 0000400 # read permission, owner
41
+ S_IWUSR = 0000200 # write permission, owner
42
+ S_IXUSR = 0000100 # execute/search permission, owner
43
+
44
+ def st_atime
45
+ self[:st_atimespec][:tv_sec]
46
+ end
47
+
48
+ def st_atime=(val)
49
+ self[:st_atimespec][:tv_sec] = val
50
+ end
51
+
52
+ def st_mtime
53
+ self[:st_mtimespec][:tv_sec]
54
+ end
55
+
56
+ def st_mtime=(val)
57
+ self[:st_mtimespec][:tv_sec] = val
58
+ end
59
+
60
+ def st_ctime
61
+ self[:st_ctimespec][:tv_sec]
62
+ end
63
+
64
+ def st_ctime=(val)
65
+ self[:st_ctimespec][:tv_sec] = val
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,20 @@
1
+ module RBFuse
2
+ class Statvfs < FFI::Struct
3
+
4
+ # http://man7.org/linux/man-pages/man2/statvfs.2.html
5
+ layout(
6
+ :f_bsize, :ulong,
7
+ :f_frsize, :ulong,
8
+ :f_blocks, :fsblkcnt_t,
9
+ :f_bfree, :fsblkcnt_t,
10
+ :f_bavail, :fsblkcnt_t,
11
+ :f_files, :fsblkcnt_t,
12
+ :f_ffree, :fsblkcnt_t,
13
+ :f_ffavail, :fsblkcnt_t,
14
+ :f_fsid, :ulong,
15
+ :f_flag, :ulong,
16
+ :f_fnamemax, :ulong
17
+ )
18
+ end
19
+ end
20
+
@@ -0,0 +1,9 @@
1
+ module RBFuse
2
+ class Timespec < FFI::Struct
3
+ layout(
4
+ :tv_sec, :time_t,
5
+ :tv_nsec, :long
6
+ )
7
+ end
8
+ end
9
+
@@ -0,0 +1,10 @@
1
+ module RBFuse
2
+ class Utimbuf < FFI::Struct
3
+ # http://man7.org/linux/man-pages/man2/utime.2.html
4
+ layout(
5
+ :actime, :time_t,
6
+ :modtime, :time_t
7
+ )
8
+ end
9
+ end
10
+
@@ -0,0 +1,76 @@
1
+ module RBFuse
2
+ class Stat < FFI::Struct
3
+
4
+ # http://man7.org/linux/man-pages/man2/stat.2.html
5
+ layout(
6
+ :st_dev, :dev_t,
7
+ :st_ino, :ino_t,
8
+ :st_mode, :mode_t,
9
+ :st_nlink, :nlink_t,
10
+ :st_uid, :uid_t,
11
+ :st_gid, :gid_t,
12
+ :st_rdev, :dev_t,
13
+ :st_size, :off_t,
14
+ :st_blksize, :blksize_t,
15
+ :st_blocks, :blkcnt_t,
16
+
17
+ :st_atimespec, RBFuse::Timespec,
18
+ :st_mtimespec, RBFuse::Timespec,
19
+ :st_ctimespec, RBFuse::Timespec
20
+ )
21
+
22
+ # http://man7.org/linux/man-pages/man2/stat.2.html
23
+ # st_mode file type
24
+ S_IFMT = 0170000 # bit mask for the file type bit field
25
+ S_IFSOCK = 0140000 # socket
26
+ S_IFLNK = 0120000 # symbolic link
27
+ S_IFREG = 0100000 # regular file
28
+ S_IFBLK = 0060000 # block device
29
+ S_IFDIR = 0040000 # directory
30
+ S_IFCHR = 0020000 # character device
31
+ S_IFIFO = 0010000 # FIFO
32
+
33
+ # st_mode file mode
34
+ S_ISUID = 04000 # set-user-ID bit
35
+ S_ISGID = 02000 # set-group-ID bit (see below)
36
+ S_ISVTX = 01000 # sticky bit (see below)
37
+ S_IRWXU = 00700 # owner has read, write, and execute permission
38
+ S_IRUSR = 00400 # owner has read permission
39
+ S_IWUSR = 00200 # owner has write permission
40
+ S_IXUSR = 00100 # owner has execute permission
41
+ S_IRWXG = 00070 # group has read, write, and execute permission
42
+ S_IRGRP = 00040 # group has read permission
43
+ S_IWGRP = 00020 # group has write permission
44
+ S_IXGRP = 00010 # group has execute permission
45
+ S_IRWXO = 00007 # others (not in group) have read, write, and execute permission
46
+ S_IROTH = 00004 # others have read permission
47
+ S_IWOTH = 00002 # others have write permission
48
+ S_IXOTH = 00001 # others have execute permission
49
+
50
+
51
+
52
+ def st_atime
53
+ self[:st_atimespec][:tv_sec]
54
+ end
55
+
56
+ def st_atime=(val)
57
+ self[:st_atimespec][:tv_sec] = val
58
+ end
59
+
60
+ def st_mtime
61
+ self[:st_mtimespec][:tv_sec]
62
+ end
63
+
64
+ def st_mtime=(val)
65
+ self[:st_mtimespec][:tv_sec] = val
66
+ end
67
+
68
+ def st_ctime
69
+ self[:st_ctimespec][:tv_sec]
70
+ end
71
+
72
+ def st_ctime=(val)
73
+ self[:st_ctimespec][:tv_sec] = val
74
+ end
75
+ end
76
+ end
@@ -0,0 +1,20 @@
1
+ module RBFuse
2
+ class Statvfs < FFI::Struct
3
+
4
+ # http://man7.org/linux/man-pages/man2/statvfs.2.html
5
+ layout(
6
+ :f_bsize, :ulong,
7
+ :f_frsize, :ulong,
8
+ :f_blocks, :fsblkcnt_t,
9
+ :f_bfree, :fsblkcnt_t,
10
+ :f_bavail, :fsblkcnt_t,
11
+ :f_files, :fsblkcnt_t,
12
+ :f_ffree, :fsblkcnt_t,
13
+ :f_ffavail, :fsblkcnt_t,
14
+ :f_fsid, :ulong,
15
+ :f_flag, :ulong,
16
+ :f_namemax, :ulong
17
+ )
18
+ end
19
+ end
20
+
@@ -0,0 +1,9 @@
1
+ module RBFuse
2
+ class Timespec < FFI::Struct
3
+ layout(
4
+ :tv_sec, :time_t,
5
+ :tv_nsec, :long
6
+ )
7
+ end
8
+ end
9
+
@@ -0,0 +1,10 @@
1
+ module RBFuse
2
+ class Utimbuf < FFI::Struct
3
+ # http://man7.org/linux/man-pages/man2/utime.2.html
4
+ layout(
5
+ :actime, :time_t,
6
+ :modtime, :time_t
7
+ )
8
+ end
9
+ end
10
+
data/lib/rbfuse.rb ADDED
@@ -0,0 +1,47 @@
1
+ require "rbfuse/version"
2
+
3
+ require 'ffi'
4
+
5
+ module RBFuse
6
+ extend FFI::Library
7
+
8
+ if RUBY_PLATFORM =~ /^x86_64-linux/
9
+ FUSE_LIB = 'libfuse.so.2'
10
+ PLATFORM_NAME = "x86_64-linux"
11
+ elsif RUBY_PLATFORM =~ /^x86_64-darwin/
12
+ FUSE_LIB = 'libosxfuse'
13
+ PLATFORM_NAME = "x86_64-darwin"
14
+ else
15
+ raise "Unsupported platform '#{RUBY_PLATFORM}'"
16
+ end
17
+
18
+ ffi_lib FUSE_LIB
19
+
20
+
21
+ autoload :FuseEnum, 'rbfuse/fuse_enum'
22
+
23
+ autoload :Errno, "rbfuse/#{PLATFORM_NAME}/Errno"
24
+ autoload :Stat, "rbfuse/#{PLATFORM_NAME}/stat"
25
+ autoload :Statvfs, "rbfuse/#{PLATFORM_NAME}/statvfs"
26
+ autoload :Utimbuf, "rbfuse/#{PLATFORM_NAME}/utimbuf"
27
+ autoload :Timespec, "rbfuse/#{PLATFORM_NAME}/timespec"
28
+
29
+ autoload :FuseBuf, 'rbfuse/fuse_buf'
30
+ autoload :FuseBufvec, 'rbfuse/fuse_bufvec'
31
+ autoload :FuseFileInfo, 'rbfuse/fuse_file_info'
32
+ autoload :FuseConnInfo, 'rbfuse/fuse_conn_info'
33
+ autoload :FuseOperations, 'rbfuse/fuse_operations'
34
+
35
+ require 'rbfuse/fuse_type'
36
+
37
+
38
+ attach_function(
39
+ :fuse_main_real,
40
+ [:int, :pointer, FuseOperations.ptr, :size_t, :pointer], :int
41
+ )
42
+
43
+ def self.fuse_main(argc, argv, fuse_operations, user_data)
44
+ fuse_main_real(argc, argv, fuse_operations, fuse_operations.pointer.size, user_data)
45
+ end
46
+ end
47
+
data/rbfuse.gemspec ADDED
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rbfuse/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rbfuse"
8
+ spec.version = RBFuse::VERSION
9
+ spec.authors = ["jiangzhi.xie"]
10
+ spec.email = ["xiejiangzhi@gmail.com"]
11
+
12
+ spec.summary = %q{Ruby FUSE by FFI}
13
+ spec.description = %q{Using Ruby FFI packing FUSE library, support Linux and OS X}
14
+ spec.homepage = "http://github.com/xjz19901211/rbfuse"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "bin"
19
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.10"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "rspec", "~> 3.0"
25
+ spec.add_development_dependency "pry", "~> 0.10.3"
26
+
27
+ spec.add_dependency "ffi", "~> 1.9.10"
28
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rbfuse
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - jiangzhi.xie
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-01 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.10'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.10'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 0.10.3
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.10.3
69
+ - !ruby/object:Gem::Dependency
70
+ name: ffi
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.9.10
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.9.10
83
+ description: Using Ruby FFI packing FUSE library, support Linux and OS X
84
+ email:
85
+ - xiejiangzhi@gmail.com
86
+ executables:
87
+ - console
88
+ - setup
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - ".gitignore"
93
+ - ".rspec"
94
+ - ".travis.yml"
95
+ - CODE_OF_CONDUCT.md
96
+ - Gemfile
97
+ - LICENSE.txt
98
+ - README.md
99
+ - README.zh-cn.md
100
+ - Rakefile
101
+ - bin/console
102
+ - bin/setup
103
+ - examples/hello
104
+ - lib/rbfuse.rb
105
+ - lib/rbfuse/fuse_buf.rb
106
+ - lib/rbfuse/fuse_bufvec.rb
107
+ - lib/rbfuse/fuse_conn_info.rb
108
+ - lib/rbfuse/fuse_enum.rb
109
+ - lib/rbfuse/fuse_file_info.rb
110
+ - lib/rbfuse/fuse_operations.rb
111
+ - lib/rbfuse/fuse_type.rb
112
+ - lib/rbfuse/version.rb
113
+ - lib/rbfuse/x86_64-darwin/fcntl.rb
114
+ - lib/rbfuse/x86_64-darwin/stat.rb
115
+ - lib/rbfuse/x86_64-darwin/statvfs.rb
116
+ - lib/rbfuse/x86_64-darwin/timespec.rb
117
+ - lib/rbfuse/x86_64-darwin/utimbuf.rb
118
+ - lib/rbfuse/x86_64-linux/stat.rb
119
+ - lib/rbfuse/x86_64-linux/statvfs.rb
120
+ - lib/rbfuse/x86_64-linux/timespec.rb
121
+ - lib/rbfuse/x86_64-linux/utimbuf.rb
122
+ - rbfuse.gemspec
123
+ homepage: http://github.com/xjz19901211/rbfuse
124
+ licenses:
125
+ - MIT
126
+ metadata: {}
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: '0'
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.4.5.1
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Ruby FUSE by FFI
147
+ test_files: []