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
|
27
|
|
|
27
|
|
265
|
use strict; |
|
27
|
|
|
|
|
36
|
|
|
27
|
|
|
|
|
575
|
|
11
|
27
|
|
|
27
|
|
73
|
use warnings; |
|
27
|
|
|
|
|
28
|
|
|
27
|
|
|
|
|
726
|
|
12
|
|
|
|
|
|
|
|
13
|
27
|
|
|
27
|
|
75
|
use Filesys::POSIX::Bits; |
|
27
|
|
|
|
|
34
|
|
|
27
|
|
|
|
|
5994
|
|
14
|
27
|
|
|
27
|
|
8509
|
use Filesys::POSIX::Error qw(throw); |
|
27
|
|
|
|
|
43
|
|
|
27
|
|
|
|
|
11915
|
|
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
|
1788
|
|
|
1788
|
1
|
3789
|
( 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
|
863
|
|
|
863
|
1
|
2534
|
( 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
|
169
|
|
|
169
|
1
|
568
|
( 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
|
93
|
|
|
93
|
1
|
359
|
( 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
|
91
|
|
|
91
|
1
|
287
|
( 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
|
22
|
( 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
|
76
|
|
|
76
|
1
|
200
|
( 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
|
38
|
my ($self) = @_; |
107
|
|
|
|
|
|
|
|
108
|
3
|
100
|
100
|
|
|
5
|
throw &Errno::EINVAL unless $self->char || $self->block; |
109
|
|
|
|
|
|
|
|
110
|
2
|
|
|
|
|
6
|
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
|
555
|
my ($self) = @_; |
122
|
|
|
|
|
|
|
|
123
|
3
|
100
|
100
|
|
|
5
|
throw &Errno::EINVAL unless $self->char || $self->block; |
124
|
|
|
|
|
|
|
|
125
|
2
|
|
|
|
|
6
|
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
|
24
|
( 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
|
21
|
( 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
|
22
|
( 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
|
25
|
( 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
|
21
|
( 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
|
53
|
|
|
53
|
1
|
89
|
my ( $self, @st ) = @_; |
197
|
|
|
|
|
|
|
|
198
|
53
|
|
|
|
|
100
|
@{$self}{qw(size atime mtime ctime uid gid mode rdev)} = |
|
53
|
|
|
|
|
260
|
|
199
|
|
|
|
|
|
|
( @st[ 7 .. 10 ], @st[ 4 .. 5 ], $st[2], $st[6] ); |
200
|
|
|
|
|
|
|
|
201
|
53
|
|
|
|
|
115
|
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
|
1304
|
|
|
1304
|
1
|
967
|
my ($self) = @_; |
213
|
|
|
|
|
|
|
|
214
|
1304
|
100
|
|
|
|
1418
|
throw &Errno::ENOTDIR unless $self->dir; |
215
|
|
|
|
|
|
|
|
216
|
1301
|
|
|
|
|
1996
|
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
|
4
|
my ($self) = @_; |
228
|
|
|
|
|
|
|
|
229
|
5
|
|
|
|
|
6
|
return $self->directory->empty; |
230
|
|
|
|
|
|
|
} |
231
|
|
|
|
|
|
|
|
232
|
|
|
|
|
|
|
=back |
233
|
|
|
|
|
|
|
|
234
|
|
|
|
|
|
|
=cut |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
1; |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
__END__ |