mbr.c
86 lines
| 2.5 KiB
| text/x-c
|
CLexer
r12 | /*------------------------------------------------------------------------------ | |||
-- This file is a part of the libuc, microcontroler library | ||||
-- Copyright (C) 2012, Alexis Jeandet | ||||
-- | ||||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
-- the Free Software Foundation; either version 3 of the License, or | ||||
-- (at your option) any later version. | ||||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
------------------------------------------------------------------------------- | ||||
-- Author : Alexis Jeandet | ||||
|
r64 | -- Mail : alexis.jeandet@member.fsf.org | ||
r12 | -------------------------------------------------------------------------------*/ | |||
r63 | #include <mbr.h> | |||
|
r18 | #include <stdio.h> | ||
r12 | ||||
int mbropen(blkdevice* phy,dikpartition* part,char partNum) | ||||
{ | ||||
|
r18 | printf("enter MBR open function\n"); | ||
r12 | char mbr[512]; | |||
if((part==0) || (phy ==0) || (partNum>4) || (partNum==0) ) return MBRBabArg; | ||||
part->phy = phy; | ||||
|
r18 | if(phy->read(phy,mbr,0,1)!=RES_OK) | ||
{ | ||||
printf("can't read MBR!\n"); | ||||
r61 | printf("%x %x %x %x %x %x %x %x\n",mbr[0],mbr[1],mbr[2],mbr[3],mbr[4],mbr[5],mbr[6],mbr[7]); | |||
r63 | part->valide = 0; | |||
|
r18 | return MBRReadErr; | ||
} | ||||
if(((mbr[510]) == (char)0x55) && ((mbr[511]) == (char)0xAA)) | ||||
{ | ||||
part->TypeCode = mbr[(512-82+TypeCodeoffset)+partNum*16]; | ||||
part->LBABegin = (unsigned int)mbr[(512-82+LBABeginoffset)+partNum*16] + ((unsigned int)mbr[(512-82+LBABeginoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+LBABeginoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+LBABeginoffset+3)+partNum*16]<<24); | ||||
part->NumOfSec = (unsigned int)mbr[(512-82+NumOfSecoffset)+partNum*16] + ((unsigned int)mbr[(512-82+NumOfSecoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+3)+partNum*16]<<24); | ||||
printf("MBR Ok\n"); | ||||
r63 | part->valide = 1; | |||
|
r18 | return MBRnoErr; | ||
} | ||||
printf("Bad MBR MBR[510]=0x%.2X MBR[511]=0x%.2X!\n",0xff&mbr[510],0xff&mbr[511]); | ||||
r63 | part->valide = 0; | |||
|
r18 | return MBRBadMbr; | ||
r12 | } | |||