NAME
Linux::Proc::Mountinfo - Parse Linux /proc/$PID/mountinfo data
SYNOPSIS
use Linux::Proc::Mountinfo;
my $mi = Linux::Proc::Mountinfo->read;
my $root = $mi->root;
say $root->mount_source, " mounted at /, filesystem type is ", $root->fs_type;
my $flatten = $root->flatten;
# umount all file systems but / in an ordered fashion:
for (reverse @flatten) {
my $mount_point = $_->mount_point;
system umount => $mount_point unless $mount_point eq '/';
}
DESCRIPTION
Linux::Proc::Mounts parses the information about mount points provided by the Linux kernel at /proc/$PID/mountinfo
.
API
The Linux::Proc::Mountinfo class
Internal public representation
The internal representation of the class is an array whose entries can be accessed directly unreferencing it. For instance:
my $mnts = Linux::Proc::Mount->read;
for my $e (@$mnts) {
say $e->spec . " is mounted at " . $e->file . " as " . $e->fstype;
}
Methods
The following methods are available from this class:
- $mnts = Linux::Proc::Mountinfo->read(%opts)
-
Reads
/proc/$PID/mountinfo
and returns a new object with the parsed data.The accepted options are as follows:
- mnt => $proc
-
Overrides the default mount point for the procfs at
/proc
. - pid => $pid
-
Reads the
mountinfo
file of the process with the given PID. By default themouninfo
file of the current process is read.For instance, for reading
init
mountinfo
file:my $mi = Linux::Proc::Mountinfo->read(pid => 1);
- file => $filename
-
Reads and parses the file of the given name.
- $mi->at($path)
-
Returns an object representing the mount point at the given place.
For instance:
my $var = $mi->at('/var'); print $var->mount_source, " is mounted at /var" if $var;
Returns undef if no file system is mounted there.
- $mi->root
-
Returns an object representing the root file system mount point.
The Linux::Proc::Mountinfo::Entry class
This class is used to represent the single entries on the mountinfo
file.
Methods
The methods supported by this class are as follows:
- $mie->mount_id
- $mie->parent_id
- $mie->major_minor
- $mie->root
- $mie->mount_point
- $mie->mount_options
- $mie->fs_type
- $mie->mount_source
- $mie->super_options
- $mie->optional_fields
-
See the excerpt from the Linux documentation below for the meaning of the return values from these accessors.
- $mie->line_number
-
Returns the line number of this entry inside the
mountinfo
file. - $mie->line
-
Returns the full line on the
mountinfo
file. - $mie->major
-
Returns the major part or the major:minor field.
- $mie->minor
-
Returns the minor part of the major:minor field.
- $mie->bind_source
-
If the mount is a binding (i.e. created with
mount --bind ...
), this method returns the object representing the source file system. Othersise, it returns undef. - $mie->children
-
Returns an Linux::Proc::Mountinfo object containing the mount point that are on top of the given one.
- $mie->flatten
-
This method is similar to children but returns all the descendants instead of just the direct ones.
Excerpt from Linux documentation
What follows is the documentation available from Linux Documentation/Linux/proc.txt
(http://git.kernel.org/?p=linux/kernel/git/torvalds/linux-2.6.git;a=blob_plain;f=Documentation/filesystems/proc.txt) related to mountinfo
.
3.5 /proc/<pid>/mountinfo - Information about mounts
--------------------------------------------------------
This file contains lines of the form:
36 35 98:0 /mnt1 /mnt2 rw,noatime master:1 - ext3 /dev/root rw,errors=continue
(1)(2)(3) (4) (5) (6) (7) (8) (9) (10) (11)
(1) mount ID: unique identifier of the mount (may be reused after
umount)
(2) parent ID: ID of parent (or of self for the top of the mount
tree)
(3) major:minor: value of st_dev for files on filesystem
(4) root: root of the mount within the filesystem
(5) mount point: mount point relative to the process's root
(6) mount options: per mount options
(7) optional fields: zero or more fields of the form "tag[:value]"
(8) separator: marks the end of the optional fields
(9) filesystem type: name of filesystem of the form
"type[.subtype]"
(10) mount source: filesystem specific information or "none"
(11) super options: per super block options
Parsers should ignore all unrecognised optional fields. Currently
the possible optional fields are:
shared:X mount is shared in peer group X
master:X mount is slave to peer group X
propagate_from:X mount is slave and receives propagation from peer
group X (*) unbindable mount is unbindable
(*) X is the closest dominant peer group under the process's root.
If X is the immediate master of the mount, or if there's no
dominant peer group under the same root, then only the "master:X"
field is present and not the "propagate_from:X" field.
For more information on mount propagation see:
Documentation/filesystems/sharedsubtree.txt
SEE ALSO
mount(8) describes the filesystems and the options accepted.
Sys::Filesystem provides similar functionality to this module and support most common operating systems.
Linux::Proc::Mounts provides similar information from /proc/mounts
, though the information from /proc/$PID/mountinfo
is supposedly more detailed so there is no reason to use that module (at least, this is the theory).
AUTHOR
Salvador Fandiño, <sfandino@yahoo.com<gt>
COPYRIGHT AND LICENSE
Copyright (C) 2012 Qindel Formación y Servicios S.L.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.14.2 or, at your option, any later version of Perl 5 you may have available.