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

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
Loading
Loading
Loading
Loading
+36 −22
Original line number Diff line number Diff line
@@ -618,21 +618,46 @@ function xml_footer() {
	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
 *  uses 'blkid' command from busybox.
 */ 
function get_mnt_dev()
{
	exec("blkid", $ids);
	$i = 0;
	foreach ($ids as $id) {
		$devices[$i] = preg_replace('/: +.*/', "", $id);
		if (preg_match('/(?<=TYPE=")[a-z0-9]+(?=")/', $id, $fs) == 1)
	$partitions = get_partitions();
	foreach ($partitions as $partition => $size) {
		$res = array();
		$dev = "/dev/" . $partition;
		exec("blkid " . $dev, $res);
		if (!empty($res)) {
			$devices[$i] = preg_replace('/: +.*/', "", $res[0]);
			if (preg_match('/(?<=TYPE=")[a-z0-9]+(?=")/', $res[0], $fs) == 1)
				$fs_types[$i] = $fs[0];
			else
				$fs_types[$i] = "none";
			$i++;
		}
	}
	
	return array("devices" => $devices, "types" => $fs_types);
}

@@ -640,22 +665,11 @@ function get_mnt_dev()
function get_raw_dev()
{
	$j = 0;
	$regexp = '/([0-9]+) +(sd[a-z0-9]+$)/';
	$names = array();
	$ret = get_mnt_dev();
	$devices = $ret["devices"]; 
	$types = $ret["types"];
	exec("cat /proc/partitions", $partitions);

	// get a list of all suitable 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++;
		}
	}
	$names = get_partitions();
	
	// filter out partitions with file system 
	$i = 0;