summaryrefslogtreecommitdiff
path: root/firmware/drivers
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/drivers
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/drivers')
-rw-r--r--firmware/drivers/fat.c59
-rw-r--r--firmware/drivers/fat.h3
2 files changed, 18 insertions, 44 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 6192d4619f..329e149a7a 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -133,25 +133,6 @@ static int fat_cache_dirty[256];
133static unsigned char lastsector[SECTOR_SIZE]; 133static unsigned char lastsector[SECTOR_SIZE];
134static unsigned char lastsector2[SECTOR_SIZE]; 134static unsigned char lastsector2[SECTOR_SIZE];
135 135
136#ifdef TEST_FAT
137
138int main(int argc, char *argv[])
139{
140 struct bpb bpb;
141
142 memset(fat_cache, 0, sizeof(fat_cache));
143 memset(fat_cache_dirty, 0, sizeof(fat_cache_dirty));
144
145 if(ata_init())
146 DEBUGF("*** Warning! The disk is uninitialized\n");
147 else
148 fat_mount(&bpb);
149
150 dbg_console(&bpb);
151 return 0;
152}
153#endif
154
155static int sec2cluster(struct bpb *bpb, unsigned int sec) 136static int sec2cluster(struct bpb *bpb, unsigned int sec)
156{ 137{
157 if ( sec < bpb->firstdatasector ) 138 if ( sec < bpb->firstdatasector )
@@ -183,7 +164,7 @@ static int first_sector_of_cluster(struct bpb *bpb, unsigned int cluster)
183 return (cluster - 2) * bpb->bpb_secperclus + bpb->firstdatasector; 164 return (cluster - 2) * bpb->bpb_secperclus + bpb->firstdatasector;
184} 165}
185 166
186int fat_mount(struct bpb *bpb) 167int fat_mount(struct bpb *bpb, int startsector)
187{ 168{
188 unsigned char buf[SECTOR_SIZE]; 169 unsigned char buf[SECTOR_SIZE];
189 int err; 170 int err;
@@ -191,7 +172,7 @@ int fat_mount(struct bpb *bpb)
191 int countofclusters; 172 int countofclusters;
192 173
193 /* Read the sector */ 174 /* Read the sector */
194 err = ata_read_sectors(0,1,buf); 175 err = ata_read_sectors(startsector,1,buf);
195 if(err) 176 if(err)
196 { 177 {
197 DEBUGF( "fat_mount() - Couldn't read BPB (error code %i)\n", 178 DEBUGF( "fat_mount() - Couldn't read BPB (error code %i)\n",
@@ -200,6 +181,7 @@ int fat_mount(struct bpb *bpb)
200 } 181 }
201 182
202 memset(bpb, 0, sizeof(struct bpb)); 183 memset(bpb, 0, sizeof(struct bpb));
184 bpb->startsector = startsector;
203 185
204 strncpy(bpb->bs_oemname, &buf[BS_OEMNAME], 8); 186 strncpy(bpb->bs_oemname, &buf[BS_OEMNAME], 8);
205 bpb->bs_oemname[8] = 0; 187 bpb->bs_oemname[8] = 0;
@@ -306,20 +288,6 @@ static int bpb_is_sane(struct bpb *bpb)
306 DEBUGF( "bpb_is_sane() - Warning: RootEntCnt is not 512 (%i)\n", 288 DEBUGF( "bpb_is_sane() - Warning: RootEntCnt is not 512 (%i)\n",
307 bpb->bpb_rootentcnt); 289 bpb->bpb_rootentcnt);
308 } 290 }
309 if(bpb->bpb_totsec16 < 200)
310 {
311 if(bpb->bpb_totsec16 == 0)
312 {
313 DEBUGF( "bpb_is_sane() - Error: TotSec16 is 0\n");
314 return -1;
315 }
316 else
317 {
318 DEBUGF( "bpb_is_sane() - Warning: TotSec16 "
319 "is quite small (%i)\n",
320 bpb->bpb_totsec16);
321 }
322 }
323 if(bpb->bpb_media != 0xf0 && bpb->bpb_media < 0xf8) 291 if(bpb->bpb_media != 0xf0 && bpb->bpb_media < 0xf8)
324 { 292 {
325 DEBUGF( "bpb_is_sane() - Warning: Non-standard " 293 DEBUGF( "bpb_is_sane() - Warning: Non-standard "
@@ -349,7 +317,7 @@ static void *cache_fat_sector(struct bpb *bpb, int secnum)
349 DEBUGF( "cache_fat_sector() - Out of memory\n"); 317 DEBUGF( "cache_fat_sector() - Out of memory\n");
350 return NULL; 318 return NULL;
351 } 319 }
352 if(ata_read_sectors(secnum,1,sec)) 320 if(ata_read_sectors(secnum+bpb->startsector,1,sec))
353 { 321 {
354 DEBUGF( "cache_fat_sector() - Could" 322 DEBUGF( "cache_fat_sector() - Could"
355 " not read sector %d\n", 323 " not read sector %d\n",
@@ -447,14 +415,17 @@ static int flush_fat(struct bpb *bpb)
447 { 415 {
448 DEBUGF("Flushing FAT sector %d\n", i); 416 DEBUGF("Flushing FAT sector %d\n", i);
449 sec = fat_cache[i]; 417 sec = fat_cache[i];
450 err = ata_write_sectors(i + bpb->bpb_rsvdseccnt,1,sec); 418 err = ata_write_sectors(i + bpb->bpb_rsvdseccnt + bpb->startsector,
419 1,sec);
451 if(err) 420 if(err)
452 { 421 {
453 DEBUGF( "flush_fat() - Couldn't write" 422 DEBUGF( "flush_fat() - Couldn't write"
454 " sector (%d)\n", i + bpb->bpb_rsvdseccnt); 423 " sector (%d)\n", i + bpb->bpb_rsvdseccnt);
455 return -1; 424 return -1;
456 } 425 }
457 err = ata_write_sectors(i + bpb->bpb_rsvdseccnt + fatsz,1,sec); 426 err = ata_write_sectors(i + bpb->bpb_rsvdseccnt + fatsz +
427 bpb->startsector,
428 1,sec);
458 if(err) 429 if(err)
459 { 430 {
460 DEBUGF( "flush_fat() - Couldn't write" 431 DEBUGF( "flush_fat() - Couldn't write"
@@ -559,7 +530,7 @@ static int add_dir_entry(struct bpb *bpb,
559 530
560 DEBUGF("Reading sector %d...\n", sec); 531 DEBUGF("Reading sector %d...\n", sec);
561 /* Read the next sector in the current dir */ 532 /* Read the next sector in the current dir */
562 err = ata_read_sectors(sec,1,buf); 533 err = ata_read_sectors(sec + bpb->startsector,1,buf);
563 if(err) 534 if(err)
564 { 535 {
565 DEBUGF( "add_dir_entry() - Couldn't read dir sector" 536 DEBUGF( "add_dir_entry() - Couldn't read dir sector"
@@ -624,7 +595,7 @@ static int add_dir_entry(struct bpb *bpb,
624 } 595 }
625 } 596 }
626 597
627 err = ata_write_sectors(sec,1,buf); 598 err = ata_write_sectors(sec + bpb->startsector,1,buf);
628 if(err) 599 if(err)
629 { 600 {
630 DEBUGF( "add_dir_entry() - " 601 DEBUGF( "add_dir_entry() - "
@@ -821,7 +792,8 @@ int fat_read(struct bpb *bpb,
821 int err, i; 792 int err, i;
822 793
823 for ( i=0; i<sectorcount; i++ ) { 794 for ( i=0; i<sectorcount; i++ ) {
824 err = ata_read_sectors(sector,1,(char*)buf+(i*SECTOR_SIZE)); 795 err = ata_read_sectors(sector + bpb->startsector, 1,
796 (char*)buf+(i*SECTOR_SIZE));
825 if(err) { 797 if(err) {
826 DEBUGF( "fat_read() - Couldn't read sector %d" 798 DEBUGF( "fat_read() - Couldn't read sector %d"
827 " (error code %i)\n", sector,err); 799 " (error code %i)\n", sector,err);
@@ -898,7 +870,7 @@ int fat_opendir(struct bpb *bpb,
898 } 870 }
899 871
900 /* Read the first sector in the current dir */ 872 /* Read the first sector in the current dir */
901 err = ata_read_sectors(sec,1,ent->cached_buf); 873 err = ata_read_sectors(sec + bpb->startsector,1,ent->cached_buf);
902 if(err) 874 if(err)
903 { 875 {
904 DEBUGF( "fat_getfirst() - Couldn't read dir sector" 876 DEBUGF( "fat_getfirst() - Couldn't read dir sector"
@@ -1037,7 +1009,8 @@ int fat_getnext(struct bpb *bpb,
1037 } 1009 }
1038 1010
1039 /* Read the next sector */ 1011 /* Read the next sector */
1040 err = ata_read_sectors(ent->cached_sec,1,ent->cached_buf); 1012 err = ata_read_sectors(ent->cached_sec + bpb->startsector, 1,
1013 ent->cached_buf);
1041 if(err) 1014 if(err)
1042 { 1015 {
1043 DEBUGF( "fat_getnext() - Couldn't read dir sector" 1016 DEBUGF( "fat_getnext() - Couldn't read dir sector"
diff --git a/firmware/drivers/fat.h b/firmware/drivers/fat.h
index 7f014a8aa1..faec5384dd 100644
--- a/firmware/drivers/fat.h
+++ b/firmware/drivers/fat.h
@@ -60,6 +60,7 @@ struct bpb
60 int totalsectors; 60 int totalsectors;
61 int rootdirsector; 61 int rootdirsector;
62 int firstdatasector; 62 int firstdatasector;
63 int startsector;
63}; 64};
64 65
65struct fat_direntry 66struct fat_direntry
@@ -100,7 +101,7 @@ struct fat_fileent
100 int sectornum; /* sector number in this cluster */ 101 int sectornum; /* sector number in this cluster */
101}; 102};
102 103
103extern int fat_mount(struct bpb *bpb); 104extern int fat_mount(struct bpb *bpb, int startsector);
104 105
105#ifdef DISK_WRITE 106#ifdef DISK_WRITE
106extern int fat_create_file(struct bpb *bpb, 107extern int fat_create_file(struct bpb *bpb,