summaryrefslogtreecommitdiff
path: root/firmware/common/disk.c
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2002-05-03 11:59:53 +0000
committerBjörn Stenberg <bjorn@haxx.se>2002-05-03 11:59:53 +0000
commitc7f7934e8f74be4b98abe83c2f6a2593fd294cf0 (patch)
treecdebbde186e8db107472c5a7b0775f050e7f4560 /firmware/common/disk.c
parent86a59ecdf6e6bf3e45938c0ca305b892777b28e0 (diff)
downloadrockbox-c7f7934e8f74be4b98abe83c2f6a2593fd294cf0.tar.gz
rockbox-c7f7934e8f74be4b98abe83c2f6a2593fd294cf0.zip
Added disk/partition handling
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@405 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/common/disk.c')
-rw-r--r--firmware/common/disk.c74
1 files changed, 74 insertions, 0 deletions
diff --git a/firmware/common/disk.c b/firmware/common/disk.c
new file mode 100644
index 0000000000..9572f115e5
--- /dev/null
+++ b/firmware/common/disk.c
@@ -0,0 +1,74 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Björn Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "ata.h"
20#include "debug.h"
21#include "disk.h"
22
23/* Partition table entry layout:
24 -----------------------
25 0: 0x80 - active
26 1: starting head
27 2: starting sector
28 3: starting cylinder
29 4: partition type
30 5: end head
31 6: end sector
32 7: end cylinder
33 8-11: starting sector (LBA)
34 12-15: nr of sectors in partition
35*/
36
37#define BYTES2INT32(array,pos) \
38 (array[pos] | (array[pos+1] << 8 ) | \
39 (array[pos+2] << 16 ) | (array[pos+3] << 24 ))
40
41struct partinfo part[8];
42
43int disk_init(void)
44{
45 int i;
46 unsigned char sector[512];
47
48 ata_read_sectors(0,1,&sector);
49
50 /* check that the boot sector is initialized */
51 if ( (sector[510] != 0x55) ||
52 (sector[511] != 0xaa)) {
53 DEBUGF("Bad boot sector signature\n");
54 return -1;
55 }
56
57 /* parse partitions */
58 for ( i=0; i<4; i++ ) {
59 unsigned char* ptr = sector + 0x1be + 16*i;
60 part[i].type = ptr[4];
61 part[i].start = BYTES2INT32(ptr, 8);
62 part[i].size = BYTES2INT32(ptr, 12);
63
64 DEBUGF("Part%d: Type %02x, start: %08x size: %08x\n",
65 i,part[i].type,part[i].start,part[i].size);
66
67 /* extended? */
68 if ( part[i].type == 5 ) {
69 /* not handled yet */
70 }
71 }
72
73 return 0;
74}