All of lore.kernel.org
 help / color / mirror / Atom feed
From: Christian Franke <Christian.Franke@t-online.de>
To: grub-devel@gnu.org
Subject: Re: [PATCH] Allow build without dirent.d_type, fix "ls (host)" crash
Date: Fri, 02 Nov 2007 21:59:17 +0100	[thread overview]
Message-ID: <472B8FA5.5030400@t-online.de> (raw)
In-Reply-To: <471E5075.9090309@t-online.de>

[-- Attachment #1: Type: text/plain, Size: 389 bytes --]

Second version of the patch.

It fixes another bug: missing fseek() in grub_hostfs_read().

Christian

2007-11-02  Christian Franke  <franke@computer.org>

	* util/hostfs.c (is_dir): New function.
	(grub_hostfs_dir):  Handle missing dirent.d_type case.
	(grub_hostfs_read): Add missing fseek().
	(grub_hostfs_label): Clear label pointer. This fixes a crash
	of grub-emu on "ls (host)".




[-- Attachment #2: grub2-hostfs-d_type-2.patch --]
[-- Type: text/x-patch, Size: 1489 bytes --]

--- grub2.orig/util/hostfs.c	2007-08-02 19:24:06.000000000 +0200
+++ grub2/util/hostfs.c	2007-11-02 21:31:37.703125000 +0100
@@ -25,6 +25,29 @@
 #include <dirent.h>
 #include <stdio.h>
 
+
+#ifndef DT_DIR
+/* dirent.d_type is a BSD extension, not part of POSIX */
+#include <sys/stat.h>
+#include <string.h>
+
+static int
+is_dir(const char *path, const char *name)
+{
+  int len1 = strlen(path), len2 = strlen(name);
+  char pathname[len1+1+len2+1+13];
+  struct stat st;
+  strcpy (pathname, path);
+  /* Avoid UNC-path "//name" on Cygwin */
+  if (len1 > 0 && pathname[len1-1] != '/')
+    strcat (pathname, "/");
+  strcat (pathname, name);
+  if (stat (pathname, &st))
+    return 0;
+  return S_ISDIR(st.st_mode);
+}
+#endif
+
 static grub_err_t
 grub_hostfs_dir (grub_device_t device, const char *path, 
 		 int (*hook) (const char *filename, int dir))
@@ -48,7 +71,11 @@ grub_hostfs_dir (grub_device_t device, c
       if (! de)
 	break;
 
+#ifdef DT_DIR
       hook (de->d_name, de->d_type == DT_DIR);
+#else
+      hook (de->d_name, is_dir(path, de->d_name));
+#endif
     }
 
   closedir (dir);
@@ -81,6 +108,7 @@ grub_hostfs_read (grub_file_t file, char
   FILE *f;
 
   f = (FILE *) file->data;
+  fseek (f, file->offset, SEEK_SET);
   int s= fread (buf, 1, len, f);
 
   return s;
@@ -101,6 +129,7 @@ static grub_err_t
 grub_hostfs_label (grub_device_t device __attribute ((unused)),
 		   char **label __attribute ((unused)))
 {
+  *label = 0;
   return GRUB_ERR_NONE;
 }
 

  reply	other threads:[~2007-11-02 20:59 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-10-23 19:50 [PATCH] Allow build without dirent.d_type, fix "ls (host)" crash Christian Franke
2007-11-02 20:59 ` Christian Franke [this message]
2007-11-09 14:55   ` Marco Gerards
2007-11-09 21:06     ` Christian Franke
2007-11-10 16:03       ` Marco Gerards
2007-11-10 18:16         ` Christian Franke
2007-11-18  7:14         ` Robert Millan

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=472B8FA5.5030400@t-online.de \
    --to=christian.franke@t-online.de \
    --cc=grub-devel@gnu.org \
    /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.