From owner-svn-src-head@FreeBSD.ORG Wed Jun 3 16:28:29 2009 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 73CB41065670; Wed, 3 Jun 2009 16:28:29 +0000 (UTC) (envelope-from raj@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 622FB8FC12; Wed, 3 Jun 2009 16:28:29 +0000 (UTC) (envelope-from raj@FreeBSD.org) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id n53GSTx3059889; Wed, 3 Jun 2009 16:28:29 GMT (envelope-from raj@svn.freebsd.org) Received: (from raj@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id n53GSTWV059888; Wed, 3 Jun 2009 16:28:29 GMT (envelope-from raj@svn.freebsd.org) Message-Id: <200906031628.n53GSTWV059888@svn.freebsd.org> From: Rafal Jaworowski Date: Wed, 3 Jun 2009 16:28:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r193387 - head/sys/boot/uboot/lib X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 03 Jun 2009 16:28:29 -0000 Author: raj Date: Wed Jun 3 16:28:29 2009 New Revision: 193387 URL: http://svn.freebsd.org/changeset/base/193387 Log: Make GPT style partitiong endian-safe in U-Boot support library. Submitted by: Piotr Ziecik Obtained from: Semihalf Modified: head/sys/boot/uboot/lib/disk.c Modified: head/sys/boot/uboot/lib/disk.c ============================================================================== --- head/sys/boot/uboot/lib/disk.c Wed Jun 3 16:11:27 2009 (r193386) +++ head/sys/boot/uboot/lib/disk.c Wed Jun 3 16:28:29 2009 (r193387) @@ -34,6 +34,7 @@ __FBSDID("$FreeBSD$"); #include +#include #include #include #include @@ -122,6 +123,15 @@ struct devsw uboot_storage = { stor_print }; +static void +uuid_letoh(uuid_t *uuid) +{ + + uuid->time_low = le32toh(uuid->time_low); + uuid->time_mid = le16toh(uuid->time_mid); + uuid->time_hi_and_version = le16toh(uuid->time_hi_and_version); +} + static int stor_init(void) { @@ -251,7 +261,7 @@ stor_open_gpt(struct open_dev *od, struc } /* Check the slice table magic. */ - if (*((uint16_t *)(buf + DOSMAGICOFFSET)) != DOSMAGIC) { + if (le16toh(*((uint16_t *)(buf + DOSMAGICOFFSET))) != DOSMAGIC) { err = ENXIO; goto out; } @@ -286,9 +296,10 @@ stor_open_gpt(struct open_dev *od, struc /* Check GPT header */ if (bcmp(hdr->hdr_sig, GPT_HDR_SIG, sizeof(hdr->hdr_sig)) != 0 || - hdr->hdr_lba_self != 1 || hdr->hdr_revision < 0x00010000 || - hdr->hdr_entsz < sizeof(*ent) || - od->od_bsize % hdr->hdr_entsz != 0) { + le64toh(hdr->hdr_lba_self) != 1 || + le32toh(hdr->hdr_revision) < 0x00010000 || + le32toh(hdr->hdr_entsz) < sizeof(*ent) || + od->od_bsize % le32toh(hdr->hdr_entsz) != 0) { debugf("Invalid GPT header!\n"); err = EINVAL; goto out; @@ -296,9 +307,9 @@ stor_open_gpt(struct open_dev *od, struc /* Count number of valid partitions */ part = 0; - eps = od->od_bsize / hdr->hdr_entsz; - slba = hdr->hdr_lba_table; - elba = slba + hdr->hdr_entries / eps; + eps = od->od_bsize / le32toh(hdr->hdr_entsz); + slba = le64toh(hdr->hdr_lba_table); + elba = slba + le32toh(hdr->hdr_entries) / eps; for (lba = slba; lba < elba; lba++) { err = stor_readdev(dev, lba, 1, buf); @@ -312,8 +323,9 @@ stor_open_gpt(struct open_dev *od, struc for (i = 0; i < eps; i++) { if (uuid_is_nil(&ent[i].ent_type, NULL) || - ent[i].ent_lba_start == 0 || - ent[i].ent_lba_end < ent[i].ent_lba_start) + le64toh(ent[i].ent_lba_start) == 0 || + le64toh(ent[i].ent_lba_end) < + le64toh(ent[i].ent_lba_start)) continue; part += 1; @@ -343,8 +355,9 @@ stor_open_gpt(struct open_dev *od, struc for (i = 0; i < eps; i++) { if (uuid_is_nil(&ent[i].ent_type, NULL) || - ent[i].ent_lba_start == 0 || - ent[i].ent_lba_end < ent[i].ent_lba_start) + le64toh(ent[i].ent_lba_start) == 0 || + le64toh(ent[i].ent_lba_end) < + le64toh(ent[i].ent_lba_start)) continue; od->od_partitions[part].gp_index = (lba - slba) @@ -352,9 +365,11 @@ stor_open_gpt(struct open_dev *od, struc od->od_partitions[part].gp_type = ent[i].ent_type; od->od_partitions[part].gp_start = - ent[i].ent_lba_start; + le64toh(ent[i].ent_lba_start); od->od_partitions[part].gp_end = - ent[i].ent_lba_end; + le64toh(ent[i].ent_lba_end); + + uuid_letoh(&od->od_partitions[part].gp_type); part += 1; } }