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