[parted-devel] [PATCH] Dont try to stat stuff that we know does not exist.

Jim Meyering jim at meyering.net
Thu Feb 19 17:14:26 UTC 2009


Joel Granados Moreno <jgranado at redhat.com> writes:
>     modified:   libparted/arch/linux.c:  When we look for stuff in

Thanks!

Please follow ChangeLog conventions, and use "*", not "modified:"
and include parenthesized (function_names):

* libparted/arch/linux.c (_mount_table_search): When we look for
  directory names...

>     /proc/mounts, /proc/swaps and /etc/mtab, there is a possibility to
>     receive none path elements.  Like "none" or "tmpfs".  We are making

Actually, a file named "none" or "tmpfs" *could* exist
in the working directory, so this is a fix, not just an optimization.

ACK.

>     a system call for each of these strings when it can be easily
>     avoided.  This is most noticeable in situations that heavily use
>     libparted, like the fedora installer.
> ---
>  libparted/arch/linux.c |    2 ++
>  1 files changed, 2 insertions(+), 0 deletions(-)
>
> diff --git a/libparted/arch/linux.c b/libparted/arch/linux.c
> index 4a8c9e7..a36017d 100644
> --- a/libparted/arch/linux.c
> +++ b/libparted/arch/linux.c
> @@ -2124,6 +2124,8 @@ _mount_table_search (const char* file_name, dev_t dev)
>                  return 0;
>          while (fgets (line, 512, file)) {
>                  junk = sscanf (line, "%s", part_name);
> +                if (part_name[0] != '/')
> +                        continue;
>                  if (stat (part_name, &part_stat) == 0) {
>                          if (part_stat.st_rdev == dev) {
>                                  fclose (file);



More information about the parted-devel mailing list