Module: FSattrLinux

Extended by:
FFI::Library
Included in:
FSattr
Defined in:
lib/fsattr/fsattr-linux.rb

Overview

provides bindings for hfs+ filesystem attributes via FFI TODO: difference between root and user attributes. currently only user attributes are supported

Instance Method Summary collapse

Instance Method Details

#fsattr_fget(attribut) ⇒ Object

man 2 getxattr



55
56
57
58
59
60
61
62
# File 'lib/fsattr/fsattr-linux.rb', line 55

def fsattr_fget(attribut)
  attribut = "user." + attribut
  size = fgetxattr(fileno.to_i, attribut, nil, 0,0,0)
  return "" if size < 0
  result = " " * size
  size = fgetxattr(fileno.to_i, attribut, result, size, 0,0)
  return result
end

#fsattr_flistObject

see man 2 listxattr



71
72
73
74
75
76
# File 'lib/fsattr/fsattr-linux.rb', line 71

def fsattr_flist()
  size = flistxattr(fileno.to_i, nil, 0,0)
  result = " " * size
  err = flistxattr(fileno.to_i, result, size, 0)
  return (result.split("\x00").map {|att| att.gsub(/(user\.)|(root\.)|^(\s)+?$/, "")}).compact.reject { |s| s.empty? }
end

#fsattr_fset(attribute, value) ⇒ Object

see man 2 setxattr



65
66
67
68
# File 'lib/fsattr/fsattr-linux.rb', line 65

def fsattr_fset(attribute, value)
  value = "user."+ value
  err = fsetxattr(fileno.to_i, attribute, value, value.bytesize, 0,0)
end

#fsattr_pget(attribut) ⇒ Object

see man 2 getxattr



30
31
32
33
34
35
36
37
# File 'lib/fsattr/fsattr-linux.rb', line 30

def fsattr_pget(attribut)
  attribut = "user." + attribut
  size = getxattr(@path, attribut, nil, 0,0,0)
  return "" if size < 0
  result = " " * size
  size = getxattr(@path, attribut, result, size, 0,0)
  return result
end

#fsattr_plistObject

see man 2 listxattr



46
47
48
49
50
51
52
# File 'lib/fsattr/fsattr-linux.rb', line 46

def fsattr_plist()
  size = listxattr(@path, nil, 0,0)
  result = " " * size
  err = listxattr(@path, result, size, 0)
  #hack. remove the user. and root. and empty string prefixes
  return (result.split("\x00").map {|att| att.gsub(/(user\.)|(root\.)|^(\s)+?$/, "")}).compact.reject { |s| s.empty? }
end

#fsattr_pset(attribute, value) ⇒ Object

see man 2 setxattr



40
41
42
43
# File 'lib/fsattr/fsattr-linux.rb', line 40

def fsattr_pset(attribute, value)
  value = "user."+ value
  err = setxattr(@path, attribute, value, value.bytesize, 0,0)
end