sys-filesystem 1.4.3 → 1.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b00e624e22bd699630d63b34f90be7758f82630a069f7db2a61e2139cb55888
4
- data.tar.gz: 59add440f0203bade0430b2acd410e785b4ab0de416f272755a72db9276aa767
3
+ metadata.gz: e69ef4806a64a956dfd3b1eb629a17654d7b14a5a8ed8468113f8ee045287682
4
+ data.tar.gz: 54182b67d58e77fc0c4b0dc8c96aa7ab64f5c7759943e966abd77d1ba212bfb8
5
5
  SHA512:
6
- metadata.gz: eb24f3c965a15d090fd7fff5800cc4c1829a7ddc7f2cbc4e943bb7e57ae92749a6abfccfecd94e8522287e9700916fc22f57af164afa413459321fa9460ba9a3
7
- data.tar.gz: d5d30e84e01f370ac62b77251f2c80c07964a99bebfa0cc30252237bc33830198d3a065c28a546c230327b1b951d45d95bc309f75276d17d7e1e8968ade216f2
6
+ metadata.gz: 496090ea1ac8ef0b3d3fe55489b3e3f7eeb39f0406135ebdc3dfc650c0ea16c2e010a8eafb8ffb47e837b4be79217311c1d0e7cd71bb0c3ee81d189a8b7e54ca
7
+ data.tar.gz: fa6242583cf58ea04fa2fc2581030fcc53e62c7871852ffd3105caa8e363685b1521a056ee0a292327a75c497720dd934c23bd7d58d9687157c8265eeac64833
checksums.yaml.gz.sig CHANGED
Binary file
data/CHANGES.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 1.5.0 - 8-Jun-2024
2
+ * Add support for DragonFlyBSD.
3
+ * Remove Solaris support. It's dead, Jim.
4
+ * Now assumes umount2 function is present on Linux systems, and some
5
+ corresponding refactoring of the umount method.
6
+
7
+ ## 1.4.5 - 22-May-2024
8
+ * Handle the possibility that a statvs64 alias may not exist on some Linux
9
+ platforms. Thanks go to Antoine Martin for the report.
10
+
11
+ ## 1.4.4 - 12-Sep-2023
12
+ * Yet another fix for 32-bit vs 64-bit linux, specifically for the Statvfs
13
+ struct. Thanks go to Josh Cooper for the spot and the patch.
14
+
1
15
  ## 1.4.3 - 20-Oct-2021
2
16
  * Another fix for 32-bit vs 64-bit Linux since it was realized we cannot always
3
17
  rely on the host architecture information. Handling for JRuby was improved
data/README.md CHANGED
@@ -78,7 +78,7 @@ Apache-2.0
78
78
 
79
79
  ## Copyright
80
80
 
81
- (C) 2003-2020 Daniel J. Berger
81
+ (C) 2003-2024 Daniel J. Berger
82
82
  All Rights Reserved
83
83
 
84
84
  ## Warranty
data/Rakefile CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'rake'
2
2
  require 'rake/clean'
3
3
  require 'rspec/core/rake_task'
4
+ require 'rubocop/rake_task'
4
5
 
5
6
  CLEAN.include('**/*.gem', '**/*.rbc', '**/*.rbx', '**/*.lock')
6
7
 
@@ -25,6 +26,18 @@ task :example do
25
26
  sh "ruby -Ilib -Ilib/unix -Ilib/windows examples/example_stat.rb"
26
27
  end
27
28
 
29
+ RuboCop::RakeTask.new
30
+
31
+ namespace :rubocop do
32
+ RuboCop::RakeTask.new(:unix) do |task|
33
+ task.patterns = ['lib/sys/unix/sys/**/*.rb', 'spec/*unix*']
34
+ end
35
+
36
+ RuboCop::RakeTask.new(:windows) do |task|
37
+ task.patterns = ['lib/sys/windows/sys/**/*.rb', 'spec/*windows*']
38
+ end
39
+ end
40
+
28
41
  desc "Run the test suite"
29
42
  RSpec::Core::RakeTask.new(:spec)
30
43
 
@@ -1,9 +1,4 @@
1
- module Sys
2
- class Filesystem
3
- # The version of the sys-filesystem library
4
- VERSION = '1.4.3'.freeze
5
- end
6
- end
1
+ # frozen_string_literal: true
7
2
 
8
3
  require 'rbconfig'
9
4
 
@@ -13,10 +8,18 @@ else
13
8
  require_relative 'unix/sys/filesystem'
14
9
  end
15
10
 
16
- # Methods universal to all platforms
11
+ # Methods and properties universal to all platforms
17
12
 
13
+ # The Sys module serves as a namespace only.
18
14
  module Sys
15
+ # The Filesystem class serves as an abstract base class. Its methods
16
+ # return objects of other types. Do not instantiate.
19
17
  class Filesystem
18
+ # The version of the sys-filesystem library
19
+ VERSION = '1.5.0'
20
+
21
+ # Stat objects are returned by the Sys::Filesystem.stat method. Here
22
+ # we're adding universal methods.
20
23
  class Stat
21
24
  # Returns true if the filesystem is case sensitive for the current path.
22
25
  # Typically this will be any path on MS Windows or Macs using HFS.
@@ -26,14 +29,12 @@ module Sys
26
29
  # general rule, I do not recommend using this method for a root path.
27
30
  #
28
31
  def case_insensitive?
29
- if path !~ /\w+/
30
- if RbConfig::CONFIG['host_os'] =~ /darwin|mac|windows|mswin|mingw/i
31
- true # Assumes HFS
32
- else
33
- false
34
- end
35
- else
32
+ if path =~ /\w+/
36
33
  File.identical?(path, path.swapcase)
34
+ elsif RbConfig::CONFIG['host_os'] =~ /darwin|mac|windows|mswin|mingw/i
35
+ true # Assumes HFS/APFS on Mac
36
+ else
37
+ false
37
38
  end
38
39
  end
39
40
 
@@ -46,8 +47,8 @@ module Sys
46
47
  end
47
48
  end
48
49
 
49
- # Some convenient methods for converting bytes to kb, mb, and gb.
50
- #
50
+ # Reopen the Numeric class and add some convenient methods
51
+ # for converting bytes to kb, mb, and gb.
51
52
  class Numeric
52
53
  # call-seq:
53
54
  # <tt>num</tt>.to_kb
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module Sys
2
4
  class Filesystem
3
5
  module Constants
@@ -23,6 +25,8 @@ module Sys
23
25
  MNT_DEFWRITE = 0x02000000 # filesystem should defer writes
24
26
  MNT_MULTILABEL = 0x04000000 # MAC support for individual labels
25
27
  MNT_NOATIME = 0x10000000 # disable update of file access time
28
+ MNT_NOCLUSTERR = 0x40000000 # disable cluster read
29
+ MNT_NOCLUSTERW = 0x80000000 # disable cluster write
26
30
 
27
31
  MNT_VISFLAGMASK = (
28
32
  MNT_RDONLY | MNT_SYNCHRONOUS | MNT_NOEXEC |
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ffi'
2
4
 
3
5
  module Sys
4
6
  class Filesystem
7
+ # A scoped module for internal FFI functions to be used by the main code.
5
8
  module Functions
6
9
  extend FFI::Library
7
10
 
@@ -9,7 +12,8 @@ module Sys
9
12
 
10
13
  def self.linux64?
11
14
  if RUBY_PLATFORM == 'java'
12
- ENV_JAVA['sun.arch.data.model'].to_i == 64
15
+ RbConfig::CONFIG['host_os'] =~ /linux/i &&
16
+ ENV_JAVA['sun.arch.data.model'].to_i == 64
13
17
  else
14
18
  RbConfig::CONFIG['host_os'] =~ /linux/i &&
15
19
  (RbConfig::CONFIG['arch'] =~ /64/ || RbConfig::CONFIG['DEFS'] =~ /64/)
@@ -18,10 +22,12 @@ module Sys
18
22
 
19
23
  private_class_method :linux64?
20
24
 
21
- if RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
22
- attach_function(:statvfs, :statvfs64, %i[string pointer], :int)
23
- elsif linux64?
24
- attach_function(:statvfs, :statvfs64, %i[string pointer], :int)
25
+ if linux64?
26
+ begin
27
+ attach_function(:statvfs, :statvfs64, %i[string pointer], :int)
28
+ rescue FFI::NotFoundError # Not every Linux distro has an alias
29
+ attach_function(:statvfs, %i[string pointer], :int)
30
+ end
25
31
  else
26
32
  attach_function(:statvfs, %i[string pointer], :int)
27
33
  end
@@ -29,29 +35,19 @@ module Sys
29
35
  attach_function(:strerror, [:int], :string)
30
36
  attach_function(:mount_c, :mount, %i[string string string ulong string], :int)
31
37
 
32
- begin
33
- attach_function(:umount_c, :umount, [:string], :int)
34
- rescue FFI::NotFoundError
35
- if RbConfig::CONFIG['host_os'] =~ /darwin|osx|mach|bsd/i
36
- attach_function(:umount_c, :unmount, [:string], :int)
37
- end
38
+ if RbConfig::CONFIG['host_os'] =~ /darwin|osx|mach|bsd|dragonfly/i
39
+ attach_function(:umount_c, :unmount, %i[string int], :int)
40
+ else
41
+ attach_function(:umount_c, :umount2, %i[string int], :int)
38
42
  end
39
43
 
40
44
  private_class_method :statvfs, :strerror, :mount_c, :umount_c
41
45
 
42
46
  begin
43
- if RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
44
- attach_function(:fopen, %i[string string], :pointer)
45
- attach_function(:fclose, [:pointer], :int)
46
- attach_function(:getmntent, %i[pointer pointer], :int)
47
- private_class_method :fopen, :fclose, :getmntent
48
- else
49
- attach_function(:getmntent, [:pointer], :pointer)
50
- attach_function(:setmntent, %i[string string], :pointer)
51
- attach_function(:endmntent, [:pointer], :int)
52
- attach_function(:umount2, %i[string int], :int)
53
- private_class_method :getmntent, :setmntent, :endmntent, :umount2
54
- end
47
+ attach_function(:getmntent, [:pointer], :pointer)
48
+ attach_function(:setmntent, %i[string string], :pointer)
49
+ attach_function(:endmntent, [:pointer], :int)
50
+ private_class_method :getmntent, :setmntent, :endmntent
55
51
  rescue FFI::NotFoundError
56
52
  if RbConfig::CONFIG['host_os'] =~ /darwin|osx|mach/i
57
53
  begin
@@ -1,11 +1,28 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'ffi'
2
4
  require 'rbconfig'
3
5
 
4
6
  module Sys
5
7
  class Filesystem
6
8
  module Structs
7
- class Statfs < FFI::Struct
9
+ # Used by DragonFlyBSD
10
+ class UUID < FFI::Struct
11
+ UUID_NODE_LEN = 6
12
+
13
+ layout(
14
+ :time_low, :uint32,
15
+ :time_mid, :uint16,
16
+ :time_hi_and_version, :uint16,
17
+ :clock_seq_hi_and_reserved, :uint8,
18
+ :clock_seq_low, :uint8,
19
+ :node, [:uint8, UUID_NODE_LEN]
20
+ )
21
+ end
8
22
 
23
+ # The Statfs struct is a subclass of FFI::Struct that corresponds to a struct statfs.
24
+ class Statfs < FFI::Struct
25
+ # Private method that will determine the layout of the struct on Linux.
9
26
  def self.linux64?
10
27
  if RUBY_PLATFORM == 'java'
11
28
  ENV_JAVA['sun.arch.data.model'].to_i == 64
@@ -20,92 +37,128 @@ module Sys
20
37
  # FreeBSD 12.0 MNAMELEN from 88 => 1024.
21
38
  MNAMELEN =
22
39
  if RbConfig::CONFIG['host_os'] =~ /freebsd(.*)/i
23
- $1.to_f < 12.0 ? 88 : 1024
40
+ Regexp.last_match(1).to_f < 12.0 ? 88 : 1024
24
41
  else
25
42
  88
26
43
  end
27
44
 
28
- if RbConfig::CONFIG['host_os'] =~ /bsd/i
29
- layout(
30
- :f_version, :uint32,
31
- :f_type, :uint32,
32
- :f_flags, :uint64,
33
- :f_bsize, :uint64,
34
- :f_iosize, :int64,
35
- :f_blocks, :uint64,
36
- :f_bfree, :uint64,
37
- :f_bavail, :int64,
38
- :f_files, :uint64,
39
- :f_ffree, :uint64,
40
- :f_syncwrites, :uint64,
41
- :f_asyncwrites, :uint64,
42
- :f_syncreads, :uint64,
43
- :f_asyncreads, :uint64,
44
- :f_spare, [:uint64, 10],
45
- :f_namemax, :uint32,
46
- :f_owner, :int32,
47
- :f_fsid, [:int32, 2],
48
- :f_charspare, [:char, 80],
49
- :f_fstypename, [:char, 16],
50
- :f_mntfromname, [:char, MNAMELEN],
51
- :f_mntonname, [:char, MNAMELEN]
52
- )
53
- elsif RbConfig::CONFIG['host_os'] =~ /linux/i
54
- if linux64?
45
+ case RbConfig::CONFIG['host_os']
46
+ when /bsd/i
55
47
  layout(
56
- :f_type, :ulong,
57
- :f_bsize, :ulong,
48
+ :f_version, :uint32,
49
+ :f_type, :uint32,
50
+ :f_flags, :uint64,
51
+ :f_bsize, :uint64,
52
+ :f_iosize, :int64,
58
53
  :f_blocks, :uint64,
59
54
  :f_bfree, :uint64,
60
- :f_bavail, :uint64,
55
+ :f_bavail, :int64,
61
56
  :f_files, :uint64,
62
57
  :f_ffree, :uint64,
63
- :f_fsid, [:int, 2],
64
- :f_namelen, :ulong,
65
- :f_frsize, :ulong,
66
- :f_flags, :ulong,
67
- :f_spare, [:ulong, 4]
58
+ :f_syncwrites, :uint64,
59
+ :f_asyncwrites, :uint64,
60
+ :f_syncreads, :uint64,
61
+ :f_asyncreads, :uint64,
62
+ :f_spare, [:uint64, 10],
63
+ :f_namemax, :uint32,
64
+ :f_owner, :int32,
65
+ :f_fsid, [:int32, 2],
66
+ :f_charspare, [:char, 80],
67
+ :f_fstypename, [:char, 16],
68
+ :f_mntfromname, [:char, MNAMELEN],
69
+ :f_mntonname, [:char, MNAMELEN]
70
+ )
71
+ when /linux/i
72
+ if linux64?
73
+ layout(
74
+ :f_type, :ulong,
75
+ :f_bsize, :ulong,
76
+ :f_blocks, :uint64,
77
+ :f_bfree, :uint64,
78
+ :f_bavail, :uint64,
79
+ :f_files, :uint64,
80
+ :f_ffree, :uint64,
81
+ :f_fsid, [:int, 2],
82
+ :f_namelen, :ulong,
83
+ :f_frsize, :ulong,
84
+ :f_flags, :ulong,
85
+ :f_spare, [:ulong, 4]
86
+ )
87
+ else
88
+ layout(
89
+ :f_type, :ulong,
90
+ :f_bsize, :ulong,
91
+ :f_blocks, :uint32,
92
+ :f_bfree, :uint32,
93
+ :f_bavail, :uint32,
94
+ :f_files, :uint32,
95
+ :f_ffree, :uint32,
96
+ :f_fsid, [:int, 2],
97
+ :f_namelen, :ulong,
98
+ :f_frsize, :ulong,
99
+ :f_flags, :ulong,
100
+ :f_spare, [:ulong, 4]
101
+ )
102
+ end
103
+ when /dragonfly/i
104
+ layout(
105
+ :f_spare2, :long,
106
+ :f_bsize, :long,
107
+ :f_iosize, :long,
108
+ :f_blocks, :long,
109
+ :f_bfree, :long,
110
+ :f_bavail, :long,
111
+ :f_files, :long,
112
+ :f_ffree, :long,
113
+ :f_fsid, [:int32_t, 2],
114
+ :f_owner, :uid_t,
115
+ :f_type, :int,
116
+ :f_flags, :int,
117
+ :f_syncwrites, :long,
118
+ :f_asyncwrites, :long,
119
+ :f_fstypename, [:char, 16],
120
+ :f_mntonname, [:char, 80],
121
+ :f_syncreads, :long,
122
+ :f_asyncreads, :long,
123
+ :f_spares1, :short,
124
+ :f_mntfromname, [:char, 80],
125
+ :f_spares2, :short,
126
+ :f_spare, [:long,2]
68
127
  )
69
128
  else
70
129
  layout(
71
- :f_type, :ulong,
72
- :f_bsize, :ulong,
73
- :f_blocks, :uint32,
74
- :f_bfree, :uint32,
75
- :f_bavail, :uint32,
76
- :f_files, :uint32,
77
- :f_ffree, :uint32,
78
- :f_fsid, [:int, 2],
79
- :f_namelen, :ulong,
80
- :f_frsize, :ulong,
81
- :f_flags, :ulong,
82
- :f_spare, [:ulong, 4]
130
+ :f_bsize, :uint32,
131
+ :f_iosize, :int32,
132
+ :f_blocks, :uint64,
133
+ :f_bfree, :uint64,
134
+ :f_bavail, :uint64,
135
+ :f_files, :uint64,
136
+ :f_ffree, :uint64,
137
+ :f_fsid, [:int32, 2],
138
+ :f_owner, :int32,
139
+ :f_type, :uint32,
140
+ :f_flags, :uint32,
141
+ :f_fssubtype, :uint32,
142
+ :f_fstypename, [:char, 16],
143
+ :f_mntonname, [:char, 1024],
144
+ :f_mntfromname, [:char, 1024],
145
+ :f_reserved, [:uint32, 8]
83
146
  )
84
- end
85
- else
86
- layout(
87
- :f_bsize, :uint32,
88
- :f_iosize, :int32,
89
- :f_blocks, :uint64,
90
- :f_bfree, :uint64,
91
- :f_bavail, :uint64,
92
- :f_files, :uint64,
93
- :f_ffree, :uint64,
94
- :f_fsid, [:int32, 2],
95
- :f_owner, :int32,
96
- :f_type, :uint32,
97
- :f_flags, :uint32,
98
- :f_fssubtype, :uint32,
99
- :f_fstypename, [:char, 16],
100
- :f_mntonname, [:char, 1024],
101
- :f_mntfromname, [:char, 1024],
102
- :f_reserved, [:uint32, 8]
103
- )
104
147
  end
105
148
  end
106
149
 
107
150
  # The Statvfs struct represents struct statvfs from sys/statvfs.h.
108
151
  class Statvfs < FFI::Struct
152
+ # Private method that will determine the layout of the struct on Linux.
153
+ def self.linux64?
154
+ if RUBY_PLATFORM == 'java'
155
+ ENV_JAVA['sun.arch.data.model'].to_i == 64
156
+ else
157
+ RbConfig::CONFIG['host_os'] =~ /linux/i &&
158
+ (RbConfig::CONFIG['arch'] =~ /64/ || RbConfig::CONFIG['DEFS'] =~ /64/)
159
+ end
160
+ end
161
+
109
162
  if RbConfig::CONFIG['host_os'] =~ /darwin|osx|mach/i
110
163
  layout(
111
164
  :f_bsize, :ulong,
@@ -134,24 +187,29 @@ module Sys
134
187
  :f_fsid, :ulong,
135
188
  :f_namemax, :ulong
136
189
  )
137
- elsif RbConfig::CONFIG['host'] =~ /sunos|solaris/i
190
+ elsif RbConfig::CONFIG['host'] =~ /dragonfly/i
138
191
  layout(
139
192
  :f_bsize, :ulong,
140
193
  :f_frsize, :ulong,
141
- :f_blocks, :uint64_t,
142
- :f_bfree, :uint64_t,
143
- :f_bavail, :uint64_t,
144
- :f_files, :uint64_t,
145
- :f_ffree, :uint64_t,
146
- :f_favail, :uint64_t,
194
+ :f_blocks, :uint64,
195
+ :f_bfree, :uint64,
196
+ :f_bavail, :uint64,
197
+ :f_files, :uint64,
198
+ :f_ffree, :uint64,
199
+ :f_favail, :uint64,
147
200
  :f_fsid, :ulong,
148
- :f_basetype, [:char, 16],
149
201
  :f_flag, :ulong,
150
202
  :f_namemax, :ulong,
151
- :f_fstr, [:char, 32],
152
- :f_filler, [:ulong, 16]
203
+ :f_owner, :uid_t,
204
+ :f_type, :uint,
205
+ :f_syncreads, :uint64,
206
+ :f_syncwrites, :uint64,
207
+ :f_asyncreads, :uint64,
208
+ :f_asyncwrites, :uint64,
209
+ :f_fsid_uuid, UUID,
210
+ :f_uid_uuid, UUID
153
211
  )
154
- elsif RbConfig::CONFIG['host'] =~ /i686/i
212
+ elsif !linux64?
155
213
  layout(
156
214
  :f_bsize, :ulong,
157
215
  :f_frsize, :ulong,
@@ -185,17 +243,6 @@ module Sys
185
243
  end
186
244
  end
187
245
 
188
- # The Mnttab struct represents struct mnnttab from sys/mnttab.h on Solaris.
189
- class Mnttab < FFI::Struct
190
- layout(
191
- :mnt_special, :string,
192
- :mnt_mountp, :string,
193
- :mnt_fstype, :string,
194
- :mnt_mntopts, :string,
195
- :mnt_time, :string
196
- )
197
- end
198
-
199
246
  # The Mntent struct represents struct mntent from sys/mount.h on Unix.
200
247
  class Mntent < FFI::Struct
201
248
  layout(
@@ -105,6 +105,27 @@ module Sys
105
105
  # The filesystem type, e.g. UFS.
106
106
  attr_accessor :base_type
107
107
 
108
+ # The filesystem ID
109
+ attr_accessor :filesystem_id
110
+
111
+ # The filesystem type
112
+ attr_accessor :filesystem_type
113
+
114
+ # The user that mounted the filesystem
115
+ attr_accessor :owner
116
+
117
+ # Count of sync reads since mount
118
+ attr_accessor :sync_reads
119
+
120
+ # Count of sync writes since mount
121
+ attr_accessor :sync_writes
122
+
123
+ # Count of async reads since mount
124
+ attr_accessor :async_reads
125
+
126
+ # Count of async writes since mount
127
+ attr_accessor :async_writes
128
+
108
129
  alias inodes files
109
130
  alias inodes_free files_free
110
131
  alias inodes_available files_available
@@ -224,7 +245,7 @@ module Sys
224
245
  fs = Statvfs.new
225
246
 
226
247
  if statvfs(path, fs) < 0
227
- raise Error, 'statvfs() function failed: ' + strerror(FFI.errno)
248
+ raise Error, "statvfs() function failed: #{strerror(FFI.errno)}"
228
249
  end
229
250
 
230
251
  obj = Sys::Filesystem::Stat.new
@@ -250,6 +271,16 @@ module Sys
250
271
  obj.base_type = fs[:f_basetype].to_s
251
272
  end
252
273
 
274
+ # DragonFlyBSD has additional struct members
275
+ if RbConfig::CONFIG['host_os'] =~ /dragonfly/i
276
+ obj.owner = fs[:f_owner]
277
+ obj.filesystem_type = fs[:f_type]
278
+ obj.sync_reads= fs[:f_syncreads]
279
+ obj.async_reads= fs[:f_asyncreads]
280
+ obj.sync_writes = fs[:f_syncwrites]
281
+ obj.async_writes = fs[:f_asyncwrites]
282
+ end
283
+
253
284
  obj.freeze
254
285
  end
255
286
 
@@ -275,7 +306,7 @@ module Sys
275
306
  num = getmntinfo(buf, 2)
276
307
 
277
308
  if num == 0
278
- raise Error, 'getmntinfo() function failed: ' + strerror(FFI.errno)
309
+ raise Error, "getmntinfo() function failed: #{strerror(FFI.errno)}"
279
310
  end
280
311
 
281
312
  ptr = buf.get_pointer(0)
@@ -325,41 +356,23 @@ module Sys
325
356
  raise SystemCallError.new(method_name, FFI.errno)
326
357
  end
327
358
 
328
- if RbConfig::CONFIG['host_os'] =~ /sunos|solaris/i
329
- mt = Mnttab.new
330
- while getmntent(fp, mt) == 0
331
- obj = Sys::Filesystem::Mount.new
332
- obj.name = mt[:mnt_special].to_s
333
- obj.mount_point = mt[:mnt_mountp].to_s
334
- obj.mount_type = mt[:mnt_fstype].to_s
335
- obj.options = mt[:mnt_mntopts].to_s
336
- obj.mount_time = Time.at(Integer(mt[:mnt_time]))
337
-
338
- if block_given?
339
- yield obj.freeze
340
- else
341
- array << obj.freeze
342
- end
343
- end
344
- else
345
- while ptr = getmntent(fp)
346
- break if ptr.null?
347
- mt = Mntent.new(ptr)
348
-
349
- obj = Sys::Filesystem::Mount.new
350
- obj.name = mt[:mnt_fsname]
351
- obj.mount_point = mt[:mnt_dir]
352
- obj.mount_type = mt[:mnt_type]
353
- obj.options = mt[:mnt_opts]
354
- obj.mount_time = nil
355
- obj.dump_frequency = mt[:mnt_freq]
356
- obj.pass_number = mt[:mnt_passno]
357
-
358
- if block_given?
359
- yield obj.freeze
360
- else
361
- array << obj.freeze
362
- end
359
+ while ptr = getmntent(fp)
360
+ break if ptr.null?
361
+ mt = Mntent.new(ptr)
362
+
363
+ obj = Sys::Filesystem::Mount.new
364
+ obj.name = mt[:mnt_fsname]
365
+ obj.mount_point = mt[:mnt_dir]
366
+ obj.mount_type = mt[:mnt_type]
367
+ obj.options = mt[:mnt_opts]
368
+ obj.mount_time = nil
369
+ obj.dump_frequency = mt[:mnt_freq]
370
+ obj.pass_number = mt[:mnt_passno]
371
+
372
+ if block_given?
373
+ yield obj.freeze
374
+ else
375
+ array << obj.freeze
363
376
  end
364
377
  end
365
378
  ensure
@@ -419,29 +432,31 @@ module Sys
419
432
  #
420
433
  def self.mount(source, target, fstype = 'ext2', flags = 0, data = nil)
421
434
  if mount_c(source, target, fstype, flags, data) != 0
422
- raise Error, 'mount() function failed: ' + strerror(FFI.errno)
435
+ raise Error, "mount() function failed: #{strerror(FFI.errno)}"
423
436
  end
424
437
 
425
438
  self
426
439
  end
427
440
 
428
441
  # Removes the attachment of the (topmost) filesystem mounted on target.
429
- # Additional flags may be provided for operating systems that support
430
- # the umount2 function. Otherwise this argument is ignored.
442
+ # You may also specify bitwise OR'd +flags+ to control the precise behavior.
443
+ # The possible flags on Linux are:
431
444
  #
432
- # Typically requires admin privileges.
445
+ # * MNT_FORCE - Abort pending requests, may cause data loss.
446
+ # * MNT_DETACH - Lazy umount, waits until the mount point is no longer busy.
447
+ # * MNT_EXPIRE - Mark mount point as expired, but don't actually remove it until
448
+ # a second call MNT_EXPIRE call is made.
433
449
  #
434
- def self.umount(target, flags = nil)
435
- if flags && respond_to?(:umount2)
436
- function = 'umount2'
437
- rv = umount2_c(target, flags)
438
- else
439
- function = 'umount'
440
- rv = umount_c(target)
441
- end
442
-
443
- if rv != 0
444
- raise Error, "#{function} function failed: " + strerror(FFI.errno)
450
+ # * UMOUNT_NOFOLLOW - Don't dereference the target if it's a symbolic link.
451
+ #
452
+ # Note that BSD platforms may support different flags. Please see the man
453
+ # pages for details.
454
+ #
455
+ # Typically this method requires admin privileges.
456
+ #
457
+ def self.umount(target, flags = 0)
458
+ if umount_c(target, flags) != 0
459
+ raise Error, "umount function failed: #{strerror(FFI.errno)}"
445
460
  end
446
461
 
447
462
  self