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