Commit 6376e6fb authored by Mikhail Karpenko's avatar Mikhail Karpenko

Update device list in camogmgui faster

It takes some time for 'blkid' command invoked without parameters to process all
partitions. The same command invoked with a path to partition works
faster. This commit replaces single blkid invokation with invokation for
each suitable partition in a list.
parent 6481a514
...@@ -618,21 +618,46 @@ function xml_footer() { ...@@ -618,21 +618,46 @@ function xml_footer() {
echo "</camogm_interface>\n"; echo "</camogm_interface>\n";
} }
/** Get a list of suitable partitions. The list will contain SATA devices only and
* will have the following format: "name" => "size_in_blocks".
*/
function get_partitions()
{
$names = array();
$regexp = '/([0-9]+) +(sd[a-z0-9]+$)/';
exec("cat /proc/partitions", $partitions);
// the first two elements of an array are table header and empty line delimiter, skip them
for ($i = 2; $i < count($partitions); $i++) {
// select SATA devices only
if (preg_match($regexp, $partitions[$i], $name) == 1) {
$names[$name[2]] = $name[1];
$j++;
}
}
return $names;
}
/** Get a list of disk devices which have file system and can be mounted. This function /** Get a list of disk devices which have file system and can be mounted. This function
* uses 'blkid' command from busybox. * uses 'blkid' command from busybox.
*/ */
function get_mnt_dev() function get_mnt_dev()
{ {
exec("blkid", $ids); $partitions = get_partitions();
$i = 0; foreach ($partitions as $partition => $size) {
foreach ($ids as $id) { $res = array();
$devices[$i] = preg_replace('/: +.*/', "", $id); $dev = "/dev/" . $partition;
if (preg_match('/(?<=TYPE=")[a-z0-9]+(?=")/', $id, $fs) == 1) exec("blkid " . $dev, $res);
$fs_types[$i] = $fs[0]; if (!empty($res)) {
else $devices[$i] = preg_replace('/: +.*/', "", $res[0]);
$fs_types[$i] = "none"; if (preg_match('/(?<=TYPE=")[a-z0-9]+(?=")/', $res[0], $fs) == 1)
$i++; $fs_types[$i] = $fs[0];
else
$fs_types[$i] = "none";
$i++;
}
} }
return array("devices" => $devices, "types" => $fs_types); return array("devices" => $devices, "types" => $fs_types);
} }
...@@ -640,22 +665,11 @@ function get_mnt_dev() ...@@ -640,22 +665,11 @@ function get_mnt_dev()
function get_raw_dev() function get_raw_dev()
{ {
$j = 0; $j = 0;
$regexp = '/([0-9]+) +(sd[a-z0-9]+$)/';
$names = array();
$ret = get_mnt_dev(); $ret = get_mnt_dev();
$devices = $ret["devices"]; $devices = $ret["devices"];
$types = $ret["types"]; $types = $ret["types"];
exec("cat /proc/partitions", $partitions);
// get a list of all suitable partitions $names = get_partitions();
// the first two elements of an array are table header and empty line delimiter, skip them
for ($i = 2; $i < count($partitions); $i++) {
// select SATA devices only
if (preg_match($regexp, $partitions[$i], $name) == 1) {
$names[$name[2]] = $name[1];
$j++;
}
}
// filter out partitions with file system // filter out partitions with file system
$i = 0; $i = 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment