File Coverage

blib/lib/Unix/Mknod.pm
Criterion Covered Total %
statement 8 8 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 11 11 100.0


line stmt bran cond sub pod time code
1             package Unix::Mknod;
2              
3 1     1   11894 use 5.006;
  1         4  
4 1     1   7 use strict;
  1         2  
  1         27  
5 1     1   6 use warnings;
  1         1  
  1         283  
6              
7             require Exporter;
8              
9             our @ISA = qw(Exporter);
10              
11             # Items to export into callers namespace by default. Note: do not export
12             # names by default without a very good reason. Use EXPORT_OK instead.
13             # Do not simply export all your public functions/methods/constants.
14              
15             # This allows declaration use Unix::Mknod qw(:all);
16             # If you do not need this, moving things directly into @EXPORT or @EXPORT_OK
17             # will save memory.
18             our %EXPORT_TAGS = ( 'all' => [ qw(
19             mknod major minor makedev
20             ) ] );
21              
22             our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} });
23              
24             our @EXPORT = qw(
25              
26             );
27              
28             our $VERSION = '0.05';
29              
30             require XSLoader;
31             XSLoader::load('Unix::Mknod', $VERSION);
32              
33             1;
34             __END__
35              
36             =head1 NAME
37              
38             Unix::Mknod - Perl extension for mknod, major, minor, and makedev
39              
40             =head1 SYNOPSIS
41              
42             use Unix::Mknod qw(:all);
43             use File::stat;
44             use Fcntl qw(:mode);
45              
46             $st=stat('/dev/null');
47             $major=major($st->rdev);
48             $minor=minor($st->rdev);
49              
50             mknod('/tmp/special', S_IFCHR|0600, makedev($major,$minor+1));
51              
52             =head1 DESCRIPTION
53              
54             This module allows access to the device routines major()/minor()/makedev()
55             that may or may not be macros in .h files.
56              
57             It also allows access to the C<mknod(2)> system call.
58              
59             =head1 FUNCTIONS
60              
61             =over 4
62              
63             =item I<mknod($filename, $mode, $rdev)>
64              
65             Creates a block or character device special file named I<$filename>.
66             Must be run as a privileged user, usually I<root>. Returns 0 on success
67             and -1 on failure, like C<POSIX::mkfifo> does.
68              
69             =item I<$major = major($rdev)>
70              
71             Returns the major number for the device special file as defined by the
72             st_rdev field from the C<stat(3)> call.
73              
74             =item I<$minor = minor($rdev)>
75              
76             Returns the minor number for the device special file as defined by the
77             st_rdev field from the C<stat(3)> call.
78              
79             =item I<$rdev = makedev($major, $minor)>
80              
81             Returns the st_rdev number for the device special file from the I<$major>
82             and I<$minor> numbers.
83              
84             =back
85              
86             =head1 NOTES
87              
88             There are 2 other perl modules that implement the C<mknod(2)> system call,
89             but they have problems working on some platforms. C<Sys::Mknod> does not
90             work on AIX because it uses the C<syscall(2)> generic system call which
91             AIX does not have. C<Mknod> implements S_IFIFO, which on most platforms
92             is not implemented in C<mknod(1)>, but rather C<mkfifo(1)> (which is
93             implemented in POSIX perl module).
94              
95             The perl module C<File::Stat::Bits> also implements major() and minor() (and
96             a version of makedev() called dev_join). They are done as a program to
97             get the bit masks at compile time, but if major() and minor() are
98             implemented as sub routines, the arugment could be something as simple
99             as an index to a lookup table (and thereby having no decernable relation
100             to its result).
101              
102             =head1 BUGS
103              
104             Running C<make test> as non root will not truly test the functions, as in
105             most UNIX like OSes, C<mknod(2)> needs to be invoked by a privelaged user,
106             usually I<root>.
107              
108             =head1 SEE ALSO
109              
110             C<$ERRNO> or C<$!> for the specific error message.
111              
112             L<File::Stat::Bits>, L<Mknod>, L<POSIX>, L<Sys::Mknod>
113              
114             C<major(9)>, C<minor(9)>, C<mkfifo(1)>, C<mknod(8)>
115              
116             =head1 AUTHOR
117              
118             Jim Pirzyk, E<lt>pirzyk@freebsd.orgE<gt>
119              
120             =head1 COPYRIGHT AND LICENSE
121              
122             Copyright (c) 2005-2023 University of Illinois Board of Trustees
123             All rights reserved.
124              
125             Developed by: Campus Information Technologies and Educational Services,
126             University of Illinois at Urbana-Champaign
127              
128             Permission is hereby granted, free of charge, to any person obtaining
129             a copy of this software and associated documentation files (the
130             ``Software''), to deal with the Software without restriction, including
131             without limitation the rights to use, copy, modify, merge, publish,
132             distribute, sublicense, and/or sell copies of the Software, and to
133             permit persons to whom the Software is furnished to do so, subject to
134             the following conditions:
135              
136             * Redistributions of source code must retain the above copyright
137             notice, this list of conditions and the following disclaimers.
138              
139             * Redistributions in binary form must reproduce the above copyright
140             notice, this list of conditions and the following disclaimers in the
141             documentation and/or other materials provided with the distribution.
142              
143             * Neither the names of Campus Information Technologies and Educational
144             Services, University of Illinois at Urbana-Champaign, nor the names
145             of its contributors may be used to endorse or promote products derived
146             from this Software without specific prior written permission.
147              
148             THE SOFTWARE IS PROVIDED ``AS IS'', WITHOUT WARRANTY OF ANY KIND,
149             EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
150             MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
151             IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR
152             ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
153             TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
154             OR THE USE OR OTHER DEALINGS WITH THE SOFTWARE.
155              
156             =cut