From patchwork Tue Mar 26 09:06:05 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: egbert.eich@googlemail.com X-Patchwork-Id: 231197 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from theia.denx.de (theia.denx.de [85.214.87.163]) by ozlabs.org (Postfix) with ESMTP id 911B92C0091 for ; Wed, 27 Mar 2013 00:26:14 +1100 (EST) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id EAD384A0B8; Tue, 26 Mar 2013 14:26:05 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id B4QNOx2nb8KO; Tue, 26 Mar 2013 14:26:05 +0100 (CET) Received: from theia.denx.de (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id AB2714A0BD; Tue, 26 Mar 2013 14:25:54 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by theia.denx.de (Postfix) with ESMTP id 2E0204A04A for ; Tue, 26 Mar 2013 10:58:35 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at theia.denx.de Received: from theia.denx.de ([127.0.0.1]) by localhost (theia.denx.de [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id ps54tswuOIvj for ; Tue, 26 Mar 2013 10:58:33 +0100 (CET) X-policyd-weight: NOT_IN_SBL_XBL_SPAMHAUS=-1.5 NOT_IN_SPAMCOP=-1.5 NOT_IN_BL_NJABL=-1.5 (only DNSBL check requested) Received: from mail-ee0-f49.google.com (mail-ee0-f49.google.com [74.125.83.49]) by theia.denx.de (Postfix) with ESMTPS id 393DD4A03A for ; Tue, 26 Mar 2013 10:58:30 +0100 (CET) Received: by mail-ee0-f49.google.com with SMTP id d41so3607712eek.22 for ; Tue, 26 Mar 2013 02:58:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20120113; h=x-received:from:to:cc:subject:date:message-id:x-mailer; bh=kng5D7L5f+RWQIIbb2inuT1CFAyhS+rIAsBLSoLRQBQ=; b=QO5O/w6KaaW1IIDlcdIG7KsdRGyv09qkWygHC6LUTaVxrg6yK6kDfwu7dE43EWe29z nDgGVFwsfwSBQGiuNrejRAzKJiIP5Ex1tRgX4nCoeBg/5kqxJy604WFEADtUmdtlPTxI lBvV088WHSHehogQdSKPemPt7hrWxUjG572vShpeSw7SvSAMc732pGE6D2WwfIHEoydX 3pQacdKl0MZFgJeryZFYi8BeUPn9xTfy6SKT0SQrNCMnqdttgapHWBrosjXx30bMkbR8 zW+MwRcEY8eUrrJLWLaNBCoJGU/P1U5zi7ViBZ8tu8fevq8HRCo5JTF5YQMKj1CnSUh5 czTg== X-Received: by 10.15.107.205 with SMTP id cb53mr14469177eeb.14.1364291909578; Tue, 26 Mar 2013 02:58:29 -0700 (PDT) Received: from debian (p5DCF07C5.dip0.t-ipconnect.de. [93.207.7.197]) by mx.google.com with ESMTPS id q42sm23970464eem.14.2013.03.26.02.58.28 (version=TLSv1 cipher=RC4-SHA bits=128/128); Tue, 26 Mar 2013 02:58:28 -0700 (PDT) Received: from sles11.fritz.box (sles11.fritz.box [192.168.178.22]) by debian (Postfix) with ESMTP id 30FAA13C76; Tue, 26 Mar 2013 10:58:27 +0100 (CET) From: egbert.eich@googlemail.com To: u-boot@lists.denx.de Date: Tue, 26 Mar 2013 05:06:05 -0400 Message-Id: <1364288765-2637-1-git-send-email-egbert.eich@gmail.com> X-Mailer: git-send-email 1.7.7 X-Mailman-Approved-At: Tue, 26 Mar 2013 14:25:51 +0100 Cc: Egbert Eich Subject: [U-Boot] [PATCH] disk: part_dos: check harder for partition table. X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.11 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: u-boot-bounces@lists.denx.de Errors-To: u-boot-bounces@lists.denx.de From: Egbert Eich Devices that used to have a whole disk FAT filesystem but got then partitioned will most likely still have a FAT or FAT32 signature in the first sector as this sector does not get overwritten by a partitioning tool (otherwise the tool would risk to kill the mbr). The current partition search algorithm will erronosly detect such a device as a raw FAT device. Instead of looking for the FAT or FAT32 signatures immediately we use the same algorithm as used by the Linux kernel and first check for a valid boot indicator flag on each of the 4 partitions. If the value of this flag is invalid for the first entry we then do the raw partition check. If the flag for any higher partition is wrong we assume the device is neiter a MBR nor PBR device. Signed-off-by: Egbert Eich --- disk/part_dos.c | 16 +++++++++++++--- 1 files changed, 13 insertions(+), 3 deletions(-) diff --git a/disk/part_dos.c b/disk/part_dos.c index 37087a6..8a23495 100644 --- a/disk/part_dos.c +++ b/disk/part_dos.c @@ -74,13 +74,23 @@ static void print_one_part(dos_partition_t *p, int ext_part_sector, static int test_block_type(unsigned char *buffer) { + int slot; + struct dos_partition *p; + if((buffer[DOS_PART_MAGIC_OFFSET + 0] != 0x55) || (buffer[DOS_PART_MAGIC_OFFSET + 1] != 0xaa) ) { return (-1); } /* no DOS Signature at all */ - if (strncmp((char *)&buffer[DOS_PBR_FSTYPE_OFFSET],"FAT",3)==0 || - strncmp((char *)&buffer[DOS_PBR32_FSTYPE_OFFSET],"FAT32",5)==0) { - return DOS_PBR; /* is PBR */ + p = ( struct dos_partition *)&buffer[DOS_PART_TBL_OFFSET]; + for (slot = 0; slot < 3; slot++) { + if (p->boot_ind != 0 && p->boot_ind != 0x80) { + if (!slot && + (strncmp((char *)&buffer[DOS_PBR_FSTYPE_OFFSET],"FAT",3)==0 || + strncmp((char *)&buffer[DOS_PBR32_FSTYPE_OFFSET],"FAT32",5)==0)) { + return DOS_PBR; /* is PBR */ + } else + return -1; + } } return DOS_MBR; /* Is MBR */ }