Manuel Pear

Introduction

Introduction --  Mount and Unmount filesystems

Contributors

  • Brett Bieber

Description

System_Mount provides methods to mount and unmount filesystems and partitions listed in a system's /etc/fstab. The fstab file is common on Unix/Linux based systems and is used to list the available filesystems and partitions which users can mount into the filesystem hierarchy. Common entries include root partitions, boot partitions, as well as cdrom drives and other removable media.

The System_Mount command utilizes File_Fstab to discover entries in the /etc/fstab file, and allow easy mount/unmount operations.

Using System_Mount

Exemple 63-1. General usage

  1. <?php
  2. require_once 'System/Mount.php';  
  3.  
  4. // Create the mount class
  5. $m = new System_Mount();  
  6.  
  7. // Get an object representing the CD-ROM entry
  8. $cdrom = $m->getEntryForPath('/media/cdrom0');  
  9.  
  10. if (PEAR::isError($cdrom)) { 
  11.    die($cdrom->message."\n");  
  12. }  
  13.  
  14. // Mount it
  15. $res = $cdrom->mount();  
  16. if (PEAR::isError($res)) { 
  17.    die($res->getMessage()."\n");  
  18. }  
  19.  
  20. // List its contents
  21. print `ls{$cdrom->mountPoint}`;  
  22.  
  23. // Unmount it
  24. $cdrom->unmount();  
  25. if (PEAR::isError($res)) { 
  26.    die($res->getMessage()."\n");  
  27. }  
  28.  
  29. ?> 

At first, you need to instantitiate a new System_Mount object.

Use the mount point for the corresponding entry in your /etc/fstab to obtain an object to mount, then check if there are any errors. If there are no errors mount the cdrom.


Remonter Remonter
L'éditeur javascript - CSS - Gentoo - Tutoriaux PHP - Tutoriels PHP - Bretagne - php - Moto - Kit graphique