All of lore.kernel.org
 help / color / mirror / Atom feed
From: Daniel Kiper <dkiper@net-space.pl>
To: Glenn Washburn <development@efficientek.com>
Cc: grub-devel@gnu.org,
	Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>,
	Patrick Steinhardt <ps@pks.im>, John Lane <john@lane.uk.net>
Subject: Re: [PATCH v9 6/7] luks2: Add detached header support
Date: Fri, 29 Apr 2022 15:12:52 +0200	[thread overview]
Message-ID: <20220429131252.hcl33m3j6g2ev7mb@tomti.i.net-space.pl> (raw)
In-Reply-To: <f15ff743c417d69c6b507e978f4e98578f3b9554.1649658484.git.development@efficientek.com>

On Mon, Apr 11, 2022 at 06:40:27AM +0000, Glenn Washburn wrote:
> If a header file is given to the LUKS2 backend, use that file as the LUKS2
> header, instead of looking for it on the disk.
>
> Signed-off-by: Glenn Washburn <development@efficientek.com>
> ---
>  grub-core/disk/luks2.c | 67 ++++++++++++++++++++++++++++++------------
>  1 file changed, 49 insertions(+), 18 deletions(-)
>
> diff --git a/grub-core/disk/luks2.c b/grub-core/disk/luks2.c
> index 349462c61a..af5bc4fc82 100644
> --- a/grub-core/disk/luks2.c
> +++ b/grub-core/disk/luks2.c
> @@ -313,13 +313,22 @@ luks2_get_keyslot (grub_luks2_keyslot_t *k, grub_luks2_digest_t *d, grub_luks2_s
>
>  /* Determine whether to use primary or secondary header */
>  static grub_err_t
> -luks2_read_header (grub_disk_t disk, grub_luks2_header_t *outhdr)
> +luks2_read_header (grub_disk_t disk, grub_file_t hdr_file, grub_luks2_header_t *outhdr)
>  {
>    grub_luks2_header_t primary, secondary, *header = &primary;
> -  grub_err_t ret;
> +  grub_err_t ret = GRUB_ERR_NONE;
>
>    /* Read the primary LUKS header. */
> -  ret = grub_disk_read (disk, 0, 0, sizeof (primary), &primary);
> +  if (hdr_file)

if (hdr_file != NULL) and below please...

> +    {
> +      if (grub_file_seek (hdr_file, 0) == (grub_off_t) -1)
> +	ret = grub_errno;

Hmmm... Why do not "return grub_errno;"?

> +
> +      else if (grub_file_read (hdr_file, &primary, sizeof (primary)) != sizeof (primary))
> +	ret = grub_errno;

Ditto. And then you can drop "else"...

> +    }
> +  else
> +    ret = grub_disk_read (disk, 0, 0, sizeof (primary), &primary);
>    if (ret)

... and this "if" ... Or to be precise add {} after else and convert to
"if (ret != GRUB_ERR_NONE)".

And it seems to me you can do similar optimizations below.

Daniel


  reply	other threads:[~2022-04-29 13:13 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-11  6:40 [PATCH v9 0/7] Cryptodisk detached headers and key files Glenn Washburn
2022-04-11  6:40 ` [PATCH v9 1/7] cryptodisk: luks: Unify grub_cryptodisk_dev function names Glenn Washburn
2022-04-28 12:01   ` Daniel Kiper
2022-04-11  6:40 ` [PATCH v9 2/7] cryptodisk: geli: " Glenn Washburn
2022-04-28 12:02   ` Daniel Kiper
2022-04-11  6:40 ` [PATCH v9 3/7] cryptodisk: Add --header option to cryptomount and fail to implement it in the backends Glenn Washburn
2022-04-28 12:39   ` Daniel Kiper
2022-04-11  6:40 ` [PATCH v9 4/7] cryptodisk: Add support for LUKS1 detached headers Glenn Washburn
2022-04-28 12:46   ` Daniel Kiper
2022-04-11  6:40 ` [PATCH v9 5/7] cryptodisk: Add options to cryptomount to support keyfiles Glenn Washburn
2022-04-29 13:03   ` Daniel Kiper
2022-05-05 23:03     ` Glenn Washburn
2022-04-11  6:40 ` [PATCH v9 6/7] luks2: Add detached header support Glenn Washburn
2022-04-29 13:12   ` Daniel Kiper [this message]
2022-04-11  6:40 ` [PATCH v9 7/7] docs: Add documentation on keyfile and detached header options to cryptomount Glenn Washburn
2022-04-29 13:15   ` Daniel Kiper

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=20220429131252.hcl33m3j6g2ev7mb@tomti.i.net-space.pl \
    --to=dkiper@net-space.pl \
    --cc=GNUtoo@cyberdimension.org \
    --cc=development@efficientek.com \
    --cc=grub-devel@gnu.org \
    --cc=john@lane.uk.net \
    --cc=ps@pks.im \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.