grub-devel
[Top][All Lists]
Advanced

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

Re: [RFC] [PATCH] Generate stable device names in device.map on Linux


From: Vladimir 'φ-coder/phcoder' Serbinenko
Subject: Re: [RFC] [PATCH] Generate stable device names in device.map on Linux
Date: Fri, 25 Jun 2010 20:46:48 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100515 Icedove/3.0.4

>
> === modified file 'util/deviceiter.c'
> --- util/deviceiter.c 2010-06-11 20:31:16 +0000
> +++ util/deviceiter.c 2010-06-21 08:54:07 +0000
> @@ -28,6 +28,7 @@
>  #include <errno.h>
>  #include <fcntl.h>
>  #include <limits.h>
> +#include <dirent.h>
>  
>  #include <grub/util/misc.h>
>  #include <grub/util/deviceiter.h>
> @@ -345,18 +346,37 @@ get_xvd_disk_name (char *name, int unit)
>  }
>  #endif
>  
> +static struct seen_device
> +{
> +  struct seen_device *next;
> +  const char *name;
> +} *seen;
> +
>  /* Check if DEVICE can be read. If an error occurs, return zero,
>     otherwise return non-zero.  */
>  static int
>  check_device (const char *device)
>  {
>   
This patch subtly changes the semantics of this function. It's a static
one so the ramifications are relatively small. But you need at very
least to resync the comment and changing name when changing semantics is
recommended.
> @@ -441,6 +483,8 @@ grub_util_iterate_devices (int NESTED_FU
>  {
>    int i;
>  
> +  clear_seen_devices ();
> +
>    /* Floppies.  */
>    for (i = 0; i < floppy_disks; i++)
>      {
> @@ -453,10 +497,56 @@ grub_util_iterate_devices (int NESTED_FU
>        /* In floppies, write the map, whether check_device succeeds
>        or not, because the user just may not insert floppies.  */
>        if (hook (name, 1))
> -     return;
> +     goto out;
>      }
>  
>  #ifdef __linux__
> +  {
> +    DIR *dir = opendir ("/dev/disk/by-id");
> +
> +    if (dir)
> +      {
> +     struct dirent *entry;
> +     char **names;
> +     size_t names_len = 0, names_max = 1024, i;
> +
> +     names = xmalloc (names_max * sizeof *names);
> +
>   
Please use parentheses for sizeof
> +     qsort (names, names_len, sizeof *names, &compare_file_names);
> +
>   
Which part of code uses that array is sorted?
> +     closedir (dir);
> +
> +     /* Now add all the devices in sorted order.  */
> +     for (i = 0; i < names_len; ++i)
> +       {
> +         char *path = xasprintf ("/dev/disk/by-id/%s", names[i]);
> +         if (check_device (path))
> +           {
> +             if (hook (path, 0))
> +               goto out;
> +           }
> +         free (path);
> +         free (names[i]);
> +       }
> +     free (names);
> +      }
> +  }
> +
>    if (have_devfs ())
>      {
>        i = 0;
>   


-- 
Regards
Vladimir 'φ-coder/phcoder' Serbinenko


Attachment: signature.asc
Description: OpenPGP digital signature


reply via email to

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