From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1IkPlo-0002v1-VD for mharc-grub-devel@gnu.org; Tue, 23 Oct 2007 15:50:33 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IkPlm-0002qe-E9 for grub-devel@gnu.org; Tue, 23 Oct 2007 15:50:30 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IkPlk-0002lv-BJ for grub-devel@gnu.org; Tue, 23 Oct 2007 15:50:29 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IkPlj-0002lS-WD for grub-devel@gnu.org; Tue, 23 Oct 2007 15:50:28 -0400 Received: from mailout04.sul.t-online.de ([194.25.134.18] helo=mailout04.sul.t-online.com) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IkPlj-00053q-2m for grub-devel@gnu.org; Tue, 23 Oct 2007 15:50:27 -0400 Received: from fwd28.aul.t-online.de by mailout04.sul.t-online.com with smtp id 1IkPli-0000H7-00; Tue, 23 Oct 2007 21:50:26 +0200 Received: from [10.3.2.2] (GvA2y+Zl8h4p-lIzqd6DmSAdA+Yk4J7kdsYA80aA4RmF6oxEUK3AR4+PkrvjV0UQST@[217.235.205.199]) by fwd28.aul.t-online.de with esmtp id 1IkPlS-1Xw8um0; Tue, 23 Oct 2007 21:50:10 +0200 Message-ID: <471E5075.9090309@t-online.de> Date: Tue, 23 Oct 2007 21:50:13 +0200 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 Content-Type: multipart/mixed; boundary="------------050204070508000005000907" X-ID: GvA2y+Zl8h4p-lIzqd6DmSAdA+Yk4J7kdsYA80aA4RmF6oxEUK3AR4+PkrvjV0UQST X-TOI-MSGID: 2f29ce9e-8853-427c-b27e-a11e36c41872 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 3) Subject: [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: Tue, 23 Oct 2007 19:50:31 -0000 This is a multi-part message in MIME format. --------------050204070508000005000907 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit This patch enables compilation on systems without the BSD extension dirent.d_type. It relies on #define DT_DIR, won't work for enums (glibc dirent.h contains both :-). An alternative would be to include is_dir() unconditionally and call it also when d_type == DT_UNKNOWN. The patch also fixes a grub-emu crash. Christian 2007-10-23 Christian Franke * util/hostfs.c (is_dir): New function. (grub_hostfs_dir): Handle missing dirent.d_type case. (grub_hostfs_label): Clear label pointer. This fixes a crash of grub-emu on "ls (host)". --------------050204070508000005000907 Content-Type: text/x-patch; name="grub2-hostfs-d_type.patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="grub2-hostfs-d_type.patch" --- grub2.orig/util/hostfs.c 2007-08-02 19:24:06.000000000 +0200 +++ grub2/util/hostfs.c 2007-10-13 17:17:20.000000000 +0200 @@ -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); @@ -101,6 +128,7 @@ static grub_err_t grub_hostfs_label (grub_device_t device __attribute ((unused)), char **label __attribute ((unused))) { + *label = 0; return GRUB_ERR_NONE; } --------------050204070508000005000907--