2002-05-03 11:59:53 +00:00
|
|
|
|
/***************************************************************************
|
|
|
|
|
* __________ __ ___.
|
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
|
* $Id$
|
|
|
|
|
*
|
|
|
|
|
* Copyright (C) 2002 by Bj<EFBFBD>rn Stenberg
|
|
|
|
|
*
|
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
|
*
|
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
|
* KIND, either express or implied.
|
|
|
|
|
*
|
|
|
|
|
****************************************************************************/
|
2002-05-30 19:41:35 +00:00
|
|
|
|
#include <stdio.h>
|
2002-05-03 11:59:53 +00:00
|
|
|
|
#include "ata.h"
|
|
|
|
|
#include "debug.h"
|
|
|
|
|
#include "disk.h"
|
|
|
|
|
|
|
|
|
|
/* Partition table entry layout:
|
|
|
|
|
-----------------------
|
|
|
|
|
0: 0x80 - active
|
|
|
|
|
1: starting head
|
|
|
|
|
2: starting sector
|
|
|
|
|
3: starting cylinder
|
|
|
|
|
4: partition type
|
|
|
|
|
5: end head
|
|
|
|
|
6: end sector
|
|
|
|
|
7: end cylinder
|
|
|
|
|
8-11: starting sector (LBA)
|
|
|
|
|
12-15: nr of sectors in partition
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#define BYTES2INT32(array,pos) \
|
|
|
|
|
(array[pos] | (array[pos+1] << 8 ) | \
|
|
|
|
|
(array[pos+2] << 16 ) | (array[pos+3] << 24 ))
|
|
|
|
|
|
2002-05-30 19:41:35 +00:00
|
|
|
|
static struct partinfo part[8];
|
2002-05-03 11:59:53 +00:00
|
|
|
|
|
2002-05-30 19:41:35 +00:00
|
|
|
|
struct partinfo* disk_init(void)
|
2002-05-03 11:59:53 +00:00
|
|
|
|
{
|
|
|
|
|
int i;
|
|
|
|
|
unsigned char sector[512];
|
|
|
|
|
|
|
|
|
|
ata_read_sectors(0,1,§or);
|
|
|
|
|
|
|
|
|
|
/* check that the boot sector is initialized */
|
|
|
|
|
if ( (sector[510] != 0x55) ||
|
|
|
|
|
(sector[511] != 0xaa)) {
|
|
|
|
|
DEBUGF("Bad boot sector signature\n");
|
2002-05-30 19:41:35 +00:00
|
|
|
|
return NULL;
|
2002-05-03 11:59:53 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* parse partitions */
|
|
|
|
|
for ( i=0; i<4; i++ ) {
|
|
|
|
|
unsigned char* ptr = sector + 0x1be + 16*i;
|
|
|
|
|
part[i].type = ptr[4];
|
|
|
|
|
part[i].start = BYTES2INT32(ptr, 8);
|
|
|
|
|
part[i].size = BYTES2INT32(ptr, 12);
|
|
|
|
|
|
|
|
|
|
DEBUGF("Part%d: Type %02x, start: %08x size: %08x\n",
|
|
|
|
|
i,part[i].type,part[i].start,part[i].size);
|
|
|
|
|
|
|
|
|
|
/* extended? */
|
|
|
|
|
if ( part[i].type == 5 ) {
|
|
|
|
|
/* not handled yet */
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2002-05-30 19:41:35 +00:00
|
|
|
|
return part;
|
2002-05-03 11:59:53 +00:00
|
|
|
|
}
|