@@ -446,35 +446,6 @@ static enum PathMatch comparePath(const char *path) {
446446 return NOT_MATCH ;
447447}
448448
449- // Check if a TOC Entry matches our extension list
450- static int compareTocEntry (char * filename , const char * extensions ) {
451- static char ext_list [129 ];
452-
453- char * token ;
454-
455-
456- strncpy (ext_list , extensions , 128 );
457- ext_list [128 ] = 0 ;
458-
459- token = strtok (ext_list , " ," );
460- while (token != NULL ) {
461- char * ext_point ;
462-
463- // if 'token' matches extension of 'filename'
464- // then return a match
465- ext_point = strrchr (filename , '.' );
466-
467- if (strcasecmp (ext_point , token ) == 0 )
468- return TRUE;
469-
470- /* Get next token: */
471- token = strtok (NULL , " ," );
472- }
473-
474- // If not match found then return FALSE
475- return FALSE;
476- }
477-
478449// Find, and cache, the requested directory, for use by GetDir or (and thus open)
479450// provide an optional offset variable, for use when caching dirs of greater than 500 files
480451
@@ -897,7 +868,7 @@ int cdfs_readSect(u32 lsn, u32 sectors, u8 *buf) {
897868 return FALSE; // error
898869}
899870
900- int cdfs_getDir (const char * pathname , const char * extensions , enum CDFS_getMode getMode , struct TocEntry tocEntry [], unsigned int req_entries ) {
871+ int cdfs_getDir (const char * pathname , struct TocEntry tocEntry [], unsigned int req_entries ) {
901872 int matched_entries ;
902873 int dir_entry ;
903874
@@ -916,165 +887,146 @@ int cdfs_getDir(const char *pathname, const char *extensions, enum CDFS_getMode
916887
917888 DPRINTF ("requested directory is %u sectors\n" , cacheInfoDir .sector_num );
918889
919- if ((getMode == CDFS_GET_DIRS_ONLY ) || (getMode == CDFS_GET_FILES_AND_DIRS )) {
920- // Cache the start of the requested directory
921- if (!cdfs_cacheDir (cacheInfoDir .pathname , CACHE_START )) {
922- DPRINTF ("cdfs_getDir - Call of cdfs_cacheDir failed\n\n" );
923- return -1 ;
924- }
890+ // Cache the start of the requested directory
891+ if (!cdfs_cacheDir (cacheInfoDir .pathname , CACHE_START )) {
892+ DPRINTF ("cdfs_getDir - Call of cdfs_cacheDir failed\n\n" );
893+ return -1 ;
894+ }
925895
926- tocEntryPointer = (struct DirTocEntry * )cacheInfoDir .cache ;
927- // skip the first self-referencing entry
928- tocEntryPointer = (struct DirTocEntry * )((u8 * )tocEntryPointer + tocEntryPointer -> length );
896+ tocEntryPointer = (struct DirTocEntry * )cacheInfoDir .cache ;
897+ // skip the first self-referencing entry
898+ tocEntryPointer = (struct DirTocEntry * )((u8 * )tocEntryPointer + tocEntryPointer -> length );
929899
930- // skip the parent entry if this is the root
931- if (cacheInfoDir .path_depth == 0 )
932- tocEntryPointer = (struct DirTocEntry * )((u8 * )tocEntryPointer + tocEntryPointer -> length );
900+ // skip the parent entry if this is the root
901+ if (cacheInfoDir .path_depth == 0 )
902+ tocEntryPointer = (struct DirTocEntry * )((u8 * )tocEntryPointer + tocEntryPointer -> length );
933903
934- dir_entry = 0 ;
904+ dir_entry = 0 ;
935905
936- while (1 ) {
937- DPRINTF ("cdfs_getDir - inside while-loop\n\n" );
906+ while (1 ) {
907+ DPRINTF ("cdfs_getDir - inside while-loop\n\n" );
938908
939- // parse the current cache block
940- for (; tocEntryPointer < (struct DirTocEntry * )(cacheInfoDir .cache + (cacheInfoDir .cache_size * 2048 )); tocEntryPointer = (struct DirTocEntry * )((u8 * )tocEntryPointer + tocEntryPointer -> length )) {
941- if (tocEntryPointer -> length == 0 ) {
942- // if we have a toc entry length of zero,
943- // then we've either reached the end of the sector, or the end of the dir
944- // so point to next sector (if there is one - will be checked by next condition)
909+ // parse the current cache block
910+ for (; tocEntryPointer < (struct DirTocEntry * )(cacheInfoDir .cache + (cacheInfoDir .cache_size * 2048 )); tocEntryPointer = (struct DirTocEntry * )((u8 * )tocEntryPointer + tocEntryPointer -> length )) {
911+ if (tocEntryPointer -> length == 0 ) {
912+ // if we have a toc entry length of zero,
913+ // then we've either reached the end of the sector, or the end of the dir
914+ // so point to next sector (if there is one - will be checked by next condition)
945915
946- tocEntryPointer = (struct DirTocEntry * )(cacheInfoDir .cache + (((((u8 * )tocEntryPointer - cacheInfoDir .cache ) / 2048 ) + 1 ) * 2048 ));
947- }
916+ tocEntryPointer = (struct DirTocEntry * )(cacheInfoDir .cache + (((((u8 * )tocEntryPointer - cacheInfoDir .cache ) / 2048 ) + 1 ) * 2048 ));
917+ }
948918
949- if (tocEntryPointer >= (struct DirTocEntry * )(cacheInfoDir .cache + (cacheInfoDir .cache_size * 2048 ))) {
950- // we've reached the end of the current cache block (which may be end of entire dir
951- // so just break the loop
952- break ;
953- }
919+ if (tocEntryPointer >= (struct DirTocEntry * )(cacheInfoDir .cache + (cacheInfoDir .cache_size * 2048 ))) {
920+ // we've reached the end of the current cache block (which may be end of entire dir
921+ // so just break the loop
922+ break ;
923+ }
954924
955- // Check if the current entry is a dir or a file
956- if (tocEntryPointer -> fileProperties & 0x02 ) {
957- DPRINTF ("We found a dir, and we want all dirs\n\n" );
958- copyToTocEntry (& localTocEntry , tocEntryPointer );
925+ // Check if the current entry is a dir or a file
926+ if (tocEntryPointer -> fileProperties & 0x02 ) {
927+ DPRINTF ("We found a dir, and we want all dirs\n\n" );
928+ copyToTocEntry (& localTocEntry , tocEntryPointer );
959929
960- if (dir_entry == 0 ) {
961- if (cacheInfoDir .path_depth != 0 ) {
962- DPRINTF ("It's the first directory entry, so name it '..'\n\n" );
963- strcpy (localTocEntry .filename , ".." );
964- }
930+ if (dir_entry == 0 ) {
931+ if (cacheInfoDir .path_depth != 0 ) {
932+ DPRINTF ("It's the first directory entry, so name it '..'\n\n" );
933+ strcpy (localTocEntry .filename , ".." );
965934 }
966-
967- // Copy from localTocEntry
968- tocEntry [matched_entries ] = localTocEntry ;
969- matched_entries ++ ;
970- } else { // it must be a file
971- DPRINTF ("We found a file, but we dont want files (at least not yet)\n\n" );
972935 }
973936
974- dir_entry ++ ;
937+ // Copy from localTocEntry
938+ tocEntry [matched_entries ] = localTocEntry ;
939+ matched_entries ++ ;
940+ } else { // it must be a file
941+ DPRINTF ("We found a file, but we dont want files (at least not yet)\n\n" );
942+ }
943+
944+ dir_entry ++ ;
975945
976- if ((unsigned int )matched_entries >= req_entries ) // if we've filled the requested buffer
977- return (matched_entries ); // then just return
946+ if ((unsigned int )matched_entries >= req_entries ) // if we've filled the requested buffer
947+ return (matched_entries ); // then just return
978948
979- } // end of the current cache block
949+ } // end of the current cache block
980950
981- // if there is more dir to load, then load next chunk, else finish
982- if ((cacheInfoDir .cache_offset + cacheInfoDir .cache_size ) < cacheInfoDir .sector_num ) {
983- if (!cdfs_cacheDir (cacheInfoDir .pathname , CACHE_NEXT )) {
984- // failed to cache next block (should return TRUE even if
985- // there is no more directory, as long as a CD read didnt fail
986- return -1 ;
987- }
988- } else
989- break ;
951+ // if there is more dir to load, then load next chunk, else finish
952+ if ((cacheInfoDir .cache_offset + cacheInfoDir .cache_size ) < cacheInfoDir .sector_num ) {
953+ if (!cdfs_cacheDir (cacheInfoDir .pathname , CACHE_NEXT )) {
954+ // failed to cache next block (should return TRUE even if
955+ // there is no more directory, as long as a CD read didnt fail
956+ return -1 ;
957+ }
958+ } else
959+ break ;
990960
991- tocEntryPointer = (struct DirTocEntry * )cacheInfoDir .cache ;
992- }
961+ tocEntryPointer = (struct DirTocEntry * )cacheInfoDir .cache ;
993962 }
994963
995964 // Next do files
996- if ((getMode == CDFS_GET_FILES_ONLY ) || (getMode == CDFS_GET_FILES_AND_DIRS )) {
997- // Cache the start of the requested directory
998- if (!cdfs_cacheDir (cacheInfoDir .pathname , CACHE_START )) {
999- DPRINTF ("cdfs_getDir - Call of cdfs_cacheDir failed\n\n" );
1000- return -1 ;
1001- }
1002-
1003- tocEntryPointer = (struct DirTocEntry * )cacheInfoDir .cache ;
965+ // Cache the start of the requested directory
966+ if (!cdfs_cacheDir (cacheInfoDir .pathname , CACHE_START )) {
967+ DPRINTF ("cdfs_getDir - Call of cdfs_cacheDir failed\n\n" );
968+ return -1 ;
969+ }
1004970
1005- // skip the first self-referencing entry
1006- tocEntryPointer = (struct DirTocEntry * )((u8 * )tocEntryPointer + tocEntryPointer -> length );
971+ tocEntryPointer = (struct DirTocEntry * )cacheInfoDir .cache ;
1007972
1008- // skip the parent entry if this is the root
1009- if (cacheInfoDir .path_depth == 0 )
1010- tocEntryPointer = (struct DirTocEntry * )((u8 * )tocEntryPointer + tocEntryPointer -> length );
973+ // skip the first self-referencing entry
974+ tocEntryPointer = (struct DirTocEntry * )((u8 * )tocEntryPointer + tocEntryPointer -> length );
1011975
1012- dir_entry = 0 ;
976+ // skip the parent entry if this is the root
977+ if (cacheInfoDir .path_depth == 0 )
978+ tocEntryPointer = (struct DirTocEntry * )((u8 * )tocEntryPointer + tocEntryPointer -> length );
1013979
1014- while (1 ) {
1015- DPRINTF ("cdfs_getDir - inside while-loop\n\n" );
980+ dir_entry = 0 ;
1016981
1017- // parse the current cache block
1018- for (; tocEntryPointer < (struct DirTocEntry * )(cacheInfoDir .cache + (cacheInfoDir .cache_size * 2048 )); tocEntryPointer = (struct DirTocEntry * )((u8 * )tocEntryPointer + tocEntryPointer -> length )) {
1019- if (tocEntryPointer -> length == 0 ) {
1020- // if we have a toc entry length of zero,
1021- // then we've either reached the end of the sector, or the end of the dir
1022- // so point to next sector (if there is one - will be checked by next condition)
982+ while (1 ) {
983+ DPRINTF ("cdfs_getDir - inside while-loop\n\n" );
1023984
1024- tocEntryPointer = (struct DirTocEntry * )(cacheInfoDir .cache + (((((u8 * )tocEntryPointer - cacheInfoDir .cache ) / 2048 ) + 1 ) * 2048 ));
1025- }
985+ // parse the current cache block
986+ for (; tocEntryPointer < (struct DirTocEntry * )(cacheInfoDir .cache + (cacheInfoDir .cache_size * 2048 )); tocEntryPointer = (struct DirTocEntry * )((u8 * )tocEntryPointer + tocEntryPointer -> length )) {
987+ if (tocEntryPointer -> length == 0 ) {
988+ // if we have a toc entry length of zero,
989+ // then we've either reached the end of the sector, or the end of the dir
990+ // so point to next sector (if there is one - will be checked by next condition)
1026991
1027- if (tocEntryPointer >= (struct DirTocEntry * )(cacheInfoDir .cache + (cacheInfoDir .cache_size * 2048 ))) {
1028- // we've reached the end of the current cache block (which may be end of entire dir
1029- // so just break the loop
1030- break ;
1031- }
992+ tocEntryPointer = (struct DirTocEntry * )(cacheInfoDir .cache + (((((u8 * )tocEntryPointer - cacheInfoDir .cache ) / 2048 ) + 1 ) * 2048 ));
993+ }
1032994
1033- // Check if the current entry is a dir or a file
1034- if (tocEntryPointer -> fileProperties & 0x02 ) {
1035- DPRINTF ("We don't want files now\n\n" );
1036- } else { // it must be a file
1037- copyToTocEntry (& localTocEntry , tocEntryPointer );
1038-
1039- if (strlen (extensions ) > 0 ) {
1040- // check if the file matches the extension list
1041- if (compareTocEntry (localTocEntry .filename , extensions )) {
1042- DPRINTF ("We found a file that matches the requested extension list\n\n" );
1043- // Copy from localTocEntry
1044- tocEntry [matched_entries ] = localTocEntry ;
1045- matched_entries ++ ;
1046- } else {
1047- DPRINTF ("We found a file, but it didnt match the requested extension list\n\n" );
1048- }
1049- } else { // no extension list to match against
1050- DPRINTF ("We found a file, and there is not extension list to match against\n\n" );
995+ if (tocEntryPointer >= (struct DirTocEntry * )(cacheInfoDir .cache + (cacheInfoDir .cache_size * 2048 ))) {
996+ // we've reached the end of the current cache block (which may be end of entire dir
997+ // so just break the loop
998+ break ;
999+ }
10511000
1052- // Copy from localTocEntry
1053- tocEntry [matched_entries ] = localTocEntry ;
1054- matched_entries ++ ;
1055- }
1001+ // Check if the current entry is a dir or a file
1002+ if (tocEntryPointer -> fileProperties & 0x02 ) {
1003+ DPRINTF ("We don't want files now\n\n" );
1004+ } else { // it must be a file
1005+ copyToTocEntry (& localTocEntry , tocEntryPointer );
1006+ // Copy from localTocEntry
1007+ tocEntry [matched_entries ] = localTocEntry ;
1008+ matched_entries ++ ;
10561009 }
10571010
1058- dir_entry ++ ;
1011+ dir_entry ++ ;
10591012
1060- if ((unsigned int )matched_entries >= req_entries ) // if we've filled the requested buffer
1061- return (matched_entries ); // then just return
1013+ if ((unsigned int )matched_entries >= req_entries ) // if we've filled the requested buffer
1014+ return (matched_entries ); // then just return
10621015
1063- } // end of the current cache block
1016+ } // end of the current cache block
10641017
10651018
1066- // if there is more dir to load, then load next chunk, else finish
1067- if ((cacheInfoDir .cache_offset + cacheInfoDir .cache_size ) < cacheInfoDir .sector_num ) {
1068- if (!cdfs_cacheDir (cacheInfoDir .pathname , CACHE_NEXT )) {
1069- // failed to cache next block (should return TRUE even if
1070- // there is no more directory, as long as a CD read didnt fail
1071- return -1 ;
1072- }
1073- } else
1074- break ;
1019+ // if there is more dir to load, then load next chunk, else finish
1020+ if ((cacheInfoDir .cache_offset + cacheInfoDir .cache_size ) < cacheInfoDir .sector_num ) {
1021+ if (!cdfs_cacheDir (cacheInfoDir .pathname , CACHE_NEXT )) {
1022+ // failed to cache next block (should return TRUE even if
1023+ // there is no more directory, as long as a CD read didnt fail
1024+ return -1 ;
1025+ }
1026+ } else
1027+ break ;
10751028
1076- tocEntryPointer = (struct DirTocEntry * )cacheInfoDir .cache ;
1077- }
1029+ tocEntryPointer = (struct DirTocEntry * )cacheInfoDir .cache ;
10781030 }
10791031 // reached the end of the dir, before filling up the requested entries
10801032
@@ -1083,7 +1035,7 @@ int cdfs_getDir(const char *pathname, const char *extensions, enum CDFS_getMode
10831035
10841036// This function uses sceCdTrayReq to check if the disc in the disc drive has changed.
10851037// Once sceCdTrayReq is called it will reset the flag inside CDVDMAN.
1086- // Avoid using sceCdTrayReq with SCECdTrayCheck as arguemnt in other code if possible.
1038+ // Avoid using sceCdTrayReq with SCECdTrayCheck as argument in other code if possible.
10871039
10881040int cdfs_checkDiskChanged (enum Cdvd_Changed_Index index ) {
10891041 u32 res = 0 ;
0 commit comments