grub-devel
[Top][All Lists]
Advanced

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

Re: [PATCH 3/3] grub EFI disk device enumberating


From: Johan Rydberg
Subject: Re: [PATCH 3/3] grub EFI disk device enumberating
Date: Tue, 24 Oct 2006 16:05:56 +0200
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

Johan Rydberg <address@hidden> writes:

> This code can be shorter; you only have to compare the lengths. If
> they match, you can do a memcmp on the whole device path.  

It could look something like this;

/* Returns zero if device path SUBPATH is a subpath of device path
   PATH.  */
static int
compare_subpath (const grub_efi_device_path_t *subpath,
                 const grub_efi_device_path_t *path)
{
  if (! subpath || ! path)
    return 1;

  while (1)
    {
      int len, ret;

      if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (subpath))
        return 0;
      else if (GRUB_EFI_END_ENTIRE_DEVICE_PATH (path))
        return 1;

      if (GRUB_EFI_DEVICE_PATH_LENGTH (subpath)
          != GRUB_EFI_DEVICE_PATH_LENGTH (path))
        return ((int) GRUB_EFI_DEVICE_PATH_LENGTH (subpath)
                - (int)  GRUB_EFI_DEVICE_PATH_LENGTH (path));

      len = GRUB_EFI_DEVICE_PATH_LENGTH (path);
      ret = grub_memcmp (subpath, path, len);
      if (ret)
        return ret;

      path = (grub_efi_device_path_t *) ((char *) path + len);
      subpath = (grub_efi_device_path_t *) ((char *) subpath + len);
    }
}

I guess that should work at least, it is not tested.

In gnufi I have a device_path_iterate function that could be used for
these kind of things.  Maybe we should bring it in to GRUB2.

/* Iterate nodes of the device path.  *PATHP should be set to point to
   the path that is to be iterated.  NULL will be returned when the
   end of the path has been reached.  */
efi_device_path_t *
efi_device_path_iterate (efi_device_path_t **pathp)
{
  efi_device_path_t *p = *pathp;

  if (EFI_END_ENTIRE_DEVICE_PATH (p))
    return NULL;
  else
    {
      efi_uint_t len = EFI_DEVICE_PATH_LENGTH (p);
      *pathp = (efi_device_path_t *) (((char *) p) + len);
      return p;
    }
}

~j

Attachment: pgp0gMCdnvh13.pgp
Description: PGP signature


reply via email to

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