From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with archive (Exim 4.43) id 1KSZWn-0005Iq-MY for mharc-grub-devel@gnu.org; Mon, 11 Aug 2008 11:41:49 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KSZWm-0005Fa-3u for grub-devel@gnu.org; Mon, 11 Aug 2008 11:41:48 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KSZWi-00057H-AY for grub-devel@gnu.org; Mon, 11 Aug 2008 11:41:47 -0400 Received: from [199.232.76.173] (port=49272 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KSZWi-000571-3Q for grub-devel@gnu.org; Mon, 11 Aug 2008 11:41:44 -0400 Received: from ti-out-0910.google.com ([209.85.142.184]:36395) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1KSZWh-0007Ue-Gl for grub-devel@gnu.org; Mon, 11 Aug 2008 11:41:44 -0400 Received: by ti-out-0910.google.com with SMTP id u5so1029091tia.10 for ; Mon, 11 Aug 2008 08:41:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:from:to:references :subject:date:mime-version:content-type:x-priority:x-msmail-priority :x-mailer:x-mimeole; bh=AJRS9Vb0xX0dCmKH6rmKlZmgbpqMPausL9O54wfoz+4=; b=kRxKJNVlOGWOduyEZne7ln5vXrW7NnnLmhAqavJrR10N89ThAUg32N9FPLzS6uZGch rfiyJtV24qERRiyL8CnXBSOc2k30nZTTlDzDVFWr2WFNZAEoUlt3sBr79Ex3QLiRJQP2 dWkTkOVpgCpXatiF83vWPJiu5tsM5NnUOsptQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:from:to:references:subject:date:mime-version :content-type:x-priority:x-msmail-priority:x-mailer:x-mimeole; b=tG8TJyBrmkxpD88TuWvYXcwNpwZ8FJd+AzmLJMIrqlD69TSgoV+pdHQ8VghcWlm4eV tIjF0y81z+sJ56qFJhwbyhmj/ctZVnNhRvt+iQUHfa0B8atVFDHYQJkch0/HXFDPIszK SjMDpnjrUt3rcUo/nX9f95l6pnDZQ/+RgxuUM= Received: by 10.110.3.15 with SMTP id 15mr9691192tic.48.1218469300454; Mon, 11 Aug 2008 08:41:40 -0700 (PDT) Received: from hp2003 ( [123.116.146.251]) by mx.google.com with ESMTPS id d1sm568513tid.11.2008.08.11.08.41.38 (version=SSLv3 cipher=RC4-MD5); Mon, 11 Aug 2008 08:41:39 -0700 (PDT) Message-ID: <4EDC0971DA234DE69A57C17D30812C79@hp2003> From: "y.volta" To: References: <48a04fce.3c432c0a.185e.ffffe7e9SMTPIN_ADDED@mx.google.com> Date: Mon, 11 Aug 2008 23:41:38 +0800 MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="----=_NextPart_000_0004_01C8FC0B.CC26E500" 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.4133 X-detected-kernel: by monty-python.gnu.org: Linux 2.6 (newer, 2) Subject: [PATCH] add pkzip support for gzio 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: Mon, 11 Aug 2008 15:41:48 -0000 This is a multi-part message in MIME format. ------=_NextPart_000_0004_01C8FC0B.CC26E500 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: base64 aGksDQoNCiAgICBpJ3ZlIG1hZGUgYSBsaXR0bGUgcGF0Y2ggZm9yIHBremlwZWQgKCBkZWZsYXRl IG1vZGUgKSBmaWxlLiBieSB1c2luZyB0aGlzLCB3ZSBjYW4gaGF2ZSBib3RoIGd1bnppcCBhbmQg cGt1bnppcCBzdXBwb3J0ZWQ6IHRoZXkgaGF2ZSBvbmx5IGhlYWRlciBkaWZmZXJlbnQgd2l0aCB0 aGUgc2FtZSBmaWxlLiA7LSkNCg0KICAgIHBsZWFzZSBub3RlLCBpZiB5b3VyIGZpbGUgaXMgdG9v IHNtYWxsLCBwa3ppcCB3aWxsIG5vdCBjb21wcmVzcyBpdCBidXQgc3RvcmUgdGhlIG9yZ2luYWwg ZGF0YSB0byB0aGUgb3V0cHV0IGZpbGUuDQoNCnkudm9sdGENCiA= ------=_NextPart_000_0004_01C8FC0B.CC26E500 Content-Type: application/octet-stream; name="gzio.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="gzio.patch" Index: gzio.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D --- gzio.c (revision 1800) +++ gzio.c (working copy) @@ -161,9 +161,81 @@ typedef unsigned short ush;=0A= typedef unsigned long ulg;=0A= =0A= +=0A= +/* PKZIP header. See=0A= + * = .=0A= + */=0A= +struct pkzip_header {=0A= + grub_int32_t magic;=0A= + grub_int16_t version;=0A= + grub_int16_t flags;=0A= + grub_int16_t method;=0A= + grub_int16_t modified_time;=0A= + grub_int16_t modified_date;=0A= + grub_int32_t crc;=0A= + grub_int32_t zbytes;=0A= + grub_int32_t dbytes;=0A= + grub_int16_t filename_len;=0A= + grub_int16_t extra_len;=0A= +} __attribute__ ((packed));=0A= +/* (followed by optional and variable length "filename" and "extra"=0A= + fields) */=0A= +=0A= +/* pkzip flag byte */=0A= +#define PK_ENCRYPTED 0x01 /* bit 0 set: file is encrypted */=0A= +#define PK_DATADESC 0x08 /* bit 3 set: file has trailing = "data=0A= + descriptor" */=0A= +#define PK_UNSUPPORTED 0xFFF0 /* All other bits must be zero */=0A= +#define PKZIP_MAGIC grub_le_to_cpu32 (0x04034B50)=0A= + =0A= +/* test for pkzip file header */=0A= static int=0A= -test_header (grub_file_t file)=0A= +pkunzip_test_header (grub_file_t file)=0A= {=0A= + struct pkzip_header pkzh;=0A= + int pkzip_header_size =3D sizeof(struct pkzip_header);=0A= + =0A= + grub_gzio_t gzio =3D file->data;=0A= + =0A= + if (grub_file_tell (gzio->file) !=3D 0)=0A= + grub_file_seek (gzio->file, 0);=0A= + =0A= + /* read header */=0A= + if ( grub_file_read (gzio->file, (char *)&pkzh, pkzip_header_size) = !=3D pkzip_header_size =0A= + || pkzh.magic !=3D PKZIP_MAGIC)=0A= + {=0A= + grub_error (GRUB_ERR_BAD_FILE_TYPE, "no pkzip magic found");=0A= + return 0;=0A= + }=0A= + =0A= + if (pkzh.flags & PK_ENCRYPTED /* error("pkzip file is = encrypted; not supported"); */=0A= + || pkzh.flags & PK_DATADESC /* error("pkzip file uses = data_descriptor field; not supported"); */=0A= + || pkzh.flags & PK_UNSUPPORTED /* error("pkzip file has = unsupported flags"); */=0A= + || pkzh.method !=3D 8) /* error("pkzip file uses = invalid method"); */=0A= + /* We only support method #8, = DEFLATED!! */=0A= + {=0A= + grub_error (GRUB_ERR_BAD_FILE_TYPE, "no pkzip magic found");=0A= + return 0;=0A= + }=0A= + =0A= + gzio->data_offset =3D pkzip_header_size; /* skip header */=0A= + =0A= + gzio->data_offset +=3D pkzh.filename_len; /* skip filename */=0A= + =0A= + gzio->data_offset +=3D pkzh.extra_len; /* skip extra field = */=0A= +=0A= + /* gzip_crc =3D pkzh.crc; crc */=0A= + file->size =3D pkzh.dbytes; /* decompressed = size */=0A= +=0A= + initialize_tables (file);=0A= + =0A= + return 1;=0A= +}=0A= +=0A= +/* test for gzip file header */=0A= +static int=0A= +gunzip_test_header (grub_file_t file)=0A= +{=0A= unsigned char buf[10] __attribute__ ((aligned));=0A= grub_gzio_t gzio =3D file->data;=0A= =0A= @@ -1128,19 +1200,25 @@ file->read_hook =3D 0;=0A= file->fs =3D &grub_gzio_fs;=0A= =0A= - if (! test_header (file))=0A= + if (! gunzip_test_header (file))=0A= {=0A= - grub_free (gzio);=0A= - grub_free (file);=0A= - grub_file_seek (io, 0);=0A= + /* before we go, reset the error num. */=0A= + grub_errno =3D GRUB_ERR_NONE;=0A= + =0A= + if (! pkunzip_test_header (file))=0A= + {=0A= + grub_free (gzio);=0A= + grub_free (file);=0A= + grub_file_seek (io, 0);=0A= =0A= - if (grub_errno =3D=3D GRUB_ERR_BAD_FILE_TYPE && transparent)=0A= - {=0A= - grub_errno =3D GRUB_ERR_NONE;=0A= - return io;=0A= + if (grub_errno =3D=3D GRUB_ERR_BAD_FILE_TYPE && transparent)=0A= + {=0A= + grub_errno =3D GRUB_ERR_NONE;=0A= + return io;=0A= + }=0A= + else=0A= + return 0;=0A= }=0A= - else=0A= - return 0;=0A= }=0A= =0A= return file;=0A= ------=_NextPart_000_0004_01C8FC0B.CC26E500--