From: Bernhard Bitsch <bbitsch@ipfire.org>
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 [thread overview]
Message-ID: <f6d77daf-8e2d-184c-5caa-afefa9ad526e@ipfire.org> (raw)
In-Reply-To: <20230801154839.2373-4-stefan.schantl@ipfire.org>
[-- Attachment #1: Type: text/plain, Size: 4259 bytes --]
Reviewed-by: Bernhard Bitsch <bbitsch(a)ipfire.org>
Am 01.08.2023 um 17:48 schrieb Stefan Schantl:
> Signed-off-by: Stefan Schantl <stefan.schantl(a)ipfire.org>
> ---
> 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 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 = ();
> 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
> - <table border='0' width='600' cellspacing="0">
> -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 = <FILE>;
> - 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 (<FILE>) {
> + # Cut the line into pieces.
> + my ($uuid, $fs, $path) = split( /\;/, $_ );
>
> - print <<END
> - <tr><td colspan="4"> </td></tr>
> - <tr><td align='left'><font color=$color><b>$uuid</b></font></td>
> - <td align='left'>$fs</td>
> - <td align='left'>$path</td>
> - <td align='center'>
> - <form method='post' action='$ENV{'SCRIPT_NAME'}'>
> - <input type='hidden' name='DEVICE' value='$uuid' />
> - <input type='hidden' name='FS' value='$fs' />
> - <input type='hidden' name='PATH' value='$path' />
> - <input type='hidden' name='ACTION' value='$Lang::tr{'delete'}' />
> - <input type='image' alt='$Lang::tr{'delete'}' title='$Lang::tr{'delete'}' src='/images/delete.gif' />
> - </form></td></tr>
> -END
> -;
> + # Add the found entry to the hash of configured drives.
> + $configured_drives{$uuid} = $path;
> }
> - print <<END
> - </table>
> -END
> -;
>
> -&Header::openbox('100%', 'center', $Lang::tr{'extrahd detected drives'});
> + # Close the file handle.
> + close(FILE);
> +
> print <<END
> <table border='0' width='600' cellspacing="0">
> 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 <<END
>
> <form method='post' action='$ENV{'SCRIPT_NAME'}'>
next prev parent reply other threads:[~2023-08-02 11:53 UTC|newest]
Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-01 15:48 [PATCHv2 01/12] extrahd.cgi: Add various perl functions deal with block devices Stefan Schantl
2023-08-01 15:48 ` [PATCHv2 02/12] extrahd.cgi: Refactor code to use new introduced perl functions Stefan Schantl
2023-08-02 11:48 ` Bernhard Bitsch
2023-08-01 15:48 ` [PATCHv2 03/12] extrahd.cgi: Abort if a device could not be umounted Stefan Schantl
2023-08-02 11:50 ` Bernhard Bitsch
2023-08-01 15:48 ` [PATCHv2 04/12] extrahd.cgi: Store configured drives in a hash Stefan Schantl
2023-08-02 11:53 ` Bernhard Bitsch [this message]
2023-08-01 15:48 ` [PATCHv2 05/12] extrahd.cgi: Add is_configured function Stefan Schantl
2023-08-02 11:54 ` Bernhard Bitsch
2023-08-01 15:48 ` [PATCHv2 06/12] extrahd.cgi: Display mount status next to the corresponding drive Stefan Schantl
2023-08-02 11:55 ` Bernhard Bitsch
2023-08-01 15:48 ` [PATCHv2 07/12] extrahd.cgi: Re-order sanity check logic Stefan Schantl
2023-08-02 11:57 ` Bernhard Bitsch
2023-08-01 15:48 ` [PATCHv2 08/12] extrahd.cgi: Add missing translation strings Stefan Schantl
2023-08-02 12:02 ` Bernhard Bitsch
2023-08-01 15:48 ` [PATCHv2 09/12] extrahd.cgi: Drop select for FS selection Stefan Schantl
2023-08-02 12:09 ` Bernhard Bitsch
2023-08-01 15:48 ` [PATCHv2 10/12] extrahd.cgi: Requires "auto" as hidden FS type to mount a new device Stefan Schantl
2023-08-02 12:10 ` Bernhard Bitsch
2023-08-01 15:48 ` [PATCHv2 11/12] extrahd.cgi: Do not allow "/mnt" or "/media" as mount points Stefan Schantl
2023-08-02 12:11 ` Bernhard Bitsch
2023-08-01 15:48 ` [PATCHv2 12/12] extrahd.cgi: Adjust copyright header Stefan Schantl
2023-08-02 12:12 ` Bernhard Bitsch
2023-08-02 11:39 ` [PATCHv2 01/12] extrahd.cgi: Add various perl functions deal with block devices Bernhard Bitsch
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=f6d77daf-8e2d-184c-5caa-afefa9ad526e@ipfire.org \
--to=bbitsch@ipfire.org \
--cc=development@lists.ipfire.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox