Entries

Entries – Working with entries

Entry overview

The File_Fstab_Entry class represents all the information available about a particular entry in a Fstab file.

Entry properties

The entry has a number of properties which represent the information in the fstab file.

$device
This is the path to the block device for this entry. $device, $uuid, and $label are mutually exclusive; only one of the three may be set.
$uuid
The UUID of the device.
$label
The label for this device.
$mountPoint
The directory this device is mounted on.
$fsType
The type of filesystem on $device.
$mountOptions
Array of mount options for this device.
$dumpFrequency
How often / if this filesystem should be backed up by dump.
$fsckPassNo
Order of / if this device should be checked by fsck when the system boots.

You may want to read fstab(5) for more information about what these fields mean.

Finding entries

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.

Finding by device

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());
}
?>

Finding by path (mountpoint)

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());
}
?>

Finding by UUID

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());
}
?>

Finding by label

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());
}
?>

Adding entries

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);
?>
Introduction to File_Fstab. (Previous) Saving your changes (Next)
Last updated: Sat, 16 Feb 2019 — Download Documentation
Do you think that something on this page is wrong? Please file a bug report.
View this page in:
  • English

User Notes:

There are no user contributed notes for this page.