summaryrefslogtreecommitdiff
path: root/firmware/test/fat/fat-mbr_sector.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/test/fat/fat-mbr_sector.c')
-rw-r--r--firmware/test/fat/fat-mbr_sector.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/firmware/test/fat/fat-mbr_sector.c b/firmware/test/fat/fat-mbr_sector.c
new file mode 100644
index 0000000000..f6b510cea5
--- /dev/null
+++ b/firmware/test/fat/fat-mbr_sector.c
@@ -0,0 +1,65 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Alan Korr
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 <fat.h>
20#include "fat-mbr_sector.h"
21
22// [Alan]:
23// I would like to draw your attention about the fact that SH1
24// cannot use misaligned address access so you must be very cautious
25// with structures stored in FAT32 partition because they come from
26// PC world where misaligned address accesses are usual and not
27// problematic. To avoid such a trouble, I decide to use special
28// structures where fields are moved in such a way they can be
29// accessed by SH1. It is possible thanks to the callback mechanism
30// I use for reading or writing from/to an ATA device in ata.h/c.
31// So don't be puzzled if those structures seem odd compared
32// with the usual ones from PC world. I use this mechanism for structures
33// 'partition_info', 'mbr_sector' and 'fsi_sector' for instance, but
34// not for structure 'bpb_sector' which is too much complex to handle
35// that way, I think.
36// By the way, SH1 is big endian, not little endian as PC is.
37
38///////////////////////////////////////////////////////////////////////////////////
39// MBR SECTOR :
40///////////////
41//
42//
43
44int __fat_get_mbr_sector_callback (struct __fat_mbr_sector *mbr_sector)
45 {
46 short *data = mbr_sector->data,*end;
47 for (end = mbr_sector->end; data < end; ++data)
48 *data = ata_get_word (0);
49 __fat_get_partition_table (mbr_sector->partition_table);
50 mbr_sector->signature = HI(ATAR_DATA);
51 return FAT_RETURN_SUCCESS;
52 }
53
54int __fat_put_mbr_sector_callback (struct __fat_mbr_sector *mbr_sector)
55 {
56 short const *data = mbr_sector->data,*end;
57 for (end = mbr_sector->end; data < end;)
58 HI(ATAR_DATA) = *data++;
59 __fat_put_partition_table (mbr_sector->partition_table);
60 ata_put_word (mbr_sector->signature,0);
61 return FAT_RETURN_SUCCESS;
62 }
63
64//
65///////////////////////////////////////////////////////////////////////////////////