| 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; | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | 25 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 25 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 25 | ▶ | use Filesys::POSIX::Mem (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 25 | ▶ | use Filesys::POSIX::FdTable (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 25 | ▶ | use Filesys::POSIX::Path (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 25 | ▶ | use Filesys::POSIX::VFS (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | 25 | ▶ | use Filesys::POSIX::Bits; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | 25 | ▶ | use Filesys::POSIX::IO (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 25 | ▶ | use Filesys::POSIX::Mount (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 25 | ▶ | use Filesys::POSIX::Userland (); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 25 | ▶ | use Filesys::POSIX::Error qw(throw); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 25 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 25 | our $VERSION = '0.9.19'; | |||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | =head1 NAME | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | Filesys::POSIX - Provide POSIX-like filesystem semantics in pure Perl | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||
| 35 | use Filesys::POSIX | ||||||||||||||||||||||||||||
| 36 | use Filesys::POSIX::Mem; | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | my $fs = Filesys::POSIX->new(Filesys::POSIX::Mem->new, | ||||||||||||||||||||||||||||
| 39 | 'noatime' => 1 | ||||||||||||||||||||||||||||
| 40 | ); | ||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | $fs->umask(0700); | ||||||||||||||||||||||||||||
| 43 | $fs->mkdir('foo'); | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | my $fd = $fs->open('/foo/bar', $O_CREAT | $O_WRONLY); | ||||||||||||||||||||||||||||
| 46 | my $inode = $fs->fstat($fd); | ||||||||||||||||||||||||||||
| 47 | $fs->printf("I have mode 0%o\n", $inode->{'mode'}); | ||||||||||||||||||||||||||||
| 48 | $fs->close($fd); | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | Filesys::POSIX provides a fairly complete suite of tools comprising the | ||||||||||||||||||||||||||||
| 53 | semantics of a POSIX filesystem, with path resolution, mount points, inodes, | ||||||||||||||||||||||||||||
| 54 | a VFS, and some common utilities found in the userland. Some features not | ||||||||||||||||||||||||||||
| 55 | found in a normal POSIX environment include the ability to perform cross- | ||||||||||||||||||||||||||||
| 56 | mountpoint hard links (aliasing), mapping portions of the real filesystem into | ||||||||||||||||||||||||||||
| 57 | an instance of a virtual filesystem, and allowing the developer to attach and | ||||||||||||||||||||||||||||
| 58 | replace inodes at arbitrary points with replacements of their own | ||||||||||||||||||||||||||||
| 59 | specification. | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | Two filesystem types are provided out-of-the-box: A filesystem that lives in | ||||||||||||||||||||||||||||
| 62 | memory completely, and a filesystem that provides a "portal" to any given | ||||||||||||||||||||||||||||
| 63 | portion of the real underlying filesystem. | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | By and large, the manner in which data is structured is quite similar to a | ||||||||||||||||||||||||||||
| 66 | real kernel filesystem implementation, with some differences: VFS inodes are | ||||||||||||||||||||||||||||
| 67 | not created for EVERY disk inode (only mount points); inodes are not referred | ||||||||||||||||||||||||||||
| 68 | to numerically, but rather by Perl reference; and, directory entries can be | ||||||||||||||||||||||||||||
| 69 | implemented in a device-specific manner, as long as they adhere to the normal | ||||||||||||||||||||||||||||
| 70 | interface specified within. | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | =head1 INSTANTIATING THE FILESYSTEM ENVIRONMENT | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | =over | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | =item C<Filesys::POSIX-E<gt>new($rootfs, %opts)> | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | Create a new filesystem environment, specifying a reference to an | ||||||||||||||||||||||||||||
| 79 | uninitialized instance of a filesystem type object to be mounted at the root | ||||||||||||||||||||||||||||
| 80 | of the virtual filesystem. Options passed will be passed to the filesystem | ||||||||||||||||||||||||||||
| 81 | initialization method C<$rootfs-E<gt>init()> in flat hash form, and passed on | ||||||||||||||||||||||||||||
| 82 | again to the VFS, where the options will be stored for later retrieval. | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | =back | ||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||
| 86 | =head1 ERROR HANDLING | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | Errors are emitted in the form of exceptions thrown by | ||||||||||||||||||||||||||||
| 89 | L<C<Carp::confess()>|Carp/confess>, with full stack traces. Where possible, | ||||||||||||||||||||||||||||
| 90 | L<C<$!>|perlvar/$!> is set with an appropriate error code from L<Errno>, and a | ||||||||||||||||||||||||||||
| 91 | stringified L<C<$!>|perlvar/$!> is thrown. | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | =cut | ||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 42 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 96 | 42 | my ( $class, $rootfs, %opts ) = @_; | |||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 42 | ▶ | confess('No root filesystem specified') unless $rootfs; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 41 | $rootfs->init(%opts); | |||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 39 | my $vfs = Filesys::POSIX::VFS->new->mount( $rootfs, '/', $rootfs->{'root'}, %opts ); | |||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | return bless { | ||||||||||||||||||||||||||||
| 105 | 'methods' => {}, | ||||||||||||||||||||||||||||
| 106 | 'umask' => 022, | ||||||||||||||||||||||||||||
| 107 | 'fds' => Filesys::POSIX::FdTable->new, | ||||||||||||||||||||||||||||
| 108 | 'cwd' => $rootfs->{'root'}, | ||||||||||||||||||||||||||||
| 109 | 'root' => $rootfs->{'root'}, | ||||||||||||||||||||||||||||
| 110 | 'vfs' => $vfs, | ||||||||||||||||||||||||||||
| 111 | 'cwd' => $vfs->vnode( $rootfs->{'root'} ), | ||||||||||||||||||||||||||||
| 112 | 39 | 'root' => $vfs->vnode( $rootfs->{'root'} ) | |||||||||||||||||||||||||||
| 113 | }, $class; | ||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | =head1 SYSTEM CALLS | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | =over | ||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||
| 120 | =item C<$fs-E<gt>umask()> | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | =item C<$fs-E<gt>umask($mode)> | ||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | When called without an argument, the current umask value is returned. When a | ||||||||||||||||||||||||||||
| 125 | value is specified, the current umask is modified to that value, and is | ||||||||||||||||||||||||||||
| 126 | returned once set. | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | =cut | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 4 | ▶ | sub umask { | ||||||||||||||||||||||||||
|
Subroutine
umask: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 131 | 4 | my ( $self, $umask ) = @_; | |||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | 4 | ▶ | return $self->{'umask'} = $umask if defined $umask; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 2 | return $self->{'umask'}; | |||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||
| 137 | 475 | ▶ | sub _find_inode { | ||||||||||||||||||||||||||
|
Subroutine
_find_inode: called CC=12 SCAR=24.8
| |||||||||||||||||||||||||||||
| 138 | 475 | my ( $self, $path, %opts ) = @_; | |||||||||||||||||||||||||||
| 139 | 475 | my $hier = Filesys::POSIX::Path->new($path); | |||||||||||||||||||||||||||
| 140 | 475 | my $dir = $self->{'cwd'}; | |||||||||||||||||||||||||||
| 141 | 475 | my $inode; | |||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 475 | ▶ | return $self->{'root'} if $hier->full eq '/'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 444 | ▶ | while ( $hier->count ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 146 | 917 | my $item = $hier->shift; | |||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | # | ||||||||||||||||||||||||||||
| 149 | # We've encountered an absolute path. Start from the beginning. | ||||||||||||||||||||||||||||
| 150 | # | ||||||||||||||||||||||||||||
| 151 | 917 | ▶ | unless (length $item) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 152 | 232 | $dir = $self->{'root'}; | |||||||||||||||||||||||||||
| 153 | 232 | next; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | # | ||||||||||||||||||||||||||||
| 157 | # Before we go further, we need to resolve the current directory for | ||||||||||||||||||||||||||||
| 158 | # a possible VFS inode in the event of a mountpoint or filesystem root. | ||||||||||||||||||||||||||||
| 159 | # | ||||||||||||||||||||||||||||
| 160 | 685 | $dir = $self->{'vfs'}->vnode($dir); | |||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | 685 | ▶ | unless ( $dir->{'dev'}->{'flags'}->{'noatime'} ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 163 | 451 | $dir->{'atime'} = time; | |||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | # | ||||||||||||||||||||||||||||
| 167 | # From this point, deal with the directory in terms of a directory entry. | ||||||||||||||||||||||||||||
| 168 | # | ||||||||||||||||||||||||||||
| 169 | 685 | my $directory = $dir->directory; | |||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||
| 171 | 684 | ▶ | if ( $item eq '.' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 172 | 101 | $inode = $dir; | |||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | elsif ( $item eq '..' ) { | ||||||||||||||||||||||||||||
| 175 | 7 | my $vnode = $self->{'vfs'}->vnode($dir); | |||||||||||||||||||||||||||
| 176 | $inode = | ||||||||||||||||||||||||||||
| 177 | $vnode->{'parent'} | ||||||||||||||||||||||||||||
| 178 | ? $vnode->{'parent'} | ||||||||||||||||||||||||||||
| 179 | 7 | ▶ | : $self->{'vfs'}->vnode( $directory->get('..') ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | else { | ||||||||||||||||||||||||||||
| 182 | 576 | $inode = $self->{'vfs'}->vnode( $directory->get($item) ); | |||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 684 | $! = 0; | |||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 684 | ▶ | throw &Errno::ENOENT unless $inode; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 663 | ▶ | if ( $inode->link ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | $hier = $hier->concat( $inode->readlink ) | ||||||||||||||||||||||||||||
| 191 | 16 | ▶ | if $opts{'resolve_symlinks'} || $hier->count; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$opts{"resolve_symlinks"} or $hier->count
MC/DC100%2/2
$opts{"resolve_symlinks"} or $hier->count
$opts{"resolve_symlinks"}
$hier->count
Truth table100%3/3
A or B
A= $opts{"resolve_symlinks"}B= $hier->count
| |||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||
| 193 | else { | ||||||||||||||||||||||||||||
| 194 | 647 | $dir = $inode; | |||||||||||||||||||||||||||
| 195 | } | ||||||||||||||||||||||||||||
| 196 | } | ||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 422 | return $inode; | |||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||
| 201 | =item C<$fs-E<gt>stat($path)> | ||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | Resolve the given path for an inode in the filesystem. If the inode found is | ||||||||||||||||||||||||||||
| 204 | a symlink, the path of that symlink will be resolved in turn until the desired | ||||||||||||||||||||||||||||
| 205 | inode is located. | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | Paths will be resolved relative to the current working directory when not | ||||||||||||||||||||||||||||
| 208 | prefixed with a slash ('C</>'), and will be resolved relative to the root | ||||||||||||||||||||||||||||
| 209 | directory when prefixed with a slash ('C</>'). | ||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||
| 211 | =cut | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | 376 | ▶ | sub stat { | ||||||||||||||||||||||||||
|
Subroutine
stat: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 214 | 376 | my ( $self, $path ) = @_; | |||||||||||||||||||||||||||
| 215 | 376 | return $self->_find_inode( $path, 'resolve_symlinks' => 1 ); | |||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | =item C<$fs-E<gt>lstat($path)> | ||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||
| 220 | Resolve the given path for an inode in the filesystem. Unlinke | ||||||||||||||||||||||||||||
| 221 | C<$fs-E<gt>stat()>, the inode found will be returned literally in the case of a | ||||||||||||||||||||||||||||
| 222 | symlink. | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | =cut | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | 99 | ▶ | sub lstat { | ||||||||||||||||||||||||||
|
Subroutine
lstat: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 227 | 99 | my ( $self, $path ) = @_; | |||||||||||||||||||||||||||
| 228 | 99 | return $self->_find_inode($path); | |||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | =item C<$fs-E<gt>fstat($fd)> | ||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||
| 233 | Return the inode corresponding to the open file descriptor passed. An | ||||||||||||||||||||||||||||
| 234 | exception will be thrown by the file descriptor lookup module if the file | ||||||||||||||||||||||||||||
| 235 | descriptor passed does not correspond to an open file. | ||||||||||||||||||||||||||||
| 236 | |||||||||||||||||||||||||||||
| 237 | =cut | ||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||
| 239 | 51 | ▶ | sub fstat { | ||||||||||||||||||||||||||
|
Subroutine
fstat: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 240 | 51 | my ( $self, $fd ) = @_; | |||||||||||||||||||||||||||
| 241 | 51 | return $self->{'fds'}->lookup($fd)->{'inode'}; | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | =item C<$fs-E<gt>chdir($path)> | ||||||||||||||||||||||||||||
| 245 | |||||||||||||||||||||||||||||
| 246 | Change the current working directory to the path specified. An | ||||||||||||||||||||||||||||
| 247 | C<$fs-E<gt>stat()> call will be used internally to lookup the inode for that | ||||||||||||||||||||||||||||
| 248 | path; an ENOTDIR will be thrown unless the inode found is a directory. The | ||||||||||||||||||||||||||||
| 249 | internal current working directory pointer will be updated with the directory | ||||||||||||||||||||||||||||
| 250 | inode found; this same inode will also be returned. | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | =cut | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 8 | ▶ | sub chdir { | ||||||||||||||||||||||||||
|
Subroutine
chdir: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 255 | 8 | my ( $self, $path ) = @_; | |||||||||||||||||||||||||||
| 256 | 8 | my $inode = $self->stat($path); | |||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 8 | $! = 0; | |||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 8 | ▶ | throw &Errno::ENOTDIR unless $inode->dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||
| 262 | 7 | return $self->{'cwd'} = $inode; | |||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | =item C<$fs-E<gt>fchdir($fd)> | ||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||
| 267 | When passed a file descriptor for a directory, update the internal pointer to | ||||||||||||||||||||||||||||
| 268 | the current working directory to that directory resolved from the file | ||||||||||||||||||||||||||||
| 269 | descriptor table, and return the same directory inode. If the inode is not a | ||||||||||||||||||||||||||||
| 270 | directory, an ENOTDIR will be thrown. | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | =cut | ||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | 2 | ▶ | sub fchdir { | ||||||||||||||||||||||||||
|
Subroutine
fchdir: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 275 | 2 | my ( $self, $fd ) = @_; | |||||||||||||||||||||||||||
| 276 | 2 | my $inode = $self->fstat($fd); | |||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||
| 278 | 2 | $! = 0; | |||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||
| 280 | 2 | ▶ | throw &Errno::ENOTDIR unless $inode->dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 1 | return $self->{'cwd'} = $inode; | |||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||
| 285 | =item C<$fs-E<gt>chown($path, $uid, $gid)> | ||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||
| 287 | Using C<$fs-E<gt>stat()> to locate the inode of the path specified, update that | ||||||||||||||||||||||||||||
| 288 | inode object's 'uid' and 'gid' fields with the values specified. The inode of | ||||||||||||||||||||||||||||
| 289 | the file modified will be returned. | ||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||
| 291 | =cut | ||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 1 | ▶ | sub chown { | ||||||||||||||||||||||||||
|
Subroutine
chown: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 294 | 1 | my ( $self, $path, $uid, $gid ) = @_; | |||||||||||||||||||||||||||
| 295 | 1 | my $inode = $self->stat($path); | |||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 1 | $inode->chown( $uid, $gid ); | |||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 1 | return $inode; | |||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | =item C<$fs-E<gt>fchown($fd, $uid, $gid)> | ||||||||||||||||||||||||||||
| 303 | |||||||||||||||||||||||||||||
| 304 | Using C<$fs-E<gt>fstat()> to locate the inode of the file descriptor specified, | ||||||||||||||||||||||||||||
| 305 | update that inode object's 'uid' and 'gid' fields with the values specified. A | ||||||||||||||||||||||||||||
| 306 | reference to the affected inode will be returned. | ||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||
| 308 | =cut | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | 1 | ▶ | sub fchown { | ||||||||||||||||||||||||||
|
Subroutine
fchown: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 311 | 1 | my ( $self, $fd, $uid, $gid ) = @_; | |||||||||||||||||||||||||||
| 312 | 1 | my $inode = $self->fstat($fd); | |||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||
| 314 | 1 | $inode->chown( $uid, $gid ); | |||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | 1 | return $inode; | |||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | =item C<$fs-E<gt>chmod($path, $mode)> | ||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | Using C<$fs-E<gt>stat()> to locate the inode of the path specified, update that | ||||||||||||||||||||||||||||
| 322 | inode object's 'mode' field with the value specified. A reference to the | ||||||||||||||||||||||||||||
| 323 | affected inode will be returned. | ||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | =cut | ||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||
| 327 | 10 | ▶ | sub chmod { | ||||||||||||||||||||||||||
|
Subroutine
chmod: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 328 | 10 | my ( $self, $path, $mode ) = @_; | |||||||||||||||||||||||||||
| 329 | 10 | my $inode = $self->stat($path); | |||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||
| 331 | 10 | $inode->chmod($mode); | |||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||
| 333 | 10 | return $inode; | |||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||
| 336 | =item C<$fs-E<gt>fchmod($fd, $mode)> | ||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||
| 338 | Using C<$fs-E<gt>fstat()> to locate the inode of the file descriptor specified, | ||||||||||||||||||||||||||||
| 339 | update that inode object's 'mode' field with the value specified. A reference | ||||||||||||||||||||||||||||
| 340 | to that inode will be returned. | ||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||
| 342 | =cut | ||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 6 | ▶ | sub fchmod { | ||||||||||||||||||||||||||
|
Subroutine
fchmod: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 345 | 6 | my ( $self, $fd, $mode ) = @_; | |||||||||||||||||||||||||||
| 346 | 6 | my $inode = $self->fstat($fd); | |||||||||||||||||||||||||||
| 347 | |||||||||||||||||||||||||||||
| 348 | 6 | $inode->chmod($mode); | |||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||
| 350 | 6 | return $inode; | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | =item C<$fs-E<gt>mkdir($path)> | ||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||
| 355 | =item C<$fs-E<gt>mkdir($path, $mode)> | ||||||||||||||||||||||||||||
| 356 | |||||||||||||||||||||||||||||
| 357 | Create a new directory at the path specified, applying the permissions field in | ||||||||||||||||||||||||||||
| 358 | the mode value specified. If no mode is specified, the default permissions of | ||||||||||||||||||||||||||||
| 359 | I<0777> will be modified by the current umask value. An ENOTDIR exception will | ||||||||||||||||||||||||||||
| 360 | be thrown in case the intended parent of the directory to be created is not | ||||||||||||||||||||||||||||
| 361 | actually a directory itself. | ||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||
| 363 | A reference to the newly-created directory inode will be returned. | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | =cut | ||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||
| 367 | 59 | ▶ | sub mkdir { | ||||||||||||||||||||||||||
|
Subroutine
mkdir: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 368 | 59 | my ( $self, $path, $mode ) = @_; | |||||||||||||||||||||||||||
| 369 | 59 | my $hier = Filesys::POSIX::Path->new($path); | |||||||||||||||||||||||||||
| 370 | 59 | my $name = $hier->basename; | |||||||||||||||||||||||||||
| 371 | 59 | my $parent = $self->stat( $hier->dirname ); | |||||||||||||||||||||||||||
| 372 | 59 | ▶ | my $perm = $mode ? $mode & ( $S_IPERM | $S_IPROT ) : $S_IPERM ^ $self->{'umask'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 59 | return $parent->child( $name, $perm | $S_IFDIR ); | |||||||||||||||||||||||||||
| 375 | } | ||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||
| 377 | =item C<$fs-E<gt>link($src, $dest)> | ||||||||||||||||||||||||||||
| 378 | |||||||||||||||||||||||||||||
| 379 | Using C<$fs-E<gt>stat()> to resolve the path of the link source, and the parent | ||||||||||||||||||||||||||||
| 380 | of the link destination, C<$fs-E<gt>link()> place a reference to the source | ||||||||||||||||||||||||||||
| 381 | inode in the location specified by the destination. | ||||||||||||||||||||||||||||
| 382 | |||||||||||||||||||||||||||||
| 383 | If a destination inode already exists, it will only be able to be replaced by | ||||||||||||||||||||||||||||
| 384 | the source if both are either directories or non-directories. If the source | ||||||||||||||||||||||||||||
| 385 | and destination are both directories, the destination will only be replaced if | ||||||||||||||||||||||||||||
| 386 | the directory entry for the destination is empty. | ||||||||||||||||||||||||||||
| 387 | |||||||||||||||||||||||||||||
| 388 | Links traversing filesystem mount points are not allowed. This functionality | ||||||||||||||||||||||||||||
| 389 | is provided in the C<alias()> call provided by the L<Filesys::POSIX::Extensions> | ||||||||||||||||||||||||||||
| 390 | module. Upon success, a reference to the inode for which a new link is to be | ||||||||||||||||||||||||||||
| 391 | created will be returned. | ||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||
| 393 | Exceptions thrown: | ||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||
| 395 | =over | ||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||
| 397 | =item * EXDEV (Cross-device link) | ||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||
| 399 | The inode resolved for the link source is not associated with the same device | ||||||||||||||||||||||||||||
| 400 | as the inode of the destination's parent directory. | ||||||||||||||||||||||||||||
| 401 | |||||||||||||||||||||||||||||
| 402 | =item * EISDIR (Is a directory) | ||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||
| 404 | Thrown if the source inode is a directory. Hard links can only be made for | ||||||||||||||||||||||||||||
| 405 | non-directory inodes. | ||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||
| 407 | =item * EEXIST (File exists) | ||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||
| 409 | Thrown if an entry at the destination path already exists. | ||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||
| 411 | =back | ||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||
| 413 | =cut | ||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||
| 415 | 5 | ▶ | sub link { | ||||||||||||||||||||||||||
|
Subroutine
link: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 416 | 5 | my ( $self, $src, $dest ) = @_; | |||||||||||||||||||||||||||
| 417 | 5 | my $hier = Filesys::POSIX::Path->new($dest); | |||||||||||||||||||||||||||
| 418 | 5 | my $name = $hier->basename; | |||||||||||||||||||||||||||
| 419 | 5 | my $inode = $self->stat($src); | |||||||||||||||||||||||||||
| 420 | 5 | my $parent = $self->stat( $hier->dirname ); | |||||||||||||||||||||||||||
| 421 | 5 | my $directory = $parent->directory; | |||||||||||||||||||||||||||
| 422 | |||||||||||||||||||||||||||||
| 423 | 5 | $! = 0; | |||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||
| 425 | 5 | ▶ | throw &Errno::EXDEV unless $inode->{'dev'} == $parent->{'dev'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 426 | 4 | ▶ | throw &Errno::EISDIR if $inode->dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 427 | 3 | ▶ | throw &Errno::EEXIST if $directory->exists($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 428 | |||||||||||||||||||||||||||||
| 429 | 2 | $directory->set( $name, $inode ); | |||||||||||||||||||||||||||
| 430 | |||||||||||||||||||||||||||||
| 431 | 2 | return $inode; | |||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||
| 434 | =item C<$fs-E<gt>symlink($old, $new)> | ||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||
| 436 | The path in the first argument specified, C<$old>, is cleaned up using | ||||||||||||||||||||||||||||
| 437 | C<Filesys::POSIX::Path-E<gt>full>, and stored in a new symlink inode created | ||||||||||||||||||||||||||||
| 438 | in the location specified by C<$new>. An EEXIST exception will be thrown if an | ||||||||||||||||||||||||||||
| 439 | inode at the path indicated by C<$new> exists. A reference to the newly-created | ||||||||||||||||||||||||||||
| 440 | symlink inode will be returned. | ||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||
| 442 | =cut | ||||||||||||||||||||||||||||
| 443 | |||||||||||||||||||||||||||||
| 444 | 15 | ▶ | sub symlink { | ||||||||||||||||||||||||||
|
Subroutine
symlink: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 445 | 15 | my ( $self, $old, $new ) = @_; | |||||||||||||||||||||||||||
| 446 | 15 | my $perms = $S_IPERM ^ $self->{'umask'}; | |||||||||||||||||||||||||||
| 447 | 15 | my $hier = Filesys::POSIX::Path->new($new); | |||||||||||||||||||||||||||
| 448 | 15 | my $name = $hier->basename; | |||||||||||||||||||||||||||
| 449 | 15 | my $parent = $self->stat( $hier->dirname ); | |||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||
| 451 | 15 | return $parent->child( $name, $S_IFLNK | $perms )->symlink( Filesys::POSIX::Path->full($old) ); | |||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||
| 454 | =item C<$fs-E<gt>readlink($path)> | ||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||
| 456 | Using C<$fs-E<gt>lstat()> to resolve the given path for an inode, the symlink | ||||||||||||||||||||||||||||
| 457 | destination path associated with the inode is returned as a string. An EINVAL | ||||||||||||||||||||||||||||
| 458 | exception is thrown unless the inode found is indeed a symlink. | ||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||
| 460 | =cut | ||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||
| 462 | 2 | ▶ | sub readlink { | ||||||||||||||||||||||||||
|
Subroutine
readlink: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 463 | 2 | my ( $self, $path ) = @_; | |||||||||||||||||||||||||||
| 464 | 2 | my $inode = $self->lstat($path); | |||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||
| 466 | 2 | $! = 0; | |||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||
| 468 | 2 | ▶ | throw &Errno::EINVAL unless $inode->link; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||
| 470 | 1 | return $inode->readlink; | |||||||||||||||||||||||||||
| 471 | } | ||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||
| 473 | =item C<$fs-E<gt>unlink($path)> | ||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||
| 475 | Using C<$fs-E<gt>lstat()> to resolve the given path for an inode specified, | ||||||||||||||||||||||||||||
| 476 | said inode will be removed from its parent directory entry. The following | ||||||||||||||||||||||||||||
| 477 | exceptions will be thrown in the event of certain errors: | ||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||
| 479 | =over | ||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||
| 481 | =item * ENOENT (No such file or directory) | ||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||
| 483 | No entry was found in the path's parent directory for the item specified in the | ||||||||||||||||||||||||||||
| 484 | path. | ||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||
| 486 | =item * EISDIR (Is a directory) | ||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||
| 488 | C<$fs-E<gt>unlink()> was called with a directory specified. | ||||||||||||||||||||||||||||
| 489 | C<$fs-E<gt>rmdir()> must be used instead for removing directory inodes. | ||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||
| 491 | =back | ||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||
| 493 | Upon success, a reference to the inode removed from its parent directory will | ||||||||||||||||||||||||||||
| 494 | be returned. | ||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||
| 496 | =cut | ||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||
| 498 | 4 | ▶ | sub unlink { | ||||||||||||||||||||||||||
|
Subroutine
unlink: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 499 | 4 | my ( $self, $path ) = @_; | |||||||||||||||||||||||||||
| 500 | 4 | my $hier = Filesys::POSIX::Path->new($path); | |||||||||||||||||||||||||||
| 501 | 4 | my $name = $hier->basename; | |||||||||||||||||||||||||||
| 502 | 4 | my $parent = $self->lstat( $hier->dirname ); | |||||||||||||||||||||||||||
| 503 | 4 | my $directory = $parent->directory; | |||||||||||||||||||||||||||
| 504 | 4 | my $inode = $directory->get($name); | |||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||
| 506 | 4 | $! = 0; | |||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||
| 508 | 4 | ▶ | throw &Errno::ENOENT unless $inode; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 509 | 3 | ▶ | throw &Errno::EISDIR if $inode->dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 510 | |||||||||||||||||||||||||||||
| 511 | 2 | $directory->delete($name); | |||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||
| 513 | 2 | return $inode; | |||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||
| 516 | =item C<$fs-E<gt>rename($old, $new)> | ||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||
| 518 | Relocate the item specified by the C<$old> argument to the new path specified by | ||||||||||||||||||||||||||||
| 519 | $new. | ||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||
| 521 | Using C<$fs-E<gt>lstat>, the inode for the old pathname is resolved; | ||||||||||||||||||||||||||||
| 522 | C<$fs-E<gt>stat> is then used to resolve the path of the parent directory of | ||||||||||||||||||||||||||||
| 523 | the argument specified in C<$new>. | ||||||||||||||||||||||||||||
| 524 | |||||||||||||||||||||||||||||
| 525 | If an inode exists at the path specified by C<$new>, it will be replaced by | ||||||||||||||||||||||||||||
| 526 | C<$old> in the following circumstances: | ||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||
| 528 | =over | ||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||
| 530 | =item Both the source C<$old> and destination C<$new> are non-directory inodes. | ||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||
| 532 | =item Both the source C<$old> and destination C<$new> are directory inodes, and | ||||||||||||||||||||||||||||
| 533 | the destination is empty. | ||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||
| 535 | =back | ||||||||||||||||||||||||||||
| 536 | |||||||||||||||||||||||||||||
| 537 | The following exceptions are thrown for error conditions: | ||||||||||||||||||||||||||||
| 538 | |||||||||||||||||||||||||||||
| 539 | =over | ||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||
| 541 | =item * EPERM (Operation not permitted) | ||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||
| 543 | Currently, C<$fs-E<gt>rename()> cannot operate if the inode at the old location | ||||||||||||||||||||||||||||
| 544 | is an inode associated with a Filesys::POSIX::Real filesystem type. | ||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||
| 546 | =item * EXDEV (Cross-device link) | ||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||
| 548 | The inode at the old path does not exist on the same filesystem device as the | ||||||||||||||||||||||||||||
| 549 | inode of the parent directory specified in the new path. | ||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||
| 551 | =item * ENOTDIR (Not a directory) | ||||||||||||||||||||||||||||
| 552 | |||||||||||||||||||||||||||||
| 553 | The old inode is a directory, but an existing inode found in the new path | ||||||||||||||||||||||||||||
| 554 | specified, is not. | ||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||
| 556 | =item * EISDIR (Is a directory) | ||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||
| 558 | The old inode is not a directory, but an existing inode found in the new path | ||||||||||||||||||||||||||||
| 559 | specified, is. | ||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||
| 561 | =item * ENOTEMPTY (Directory not empty) | ||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||
| 563 | Both the old and new paths correspond to a directory, but the new path is not | ||||||||||||||||||||||||||||
| 564 | of an empty directory. | ||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||
| 566 | =back | ||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||
| 568 | Upon success, a reference to the inode to be renamed will be returned. | ||||||||||||||||||||||||||||
| 569 | |||||||||||||||||||||||||||||
| 570 | =cut | ||||||||||||||||||||||||||||
| 571 | |||||||||||||||||||||||||||||
| 572 | 10 | ▶ | sub rename { | ||||||||||||||||||||||||||
|
Subroutine
rename: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||
| 573 | 10 | my ( $self, $old, $new ) = @_; | |||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||
| 575 | 10 | my $inode = $self->lstat($old); | |||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||
| 577 | 10 | my $old_hier = Filesys::POSIX::Path->new($old); | |||||||||||||||||||||||||||
| 578 | 10 | my $old_name = $old_hier->basename; | |||||||||||||||||||||||||||
| 579 | 10 | my $old_parent = $self->stat( $old_hier->dirname ); | |||||||||||||||||||||||||||
| 580 | 10 | my $old_dir = $old_parent->directory; | |||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||
| 582 | 10 | my $new_hier = Filesys::POSIX::Path->new($new); | |||||||||||||||||||||||||||
| 583 | 10 | my $new_name = $new_hier->basename; | |||||||||||||||||||||||||||
| 584 | 10 | my $new_parent = $self->stat( $new_hier->dirname ); | |||||||||||||||||||||||||||
| 585 | 10 | my $new_dir = $new_parent->directory; | |||||||||||||||||||||||||||
| 586 | |||||||||||||||||||||||||||||
| 587 | 10 | $! = 0; | |||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||
| 589 | 10 | ▶ | throw &Errno::EXDEV unless $inode->{'dev'} eq $new_parent->{'dev'}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||
| 591 | 9 | ▶ | if ( my $existing = $new_dir->get($new_name) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 592 | 5 | ▶ | if ( $inode->dir ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 593 | 3 | ▶ | throw &Errno::ENOTDIR unless $existing->dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 594 | 2 | ▶ | throw &Errno::ENOTEMPTY unless $existing->empty; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 595 | } | ||||||||||||||||||||||||||||
| 596 | else { | ||||||||||||||||||||||||||||
| 597 | 2 | ▶ | throw &Errno::EISDIR if $existing->dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 598 | } | ||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||
| 601 | 6 | $new_dir->rename_member( $inode, $old_dir, $old_name, $new_name ); | |||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||
| 603 | 6 | return $inode; | |||||||||||||||||||||||||||
| 604 | } | ||||||||||||||||||||||||||||
| 605 | |||||||||||||||||||||||||||||
| 606 | =item C<$fs-E<gt>rmdir($path)> | ||||||||||||||||||||||||||||
| 607 | |||||||||||||||||||||||||||||
| 608 | Unlinks the directory inode at the specified path. Exceptions are thrown in | ||||||||||||||||||||||||||||
| 609 | the following conditions: | ||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||
| 611 | =over | ||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||
| 613 | =item * ENOENT (No such file or directory) | ||||||||||||||||||||||||||||
| 614 | |||||||||||||||||||||||||||||
| 615 | No inode exists by the name specified in the final component of the path in | ||||||||||||||||||||||||||||
| 616 | the parent directory specified in the path. | ||||||||||||||||||||||||||||
| 617 | |||||||||||||||||||||||||||||
| 618 | =item * EBUSY (Device or resource busy) | ||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||
| 620 | The directory specified is an active mount point. | ||||||||||||||||||||||||||||
| 621 | |||||||||||||||||||||||||||||
| 622 | =item * ENOTDIR (Not a directory) | ||||||||||||||||||||||||||||
| 623 | |||||||||||||||||||||||||||||
| 624 | The inode found at C<$path> is not a directory. | ||||||||||||||||||||||||||||
| 625 | |||||||||||||||||||||||||||||
| 626 | =item * ENOTEMPTY (Directory not empty) | ||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||
| 628 | The directory is not empty. | ||||||||||||||||||||||||||||
| 629 | |||||||||||||||||||||||||||||
| 630 | =back | ||||||||||||||||||||||||||||
| 631 | |||||||||||||||||||||||||||||
| 632 | Upon success, a reference to the inode of the directory to be removed will be | ||||||||||||||||||||||||||||
| 633 | returned. | ||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||
| 635 | =cut | ||||||||||||||||||||||||||||
| 636 | |||||||||||||||||||||||||||||
| 637 | 5 | ▶ | sub rmdir { | ||||||||||||||||||||||||||
|
Subroutine
rmdir: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 638 | 5 | my ( $self, $path ) = @_; | |||||||||||||||||||||||||||
| 639 | 5 | my $hier = Filesys::POSIX::Path->new($path); | |||||||||||||||||||||||||||
| 640 | 5 | my $name = $hier->basename; | |||||||||||||||||||||||||||
| 641 | 5 | my $parent = $self->lstat( $hier->dirname ); | |||||||||||||||||||||||||||
| 642 | 5 | my $directory = $parent->directory; | |||||||||||||||||||||||||||
| 643 | 5 | my $inode = $directory->get($name); | |||||||||||||||||||||||||||
| 644 | |||||||||||||||||||||||||||||
| 645 | 5 | $! = 0; | |||||||||||||||||||||||||||
| 646 | |||||||||||||||||||||||||||||
| 647 | 5 | ▶ | throw &Errno::ENOENT unless $inode; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 648 | |||||||||||||||||||||||||||||
| 649 | 4 | ▶ | throw &Errno::EBUSY if $self->{'vfs'}->statfs( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 650 | $self->stat($path), | ||||||||||||||||||||||||||||
| 651 | 'exact' => 1, 'silent' => 1 | ||||||||||||||||||||||||||||
| 652 | ); | ||||||||||||||||||||||||||||
| 653 | |||||||||||||||||||||||||||||
| 654 | 3 | ▶ | throw &Errno::ENOTEMPTY unless $inode->empty; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||
| 656 | 1 | $directory->delete($name); | |||||||||||||||||||||||||||
| 657 | |||||||||||||||||||||||||||||
| 658 | 1 | return $inode; | |||||||||||||||||||||||||||
| 659 | } | ||||||||||||||||||||||||||||
| 660 | |||||||||||||||||||||||||||||
| 661 | =item C<$fs-E<gt>mknod($path, $mode)> | ||||||||||||||||||||||||||||
| 662 | |||||||||||||||||||||||||||||
| 663 | =item C<$fs-E<gt>mknod($path, $mode, $dev)> | ||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||
| 665 | Create a new inode at the specified C<$path>, with the inode permissions and | ||||||||||||||||||||||||||||
| 666 | format specified in the C<$mode> argument. If C<$mode> specifies a C<$S_IFCHR> | ||||||||||||||||||||||||||||
| 667 | or C<$S_IFBLK> value, then the device number specified in C<$dev> will be given | ||||||||||||||||||||||||||||
| 668 | to the new inode. | ||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||
| 670 | Code contained within the C<Filesys::POSIX> distribution assumes that the device | ||||||||||||||||||||||||||||
| 671 | identifier shall contain the major and minor numbers in separate 16-bit fields, | ||||||||||||||||||||||||||||
| 672 | in the following manner: | ||||||||||||||||||||||||||||
| 673 | |||||||||||||||||||||||||||||
| 674 | my $major = ($dev & 0xffff0000) >> 16; | ||||||||||||||||||||||||||||
| 675 | my $minor = $dev & 0x0000ffff; | ||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||
| 677 | Returns a reference to a L<Filesys::POSIX::Inode> object upon success. | ||||||||||||||||||||||||||||
| 678 | |||||||||||||||||||||||||||||
| 679 | =cut | ||||||||||||||||||||||||||||
| 680 | |||||||||||||||||||||||||||||
| 681 | 30 | ▶ | sub mknod { | ||||||||||||||||||||||||||
|
Subroutine
mknod: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||
| 682 | 30 | my ( $self, $path, $mode, $dev ) = @_; | |||||||||||||||||||||||||||
| 683 | 30 | my $hier = Filesys::POSIX::Path->new($path); | |||||||||||||||||||||||||||
| 684 | 30 | my $name = $hier->basename; | |||||||||||||||||||||||||||
| 685 | 30 | my $parent = $self->lstat( $hier->dirname ); | |||||||||||||||||||||||||||
| 686 | 29 | my $directory = $parent->directory; | |||||||||||||||||||||||||||
| 687 | |||||||||||||||||||||||||||||
| 688 | 29 | my $format = $mode & $S_IFMT; | |||||||||||||||||||||||||||
| 689 | 29 | my $perms = $mode & $S_IPERM; | |||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||
| 691 | 29 | $! = 0; | |||||||||||||||||||||||||||
| 692 | |||||||||||||||||||||||||||||
| 693 | 29 | ▶ | throw &Errno::EINVAL unless $format; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 694 | 28 | ▶ | throw &Errno::EEXIST if $directory->exists($name); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||
| 696 | 27 | my $inode = $parent->child( $name, $format | $perms ); | |||||||||||||||||||||||||||
| 697 | |||||||||||||||||||||||||||||
| 698 | 27 | ▶ | if ( $format == $S_IFCHR || $format == $S_IFBLK ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$format == $Filesys::POSIX::S_IFCHR or $format == $Filesys::POSIX::S_IFBLK
MC/DC100%2/2
$format == $Filesys::POSIX::S_IFCHR or $format == $Filesys::POSIX::S_IFBLK
$format == $Filesys::POSIX::S_IFCHR
$format == $Filesys::POSIX::S_IFBLK
Truth table100%3/3
A or B
A= $format == $Filesys::POSIX::S_IFCHRB= $format == $Filesys::POSIX::S_IFBLK
| |||||||||||||||||||||||||||||
| 699 | 24 | $inode->{'rdev'} = $dev; | |||||||||||||||||||||||||||
| 700 | } | ||||||||||||||||||||||||||||
| 701 | |||||||||||||||||||||||||||||
| 702 | 27 | return $inode; | |||||||||||||||||||||||||||
| 703 | } | ||||||||||||||||||||||||||||
| 704 | |||||||||||||||||||||||||||||
| 705 | =item C<$fs-E<gt>mkfifo($path, $mode)> | ||||||||||||||||||||||||||||
| 706 | |||||||||||||||||||||||||||||
| 707 | Create a new FIFO device at the specified C<$path>, with the permissions listed | ||||||||||||||||||||||||||||
| 708 | in C<$mode>. Internally, this function is a frontend to | ||||||||||||||||||||||||||||
| 709 | C<Filesys::POSIX-E<gt>mknod>. | ||||||||||||||||||||||||||||
| 710 | |||||||||||||||||||||||||||||
| 711 | Returns a reference to a L<Filesys::POSIX::Inode> object upon success. | ||||||||||||||||||||||||||||
| 712 | |||||||||||||||||||||||||||||
| 713 | =cut | ||||||||||||||||||||||||||||
| 714 | |||||||||||||||||||||||||||||
| 715 | 2 | ▶ | sub mkfifo { | ||||||||||||||||||||||||||
|
Subroutine
mkfifo: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 716 | 2 | my ( $self, $path, $mode ) = @_; | |||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||
| 718 | 2 | my $format = $S_IFIFO; | |||||||||||||||||||||||||||
| 719 | 2 | my $perms = $mode & $S_IPERM; | |||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||
| 721 | 2 | return $self->mknod( $path, $format | $perms ); | |||||||||||||||||||||||||||
| 722 | } | ||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||
| 724 | =back | ||||||||||||||||||||||||||||
| 725 | |||||||||||||||||||||||||||||
| 726 | =cut | ||||||||||||||||||||||||||||
| 727 | |||||||||||||||||||||||||||||
| 728 | 25 | 1; | |||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||
| 730 | __END__ | ||||||||||||||||||||||||||||