The File_Fstab_Entry class represents all the information available about a particular entry in a Fstab file.
The entry has a number of properties which represent the information in the fstab file.
$device
, $uuid
,
and $label
are mutually exclusive;
only one of the three may be set.
$device
.
dump
.
fsck
when the system boots.
You may want to read fstab(5)
for more information about
what these fields mean.
There are a number of ways of finding a specific entry from the fstab. You may find based on device, mountpoint, filesystem label, or UUID.
To find by device, you want to use the getEntryForDevice() function. The single argument this function accepts is the path to the block device for an entry.
Get entry by device
<?php
require_once 'File/Fstab.php';
$fstab =& new File_Fstab();
$dev =& $fstab->getEntryForDevice('/dev/hda1');
if (PEAR::isError($dev)) {
die($dev->getMessage());
}
?>
You may want to find a device based on the path it is mounted on;
for example, you may want to get the entry for /cdrom
,
without caring if the CD device is /dev/hdb
,
/dev/cdrom
, or some other device. To do this, use
the getEntryForPath() function.
Get entry by path
<?php
require_once 'File/Fstab.php';
$fstab =& new File_Fstab();
$dev =& $fstab->getEntryForPath('/cdrom');
if (PEAR::isError($dev)) {
die($dev->getMessage());
}
?>
Some systems use a filesystem UUID to specify the
device to mount. A UUID may look like this:
b46ad2ee-01f3-4041-96ca-91d35d059417
. The
getEntryForUUID() function handles this.
Get entry by UUID
<?php
require_once 'File/Fstab.php';
$fstab =& new File_Fstab();
$dev =& $fstab->getEntryForUUID('b46ad2ee-01f3-4041-96ca-91d35d059417');
if (PEAR::isError($dev)) {
die($dev->getMessage());
}
?>
Some filesystems allow you to specify a textual label to a filesystem.
For example, you may label your root device rootdev
,
the device you mount on /home
could be named
homedirs
and so forth. File_Fstab
supports getting entries based on the device label. This is accomplished
by using the getEntryForLabel() function.
Get entry by label
<?php
require_once 'File/Fstab.php';
$fstab =& new File_Fstab();
$dev =& $fstab->getEntryForLabel('homedirs');
if (PEAR::isError($dev)) {
die($dev->getMessage());
}
?>
In addition to reading fstab files, you may modify them as well.
Add an entry for a floppy disk
<?php
require_once 'File/Fstab.php';
$fstab =& new File_Fstab();
$floppy =& new File_Fstab_Entry();
$floppy->fsType = 'vfat';
$floppy->device = '/dev/fd0';
$floppy->mountPoint = '/floppy';
$fstab->addEntry($floppy);
?>