summaryrefslogtreecommitdiff
path: root/firmware/drivers
diff options
context:
space:
mode:
authorMarcin Bukat <marcin.bukat@gmail.com>2012-05-08 08:53:38 +0200
committerMarcin Bukat <marcin.bukat@gmail.com>2012-05-08 13:00:56 +0200
commit18c016b4e0262bc2e23a193fc7c8fb92907303b1 (patch)
treef7fec7d10ef99ffdbdb417e7d3ff0bb611e7f0f5 /firmware/drivers
parent10829b2f78de91f66c7da5f7a2a2fe6d252eb38d (diff)
downloadrockbox-18c016b4e0262bc2e23a193fc7c8fb92907303b1.tar.gz
rockbox-18c016b4e0262bc2e23a193fc7c8fb92907303b1.zip
Fix test fat failing on 64bit system (second bit of FS#12646)
We use unsigned long/long in number of places in fat.c. When this is used to cast 32bit fat field it fails on 64bit systems. This patch introduces explicit types (uint16_t, uint32_t) only in places which influence how fat structures are interpreted. Change-Id: I0be44d0b355f9de20b4deb221698d095f55d4bde Reviewed-on: http://gerrit.rockbox.org/232 Reviewed-by: Frank Gevaerts <frank@gevaerts.be> Reviewed-by: Torne Wuff <torne@wolfpuppy.org.uk>
Diffstat (limited to 'firmware/drivers')
-rw-r--r--firmware/drivers/fat.c62
1 files changed, 31 insertions, 31 deletions
diff --git a/firmware/drivers/fat.c b/firmware/drivers/fat.c
index 51b0cba372..e22f9507b0 100644
--- a/firmware/drivers/fat.c
+++ b/firmware/drivers/fat.c
@@ -131,9 +131,9 @@ static unsigned char FATLONG_NAME_SIZE[FATLONG_NAME_CHUNKS] = {10, 12, 4};
131#define FAT_LONGNAME_PAD_UCS 0xffff 131#define FAT_LONGNAME_PAD_UCS 0xffff
132 132
133struct fsinfo { 133struct fsinfo {
134 unsigned long freecount; /* last known free cluster count */ 134 uint32_t freecount; /* last known free cluster count */
135 unsigned long nextfree; /* first cluster to start looking for free 135 uint32_t nextfree; /* first cluster to start looking for free
136 clusters, or 0xffffffff for no hint */ 136 clusters, or 0xffffffff for no hint */
137}; 137};
138/* fsinfo offsets */ 138/* fsinfo offsets */
139#define FSINFO_FREECOUNT 488 139#define FSINFO_FREECOUNT 488
@@ -511,11 +511,11 @@ int fat_mount(IF_MV2(int volume,) IF_MD2(int drive,) long startsector)
511 fat_recalc_free(IF_MV(volume)); 511 fat_recalc_free(IF_MV(volume));
512 } 512 }
513 513
514 LDEBUGF("Freecount: %ld\n",fat_bpb->fsinfo.freecount); 514 LDEBUGF("Freecount: %ld\n",(unsigned long)fat_bpb->fsinfo.freecount);
515 LDEBUGF("Nextfree: 0x%lx\n",fat_bpb->fsinfo.nextfree); 515 LDEBUGF("Nextfree: 0x%lx\n",(unsigned long)fat_bpb->fsinfo.nextfree);
516 LDEBUGF("Cluster count: 0x%lx\n",fat_bpb->dataclusters); 516 LDEBUGF("Cluster count: 0x%lx\n",(unsigned long)fat_bpb->dataclusters);
517 LDEBUGF("Sectors per cluster: %d\n",fat_bpb->bpb_secperclus); 517 LDEBUGF("Sectors per cluster: %d\n",fat_bpb->bpb_secperclus);
518 LDEBUGF("FAT sectors: 0x%lx\n",fat_bpb->fatsize); 518 LDEBUGF("FAT sectors: 0x%lx\n",(unsigned long)fat_bpb->fatsize);
519 519
520#ifdef HAVE_MULTIVOLUME 520#ifdef HAVE_MULTIVOLUME
521 fat_bpb->mounted = true; 521 fat_bpb->mounted = true;
@@ -576,7 +576,7 @@ void fat_recalc_free(IF_MV_NONVOID(int volume))
576 { 576 {
577 for (i = 0; i<fat_bpb->fatsize; i++) { 577 for (i = 0; i<fat_bpb->fatsize; i++) {
578 unsigned int j; 578 unsigned int j;
579 unsigned short* fat = cache_fat_sector(IF_MV2(fat_bpb,) i, false); 579 uint16_t* fat = cache_fat_sector(IF_MV2(fat_bpb,) i, false);
580 for (j = 0; j < CLUSTERS_PER_FAT16_SECTOR; j++) { 580 for (j = 0; j < CLUSTERS_PER_FAT16_SECTOR; j++) {
581 unsigned int c = i * CLUSTERS_PER_FAT16_SECTOR + j; 581 unsigned int c = i * CLUSTERS_PER_FAT16_SECTOR + j;
582 if ( c > fat_bpb->dataclusters+1 ) /* nr 0 is unused */ 582 if ( c > fat_bpb->dataclusters+1 ) /* nr 0 is unused */
@@ -595,7 +595,7 @@ void fat_recalc_free(IF_MV_NONVOID(int volume))
595 { 595 {
596 for (i = 0; i<fat_bpb->fatsize; i++) { 596 for (i = 0; i<fat_bpb->fatsize; i++) {
597 unsigned int j; 597 unsigned int j;
598 unsigned long* fat = cache_fat_sector(IF_MV2(fat_bpb,) i, false); 598 uint32_t* fat = cache_fat_sector(IF_MV2(fat_bpb,) i, false);
599 for (j = 0; j < CLUSTERS_PER_FAT_SECTOR; j++) { 599 for (j = 0; j < CLUSTERS_PER_FAT_SECTOR; j++) {
600 unsigned long c = i * CLUSTERS_PER_FAT_SECTOR + j; 600 unsigned long c = i * CLUSTERS_PER_FAT_SECTOR + j;
601 if ( c > fat_bpb->dataclusters+1 ) /* nr 0 is unused */ 601 if ( c > fat_bpb->dataclusters+1 ) /* nr 0 is unused */
@@ -656,7 +656,7 @@ static int bpb_is_sane(IF_MV_NONVOID(struct bpb* fat_bpb))
656 fat_bpb->bpb_secperclus) 656 fat_bpb->bpb_secperclus)
657 { 657 {
658 DEBUGF( "bpb_is_sane() - Error: FSInfo.Freecount > disk size " 658 DEBUGF( "bpb_is_sane() - Error: FSInfo.Freecount > disk size "
659 "(0x%04lx)\n", fat_bpb->fsinfo.freecount); 659 "(0x%04lx)\n", (unsigned long)fat_bpb->fsinfo.freecount);
660 return -4; 660 return -4;
661 } 661 }
662 662
@@ -785,7 +785,7 @@ static unsigned long find_free_cluster(IF_MV2(struct bpb* fat_bpb,)
785 for (i = 0; i<fat_bpb->fatsize; i++) { 785 for (i = 0; i<fat_bpb->fatsize; i++) {
786 unsigned int j; 786 unsigned int j;
787 unsigned int nr = (i + sector) % fat_bpb->fatsize; 787 unsigned int nr = (i + sector) % fat_bpb->fatsize;
788 unsigned short* fat = cache_fat_sector(IF_MV2(fat_bpb,) nr, false); 788 uint16_t* fat = cache_fat_sector(IF_MV2(fat_bpb,) nr, false);
789 if ( !fat ) 789 if ( !fat )
790 break; 790 break;
791 for (j = 0; j < CLUSTERS_PER_FAT16_SECTOR; j++) { 791 for (j = 0; j < CLUSTERS_PER_FAT16_SECTOR; j++) {
@@ -813,7 +813,7 @@ static unsigned long find_free_cluster(IF_MV2(struct bpb* fat_bpb,)
813 for (i = 0; i<fat_bpb->fatsize; i++) { 813 for (i = 0; i<fat_bpb->fatsize; i++) {
814 unsigned int j; 814 unsigned int j;
815 unsigned long nr = (i + sector) % fat_bpb->fatsize; 815 unsigned long nr = (i + sector) % fat_bpb->fatsize;
816 unsigned long* fat = cache_fat_sector(IF_MV2(fat_bpb,) nr, false); 816 uint32_t* fat = cache_fat_sector(IF_MV2(fat_bpb,) nr, false);
817 if ( !fat ) 817 if ( !fat )
818 break; 818 break;
819 for (j = 0; j < CLUSTERS_PER_FAT_SECTOR; j++) { 819 for (j = 0; j < CLUSTERS_PER_FAT_SECTOR; j++) {
@@ -877,7 +877,7 @@ static int update_fat_entry(IF_MV2(struct bpb* fat_bpb,) unsigned long entry,
877 } 877 }
878 878
879 LDEBUGF("update_fat_entry: %lu free clusters\n", 879 LDEBUGF("update_fat_entry: %lu free clusters\n",
880 fat_bpb->fsinfo.freecount); 880 (unsigned long)fat_bpb->fsinfo.freecount);
881 881
882 sec[offset] = htole16(val); 882 sec[offset] = htole16(val);
883 } 883 }
@@ -886,7 +886,7 @@ static int update_fat_entry(IF_MV2(struct bpb* fat_bpb,) unsigned long entry,
886 { 886 {
887 long sector = entry / CLUSTERS_PER_FAT_SECTOR; 887 long sector = entry / CLUSTERS_PER_FAT_SECTOR;
888 int offset = entry % CLUSTERS_PER_FAT_SECTOR; 888 int offset = entry % CLUSTERS_PER_FAT_SECTOR;
889 unsigned long* sec; 889 uint32_t* sec;
890 890
891 LDEBUGF("update_fat_entry(%lx,%lx)\n",entry,val); 891 LDEBUGF("update_fat_entry(%lx,%lx)\n",entry,val);
892 892
@@ -914,7 +914,7 @@ static int update_fat_entry(IF_MV2(struct bpb* fat_bpb,) unsigned long entry,
914 } 914 }
915 915
916 LDEBUGF("update_fat_entry: %ld free clusters\n", 916 LDEBUGF("update_fat_entry: %ld free clusters\n",
917 fat_bpb->fsinfo.freecount); 917 (unsigned long)fat_bpb->fsinfo.freecount);
918 918
919 /* don't change top 4 bits */ 919 /* don't change top 4 bits */
920 sec[offset] &= htole32(0xf0000000); 920 sec[offset] &= htole32(0xf0000000);
@@ -950,7 +950,7 @@ static long read_fat_entry(IF_MV2(struct bpb* fat_bpb,) unsigned long entry)
950 { 950 {
951 long sector = entry / CLUSTERS_PER_FAT_SECTOR; 951 long sector = entry / CLUSTERS_PER_FAT_SECTOR;
952 int offset = entry % CLUSTERS_PER_FAT_SECTOR; 952 int offset = entry % CLUSTERS_PER_FAT_SECTOR;
953 unsigned long* sec; 953 uint32_t* sec;
954 954
955 sec = cache_fat_sector(IF_MV2(fat_bpb,) sector, false); 955 sec = cache_fat_sector(IF_MV2(fat_bpb,) sector, false);
956 if (!sec) 956 if (!sec)
@@ -993,7 +993,7 @@ static int update_fsinfo(IF_MV_NONVOID(struct bpb* fat_bpb))
993#ifndef HAVE_MULTIVOLUME 993#ifndef HAVE_MULTIVOLUME
994 struct bpb* fat_bpb = &fat_bpbs[0]; 994 struct bpb* fat_bpb = &fat_bpbs[0];
995#endif 995#endif
996 unsigned long* intptr; 996 uint32_t* intptr;
997 int rc; 997 int rc;
998 998
999#ifdef HAVE_FAT16SUPPORT 999#ifdef HAVE_FAT16SUPPORT
@@ -1011,10 +1011,10 @@ static int update_fsinfo(IF_MV_NONVOID(struct bpb* fat_bpb))
1011 DEBUGF( "update_fsinfo() - Couldn't read FSInfo (error code %d)", rc); 1011 DEBUGF( "update_fsinfo() - Couldn't read FSInfo (error code %d)", rc);
1012 return rc * 10 - 1; 1012 return rc * 10 - 1;
1013 } 1013 }
1014 intptr = (long*)&(fsinfo[FSINFO_FREECOUNT]); 1014 intptr = (uint32_t*)&(fsinfo[FSINFO_FREECOUNT]);
1015 *intptr = htole32(fat_bpb->fsinfo.freecount); 1015 *intptr = htole32(fat_bpb->fsinfo.freecount);
1016 1016
1017 intptr = (long*)&(fsinfo[FSINFO_NEXTFREE]); 1017 intptr = (uint32_t*)&(fsinfo[FSINFO_NEXTFREE]);
1018 *intptr = htole32(fat_bpb->fsinfo.nextfree); 1018 *intptr = htole32(fat_bpb->fsinfo.nextfree);
1019 1019
1020 rc = storage_write_sectors(IF_MD2(fat_bpb->drive,) 1020 rc = storage_write_sectors(IF_MD2(fat_bpb->drive,)
@@ -1625,8 +1625,8 @@ static void randomize_dos_name(unsigned char *name)
1625static int update_short_entry( struct fat_file* file, long size, int attr ) 1625static int update_short_entry( struct fat_file* file, long size, int attr )
1626{ 1626{
1627 int sector = file->direntry / DIR_ENTRIES_PER_SECTOR; 1627 int sector = file->direntry / DIR_ENTRIES_PER_SECTOR;
1628 unsigned long* sizeptr; 1628 uint32_t* sizeptr;
1629 unsigned short* clusptr; 1629 uint16_t* clusptr;
1630 struct fat_file dir; 1630 struct fat_file dir;
1631 int rc; 1631 int rc;
1632 1632
@@ -1660,28 +1660,28 @@ static int update_short_entry( struct fat_file* file, long size, int attr )
1660 1660
1661 entry[FATDIR_ATTR] = attr & 0xFF; 1661 entry[FATDIR_ATTR] = attr & 0xFF;
1662 1662
1663 clusptr = (short*)(entry + FATDIR_FSTCLUSHI); 1663 clusptr = (uint16_t*)(entry + FATDIR_FSTCLUSHI);
1664 *clusptr = htole16(file->firstcluster >> 16); 1664 *clusptr = htole16(file->firstcluster >> 16);
1665 1665
1666 clusptr = (short*)(entry + FATDIR_FSTCLUSLO); 1666 clusptr = (uint16_t*)(entry + FATDIR_FSTCLUSLO);
1667 *clusptr = htole16(file->firstcluster & 0xffff); 1667 *clusptr = htole16(file->firstcluster & 0xffff);
1668 1668
1669 sizeptr = (long*)(entry + FATDIR_FILESIZE); 1669 sizeptr = (uint32_t*)(entry + FATDIR_FILESIZE);
1670 *sizeptr = htole32(size); 1670 *sizeptr = htole32(size);
1671 1671
1672 { 1672 {
1673#if CONFIG_RTC 1673#if CONFIG_RTC
1674 unsigned short time = 0; 1674 uint16_t time = 0;
1675 unsigned short date = 0; 1675 uint16_t date = 0;
1676#else 1676#else
1677 /* get old time to increment from */ 1677 /* get old time to increment from */
1678 unsigned short time = htole16(*(unsigned short*)(entry+FATDIR_WRTTIME)); 1678 uint16_t time = htole16(*(uint16_t*)(entry+FATDIR_WRTTIME));
1679 unsigned short date = htole16(*(unsigned short*)(entry+FATDIR_WRTDATE)); 1679 uint16_t date = htole16(*(uint16_t*)(entry+FATDIR_WRTDATE));
1680#endif 1680#endif
1681 fat_time(&date, &time, NULL); 1681 fat_time(&date, &time, NULL);
1682 *(unsigned short*)(entry + FATDIR_WRTTIME) = htole16(time); 1682 *(uint16_t*)(entry + FATDIR_WRTTIME) = htole16(time);
1683 *(unsigned short*)(entry + FATDIR_WRTDATE) = htole16(date); 1683 *(uint16_t*)(entry + FATDIR_WRTDATE) = htole16(date);
1684 *(unsigned short*)(entry + FATDIR_LSTACCDATE) = htole16(date); 1684 *(uint16_t*)(entry + FATDIR_LSTACCDATE) = htole16(date);
1685 } 1685 }
1686 1686
1687 rc = fat_seek( &dir, sector ); 1687 rc = fat_seek( &dir, sector );