grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 3/4] luks2: set up dummy sector size during scan


From: Patrick Steinhardt
Subject: Re: [PATCH 3/4] luks2: set up dummy sector size during scan
Date: Sun, 8 Aug 2021 16:20:12 +0200

On Fri, Aug 06, 2021 at 12:51:10PM +0800, Michael Chang via Grub-devel wrote:
[snip]
> diff --git a/grub-core/disk/cryptodisk.c b/grub-core/disk/cryptodisk.c
> index 90f82b2d3..c2bb2b6eb 100644
> --- a/grub-core/disk/cryptodisk.c
> +++ b/grub-core/disk/cryptodisk.c
> @@ -1040,6 +1040,7 @@ grub_cryptodisk_cheat_mount (const char *sourcedev, 
> const char *cheat)
>    grub_cryptodisk_t dev;
>    grub_cryptodisk_dev_t cr;
>    grub_disk_t source;
> +  unsigned int cheat_sector_size;
>  
>    /* Try to open disk.  */
>    source = grub_disk_open (sourcedev);
> @@ -1062,6 +1063,25 @@ grub_cryptodisk_cheat_mount (const char *sourcedev, 
> const char *cheat)
>      if (!dev)
>        continue;
>  
> +    /* Use the sector size and count of the cheat device */
> +    dev->cheat_fd = grub_util_fd_open (cheat, GRUB_UTIL_FD_O_RDONLY);
> +    if (!GRUB_UTIL_FD_IS_VALID (dev->cheat_fd))
> +      {
> +        grub_free (dev);
> +        return grub_errno;
> +      }
> +    dev->total_sectors = grub_util_get_fd_size (dev->cheat_fd, cheat, 
> &cheat_sector_size);
> +    if (dev->total_sectors == -1)
> +      {
> +        grub_util_fd_close (dev->cheat_fd);
> +        grub_free (dev);
> +        return grub_errno;
> +      }

We may want to print error messages for both error cases. Otherwise it's
hard to tell why cheat mounting might've failed.

> +    dev->log_sector_size = cheat_sector_size;
> +    dev->total_sectors >>= dev->log_sector_size;
> +    grub_util_fd_close (dev->cheat_fd);
> +    dev->cheat_fd = GRUB_UTIL_FD_INVALID;

Wouldn't it make more sense to just use a separate variable for the FD?
Feels kind of weird to put it into `dev->cheat_fd`, only to clone and
unset the member variable immediately after we're done again.

In any case, thanks for the patch. It does look a lot more sensible
compared to what I'd been doing. Do you want to keep owning the patch
and try to upstream it, or shall I pick it up as part of this patch
series? I'd of course retain author information.

Patrick

Attachment: signature.asc
Description: PGP signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]