Continued:
[core.git] / framework / main / classes / fuse / class_FrameworkFuseWrapper.php_discontinued
1 <?php
2 // Own namespace
3 namespace Org\Mxchange\CoreFramework\Wrapper\Fuse;
4
5 // Import framework stuff
6 use Org\Mxchange\CoreFramework\Registry\Registerable;
7
8 // Import library stuff
9 use \FuseWrapper;
10
11 /**
12  * A class for binding to the FUSE wrapper. This class requires the PHP
13  * extension fuse.dll/so being added to your setup. If you want to use this
14  * class, please activate and use the FUSE feature instead of using this class
15  * directly. This gives you all required pre-tests. Please read there for
16  * more detailed informations.
17  *
18  * @author              Roland Haeder <webmaster@ship-simu.org>
19  * @version             0.0.0
20  * @copyright   Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2017 Core Developer Team
21  * @license             GNU GPL 3.0 or any newer version
22  * @link                http://www.ship-simu.org
23  *
24  * This program is free software: you can redistribute it and/or modify
25  * it under the terms of the GNU General Public License as published by
26  * the Free Software Foundation, either version 3 of the License, or
27  * (at your option) any later version.
28  *
29  * This program is distributed in the hope that it will be useful,
30  * but WITHOUT ANY WARRANTY; without even the implied warranty of
31  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
32  * GNU General Public License for more details.
33  *
34  * You should have received a copy of the GNU General Public License
35  * along with this program. If not, see <http://www.gnu.org/licenses/>.
36  */
37 class FrameworkFuseWrapper extends FuseWrapper implements Registerable {
38         /**
39          * Get attributes
40          *
41          * @param       $path   Path to get attributes from
42          * @param       $stbuf  An instance of a FuseStat class
43          * @return      Status code
44          */
45         public function FsGetAttr ($path, FuseStat $stbuf) {
46                 if (strcmp($path, '/') == 0 ) {
47                         $stbuf->st_mode = FUSE_S_IFDIR | 0750;
48                         $stbuf->st_nlink = 2;
49                 } else {
50                         $stbuf->st_uid   = posix_getuid();
51                         $stbuf->st_gid   = posix_getgid();
52                         $stbuf->st_mode  = FUSE_S_IFREG | 0640;
53                         $stbuf->st_nlink = 1;
54                         $stbuf->st_size  = 56;
55                         $stbuf->st_mtime = 1226379246;
56                 }
57
58                 return -FUSE_ENOERR;
59         }
60
61         /**
62          * Open operation
63          *
64          * @param       $path   Path to open
65          * @param       $fi             An instance of a FuseFileInfo class
66          * @return      Status code
67          */
68         public function FsOpen ($path, FuseFileInfo $fi) {
69                 if (($fi->flags & FUSE_O_ACCMODE) != FUSE_O_RDONLY) {
70                         return -FUSE_ENOACCES;
71                 } // END - if
72
73                 return -FUSE_ENOERR;
74         }
75
76         /**
77          * Read operation
78          *
79          * @param       $path   Path to open
80          * @param       $buf    Read data
81          * @param       $size   Maximum expected size (?)
82          * @param       $offset Seek offset
83          * @param       $fi             An instance of a FuseFileInfo class
84          * @return      Length of read data
85          */
86         public function FsRead ($path, &$buf, $size, $offset, FuseFileInfo $fi) {
87                 $data = 'You have implemented your first FUSE file system with PHP!' . PHP_EOL;
88
89                 if ($offset > strlen($data)) {
90                         return 0;
91                 } // END - if
92
93                 $buf = substr( $data, $offset, $size );
94
95                 return strlen($data);
96         }
97
98         /**
99          * Read directory operation
100          *
101          * @param       $path   Path to open
102          * @param       $buf    An array with all read entries
103          * @return      Status code
104          */
105         public function FsReadDir ($path, array &$buf) {
106                 if (strcmp($path, '/') != 0) {
107                         return -FUSE_ENOENT;
108                 } // END - if
109
110                 $buf[] = '.';
111                 $buf[] = '..';
112                 $buf[] = 'helloworld.txt';
113
114                 return -FUSE_ENOERR;
115         }
116
117 }