+ /**
+ * Clears all ZFS labels on specified devices.
+ * Needed for blkid to display proper data.
+ *
+ */
+ public static function clearZFSLabel($disks) {
+ foreach ($disks as $disk) {
+ $cmd = "zpool labelclear /dev/" . $disk . "1";
+ OMVModuleZFSUtil::exec($cmd,$out,$res);
+ }
+ }
+
+ /**
+ * Return all disks in /dev/sdXX used by the pool
+ *
+ * @return array An array with all the disks
+ */
+ public static function getDevDisksByPool($name) {
+ $pool = new OMVModuleZFSZpool($name);
+ $disks = array();
+ $vdevs = $pool->getVdevs();
+ foreach ($vdevs as $vdev) {
+ $vdisks = $vdev->getDisks();
+ foreach ($vdisks as $vdisk) {
+ if (preg_match('/^[a-z0-9]+$/', $vdisk)) {
+ $disks[] = $vdisk;
+ continue;
+ }
+ $cmd = "ls -la /dev/disk/by-path/" . $vdisk;
+ unset($out);
+ OMVModuleZFSUtil::exec($cmd,$out,$res);
+ if (count($out) === 1) {
+ if (preg_match('/^.*\/([a-z0-9]+)$/', $out[0], $match)) {
+ $disks[] = $match[1];
+ }
+ }
+ }
+ }
+ return($disks);
+ }
+
+ /**
+ * Deletes all shared folders pointing to the specifc path
+ *
+ */
+ public static function deleteShares($name) {
+ global $xmlConfig;
+ $tmp = new OMVModuleZFSDataset($name);
+ $reldirpath = OMVModuleZFSUtil::getReldirpath($tmp->getMountPoint());
+ $poolname = OMVModuleZFSUtil::getPoolname($name);
+ $pooluuid = OMVModuleZFSUtil::getUUIDbyName($poolname);
+ $xpath = "//system/fstab/mntent[fsname='" . $pooluuid . "']";
+ $mountpoint = $xmlConfig->get($xpath);
+ $mntentuuid = $mountpoint['uuid'];
+ $xpath = "//system/shares/sharedfolder[mntentref='" . $mntentuuid . "' and reldirpath='" . $reldirpath . "']";
+ $object = $xmlConfig->get($xpath);
+ $xmlConfig->delete($xpath);
+ $dispatcher = &OMVNotifyDispatcher::getInstance();
+ $dispatcher->notify(OMV_NOTIFY_DELETE,"org.openmediavault.system.shares.sharedfolder",$object);
+ }
+
+ /**
+ * Get the relative path by complete path
+ *
+ * @return string Relative path of the complet path
+ */
+ public static function getReldirpath($path) {
+ $subdirs = preg_split('/\//',$path);
+ $reldirpath = "";
+ for ($i=2;$i<count($subdirs);$i++) {
+ $reldirpath .= $subdirs[$i] . "/";
+ }
+ return(rtrim($reldirpath, "/"));
+
+ }
+
+ /**
+ * Get /dev/disk/by-path from /dev/sdX
+ *
+ * @return string Disk identifier
+ */
+ public static function getDiskPath($disk) {
+ preg_match("/^.*\/([A-Za-z0-9]+)$/", $disk, $identifier);
+ $cmd = "ls -la /dev/disk/by-path | grep '$identifier[1]$'";
+ OMVModuleZFSUtil::exec($cmd, $out, $res);
+ if (is_array($out)) {
+ $cols = preg_split('/[\s]+/', $out[0]);
+ return($cols[count($cols)-3]);
+ }
+ }
+
+
+ /**
+ * Get poolname from name of dataset/volume etc.
+ *
+ * @return string Name of the pool
+ */
+ public static function getPoolname($name) {
+ $tmp = preg_split('/[\/]+/', $name);
+ return($tmp[0]);
+ }
+