diff --git a/ee_core/include/igs_api.h b/ee_core/include/igs_api.h index 4c7d3d5d8..962b46352 100644 --- a/ee_core/include/igs_api.h +++ b/ee_core/include/igs_api.h @@ -25,7 +25,6 @@ #ifndef _IGSAPI_H_ #define _IGSAPI_H_ -#include "fileio.h" #include "ee_core.h" #include #include "iopmgr.h" diff --git a/ee_core/src/igs_api.c b/ee_core/src/igs_api.c index 825e0d036..3add1e5d6 100644 --- a/ee_core/src/igs_api.c +++ b/ee_core/src/igs_api.c @@ -23,6 +23,8 @@ */ #include "include/igs_api.h" +#define NEWLIB_PORT_AWARE +#include "fileio.h" static void FastDelay(int count) { diff --git a/include/config.h b/include/config.h index 71cb7154e..2a8c0f323 100644 --- a/include/config.h +++ b/include/config.h @@ -156,7 +156,6 @@ int configReadBuffer(config_set_t *configSet, const void *buffer, int size); int configReadMulti(int types); int configWrite(config_set_t *configSet); int configWriteMulti(int types); -int configGetStat(config_set_t *configSet, iox_stat_t *stat); void configClear(config_set_t *configSet); void configGetVMC(config_set_t *configSet, char *vmc, int length, int slot); diff --git a/include/opl.h b/include/opl.h index 32a648709..c4fff2ee8 100644 --- a/include/opl.h +++ b/include/opl.h @@ -11,6 +11,12 @@ #include #include #include +#include +#include +#include +#include +#include +#include #include #include #include @@ -26,13 +32,11 @@ #include #include #include -#include #include #include #include #include #include "config.h" -#include // Last Played Auto Start #include diff --git a/modules/debug/ps2link/hostlink.h b/modules/debug/ps2link/hostlink.h index a76e26381..438a9b0aa 100644 --- a/modules/debug/ps2link/hostlink.h +++ b/modules/debug/ps2link/hostlink.h @@ -171,7 +171,7 @@ typedef struct unsigned int cmd; unsigned short len; int retval; - /* from io_common.h (fio_dirent_t) in ps2lib */ + /* from io_common.h (io_dirent_t) in ps2sdk */ unsigned int mode; unsigned int attr; unsigned int size; diff --git a/modules/debug/ps2link/net_fio.c b/modules/debug/ps2link/net_fio.c index a85ccc6a6..d11c37c2c 100644 --- a/modules/debug/ps2link/net_fio.c +++ b/modules/debug/ps2link/net_fio.c @@ -572,7 +572,7 @@ int pko_read_dir(int fd, void *buf) { pko_pkt_dread_req *dirreq; pko_pkt_dread_rly *dirrly; - fio_dirent_t *dirent; + io_dirent_t *dirent; if (pko_fileio_sock < 0) { return -1; @@ -601,7 +601,7 @@ int pko_read_dir(int fd, void *buf) dbgprintf("pko_file: dir read reply received (ret %ld)\n", ntohl(dirrly->retval)); - dirent = (fio_dirent_t *)buf; + dirent = (io_dirent_t *)buf; // now handle the return buffer translation, to build reply bit dirent->stat.mode = ntohl(dirrly->mode); dirent->stat.attr = ntohl(dirrly->attr); diff --git a/modules/iopcore/cdvdman/ioman_add.h b/modules/iopcore/cdvdman/ioman_add.h index 4eea2adca..3800534d5 100644 --- a/modules/iopcore/cdvdman/ioman_add.h +++ b/modules/iopcore/cdvdman/ioman_add.h @@ -1,6 +1,8 @@ #ifndef _IOMAN_ADD_H_ #define _IOMAN_ADD_H_ +#include + #define IOP_DT_FSEXT 0x10000000 typedef struct _iop_ext_device diff --git a/modules/network/SMSTCPIP/include/lwip/sockets.h b/modules/network/SMSTCPIP/include/lwip/sockets.h index af4ebb8b6..f0d7933ce 100644 --- a/modules/network/SMSTCPIP/include/lwip/sockets.h +++ b/modules/network/SMSTCPIP/include/lwip/sockets.h @@ -34,6 +34,7 @@ #ifndef __LWIP_SOCKETS_H__ #define __LWIP_SOCKETS_H__ #include "lwip/ip_addr.h" +#include struct sockaddr_in { @@ -210,15 +211,6 @@ typedef struct fd_set } fd_set; #endif -#ifndef TIMEVAL -#define TIMEVAL -struct timeval -{ - long tv_sec; /* seconds */ - long tv_usec; /* and microseconds */ -}; -#endif - int lwip_accept(int s, struct sockaddr *addr, socklen_t *addrlen); int lwip_bind(int s, struct sockaddr *name, socklen_t namelen); int lwip_shutdown(int s, int how); diff --git a/modules/network/common/smstcpip-common.h b/modules/network/common/smstcpip-common.h index 97c7c8d96..8a9a8a746 100644 --- a/modules/network/common/smstcpip-common.h +++ b/modules/network/common/smstcpip-common.h @@ -48,6 +48,8 @@ * */ +#include + typedef signed char err_t; /* lwIP error type. */ /* From src/include/lwip/pbuf.h: */ @@ -294,15 +296,6 @@ typedef struct fd_set } fd_set; #endif -#ifndef TIMEVAL -#define TIMEVAL -struct timeval -{ - long tv_sec; /* seconds */ - long tv_usec; /* and microseconds */ -}; -#endif - #if !defined(INVALID_SOCKET) #define INVALID_SOCKET -1 #endif diff --git a/src/OSDHistory.c b/src/OSDHistory.c index f260164ca..d9fb184f4 100644 --- a/src/OSDHistory.c +++ b/src/OSDHistory.c @@ -13,6 +13,9 @@ #include #include #include +#include +#include +#include #include "include/util.h" #include "include/OSDHistory.h" @@ -35,7 +38,7 @@ int CreateSystemDataFolder(const char *path, char FolderRegionLetter) sprintf(fullpath, "%s/icon.sys", path); if ((fd = open(fullpath, O_RDONLY)) < 0) { - mkdir(path); + mkdir(path, 0777); if ((fd = open(fullpath, O_CREAT | O_TRUNC | O_WRONLY)) >= 0) { switch(FolderRegionLetter) { case 'I': diff --git a/src/appsupport.c b/src/appsupport.c index b7ccef5c6..2b77267e5 100644 --- a/src/appsupport.c +++ b/src/appsupport.c @@ -308,7 +308,7 @@ static void appDeleteItem(int id) if (appsList[id].legacy) { struct config_value_t *cur = appGetConfigValue(id); - fileXioRemove(cur->val); + unlink(cur->val); cur->key[0] = '\0'; configApps->modified = 1; configWrite(configApps); @@ -358,9 +358,9 @@ static void appLaunchItem(int id, config_set_t *configSet) //Retrieve configuration set by appGetConfig() configGetStr(configSet, CONFIG_ITEM_STARTUP, &filename); - fd = fileXioOpen(filename, O_RDONLY); + fd = open(filename, O_RDONLY); if (fd >= 0) { - fileXioClose(fd); + close(fd); //To keep the necessary device accessible, we will assume the mode that owns the device which contains the file to boot. mode = oplPath2Mode(filename); diff --git a/src/atlas.c b/src/atlas.c index 62d44242f..e1c85892a 100644 --- a/src/atlas.c +++ b/src/atlas.c @@ -5,6 +5,7 @@ */ #include +#include #include "include/atlas.h" #include "include/renderman.h" diff --git a/src/cheatman.c b/src/cheatman.c index e9714c414..a083f2e90 100644 --- a/src/cheatman.c +++ b/src/cheatman.c @@ -22,6 +22,7 @@ * $Id$ */ +#include #include "include/cheatman.h" #include "include/ioman.h" diff --git a/src/config.c b/src/config.c index c9c97bbea..479025e58 100644 --- a/src/config.c +++ b/src/config.c @@ -9,6 +9,12 @@ #include "include/ioman.h" #include +// FIXME: We should not need this function. +// Use newlib's 'stat' to get GMT time. +#define NEWLIB_PORT_AWARE +#include // iox_stat_t, fileXioGetStat +int configGetStat(config_set_t *configSet, iox_stat_t *stat); + static u32 currentUID = 0; static config_set_t configFiles[CONFIG_INDEX_COUNT]; static char legacyNetConfigPath[256] = "mc?:SYS-CONF/IPCONFIG.DAT"; @@ -411,8 +417,8 @@ static int configReadLegacyIP(void) if (fd >= 0) { char ipconfig[256]; int size = getFileSize(fd); - fileXioRead(fd, &ipconfig, size); - fileXioClose(fd); + read(fd, &ipconfig, size); + close(fd); sscanf(ipconfig, "%d.%d.%d.%d %d.%d.%d.%d %d.%d.%d.%d", &ps2_ip[0], &ps2_ip[1], &ps2_ip[2], &ps2_ip[3], &ps2_netmask[0], &ps2_netmask[1], &ps2_netmask[2], &ps2_netmask[3], diff --git a/src/ethsupport.c b/src/ethsupport.c index eaa4a85d4..5ff90aead 100644 --- a/src/ethsupport.c +++ b/src/ethsupport.c @@ -13,14 +13,17 @@ #include "include/cheatman.h" #include "modules/iopcore/common/cdvd_config.h" +#define NEWLIB_PORT_AWARE +#include // fileXioDevctl(ethBase, SMB_***) + #include "include/nbns.h" #include "httpclient.h" static char ethPrefix[40]; //Contains the full path to the folder where all the games are. static char *ethBase; static int ethULSizePrev = -2; -static unsigned char ethModifiedCDPrev[8]; -static unsigned char ethModifiedDVDPrev[8]; +static time_t ethModifiedCDPrev; +static time_t ethModifiedDVDPrev; static int ethGameCount = 0; static unsigned char ethModulesLoaded = 0; static base_game_info_t *ethGames = NULL; @@ -421,8 +424,8 @@ void ethInit(void) LOG("ETHSUPPORT Init\n"); ethBase = "smb0:"; ethULSizePrev = -2; - memset(ethModifiedCDPrev, 0, sizeof(ethModifiedCDPrev)); - memset(ethModifiedDVDPrev, 0, sizeof(ethModifiedDVDPrev)); + ethModifiedCDPrev = 0; + ethModifiedDVDPrev = 0; ethGameCount = 0; ethGames = NULL; configGetInt(configGetByType(CONFIG_OPL), "eth_frames_delay", ðGameList.delay); @@ -449,22 +452,22 @@ static int ethNeedsUpdate(void) result = 1; if (gNetworkStartup == 0) { - iox_stat_t stat; + struct stat st; char path[256]; sprintf(path, "%sCD", ethPrefix); - if (fileXioGetStat(path, &stat) != 0) - memset(stat.mtime, 0, sizeof(stat.mtime)); - if (memcmp(ethModifiedCDPrev, stat.mtime, sizeof(ethModifiedCDPrev))) { - memcpy(ethModifiedCDPrev, stat.mtime, sizeof(ethModifiedCDPrev)); + if (stat(path, &st) != 0) + st.st_mtime = 0; + if (ethModifiedCDPrev != st.st_mtime) { + ethModifiedCDPrev = st.st_mtime; result = 1; } sprintf(path, "%sDVD", ethPrefix); - if (fileXioGetStat(path, &stat) != 0) - memset(stat.mtime, 0, sizeof(stat.mtime)); - if (memcmp(ethModifiedDVDPrev, stat.mtime, sizeof(ethModifiedDVDPrev))) { - memcpy(ethModifiedDVDPrev, stat.mtime, sizeof(ethModifiedDVDPrev)); + if (stat(path, &st) != 0) + st.st_mtime = 0; + if (ethModifiedDVDPrev != st.st_mtime) { + ethModifiedDVDPrev = st.st_mtime; result = 1; } @@ -671,10 +674,10 @@ static void ethLaunchGame(int id, config_set_t *configSet) } if (gPS2Logo) { - int fd = fileXioOpen(partname, O_RDONLY, 0666); + int fd = open(partname, O_RDONLY, 0666); if (fd >= 0) { EnablePS2Logo = CheckPS2Logo(fd, 0); - fileXioClose(fd); + close(fd); } } diff --git a/src/gsm.c b/src/gsm.c index ea7d2d1f3..6d8d090bc 100644 --- a/src/gsm.c +++ b/src/gsm.c @@ -111,10 +111,10 @@ void PrepareGSM(char *cmdline) k576p_fix = 0; kGsDxDyOffsetSupported = 0; - if((fd = fileXioOpen("rom0:ROMVER", O_RDONLY)) >= 0) { + if((fd = open("rom0:ROMVER", O_RDONLY)) >= 0) { //Read ROM version - fileXioRead(fd, romver, sizeof(romver)); - fileXioClose(fd); + read(fd, romver, sizeof(romver)); + close(fd); strncpy(romverNum, romver, 4); romverNum[4] = '\0'; diff --git a/src/guigame.c b/src/guigame.c index b22c66d95..f2921fd6a 100644 --- a/src/guigame.c +++ b/src/guigame.c @@ -20,6 +20,9 @@ #include #endif +#define NEWLIB_PORT_AWARE +#include // fileXioDevctl("genvmc:", ***) + static int configSourceID; static int dmaMode; static int compatMode; diff --git a/src/hdd.c b/src/hdd.c index 9b1eabe7d..def4a200a 100644 --- a/src/hdd.c +++ b/src/hdd.c @@ -3,6 +3,9 @@ #include "include/ioman.h" #include "include/hddsupport.h" +#define NEWLIB_PORT_AWARE +#include + typedef struct // size = 1024 { u32 checksum; // HDL uses 0xdeadfeed magic here @@ -294,7 +297,7 @@ int hddDeleteHDLGame(hdl_game_info_t *ginfo) sprintf(path, "hdd0:%s", ginfo->partition_name); - return fileXioRemove(path); + return unlink(path); } //------------------------------------------------------------------------- diff --git a/src/hddsupport.c b/src/hddsupport.c index 41bdc33eb..048d3a800 100644 --- a/src/hddsupport.c +++ b/src/hddsupport.c @@ -13,6 +13,10 @@ #include "include/cheatman.h" #include "modules/iopcore/common/cdvd_config.h" +#define NEWLIB_PORT_AWARE +#include // fileXioFormat, fileXioMount, fileXioUmount, fileXioDevctl +#include // FIO_MT_RDWR + #include #define OPL_HDD_MODE_PS2LOGO_OFFSET 0x17F8 @@ -96,8 +100,8 @@ static int CreateOPLPartition(const char *oplPart, const char *mountpoint) char cmd[43]; sprintf(cmd, "%s,,,128M,PFS", oplPart); - if ((fd = fileXioOpen(cmd, O_CREAT | O_TRUNC | O_WRONLY)) >= 0) { - fileXioClose(fd); + if ((fd = open(cmd, O_CREAT | O_TRUNC | O_WRONLY)) >= 0) { + close(fd); result = fileXioFormat(mountpoint, oplPart, (const char *)&formatArg, sizeof(formatArg)); } else { result = fd; diff --git a/src/lang.c b/src/lang.c index d4db1b305..b2c5b32c5 100644 --- a/src/lang.c +++ b/src/lang.c @@ -385,7 +385,7 @@ char *lngGetValue(void) static int lngReadEntry(int index, const char *path, const char *separator, const char *name, unsigned int mode) { - if (!FIO_S_ISDIR(mode)) { + if (!S_ISDIR(mode)) { if (strstr(name, ".lng") || strstr(name, ".LNG")) { language_t *currLang = &languages[nLanguages + index]; diff --git a/src/opl.c b/src/opl.c index f58d49492..64828ef30 100644 --- a/src/opl.c +++ b/src/opl.c @@ -35,6 +35,12 @@ #include "include/sound.h" +// FIXME: We should not need this function. +// Use newlib's 'stat' to get GMT time. +#define NEWLIB_PORT_AWARE +#include // iox_stat_t +int configGetStat(config_set_t *configSet, iox_stat_t *stat); + #include #include #ifdef PADEMU @@ -388,8 +394,10 @@ int oplGetAppImage(const char *device, char *folder, int isRelative, char *value int oplScanApps(int (*callback)(const char *path, config_set_t *appConfig, void *arg), void *arg) { - iox_dirent_t dirent; - int i, fd, count, ret; + struct dirent *pdirent; + DIR *pdir; + struct stat st; + int i, count, ret; item_list_t *listSupport; config_set_t *appConfig; char appsPath[64]; @@ -404,14 +412,19 @@ int oplScanApps(int (*callback)(const char *path, config_set_t *appConfig, void { listSupport->itemGetAppsPath(appsPath, sizeof(appsPath)); - if ((fd = fileXioDopen(appsPath)) > 0) + if ((pdir = opendir(appsPath)) != NULL) { - while (fileXioDread(fd, &dirent) > 0) + while ((pdirent = readdir(pdir)) != NULL) { - if (strcmp(dirent.name, ".") == 0 || strcmp(dirent.name, "..") == 0 || (!FIO_S_ISDIR(dirent.stat.mode))) + if (strcmp(pdirent->d_name, ".") == 0 || strcmp(pdirent->d_name, "..") == 0) continue; - snprintf(dir, sizeof(dir), "%s/%s", appsPath, dirent.name); + snprintf(dir, sizeof(dir), "%s/%s", appsPath, pdirent->d_name); + if (stat(dir, &st) < 0) + continue; + if(!S_ISDIR(st.st_mode)) + continue; + snprintf(path, sizeof(path), "%s/%s", dir, APP_TITLE_CONFIG_FILE); appConfig = configAlloc(0, NULL, path); if (appConfig != NULL) @@ -430,7 +443,7 @@ int oplScanApps(int (*callback)(const char *path, config_set_t *appConfig, void } } - fileXioDclose(fd); + closedir(pdir); } else LOG("APPS failed to open dir %s\n", appsPath); } @@ -595,9 +608,9 @@ static int checkLoadConfigHDD(int types) int value; hddLoadModules(); - value = fileXioOpen("pfs0:conf_opl.cfg", O_RDONLY); + value = open("pfs0:conf_opl.cfg", O_RDONLY); if (value >= 0) { - fileXioClose(value); + close(value); configEnd(); configInit("pfs0:"); value = configReadMulti(types); @@ -614,6 +627,7 @@ static int tryAlternateDevice(int types) { char pwd[8]; int value; + DIR *dir; getcwd(pwd, sizeof(pwd)); @@ -646,16 +660,16 @@ static int tryAlternateDevice(int types) return 0; } // No memory cards? Try a USB device... - value = fileXioDopen("mass0:"); - if (value >= 0) { - fileXioDclose(value); + dir = opendir("mass0:"); + if (dir != NULL) { + closedir(dir); configEnd(); configInit("mass0:"); } else { // No? Check if the save location on the HDD is available. - value = fileXioDopen("pfs0:"); - if (value >= 0) { - fileXioDclose(value); + dir = opendir("pfs0:"); + if (dir != NULL) { + closedir(dir); configEnd(); configInit("pfs0:"); } diff --git a/src/ps2cnf.c b/src/ps2cnf.c index c036bf028..3952a1132 100644 --- a/src/ps2cnf.c +++ b/src/ps2cnf.c @@ -6,6 +6,7 @@ #include #include #include +#include #include "ps2cnf.h" #include "ioman.h" diff --git a/src/sound.c b/src/sound.c index 29436bdad..894d72028 100644 --- a/src/sound.c +++ b/src/sound.c @@ -186,11 +186,11 @@ int sfxInit(int bootSnd) snprintf(sound_path, sizeof(sound_path), "%ssound", thmPath); //Check for custom sfx folder - int fd = fileXioDopen(sound_path); - if (fd >= 0) + DIR *dir = opendir(sound_path); + if (dir != NULL) { thmSfxEnabled = 1; - - fileXioDclose(fd); + closedir(dir); + } } //boot sound only needs to be read/loaded at init diff --git a/src/supportbase.c b/src/supportbase.c index 52bd48d32..d74b29bf7 100644 --- a/src/supportbase.c +++ b/src/supportbase.c @@ -11,7 +11,9 @@ #include "include/cheatman.h" #include "include/ps2cnf.h" -#include +#define NEWLIB_PORT_AWARE +#include // fileXioMount("iso:", ***), fileXioUmount("iso:") +#include // FIO_MT_RDONLY /// internal linked list used to populate the list from directory listing struct game_list_t @@ -34,7 +36,7 @@ int sbIsSameSize(const char *prefix, int prevSize) int fd = openFile(path, O_RDONLY); if (fd >= 0) { size = getFileSize(fd); - fileXioClose(fd); + close(fd); } return size == prevSize; @@ -275,19 +277,21 @@ static int queryISOGameListCache(const struct game_cache_list *cache, base_game_ static int scanForISO(char *path, char type, struct game_list_t **glist) { - int fd, NameLen, count = 0, format, MountFD, cacheLoaded; + int NameLen, count = 0, format, MountFD, cacheLoaded; struct game_cache_list cache; base_game_info_t cachedGInfo; char fullpath[256], startup[GAME_STARTUP_MAX]; - iox_dirent_t record; + struct dirent *dirent; + DIR *dir; + struct stat st; cache.games = NULL; cache.count = 0; cacheLoaded = loadISOGameListCache(path, &cache) == 0; - if ((fd = fileXioDopen(path)) > 0) { - while (fileXioDread(fd, &record) > 0) { - if ((format = isValidIsoName(record.name, &NameLen)) > 0) { + if ((dir = opendir(path)) != NULL) { + while ((dirent = readdir(dir)) != NULL) { + if ((format = isValidIsoName(dirent->d_name, &NameLen)) > 0) { base_game_info_t *game; if (NameLen > ISO_GAME_NAME_MAX) @@ -303,19 +307,19 @@ static int scanForISO(char *path, char type, struct game_list_t **glist) game = &(*glist)->gameinfo; memset(game, 0, sizeof(base_game_info_t)); - strncpy(game->name, &record.name[GAME_STARTUP_MAX], NameLen); + strncpy(game->name, &dirent->d_name[GAME_STARTUP_MAX], NameLen); game->name[NameLen] = '\0'; - strncpy(game->startup, record.name, GAME_STARTUP_MAX - 1); + strncpy(game->startup, dirent->d_name, GAME_STARTUP_MAX - 1); game->startup[GAME_STARTUP_MAX - 1] = '\0'; - strncpy(game->extension, &record.name[GAME_STARTUP_MAX + NameLen], sizeof(game->extension)); + strncpy(game->extension, &dirent->d_name[GAME_STARTUP_MAX + NameLen], sizeof(game->extension)); game->extension[sizeof(game->extension) - 1] = '\0'; } else { //Out of memory. break; } } else { - if(queryISOGameListCache(&cache, &cachedGInfo, record.name) != 0) { - sprintf(fullpath, "%s/%s", path, record.name); + if(queryISOGameListCache(&cache, &cachedGInfo, dirent->d_name) != 0) { + sprintf(fullpath, "%s/%s", path, dirent->d_name); if ((MountFD = fileXioMount("iso:", fullpath, FIO_MT_RDONLY)) >= 0) { if (GetStartupExecName("iso:/SYSTEM.CNF;1", startup, GAME_STARTUP_MAX - 1) == 0) { @@ -329,9 +333,9 @@ static int scanForISO(char *path, char type, struct game_list_t **glist) memset(game, 0, sizeof(base_game_info_t)); strcpy(game->startup, startup); - strncpy(game->name, record.name, NameLen); + strncpy(game->name, dirent->d_name, NameLen); game->name[NameLen] = '\0'; - strncpy(game->extension, &record.name[NameLen], sizeof(game->extension)); + strncpy(game->extension, &dirent->d_name[NameLen], sizeof(game->extension)); game->extension[sizeof(game->extension) - 1] = '\0'; } else { //Out of memory. @@ -366,17 +370,20 @@ static int scanForISO(char *path, char type, struct game_list_t **glist) } } + sprintf(fullpath, "%s/%s", path, dirent->d_name); + stat(fullpath, &st); + game->parts = 1; game->media = type; game->format = format; - game->sizeMB = (record.stat.size >> 20) | (record.stat.hisize << 12); + game->sizeMB = st.st_size >> 20; count++; } } - fileXioDclose(fd); + closedir(dir); } else { - count = fd; + count = 0; } if (cacheLoaded) @@ -431,7 +438,7 @@ int sbReadList(base_game_info_t **list, const char *prefix, int *fsize, int *gam memset(*list, 0, sizeof(base_game_info_t) * count); while (size > 0) { - fileXioRead(fd, &GameEntry, sizeof(USBExtreme_game_entry_t)); + read(fd, &GameEntry, sizeof(USBExtreme_game_entry_t)); base_game_info_t *g = &(*list)[id++]; @@ -449,7 +456,7 @@ int sbReadList(base_game_info_t **list, const char *prefix, int *fsize, int *gam } } } - fileXioClose(fd); + close(fd); } else if (count > 0) { *list = (base_game_info_t *)malloc(sizeof(base_game_info_t) * count); } @@ -519,14 +526,14 @@ int sbProbeISO9660_64(const char *path, base_game_info_t *game, u32 layer1_offse result = -1; if (game->media == SCECdPS2DVD) { //Only DVDs can have multiple layers. - if ((fd = fileXioOpen(path, O_RDONLY, 0666)) >= 0) { - if (fileXioLseek64(fd, (u64)layer1_offset * 2048, SEEK_SET) == (u64)layer1_offset * 2048) { - if ((fileXioRead(fd, buffer, sizeof(buffer)) == sizeof(buffer)) && + if ((fd = open(path, O_RDONLY, 0666)) >= 0) { + if (lseek(fd, (u64)layer1_offset * 2048, SEEK_SET) == (u64)layer1_offset * 2048) { + if ((read(fd, buffer, sizeof(buffer)) == sizeof(buffer)) && ((buffer[0x00] == 1) && (!strncmp(&buffer[0x01], "CD001", 5)))) { result = 0; } } - fileXioClose(fd); + close(fd); } else result = fd; } @@ -672,14 +679,14 @@ void sbDelete(base_game_info_t **list, const char *prefix, const char *sep, int else snprintf(path, sizeof(path), "%sDVD%s%s%s", prefix, sep, game->name, game->extension); } - fileXioRemove(path); + unlink(path); } else { char *pathStr = "%sul.%08X.%s.%02x"; unsigned int crc = USBA_crc32(game->name); int i = 0; do { snprintf(path, sizeof(path), pathStr, prefix, crc, game->startup, i++); - fileXioRemove(path); + unlink(path); } while (i < game->parts); sbRebuildULCfg(list, prefix, gamecount, id); @@ -709,7 +716,7 @@ void sbRename(base_game_info_t **list, const char *prefix, const char *sep, int snprintf(newpath, sizeof(newpath), "%sDVD%s%s%s", prefix, sep, newname, game->extension); } } - fileXioRename(oldpath, newpath); + rename(oldpath, newpath); } else { const char *pathStr = "%sul.%08X.%s.%02x"; unsigned int oldcrc = USBA_crc32(game->name); @@ -719,7 +726,7 @@ void sbRename(base_game_info_t **list, const char *prefix, const char *sep, int for (i = 0; i < game->parts; i++) { snprintf(oldpath, sizeof(oldpath), pathStr, prefix, oldcrc, game->startup, i); snprintf(newpath, sizeof(newpath), pathStr, prefix, newcrc, game->startup, i); - fileXioRename(oldpath, newpath); + rename(oldpath, newpath); } memset(game->name, 0, UL_GAME_NAME_MAX + 1); @@ -754,7 +761,7 @@ static void sbCreateFoldersFromList(const char *path, const char **folders) for (i = 0; folders[i] != NULL; i++) { sprintf(fullpath, "%s%s", path, folders[i]); - fileXioMkdir(fullpath, 0777); + mkdir(fullpath, 0777); } } diff --git a/src/system.c b/src/system.c index cdac8656a..b7ddec3fc 100644 --- a/src/system.c +++ b/src/system.c @@ -30,6 +30,9 @@ #include #endif +#define NEWLIB_PORT_AWARE +#include // fileXioInit, fileXioExit, fileXioDevctl + typedef struct { char VMC_filename[1024]; @@ -926,16 +929,16 @@ int sysCheckVMC(const char *prefix, const char *sep, char *name, int createSize, snprintf(path, sizeof(path), "%sVMC%s%s.bin", prefix, sep, name); if (createSize == -1) - fileXioRemove(path); + unlink(path); else { - int fd = fileXioOpen(path, O_RDONLY, FIO_S_IRUSR | FIO_S_IWUSR | FIO_S_IXUSR | FIO_S_IRGRP | FIO_S_IWGRP | FIO_S_IXGRP | FIO_S_IROTH | FIO_S_IWOTH | FIO_S_IXOTH); + int fd = open(path, O_RDONLY, S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH); if (fd >= 0) { - size = fileXioLseek(fd, 0, SEEK_END); + size = lseek(fd, 0, SEEK_END); if (vmc_superblock) { memset(vmc_superblock, 0, sizeof(vmc_superblock_t)); - fileXioLseek(fd, 0, SEEK_SET); - fileXioRead(fd, (void *)vmc_superblock, sizeof(vmc_superblock_t)); + lseek(fd, 0, SEEK_SET); + read(fd, (void *)vmc_superblock, sizeof(vmc_superblock_t)); LOG("SYSTEM File size : 0x%X\n", size); LOG("SYSTEM Magic : %s\n", vmc_superblock->magic); @@ -956,10 +959,10 @@ int sysCheckVMC(const char *prefix, const char *sep, char *name, int createSize, else size /= 1048576; - fileXioClose(fd); + close(fd); if (createSize && (createSize != size)) - fileXioRemove(path); + unlink(path); } diff --git a/src/themes.c b/src/themes.c index 632fb3465..31b846501 100644 --- a/src/themes.c +++ b/src/themes.c @@ -1052,7 +1052,7 @@ static void thmFree(theme_t *theme) static int thmReadEntry(int index, const char *path, const char *separator, const char *name, unsigned int mode) { - if (FIO_S_ISDIR(mode) && strstr(name, "thm_")) { + if (S_ISDIR(mode) && strstr(name, "thm_")) { theme_file_t *currTheme = &themes[nThemes + index]; int length = strlen(name) - 4 + 1; diff --git a/src/usbsupport.c b/src/usbsupport.c index 4fa0c6445..0e034e97b 100644 --- a/src/usbsupport.c +++ b/src/usbsupport.c @@ -13,13 +13,16 @@ #include "include/cheatman.h" #include "modules/iopcore/common/cdvd_config.h" +#define NEWLIB_PORT_AWARE +#include // fileXioIoctl, fileXioDevctl + void *pusbd_irx = NULL; int size_pusbd_irx = 0; static char usbPrefix[40]; //Contains the full path to the folder where all the games are. static int usbULSizePrev = -2; -static unsigned char usbModifiedCDPrev[8]; -static unsigned char usbModifiedDVDPrev[8]; +static time_t usbModifiedCDPrev; +static time_t usbModifiedDVDPrev; static int usbGameCount = 0; static base_game_info_t *usbGames; @@ -38,16 +41,16 @@ int usbFindPartition(char *target, const char *name, int write) else sprintf(path, "mass%d:%s", i, name); if (write) - fd = fileXioOpen(path, O_WRONLY|O_TRUNC|O_CREAT, 0666); + fd = open(path, O_WRONLY|O_TRUNC|O_CREAT, 0666); else - fd = fileXioOpen(path, O_RDONLY); + fd = open(path, O_RDONLY); if (fd >= 0) { if (gUSBPrefix[0] != '\0') sprintf(target, "mass%d:%s/", i, gUSBPrefix); else sprintf(target, "mass%d:", i); - fileXioClose(fd); + close(fd); return 1; } } @@ -97,8 +100,8 @@ void usbInit(void) { LOG("USBSUPPORT Init\n"); usbULSizePrev = -2; - memset(usbModifiedCDPrev, 0, sizeof(usbModifiedCDPrev)); - memset(usbModifiedDVDPrev, 0, sizeof(usbModifiedDVDPrev)); + usbModifiedCDPrev = 0; + usbModifiedDVDPrev = 0; usbGameCount = 0; usbGames = NULL; configGetInt(configGetByType(CONFIG_OPL), "usb_frames_delay", &usbGameList.delay); @@ -119,7 +122,7 @@ static int usbNeedsUpdate(void) static unsigned char ThemesLoaded = 0; static unsigned char LanguagesLoaded = 0; int result = 0; - iox_stat_t stat; + struct stat st; if (usbULSizePrev != -2 && OldGeneration == UsbGeneration) return 0; @@ -128,18 +131,18 @@ static int usbNeedsUpdate(void) usbFindPartition(usbPrefix, "ul.cfg", 0); sprintf(path, "%sCD", usbPrefix); - if (fileXioGetStat(path, &stat) != 0) - memset(stat.mtime, 0, sizeof(stat.mtime)); - if (memcmp(usbModifiedCDPrev, stat.mtime, sizeof(usbModifiedCDPrev))) { - memcpy(usbModifiedCDPrev, stat.mtime, sizeof(usbModifiedCDPrev)); + if (stat(path, &st) != 0) + st.st_mtime = 0; + if (usbModifiedCDPrev != st.st_mtime) { + usbModifiedCDPrev = st.st_mtime; result = 1; } sprintf(path, "%sDVD", usbPrefix); - if (fileXioGetStat(path, &stat) != 0) - memset(stat.mtime, 0, sizeof(stat.mtime)); - if (memcmp(usbModifiedDVDPrev, stat.mtime, sizeof(usbModifiedDVDPrev))) { - memcpy(usbModifiedDVDPrev, stat.mtime, sizeof(usbModifiedDVDPrev)); + if (stat(path, &st) != 0) + st.st_mtime = 0; + if (usbModifiedDVDPrev != st.st_mtime) { + usbModifiedDVDPrev = st.st_mtime; result = 1; } @@ -240,7 +243,7 @@ static void usbLaunchGame(int id, config_set_t *configSet) sprintf(vmc_path, "%sVMC/%s.bin", usbPrefix, vmc_name); - fd = fileXioOpen(vmc_path, O_RDONLY); + fd = open(vmc_path, O_RDONLY); if (fd >= 0) { if ((start = (unsigned int)fileXioIoctl(fd, USBMASS_IOCTL_GET_LBA, vmc_path)) != 0 && (startCluster = (unsigned int)fileXioIoctl(fd, USBMASS_IOCTL_GET_CLUSTER, vmc_path)) != 0) { @@ -257,7 +260,7 @@ static void usbLaunchGame(int id, config_set_t *configSet) } } - fileXioClose(fd); + close(fd); } } } @@ -299,13 +302,13 @@ static void usbLaunchGame(int id, config_set_t *configSet) sprintf(partname, "%sul.%08X.%s.%02x", usbPrefix, USBA_crc32(game->name), game->startup, i); } - fd = fileXioOpen(partname, O_RDONLY); + fd = open(partname, O_RDONLY); if (fd >= 0) { settings->LBAs[i] = fileXioIoctl(fd, USBMASS_IOCTL_GET_LBA, partname); if (gCheckUSBFragmentation) { if ((startCluster = (unsigned int)fileXioIoctl(fd, USBMASS_IOCTL_GET_CLUSTER, partname)) == 0 || fileXioDevctl("xmass0:", XUSBHDFSD_CHECK_CLUSTER_CHAIN, &startCluster, 4, NULL, 0) == 0) { - fileXioClose(fd); + close(fd); //Game is fragmented. Do not continue. if (settings != NULL) sbUnprepare(&settings->common); @@ -318,7 +321,7 @@ static void usbLaunchGame(int id, config_set_t *configSet) if ((gPS2Logo) && (i == 0)) EnablePS2Logo = CheckPS2Logo(fd, 0); - fileXioClose(fd); + close(fd); } else { //Unable to open part of the game. Do not continue. if (settings != NULL) diff --git a/src/util.c b/src/util.c index 06ea3cea9..591597f71 100644 --- a/src/util.c +++ b/src/util.c @@ -8,10 +8,8 @@ #include "include/util.h" #include "include/ioman.h" #include "include/system.h" -#include #include #include -#include #include #include "include/hdd.h" @@ -32,8 +30,8 @@ int getmcID(void) int getFileSize(int fd) { - int size = fileXioLseek(fd, 0, SEEK_END); - fileXioLseek(fd, 0, SEEK_SET); + int size = lseek(fd, 0, SEEK_END); + lseek(fd, 0, SEEK_SET); return size; } @@ -43,55 +41,56 @@ static void writeMCIcon(void) fd = openFile("mc?:OPL/opl.icn", O_WRONLY | O_CREAT | O_TRUNC); if (fd >= 0) { - fileXioWrite(fd, &icon_icn, size_icon_icn); - fileXioClose(fd); + write(fd, &icon_icn, size_icon_icn); + close(fd); } fd = openFile("mc?:OPL/icon.sys", O_WRONLY | O_CREAT | O_TRUNC); if (fd >= 0) { - fileXioWrite(fd, &icon_sys, size_icon_sys); - fileXioClose(fd); + write(fd, &icon_sys, size_icon_sys); + close(fd); } } void checkMCFolder(void) { char path[32]; + int fd; snprintf(path, sizeof(path), "mc%d:OPL", mcID); - int fd = fileXioDopen(path); - if (fd < 0) - fileXioMkdir(path, 0777); - - fileXioDclose(fd); + DIR *dir = opendir(path); + if (dir != NULL) + mkdir(path, 0777); + else + closedir(dir); snprintf(path, sizeof(path), "mc%d:OPL/opl.icn", mcID); - fd = fileXioOpen(path, O_RDONLY, 0666); + fd = open(path, O_RDONLY, 0666); if (fd < 0) writeMCIcon(); - fileXioClose(fd); + close(fd); snprintf(path, sizeof(path), "mc%d:OPL/icon.sys", mcID); - fd = fileXioOpen(path, O_RDONLY, 0666); + fd = open(path, O_RDONLY, 0666); if (fd < 0) writeMCIcon(); - fileXioClose(fd); + close(fd); } static int checkMC() { - int dummy, ret; + int dummy, ret, fd; if (mcID == -1) { mcGetInfo(0, 0, &dummy, &dummy, &dummy); mcSync(0, NULL, &ret); - int fd = fileXioDopen("mc0:OPL"); - if (fd < 0) { - fd = fileXioDopen("mc1:OPL"); - if (fd < 0) { + DIR *dir = opendir("mc0:OPL"); + if (dir == NULL) { + dir = opendir("mc1:OPL"); + if (dir == NULL) { // No base dir found on any MC, check MC is inserted fd = sysCheckMC(); if (fd == 0) @@ -99,11 +98,11 @@ static int checkMC() else if (fd == 1) mcID = 0x31; } else { - fileXioDclose(fd); + closedir(dir); mcID = 0x31; } } else { - fileXioDclose(fd); + closedir(dir); mcID = 0x30; } } @@ -132,12 +131,12 @@ static int checkFile(char *path, int mode) if (pos) { memcpy(dirPath, path, pos - path); dirPath[pos - path] = '\0'; - int fd = fileXioDopen(dirPath); - if (fd < 0) { - if (fileXioMkdir(dirPath, 0777) < 0) + DIR *dir = opendir(dirPath); + if (dir == NULL) { + if (mkdir(dirPath, 0777) < 0) return 0; } else - fileXioDclose(fd); + closedir(dir); } } } @@ -147,7 +146,7 @@ static int checkFile(char *path, int mode) int openFile(char *path, int mode) { if (checkFile(path, mode)) - return fileXioOpen(path, mode, 0666); + return open(path, mode, 0666); else return -1; } @@ -162,7 +161,7 @@ void *readFile(char *path, int align, int *size) if ((*size > 0) && (*size != realSize)) { LOG("UTIL Invalid filesize, expected: %d, got: %d\n", *size, realSize); - fileXioClose(fd); + close(fd); return NULL; } @@ -175,8 +174,8 @@ void *readFile(char *path, int align, int *size) LOG("UTIL ReadFile: Failed allocation of %d bytes", realSize); *size = 0; } else { - fileXioRead(fd, buffer, realSize); - fileXioClose(fd); + read(fd, buffer, realSize); + close(fd); *size = realSize; } } @@ -186,16 +185,21 @@ void *readFile(char *path, int align, int *size) int listDir(char *path, const char *separator, int maxElem, int (*readEntry)(int index, const char *path, const char *separator, const char *name, unsigned int mode)) { - int fdDir, index = 0; - if (checkFile(path, O_RDONLY)) { - iox_dirent_t record; + int index = 0; + struct stat st; + char filename[128]; - fdDir = fileXioDopen(path); - if (fdDir > 0) { - while (index < maxElem && fileXioDread(fdDir, &record) > 0) - index = readEntry(index, path, separator, record.name, record.stat.mode); + if (checkFile(path, O_RDONLY)) { + DIR *dir = opendir(path); + struct dirent *dirent; + if (dir != NULL) { + while (index < maxElem && (dirent = readdir(dir)) != NULL) { + snprintf(filename, 128, "%s/%s", path, dirent->d_name); + stat(filename, &st); + index = readEntry(index, path, separator, dirent->d_name, st.st_mode); + } - fileXioDclose(fdDir); + closedir(dir); } } return index; @@ -217,10 +221,10 @@ file_buffer_t *openFileBuffer(char *fpath, int mode, short allocResult, unsigned fileBuffer->lastPtr = NULL; //Check for and skip the UTF-8 BOM sequence. - if ((fileXioRead(fd, bom, sizeof(bom)) != 3) || + if ((read(fd, bom, sizeof(bom)) != 3) || (bom[0] != 0xEF || bom[1] != 0xBB || bom[2] != 0xBF)) { //Not BOM, so rewind. - fileXioLseek(fd, 0, SEEK_SET); + lseek(fd, 0, SEEK_SET); } } else fileBuffer->lastPtr = fileBuffer->buffer; @@ -254,7 +258,7 @@ file_buffer_t *openFileBufferBuffer(short allocResult, const void *buffer, unsig int readFileBuffer(file_buffer_t *fileBuffer, char **outBuf) { - int lineSize = 0, read, length; + int lineSize = 0, readSize, length; char *posLF = NULL; while (1) { @@ -281,20 +285,20 @@ int readFileBuffer(file_buffer_t *fileBuffer, char **outBuf) // Load as many characters necessary to fill the buffer length = fileBuffer->size - lineSize - 1; //LOG("##### Asking for %d characters to complete buffer\n", length); - read = fileXioRead(fileBuffer->fd, fileBuffer->buffer + lineSize, length); - fileBuffer->buffer[lineSize + read] = '\0'; + readSize = read(fileBuffer->fd, fileBuffer->buffer + lineSize, length); + fileBuffer->buffer[lineSize + readSize] = '\0'; // Search again (from the lastly added chars only), the result will be "analyzed" in next if posLF = strchr(fileBuffer->buffer + lineSize, '\n'); // Now update read context info - lineSize = lineSize + read; + lineSize = lineSize + readSize; //LOG("##### %d characters really read, line size now (\\0 not inc.): %d\n", read, lineSize); // If buffer not full it means we are at EOF if (fileBuffer->size != lineSize + 1) { //LOG("##### Reached EOF\n"); - fileXioClose(fileBuffer->fd); + close(fileBuffer->fd); fileBuffer->fd = -1; } } @@ -349,14 +353,14 @@ void writeFileBuffer(file_buffer_t *fileBuffer, char *inBuf, int size) //LOG("writeFileBuffer avail: %d size: %d\n", fileBuffer->available, size); if (fileBuffer->available && fileBuffer->available + size > fileBuffer->size) { //LOG("writeFileBuffer flushing: %d\n", fileBuffer->available); - fileXioWrite(fileBuffer->fd, fileBuffer->buffer, fileBuffer->available); + write(fileBuffer->fd, fileBuffer->buffer, fileBuffer->available); fileBuffer->lastPtr = fileBuffer->buffer; fileBuffer->available = 0; } if (size > fileBuffer->size) { //LOG("writeFileBuffer direct write: %d\n", size); - fileXioWrite(fileBuffer->fd, inBuf, size); + write(fileBuffer->fd, inBuf, size); } else { memcpy(fileBuffer->lastPtr, inBuf, size); fileBuffer->lastPtr += size; @@ -371,9 +375,9 @@ void closeFileBuffer(file_buffer_t *fileBuffer) if (fileBuffer->fd >= 0) { if (fileBuffer->mode != O_RDONLY && fileBuffer->available) { //LOG("writeFileBuffer final write: %d\n", fileBuffer->available); - fileXioWrite(fileBuffer->fd, fileBuffer->buffer, fileBuffer->available); + write(fileBuffer->fd, fileBuffer->buffer, fileBuffer->available); } - fileXioClose(fileBuffer->fd); + close(fileBuffer->fd); } free(fileBuffer->buffer); free(fileBuffer); @@ -480,7 +484,7 @@ int CheckPS2Logo(int fd, u32 lba) w = 0; if ((fd > 0) && (lba == 0)) // USB_MODE & ETH_MODE - w = fileXioRead(fd, logo, sizeof(logo)) == sizeof(logo); + w = read(fd, logo, sizeof(logo)) == sizeof(logo); if ((lba > 0) && (fd == 0)) { // HDD_MODE for (k = 0; k <= 12 * 4; k++) { // NB: Disc sector size (2048 bytes) and HDD sector size (512 bytes) differ, hence why we multiplied the number of sectors (12) by 4. w = !(hddReadSectors(lba + k, 1, buffer)); @@ -530,26 +534,31 @@ struct DirentToDelete { int sysDeleteFolder(const char *folder) { - int fd, result; + int result; char *path; - iox_dirent_t dirent; + struct dirent *dirent; + DIR *dir; + struct stat st; struct DirentToDelete *head, *start; result = 0; start = head = NULL; - if((fd = fileXioDopen(folder)) >= 0) { + if((dir = opendir(folder)) != NULL) { /* Generate a list of files in the directory. */ - while(fileXioDread(fd, &dirent) > 0) { - if((strcmp(dirent.name, ".") == 0) || ((strcmp(dirent.name, "..") == 0))) + while((dirent = readdir(dir)) != NULL) { + if((strcmp(dirent->d_name, ".") == 0) || ((strcmp(dirent->d_name, "..") == 0))) continue; - if(FIO_S_ISDIR(dirent.stat.mode)) { - if((path = malloc(strlen(folder)+strlen(dirent.name) + 2)) != NULL) { - sprintf(path, "%s/%s", folder, dirent.name); - result = sysDeleteFolder(path); - free(path); - } + path = malloc(strlen(folder)+strlen(dirent->d_name) + 2); + sprintf(path, "%s/%s", folder, dirent->d_name); + stat(path, &st); + + if(S_ISDIR(st.st_mode)) { + /* Recursive, delete all subfolders */ + result = sysDeleteFolder(path); + free(path); } else { + free(path); if(start == NULL) { head = malloc(sizeof(struct DirentToDelete)); if(head == NULL) @@ -564,16 +573,16 @@ int sysDeleteFolder(const char *folder) head->next=NULL; - if((head->filename = malloc(strlen(dirent.name) + 1)) != NULL) - strcpy(head->filename, dirent.name); + if((head->filename = malloc(strlen(dirent->d_name) + 1)) != NULL) + strcpy(head->filename, dirent->d_name); else break; } } - fileXioDclose(fd); + closedir(dir); } else - result = fd; + result = 0; if (result >= 0) { /* Delete the files. */ @@ -581,7 +590,7 @@ int sysDeleteFolder(const char *folder) if(head->filename != NULL) { if((path = malloc(strlen(folder) + strlen(head->filename) + 2)) != NULL) { sprintf(path, "%s/%s", folder, head->filename); - result=fileXioRemove(path); + result=unlink(path); if (result < 0) LOG("sysDeleteFolder: failed to remove %s: %d\n", path, result); @@ -595,7 +604,7 @@ int sysDeleteFolder(const char *folder) } if(result >= 0) { - result = fileXioRmdir(folder); + result = rmdir(folder); LOG("sysDeleteFolder: failed to rmdir %s: %d\n", folder, result); } }