From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1IqVFw-00022u-9W for mharc-grub-devel@gnu.org; Fri, 09 Nov 2007 09:54:48 -0500 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1IqVFv-00022P-0U for grub-devel@gnu.org; Fri, 09 Nov 2007 09:54:47 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1IqVFu-000221-DD for grub-devel@gnu.org; Fri, 09 Nov 2007 09:54:46 -0500 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1IqVFu-00021v-3c for grub-devel@gnu.org; Fri, 09 Nov 2007 09:54:46 -0500 Received: from smtp-vbr6.xs4all.nl ([194.109.24.26]) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1IqVFt-0006g1-IW for grub-devel@gnu.org; Fri, 09 Nov 2007 09:54:45 -0500 Received: from localhost.localdomain (249-174.surfsnel.dsl.internl.net [145.99.174.249]) by smtp-vbr6.xs4all.nl (8.13.8/8.13.8) with ESMTP id lA9EsfGI059031 for ; Fri, 9 Nov 2007 15:54:42 +0100 (CET) (envelope-from mgerards@xs4all.nl) From: Marco Gerards To: The development of GRUB 2 References: <471E5075.9090309@t-online.de> <472B8FA5.5030400@t-online.de> Mail-Copies-To: mgerards@xs4all.nl Date: Fri, 09 Nov 2007 15:55:13 +0100 In-Reply-To: <472B8FA5.5030400@t-online.de> (Christian Franke's message of "Fri, 02 Nov 2007 21:59:17 +0100") Message-ID: <874pfvmpta.fsf@xs4all.nl> User-Agent: Gnus/5.110006 (No Gnus v0.6) Emacs/21.4 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by XS4ALL Virus Scanner X-detected-kernel: by monty-python.gnu.org: FreeBSD 4.6-4.9 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, 09 Nov 2007 14:54:47 -0000 Christian Franke writes: > 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)". > > > > --- 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) is_dir ( > +{ > + int len1 = strlen(path), len2 = strlen(name); Please split this up. Or even better use separate declarations and code. > + char pathname[len1+1+len2+1+13]; Please add spaces around binary operators. > + struct stat st; > + strcpy (pathname, path); Please add more blank lines between your code to make it easier to read. :-) > + /* Avoid UNC-path "//name" on Cygwin */ ". " like explained in a previous email. > + if (len1 > 0 && pathname[len1-1] != '/') > + strcat (pathname, "/"); > + strcat (pathname, name); > + if (stat (pathname, &st)) > + return 0; > + return S_ISDIR(st.st_mode); > +} > +#endif Why can't you just use S_ISDIR? > 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); "int s = " > 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; > } > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > http://lists.gnu.org/mailman/listinfo/grub-devel