/
sg.inc
66 lines (62 loc) · 1.95 KB
/
sg.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
/**
* This file is part of OpenMediaVault.
*
* @license http://www.gnu.org/licenses/gpl.html GPL Version 3
* @author Volker Theile <volker.theile@openmediavault.org>
* @copyright Copyright (c) 2009-2024 Volker Theile
*
* OpenMediaVault is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* OpenMediaVault is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenMediaVault. If not, see <http://www.gnu.org/licenses/>.
*/
namespace OMV\System\Storage\Backend;
/**
* Implements the storage device backend for SCSI generic character devices.
* https://www.kernel.org/doc/Documentation/scsi/scsi-generic.txt
* @ingroup api
*/
class SG extends BackendAbstract {
function getType() {
return OMV_STORAGE_DEVICE_TYPE_SCSIGENERIC;
}
function enumerate() {
$path = "/sys/class/scsi_generic";
if (!file_exists($path)) {
return FALSE;
}
$result = [];
foreach (new \DirectoryIterator($path) as $item) {
if ($item->isDot() || !$item->isLink())
continue;
if (1 !== preg_match("/^sg[0-9]+$/", $item->getFilename()))
continue;
// Check if it is a SCSI generic disk.
$sd = $this->getImpl(sprintf("/dev/%s", $item->getFilename()));
if (0 !== $sd->getType())
continue;
$result[] = $sd->getDeviceFile();
}
if (!sort($result, SORT_NATURAL))
return FALSE;
return $result;
}
function isTypeOf($deviceFile) {
// Examples:
// - /dev/sg0
// - /dev/sg17
return $this->isTypeOfByName($deviceFile, "sg[0-9]+");
}
function getImpl($args) {
return new \OMV\System\Storage\StorageDeviceSG($args);
}
}