##// END OF EJS Templates
Fat32 library partially working, can read a file.
Fat32 library partially working, can read a file.

File last commit:

r61:efd3992e476b dev_alexis
r62:25c982b9ed94 dev_alexis
Show More
mbr.c
83 lines | 2.4 KiB | text/x-c | CLexer
/*------------------------------------------------------------------------------
-- 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
-- Mail : alexis.jeandet@gmail.com
-------------------------------------------------------------------------------*/
#include "mbr.h"
#include <stdio.h>
int mbropen(blkdevice* phy,dikpartition* part,char partNum)
{
printf("enter MBR open function\n");
char mbr[512];
if((part==0) || (phy ==0) || (partNum>4) || (partNum==0) ) return MBRBabArg;
part->phy = phy;
if(phy->read(phy,mbr,0,1)!=RES_OK)
{
printf("can't read MBR!\n");
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]);
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");
return MBRnoErr;
}
printf("Bad MBR MBR[510]=0x%.2X MBR[511]=0x%.2X!\n",0xff&mbr[510],0xff&mbr[511]);
return MBRBadMbr;
}