line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::System; |
2
|
|
|
|
|
|
|
|
3
|
16
|
|
|
16
|
|
102785
|
use strict; |
|
16
|
|
|
|
|
48
|
|
|
16
|
|
|
|
|
493
|
|
4
|
8
|
|
|
8
|
|
56
|
use warnings; |
|
8
|
|
|
|
|
21
|
|
|
8
|
|
|
|
|
466
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
our $VERSION = '1.16'; |
7
|
|
|
|
|
|
|
|
8
|
8
|
|
|
8
|
|
46
|
use Carp; |
|
8
|
|
|
|
|
20
|
|
|
8
|
|
|
|
|
2689
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
# declaring avoids 'Name "File::System::prune" used only once: possible typo' |
11
|
|
|
|
|
|
|
our $prune; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
File::System - A virtual file system written in pure Perl |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $root = File::System->new("Real", root => '/var/chroot/foo'); |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
my $file = $root->lookup('/etc/fstab'); |
22
|
|
|
|
|
|
|
print $file->lines; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head1 DESCRIPTION |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
The L library is intended to provide an interface to a file system. Generally, a file system is a heirarchical arrangement of records commonly found on most modern computers. This library attempts to generalize this idea as it pertains to loading and accessing these files. This is not meant to generalize on the specifics of file system implementations or get into hardware details. |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
The goal of this system is not to present the file system in a native way, but to provide the Perl program using it a simple hook into a potentially complex structure. Thus, certain file system module requirements may force unnatural or arbitrary constraints on the file system appearance. The most notable is that this implementation purposely does not address the concept of "volumes" except to state that such things should just be made parts of the file system under an artificial root. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
This system is also still immature and certain aspects---notably the concept of "capabilities" and "permissions"---are absent. These may be added in future making existing file modules created to this system incompatible with future revisions. I will try to make sure that such things are "optional" such that the system can function in a crippled way without support for these future additions when they come, but I make guarantees. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=head1 VIRTUAL FILE SYSTEM |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
Every file system is comprised of records. In the typical modern file system, you will find at least two types of objects: files and directories. However, this is by no means the only kind of objects in a file system. There might also be links, devices, FIFOs, etc. Rather than try and anticipate all of the possible variations in file type, the basic idea has been reduced to a single object, L. Module authors should see the documentation there for additional details. |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
The records of a file system are generally organized in a heirarchy. It is possible for this heirarchy to have a depth of 1 (i.e., it's flat). To keep everything standard, file paths are always separated by the forward slash ("/") and a lone slash indicates the "root". Some systems provide multiple roots (usually called "volumes"). If a file system module wishes to address this problem, it should do so by artificially establishing an ultimate root under which the volumes exist. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
In the heirarchy, the root has a special feature such that it is it's own parent. Any attempt to load the parent of the root, must load the root again. It should not be an error and it should never be able to reach some other object above the root (such as might be the case if a file system represents a "chroot" environment). Any other implementation is incorrect. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
=head2 FACTORY SYSTEM |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
The C module provides a central interface into loading other C modules. It provides a single method for instantiating a file system module: |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=over |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=item $root = File::System->new($module_name, ...) |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
This will create and return the root file system object (i.e., an instance of L) for the file system module named C<$module_name>. |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
If the C<$module_name> does not contain any colons, then it the package "C" is loaded and the C method for that package is used to create the object. Otherwise, the C<$module_name> is loaded and it's C method is used. For example, |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$fs = File::System->new('Real') |
53
|
|
|
|
|
|
|
# Module File::System::Real is loaded |
54
|
|
|
|
|
|
|
# Method File::System::Real->new is called |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
$fs = File::System->new('My::File::System::Foo') |
57
|
|
|
|
|
|
|
# Module My::File::System::Foo is loaded |
58
|
|
|
|
|
|
|
# Method My::File::System::Foo->new is called |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Any additional arguments passed to this method are then passed to the C method of the loaded package. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { |
65
|
18
|
|
|
18
|
1
|
6241
|
my $class = shift; |
66
|
18
|
|
|
|
|
48
|
my $fs = shift; |
67
|
|
|
|
|
|
|
|
68
|
18
|
50
|
|
|
|
122
|
$fs =~ /[\w:]+/ |
69
|
|
|
|
|
|
|
or die "The given FS package, $fs, doesn't appear to be a package name."; |
70
|
|
|
|
|
|
|
|
71
|
18
|
50
|
|
|
|
100
|
$fs =~ /:/ |
72
|
|
|
|
|
|
|
or $fs = "File::System::$fs"; |
73
|
|
|
|
|
|
|
|
74
|
7
|
|
|
7
|
|
6646
|
eval "use $fs"; |
|
7
|
|
|
|
|
28
|
|
|
7
|
|
|
|
|
165
|
|
|
18
|
|
|
|
|
346265
|
|
75
|
18
|
50
|
|
|
|
108
|
warn "Failed to load FS package, $fs: $@" if $@; |
76
|
|
|
|
|
|
|
|
77
|
18
|
|
|
|
|
41
|
my $result = eval { $fs->new(@_) }; |
|
18
|
|
|
|
|
108
|
|
78
|
18
|
50
|
|
|
|
86
|
if ($@) { |
79
|
0
|
|
|
|
|
0
|
$@ =~ s/ at .*$//s; |
80
|
0
|
0
|
|
|
|
0
|
croak $@ if $@; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
18
|
|
|
|
|
97
|
return $result; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=back |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
The returned object will behave according to the documentation available in L. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 BUGS |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Lots of methods need to be added to the drivers. There are lots of questions that still need to be answerable. Such as, can a particular directory of a file system contain only certain kinds of files? The C, C, and C methods should be optional and methods for checking if they are proper should exist. Anyway, lots more informational methods need to be added. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
The API is not set in stone yet. I'm going to start using it directly in another project of mine soon, so it is becoming solid. However, some aspects might be tweaked still. Hopefully, I will only be adding, but that doesn't much help a potential module author. I will put a note into the documentation when the API is locked in place. After that, I will require major version changes to change the API. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head1 SEE ALSO |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
L, L |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head1 AUTHOR |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Andrew Sterling Hanenkamp, Ehanenkamp@users.sourceforge.netE |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
Copyright 2005 Andrew Sterling Hanenkamp. All Rights Reserved. |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
This software is distributed and licensed under the same terms as Perl itself. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=cut |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
1 |