From patchwork Fri Jun 23 04:01:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Schantl X-Patchwork-Id: 6949 Return-Path: Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by web04.haj.ipfire.org (Postfix) with ESMTPS id 4QnNpY09ZFz3wmM for ; Fri, 23 Jun 2023 04:01:41 +0000 (UTC) Received: from mail02.haj.ipfire.org (mail02.haj.ipfire.org [172.28.1.201]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail02.haj.ipfire.org", Issuer "R3" (verified OK)) by mail01.ipfire.org (Postfix) with ESMTPS id 4QnNpV1LJVz2SR; Fri, 23 Jun 2023 04:01:38 +0000 (UTC) Received: from mail02.haj.ipfire.org (localhost [127.0.0.1]) by mail02.haj.ipfire.org (Postfix) with ESMTP id 4QnNpT6l4bz2xY5; Fri, 23 Jun 2023 04:01:37 +0000 (UTC) Received: from mail01.ipfire.org (mail01.haj.ipfire.org [172.28.1.202]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) client-signature ECDSA (P-384)) (Client CN "mail01.haj.ipfire.org", Issuer "R3" (verified OK)) by mail02.haj.ipfire.org (Postfix) with ESMTPS id 4QnNpS6Fpbz2xRH for ; Fri, 23 Jun 2023 04:01:36 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384) server-digest SHA384) (No client certificate requested) by mail01.ipfire.org (Postfix) with ESMTPSA id 4QnNpS2VJkz1GG; Fri, 23 Jun 2023 04:01:36 +0000 (UTC) DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003ed25519; t=1687492896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b6pWBIaoqM+6K3/xraJ9IbHWjs8LJMJm6hlRsigbs3o=; b=XBb4cYCED1cra8JTDN8NBloatf70pRYqyt+1ZorI6Rxb+k+P5wPDrcuNfwB29hVOVW8dCM /QnoTUR+N91W8FAA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ipfire.org; s=202003rsa; t=1687492896; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=b6pWBIaoqM+6K3/xraJ9IbHWjs8LJMJm6hlRsigbs3o=; b=U4icPE05UgCjksWJKogpRqTphqrIwKoBlTSEzl44iaO7VTGGo9WFHm9CQR4CmvXZ+YU5AY V48YdXaHqTAwFlSeEYV1l1W5QG1S0rX2ma+0EpJElL2Idll/NlGu6DL6RdR8aei3R5DcHE bybC0s6Yg7KCyK3Ni6UCg8YK2sX4HtvqTnzmEq5nCh+itNLuPzpA3UsP7Rb1fblahTYwJg aZI14zZybQuRVizDbUXtiX5fL8197clLGrqdR4nar8P8Gp4k6OGt6+9iqfYOxTY7XQh17k pT/nU2JTMdOmDECQzYooFgZxGyRdGtoERlE8TgFn2Nybfc74OyP1AjJKAOTP0Q== From: Stefan Schantl To: development@lists.ipfire.org Subject: [PATCH 4/8] extrahd.cgi: Store configured drives in a hash Date: Fri, 23 Jun 2023 06:01:20 +0200 Message-Id: <20230623040124.3826-4-stefan.schantl@ipfire.org> In-Reply-To: <20230623040124.3826-1-stefan.schantl@ipfire.org> References: <20230623040124.3826-1-stefan.schantl@ipfire.org> MIME-Version: 1.0 X-BeenThere: development@lists.ipfire.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: IPFire development talk List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: development-bounces@lists.ipfire.org Sender: "Development" Signed-off-by: Stefan Schantl --- html/cgi-bin/extrahd.cgi | 71 ++++++++++++++++++---------------------- 1 file changed, 32 insertions(+), 39 deletions(-) diff --git a/html/cgi-bin/extrahd.cgi b/html/cgi-bin/extrahd.cgi index dde4e7356..fc8685830 100644 --- a/html/cgi-bin/extrahd.cgi +++ b/html/cgi-bin/extrahd.cgi @@ -31,6 +31,9 @@ require "${General::swroot}/header.pl"; my %extrahdsettings = (); my $errormessage = ""; +# Hash to store the configured drives. +my %configured_drives; + # SYSFS directory which contains all block device data. my $sysfs_block_dir = "/sys/class/block"; @@ -187,50 +190,26 @@ if ($errormessage) { ############################################################################################################################ ############################################################################################################################ - print < -END -; +&Header::openbox('100%', 'center', $Lang::tr{'extrahd detected drives'}); + # Re-read mountpoints. %mountpoints = &get_mountpoints(); # Read-in the device config file. open( FILE, "< $devicefile" ) or die "Unable to read $devicefile"; - my @configfile = ; - close FILE; # Loop through the file content. - foreach my $entry (sort @configfile) { - my ($uuid, $fs, $path) = split( /\;/, $entry ); - my $color="$Header::colourred"; - - # Check if the device is currently mounted. - if (&is_mounted($path)) { - $color=$Header::colourgreen; - } + while () { + # Cut the line into pieces. + my ($uuid, $fs, $path) = split( /\;/, $_ ); - print <  - $uuid - $fs - $path - -
- - - - - -
-END -; + # Add the found entry to the hash of configured drives. + $configured_drives{$uuid} = $path; } - print < -END -; -&Header::openbox('100%', 'center', $Lang::tr{'extrahd detected drives'}); + # Close the file handle. + close(FILE); + print < END @@ -270,21 +249,35 @@ END # Get the mountpoint. my $mountpoint = $mountpoints{$partition}; + # If no mountpoint could be determined try to grab from + # configured drives. + unless($mountpoint) { + my $uuid = $uuids{$partition}; + + # Build uuid string. + $uuid = "UUID=" . $uuid; + + # Try to obtain a possible moutpoint from configured drives. + $mountpoint = $configured_drives{$uuid} if ($configured_drives{$uuid}); + } + + # Check if the mountpoint is used as root or boot device. if ($mountpoint eq "/" or $mountpoint =~ "^/boot") { $disabled = "disabled"; + + # Check if it is mounted. } elsif(&is_mounted($mountpoint)) { $disabled = "disabled"; - } - - # Omit the used filesystem. - my $fs = $filesystems{$partition}; # Check if the device is used as swap. - if (&is_swap($partition)) { + } elsif (&is_swap($partition)) { $disabled = "disabled"; $mountpoint = "swap"; } + # Omit the used filesystem. + my $fs = $filesystems{$partition}; + print <