Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KUYwu-0002M0-Rm for mharc-grub-devel@gnu.org; Sat, 16 Aug 2008 23:29:00 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KUYws-0002L8-BS for grub-devel@gnu.org; Sat, 16 Aug 2008 23:28:58 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KUYwq-0002KD-8A for grub-devel@gnu.org; Sat, 16 Aug 2008 23:28:57 -0400 Received: from [199.232.76.173] (port=42952 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KUYwp-0002K4-Ve for grub-devel@gnu.org; Sat, 16 Aug 2008 23:28:56 -0400 Received: from m5-82.163.com ([202.108.5.82]:54782) by monty-python.gnu.org with smtp (Exim 4.60) (envelope-from ) id 1KUYwn-00063F-K0 for grub-devel@gnu.org; Sat, 16 Aug 2008 23:28:55 -0400 Received: from hp2003 (unknown [221.219.27.49]) by smtp2 (Coremail) with SMTP id DNGowLBbRwpKkKdIz9KbDw==.22645S2; Sun, 17 Aug 2008 10:43:23 +0800 (CST) Message-ID: <5BACA85F3C9C449AA54CC447C1E5D61D@hp2003> From: "y.volta" To: References: <48A6FA9A.45473C.07156@m12-70.163.com> Date: Sun, 17 Aug 2008 10:43:25 +0800 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0020_01C90056.13B66DC0" X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.3790.3959 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.4325 X-Coremail-Antispam: 1Uf129KBjvJXoW7Cr1fXF47Jr1kKF4kZF13urg_yoW8Gw4kpa n3Jr13trWDJw4UJrnrur17JF48J3yUtrWDJFy5Zr1xAr1Yyr1Iq3WxtFyrAa48Xry3JF1U Zr4UWrW7JryDA3DanT9S1TB71UUUUUUv73VFW2AGmfu7bjvjm3AaLaJ3UjIYCTnIWjp_UU U0r7k0a2IF6r1UM7kC6x804xWl14x267AKxVWUJVW8JwAFxVCF77xC6IxKo4kEV4yl1I0E scIYIxCEI4klw4CSwwAFIxvE14AKwVWUJVWUGwASzI0EjI02j7AqF2xKxwAqx4xG64xvF2 IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jr0_Jr4lYx0Ex4A2jsIE14v26r1j6r4U M4xvF2IEb7IF0Fy264kE64k0F24lFcxC0VAYjxAxZF0Ex2IqxwAC62BYpTIE1TZKA3svLV AKvSnIqfZI6r4lFVCF04k20xvEw2I207IF0wCjxxvEw4Wlc7Ca8VAvwVCjb41lc7Ca8VAv wVCFzxkY4VCF77xAMxkI7II2jI8vz4vEwIxGrwCF72vE52k0Y41lx4CE17CEb7AF67AKxV WUJVWUXwCE64xvF2IEb7IF0Fy7YxBIdaVFxhVjvjDU0xZFpf9x07UciSLUUUUU= X-detected-kernel: by monty-python.gnu.org: Linux 2.6, seldom 2.4 (older, 4) X-Greylist: delayed 2720 seconds by postgrey-1.27 at monty-python; Sat, 16 Aug 2008 23:28:49 EDT Subject: [PATCH] romfs support for Grub2 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, 17 Aug 2008 03:28:58 -0000 This is a multi-part message in MIME format. ------=_NextPart_000_0020_01C90056.13B66DC0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: base64 SGksDQoNCiAgICBJIG1hZGUgYSBzbWFsbCBwYXRjaCBmb3IgZ3J1YjIgdXNpbmcgIGEgcm9tZnMg ZmlsZSAoIHppcCBjb21wcmVzc2luZyBzdXBwb3J0ICkuIHRoZXJlIGFyZSAzIGZpbGVzIGFkZGVk Og0KDQotL2NvbW1hbmRzL2kzODYvcGMvcm9tZnN0LmMgICAgICAgICAgICAgICAgICAgICAgICAg ICAgICAgICBjb21tYW5kIHRvIG1vdW50IGEgcm9tZnMgaW1hZ2UgZmlsZS4NCi0vZnMvaTM4Ni9w Yy9yb21mcy5jICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAg IGZzIGFuZCBkaXNrIGxheWVyIGZvciByb21mcy4NCi0vaW5jbHVkZS9ncnViL2kzODYvcGMvcm9t ZnMuaCAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIGhlYWRlciBmaWxlLg0KDQp1c2Fn ZTogICAgDQpncnViPnJvbWZzdCAvcm9tZnMuZ3oNCmdydWI+Y2F0IChyZCkvcmVhZG1lLnR4dA0K DQppbmZvDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0NCmkgbWFrZSB0aGlzIHBhdGNoIGhhdmUgdHdvIHJlc291cmNlczogdGhlIGdy dWIgbGVnYW5jeSByb21mcyBwYXRjaCBhbmQgdGhlIGJlYW4ncyBweGUgcGF0Y2guIA0KaSBnZXQg dG8ga25vdyB0aGUgcHhlIG1vZCBtZXJnZWQgdGhlIGRpc2smZnMgaW50byBhIGZzIHNvdXJjZSBm aWxlLiB0aGlzIHdpbGwgbWFrZSBtb2QgbW9yZSBzaW1wbGUgdG8gaW1wbGVtZW50Lg0KdGhlIHJv bWZzdCBjb21tYW5kIHdpbGwgbG9hZCB0aGUgc3BlY2lmeSBmaWxlIHRvIGEgbmV3IG1lbW9yeSBi bG9jay4gd2hlbiB1c2VyIGFjY2VzcyAocmQpLCB0aGUgbmV3IGZpbGVzIGFyZSByZWFkeSBmb3Ig aGltLg0KDQoNCmxpbWl0YXRpb25zDQotLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0t LS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0NCiogdGhpcyBwYXRjaCBpcyBmb3IgZmlsZSBvbmx5 OiBpZiB5b3Ugd2FudCB0byB1c2UgaXQgb24gYSBkaXNrL3BhcnRpdGlvbiwgd2Ugc2hvdWxkIGlt cHJvdmUgaXQuDQoqIGdydWJfcm9tZnNfZGF0YSAqZGF0YSwgaGFzIG5vdCBzZXQgdG8gZmlsZS0+ ZGF0YSAtIGkgdXNlZCBzZXZlcmFsIGdsb2JhbCB2YXJpYmxlcyB0byBzdG9yZSByZWxlYXRlZCBz dHVmZnMuDQoNCg0Kd2VsbCwgdGhpcyBpcyBqdXN0IGEgd29yay1hYmxlIHBhdGNoLCBub3QgdG9v IHByb2Zlc3Npb25hbC4gOy0pDQoNCmJ0dywgaSB0aGluayB0aGUgZ3J1Yl9kcHJpbnRmIHNob3Vs ZCBvdXRwdXQgdG8gbm9uLWRpc3BsYXkgZGV2aWNlLCB0aGlzIHdpbGwgbWFrZSBkZWJ1Z2luZyBt b3JlIGVhc2llciBhbmQgY29tZm9ydCAuIGkgdGhpbmsgdGhlIGxvdy1jb3N0IGRldmljZSBpcyBh IGNvbS1wb3J0LiBmb3IsIG5vdyB0aW1lIHZpcnR1YWwgbWFjaGluZSBzb2Z0d2FyZSBoYXMgdGhp cyBsZWdhbmN5IGRldmljZSBmdWxsIHN1cHBvcnRlZC4NCnRoZSBmcmVlbGRyIGNvbWluZyB3aXRo IFJlYWN0T1MgaGF2ZSB0aGlzIGtpbmQgb2YgZnVuY3Rpb24gKG9ubHkgZGlzcGxheSBhIHN0cmlu ZywgYnV0IGNhbiBkbyBrZXJuYWwgZGVidWcgYWxzbyApDQoNCnkudm9sdGENCiA= ------=_NextPart_000_0020_01C90056.13B66DC0 Content-Type: application/octet-stream; name="rev_1813.romfs.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="rev_1813.romfs.patch" diff -ruNa grub2/commands/i386/pc/romfst.c = grub2_romfs/commands/i386/pc/romfst.c=0A= --- grub2/commands/i386/pc/romfst.c 1970-01-01 08:00:00.000000000 +0800=0A= +++ grub2_romfs/commands/i386/pc/romfst.c 2008-08-17 09:14:15.000000000 = +0800=0A= @@ -0,0 +1,111 @@=0A= +/* romfst.c -- init a romfs from a disk file. */=0A= +/*=0A= + * GRUB -- GRand Unified Bootloader=0A= + * Copyright (C) 2008 Free Software Foundation, Inc.=0A= + *=0A= + * GRUB is free software: you can redistribute it and/or modify=0A= + * it under the terms of the GNU General Public License as published by=0A= + * the Free Software Foundation, either version 3 of the License, or=0A= + * (at your option) any later version.=0A= + *=0A= + * GRUB is distributed in the hope that it will be useful,=0A= + * but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= + * GNU General Public License for more details.=0A= + *=0A= + * You should have received a copy of the GNU General Public License=0A= + * along with GRUB. If not, see .=0A= + */=0A= +=0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +=0A= +=0A= +static grub_err_t=0A= +grub_cmd_romfst (struct grub_arg_list *state __attribute__ ((unused)), = int argc,=0A= + char **args)=0A= +{=0A= + grub_file_t file;=0A= + char chHead[8];=0A= +=0A= + DBG_MSG ("\n\n ------- romfst get in. ----------\n");=0A= +=0A= + /* check for existence of this file */=0A= + if (argc !=3D 1)=0A= + return grub_error (GRUB_ERR_BAD_ARGUMENT, "file name required");=0A= +=0A= + file =3D grub_gzfile_open (args[0], 1);=0A= + if (! file)=0A= + return 0;=0A= + =0A= + /* check for "-romfs-" */=0A= + if (grub_file_read (file, chHead, 8) !=3D 8)=0A= + {=0A= + grub_file_close ( file );=0A= + return grub_error(GRUB_ERR_FILE_READ_ERROR, "read file header = failed");=0A= + }=0A= +=0A= + DBG_MSG ("\t seek to begin.\n");=0A= + grub_file_seek (file, 0);=0A= + =0A= + if(grub_memcmp(chHead, "-rom1fs-", 8) !=3D0)=0A= + {=0A= + grub_file_close( file );=0A= + return grub_error(GRUB_ERR_UNKNOWN_FS, "not a valid romfs");=0A= + }=0A= +=0A= + DBG_MSG ("\t file header verified.\n");=0A= + =0A= + /* reset the basic romfs information */=0A= + if (romdisk_addr)=0A= + grub_free (romdisk_addr);=0A= +=0A= + romdisk_size =3D 0;=0A= +=0A= + DBG_MSG ("\t malloc the romdisk_addr.\n");=0A= +=0A= + /* prepare the memory */=0A= + romdisk_addr =3D grub_malloc (grub_file_size(file));=0A= + if (!romdisk_addr)=0A= + {=0A= + grub_file_close(file);=0A= + return grub_error (GRUB_ERR_OUT_OF_MEMORY, "romfs base memory = alloc failed");=0A= + }=0A= +=0A= + romdisk_size =3D grub_file_size(file);=0A= +=0A= + /* read this all */=0A= + grub_file_read (file, romdisk_addr, romdisk_size);=0A= + grub_file_close(file);=0A= +=0A= + DBG_MSG ("\t load this file whole.\n");=0A= +=0A= + /* O.K. reinit this disk */=0A= + re_init_romdisk ();=0A= +=0A= + DBG_MSG ("\t romfs re-inited..\n");=0A= +=0A= + return grub_errno;=0A= +}=0A= +=0A= +=0A= +=0C=0A= +GRUB_MOD_INIT(romfst)=0A= +{=0A= + (void)mod; /* To stop warning. */=0A= + grub_register_command ("romfst", grub_cmd_romfst, = GRUB_COMMAND_FLAG_BOTH,=0A= + "romfst FILE", "Init romfs from a file", 0);=0A= +}=0A= +=0A= +GRUB_MOD_FINI(romfst)=0A= +{=0A= + grub_unregister_command ("romfst");=0A= +}=0A= diff -ruNa grub2/conf/i386-pc.rmk grub2_romfs/conf/i386-pc.rmk=0A= --- grub2/conf/i386-pc.rmk 2008-08-17 09:17:30.000000000 +0800=0A= +++ grub2_romfs/conf/i386-pc.rmk 2008-08-17 09:05:52.000000000 +0800=0A= @@ -164,7 +164,7 @@=0A= videotest.mod play.mod bitmap.mod tga.mod cpuid.mod serial.mod \=0A= ata.mod vga.mod memdisk.mod jpeg.mod png.mod pci.mod lspci.mod \=0A= aout.mod _bsd.mod bsd.mod pxe.mod pxecmd.mod datetime.mod date.mod \=0A= - datehook.mod=0A= + datehook.mod romfst.mod romfs.mod=0A= =0A= # For biosdisk.mod.=0A= biosdisk_mod_SOURCES =3D disk/i386/pc/biosdisk.c=0A= @@ -356,4 +356,14 @@=0A= datehook_mod_CFLAGS =3D $(COMMON_CFLAGS)=0A= datehook_mod_LDFLAGS =3D $(COMMON_LDFLAGS)=0A= =0A= +# For romfs.mod.=0A= +romfs_mod_SOURCES =3D fs/i386/pc/romfs.c=0A= +romfs_mod_CFLAGS =3D $(COMMON_CFLAGS)=0A= +romfs_mod_LDFLAGS =3D $(COMMON_LDFLAGS)=0A= +=0A= +# For romfst.mod.=0A= +romfst_mod_SOURCES =3D commands/i386/pc/romfst.c=0A= +romfst_mod_CFLAGS =3D $(COMMON_CFLAGS)=0A= +romfst_mod_LDFLAGS =3D $(COMMON_LDFLAGS)=0A= +=0A= include $(srcdir)/conf/common.mk=0A= diff -ruNa grub2/fs/i386/pc/romfs.c grub2_romfs/fs/i386/pc/romfs.c=0A= --- grub2/fs/i386/pc/romfs.c 1970-01-01 08:00:00.000000000 +0800=0A= +++ grub2_romfs/fs/i386/pc/romfs.c 2008-08-17 09:13:27.000000000 +0800=0A= @@ -0,0 +1,653 @@=0A= +/* romfs.c - rom filesystem and romdisk layer. */=0A= +/*=0A= + * GRUB -- GRand Unified Bootloader=0A= + * Copyright (C) 2008 Free Software Foundation, Inc.=0A= + *=0A= + * This program is free software: you can redistribute it and/or modify=0A= + * it under the terms of the GNU General Public License as published by=0A= + * the Free Software Foundation, either version 3 of the License, or=0A= + * (at your option) any later version.=0A= + *=0A= + * This program is distributed in the hope that it will be useful,=0A= + * but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= + * GNU General Public License for more details.=0A= + *=0A= + * You should have received a copy of the GNU General Public License=0A= + * along with this program. If not, see = .=0A= + */=0A= +=0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +#include =0A= +=0A= +=0A= +struct grub_romfs_data=0A= +{=0A= + grub_disk_t disk;=0A= + =0A= + char *plabel; /* volume name */=0A= +=0A= + grub_uint32_t rootdir_offset; /* root offset */=0A= + =0A= + grub_uint32_t dir_offset; /* dir offset */=0A= +=0A= + grub_uint32_t filesize; /* file size */=0A= +=0A= + grub_uint32_t file_type; /* object type: dir, file, ... */=0A= +=0A= +};=0A= +=0A= +=0A= +/* internal buffer for block using */=0A= +char blk_buf[GRUB_DISK_SECTOR_SIZE] =3D {0};=0A= +=0A= +/* file data offset to load */=0A= +grub_uint32_t file_offset; /* file data offset */=0A= +=0A= +/* romfs memory data start address */=0A= +char *romdisk_addr =3D 0;=0A= +grub_off_t romdisk_size =3D 0;=0A= +=0A= +=0A= +/* made up, these are pointers into blk_buf, 512 bytes is enough for = internal use */=0A= +/* read once, always stays there: */=0A= +#define SUPERBLOCK \=0A= + ((struct romfs_super_block *)(blk_buf))=0A= +#define INODE \=0A= + ((struct romfs_inode *)((int)SUPERBLOCK + sizeof(struct = romfs_super_block)))=0A= +=0A= +=0A= +#ifndef GRUB_UTIL=0A= +static grub_dl_t my_mod;=0A= +#endif=0A= +=0A= +static inline /*__const__*/ grub_uint32_t=0A= +le32 (grub_uint32_t x)=0A= +{=0A= +#if 0=0A= + /* 386 doesn't have bswap. */=0A= + __asm__("bswap %0" : "=3Dr" (x) : "0" (x));=0A= +#else=0A= + /* This is slower but this works on all x86 architectures. */=0A= + __asm__("xchgb %b0, %h0" \=0A= + "\n\troll $16, %0" \=0A= + "\n\txchgb %b0, %h0" \=0A= + : "=3Dq" (x) : "0" (x));=0A= +#endif=0A= + return x;=0A= +}=0A= +=0A= +static int=0A= +//romfs_devread (int sector, int byte_offset, int byte_len, unsigned = char *buf)=0A= +romfs_devread (grub_uint32_t offset, int byte_len, unsigned char *buf)=0A= +{ =0A= + /* range check */=0A= + if ( offset + byte_len > romdisk_size )=0A= + {=0A= + grub_error (GRUB_ERR_OUT_OF_RANGE, "romfs_devread out of range");=0A= + return 0;=0A= + }=0A= +=0A= + grub_memmove(buf, romdisk_addr + offset, byte_len);=0A= +=0A= + return 1;=0A= +}=0A= +=0A= +=0A= +static int =0A= +find_string_len(unsigned char *buf, grub_uint32_t offset) =0A= +{=0A= + int i=3D0;=0A= +=0A= + int ix;=0A= + /* all strings are nul-padded to even 16 bytes */=0A= + do =0A= + {=0A= + ix =3D i << 4;=0A= +// romfs_devread ( (offset+i*16) / GRUB_DISK_SECTOR_SIZE,=0A= +// (offset+i*16) % GRUB_DISK_SECTOR_SIZE,=0A= +// 16, buf+(i*16));=0A= + =0A= + romfs_devread (offset + ix, 16, buf + ix);=0A= +=0A= + /* grub_dprintf("reading name, i=3D%d, buf=3D%s\n", i, buf); */=0A= +=0A= + i++;=0A= + } while (buf[i*16-1] !=3D '\0');=0A= +=0A= + return i*16;=0A= +}=0A= +=0A= +/* return disk offset of file data. */=0A= +static int =0A= +load_inode (int offset) =0A= +{=0A= + int namelen;=0A= + DBG_MSG (" load_inode at %d.\n", offset);=0A= + =0A= + romfs_devread (offset, sizeof(*INODE)+16, (unsigned char*)INODE);=0A= +=0A= + INODE->next =3D le32(INODE->next); /* grub_cpu_to_le32 */=0A= + INODE->spec =3D le32(INODE->spec);=0A= + INODE->size =3D le32(INODE->size);=0A= + INODE->checksum =3D le32(INODE->checksum);=0A= +=0A= + namelen =3D find_string_len(((unsigned char*)INODE)+sizeof(*INODE),=0A= + offset+16);=0A= +=0A= + /* grub_printf(" name=3D%s\n", INODE->name); */=0A= +=0A= + return offset+16+namelen;=0A= +}=0A= +=0A= +=0A= +static int=0A= +grub_romdisk_iterate (int (*hook) (const char *name))=0A= +{=0A= + DBG_MSG ("dbg: grub_romdisk_iterate().++\n");=0A= +=0A= + if (hook ("rd"))=0A= + return 1;=0A= + return 0;=0A= +}=0A= +=0A= +static grub_err_t=0A= +grub_romdisk_open (const char *name, grub_disk_t disk)=0A= +{=0A= + DBG_MSG ("dbg: grub_romdisk_open(%s).++\n", name);=0A= +=0A= + if (grub_strcmp (name, "rd"))=0A= + {=0A= + DBG_MSG ("\t %s. not a rd disk.\n", name);=0A= + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a romdisk");=0A= + }=0A= +=0A= + DBG_MSG ("\t %s. is a rd disk.\n", name);=0A= +=0A= + disk->total_sectors =3D 0; /* romdisk_size / GRUB_DISK_SECTOR_SIZE; */=0A= + disk->id =3D (unsigned long) "rd";=0A= + disk->has_partitions =3D 0;=0A= + disk->data =3D 0;=0A= +=0A= + return GRUB_ERR_NONE;=0A= +}=0A= +=0A= +=0A= +static void=0A= +grub_romdisk_close (grub_disk_t disk __attribute((unused)))=0A= +{=0A= + DBG_MSG ("dbg: grub_romdisk_close().++\n");=0A= +}=0A= +=0A= +static grub_err_t=0A= +grub_romdisk_read (grub_disk_t disk __attribute((unused)), = grub_disk_addr_t sector,=0A= + grub_size_t size, char *buf)=0A= +{=0A= + DBG_MSG ("dbg: grub_romdisk_read().++\n");=0A= +=0A= + grub_memcpy (buf, romdisk_addr + (sector << GRUB_DISK_SECTOR_BITS), = size << GRUB_DISK_SECTOR_BITS);=0A= + return 0;=0A= +}=0A= +=0A= +static grub_err_t=0A= +grub_romdisk_write (grub_disk_t disk __attribute((unused)), = grub_disk_addr_t sector,=0A= + grub_size_t size, const char *buf)=0A= +{=0A= + DBG_MSG ("dbg: grub_romdisk_write().++\n");=0A= +=0A= + /* romdisk is read-only disk. */=0A= + grub_error (GRUB_ERR_WRITE_ERROR, "romdisk is read only");=0A= + return 0;=0A= +}=0A= +=0A= +static struct grub_disk_dev grub_romdisk_dev =3D=0A= +{=0A= + .name =3D "rd",=0A= + .id =3D GRUB_DISK_DEVICE_ROMDISK_ID,=0A= + .iterate =3D grub_romdisk_iterate,=0A= + .open =3D grub_romdisk_open,=0A= + .close =3D grub_romdisk_close,=0A= + .read =3D grub_romdisk_read,=0A= + .write =3D grub_romdisk_write,=0A= + .next =3D 0=0A= +};=0A= +=0A= +static struct grub_romfs_data *=0A= +grub_romfs_mount (grub_disk_t disk)=0A= +{=0A= + DBG_MSG (" grub_romfs_mount()++. \n");=0A= +=0A= + int vollen =3D 0;=0A= + struct grub_romfs_data *data;=0A= +=0A= + /* read the super block */=0A= + if (!romfs_devread (0, =0A= + sizeof (struct romfs_super_block),=0A= + (unsigned char *) SUPERBLOCK))=0A= + {=0A= + grub_print_error();=0A= + DBG_MSG (" \t grub_disk_read() failed.\n");=0A= + goto fail; =0A= + }=0A= +=0A= + /* check the "-romfs-" header */=0A= + if (SUPERBLOCK->word0 !=3D 0x6d6f722d=0A= + || SUPERBLOCK->word1 !=3D 0x2d736631 )=0A= + {=0A= + DBG_MSG (" \t check header failed.\n");=0A= + goto fail;=0A= + }=0A= +=0A= + grub_errno =3D GRUB_ERR_NONE;=0A= + data =3D (struct grub_romfs_data *) grub_malloc (sizeof (*data));=0A= + if (!data)=0A= + {=0A= + DBG_MSG (" \t malloc romfs data failed.\n");=0A= + goto fail;=0A= + }=0A= + grub_memset (data, 0x0, sizeof (struct grub_romfs_data));=0A= +=0A= + data->disk =3D disk;=0A= + data->plabel =3D (char *)&SUPERBLOCK->name;=0A= +=0A= + vollen =3D find_string_len((unsigned char *)&SUPERBLOCK->name, 16);=0A= + data ->rootdir_offset =3D 16 + vollen;=0A= + DBG_MSG (" \t rootdir_offset =3D %d.\n", data ->rootdir_offset);=0A= +=0A= + return data;=0A= +=0A= +fail:=0A= + grub_error (GRUB_ERR_BAD_FS, "not a romfs filesystem");=0A= + return 0;=0A= +}=0A= +=0A= +=0A= +int grub_stricmp(const char *string1, const char *string2)=0A= +{=0A= + while(grub_tolower(*string1) =3D=3D grub_tolower(*string2))=0A= + {=0A= + if(*string1 =3D=3D 0)=0A= + return 0;=0A= +=0A= + string1++;=0A= + string2++;=0A= + }=0A= +=0A= + return (int)grub_tolower(*string1) - (int)grub_tolower(*string2);=0A= +}=0A= +=0A= +=0A= +static char *=0A= +grub_find_dir (char *path, struct grub_romfs_data *data,=0A= + int (*hook) (const char *filename, int dir))=0A= +{=0A= + char *rest;=0A= + char ch;=0A= + int dir_nofound;=0A= + int call_hook =3D 0;=0A= + int dir_offset =3D 0;=0A= + unsigned int pathlen;=0A= +=0A= + DBG_MSG (" grub_find_dir()++.\n");=0A= +=0A= + if ( hook )=0A= + call_hook =3D 1;=0A= +=0A= + /* skip over slashes */=0A= + while (*path =3D=3D '/')=0A= + path++;=0A= +=0A= + for (pathlen =3D 0 ;=0A= + path[pathlen]=0A= + && !grub_isspace(path[pathlen]) && path[pathlen] !=3D '/' ;=0A= + pathlen++)=0A= + ;=0A= +=0A= + /* if this isn't a directory of sufficient size to hold our file, = abort */=0A= + if (data->file_type !=3D ROMFH_DIR) =0A= + {=0A= + DBG_MSG ("\t grub_errno =3D GRUB_ERR_BAD_FILE_TYPE;\n");=0A= + grub_errno =3D GRUB_ERR_BAD_FILE_TYPE;=0A= + return 0;=0A= + }=0A= +=0A= + /* skip to next slash or end of filename (space) */=0A= + for (rest =3D path;=0A= + (ch =3D *rest) && !grub_isspace (ch) && ch !=3D '/';=0A= + rest++)=0A= + ;=0A= +=0A= + /* look through this directory and find the next filename=0A= + component */=0A= + /* invariant: rest points to slash after the next filename=0A= + component */=0A= + *rest =3D 0;=0A= +=0A= + dir_offset =3D INODE->spec; /* disk offset for this dir search */=0A= +=0A= + DBG_MSG ("\t dir_offset=3D%d.\n", dir_offset);=0A= +=0A= + do {=0A= + if (!dir_offset) =0A= + {=0A= + /* not found */=0A= + if ( call_hook >=3D0 ) =0A= + {=0A= + grub_errno =3D GRUB_ERR_FILE_NOT_FOUND;=0A= + *rest =3D ch;=0A= + }=0A= +=0A= + return 0;=0A= + }=0A= +=0A= + load_inode(dir_offset);=0A= +=0A= + DBG_MSG ("\t %s<->%s.\n", path, INODE->name);=0A= + dir_nofound =3D grub_stricmp(path, INODE->name);=0A= +=0A= + if (grub_strlen(INODE->name) >=3D pathlen && call_hook=0A= + && !grub_memcmp(INODE->name, path, pathlen) && ch !=3D '/')=0A= + {=0A= + if (call_hook > 0)=0A= + call_hook =3D -call_hook;=0A= +=0A= + /* skip the `.' and `..' */=0A= + if (!(grub_strcmp(INODE->name, ".") =3D=3D 0 || =0A= + grub_strcmp(INODE->name, "..") =3D=3D 0))=0A= + hook (INODE->name, ((INODE->next & ROMFH_TYPE) =3D=3D ROMFH_DIR) );=0A= +=0A= + dir_nofound =3D -1;=0A= + }=0A= +=0A= + if (dir_nofound)=0A= + {=0A= + dir_offset =3D INODE->next & ROMFH_SIZE_MASK;=0A= + }=0A= + } while (dir_nofound || (call_hook && ch !=3D '/'));=0A= +=0A= + data->dir_offset =3D dir_offset;=0A= +=0A= + *(path =3D rest) =3D ch;=0A= +=0A= + return path;=0A= +}=0A= +=0A= +=0A= +static grub_err_t=0A= +grub_romfs_dir (grub_device_t device, const char *path,=0A= + int (*hook) (const char *filename, int dir))=0A= +{=0A= + char *p, *dirname =3D 0;=0A= + int len =3D 0;=0A= + struct grub_romfs_data *data;=0A= +=0A= + DBG_MSG (" grub_romfs_dir(%s, 0x%x)++. \n", path, hook);=0A= +=0A= + if (device->disk->id !=3D (unsigned long) "rd")=0A= + return grub_error (GRUB_ERR_BAD_FS, "romfs is only for romdisk");=0A= +=0A= + data =3D grub_romfs_mount (device->disk);=0A= + if (!data)=0A= + {=0A= + grub_print_error();=0A= + DBG_MSG (" mount disk failed.\n");=0A= + goto clean;=0A= + }=0A= +=0A= + /* Make sure that DIRNAME terminates with '/'. */=0A= + len =3D grub_strlen (path);=0A= + dirname =3D grub_malloc (len + 1 + 1);=0A= + if (! dirname)=0A= + goto clean;=0A= +=0A= + grub_memcpy (dirname, path, len);=0A= + p =3D dirname + len;=0A= + *p =3D '\0';=0A= + p =3D dirname;=0A= +=0A= + data->dir_offset =3D data->rootdir_offset;=0A= + do=0A= + {=0A= + load_inode(data->dir_offset);=0A= +=0A= + data->file_type =3D INODE->next & ROMFH_TYPE;=0A= +=0A= + if (data->file_type =3D=3D ROMFH_HRD) =0A= + {=0A= + data->dir_offset =3D INODE->spec;=0A= + continue;=0A= + }=0A= + else if (data->file_type =3D=3D ROMFH_SYM) =0A= + {=0A= + grub_errno =3D GRUB_ERR_SYMLINK_LOOP;=0A= + goto clean;=0A= + }=0A= + else =0A= + {=0A= + /* if end of filename, INODE points to the file's inode */=0A= + if (!*p || grub_isspace (*p)) =0A= + {=0A= + DBG_MSG ("\t end of filename.\n");=0A= + if (data->file_type !=3D ROMFH_REG) =0A= + {=0A= + grub_errno =3D GRUB_ERR_BAD_FILE_TYPE;=0A= + goto clean;=0A= + }=0A= +=0A= + data->filesize =3D INODE->size;=0A= + file_offset =3D data->dir_offset;=0A= + =0A= + DBG_MSG ("\t file with size=3D%d, offset=3D0x%x.\n", = data->filesize, file_offset);=0A= + goto clean;=0A= + }=0A= + else=0A= + {=0A= + DBG_MSG ("\t grub_find_dir>\n");=0A= + p =3D grub_find_dir (p, data, hook);=0A= + }=0A= + }=0A= + }=0A= + while (p && grub_errno =3D=3D GRUB_ERR_NONE);=0A= +=0A= +clean:=0A= +=0A= + if (data)=0A= + {=0A= + grub_free (data);=0A= + data =3D 0;=0A= + }=0A= +=0A= + return grub_errno;=0A= +}=0A= +=0A= +static grub_err_t=0A= +grub_romfs_open (grub_file_t file, const char *name)=0A= +{=0A= + char *p, *dirname =3D 0;=0A= + int len =3D 0;=0A= + struct grub_romfs_data *data;=0A= +=0A= + if (file->device->disk->id !=3D (unsigned long) "rd")=0A= + return grub_error (GRUB_ERR_UNKNOWN_DEVICE, "not a romdisk");=0A= +=0A= + DBG_MSG(" grub_romfs_open(%s)++. \n", name);=0A= +=0A= + if (!name || name[0] !=3D '/')=0A= + {=0A= + grub_error (GRUB_ERR_BAD_FILENAME, "bad filename");=0A= + return grub_errno;=0A= + }=0A= +=0A= + data =3D grub_romfs_mount (file->device->disk);=0A= + if (!data)=0A= + {=0A= + grub_print_error();=0A= + DBG_MSG (" mount disk failed.\n");=0A= + goto clean;=0A= + }=0A= +=0A= + /* Make sure that DIRNAME terminates with '/'. */=0A= + len =3D grub_strlen (name);=0A= + dirname =3D grub_malloc (len + 1 + 1);=0A= + if (! dirname)=0A= + goto clean;=0A= +=0A= + grub_memcpy (dirname, name, len);=0A= + p =3D dirname + len;=0A= + *p =3D '\0';=0A= + p =3D dirname;=0A= +=0A= + data->dir_offset =3D data->rootdir_offset;=0A= + do=0A= + {=0A= + load_inode(data->dir_offset);=0A= +=0A= + data->file_type =3D INODE->next & ROMFH_TYPE;=0A= +=0A= + if (data->file_type =3D=3D ROMFH_HRD) =0A= + {=0A= + data->dir_offset =3D INODE->spec;=0A= + continue;=0A= + }=0A= + else if (data->file_type =3D=3D ROMFH_SYM) =0A= + {=0A= + grub_errno =3D GRUB_ERR_SYMLINK_LOOP;=0A= + goto clean;=0A= + }=0A= + else =0A= + {=0A= + /* if end of filename, INODE points to the file's inode */=0A= + if (!*p || grub_isspace (*p)) =0A= + {=0A= + DBG_MSG ("\t end of filename.\n");=0A= + if (data->file_type !=3D ROMFH_REG) =0A= + {=0A= + grub_errno =3D GRUB_ERR_BAD_FILE_TYPE;=0A= + goto clean;=0A= + }=0A= +=0A= + data->filesize =3D INODE->size;=0A= + file_offset =3D data->dir_offset + data->rootdir_offset;=0A= +=0A= + file->data =3D 0;=0A= + file->size =3D data->filesize;=0A= +=0A= + DBG_MSG ("\t file with size=3D%d, offset=3D0x%x.\n", = data->filesize, file_offset);=0A= + goto clean;=0A= + }=0A= + else=0A= + {=0A= + DBG_MSG ("\t grub_find_dir>\n");=0A= + p =3D grub_find_dir (p, data, 0);=0A= + }=0A= + }=0A= + }=0A= + while (p && grub_errno =3D=3D GRUB_ERR_NONE);=0A= +=0A= +clean:=0A= +=0A= + if (data)=0A= + {=0A= + grub_free (data);=0A= + data =3D 0;=0A= + }=0A= +=0A= + return grub_errno;=0A= +}=0A= +=0A= +static grub_ssize_t=0A= +grub_romfs_read (grub_file_t file, char *buf, grub_size_t len)=0A= +{=0A= + int x =3D 0;=0A= + DBG_MSG (" grub_romfs_read(%d, %d, %d, fsize=3D%d)++2. \n", = file_offset, file->offset, len, file->size);=0A= +=0A= + if (len>0)=0A= + {=0A= + x =3D file_offset;=0A= + DBG_MSG ("\t x=3D%d. \n", x);=0A= +=0A= + romfs_devread (x + file->offset, len, buf);=0A= + }=0A= +=0A= + return len;=0A= +}=0A= +=0A= +static grub_err_t=0A= +grub_romfs_close (grub_file_t file)=0A= +{=0A= + DBG_MSG (" grub_romfs_close(). \n");=0A= +=0A= +#ifndef GRUB_UTIL=0A= + grub_dl_unref (my_mod);=0A= +#endif=0A= +=0A= + return grub_errno;=0A= +}=0A= +=0A= +static grub_err_t=0A= +grub_romfs_label (grub_device_t device, char **label)=0A= +{=0A= + struct grub_romfs_data *data;=0A= + DBG_MSG (" grub_romfs_label(). \n");=0A= +=0A= + data =3D grub_romfs_mount (device->disk);=0A= + if (!data)=0A= + {=0A= + DBG_MSG (" mount disk failed.\n");=0A= + *label =3D 0;=0A= + }=0A= + else=0A= + {=0A= + *label =3D data->plabel;=0A= + }=0A= +=0A= + return GRUB_ERR_NONE;=0A= +}=0A= +=0A= +static struct grub_fs grub_romfs_fs =3D {=0A= + .name =3D "romfs",=0A= + .dir =3D grub_romfs_dir,=0A= + .open =3D grub_romfs_open,=0A= + .read =3D grub_romfs_read,=0A= + .close =3D grub_romfs_close,=0A= + .label =3D grub_romfs_label,=0A= + .next =3D 0=0A= +};=0A= +=0A= +void re_init_romdisk ()=0A= +{=0A= + //grub_disk_dev_unregister (&grub_romdisk_dev);=0A= + //grub_fs_unregister (&grub_romfs_fs);=0A= +=0A= + if ( romdisk_addr )=0A= + {=0A= + grub_disk_dev_register (&grub_romdisk_dev);=0A= + grub_fs_register (&grub_romfs_fs);=0A= + }=0A= +}=0A= +=0A= +GRUB_MOD_INIT (romfs)=0A= +{=0A= +#ifndef GRUB_UTIL=0A= + my_mod =3D mod;=0A= +#endif=0A= + =0A= +}=0A= +=0A= +GRUB_MOD_FINI (romfs)=0A= +{=0A= + grub_fs_unregister (&grub_romfs_fs);=0A= +=0A= +/*=0A= +grub_free (romdisk_addr);=0A= +romdisk_addr =3D 0;=0A= +=0A= +grub_disk_dev_unregister (&grub_romdisk_dev);=0A= + */=0A= +}=0A= +=0A= diff -ruNa grub2/include/grub/disk.h grub2_romfs/include/grub/disk.h=0A= --- grub2/include/grub/disk.h 2008-08-17 09:17:24.000000000 +0800=0A= +++ grub2_romfs/include/grub/disk.h 2008-08-17 09:09:19.000000000 +0800=0A= @@ -40,6 +40,7 @@=0A= GRUB_DISK_DEVICE_NAND_ID,=0A= GRUB_DISK_DEVICE_UUID_ID,=0A= GRUB_DISK_DEVICE_PXE_ID,=0A= + GRUB_DISK_DEVICE_ROMDISK_ID,=0A= };=0A= =0A= struct grub_disk;=0A= diff -ruNa grub2/include/grub/i386/pc/romfs.h = grub2_romfs/include/grub/i386/pc/romfs.h=0A= --- grub2/include/grub/i386/pc/romfs.h 1970-01-01 08:00:00.000000000 = +0800=0A= +++ grub2_romfs/include/grub/i386/pc/romfs.h 2008-08-17 = 09:13:27.000000000 +0800=0A= @@ -0,0 +1,72 @@=0A= +/* romfs - prototypes for romfs and romdisk */=0A= +/*=0A= + * GRUB -- GRand Unified Bootloader=0A= + * Copyright (C) 2008 Free Software Foundation, Inc.=0A= + *=0A= + * GRUB is free software: you can redistribute it and/or modify=0A= + * it under the terms of the GNU General Public License as published by=0A= + * the Free Software Foundation, either version 3 of the License, or=0A= + * (at your option) any later version.=0A= + *=0A= + * GRUB is distributed in the hope that it will be useful,=0A= + * but WITHOUT ANY WARRANTY; without even the implied warranty of=0A= + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the=0A= + * GNU General Public License for more details.=0A= + *=0A= + * You should have received a copy of the GNU General Public License=0A= + * along with GRUB. If not, see .=0A= + */=0A= +=0A= +#ifndef GRUB_ROMDISK_H=0A= +#define GRUB_ROMDISK_H 1=0A= +=0A= +#include =0A= +=0A= +#define ROMFH_SIZE_MASK (~15)=0A= +#define ROMFH_TYPE 7=0A= +#define ROMFH_HRD 0=0A= +#define ROMFH_DIR 1=0A= +#define ROMFH_REG 2=0A= +#define ROMFH_SYM 3=0A= +#define ROMFH_BLK 4=0A= +#define ROMFH_CHR 5=0A= +#define ROMFH_SCK 6=0A= +#define ROMFH_FIF 7=0A= +#define ROMFH_EXEC 8=0A= +=0A= +/* Alignment */=0A= +#define ROMFH_SIZE 16=0A= +#define ROMFH_PAD (ROMFH_SIZE-1)=0A= +#define ROMFH_MASK (~ROMFH_PAD)=0A= +=0A= +#define NAME_MAX 255 /* # chars in a file name */=0A= +=0A= +/* On-disk "super block" */=0A= +struct romfs_super_block =0A= +{=0A= + grub_uint32_t word0; = =0A= + grub_uint32_t word1; = =0A= + grub_uint32_t size; = =0A= + grub_uint32_t checksum; = =0A= + char name[0]; /* volume name */ = =0A= +}; = =0A= +=0A= +/* On disk inode */=0A= +struct romfs_inode =0A= +{=0A= + grub_uint32_t next; /* low 4 bits see ROMFH_ */ = =0A= + grub_uint32_t spec; = =0A= + grub_uint32_t size; = =0A= + grub_uint32_t checksum; = =0A= + char name[0]; = =0A= +};=0A= +=0A= +extern char *EXPORT_VAR(romdisk_addr);=0A= +extern grub_off_t EXPORT_VAR(romdisk_size);=0A= +void EXPORT_FUNC(re_init_romdisk) ();=0A= +=0A= +/* debug support */=0A= +/* #define DBG_MSG grub_dprintf */=0A= +#define DBG_MSG=0A= +=0A= +#endif /* ! GRUB_ROMDISK_H */=0A= ------=_NextPart_000_0020_01C90056.13B66DC0--