sys-filesystem 0.3.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +4 -0
- data/MANIFEST +2 -3
- data/Rakefile +13 -47
- data/lib/sys/filesystem.rb +5 -0
- data/lib/unix/sys/filesystem.rb +561 -0
- data/lib/windows/sys/filesystem.rb +408 -0
- data/sys-filesystem.gemspec +2 -3
- data/test/test_sys_filesystem.rb +1 -3
- data/test/test_sys_filesystem_unix.rb +15 -7
- data/test/test_sys_filesystem_windows.rb +1 -1
- metadata +28 -14
- data/ext/extconf.rb +0 -21
- data/ext/sys/filesystem.c +0 -492
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sys-filesystem
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
6
|
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
7
9
|
- 0
|
8
|
-
|
9
|
-
- 4
|
10
|
-
version: 0.3.4
|
10
|
+
version: 1.0.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Daniel J. Berger
|
@@ -15,8 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date:
|
19
|
-
default_executable:
|
18
|
+
date: 2012-01-11 00:00:00 Z
|
20
19
|
dependencies:
|
21
20
|
- !ruby/object:Gem::Dependency
|
22
21
|
name: test-unit
|
@@ -34,22 +33,38 @@ dependencies:
|
|
34
33
|
version: 2.1.1
|
35
34
|
type: :development
|
36
35
|
version_requirements: *id001
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: ffi
|
38
|
+
prerelease: false
|
39
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 23
|
45
|
+
segments:
|
46
|
+
- 1
|
47
|
+
- 0
|
48
|
+
- 0
|
49
|
+
version: 1.0.0
|
50
|
+
type: :runtime
|
51
|
+
version_requirements: *id002
|
37
52
|
description: " The sys-filesystem library provides an interface for gathering filesystem\n information, such as disk space and mount point data.\n"
|
38
53
|
email: djberg96@gmail.com
|
39
54
|
executables: []
|
40
55
|
|
41
|
-
extensions:
|
42
|
-
|
56
|
+
extensions: []
|
57
|
+
|
43
58
|
extra_rdoc_files:
|
44
59
|
- CHANGES
|
45
60
|
- README
|
46
61
|
- MANIFEST
|
47
|
-
- ext/sys/filesystem.c
|
48
62
|
files:
|
49
63
|
- CHANGES
|
50
64
|
- examples/example_stat.rb
|
51
|
-
-
|
52
|
-
-
|
65
|
+
- lib/sys/filesystem.rb
|
66
|
+
- lib/unix/sys/filesystem.rb
|
67
|
+
- lib/windows/sys/filesystem.rb
|
53
68
|
- MANIFEST
|
54
69
|
- Rakefile
|
55
70
|
- README
|
@@ -57,7 +72,6 @@ files:
|
|
57
72
|
- test/test_sys_filesystem.rb
|
58
73
|
- test/test_sys_filesystem_unix.rb
|
59
74
|
- test/test_sys_filesystem_windows.rb
|
60
|
-
has_rdoc: true
|
61
75
|
homepage: http://www.rubyforge.org/projects/sysutils
|
62
76
|
licenses:
|
63
77
|
- Artistic 2.0
|
@@ -87,7 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
87
101
|
requirements: []
|
88
102
|
|
89
103
|
rubyforge_project: sysutils
|
90
|
-
rubygems_version: 1.
|
104
|
+
rubygems_version: 1.8.10
|
91
105
|
signing_key:
|
92
106
|
specification_version: 3
|
93
107
|
summary: A Ruby interface for getting file system information.
|
data/ext/extconf.rb
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'mkmf'
|
2
|
-
|
3
|
-
dir_config('filesystem')
|
4
|
-
|
5
|
-
have_header("sys/mnttab.h") || have_header("mntent.h")
|
6
|
-
|
7
|
-
have_func("statvfs")
|
8
|
-
have_func("getextmntent")
|
9
|
-
|
10
|
-
if have_func("getmntinfo")
|
11
|
-
have_macro("MNT_NOATIME", "sys/mount.h")
|
12
|
-
have_macro("MNT_MULTILABEL", "sys/mount.h")
|
13
|
-
end
|
14
|
-
|
15
|
-
if have_header("sys/statvfs.h")
|
16
|
-
have_struct_member("struct statvfs", "f_basetype", "sys/statvfs.h")
|
17
|
-
else
|
18
|
-
have_header("sys/vnode.h")
|
19
|
-
end
|
20
|
-
|
21
|
-
create_makefile("sys/filesystem", "sys")
|
data/ext/sys/filesystem.c
DELETED
@@ -1,492 +0,0 @@
|
|
1
|
-
/********************************************************************
|
2
|
-
* filesystem.c
|
3
|
-
*
|
4
|
-
* This is the source file for the sys-filesystem package for Ruby.
|
5
|
-
* This is for UNIX platforms only.
|
6
|
-
********************************************************************/
|
7
|
-
#include <ruby.h>
|
8
|
-
|
9
|
-
#include <sys/types.h>
|
10
|
-
|
11
|
-
#ifdef HAVE_SYS_STATVFS_H // Most flavors of UNIX
|
12
|
-
#include <sys/statvfs.h>
|
13
|
-
#else // FreeBSD 4.x
|
14
|
-
#include <sys/param.h>
|
15
|
-
#include <sys/mount.h>
|
16
|
-
#include <sys/vnode.h>
|
17
|
-
#endif
|
18
|
-
|
19
|
-
#ifdef HAVE_SYS_MNTTAB_H // Solaris
|
20
|
-
|
21
|
-
#include <sys/mnttab.h>
|
22
|
-
#define MNTENT mnttab
|
23
|
-
#define START_MNT(F,M) fopen(F,M)
|
24
|
-
#define GET_MNT(FP,MP) (getmntent(FP,MP) == 0)
|
25
|
-
#define END_MNT(F) fclose(F)
|
26
|
-
#define MOUNTFILE "/etc/mnttab"
|
27
|
-
|
28
|
-
// Ruby 1.9.x compatibility
|
29
|
-
#ifndef RSTRING_PTR
|
30
|
-
#define RSTRING_PTR(v) (RSTRING(v)->ptr)
|
31
|
-
#define RSTRING_LEN(v) (RSTRING(v)->len)
|
32
|
-
#endif
|
33
|
-
|
34
|
-
#ifndef RARRAY_PTR
|
35
|
-
#define RARRAY_PTR(v) (RARRAY(v)->ptr)
|
36
|
-
#define RARRAY_LEN(v) (RARRAY(v)->len)
|
37
|
-
#endif
|
38
|
-
|
39
|
-
#elif HAVE_GETMNTINFO
|
40
|
-
|
41
|
-
struct _ment {
|
42
|
-
struct statfs *mntbufp;
|
43
|
-
int current;
|
44
|
-
int max;
|
45
|
-
};
|
46
|
-
|
47
|
-
#include <sys/param.h>
|
48
|
-
#include <sys/mount.h>
|
49
|
-
#include <sys/vnode.h>
|
50
|
-
|
51
|
-
#define MNTENT _ment
|
52
|
-
#define START_MNT(F,M) start_mnt(F,M)
|
53
|
-
#define GET_MNT(FP,MP) ((MP = get_mnt(MP)) != NULL)
|
54
|
-
#define END_MNT(F) end_mnt(F)
|
55
|
-
#define MOUNTFILE "getmntinfo"
|
56
|
-
|
57
|
-
#else // Most flavors of UNIX
|
58
|
-
|
59
|
-
#ifdef HAVE_MNTENT_H
|
60
|
-
#include <mntent.h>
|
61
|
-
#define MNTENT mntent
|
62
|
-
#define START_MNT(F,M) setmntent(F,M)
|
63
|
-
#define GET_MNT(FP,MP) ((MP = getmntent(FP)) != NULL)
|
64
|
-
#define END_MNT(F) endmntent(F)
|
65
|
-
#define MOUNTFILE "/etc/mtab"
|
66
|
-
#endif
|
67
|
-
|
68
|
-
#endif
|
69
|
-
|
70
|
-
#ifdef HAVE_GETMNTINFO
|
71
|
-
|
72
|
-
// This table comes from FreeBSD mount.c@1.105
|
73
|
-
static struct opt {
|
74
|
-
int o_opt;
|
75
|
-
const char *o_name;
|
76
|
-
} optnames[] = {
|
77
|
-
{ MNT_ASYNC, "asynchronous" },
|
78
|
-
{ MNT_EXPORTED, "NFS exported" },
|
79
|
-
{ MNT_LOCAL, "local" },
|
80
|
-
{ MNT_NOEXEC, "noexec" },
|
81
|
-
{ MNT_NOSUID, "nosuid" },
|
82
|
-
{ MNT_QUOTA, "with quotas" },
|
83
|
-
{ MNT_RDONLY, "read-only" },
|
84
|
-
{ MNT_SYNCHRONOUS, "synchronous" },
|
85
|
-
{ MNT_UNION, "union" },
|
86
|
-
#ifdef HAVE_MNT_MULTILABEL
|
87
|
-
{ MNT_MULTILABEL, "multilabel" },
|
88
|
-
#endif
|
89
|
-
#ifdef HAVE_MNT_NOATIME
|
90
|
-
{ MNT_NOATIME, "noatime" },
|
91
|
-
#endif
|
92
|
-
#if !defined(__MACH__) || !defined(__APPLE__)
|
93
|
-
{ MNT_NOSYMFOLLOW, "nosymfollow" },
|
94
|
-
{ MNT_NOCLUSTERR, "noclusterr" },
|
95
|
-
{ MNT_NOCLUSTERW, "noclusterw" },
|
96
|
-
{ MNT_SUIDDIR, "suiddir" },
|
97
|
-
{ MNT_SOFTDEP, "soft-updates" },
|
98
|
-
{ MNT_ACLS, "acls" },
|
99
|
-
#endif
|
100
|
-
{ 0, NULL }
|
101
|
-
};
|
102
|
-
|
103
|
-
static FILE* start_mnt(const char *filename, const char *type)
|
104
|
-
{
|
105
|
-
return (FILE*)!0; // Do nothing
|
106
|
-
}
|
107
|
-
|
108
|
-
static struct _ment* get_mnt(struct _ment* m)
|
109
|
-
{
|
110
|
-
struct _ment* ret = m;
|
111
|
-
|
112
|
-
if (m->max == 0) {
|
113
|
-
if ((m->max = getmntinfo(&(m->mntbufp), MNT_NOWAIT)) == 0) {
|
114
|
-
return NULL;
|
115
|
-
}
|
116
|
-
m->current = 0;
|
117
|
-
}
|
118
|
-
|
119
|
-
if (m->current >= m->max) {
|
120
|
-
ret = NULL;
|
121
|
-
}
|
122
|
-
m->current++;
|
123
|
-
|
124
|
-
return ret;
|
125
|
-
}
|
126
|
-
|
127
|
-
static void end_mnt(FILE* fp)
|
128
|
-
{
|
129
|
-
// Do nothing
|
130
|
-
}
|
131
|
-
|
132
|
-
#endif
|
133
|
-
|
134
|
-
|
135
|
-
VALUE mSys, cFilesys, cStat, cMount;
|
136
|
-
|
137
|
-
static VALUE create_mount_object(struct MNTENT*);
|
138
|
-
|
139
|
-
/* call-seq:
|
140
|
-
* Filesystem.stat(path)
|
141
|
-
*
|
142
|
-
* Returns a a Filesystem::Stat object containing information about the +path+
|
143
|
-
* file system.
|
144
|
-
*/
|
145
|
-
static VALUE fs_stat(VALUE klass, VALUE v_path){
|
146
|
-
VALUE v_stat;
|
147
|
-
char* path = StringValuePtr(v_path);
|
148
|
-
|
149
|
-
#ifdef HAVE_STATVFS
|
150
|
-
struct statvfs fs;
|
151
|
-
|
152
|
-
if(statvfs(path, &fs) < 0)
|
153
|
-
rb_sys_fail("statvfs");
|
154
|
-
#else
|
155
|
-
struct mount mp;
|
156
|
-
struct statfs fs;
|
157
|
-
struct proc p;
|
158
|
-
|
159
|
-
if(VFS_STATFS(&mp, &fs, &p) < 0)
|
160
|
-
rb_sys_fail("VFS_STATFS");
|
161
|
-
#endif
|
162
|
-
|
163
|
-
v_stat = rb_funcall(cStat, rb_intern("new"), 0, 0);
|
164
|
-
|
165
|
-
rb_iv_set(v_stat, "@path", v_path);
|
166
|
-
|
167
|
-
// You gotta love OS X, right?
|
168
|
-
#ifdef __MACH__
|
169
|
-
rb_iv_set(v_stat, "@block_size", ULONG2NUM(fs.f_bsize/256));
|
170
|
-
#else
|
171
|
-
rb_iv_set(v_stat, "@block_size", ULONG2NUM(fs.f_bsize));
|
172
|
-
#endif
|
173
|
-
|
174
|
-
rb_iv_set(v_stat, "@fragment_size", ULONG2NUM(fs.f_frsize));
|
175
|
-
rb_iv_set(v_stat, "@blocks", ULONG2NUM(fs.f_blocks));
|
176
|
-
rb_iv_set(v_stat, "@blocks_free", ULONG2NUM(fs.f_bfree));
|
177
|
-
rb_iv_set(v_stat, "@blocks_available", ULONG2NUM(fs.f_bavail));
|
178
|
-
rb_iv_set(v_stat, "@files", ULONG2NUM(fs.f_files));
|
179
|
-
rb_iv_set(v_stat, "@files_free", ULONG2NUM(fs.f_ffree));
|
180
|
-
rb_iv_set(v_stat, "@files_available", ULONG2NUM(fs.f_favail));
|
181
|
-
rb_iv_set(v_stat, "@filesystem_id", ULONG2NUM(fs.f_fsid));
|
182
|
-
rb_iv_set(v_stat, "@flags", ULONG2NUM(fs.f_flag));
|
183
|
-
rb_iv_set(v_stat, "@name_max", ULONG2NUM(fs.f_namemax));
|
184
|
-
|
185
|
-
#ifdef HAVE_ST_F_BASETYPE
|
186
|
-
rb_iv_set(v_stat, "@base_type", rb_str_new2(fs.f_basetype));
|
187
|
-
#endif
|
188
|
-
|
189
|
-
return rb_obj_freeze(v_stat);
|
190
|
-
}
|
191
|
-
|
192
|
-
/* Convenient methods for converting bytes to kilobytes, megabytes or
|
193
|
-
* gigabytes.
|
194
|
-
*/
|
195
|
-
|
196
|
-
/*
|
197
|
-
* call-seq:
|
198
|
-
* <tt>fix</tt>.to_kb
|
199
|
-
*
|
200
|
-
* Returns +fix+ in terms of kilobytes.
|
201
|
-
*/
|
202
|
-
static VALUE fixnum_to_kb(VALUE self){
|
203
|
-
return ULL2NUM(NUM2ULONG(self) / 1024);
|
204
|
-
}
|
205
|
-
|
206
|
-
/*
|
207
|
-
* call-seq:
|
208
|
-
* <tt>fix</tt>.to_mb
|
209
|
-
*
|
210
|
-
* Returns +fix+ in terms of megabytes.
|
211
|
-
*/
|
212
|
-
static VALUE fixnum_to_mb(VALUE self){
|
213
|
-
return ULL2NUM(NUM2ULONG(self) / 1048576);
|
214
|
-
}
|
215
|
-
|
216
|
-
/*
|
217
|
-
* call-seq:
|
218
|
-
* <tt>fix</tt>.to_gb
|
219
|
-
*
|
220
|
-
* Returns +fix+ in terms of gigabytes.
|
221
|
-
*/
|
222
|
-
static VALUE fixnum_to_gb(VALUE self){
|
223
|
-
return ULL2NUM(NUM2ULONG(self) / 1073741824);
|
224
|
-
}
|
225
|
-
|
226
|
-
/*
|
227
|
-
* call-seq:
|
228
|
-
* Filesystem.mounts
|
229
|
-
* Filesystem.mounts{ ... }
|
230
|
-
*
|
231
|
-
* In block form, yields a Filesystem::Mount object for each mounted filesystem
|
232
|
-
* on your machine. In non-block form, returns an array of Filesystem::Mount
|
233
|
-
* objects instead.
|
234
|
-
*
|
235
|
-
* Example:
|
236
|
-
*
|
237
|
-
* Filesystem.mounts{ |fs|
|
238
|
-
* p fs.name # => e.g. '/dev/dsk/c0t0d0s0', 'proc', etc
|
239
|
-
* p fs.mount_time # => e.g. Thu Dec 11 15:07:23 -0700 2008
|
240
|
-
* p fs.mount_type # => e.g. 'ufs', 'proc', etc
|
241
|
-
* p fs.mount_point # => e.g. '/', '/proc', '/tmp', etc
|
242
|
-
* p fs.options # => e.g. "rw,intr,largefiles,logging,xattr,onerror=panic,dev=2200008"
|
243
|
-
* p fs.pass_number # => e.g. ???
|
244
|
-
* p fs.dump_frequency # => e.g. ???
|
245
|
-
* }
|
246
|
-
*/
|
247
|
-
static VALUE fs_mounts(VALUE klass){
|
248
|
-
VALUE v_array;
|
249
|
-
FILE* fp;
|
250
|
-
struct MNTENT* mp;
|
251
|
-
#ifdef HAVE_SYS_MNTTAB_H
|
252
|
-
struct MNTENT mt;
|
253
|
-
mp = &mt;
|
254
|
-
#elif HAVE_GETMNTINFO
|
255
|
-
struct MNTENT mt;
|
256
|
-
mt.max = 0;
|
257
|
-
mp = &mt;
|
258
|
-
#endif
|
259
|
-
|
260
|
-
v_array = Qnil;
|
261
|
-
|
262
|
-
if((fp = START_MNT(MOUNTFILE, "r")) == NULL)
|
263
|
-
rb_sys_fail(MOUNTFILE);
|
264
|
-
|
265
|
-
if(rb_block_given_p()){
|
266
|
-
while(GET_MNT(fp, mp))
|
267
|
-
rb_yield(create_mount_object(mp));
|
268
|
-
}
|
269
|
-
else{
|
270
|
-
v_array = rb_ary_new();
|
271
|
-
while(GET_MNT(fp, mp))
|
272
|
-
rb_ary_push(v_array, create_mount_object(mp));
|
273
|
-
}
|
274
|
-
|
275
|
-
END_MNT(fp);
|
276
|
-
|
277
|
-
return v_array; /* nil in block form */
|
278
|
-
}
|
279
|
-
|
280
|
-
/* Private function to create a Filesystem object */
|
281
|
-
static VALUE create_mount_object(struct MNTENT* mp){
|
282
|
-
VALUE v_mount = rb_funcall(cMount, rb_intern("new"), 0, 0);
|
283
|
-
|
284
|
-
#ifdef HAVE_SYS_MNTTAB_H
|
285
|
-
rb_iv_set(v_mount, "@name", rb_tainted_str_new2(mp->mnt_special));
|
286
|
-
rb_iv_set(v_mount, "@mount_point", rb_tainted_str_new2(mp->mnt_mountp));
|
287
|
-
rb_iv_set(v_mount, "@mount_type", rb_tainted_str_new2(mp->mnt_fstype));
|
288
|
-
rb_iv_set(v_mount, "@options", rb_tainted_str_new2(mp->mnt_mntopts));
|
289
|
-
rb_iv_set(v_mount, "@mount_time", rb_time_new(atoi(mp->mnt_time), 0));
|
290
|
-
rb_iv_set(v_mount, "@dump_frequency", Qnil);
|
291
|
-
rb_iv_set(v_mount, "@pass_number", Qnil);
|
292
|
-
#elif HAVE_GETMNTINFO
|
293
|
-
{
|
294
|
-
struct statfs *p = mp->mntbufp + (mp->current-1);
|
295
|
-
struct opt *o;
|
296
|
-
int flags, mul;
|
297
|
-
char ostr[BUFSIZ];
|
298
|
-
|
299
|
-
flags = p->f_flags & MNT_VISFLAGMASK;
|
300
|
-
ostr[0] = '\0';
|
301
|
-
|
302
|
-
for (mul = 0, o = optnames; flags && o->o_opt; o++) {
|
303
|
-
if (flags & o->o_opt) {
|
304
|
-
strlcat(ostr, ((mul++) ? "," : ""), BUFSIZ);
|
305
|
-
strlcat(ostr, o->o_name, BUFSIZ);
|
306
|
-
flags &= ~o->o_opt;
|
307
|
-
}
|
308
|
-
}
|
309
|
-
|
310
|
-
rb_iv_set(v_mount, "@name", rb_tainted_str_new2(p->f_mntfromname));
|
311
|
-
rb_iv_set(v_mount, "@mount_point", rb_tainted_str_new2(p->f_mntonname));
|
312
|
-
rb_iv_set(v_mount, "@mount_type", rb_tainted_str_new2(p->f_fstypename));
|
313
|
-
rb_iv_set(v_mount, "@options", rb_tainted_str_new2(ostr));
|
314
|
-
rb_iv_set(v_mount, "@mount_time", Qnil);
|
315
|
-
rb_iv_set(v_mount, "@dump_frequency", Qnil);
|
316
|
-
rb_iv_set(v_mount, "@pass_number", Qnil);
|
317
|
-
}
|
318
|
-
#else
|
319
|
-
rb_iv_set(v_mount, "@name", rb_tainted_str_new2(mp->mnt_fsname));
|
320
|
-
rb_iv_set(v_mount, "@mount_point", rb_tainted_str_new2(mp->mnt_dir));
|
321
|
-
rb_iv_set(v_mount, "@mount_type", rb_tainted_str_new2(mp->mnt_type));
|
322
|
-
rb_iv_set(v_mount, "@options", rb_tainted_str_new2(mp->mnt_opts));
|
323
|
-
rb_iv_set(v_mount, "@mount_time", Qnil);
|
324
|
-
rb_iv_set(v_mount, "@dump_frequency", INT2NUM(mp->mnt_freq));
|
325
|
-
rb_iv_set(v_mount, "@pass_number", INT2NUM(mp->mnt_passno));
|
326
|
-
#endif
|
327
|
-
|
328
|
-
return v_mount;
|
329
|
-
}
|
330
|
-
|
331
|
-
/*
|
332
|
-
* call-seq:
|
333
|
-
* Filesystem.mount_point(file)
|
334
|
-
*
|
335
|
-
* Returns the mount point of the given +file+, or itself if it cannot be
|
336
|
-
* determined.
|
337
|
-
*
|
338
|
-
* Example:
|
339
|
-
*
|
340
|
-
* Filesystem.mount_point('/home/djberge/some_file.txt') => '/home'
|
341
|
-
*/
|
342
|
-
static VALUE fs_mount_point(VALUE klass, VALUE v_file){
|
343
|
-
VALUE v_stat, v_stat_m, v_mounts, v_mount_pt, v_mount;
|
344
|
-
VALUE v_found = Qfalse;
|
345
|
-
long dev1, dev2;
|
346
|
-
int i = 0;
|
347
|
-
|
348
|
-
v_stat = rb_funcall(rb_cFile, rb_intern("stat"), 1, v_file);
|
349
|
-
v_mounts = fs_mounts(klass);
|
350
|
-
dev1 = FIX2LONG(rb_funcall(v_stat, rb_intern("dev"), 0, 0));
|
351
|
-
|
352
|
-
/* Stat each mount point and compare its device number with the device
|
353
|
-
* number of the file provided. If they match, we have a winner.
|
354
|
-
*/
|
355
|
-
for(i = 0; i < RARRAY_LEN(v_mounts); i++){
|
356
|
-
v_mount = RARRAY_PTR(v_mounts)[i];
|
357
|
-
v_mount_pt = rb_funcall(v_mount, rb_intern("mount_point"), 0, 0);
|
358
|
-
v_stat_m = rb_funcall(rb_cFile, rb_intern("stat"), 1, v_mount_pt);
|
359
|
-
dev2 = FIX2LONG(rb_funcall(v_stat_m, rb_intern("dev"), 0, 0));
|
360
|
-
|
361
|
-
if(dev1 == dev2){
|
362
|
-
v_found = Qtrue;
|
363
|
-
break;
|
364
|
-
}
|
365
|
-
}
|
366
|
-
|
367
|
-
if(v_found == Qtrue)
|
368
|
-
return v_mount_pt;
|
369
|
-
else
|
370
|
-
return v_file;
|
371
|
-
}
|
372
|
-
|
373
|
-
void Init_filesystem(){
|
374
|
-
/* The toplevel namespace */
|
375
|
-
mSys = rb_define_module("Sys");
|
376
|
-
|
377
|
-
/* The Filesystem class serves an abstract base class. It's methods return
|
378
|
-
* objects of other types. Do not instantiate.
|
379
|
-
*/
|
380
|
-
cFilesys = rb_define_class_under(mSys, "Filesystem", rb_cObject);
|
381
|
-
|
382
|
-
/* Instances of this class are returned by the Filesystem.mount method */
|
383
|
-
cMount = rb_define_class_under(cFilesys, "Mount", rb_cObject);
|
384
|
-
|
385
|
-
/* Instances of this class are returned by the Filesystem.stat method */
|
386
|
-
cStat = rb_define_class_under(cFilesys, "Stat", rb_cObject);
|
387
|
-
|
388
|
-
/* Singleton methods */
|
389
|
-
rb_define_singleton_method(cFilesys, "mount_point", fs_mount_point, 1);
|
390
|
-
rb_define_singleton_method(cFilesys, "mounts", fs_mounts, 0);
|
391
|
-
rb_define_singleton_method(cFilesys, "stat", fs_stat, 1);
|
392
|
-
|
393
|
-
/* Filesystem::Mount accessors */
|
394
|
-
|
395
|
-
/* The name of the mounted resource */
|
396
|
-
rb_define_attr(cMount, "name", 1, 0);
|
397
|
-
|
398
|
-
/* The mount point/directory */
|
399
|
-
rb_define_attr(cMount, "mount_point", 1, 0);
|
400
|
-
|
401
|
-
/* The type of the file system mount, e.g. 'ufs', 'nfs', etc */
|
402
|
-
rb_define_attr(cMount, "mount_type", 1, 0);
|
403
|
-
|
404
|
-
/* A list of comma separated options for the mount, e.g. 'rw', etc */
|
405
|
-
rb_define_attr(cMount, "options", 1, 0);
|
406
|
-
|
407
|
-
/* The time the file system was mounted or nil if not supported */
|
408
|
-
rb_define_attr(cMount, "mount_time", 1, 0);
|
409
|
-
|
410
|
-
/* The dump frequency in days (or nil if not supported) */
|
411
|
-
rb_define_attr(cMount, "dump_frequency", 1, 0);
|
412
|
-
|
413
|
-
/* The pass number of the file system check or nil if not supported */
|
414
|
-
rb_define_attr(cMount, "pass_number", 1, 0);
|
415
|
-
|
416
|
-
/* Filesystem::Mount Aliases */
|
417
|
-
|
418
|
-
rb_define_alias(cMount, "fsname", "name");
|
419
|
-
rb_define_alias(cMount, "dir", "mount_point");
|
420
|
-
rb_define_alias(cMount, "opts", "options");
|
421
|
-
rb_define_alias(cMount, "passno", "pass_number");
|
422
|
-
rb_define_alias(cMount, "freq", "dump_frequency");
|
423
|
-
|
424
|
-
/* Filesystem::Stat accessors */
|
425
|
-
|
426
|
-
/* The path of the file system */
|
427
|
-
rb_define_attr(cStat, "path", 1, 0);
|
428
|
-
|
429
|
-
/* The preferred system block size */
|
430
|
-
rb_define_attr(cStat, "block_size", 1, 0);
|
431
|
-
|
432
|
-
/* The fragment size, i.e. fundamental file system block size */
|
433
|
-
rb_define_attr(cStat, "fragment_size", 1, 0);
|
434
|
-
|
435
|
-
/* The total number of +fragment_size+ blocks in the file system */
|
436
|
-
rb_define_attr(cStat, "blocks", 1, 0);
|
437
|
-
|
438
|
-
/* The total number of free blocks in the file system */
|
439
|
-
rb_define_attr(cStat, "blocks_free", 1, 0);
|
440
|
-
|
441
|
-
/* The number of free blocks available to unprivileged processes */
|
442
|
-
rb_define_attr(cStat, "blocks_available", 1, 0);
|
443
|
-
|
444
|
-
/* The total number of files/inodes that can be created */
|
445
|
-
rb_define_attr(cStat, "files", 1, 0);
|
446
|
-
|
447
|
-
/* The total number of free files/inodes on the file system */
|
448
|
-
rb_define_attr(cStat, "files_free", 1, 0);
|
449
|
-
|
450
|
-
/* The number of free files/inodes available to unprivileged processes */
|
451
|
-
rb_define_attr(cStat, "files_available", 1, 0);
|
452
|
-
|
453
|
-
/* The file system identifier */
|
454
|
-
rb_define_attr(cStat, "filesystem_id", 1, 0);
|
455
|
-
|
456
|
-
/* The file system type, e.g. UFS */
|
457
|
-
rb_define_attr(cStat, "base_type", 1, 0);
|
458
|
-
|
459
|
-
/* A bit mask of flags. See the <tt>Constants</tt> for a list of flags */
|
460
|
-
rb_define_attr(cStat, "flags", 1, 0);
|
461
|
-
|
462
|
-
/* The maximum length of a file name permitted on the file system */
|
463
|
-
rb_define_attr(cStat, "name_max", 1, 0);
|
464
|
-
|
465
|
-
// Constants
|
466
|
-
|
467
|
-
/* 0.3.4: The version of this library (a String) */
|
468
|
-
rb_define_const(cFilesys, "VERSION", rb_str_new2("0.3.4"));
|
469
|
-
|
470
|
-
/* 0x00000001: Read only file system */
|
471
|
-
rb_define_const(cStat, "RDONLY", INT2FIX(ST_RDONLY));
|
472
|
-
|
473
|
-
/* 0x00000002: File system does not support suid or sgid semantics */
|
474
|
-
rb_define_const(cStat, "NOSUID", INT2FIX(ST_NOSUID));
|
475
|
-
|
476
|
-
#ifdef ST_NOTRUNC
|
477
|
-
/* 0x00000003: File system does not truncate file names longer than +name_max+ */
|
478
|
-
rb_define_const(cStat, "NOTRUNC", INT2FIX(ST_NOTRUNC));
|
479
|
-
#endif
|
480
|
-
|
481
|
-
// Aliases
|
482
|
-
|
483
|
-
rb_define_alias(cStat, "inodes", "files");
|
484
|
-
rb_define_alias(cStat, "inodes_free", "files_free");
|
485
|
-
rb_define_alias(cStat, "inodes_available", "files_available");
|
486
|
-
|
487
|
-
// Convenient methods for Fixnum
|
488
|
-
|
489
|
-
rb_define_method(rb_cFixnum, "to_kb", fixnum_to_kb, 0);
|
490
|
-
rb_define_method(rb_cFixnum, "to_mb", fixnum_to_mb, 0);
|
491
|
-
rb_define_method(rb_cFixnum, "to_gb", fixnum_to_gb, 0);
|
492
|
-
}
|