|
From: <gu...@us...> - 2007-05-11 21:47:25
|
Revision: 148
http://svn.sourceforge.net/easybox-mod/?rev=148&view=rev
Author: guyou
Date: 2007-05-11 14:47:23 -0700 (Fri, 11 May 2007)
Log Message:
-----------
Support des partitions via /etc/fstab
Easybox, au d?\195?\169marrage, scanne les disques et
cherche a d?\195?\169terminer en particulier quels sont
les disques optiques.
Modified Paths:
--------------
trunk/_framework/demarrage.php
trunk/_framework/fonctions_partagees.inc.php
trunk/_framework/framework.php
Added Paths:
-----------
trunk/_framework/lib/File_Fstab-2.0.2/
trunk/_framework/lib/File_Fstab-2.0.2/Entry.php
trunk/_framework/lib/File_Fstab-2.0.2/Fstab.php
Modified: trunk/_framework/demarrage.php
===================================================================
--- trunk/_framework/demarrage.php 2007-05-08 23:08:11 UTC (rev 147)
+++ trunk/_framework/demarrage.php 2007-05-11 21:47:23 UTC (rev 148)
@@ -82,7 +82,7 @@
clean_vars();
// R\xE9cup\xE9ration des disques
- if (PHP_OS == "WIN32" || PHP_OS == "WINNT") {
+ if (PHP_OS == "WIN32" || PHP_OS == "WINNT" || is_readable('/etc/fstab')) {
save_variable('disques', serialize(DISQUES()));
}
Modified: trunk/_framework/fonctions_partagees.inc.php
===================================================================
--- trunk/_framework/fonctions_partagees.inc.php 2007-05-08 23:08:11 UTC (rev 147)
+++ trunk/_framework/fonctions_partagees.inc.php 2007-05-11 21:47:23 UTC (rev 148)
@@ -242,6 +242,30 @@
$obj = null;
}
+ } elseif (is_readable('/etc/fstab')) {
+ // si ce fichier est lisible on assume qu'on est sur un OS qui le supporte
+ // Noter que c'est une facon pour un autre OS que Linux ou Windows de faire
+ // en sorte que easybox puisse acc\xE9der aux disques!
+
+ $fstab =& new File_Fstab();
+ foreach($fstab->entries as $io) {
+ // On n'a pas la description hardware du type de disque,
+ // mais on sait qu'un CD-ROM ou un DVD sont pratiquement
+ // toujours de type cd9660 pour mac, udf ou iso9660
+ // A priori on pourrait ajouter 'auto' dans les types accept\xE9s,
+ // mais en pratique ca revient a rajouter une entr\xE9e pour
+ // le... lecteur de disquettes.
+ if (strstr($io->getFsType(),'udf') || strstr($io->getFsType(),'iso9660') || strstr($io->getFsType(),'cd9660')) {
+ $lect[] = array('lettre'=>$io->getDevice(), 'path'=>$io->getMountPoint(), 'type'=>'Disque optique', 'nom'=>$io->getMountPoint(), 'gif'=>'diskoptical');
+ } elseif (! strstr($io->getFsType(),'proc')) {
+ // Bon, on se souviens quand-meme des autres, sauf /proc car faut pas pousser
+ $lect[] = array('lettre'=>$io->getDevice(), 'path'=>$io->getMountPoint(), 'type'=>'Inconnu', 'nom'=>$io->getMountPoint(), 'gif'=>'diskunknown');
+ }
+ }
+
+ // On ajoute le bouton de rafraichissement
+ $lect[] = array('lettre'=>'Rafra\xEEchir', 'path'=>'reload', 'type'=>'fonction', 'nom'=>'Recharger', 'gif'=>'reload');
+
}
//print_r($lect);
RETURN($lect);
Modified: trunk/_framework/framework.php
===================================================================
--- trunk/_framework/framework.php 2007-05-08 23:08:11 UTC (rev 147)
+++ trunk/_framework/framework.php 2007-05-11 21:47:23 UTC (rev 148)
@@ -72,6 +72,11 @@
//-- Librairie pour r\xE9cup\xE9rer des infos sur des fichiers depuis allocine ou autre...
require_once($LIBRARIES_REP.'get_info.php');
+//-- Librairie pour g\xE9rer /etc/fstab (PEAR)
+ require_once($LIBRARIES_REP.'File_Fstab-2.0.2/Entry.php');
+ require_once($LIBRARIES_REP.'File_Fstab-2.0.2/Fstab.php');
+
+
//--Libraire de gestion du fichier ini
require_once($LIBRARIES_REP.'ini.php');
Added: trunk/_framework/lib/File_Fstab-2.0.2/Entry.php
===================================================================
--- trunk/_framework/lib/File_Fstab-2.0.2/Entry.php (rev 0)
+++ trunk/_framework/lib/File_Fstab-2.0.2/Entry.php 2007-05-11 21:47:23 UTC (rev 148)
@@ -0,0 +1,552 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * This file contains the class for an entry in a fstab file
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to li...@ph... so we can mail you a copy immediately.
+ *
+ * @category File Formats
+ * @package File_Fstab
+ * @author Ian Eure <ie...@ph...>
+ * @copyright (c) 2004, 2005 Ian Eure
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @version Release: @package_version@
+ * @version CVS: $Revision: 1.7 $
+ * @link http://pear.php.net/package/File_Fstab
+ */
+
+
+/**
+ * These defines enumerate the possible types of device entries in the fstab
+ */
+define('FILE_FSTAB_ENTRY_DEVTYPE_BLOCKDEV', 1);
+define('FILE_FSTAB_ENTRY_DEVTYPE_UUID', 2);
+define('FILE_FSTAB_ENTRY_DEVTYPE_LABEL', 3);
+
+
+/**
+ * A single entry in a fstab file
+ *
+ * @category File Formats
+ * @package File_Fstab
+ * @author Ian Eure <ie...@ph...>
+ * @copyright (c) 2004, 2005 Ian Eure
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @version Release: @package_version@
+ * @version CVS: $Revision: 1.7 $
+ * @link http://pear.php.net/package/File_Fstab
+ */
+class File_Fstab_Entry {
+ /**
+ * Raw line from fstab
+ *
+ * @var string
+ */
+ var $entry;
+
+ /**
+ * Block device
+ *
+ * Only one of $device, $uuid, or $label will be set, based on what's in the
+ * fstab entry.
+ *
+ * @var string
+ */
+ var $device = '/dev/null';
+
+ /**
+ * Device UUID
+ *
+ * Only one of $device, $uuid, or $label will be set, based on what's in the
+ * fstab entry.
+ *
+ * @var string
+ */
+ var $uuid;
+
+ /**
+ * Device label
+ *
+ * Only one of $device, $uuid, or $label will be set, based on what's in the
+ * fstab entry.
+ *
+ * @var string
+ */
+ var $label;
+
+ /**
+ * Device mount point
+ *
+ * @var string
+ */
+ var $mountPoint = '/mnt';
+
+ /**
+ * Device filesystem type
+ *
+ * @var string
+ */
+ var $fsType = 'auto';
+
+ /**
+ * Mount options
+ *
+ * @var array
+ */
+ var $mountOptions = array(
+ 'defaults' => "defaults"
+ );
+
+ /**
+ * Device dump frequency
+ *
+ * @var int
+ */
+ var $dumpFrequency = 0;
+
+ /**
+ * Device fsck pass number
+ *
+ * @var int
+ */
+ var $fsckPassNo = 0;
+
+ /**
+ * Have we parsed the entry?
+ *
+ * @var boolean
+ * @access private
+ */
+ var $_haveParsed = false;
+
+
+ /**
+ * Constructor
+ *
+ * @param string $entry Single entry from fstab file
+ * @return void
+ */
+ function File_Fstab_Entry($entry = false)
+ {
+ if ($entry) {
+ $this->setEntry($entry);
+ $this->parse();
+ }
+ }
+
+ /**
+ * Set block device
+ *
+ * Only one of device, uuid, or label may be set; setting this will un-set
+ * any valies in the other variables.
+ *
+ * @since 2.0.0beta1
+ * @param string $device Value to set
+ * @return mixed boolean true on success, PEAR_Error otherwise
+ */
+ function setDevice($device)
+ {
+ $this->device = $device;
+ unset($this->uuid, $this->label);
+ return true;
+ }
+
+ /**
+ * Get block device
+ *
+ * @since 2.0.0beta1
+ * @return string
+ */
+ function getDevice()
+ {
+ return $this->device;
+ }
+
+ /**
+ * Set UUID
+ *
+ * Only one of device, uuid, or label may be set; setting this will un-set
+ * any valies in the other variables.
+ *
+ * @since 2.0.0beta1
+ * @param string $uuid Value to set
+ * @return mixed boolean true on success, PEAR_Error otherwise
+ */
+ function setUUID($uuid)
+ {
+ $this->uuid = $uuid;
+ unset($this->device, $this->label);
+ return true;
+ }
+
+ /**
+ * Get UUID
+ *
+ * @since 2.0.0beta1
+ * @return string
+ */
+ function getUUID()
+ {
+ return $this->uuid;
+ }
+
+ /**
+ * Set device label
+ *
+ * Only one of device, uuid, or label may be set; setting this will un-set
+ * any valies in the other variables.
+ *
+ * @since 2.0.0beta1
+ * @param string $label Value to set
+ * @return mixed boolean true on success, PEAR_Error otherwise
+ */
+ function setLabel($label)
+ {
+ $this->label = $label;
+ unset($this->device, $this->uuid);
+ return true;
+ }
+
+ /**
+ * Get device label
+ *
+ * @since 2.0.0beta1
+ * @return string
+ */
+ function getLabel()
+ {
+ return $this->label;
+ }
+
+ /**
+ * Set mount point
+ *
+ * @since 2.0.0beta1
+ * @param string $dir Value to set
+ * @return mixed boolean true on success, PEAR_Error otherwise
+ */
+ function setMountPoint($dir)
+ {
+ $this->mountPoint = $dir;
+ return true;
+ }
+
+ /**
+ * Get mount point
+ *
+ * @since 2.0.0beta1
+ * @return string
+ */
+ function getMountPoint()
+ {
+ return $this->mountPoint;
+ }
+
+ /**
+ * Set filesystem type
+ *
+ * @since 2.0.0beta1
+ * @param string $type Value to set
+ * @return mixed boolean true on success, PEAR_Error otherwise
+ */
+ function setFsType($type)
+ {
+ $this->fsType = $type;
+ return true;
+ }
+
+ /**
+ * Get filesystem type
+ *
+ * @since 2.0.0beta1
+ * @return string
+ */
+ function getFsType()
+ {
+ return $this->fsType;
+ }
+
+ /**
+ * Set filesystem dump frequency
+ *
+ * @since 2.0.0beta1
+ * @param int $type Value to set
+ * @return mixed boolean true on success, PEAR_Error otherwise
+ */
+ function setDumpFrequency($freq)
+ {
+ $this->dumpFrequency = $freq;
+ return true;
+ }
+
+ /**
+ * Get filesystem dump frequency
+ *
+ * @since 2.0.0beta1
+ * @return int
+ */
+ function getDumpFrequency()
+ {
+ return $this->dumpFrequency;
+ }
+
+ /**
+ * Set filesystem fsck pass number
+ *
+ * @since 2.0.0beta1
+ * @param int $type Value to set
+ * @return mixed boolean true on success, PEAR_Error otherwise
+ */
+ function setFsckPassNo($pass)
+ {
+ $this->fsckPassNo = $pass;
+ return true;
+ }
+
+ /**
+ * Get filesystem fsck pass number
+ *
+ * @since 2.0.0beta1
+ * @return int
+ */
+ function getFsckPassNo()
+ {
+ return $this->fsckPassNo;
+ }
+
+ /**
+ * Set an entry
+ *
+ * @param string $entry Single entry from fstab file
+ * @return void
+ */
+ function setEntry($entry)
+ {
+ $this->entry = $entry;
+ $this->_haveParsed = false;
+ }
+
+ /**
+ * Parse fstab entry
+ *
+ * @param string $entry Line from fstab to parse
+ * @return mixed true on success, PEAR_Error on failure
+ */
+ function parse()
+ {
+ if ($this->_haveParsed || !strlen($this->entry)) {
+ return true;
+ }
+
+ // Sanitize.
+ $this->_cleanup();
+
+ // It might be a good idea to allow specifying a custom whitespace
+ // character list.
+ $sections = split("\ +|\t+", $this->entry);
+ if (count($sections) != 6) {
+ return false;
+ }
+
+ list($device, $this->mountPoint, $this->fsType, $options, $this->dumpFrequency, $this->fsckPassNo) = $sections;
+
+ // Device, UUID, or Label?
+ switch (substr($device, 0, 4)) {
+ case 'UUID':
+ list($null, $this->uuid) = explode('=', $device);
+ break;
+
+ case 'LABE':
+ list($null, $this->label) = explode('=', $device);
+ break;
+
+ default:
+ $this->device = $device;
+ }
+
+ $this->_parseMountOptions($options);
+
+ $this->_haveParsed = true;
+ return true;
+ }
+
+ /**
+ * Clean up prior to parsing
+ *
+ * @access private
+ * @return void
+ */
+ function _cleanup()
+ {
+ $this->mountOptions = array();
+ unset($this->device, $this->uuid, $this->label, $this->mountPoint,
+ $this->fsType, $this->dumpFrequency, $this->fsckPassNo);
+ }
+
+ /**
+ * Parse fstab options
+ *
+ * @param $options string Mount options from fstab
+ *
+ * @return void
+ * @access protected
+ */
+ function _parseMountOptions($options)
+ {
+ foreach (explode(',', $options) as $option) {
+ if (strstr($option, '=')) {
+ $tmp = explode('=', $option);
+ list($name, $value) = $tmp;
+ } else {
+ $name = $option;
+ $value = $option;
+ }
+ $this->mountOptions[$name] = $value;
+ }
+ }
+
+ /**
+ * Reconstruct fstab options from $mountOptions
+ *
+ * @return string fstab mount options
+ * @access protected
+ */
+ function _makeMountOptions()
+ {
+ // Copy.
+ foreach ($this->mountOptions as $option => $value) {
+ if ($option == $value) {
+ $opts[] = $option;
+ } else {
+ $opts[] = $option.'='.$value;
+ }
+ }
+ return implode(',', $opts);
+ }
+
+ /**
+ * Get the fstab entry
+ *
+ * This rebuilds the entry from the class variables.
+ *
+ * @return string The fstab entry
+ */
+ function getEntry($seperator)
+ {
+ $entry = array(
+ $this->_getDeviceEntry(),
+ $this->getMountPoint(),
+ $this->getFsType(),
+ $this->_makeMountOptions(),
+ $this->getDumpFrequency(),
+ $this->getFsckPassNo()
+ );
+ return implode($entry, $seperator);
+ }
+
+ /**
+ * Get device, or uuid, or label
+ *
+ * @return string Device/UUID/LABEL
+ */
+ function getDeviceUUIDOrLabel()
+ {
+ if ($this->device) {
+ return $this->getDevice();
+ } else if ($this->uuid) {
+ return $this->getUUID();
+ } else if($this->label) {
+ return $this->getLabel();
+ }
+ }
+
+ /**
+ * Get device entry for building fstab
+ *
+ * This is like getDeviceUUIDOrLabel(), but we prefix the actual value
+ * with the necessary string for it to work in the fstab.
+ *
+ * @return string Device/UUID/LABEL
+ * @access protected
+ */
+ function _getDeviceEntry()
+ {
+ switch ($this->getDeviceType()) {
+ case FILE_FSTAB_ENTRY_DEVTYPE_UUID:
+ $prefix = 'UUID=';
+ break;
+
+ case FILE_FSTAB_ENTRY_DEVTYPE_LABEL:
+ $prefix = 'LABEL=';
+ break;
+
+ default:
+ $prefix = '';
+ }
+ return $prefix.$this->getDeviceUUIDOrLabel();
+ }
+
+ /**
+ * Get device type
+ *
+ * @return int One of FILE_FSTAB_ENTRY_DEVTYPE_BLOCKDEV, _UUID, or _LABEL
+ */
+ function getDeviceType()
+ {
+ if ($this->device) {
+ return FILE_FSTAB_ENTRY_DEVTYPE_BLOCKDEV;
+ } else if ($this->uuid) {
+ return FILE_FSTAB_ENTRY_DEVTYPE_UUID;
+ } else if ($this->label) {
+ return FILE_FSTAB_ENTRY_DEVTYPE_LABEL;
+ }
+ }
+
+ /**
+ * Is an option set?
+ *
+ * @param string $option Option name
+ * @return boolean
+ */
+ function hasMountOption($option)
+ {
+ return @array_key_exists($option, $this->mountOptions);
+ }
+
+ /**
+ * Get a mount option
+ *
+ * @param string $which Option to get
+ * @return string Mount option
+ */
+ function getMountOption($which)
+ {
+ if (!$this->hasMountOption($which)) {
+ return false;
+ }
+ return $this->mountOptions[$which];
+ }
+
+ /**
+ * Set a mount option
+ *
+ * @param string $name Option to set
+ * @param string $value Value to give option, or blank if option takes no args
+ * @return void
+ */
+ function setMountOption($name, $value = false)
+ {
+ if (!$value) {
+ $value = $name;
+ }
+ $this->mountOptions[$name] = $value;
+ }
+}
+?>
Added: trunk/_framework/lib/File_Fstab-2.0.2/Fstab.php
===================================================================
--- trunk/_framework/lib/File_Fstab-2.0.2/Fstab.php (rev 0)
+++ trunk/_framework/lib/File_Fstab-2.0.2/Fstab.php 2007-05-11 21:47:23 UTC (rev 148)
@@ -0,0 +1,297 @@
+<?php
+/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: */
+
+/**
+ * Main File_Fstab file
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: This source file is subject to version 3.0 of the PHP license
+ * that is available through the world-wide-web at the following URI:
+ * http://www.php.net/license/3_0.txt. If you did not receive a copy of
+ * the PHP License and are unable to obtain it through the web, please
+ * send a note to li...@ph... so we can mail you a copy immediately.
+ *
+ * @category File Formats
+ * @package File_Fstab
+ * @author Ian Eure <ie...@ph...>
+ * @copyright (c) 2004, 2005 Ian Eure
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @version Release: @package_version@
+ * @version CVS: $Revision: 1.11 $
+ * @link http://pear.php.net/package/File_Fstab
+ */
+
+/**
+ * These defines enumerate the possible error types
+ */
+define('FILE_FSTAB_ERROR_NOENT', -1);
+define('FILE_FSTAB_PERMISSION_DENIED', -2);
+define('FILE_FSTAB_WRONG_CLASS', -3);
+
+/**
+ * Class to read, write, and manipulate fstab files
+ *
+ * @category File Formats
+ * @package File_Fstab
+ * @author Ian Eure <ie...@ph...>
+ * @copyright (c) 2004, 2005 Ian Eure
+ * @license http://www.php.net/license/3_0.txt PHP License 3.0
+ * @version Release: @package_version@
+ * @version CVS: $Revision: 1.11 $
+ * @link http://pear.php.net/package/File_Fstab
+ */
+class File_Fstab {
+ /**
+ * Array of fstab entries
+ *
+ * @var array
+ */
+ var $entries = array();
+
+ /**
+ * Class options.
+ *
+ * @var array
+ */
+ var $options = array();
+
+ /**
+ * Default options
+ *
+ * @var array
+ * @access private
+ */
+ var $_defaultOptions = array(
+ 'entryClass' => "File_Fstab_Entry",
+ 'file' => "/etc/fstab",
+ 'fieldSeperator' => "\t"
+ );
+
+ /**
+ * Has the fstab been parsed?
+ *
+ * @var boolean
+ * @access private
+ */
+ var $_isLoaded = false;
+
+ /**
+ * Constructor
+ *
+ * @param array $options Associative array of options to set
+ * @return void
+ */
+ function File_Fstab($options = false)
+ {
+ $this->setOptions($options);
+ if ($this->options['file']) {
+ $this->load();
+ }
+ }
+
+ /**
+ * Return a single instance to handle a fstab file
+ *
+ * @param string $fstab Path to the fstab file
+ * @return object File_Fstab instance
+ */
+ function &singleton($fstab)
+ {
+ static $instances;
+ if (!isset($instances)) {
+ $instances = array();
+ }
+
+ if (!isset($instances[$fstab])) {
+ $instances[$fstab] = &new File_Fstab(array('file' => $fstab));
+ }
+
+ return $instances[$fstab];
+ }
+
+ /**
+ * Parse fstab file
+ *
+ * @return void
+ * @since 1.0.1
+ */
+ function load()
+ {
+ $fp = fopen($this->options['file'], 'r');
+ while ($line = fgets($fp, 1024)) {
+
+ // Strip comments & trim whitespace
+ $line = trim(ereg_replace('#.*$', '', $line));
+
+ // Ignore blank lines
+ if (!strlen($line)) {
+ continue;
+ }
+
+ $class = $this->options['entryClass'];
+ $this->entries[] = new $class($line);
+
+ }
+
+ $this->_isLoaded = true;
+ }
+
+ /**
+ * Update entries
+ *
+ * This will dump all the entries and re-parse the fstab. There's probably
+ * a better way of doing this, like forcing the extant entries to re-parse,
+ * and adding/removing entries as needed, but I don't feel like doing that
+ * right now.
+ *
+ * @return void
+ */
+ function update()
+ {
+ unset($this->entries);
+ $this->load();
+ }
+
+ /**
+ * Get a File_Fstab_Entry object for a path
+ *
+ * @param string $path Mount point
+ * @return mixed File_Fstab_Entry instance on success, PEAR_Error otherwise
+ */
+ function &getEntryForPath($path)
+ {
+ foreach ($this->entries as $key => $entry) {
+ if ($entry->mountPoint == $path) {
+ // Foreach makes copies - make sure we return a reference
+ return $this->entries[$key];
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Get a File_Fstab_Entry object for a block device
+ *
+ * @param string $blockdev Block device
+ * @return mixed File_Fstab_Entry instance on success, PEAR_Error otherwise
+ */
+ function &getEntryForDevice($blockdev)
+ {
+ foreach ($this->entries as $key => $entry) {
+ if ($entry->getDeviceType() == FILE_FSTAB_ENTRY_DEVTYPE_BLOCKDEV &&
+ $entry->device == $blockdev) {
+ // Foreach makes copies - make sure we return a reference
+ return $this->entries[$key];
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Get a File_Fstab_Entry object for a UUID
+ *
+ * @param string $uuid UUID device
+ * @return mixed File_Fstab_Entry instance on success, PEAR_Error otherwise
+ */
+ function &getEntryForUUID($uuid)
+ {
+ foreach ($this->entries as $key => $entry) {
+ if ($entry->getDeviceType() == FILE_FSTAB_ENTRY_DEVTYPE_UUID &&
+ $entry->uuid == $uuid) {
+ // Foreach makes copies - make sure we return a reference
+ return $this->entries[$key];
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Get a File_Fstab_Entry object for a label
+ *
+ * @param string $label Label
+ * @return mixed File_Fstab_Entry instance on success, PEAR_Error otherwise
+ */
+ function &getEntryForLabel($label)
+ {
+ foreach ($this->entries as $key => $entry) {
+ if ($entry->getDeviceType() == FILE_FSTAB_ENTRY_DEVTYPE_LABEL &&
+ $entry->label == $label) {
+ // Foreach makes copies - make sure we return a reference
+ return $this->entries[$key];
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Add a new entry
+ *
+ * @param object $entry Reference to a File_Fstab_Entry-derived class
+ * @return mixed boolean true on success, PEAR_Error otherwise.
+ */
+ function addEntry(&$entry)
+ {
+ if (!is_a($entry, 'File_Fstab_Entry')) {
+ return false;
+ }
+
+ $this->entries[] = $entry;
+ return true;
+ }
+
+ /**
+ * Set class options
+ *
+ * The allowed options are:
+ *
+ * - entryClass
+ * Class to use for entries in the fstab. Defaults to File_Fstab_Entry.
+ * you can use this to provide your own entry class with added
+ * functionality. This class must extend File_Fstab_Entry.
+ *
+ * - file
+ * File to parse. Defaults to /etc/fstab.
+ *
+ * - fieldSeparator
+ * Separator for fields. This only affects the output when you call
+ * {@link save()}. This text is placed in between the elements of the
+ * fstab entry line.
+ *
+ * @param array $options Associative array of options to set
+ * @return void
+ */
+ function setOptions($options = false)
+ {
+ if (!is_array($options)) {
+ $options = array();
+ }
+
+ $this->options = array_merge($this->_defaultOptions, $options);
+ }
+
+ /**
+ * Write out a modified fstab
+ *
+ * WARNING: This will strip comments and blank lines from the original fstab.
+ *
+ * @return mixed true on success, PEAR_Error on failure
+ * @since 1.0.1
+ */
+ function save($output = false)
+ {
+ $output = $output ? $output : $this->options['file'];
+
+ $fp = @fopen($output, 'w');
+ if (!$fp) {
+ return false;
+ }
+
+ foreach($this->entries as $entry) {
+ fwrite($fp, $entry->getEntry($this->options['fieldSeperator'])."\n");
+ }
+ fclose($fp);
+ return true;
+ }
+}
+?>
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|