line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Copyright (c) 2014, cPanel, Inc. |
2
|
|
|
|
|
|
|
# All rights reserved. |
3
|
|
|
|
|
|
|
# http://cpanel.net/ |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# This is free software; you can redistribute it and/or modify it under the same |
6
|
|
|
|
|
|
|
# terms as Perl itself. See the LICENSE file for further details. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Filesys::POSIX::Inode; |
9
|
|
|
|
|
|
|
|
10
|
26
|
|
|
26
|
|
319
|
use strict; |
|
26
|
|
|
|
|
43
|
|
|
26
|
|
|
|
|
860
|
|
11
|
26
|
|
|
26
|
|
102
|
use warnings; |
|
26
|
|
|
|
|
27
|
|
|
26
|
|
|
|
|
557
|
|
12
|
|
|
|
|
|
|
|
13
|
26
|
|
|
26
|
|
104
|
use Filesys::POSIX::Bits; |
|
26
|
|
|
|
|
43
|
|
|
26
|
|
|
|
|
7369
|
|
14
|
26
|
|
|
26
|
|
9308
|
use Filesys::POSIX::Error qw(throw); |
|
26
|
|
|
|
|
45
|
|
|
26
|
|
|
|
|
13998
|
|
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Filesys::POSIX::Inode - Base class for filesystem inode objects |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 DESCRIPTION |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Provides a base class for filesystem-type dependent inode objects. This class |
23
|
|
|
|
|
|
|
offers a number of methods used to help determine the nature of the inode by |
24
|
|
|
|
|
|
|
analyzing its attributes. |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=over |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=item C<$inode-Edir> |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Returns true if the current inode refers to a directory. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub dir { |
35
|
1740
|
|
|
1740
|
1
|
4391
|
( shift->{'mode'} & $S_IFMT ) == $S_IFDIR; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=item C<$inode-Elink> |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
Returns true if the current inode is a symlink. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=cut |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub link { |
45
|
921
|
|
|
921
|
1
|
3112
|
( shift->{'mode'} & $S_IFMT ) == $S_IFLNK; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item C<$inode-Efile> |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Returns true if the current inode is a regular file. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub file { |
55
|
173
|
|
|
173
|
1
|
869
|
( shift->{'mode'} & $S_IFMT ) == $S_IFREG; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item C<$inode-Echar> |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns true if the current inode is a character device. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub char { |
65
|
96
|
|
|
96
|
1
|
483
|
( shift->{'mode'} & $S_IFMT ) == $S_IFCHR; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item C<$inode-Eblock> |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Returns true if the current inode is a block device. |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=cut |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
sub block { |
75
|
94
|
|
|
94
|
1
|
349
|
( shift->{'mode'} & $S_IFMT ) == $S_IFBLK; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=item C<$inode-Efifo> |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
Returns true if the current inode is a FIFO. |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub fifo { |
85
|
6
|
|
|
6
|
1
|
33
|
( shift->{'mode'} & $S_IFMT ) == $S_IFIFO; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item C<$inode-Esock> |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
Returns true if the current inode refers to a socket. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub sock { |
95
|
79
|
|
|
79
|
1
|
203
|
( shift->{'mode'} & $S_IFMT ) == $S_IFSOCK; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=item C<$inode-Emajor> |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
If the current inode is a block or character device, return the major number. |
101
|
|
|
|
|
|
|
Otherwise, an EINVAL is thrown. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub major { |
106
|
3
|
|
|
3
|
1
|
94
|
my ($self) = @_; |
107
|
|
|
|
|
|
|
|
108
|
3
|
100
|
100
|
|
|
12
|
throw &Errno::EINVAL unless $self->char || $self->block; |
109
|
|
|
|
|
|
|
|
110
|
2
|
|
|
|
|
10
|
return ( $self->{'rdev'} & 0xffff0000 ) >> 16; |
111
|
|
|
|
|
|
|
} |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=item C<$inode-Eminor> |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
If the current inode is a block or character device, return the minor number. |
116
|
|
|
|
|
|
|
Otherwise, an EINVAL is thrown. |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=cut |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub minor { |
121
|
3
|
|
|
3
|
1
|
831
|
my ($self) = @_; |
122
|
|
|
|
|
|
|
|
123
|
3
|
100
|
100
|
|
|
6
|
throw &Errno::EINVAL unless $self->char || $self->block; |
124
|
|
|
|
|
|
|
|
125
|
2
|
|
|
|
|
9
|
return $self->{'rdev'} & 0x0000ffff; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=item C<$inode-Eperms> |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
Returns the permissions bitfield value of the current inode's mode attribute. |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=cut |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
sub perms { |
135
|
6
|
|
|
6
|
1
|
27
|
shift->{'mode'} & $S_IPERM; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=item C<$inode-Ereadable> |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Returns true if the inode is readable by anyone. |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=cut |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
sub readable { |
145
|
7
|
|
|
7
|
1
|
33
|
( shift->{'mode'} & $S_IR ) != 0; |
146
|
|
|
|
|
|
|
} |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=item C<$inode-Ewritable> |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
Returns true if the inode is writable by anyone. |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=cut |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
sub writable { |
155
|
7
|
|
|
7
|
1
|
27
|
( shift->{'mode'} & $S_IW ) != 0; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=item C<$inode-Eexecutable> |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
Returns true if the inode is executable by anyone. |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=cut |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
sub executable { |
165
|
7
|
|
|
7
|
1
|
24
|
( shift->{'mode'} & $S_IX ) != 0; |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=item C<$inode-Esetuid> |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Returns true if the inode has a setuid bit set. |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=cut |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
sub setuid { |
175
|
7
|
|
|
7
|
1
|
34
|
( shift->{'mode'} & $S_ISUID ) != 0; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=item C<$inode-Esetgid> |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Returns true if the inode has a setgid bit set. |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=cut |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
sub setgid { |
185
|
7
|
|
|
7
|
1
|
28
|
( shift->{'mode'} & $S_ISGID ) != 0; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=item C<$inode-Eupdate(@st)> |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
Updates the current inode object with a list of values as returned by |
191
|
|
|
|
|
|
|
L. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=cut |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
sub update { |
196
|
39
|
|
|
39
|
1
|
86
|
my ( $self, @st ) = @_; |
197
|
|
|
|
|
|
|
|
198
|
39
|
|
|
|
|
102
|
@{$self}{qw(size atime mtime ctime uid gid mode rdev)} = |
|
39
|
|
|
|
|
261
|
|
199
|
|
|
|
|
|
|
( @st[ 7 .. 10 ], @st[ 4 .. 5 ], $st[2], $st[6] ); |
200
|
|
|
|
|
|
|
|
201
|
39
|
|
|
|
|
98
|
return $self; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
=item C<$inode-Edirectory> |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
If the current inode is a directory, return the directory object held by it. |
207
|
|
|
|
|
|
|
Otherwise, an ENOTDIR is thrown. |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
sub directory { |
212
|
1253
|
|
|
1253
|
1
|
1036
|
my ($self) = @_; |
213
|
|
|
|
|
|
|
|
214
|
1253
|
100
|
|
|
|
1765
|
throw &Errno::ENOTDIR unless $self->dir; |
215
|
|
|
|
|
|
|
|
216
|
1250
|
|
|
|
|
2336
|
return $self->{'directory'}; |
217
|
|
|
|
|
|
|
} |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item C<$inode-Eempty> |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Uses the above C<$inode-Edirectory()> call to obtain the directory for the |
222
|
|
|
|
|
|
|
current inode, and returns the result of C<$directory-Eempty()>. |
223
|
|
|
|
|
|
|
|
224
|
|
|
|
|
|
|
=cut |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
sub empty { |
227
|
5
|
|
|
5
|
1
|
6
|
my ($self) = @_; |
228
|
|
|
|
|
|
|
|
229
|
5
|
|
|
|
|
11
|
return $self->directory->empty; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=back |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=cut |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
1; |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
__END__ |