From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1Io3c3-0006FQ-DB for mharc-grub-devel@gnu.org; Fri, 02 Nov 2007 16:59:31 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Io3c2-0006E6-7o for grub-devel@gnu.org; Fri, 02 Nov 2007 16:59:30 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Io3c1-0006Ce-6Q for grub-devel@gnu.org; Fri, 02 Nov 2007 16:59:29 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Io3c0-0006CL-Pf for grub-devel@gnu.org; Fri, 02 Nov 2007 16:59:28 -0400 Received: from mailout02.sul.t-online.de ([194.25.134.17] helo=mailout02.sul.t-online.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Io3c0-0004iQ-7f for grub-devel@gnu.org; Fri, 02 Nov 2007 16:59:28 -0400 Received: from fwd26.aul.t-online.de by mailout02.sul.t-online.com with smtp id 1Io3by-0006ru-00; Fri, 02 Nov 2007 21:59:26 +0100 Received: from [10.3.2.2] (XRxH0EZXQhUnCyafOxiNGtc5ppz7SKtje250xpeE4VoxaRGTsCUWE5RYp6Kw78NgN1@[217.235.196.19]) by fwd26.aul.t-online.de with esmtp id 1Io3bq-0l4f6O0; Fri, 2 Nov 2007 21:59:18 +0100 Message-ID: <472B8FA5.5030400@t-online.de> Date: Fri, 02 Nov 2007 21:59:17 +0100 From: Christian Franke User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.6) Gecko/20070802 SeaMonkey/1.1.4 MIME-Version: 1.0 To: grub-devel@gnu.org References: <471E5075.9090309@t-online.de> In-Reply-To: <471E5075.9090309@t-online.de> Content-Type: multipart/mixed; boundary="------------090307030809040204040106" X-ID: XRxH0EZXQhUnCyafOxiNGtc5ppz7SKtje250xpeE4VoxaRGTsCUWE5RYp6Kw78NgN1 X-TOI-MSGID: 7a755416-6654-42ba-a6bd-d74b7f639107 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: Re: [PATCH] Allow build without dirent.d_type, fix "ls (host)" crash X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list Reply-To: The development of GRUB 2 List-Id: The development of GRUB 2 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 02 Nov 2007 20:59:30 -0000 This is a multi-part message in MIME format. --------------090307030809040204040106 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Second version of the patch. It fixes another bug: missing fseek() in grub_hostfs_read(). Christian 2007-11-02 Christian Franke * 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)". --------------090307030809040204040106 Content-Type: text/x-patch; name="grub2-hostfs-d_type-2.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-hostfs-d_type-2.patch" --- 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 #include + +#ifndef DT_DIR +/* dirent.d_type is a BSD extension, not part of POSIX */ +#include +#include + +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; } --------------090307030809040204040106--