diff options
author | Alan Korr <alkorr@rockbox.org> | 2002-04-19 12:16:19 +0000 |
---|---|---|
committer | Alan Korr <alkorr@rockbox.org> | 2002-04-19 12:16:19 +0000 |
commit | 6dd637f44c0523958012f3c28068c631a73b0569 (patch) | |
tree | 73f926f81d05617869da14a40f9613909e7f2dee /firmware/test/fat/fat-fsi_sector.c | |
parent | b41596560eed4f805d19931eec3d37b3bad06e61 (diff) | |
download | rockbox-6dd637f44c0523958012f3c28068c631a73b0569.tar.gz rockbox-6dd637f44c0523958012f3c28068c631a73b0569.zip |
adding files... nothin working... a lot of thing missing
not speaking about possible drastic changes...
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@144 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/test/fat/fat-fsi_sector.c')
-rw-r--r-- | firmware/test/fat/fat-fsi_sector.c | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/firmware/test/fat/fat-fsi_sector.c b/firmware/test/fat/fat-fsi_sector.c new file mode 100644 index 0000000000..54863dc2a4 --- /dev/null +++ b/firmware/test/fat/fat-fsi_sector.c | |||
@@ -0,0 +1,105 @@ | |||
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-fsi_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 | // FSI SECTOR : | ||
40 | /////////////// | ||
41 | // | ||
42 | // | ||
43 | |||
44 | int __fat_get_fsi_sector_callback (struct __fat_fsi_sector *fsi_sector) | ||
45 | { | ||
46 | short *data = fsi_sector->data,*end; | ||
47 | union { unsigned long si[2]; unsigned short hi[4]; unsigned char qi[8]; } words; | ||
48 | for (end = fsi_sector->end0; data < end; ++data) | ||
49 | *data = ata_get_word (0); | ||
50 | #ifdef __little__ | ||
51 | words.hi[0] = ata_get_word (0); | ||
52 | words.hi[1] = ata_get_word (0); | ||
53 | words.hi[2] = ata_get_word (0); | ||
54 | words.hi[3] = ata_get_word (0); | ||
55 | #else | ||
56 | words.hi[1] = ata_get_word (0); | ||
57 | words.hi[0] = ata_get_word (0); | ||
58 | words.hi[3] = ata_get_word (0); | ||
59 | words.hi[2] = ata_get_word (0); | ||
60 | #endif | ||
61 | for (end = fsi_sector->end1; data < end; ++data) | ||
62 | *data = ata_get_word (0); | ||
63 | #ifdef __little__ | ||
64 | fsi_sector->left_free_clusters = words.si[0]; | ||
65 | fsi_sector->next_free_cluster = words.si[1]; | ||
66 | #else | ||
67 | fsi_sector->left_free_clusters = swawSI (words.si[0]); | ||
68 | fsi_sector->next_free_cluster = swawSI (words.si[1]); | ||
69 | #endif | ||
70 | return ATA_RETURN_SUCCESS; | ||
71 | } | ||
72 | |||
73 | int __fat_put_fsi_sector_callback (struct __fat_fsi_sector *fsi_sector) | ||
74 | { | ||
75 | short *data = fsi_sector->data,*end; | ||
76 | union { unsigned long si[2]; unsigned short hi[4]; unsigned char qi[8]; } words; | ||
77 | #ifdef __little__ | ||
78 | words.si[0] = swawSI (fsi_sector->left_free_clusters); | ||
79 | words.si[1] = swawSI (fsi_sector->next_free_cluster); | ||
80 | #else | ||
81 | words.si[0] = swawSI (fsi_sector->left_free_clusters); | ||
82 | words.si[1] = swawSI (fsi_sector->next_free_cluster); | ||
83 | #endif | ||
84 | for (end = fsi_sector->end0; data < end;) | ||
85 | ata_put_word (*data++); | ||
86 | #ifdef __little__ | ||
87 | ata_put_word (words.hi[0],0); | ||
88 | ata_put_word (words.hi[1],0); | ||
89 | ata_put_word (words.hi[2],0); | ||
90 | ata_put_word (words.hi[3],0); | ||
91 | #else | ||
92 | ata_put_word (words.hi[1],0); | ||
93 | ata_put_word (words.hi[0],0); | ||
94 | ata_put_word (words.hi[3],0); | ||
95 | ata_put_word (words.hi[2],0); | ||
96 | #endif | ||
97 | for (end = fsi_sector->end1; data < end;) | ||
98 | ata_put_word (*data++); | ||
99 | return ATA_RETURN_SUCCESS; | ||
100 | } | ||
101 | |||
102 | // | ||
103 | /////////////////////////////////////////////////////////////////////////////////// | ||
104 | |||
105 | #endif \ No newline at end of file | ||