Skip to content

Instantly share code, notes, and snippets.

@maebashi
Created November 29, 2013 06:14
Show Gist options
  • Save maebashi/7702150 to your computer and use it in GitHub Desktop.
Save maebashi/7702150 to your computer and use it in GitHub Desktop.
The simplest libgfapi example Ruby FFI version.
require 'ffi'
module GLFS
extend FFI::Library
ffi_lib 'gfapi'
attach_function :new, :glfs_new, [:string], :pointer
attach_function :set_volfile_server, :glfs_set_volfile_server,
[:pointer, :string, :string, :int], :int
attach_function :init, :glfs_init, [:pointer], :int
attach_function :creat, :glfs_creat, [:pointer, :string, :int, :int], :pointer
attach_function :write, :glfs_write, [:pointer, :string, :uint, :int], :uint
attach_function :close, :glfs_close, [:pointer], :int
end
fs = GLFS.new 'volume_name'
ret = GLFS.set_volfile_server fs, 'tcp', 'server_address', 24007
ret = GLFS.init fs
fd = GLFS.creat fs, 'filename', 2, 0644
s = "hello gluster\n"
ret = GLFS.write fd, s, s.size+1, 0
GLFS.close fd
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment