freemyipod r51 - Code Review

Jump to: navigation, search
Repository:freemyipod
Revision:r50‎ | r51 | r52 >
Date:13:41, 7 August 2010
Author:theseven
Status:new
Tags:
Comment:
Make fat.c compile
Modified paths:
  • /embios/trunk/fat.c (modified) (history)
  • /embios/trunk/target/ipodnano2g/target.h (modified) (history)

Diff [purge]

Index: embios/trunk/target/ipodnano2g/target.h
@@ -35,4 +35,7 @@
3636 #define USB_NUM_ENDPOINTS 5
3737
3838
 39+#define NUM_VOLUMES 1
 40+
 41+
3942 #endif
Index: embios/trunk/fat.c
@@ -208,12 +208,12 @@
209209
210210 static char fat_cache_sectors[FAT_CACHE_SIZE][SECTOR_SIZE];
211211 static struct fat_cache_entry fat_cache[FAT_CACHE_SIZE];
212 -static struct mutex cache_mutex SHAREDBSS_ATTR;
 212+static struct mutex cache_mutex;
213213
214214 #if defined(HAVE_HOTSWAP) && !(CONFIG_STORAGE & STORAGE_MMC) /* A better condition ?? */
215215 void fat_lock(void)
216216 {
217 - mutex_lock(&cache_mutex);
 217+ mutex_lock(&cache_mutex, TIMEOUT_BLOCK);
218218 }
219219
220220 void fat_unlock(void)
@@ -475,7 +475,7 @@
476476 else
477477 { /* volume is not accessible any more, e.g. MMC removed */
478478 int i;
479 - mutex_lock(&cache_mutex);
 479+ mutex_lock(&cache_mutex, TIMEOUT_BLOCK);
480480 for(i = 0;i < FAT_CACHE_SIZE;i++)
481481 {
482482 struct fat_cache_entry *fce = &fat_cache[i];
@@ -660,7 +660,7 @@
661661 unsigned char *sectorbuf = &fat_cache_sectors[cache_index][0];
662662 int rc;
663663
664 - mutex_lock(&cache_mutex); /* make changes atomic */
 664+ mutex_lock(&cache_mutex, TIMEOUT_BLOCK); /* make changes atomic */
665665
666666 /* Delete the cache entry if it isn't the sector we want */
667667 if(fce->inuse && (fce->secnum != secnum
@@ -970,7 +970,7 @@
971971 unsigned char *sec;
972972 DEBUGF("flush_fat()");
973973
974 - mutex_lock(&cache_mutex);
 974+ mutex_lock(&cache_mutex, TIMEOUT_BLOCK);
975975 for(i = 0;i < FAT_CACHE_SIZE;i++)
976976 {
977977 struct fat_cache_entry *fce = &fat_cache[i];
@@ -1013,81 +1013,11 @@
10141014 if (tenth)
10151015 *tenth = (tm->tm_sec & 1) * 100;
10161016 #else
1017 - /* non-RTC version returns an increment from the supplied time, or a
1018 - * fixed standard time/date if no time given as input */
10191017
1020 -/* Macros to convert a 2-digit string to a decimal constant.
1021 - (YEAR), MONTH and DAY are set by the date command, which outputs
1022 - DAY as 00..31 and MONTH as 01..12. The leading zero would lead to
1023 - misinterpretation as an octal constant. */
1024 -#define S100(x) 1 ## x
1025 -#define C2DIG2DEC(x) (S100(x)-100)
1026 -/* The actual build date, as FAT date constant */
1027 -#define BUILD_DATE_FAT (((YEAR - 1980) << 9) \
1028 - | (C2DIG2DEC(MONTH) << 5) \
1029 - | C2DIG2DEC(DAY))
 1018+ if (date) *date = (1 << 5) | 1;
 1019+ if (time) *time = 0;
 1020+ if (tenth) *tenth = 0;
10301021
1031 - bool date_forced = false;
1032 - bool next_day = false;
1033 - unsigned time2 = 0; /* double time, for CRTTIME with 1s precision */
1034 -
1035 - if (date && *date < BUILD_DATE_FAT)
1036 - {
1037 - *date = BUILD_DATE_FAT;
1038 - date_forced = true;
1039 - }
1040 -
1041 - if (time)
1042 - {
1043 - time2 = *time << 1;
1044 - if (time2 == 0 || date_forced)
1045 - {
1046 - time2 = (11 < 6) | 11; /* set to 00:11:11 */
1047 - }
1048 - else
1049 - {
1050 - unsigned mins = (time2 >> 6) & 0x3f;
1051 - unsigned hours = (time2 >> 12) & 0x1f;
1052 -
1053 - mins = 11 * ((mins/11) + 1); /* advance to next multiple of 11 */
1054 - if (mins > 59)
1055 - {
1056 - mins = 11; /* 00 would be a bad marker */
1057 - if (++hours > 23)
1058 - {
1059 - hours = 0;
1060 - next_day = true;
1061 - }
1062 - }
1063 - time2 = (hours << 12) | (mins << 6) | mins; /* secs = mins */
1064 - }
1065 - *time = time2 >> 1;
1066 - }
1067 -
1068 - if (tenth)
1069 - *tenth = (time2 & 1) * 100;
1070 -
1071 - if (date && next_day)
1072 - {
1073 - static const unsigned char daysinmonth[] =
1074 - {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
1075 - unsigned day = *date & 0x1f;
1076 - unsigned month = (*date >> 5) & 0x0f;
1077 - unsigned year = (*date >> 9) & 0x7f;
1078 -
1079 - /* simplification: ignore leap years */
1080 - if (++day > daysinmonth[month-1])
1081 - {
1082 - day = 1;
1083 - if (++month > 12)
1084 - {
1085 - month = 1;
1086 - year++;
1087 - }
1088 - }
1089 - *date = (year << 9) | (month << 5) | day;
1090 - }
1091 -
10921022 #endif /* CONFIG_RTC */
10931023 }
10941024
@@ -1104,7 +1034,7 @@
11051035 unsigned int sector = firstentry / DIR_ENTRIES_PER_SECTOR;
11061036 unsigned char chksum = 0;
11071037 unsigned int i, j=0;
1108 - unsigned int nameidx=0, namelen = utf8length(name);
 1038+ unsigned int nameidx=0, namelen = strlen(name);
11091039 int rc;
11101040 unsigned short name_utf16[namelen + 1];
11111041
@@ -1132,7 +1062,7 @@
11331063 /* we need to convert the name first */
11341064 /* since it is written in reverse order */
11351065 for (i = 0; i <= namelen; i++)
1136 - name = utf8decode(name, &name_utf16[i]);
 1066+ name_utf16[i] = *(name++);
11371067
11381068 for (i=0; i < numentries; i++) {
11391069 /* new sector? */
@@ -2456,7 +2386,7 @@
24572387 break;
24582388 /* utf8encode will return a pointer after the converted
24592389 * string, subtract the pointer to the start to get the length of it */
2460 - segm_utf8len = utf8encode(ucs, longname_utf8segm) - longname_utf8segm;
 2390+ segm_utf8len = 1;
24612391
24622392 /* warn the trailing zero ! (FAT_FILENAME_BYTES includes it) */
24632393 if (longname_utf8len + segm_utf8len >= FAT_FILENAME_BYTES) {
@@ -2465,6 +2395,8 @@
24662396 break; /* fallback later */
24672397 }
24682398 else {
 2399+ if (ucs < 128) longname_utf8segm[0] = (unsigned char)ucs;
 2400+ else longname_utf8segm[0] = '?';
24692401 longname_utf8segm[segm_utf8len] = 0;
24702402 strcat(entry->name + longname_utf8len, longname_utf8segm);
24712403 longname_utf8len += segm_utf8len;
@@ -2482,9 +2414,8 @@
24832415 are control characters. */
24842416 DEBUGF("SN-DOS: %s", shortname);
24852417 unsigned char *utf8;
2486 - utf8 = iso_decode(shortname, entry->name, -1,
2487 - strlen(shortname));
2488 - *utf8 = 0;
 2418+ memcpy(entry->name, shortname, strlen(shortname));
 2419+ *(entry->name + strlen(shortname)) = 0;
24892420 DEBUGF("SN: %s", entry->name);
24902421 } else {
24912422 DEBUGF("LN: %s", entry->name);