freemyipod r47 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r46‎ | r47 | r48 >
Date:05:20, 7 August 2010
Author:farthen
Status:new
Tags:
Comment:
Make the rockbox fat code compile except for the mutex stuff in disk.c
Modified paths:
  • /embios/trunk/SOURCES (modified) (history)
  • /embios/trunk/disk.c (modified) (history)
  • /embios/trunk/fat.c (modified) (history)
  • /embios/trunk/fat.h (modified) (history)
  • /embios/trunk/file.c (modified) (history)

Diff [purge]

Index: embios/trunk/disk.c
@@ -19,7 +19,6 @@
2020 *
2121 ****************************************************************************/
2222 #include <stdio.h>
23 -#include "kernel.h"
2423 #include "storage.h"
2524 #include "debug.h"
2625 #include "fat.h"
@@ -67,8 +66,8 @@
6867 int i;
6968 unsigned char sector[SECTOR_SIZE];
7069 #ifdef HAVE_MULTIDRIVE
71 - /* For each drive, start at a different position, in order not to destroy
72 - the first entry of drive 0.
 70+ /* For each drive, start at a different position, in order not to destroy
 71+ the first entry of drive 0.
7372 That one is needed to calculate config sector position. */
7473 struct partinfo* pinfo = &part[drive*4];
7574 if ((size_t)drive >= sizeof(part)/sizeof(*part)/4)
Index: embios/trunk/SOURCES
@@ -35,3 +35,5 @@
3636 usb/usb.c
3737 shutdown.c
3838 syscall.c
 39+disk.c
 40+fat32.c
Index: embios/trunk/fat.c
@@ -31,8 +31,6 @@
3232 #include "timefuncs.h"
3333 #include "kernel.h"
3434 #include "rbunicode.h"
35 -/*#define LOGF_ENABLE*/
36 -#include "logf.h"
3735
3836 #define BYTES2INT16(array,pos) \
3937 (array[pos] | (array[pos+1] << 8 ))
@@ -450,11 +448,11 @@
451449 fat_recalc_free(IF_MV(volume));
452450 }
453451
454 - LDEBUGF("Freecount: %ld\n",fat_bpb->fsinfo.freecount);
455 - LDEBUGF("Nextfree: 0x%lx\n",fat_bpb->fsinfo.nextfree);
456 - LDEBUGF("Cluster count: 0x%lx\n",fat_bpb->dataclusters);
457 - LDEBUGF("Sectors per cluster: %d\n",fat_bpb->bpb_secperclus);
458 - LDEBUGF("FAT sectors: 0x%lx\n",fat_bpb->fatsize);
 452+ DEBUGF("Freecount: %ld\n",fat_bpb->fsinfo.freecount);
 453+ DEBUGF("Nextfree: 0x%lx\n",fat_bpb->fsinfo.nextfree);
 454+ DEBUGF("Cluster count: 0x%lx\n",fat_bpb->dataclusters);
 455+ DEBUGF("Sectors per cluster: %d\n",fat_bpb->bpb_secperclus);
 456+ DEBUGF("FAT sectors: 0x%lx\n",fat_bpb->fatsize);
459457
460458 #ifdef HAVE_MULTIVOLUME
461459 fat_bpb->mounted = true;
@@ -737,7 +735,7 @@
738736 cluster numbers out of bounds */
739737 if ( c < 2 || c > fat_bpb->dataclusters+1 )
740738 continue;
741 - LDEBUGF("find_free_cluster(%x) == %x\n",startcluster,c);
 739+ DEBUGF("find_free_cluster(%x) == %x\n",startcluster,c);
742740 fat_bpb->fsinfo.nextfree = c;
743741 return c;
744742 }
@@ -765,7 +763,7 @@
766764 cluster numbers out of bounds */
767765 if ( c < 2 || c > fat_bpb->dataclusters+1 )
768766 continue;
769 - LDEBUGF("find_free_cluster(%lx) == %lx\n",startcluster,c);
 767+ DEBUGF("find_free_cluster(%lx) == %lx\n",startcluster,c);
770768 fat_bpb->fsinfo.nextfree = c;
771769 return c;
772770 }
@@ -774,7 +772,7 @@
775773 }
776774 }
777775
778 - LDEBUGF("find_free_cluster(%lx) == 0\n",startcluster);
 776+ DEBUGF("find_free_cluster(%lx) == 0\n",startcluster);
779777 return 0; /* 0 is an illegal cluster number */
780778 }
781779
@@ -793,7 +791,7 @@
794792
795793 val &= 0xFFFF;
796794
797 - LDEBUGF("update_fat_entry(%x,%x)\n",entry,val);
 795+ DEBUGF("update_fat_entry(%x,%x)\n",entry,val);
798796
799797 if (entry==val)
800798 panicf("Creating FAT loop: %lx,%lx\n",entry,val);
@@ -817,7 +815,7 @@
818816 fat_bpb->fsinfo.freecount++;
819817 }
820818
821 - LDEBUGF("update_fat_entry: %d free clusters\n",
 819+ DEBUGF("update_fat_entry: %d free clusters\n",
822820 fat_bpb->fsinfo.freecount);
823821
824822 sec[offset] = htole16(val);
@@ -829,7 +827,7 @@
830828 int offset = entry % CLUSTERS_PER_FAT_SECTOR;
831829 unsigned long* sec;
832830
833 - LDEBUGF("update_fat_entry(%lx,%lx)\n",entry,val);
 831+ DEBUGF("update_fat_entry(%lx,%lx)\n",entry,val);
834832
835833 if (entry==val)
836834 panicf("Creating FAT loop: %lx,%lx\n",entry,val);
@@ -854,7 +852,7 @@
855853 fat_bpb->fsinfo.freecount++;
856854 }
857855
858 - LDEBUGF("update_fat_entry: %ld free clusters\n",
 856+ DEBUGF("update_fat_entry: %ld free clusters\n",
859857 fat_bpb->fsinfo.freecount);
860858
861859 /* don't change top 4 bits */
@@ -973,7 +971,7 @@
974972 int i;
975973 int rc;
976974 unsigned char *sec;
977 - LDEBUGF("flush_fat()\n");
 975+ DEBUGF("flush_fat()\n");
978976
979977 mutex_lock(&cache_mutex);
980978 for(i = 0;i < FAT_CACHE_SIZE;i++)
@@ -1113,7 +1111,7 @@
11141112 int rc;
11151113 unsigned short name_utf16[namelen + 1];
11161114
1117 - LDEBUGF("write_long_name(file:%lx, first:%d, num:%d, name:%s)\n",
 1115+ DEBUGF("write_long_name(file:%lx, first:%d, num:%d, name:%s)\n",
11181116 file->firstcluster, firstentry, numentries, name);
11191117
11201118 rc = fat_seek(file, sector);
@@ -1154,7 +1152,7 @@
11551153 /* read next sector */
11561154 rc = fat_readwrite(file, 1, buf, false);
11571155 if (rc<0) {
1158 - LDEBUGF("Failed writing new sector: %d\n",rc);
 1156+ DEBUGF("Failed writing new sector: %d\n",rc);
11591157 return rc * 10 - 5;
11601158 }
11611159 if (rc==0)
@@ -1207,12 +1205,12 @@
12081206 entry[FATDIR_FSTCLUSLO] = 0;
12091207 entry[FATLONG_TYPE] = 0;
12101208 entry[FATLONG_CHKSUM] = chksum;
1211 - LDEBUGF("Longname entry %d: %s\n", idx, name+nameidx);
 1209+ DEBUGF("Longname entry %d: %s\n", idx, name+nameidx);
12121210 }
12131211 else {
12141212 /* shortname entry */
12151213 unsigned short date=0, time=0, tenth=0;
1216 - LDEBUGF("Shortname entry: %s\n", shortname);
 1214+ DEBUGF("Shortname entry: %s\n", shortname);
12171215 memcpy(entry + FATDIR_NAME, shortname, 11);
12181216 entry[FATDIR_ATTR] = is_directory?FAT_ATTR_DIRECTORY:0;
12191217 entry[FATDIR_NTRES] = 0;
@@ -1282,7 +1280,7 @@
12831281 int entries_needed, entries_found = 0;
12841282 int firstentry;
12851283
1286 - LDEBUGF( "add_dir_entry(%s,%lx)\n",
 1284+ DEBUGF( "add_dir_entry(%s,%lx)\n",
12871285 name, file->firstcluster);
12881286
12891287 /* Don't check dotdirs name for validity */
@@ -1335,7 +1333,7 @@
13361334 }
13371335
13381336 if (rc == 0) { /* current end of dir reached */
1339 - LDEBUGF("End of dir on cluster boundary\n");
 1337+ DEBUGF("End of dir on cluster boundary\n");
13401338 break;
13411339 }
13421340
@@ -1345,7 +1343,7 @@
13461344 switch (buf[i * DIR_ENTRY_SIZE]) {
13471345 case 0:
13481346 entries_found += DIR_ENTRIES_PER_SECTOR - i;
1349 - LDEBUGF("Found end of dir %d\n",
 1347+ DEBUGF("Found end of dir %d\n",
13501348 sector * DIR_ENTRIES_PER_SECTOR + i);
13511349 i = DIR_ENTRIES_PER_SECTOR - 1;
13521350 done = true;
@@ -1353,7 +1351,7 @@
13541352
13551353 case 0xe5:
13561354 entries_found++;
1357 - LDEBUGF("Found free entry %d (%d/%d)\n",
 1355+ DEBUGF("Found free entry %d (%d/%d)\n",
13581356 sector * DIR_ENTRIES_PER_SECTOR + i,
13591357 entries_found, entries_needed);
13601358 break;
@@ -1365,7 +1363,7 @@
13661364 if (!strncmp(shortname, buf + i * DIR_ENTRY_SIZE, 11)) {
13671365 /* shortname exists already, make a new one */
13681366 randomize_dos_name(shortname);
1369 - LDEBUGF("Duplicate shortname, changing to %s\n",
 1367+ DEBUGF("Duplicate shortname, changing to %s\n",
13701368 shortname);
13711369
13721370 /* name has changed, we need to restart search */
@@ -1382,7 +1380,7 @@
13831381 /* step 2: extend the dir if necessary */
13841382 if (firstentry < 0)
13851383 {
1386 - LDEBUGF("Adding new sector(s) to dir\n");
 1384+ DEBUGF("Adding new sector(s) to dir\n");
13871385 rc = fat_seek(&dir->file, sector);
13881386 if (rc < 0)
13891387 return rc * 10 - 4;
@@ -1407,7 +1405,7 @@
14081406
14091407 /* step 3: add entry */
14101408 sector = firstentry / DIR_ENTRIES_PER_SECTOR;
1411 - LDEBUGF("Adding longname to entry %d in sector %d\n",
 1409+ DEBUGF("Adding longname to entry %d in sector %d\n",
14121410 firstentry, sector);
14131411
14141412 rc = write_long_name(&dir->file, firstentry,
@@ -1419,7 +1417,7 @@
14201418 file->direntry = firstentry + entries_needed - 1;
14211419 file->direntries = entries_needed;
14221420 file->dircluster = dir->file.firstcluster;
1423 - LDEBUGF("Added new dir entry %d, using %d slots.\n",
 1421+ DEBUGF("Added new dir entry %d, using %d slots.\n",
14241422 file->direntry, file->direntries);
14251423
14261424 return 0;
@@ -1540,7 +1538,7 @@
15411539 struct fat_file dir;
15421540 int rc;
15431541
1544 - LDEBUGF("update_file_size(cluster:%lx entry:%d size:%ld)\n",
 1542+ DEBUGF("update_file_size(cluster:%lx entry:%d size:%ld)\n",
15451543 file->firstcluster, file->direntry, size);
15461544
15471545 /* create a temporary file handle for the dir holding this file */
@@ -1661,12 +1659,12 @@
16621660 /* fixme: remove error check when done */
16631661 if (volume >= NUM_VOLUMES || !fat_bpbs[volume].mounted)
16641662 {
1665 - LDEBUGF("fat_open() illegal volume %d\n", volume);
 1663+ DEBUGF("fat_open() illegal volume %d\n", volume);
16661664 return -1;
16671665 }
16681666 #endif
16691667
1670 - LDEBUGF("fat_open(%lx), entry %d\n",startcluster,file->direntry);
 1668+ DEBUGF("fat_open(%lx), entry %d\n",startcluster,file->direntry);
16711669 return 0;
16721670 }
16731671
@@ -1676,7 +1674,7 @@
16771675 {
16781676 int rc;
16791677
1680 - LDEBUGF("fat_create_file(\"%s\",%lx,%lx)\n",name,(long)file,(long)dir);
 1678+ DEBUGF("fat_create_file(\"%s\",%lx,%lx)\n",name,(long)file,(long)dir);
16811679 rc = add_dir_entry(dir, file, name, false, false);
16821680 if (!rc) {
16831681 file->firstcluster = 0;
@@ -1705,7 +1703,7 @@
17061704 int rc;
17071705 struct fat_file dummyfile;
17081706
1709 - LDEBUGF("fat_create_dir(\"%s\",%lx,%lx)\n",name,(long)newdir,(long)dir);
 1707+ DEBUGF("fat_create_dir(\"%s\",%lx,%lx)\n",name,(long)newdir,(long)dir);
17101708
17111709 memset(newdir, 0, sizeof(struct fat_dir));
17121710 memset(&dummyfile, 0, sizeof(struct fat_file));
@@ -1770,7 +1768,7 @@
17711769 struct bpb* fat_bpb = &fat_bpbs[file->volume];
17721770 #endif
17731771
1774 - LDEBUGF("fat_truncate(%lx, %lx)\n", file->firstcluster, last);
 1772+ DEBUGF("fat_truncate(%lx, %lx)\n", file->firstcluster, last);
17751773
17761774 for ( last = get_next_cluster(IF_MV2(fat_bpb,) last); last; last = next ) {
17771775 next = get_next_cluster(IF_MV2(fat_bpb,) last);
@@ -1788,7 +1786,7 @@
17891787 #ifdef HAVE_MULTIVOLUME
17901788 struct bpb* fat_bpb = &fat_bpbs[file->volume];
17911789 #endif
1792 - LDEBUGF("fat_closewrite(size=%ld)\n",size);
 1790+ DEBUGF("fat_closewrite(size=%ld)\n",size);
17931791
17941792 if (!size) {
17951793 /* empty file */
@@ -1819,11 +1817,11 @@
18201818 long next;
18211819 for ( next = file->firstcluster; next;
18221820 next = get_next_cluster(IF_MV2(fat_bpb,) next) ) {
1823 - LDEBUGF("cluster %ld: %lx\n", count, next);
 1821+ DEBUGF("cluster %ld: %lx\n", count, next);
18241822 count++;
18251823 }
18261824 len = count * fat_bpb->bpb_secperclus * SECTOR_SIZE;
1827 - LDEBUGF("File is %ld clusters (chainlen=%ld, size=%ld)\n",
 1825+ DEBUGF("File is %ld clusters (chainlen=%ld, size=%ld)\n",
18281826 count, len, size );
18291827 if ( len > size + fat_bpb->bpb_secperclus * SECTOR_SIZE)
18301828 panicf("Cluster chain is too long\n");
@@ -1859,7 +1857,7 @@
18601858 return rc * 10 - 3;
18611859
18621860 for (i=0; i < numentries; i++) {
1863 - LDEBUGF("Clearing dir entry %d (%d/%d)\n",
 1861+ DEBUGF("Clearing dir entry %d (%d/%d)\n",
18641862 entry, i+1, numentries);
18651863 buf[(entry % DIR_ENTRIES_PER_SECTOR) * DIR_ENTRY_SIZE] = 0xe5;
18661864 entry++;
@@ -1906,7 +1904,7 @@
19071905 struct bpb* fat_bpb = &fat_bpbs[file->volume];
19081906 #endif
19091907
1910 - LDEBUGF("fat_remove(%lx)\n",last);
 1908+ DEBUGF("fat_remove(%lx)\n",last);
19111909
19121910 while ( last ) {
19131911 next = get_next_cluster(IF_MV2(fat_bpb,) last);
@@ -2045,7 +2043,7 @@
20462044 long cluster = 0;
20472045 long sector;
20482046
2049 - LDEBUGF("next_write_cluster(%lx,%lx)\n",file->firstcluster, oldcluster);
 2047+ DEBUGF("next_write_cluster(%lx,%lx)\n",file->firstcluster, oldcluster);
20502048
20512049 if (oldcluster)
20522050 cluster = get_next_cluster(IF_MV2(fat_bpb,) oldcluster);
@@ -2094,7 +2092,7 @@
20952093 #endif
20962094 int rc;
20972095
2098 - LDEBUGF("transfer(s=%lx, c=%lx, %s)\n",
 2096+ DEBUGF("transfer(s=%lx, c=%lx, %s)\n",
20992097 start+ fat_bpb->startsector, count, write?"write":"read");
21002098 if (write) {
21012099 unsigned long firstallowed;
@@ -2143,9 +2141,9 @@
21442142 long i;
21452143 int rc;
21462144
2147 - LDEBUGF( "fat_readwrite(file:%lx,count:0x%lx,buf:%lx,%s)\n",
 2145+ DEBUGF( "fat_readwrite(file:%lx,count:0x%lx,buf:%lx,%s)\n",
21482146 file->firstcluster,sectorcount,(long)buf,write?"write":"read");
2149 - LDEBUGF( "fat_readwrite: sec=%lx numsec=%ld eof=%d\n",
 2147+ DEBUGF( "fat_readwrite: sec=%lx numsec=%ld eof=%d\n",
21502148 sector,numsec, eof?1:0);
21512149
21522150 if ( eof && !write)
@@ -2286,7 +2284,7 @@
22872285 sectornum = -1;
22882286 }
22892287
2290 - LDEBUGF("fat_seek(%lx, %lx) == %lx, %lx, %lx\n",
 2288+ DEBUGF("fat_seek(%lx, %lx) == %lx, %lx, %lx\n",
22912289 file->firstcluster, seeksector, cluster, sector, sectornum);
22922290
22932291 file->lastcluster = cluster;
@@ -2305,7 +2303,7 @@
23062304 /* fixme: remove error check when done */
23072305 if (volume >= NUM_VOLUMES || !fat_bpbs[volume].mounted)
23082306 {
2309 - LDEBUGF("fat_open() illegal volume %d\n", volume);
 2307+ DEBUGF("fat_open() illegal volume %d\n", volume);
23102308 return -1;
23112309 }
23122310 #else
@@ -2405,7 +2403,7 @@
24062404 else {
24072405 /* check orphan entry */
24082406 if (nb_longs == 0) {
2409 - logf("fat warning: orphan LFN entry");
 2407+ DEBUGF("fat warning: orphan LFN entry");
24102408 /* ignore */
24112409 continue;
24122410 }
@@ -2412,7 +2410,7 @@
24132411
24142412 /* check order */
24152413 if (order != (last_long_ord - 1)) {
2416 - logf("fat warning: wrong LFN ordinal");
 2414+ DEBUGF("fat warning: wrong LFN ordinal");
24172415 /* ignore the whole LFN, will trigger lots of warnings */
24182416 nb_longs = 0;
24192417 }
@@ -2485,15 +2483,15 @@
24862484 Beware: this file will be shown with strange
24872485 glyphs in file browser since unicode 0x80 to 0x9F
24882486 are control characters. */
2489 - logf("SN-DOS: %s", shortname);
 2487+ DEBUGF("SN-DOS: %s", shortname);
24902488 unsigned char *utf8;
24912489 utf8 = iso_decode(shortname, entry->name, -1,
24922490 strlen(shortname));
24932491 *utf8 = 0;
2494 - logf("SN: %s", entry->name);
 2492+ DEBUGF("SN: %s", entry->name);
24952493 } else {
2496 - logf("LN: %s", entry->name);
2497 - logf("LNLen: %d", longname_utf8len);
 2494+ DEBUGF("LN: %s", entry->name);
 2495+ DEBUGF("LNLen: %d", longname_utf8len);
24982496 }
24992497 }
25002498 done = true;
Index: embios/trunk/fat.h
@@ -115,13 +115,13 @@
116116 extern int fat_create_file(const char* name,
117117 struct fat_file* ent,
118118 struct fat_dir* dir);
119 -extern long fat_readwrite(struct fat_file *ent, long sectorcount,
 119+extern long fat_readwrite(struct fat_file *ent, long sectorcount,
120120 void* buf, bool write );
121121 extern int fat_closewrite(struct fat_file *ent, long size, int attr);
122122 extern int fat_seek(struct fat_file *ent, unsigned long sector );
123123 extern int fat_remove(struct fat_file *ent);
124124 extern int fat_truncate(const struct fat_file *ent);
125 -extern int fat_rename(struct fat_file* file,
 125+extern int fat_rename(struct fat_file* file,
126126 struct fat_dir* dir,
127127 const unsigned char* newname,
128128 long size, int attr);
Index: embios/trunk/file.c
@@ -34,7 +34,7 @@
3535
3636 Since the fat32 driver only manages sectors, we maintain a one-sector
3737 cache for each open file. This way we can provide byte access without
38 - having to re-read the sector each time.
 38+ having to re-read the sector each time.
3939 The penalty is the RAM used for the cache and slightly more complex code.
4040 */
4141
@@ -73,7 +73,7 @@
7474 (void)use_cache;
7575 #endif
7676
77 - LDEBUGF("open(\"%s\",%d)\n",pathname,flags);
 77+ DEBUGF("open(\"%s\",%d)\n",pathname,flags);
7878
7979 if ( pathname[0] != '/' ) {
8080 DEBUGF("'%s' is not an absolute path.\n",pathname);
@@ -176,7 +176,7 @@
177177 }
178178
179179 if ( !entry ) {
180 - LDEBUGF("Didn't find file %s\n",name);
 180+ DEBUGF("Didn't find file %s\n",name);
181181 if ( file->write && (flags & O_CREAT) ) {
182182 rc = fat_create_file(name,
183183 &(file->fatfile),
@@ -239,7 +239,7 @@
240240 struct filedesc* file = &openfiles[fd];
241241 int rc = 0;
242242
243 - LDEBUGF("close(%d)\n", fd);
 243+ DEBUGF("close(%d)\n", fd);
244244
245245 if (fd < 0 || fd > MAX_OPEN_FILES-1) {
246246 errno = EINVAL;
@@ -268,7 +268,7 @@
269269 struct filedesc* file = &openfiles[fd];
270270 int rc = 0;
271271
272 - LDEBUGF("fsync(%d)\n", fd);
 272+ DEBUGF("fsync(%d)\n", fd);
273273
274274 if (fd < 0 || fd > MAX_OPEN_FILES-1) {
275275 errno = EINVAL;
@@ -516,7 +516,7 @@
517517 return -1;
518518 }
519519
520 - LDEBUGF( "readwrite(%d,%lx,%ld,%s)\n",
 520+ DEBUGF( "readwrite(%d,%lx,%ld,%s)\n",
521521 fd,(long)buf,count,write?"write":"read");
522522
523523 /* attempt to read past EOF? */
@@ -606,7 +606,7 @@
607607 if (write) {
608608 if ( file->fileoffset + nread < file->size ) {
609609 /* sector is only partially filled. copy-back from disk */
610 - LDEBUGF("Copy-back tail cache\n");
 610+ DEBUGF("Copy-back tail cache\n");
611611 rc = fat_readwrite(&(file->fatfile), 1, file->cache, false );
612612 if ( rc < 0 ) {
613613 DEBUGF("Failed writing\n");
@@ -663,7 +663,7 @@
664664 }
665665
666666 file->fileoffset += nread;
667 - LDEBUGF("fileoffset: %ld\n", file->fileoffset);
 667+ DEBUGF("fileoffset: %ld\n", file->fileoffset);
668668
669669 /* adjust file size to length written */
670670 if ( write && file->fileoffset > file->size )
@@ -701,7 +701,7 @@
702702 int rc;
703703 struct filedesc* file = &openfiles[fd];
704704
705 - LDEBUGF("lseek(%d,%ld,%d)\n",fd,offset,whence);
 705+ DEBUGF("lseek(%d,%ld,%d)\n",fd,offset,whence);
706706
707707 if (fd < 0 || fd > MAX_OPEN_FILES-1) {
708708 errno = EINVAL;