|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of the sj-i/php-fuse package. |
|
5
|
|
|
* |
|
6
|
|
|
* (c) sji <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
declare(strict_types=1); |
|
13
|
|
|
|
|
14
|
|
|
namespace Fuse; |
|
15
|
|
|
|
|
16
|
|
|
use FFI; |
|
17
|
|
|
use FFI\CData; |
|
18
|
|
|
use Fuse\Libc\Fuse\FuseIoctlDataPointer; |
|
19
|
|
|
|
|
20
|
|
|
final class Fuse |
|
21
|
|
|
{ |
|
22
|
|
|
private static ?self $instance; |
|
23
|
|
|
/** @var FuseFFI */ |
|
24
|
|
|
public FFI $ffi; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* @param FuseFFI $ffi |
|
28
|
|
|
*/ |
|
29
|
|
|
private function __construct(FFI $ffi) |
|
30
|
|
|
{ |
|
31
|
|
|
$this->ffi = $ffi; |
|
|
|
|
|
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @return FuseFFI |
|
36
|
|
|
*/ |
|
37
|
|
|
private static function load(): FFI |
|
38
|
|
|
{ |
|
39
|
|
|
/** @var FuseFFI */ |
|
40
|
|
|
return FFI::cdef( |
|
41
|
|
|
file_get_contents(__DIR__ . '/Headers/fuse.h'), |
|
42
|
|
|
'libfuse.so' |
|
43
|
|
|
); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
public static function getInstance(): self |
|
47
|
|
|
{ |
|
48
|
|
|
if (!isset(self::$instance)) { |
|
49
|
|
|
self::$instance = new self(self::load()); |
|
50
|
|
|
} |
|
51
|
|
|
return self::$instance; |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param list<string> $args |
|
|
|
|
|
|
56
|
|
|
* @param FuseOperations $fuse_operations |
|
57
|
|
|
* @param CData|null $user_data |
|
58
|
|
|
* @return int |
|
59
|
|
|
*/ |
|
60
|
|
|
public function main(array $args, FuseOperations $fuse_operations, ?CData $user_data = null): int |
|
61
|
|
|
{ |
|
62
|
|
|
$argc = count($args); |
|
63
|
|
|
/** @var \FFI\CDataArray $argv_real */ |
|
64
|
|
|
$argv_real = FFI::new('char *[' . count($args) . ']'); |
|
65
|
|
|
foreach ($args as $key => $item) { |
|
66
|
|
|
$item_len = strlen($item); |
|
67
|
|
|
$item_len_nul = $item_len + 1; |
|
68
|
|
|
/** @var \FFI\CDataArray $argv_item */ |
|
69
|
|
|
$argv_item = FFI::new("char[{$item_len_nul}]", false, true); |
|
70
|
|
|
FFI::memcpy($argv_item, $item, $item_len); |
|
71
|
|
|
$argv_item[$item_len] = "\0"; |
|
72
|
|
|
$argv_real[$key] = $argv_item; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
return Fuse::getInstance()->ffi->fuse_main_real( |
|
|
|
|
|
|
76
|
|
|
$argc, |
|
77
|
|
|
$argv_real, |
|
78
|
|
|
FFI::addr($fuse_operations->getCData()), |
|
79
|
|
|
$fuse_operations->getSize(), |
|
80
|
|
|
$user_data |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.