From mboxrd@z Thu Jan 1 00:00:00 1970 From: Bernhard Bitsch To: development@lists.ipfire.org Subject: Re: [PATCHv2 04/12] extrahd.cgi: Store configured drives in a hash Date: Wed, 02 Aug 2023 13:53:21 +0200 Message-ID: In-Reply-To: <20230801154839.2373-4-stefan.schantl@ipfire.org> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============1853806738716745348==" List-Id: --===============1853806738716745348== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Reviewed-by: Bernhard Bitsch Am 01.08.2023 um 17:48 schrieb Stefan Schantl: > Signed-off-by: Stefan Schantl > --- > html/cgi-bin/extrahd.cgi | 71 ++++++++++++++++++---------------------- > 1 file changed, 32 insertions(+), 39 deletions(-) >=20 > diff --git a/html/cgi-bin/extrahd.cgi b/html/cgi-bin/extrahd.cgi > index f31bc2c44..bb0c22610 100644 > --- a/html/cgi-bin/extrahd.cgi > +++ b/html/cgi-bin/extrahd.cgi > @@ -31,6 +31,9 @@ require "${General::swroot}/header.pl"; > my %extrahdsettings =3D (); > my $errormessage =3D ""; > =20 > +# Hash to store the configured drives. > +my %configured_drives; > + > # SYSFS directory which contains all block device data. > my $sysfs_block_dir =3D "/sys/class/block"; > =20 > @@ -187,50 +190,26 @@ if ($errormessage) { > #########################################################################= ################################################### > #########################################################################= ################################################### > =20 > - print < - > -END > -; > +&Header::openbox('100%', 'center', $Lang::tr{'extrahd detected drives'}); > + > # Re-read mountpoints. > %mountpoints =3D &get_mountpoints(); > =20 > # Read-in the device config file. > open( FILE, "< $devicefile" ) or die "Unable to read $devicefile"; > - my @configfile =3D ; > - close FILE; > =20 > # Loop through the file content. > - foreach my $entry (sort @configfile) { > - my ($uuid, $fs, $path) =3D split( /\;/, $entry ); > - my $color=3D"$Header::colourred"; > - > - # Check if the device is currently mounted. > - if (&is_mounted($path)) { > - $color=3D$Header::colourgreen; > - } > + while () { > + # Cut the line into pieces. > + my ($uuid, $fs, $path) =3D split( /\;/, $_ ); > =20 > - print < - > - > - > - > - > -END > -; > + # Add the found entry to the hash of configured drives. > + $configured_drives{$uuid} =3D $path; > } > - print < -
 
$uuid$fs$path > -
> - > - > - > - > - > -
> -END > -; > =20 > -&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 =3D $mountpoints{$partition}; > =20 > + # If no mountpoint could be determined try to grab from > + # configured drives. > + unless($mountpoint) { > + my $uuid =3D $uuids{$partition}; > + > + # Build uuid string. > + $uuid =3D "UUID=3D" . $uuid; > + > + # Try to obtain a possible moutpoint from configured drives. > + $mountpoint =3D $configured_drives{$uuid} if ($configured_drives{$uuid= }); > + } > + > + # Check if the mountpoint is used as root or boot device. > if ($mountpoint eq "/" or $mountpoint =3D~ "^/boot") { > $disabled =3D "disabled"; > + > + # Check if it is mounted. > } elsif(&is_mounted($mountpoint)) { > $disabled =3D "disabled"; > - } > - > - # Omit the used filesystem. > - my $fs =3D $filesystems{$partition}; > =20 > # Check if the device is used as swap. > - if (&is_swap($partition)) { > + } elsif (&is_swap($partition)) { > $disabled =3D "disabled"; > $mountpoint =3D "swap"; > } > =20 > + # Omit the used filesystem. > + my $fs =3D $filesystems{$partition}; > + > print < =20 >
--===============1853806738716745348==--