From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.33) id 1BttEg-0007oq-03 for mharc-grub-devel@gnu.org; Sun, 08 Aug 2004 15:21:38 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BttEe-0007oK-Rf for grub-devel@gnu.org; Sun, 08 Aug 2004 15:21:36 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BttEe-0007na-1j for grub-devel@gnu.org; Sun, 08 Aug 2004 15:21:36 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BttEd-0007nX-UD for grub-devel@gnu.org; Sun, 08 Aug 2004 15:21:35 -0400 Received: from [212.43.237.68] (helo=kotoba.storever.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BttAs-00069P-BU for grub-devel@gnu.org; Sun, 08 Aug 2004 15:17:42 -0400 Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by kotoba.storever.com (Postfix) with ESMTP id C56C7F0D47A2 for ; Sun, 8 Aug 2004 15:17:41 -0400 (EDT) From: "Yoshinori K. Okuji" Organization: enbug.org To: The development of GRUB 2 Date: Sun, 8 Aug 2004 21:17:56 +0200 User-Agent: KMail/1.6.1 References: <20040808173040.GA11531@artax.karlin.mff.cuni.cz> <87smaxldbe.fsf@marco.marco-g.com> <20040808181720.GA14939@artax.karlin.mff.cuni.cz> In-Reply-To: <20040808181720.GA14939@artax.karlin.mff.cuni.cz> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Message-Id: <200408082117.56911.okuji@enbug.org> Subject: Re: bugfix, hostfs 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: Sun, 08 Aug 2004 19:21:37 -0000 On Sunday 08 August 2004 20:17, Tomas Ebenlendr wrote: > > > +#ifndef GRUB_UTIL > > > +#error cannot live outside host fs > > > +#endif > > > > I think there is no need to do this. > > Maybe. I'm just used to write in files that shouldn't be ported to > other "parts" of software that they can't be ported. It is a good idea. But the indentation is not appropriate. It should be: #ifndef GRUB_UTIL # error cannot live outside host fs #endif > > > + if ((signed) device->disk->id !=3D -2) { > > > > What is -2? > > Oh, sorry. Just a magic constant. Probably there should be better > identification (e.g. magic device->disk->data (e.g. device->disk =3D=3D > device->disk->data)). This identification is used in hostfs_mount() Probably the id is a problem on Open Firmware potentially, since Marco=20 used phandlers for disk ids and phandlers can be anything in theory. I bet that I made a mistake in the design of struct grub_disk. I thought=20 it would be easy to find an identifier because the size of an id is=20 4-byte. But this assumption breaks on Open Firmware. So perhaps we=20 should add one more id for the type of a disk, so that we can write=20 this kind of code: (include/grub/disk.h) enum grub_disk_class_id { GRUB_DISK_CLASS_IEEE1275_ID, GRUB_DISK_CLASS_PCBIOS_ID, GRUB_DISK_CLASS_HOST_ID, }; (disk/powerpc/ieee1275/ofdisk.c) disk->class_id =3D GRUB_DISK_CLASS_IEEE1275_ID; disk->id =3D phandler; Then you can use this: disk->class_id =3D GRUB_DISK_CLASS_HOST_ID; disk->id =3D 0; This requires some changes in the cache manager, but not difficult. What=20 do you think? > > > + grub_strncpy(pathbuf,path,/*FIXME*/2048 - 1); > > > > Why do you use pathbuf? Can't you just use path directly? If that > > is not possible use MAX_PATH_LEN here when it is defined and > > dynamic memory allocation otherwise (when there is no limit). > > I concatenate path of directory and its entries to stat them. I will > use the MAX_PATH_LEN. I only forgot that I forgot the name of this > constant. (Uh). You should not use MAX_PATH_LEN if not defined, otherwise you code won't=20 work well on GNU/Hurd. The right way is to allocate memory dynamically=20 for PATHBUF: static grub_err_t grub_host_dir (grub_device_t device, const char *path, =A0=A0=A0=A0=A0=A0=A0 =A0 =A0 =A0 int (*hook) (const char *filename, int d= ir)) { =A0DIR * dir; =A0struct dirent * dent; =A0struct stat stent; =A0char *pathbuf; unsigned dir_len; unsigned entry_max_len; =A0char *ename; =A0if (host_mount(device)) return grub_errno; =A0 =A0dir =3D opendir(path); =A0if (dir =3D=3D 0) =A0 =A0return errno2err(); dir_len =3D grub_strlen (path) entry_max_len =3D 32; /* Sifficient as the initial value. */ pathbuf =3D grub_malloc (dir_len + entry_max_len + 1); if (! pathbuf) goto fail; =A0grub_strcpy(pathbuf, path); if (pathbuf[dir_len - 1] !=3D '/') { pathbuf[dir_len - 1] =3D '/'; pathbuf[dir_len] =3D '\0'; dir_len++; entry_max_len--; } ename =3D pathbuf + dir_len; =A0while ((dent =3D readdir (dir)) !=3D 0) =A0 =A0{ if (grub_strlen (dent->d_name) > entry_max_len) { entry_max_len =3D grub_strlen (dent->d_name); pathbuf =3D grub_realloc (pathbuf, dir_len + entry_max_len + 1); if (! pathbuf) goto fail; } =A0 =A0 =A0grub_strcpy(ename, dent->d_name); =A0 =A0 =A0lstat(pathbuf, &stent); =A0 =A0 =A0hook (dent->d_name, (stent.st_mode & S_IFMT) =3D=3D S_IFDIR); =A0 =A0} fail: grub_free (pathbuf); closedir (dir); =A0return grub_errno; } BTW, do you have an account on Savannah? If you have, let me know. I can=20 give you a write permission for the CVS. Regards, Okuji