mirror of
https://github.com/joel16/CMFileManager-PSP.git
synced 2024-11-26 21:20:24 +00:00
fs_driver: Extend functions and use fs_driver funcs with extended privileges
This commit is contained in:
parent
dfef7f0970
commit
cf7454758a
@ -31,34 +31,34 @@ typedef enum {
|
||||
|
||||
typedef struct ftppsp_client_info {
|
||||
/* Client number */
|
||||
int num;
|
||||
int num = 0;
|
||||
/* Thread UID */
|
||||
SceUID thid;
|
||||
SceUID thid = 0;
|
||||
/* Control connection socket FD */
|
||||
int ctrl_sockfd;
|
||||
int ctrl_sockfd = 0;
|
||||
/* Data connection attributes */
|
||||
int data_sockfd;
|
||||
DataConnectionType data_con_type;
|
||||
int data_sockfd = 0;
|
||||
DataConnectionType data_con_type = FTP_DATA_CONNECTION_NONE;
|
||||
struct sockaddr_in data_sockaddr;
|
||||
/* PASV mode client socket */
|
||||
struct sockaddr_in pasv_sockaddr;
|
||||
int pasv_sockfd;
|
||||
int pasv_sockfd = 0;
|
||||
/* Remote client net info */
|
||||
struct sockaddr_in addr;
|
||||
/* Receive buffer attributes */
|
||||
int n_recv;
|
||||
char recv_buffer[1024];
|
||||
int n_recv = 0;
|
||||
char recv_buffer[1024] = {0};
|
||||
/* Points to the character after the first space */
|
||||
const char *recv_cmd_args;
|
||||
const char *recv_cmd_args = nullptr;
|
||||
/* Current working directory */
|
||||
char cur_path[1024];
|
||||
char cur_path[1024] = {0};
|
||||
/* Rename path */
|
||||
char rename_path[1024];
|
||||
char rename_path[1024] = {0};
|
||||
/* Client list */
|
||||
struct ftppsp_client_info *next;
|
||||
struct ftppsp_client_info *prev;
|
||||
/* Offset for transfer resume */
|
||||
unsigned int restore_point;
|
||||
unsigned int restore_point = 0;
|
||||
} ftppsp_client_info_t;
|
||||
|
||||
typedef void (*cmd_dispatch_func)(ftppsp_client_info_t *client); // Command handler
|
||||
|
@ -18,9 +18,21 @@ extern int pspDisplayEnable(void);
|
||||
extern int pspDisplayDisable(void);
|
||||
|
||||
// fs_driver functions
|
||||
extern int pspOpenDir(const char *dirname);
|
||||
extern int pspReadDir(SceUID dir, SceIoDirent *dirent);
|
||||
extern int pspCloseDir(SceUID dir);
|
||||
extern int pspIoOpenDir(const char *dirname);
|
||||
extern int pspIoReadDir(SceUID dir, SceIoDirent *dirent);
|
||||
extern int pspIoCloseDir(SceUID dir);
|
||||
extern int pspIoMakeDir(const char *dir, SceMode mode);
|
||||
extern int pspIoRemoveDir(const char *path);
|
||||
extern int pspIoOpenFile(const char *file, int flags, SceMode mode);
|
||||
extern int pspIoReadFile(SceUID file, void *data, SceSize size);
|
||||
extern int pspIoWriteFile(SceUID file, void *data, SceSize size);
|
||||
extern int pspIoCloseFile(SceUID file);
|
||||
extern int pspIoLseek(SceUID file, SceOff offset, int whence);
|
||||
extern int pspIoLseek32(SceUID file, SceOff offset, int whence);
|
||||
extern int pspIoGetstat(const char *file, SceIoStat *stat);
|
||||
extern int pspIoRename(const char *oldname, const char *newname);
|
||||
extern int pspIoRemoveFile(const char *file);
|
||||
extern int pspIoDevctl(const char *dev, unsigned int cmd, void *indata, int inlen, void *outdata, int outlen);
|
||||
|
||||
// input_driver functions
|
||||
extern unsigned int pspGetButtons(void);
|
||||
|
@ -21,7 +21,11 @@ namespace FS {
|
||||
|
||||
bool FileExists(const std::string &path) {
|
||||
SceIoStat stat;
|
||||
#ifdef FS_DEBUG
|
||||
return sceIoGetstat(path.c_str(), &stat) >= 0;
|
||||
#else
|
||||
return pspIoGetstat(path.c_str(), &stat) >= 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
bool DirExists(const std::string &path) {
|
||||
@ -30,8 +34,8 @@ namespace FS {
|
||||
if (R_SUCCEEDED(dir = sceIoDopen(path.c_str()))) {
|
||||
sceIoDclose(dir);
|
||||
#else
|
||||
if (R_SUCCEEDED(dir = pspOpenDir(path.c_str()))) {
|
||||
pspCloseDir(dir);
|
||||
if (R_SUCCEEDED(dir = pspIoOpenDir(path.c_str()))) {
|
||||
pspIoCloseDir(dir);
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
@ -41,9 +45,13 @@ namespace FS {
|
||||
|
||||
int MakeDir(const std::string &path) {
|
||||
int ret = 0;
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (R_FAILED(ret = sceIoMkdir(path.c_str(), 0777)))
|
||||
return ret;
|
||||
#else
|
||||
if (R_FAILED(ret = pspIoMakeDir(path.c_str(), 0777)))
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
@ -70,11 +78,18 @@ namespace FS {
|
||||
|
||||
int CreateFile(const std::string &path) {
|
||||
SceUID file = 0;
|
||||
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (R_SUCCEEDED(file = sceIoOpen(path.c_str(), PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777))) {
|
||||
sceIoClose(file);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
if (R_SUCCEEDED(file = pspIoOpenFile(path.c_str(), PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777))) {
|
||||
pspIoCloseFile(file);
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
return file;
|
||||
}
|
||||
@ -111,8 +126,13 @@ namespace FS {
|
||||
SceIoStat stat;
|
||||
std::memset(&stat, 0, sizeof(stat));
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (R_FAILED(ret = sceIoGetstat(path.c_str(), &stat)))
|
||||
return ret;
|
||||
#else
|
||||
if (R_FAILED(ret = pspIoGetstat(path.c_str(), &stat)))
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
return stat.st_size;
|
||||
}
|
||||
@ -153,12 +173,20 @@ namespace FS {
|
||||
|
||||
int ReadFile(const std::string &path, void *buf, int size) {
|
||||
SceUID file = 0;
|
||||
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (R_SUCCEEDED(file = sceIoOpen(path.c_str(), PSP_O_RDONLY, 0))) {
|
||||
int read = sceIoRead(file, buf, size);
|
||||
sceIoClose(file);
|
||||
return read;
|
||||
}
|
||||
#else
|
||||
if (R_SUCCEEDED(file = pspIoOpenFile(path.c_str(), PSP_O_RDONLY, 0))) {
|
||||
int read = pspIoReadFile(file, buf, size);
|
||||
pspIoCloseFile(file);
|
||||
return read;
|
||||
}
|
||||
#endif
|
||||
|
||||
return file;
|
||||
}
|
||||
@ -166,11 +194,19 @@ namespace FS {
|
||||
int WriteFile(const std::string &path, void *buf, int size) {
|
||||
SceUID file = 0;
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (R_SUCCEEDED(file = sceIoOpen(path.c_str(), PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777))) {
|
||||
int written = sceIoWrite(file, buf, size);
|
||||
sceIoClose(file);
|
||||
return written;
|
||||
}
|
||||
#else
|
||||
if (R_SUCCEEDED(file = pspIoOpenFile(path.c_str(), PSP_O_WRONLY | PSP_O_CREAT | PSP_O_TRUNC, 0777))) {
|
||||
int written = pspIoWriteFile(file, buf, size);
|
||||
pspIoCloseFile(file);
|
||||
return written;
|
||||
}
|
||||
#endif
|
||||
|
||||
return file;
|
||||
}
|
||||
@ -221,8 +257,8 @@ namespace FS {
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
if (R_FAILED(ret = dir = pspOpenDir(path.c_str()))) {
|
||||
Log::Error("pspOpenDir(%s) failed: %08x\n", path.c_str(), ret);
|
||||
if (R_FAILED(ret = dir = pspIoOpenDir(path.c_str()))) {
|
||||
Log::Error("pspIoOpenDir(%s) failed: %08x\n", path.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
@ -233,7 +269,7 @@ namespace FS {
|
||||
#ifdef FS_DEBUG
|
||||
ret = sceIoDread(dir, &entry);
|
||||
#else
|
||||
ret = pspReadDir(dir, &entry);
|
||||
ret = pspIoReadDir(dir, &entry);
|
||||
#endif
|
||||
if (ret > 0) {
|
||||
if ((std::strcmp(entry.d_name, ".") == 0) || (std::strcmp(entry.d_name, "..") == 0))
|
||||
@ -248,7 +284,7 @@ namespace FS {
|
||||
#ifdef FS_DEBUG
|
||||
sceIoDclose(dir);
|
||||
#else
|
||||
pspCloseDir(dir);
|
||||
pspIoCloseDir(dir);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@ -291,27 +327,48 @@ namespace FS {
|
||||
int ret = 0;
|
||||
SceUID src_handle = 0, dest_handle = 0;
|
||||
scePowerLock(0);
|
||||
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (R_FAILED(ret = src_handle = sceIoOpen(src_path.c_str(), PSP_O_RDONLY, 0))) {
|
||||
Log::Error("sceIoOpen(%s) failed: 0x%x\n", src_path.c_str(), ret);
|
||||
scePowerUnlock(0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else
|
||||
if (R_FAILED(ret = src_handle = pspIoOpenFile(src_path.c_str(), PSP_O_RDONLY, 0))) {
|
||||
Log::Error("pspIoOpenFile(%s) failed: 0x%x\n", src_path.c_str(), ret);
|
||||
scePowerUnlock(0);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
u64 size = sceIoLseek(src_handle, 0, PSP_SEEK_END);
|
||||
sceIoLseek(src_handle, 0, PSP_SEEK_SET);
|
||||
#else
|
||||
u64 size = pspIoLseek(src_handle, 0, PSP_SEEK_END);
|
||||
pspIoLseek(src_handle, 0, PSP_SEEK_SET);
|
||||
#endif
|
||||
|
||||
// Make sure we have enough storage to carry out this operation
|
||||
if (Utils::GetFreeStorage() < size) {
|
||||
Log::Error("Not enough storage is available to process this command 0x%x\n", src_path.c_str(), ret);
|
||||
#ifdef FS_DEBUG
|
||||
sceIoClose(src_handle);
|
||||
#else
|
||||
pspIoCloseFile(src_handle);
|
||||
#endif
|
||||
scePowerUnlock(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (R_FAILED(ret = dest_handle = sceIoOpen(dest_path.c_str(), PSP_O_WRONLY | PSP_O_CREAT | PSP_O_APPEND, 0777))) {
|
||||
Log::Error("sceIoOpen(%s) failed: 0x%x\n", dest_path.c_str(), ret);
|
||||
#ifdef FS_DEBUG
|
||||
sceIoClose(src_handle);
|
||||
#else
|
||||
pspIoCloseFile(src_handle);
|
||||
#endif
|
||||
scePowerUnlock(0);
|
||||
return ret;
|
||||
}
|
||||
@ -325,28 +382,53 @@ namespace FS {
|
||||
do {
|
||||
if (Utils::IsCancelButtonPressed()) {
|
||||
delete[] buf;
|
||||
#ifdef FS_DEBUG
|
||||
sceIoClose(src_handle);
|
||||
sceIoClose(dest_handle);
|
||||
#else
|
||||
pspIoCloseFile(src_handle);
|
||||
pspIoCloseFile(dest_handle);
|
||||
#endif
|
||||
scePowerUnlock(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
std::memset(buf, 0, buf_size);
|
||||
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (R_FAILED(ret = bytes_read = sceIoRead(src_handle, buf, buf_size))) {
|
||||
Log::Error("sceIoRead(%s) failed: 0x%x\n", src_path.c_str(), ret);
|
||||
#else
|
||||
if (R_FAILED(ret = bytes_read = pspIoReadFile(src_handle, buf, buf_size))) {
|
||||
Log::Error("pspIoReadFile(%s) failed: 0x%x\n", src_path.c_str(), ret);
|
||||
#endif
|
||||
delete[] buf;
|
||||
#ifdef FS_DEBUG
|
||||
sceIoClose(src_handle);
|
||||
sceIoClose(dest_handle);
|
||||
#else
|
||||
pspIoCloseFile(src_handle);
|
||||
pspIoCloseFile(dest_handle);
|
||||
#endif
|
||||
scePowerUnlock(0);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (R_FAILED(ret = bytes_written = sceIoWrite(dest_handle, buf, bytes_read))) {
|
||||
Log::Error("sceIoWrite(%s) failed: 0x%x\n", dest_path.c_str(), ret);
|
||||
#else
|
||||
if (R_FAILED(ret = bytes_written = pspIoWriteFile(dest_handle, buf, bytes_read))) {
|
||||
Log::Error("pspIoWriteFile(%s) failed: 0x%x\n", dest_path.c_str(), ret);
|
||||
#endif
|
||||
delete[] buf;
|
||||
#ifdef FS_DEBUG
|
||||
sceIoClose(src_handle);
|
||||
sceIoClose(dest_handle);
|
||||
#else
|
||||
pspIoCloseFile(src_handle);
|
||||
pspIoCloseFile(dest_handle);
|
||||
#endif
|
||||
scePowerUnlock(0);
|
||||
return ret;
|
||||
}
|
||||
@ -356,8 +438,13 @@ namespace FS {
|
||||
} while(offset < size);
|
||||
|
||||
delete[] buf;
|
||||
#ifdef FS_DEBUG
|
||||
sceIoClose(src_handle);
|
||||
sceIoClose(dest_handle);
|
||||
#else
|
||||
pspIoCloseFile(src_handle);
|
||||
pspIoCloseFile(dest_handle);
|
||||
#endif
|
||||
scePowerUnlock(0);
|
||||
return 0;
|
||||
}
|
||||
@ -372,14 +459,18 @@ namespace FS {
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
if (R_FAILED(ret = dir = pspOpenDir(src_path.c_str()))) {
|
||||
Log::Error("pspOpenDir(%s) failed: %08x\n", src_path.c_str(), ret);
|
||||
if (R_FAILED(ret = dir = pspIoOpenDir(src_path.c_str()))) {
|
||||
Log::Error("pspIoOpenDir(%s) failed: %08x\n", src_path.c_str(), ret);
|
||||
return dir;
|
||||
}
|
||||
#endif
|
||||
|
||||
// This may fail or not, but we don't care -> make the dir if it doesn't exist, otherwise continue.
|
||||
#ifdef FS_DEBUG
|
||||
sceIoMkdir(dest_path.c_str(), 0777);
|
||||
#else
|
||||
pspIoMakeDir(dest_path.c_str(), 0777);
|
||||
#endif
|
||||
|
||||
do {
|
||||
SceIoDirent entry;
|
||||
@ -388,7 +479,7 @@ namespace FS {
|
||||
#ifdef FS_DEBUG
|
||||
ret = sceIoDread(dir, &entry);
|
||||
#else
|
||||
ret = pspReadDir(dir, &entry);
|
||||
ret = pspIoReadDir(dir, &entry);
|
||||
#endif
|
||||
if (ret > 0) {
|
||||
if ((std::strcmp(entry.d_name, ".") == 0) || (std::strcmp(entry.d_name, "..") == 0))
|
||||
@ -407,7 +498,7 @@ namespace FS {
|
||||
#ifdef FS_DEBUG
|
||||
sceIoDclose(dir);
|
||||
#else
|
||||
pspCloseDir(dir);
|
||||
pspIoCloseDir(dir);
|
||||
#endif
|
||||
return 0;
|
||||
}
|
||||
@ -444,7 +535,7 @@ namespace FS {
|
||||
static int sceIoMove(const char *src, const char *dest) {
|
||||
int ret = 0;
|
||||
size_t i = 0;
|
||||
char strage[32];
|
||||
char strage[32] = {0};
|
||||
char *p1 = nullptr, *p2 = nullptr;
|
||||
p1 = std::strchr(src, ':');
|
||||
|
||||
@ -470,15 +561,22 @@ namespace FS {
|
||||
|
||||
strage[i] = '\0';
|
||||
|
||||
u32 data[2];
|
||||
u32 data[2] = {0};
|
||||
data[0] = (u32)(p1 + 1);
|
||||
data[1] = (u32)(p2 + 1);
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (R_FAILED(ret = sceIoDevctl(strage, 0x02415830, &data, sizeof(data), nullptr, 0))) {
|
||||
Log::Error("sceIoDevctl() failed!", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
#else
|
||||
if (R_FAILED(ret = pspIoDevctl(strage, 0x02415830, &data, sizeof(data), nullptr, 0))) {
|
||||
Log::Error("pspIoDevctl() failed!", ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -503,18 +601,20 @@ namespace FS {
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (R_FAILED(ret = dir = sceIoDopen(path.c_str()))) {
|
||||
Log::Error("sceIoDopen(%s) failed: %08x\n", path.c_str(), ret);
|
||||
scePowerUnlock(0);
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
if (R_FAILED(ret = dir = pspOpenDir(path.c_str()))) {
|
||||
if (R_FAILED(ret = sceIoRemove(path.c_str()))) {
|
||||
Log::Error("sceIoRemove(%s) failed: %08x\n", path.c_str(), ret);
|
||||
scePowerUnlock(0);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
#else
|
||||
if (R_FAILED(ret = dir = pspIoOpenDir(path.c_str()))) {
|
||||
if (R_FAILED(ret = pspIoRemoveFile(path.c_str()))) {
|
||||
Log::Error("pspIoRemoveFile(%s) failed: %08x\n", path.c_str(), ret);
|
||||
scePowerUnlock(0);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
do {
|
||||
@ -522,7 +622,7 @@ namespace FS {
|
||||
#ifdef FS_DEBUG
|
||||
sceIoDclose(dir);
|
||||
#else
|
||||
pspCloseDir(dir);
|
||||
pspIoCloseDir(dir);
|
||||
#endif
|
||||
scePowerUnlock(0);
|
||||
return 0;
|
||||
@ -534,7 +634,7 @@ namespace FS {
|
||||
#ifdef FS_DEBUG
|
||||
ret = sceIoDread(dir, &entry);
|
||||
#else
|
||||
ret = pspReadDir(dir, &entry);
|
||||
ret = pspIoReadDir(dir, &entry);
|
||||
#endif
|
||||
if (ret > 0) {
|
||||
if ((std::strcmp(entry.d_name, ".") == 0) || (std::strcmp(entry.d_name, "..") == 0))
|
||||
@ -549,20 +649,23 @@ namespace FS {
|
||||
#ifdef FS_DEBUG
|
||||
sceIoDclose(dir);
|
||||
#else
|
||||
pspCloseDir(dir);
|
||||
pspIoCloseDir(dir);
|
||||
#endif
|
||||
scePowerUnlock(0);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
else {
|
||||
#ifdef FS_DEBUG
|
||||
int result = sceIoRemove(new_path.c_str());
|
||||
if (R_FAILED(result)) {
|
||||
Log::Error("sceIoRemove(%s) failed: %08x\n", path.c_str(), ret);
|
||||
#ifdef FS_DEBUG
|
||||
sceIoDclose(dir);
|
||||
#else
|
||||
pspCloseDir(dir);
|
||||
int result = pspIoRemoveFile(new_path.c_str());
|
||||
if (R_FAILED(result)) {
|
||||
Log::Error("pspIoRemoveFile(%s) failed: %08x\n", path.c_str(), ret);
|
||||
pspIoCloseDir(dir);
|
||||
#endif
|
||||
scePowerUnlock(0);
|
||||
return ret;
|
||||
@ -574,14 +677,21 @@ namespace FS {
|
||||
#ifdef FS_DEBUG
|
||||
sceIoDclose(dir);
|
||||
#else
|
||||
pspCloseDir(dir);
|
||||
pspIoCloseDir(dir);
|
||||
#endif
|
||||
scePowerUnlock(0);
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (R_FAILED(ret = sceIoRmdir(path.c_str()))) {
|
||||
Log::Error("sceIoRmdir(%s) failed: %08x\n", path.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
if (R_FAILED(ret = pspIoRemoveDir(path.c_str()))) {
|
||||
Log::Error("pspIoRemoveDir(%s) failed: %08x\n", path.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -597,10 +707,17 @@ namespace FS {
|
||||
}
|
||||
}
|
||||
else {
|
||||
#ifdef FS_DEBUG
|
||||
if (R_FAILED(ret = sceIoRemove(path.c_str()))) {
|
||||
Log::Error("sceIoRemove(%s) failed: 0x%x\n", path.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
if (R_FAILED(ret = pspIoRemoveFile(path.c_str()))) {
|
||||
Log::Error("pspIoRemoveFile(%s) failed: 0x%x\n", path.c_str(), ret);
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -14,7 +14,10 @@
|
||||
#include <psprtc.h>
|
||||
#include <sys/syslimits.h>
|
||||
|
||||
#include "fs.h"
|
||||
#include "ftppsp.h"
|
||||
#include "kernel_functions.h"
|
||||
#include "log.h"
|
||||
#include "mutex.h"
|
||||
|
||||
#define UNUSED(x) (void)(x)
|
||||
@ -28,37 +31,37 @@
|
||||
#define MAX_CUSTOM_COMMANDS 16
|
||||
|
||||
typedef struct {
|
||||
const char *cmd;
|
||||
const char *cmd = nullptr;
|
||||
cmd_dispatch_func func;
|
||||
} cmd_dispatch_entry;
|
||||
|
||||
static struct {
|
||||
char name[512];
|
||||
int valid;
|
||||
char name[512] = {0};
|
||||
int valid = 0;
|
||||
} device_list[MAX_DEVICES];
|
||||
|
||||
static struct {
|
||||
const char *cmd;
|
||||
const char *cmd = nullptr;
|
||||
cmd_dispatch_func func;
|
||||
int valid;
|
||||
int valid = 0;
|
||||
} custom_command_dispatchers[MAX_CUSTOM_COMMANDS];
|
||||
|
||||
static void *net_memory = nullptr;
|
||||
static int ftp_initialized = 0;
|
||||
static unsigned int file_buf_size = DEFAULT_FILE_BUF_SIZE;
|
||||
static struct in_addr psp_addr;
|
||||
static SceUID server_thid;
|
||||
static int server_sockfd;
|
||||
static SceUID server_thid = 0;
|
||||
static int server_sockfd = 0;
|
||||
static int number_clients = 0;
|
||||
static ftppsp_client_info_t *client_list = nullptr;
|
||||
static SceUID client_list_mtx;
|
||||
static SceUID client_list_mtx = 0;
|
||||
|
||||
static void (*info_log_cb)(const char *) = nullptr;
|
||||
static void (*debug_log_cb)(const char *) = nullptr;
|
||||
|
||||
static void log_func(ftppsp_log_cb_t log_cb, const char *s, ...) {
|
||||
if (log_cb) {
|
||||
char buf[256];
|
||||
char buf[256] = {0};
|
||||
va_list argptr;
|
||||
va_start(argptr, s);
|
||||
vsnprintf(buf, sizeof(buf), s, argptr);
|
||||
@ -124,11 +127,6 @@ static inline const char *get_psp_path(const char *path) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
static int file_exists(const char *path) {
|
||||
SceIoStat stat;
|
||||
return (sceIoGetstat(path, &stat) >= 0);
|
||||
}
|
||||
|
||||
static void cmd_NOOP_func(ftppsp_client_info_t *client) {
|
||||
client_send_ctrl_msg(client, "200 No operation ;)\r\n");
|
||||
}
|
||||
@ -153,7 +151,7 @@ static void cmd_PASV_func(ftppsp_client_info_t *client) {
|
||||
int ret;
|
||||
UNUSED(ret);
|
||||
|
||||
char cmd[512];
|
||||
char cmd[512] = {0};
|
||||
unsigned int namelen;
|
||||
struct sockaddr_in picked;
|
||||
|
||||
@ -165,7 +163,7 @@ static void cmd_PASV_func(ftppsp_client_info_t *client) {
|
||||
/* Fill the data socket address */
|
||||
client->data_sockaddr.sin_family = AF_INET;
|
||||
client->data_sockaddr.sin_addr.s_addr = SCE_HTONL(INADDR_ANY);
|
||||
/* Let the PSVita choose a port */
|
||||
/* Let the PSP choose a port */
|
||||
client->data_sockaddr.sin_port = SCE_HTONS(0);
|
||||
|
||||
/* Bind the data socket address to the data socket */
|
||||
@ -176,7 +174,7 @@ static void cmd_PASV_func(ftppsp_client_info_t *client) {
|
||||
ret = sceNetInetListen(client->data_sockfd, 128);
|
||||
DEBUG("sceNetInetListen(): 0x%08X\n", ret);
|
||||
|
||||
/* Get the port that the PSVita has chosen */
|
||||
/* Get the port that the PSP has chosen */
|
||||
namelen = sizeof(picked);
|
||||
sceNetInetGetsockname(client->data_sockfd, (struct sockaddr *)&picked, &namelen);
|
||||
|
||||
@ -198,10 +196,10 @@ static void cmd_PASV_func(ftppsp_client_info_t *client) {
|
||||
}
|
||||
|
||||
static void cmd_PORT_func(ftppsp_client_info_t *client) {
|
||||
unsigned int data_ip[4];
|
||||
unsigned int data_ip[4] = {0};
|
||||
unsigned int porthi, portlo;
|
||||
unsigned short data_port;
|
||||
char ip_str[16];
|
||||
char ip_str[16] = {0};
|
||||
struct in_addr data_addr;
|
||||
|
||||
/* Using ints because of newlibc's u8 std::sscanf bug */
|
||||
@ -266,7 +264,7 @@ static int gen_list_format(char *out, int n, int dir, const SceIoStat *stat, con
|
||||
"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
|
||||
};
|
||||
|
||||
char yt[13];
|
||||
char yt[13] = {0};
|
||||
pspTime cdt;
|
||||
sceRtcGetCurrentClockLocalTime(&cdt);
|
||||
|
||||
@ -275,13 +273,13 @@ static int gen_list_format(char *out, int n, int dir, const SceIoStat *stat, con
|
||||
else
|
||||
snprintf(yt, 11, "%04d", stat->st_mtime.year);
|
||||
|
||||
return snprintf(out, n, "%c%s 1 vita vita %u %s %-2d %s %s\r\n", dir ? 'd' : '-', dir ? "rwxr-xr-x" : "rw-r--r--",
|
||||
return snprintf(out, n, "%c%s 1 psp psp %u %s %-2d %s %s\r\n", dir ? 'd' : '-', dir ? "rwxr-xr-x" : "rw-r--r--",
|
||||
(unsigned int) stat->st_size, num_to_month[stat->st_mtime.month<=0?0:(stat->st_mtime.month-1)%12], stat->st_mtime.day,
|
||||
yt, filename);
|
||||
}
|
||||
|
||||
static void send_LIST(ftppsp_client_info_t *client, const char *path) {
|
||||
char buffer[512];
|
||||
char buffer[512] = {0};
|
||||
SceUID dir;
|
||||
SceIoDirent dirent;
|
||||
SceIoStat stat;
|
||||
@ -294,7 +292,11 @@ static void send_LIST(ftppsp_client_info_t *client, const char *path) {
|
||||
send_devices = 1;
|
||||
|
||||
if (!send_devices) {
|
||||
#ifdef FS_DEBUG
|
||||
dir = sceIoDopen(get_psp_path(path));
|
||||
#else
|
||||
dir = pspIoOpenDir(get_psp_path(path));
|
||||
#endif
|
||||
if (dir < 0) {
|
||||
client_send_ctrl_msg(client, "550 Invalid directory.\r\n");
|
||||
return;
|
||||
@ -309,6 +311,7 @@ static void send_LIST(ftppsp_client_info_t *client, const char *path) {
|
||||
for (int i = 0; i < MAX_DEVICES; i++) {
|
||||
if (device_list[i].valid) {
|
||||
devname = device_list[i].name;
|
||||
Log::Error("send_devices devname: [%d]%s\n", i, devname);
|
||||
gen_list_format(buffer, sizeof(buffer), 1, &stat, devname);
|
||||
client_send_data_msg(client, buffer);
|
||||
}
|
||||
@ -317,14 +320,22 @@ static void send_LIST(ftppsp_client_info_t *client, const char *path) {
|
||||
else {
|
||||
std::memset(&dirent, 0, sizeof(dirent));
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
while (sceIoDread(dir, &dirent) > 0) {
|
||||
#else
|
||||
while (pspIoReadDir(dir, &dirent) > 0) {
|
||||
#endif
|
||||
gen_list_format(buffer, sizeof(buffer), FIO_S_ISDIR(dirent.d_stat.st_mode), &dirent.d_stat, dirent.d_name);
|
||||
client_send_data_msg(client, buffer);
|
||||
std::memset(&dirent, 0, sizeof(dirent));
|
||||
std::memset(buffer, 0, sizeof(buffer));
|
||||
}
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
sceIoDclose(dir);
|
||||
#else
|
||||
pspIoCloseDir(dir);
|
||||
#endif
|
||||
}
|
||||
|
||||
DEBUG("Done sending LIST\n");
|
||||
@ -334,12 +345,12 @@ static void send_LIST(ftppsp_client_info_t *client, const char *path) {
|
||||
}
|
||||
|
||||
static void cmd_LIST_func(ftppsp_client_info_t *client) {
|
||||
char list_path[512];
|
||||
char list_path[512] = {0};
|
||||
int list_cur_path = 1;
|
||||
|
||||
int n = std::sscanf(client->recv_cmd_args, "%[^\r\n\t]", list_path);
|
||||
|
||||
if (n > 0 && file_exists(list_path))
|
||||
if (n > 0 && FS::FileExists(list_path))
|
||||
list_cur_path = 0;
|
||||
|
||||
if (list_cur_path)
|
||||
@ -349,7 +360,7 @@ static void cmd_LIST_func(ftppsp_client_info_t *client) {
|
||||
}
|
||||
|
||||
static void cmd_PWD_func(ftppsp_client_info_t *client) {
|
||||
char msg[1059];
|
||||
char msg[1059] = {0};
|
||||
snprintf(msg, 1058, "257 \"%s\" is the current directory.\r\n", client->cur_path);
|
||||
client_send_ctrl_msg(client, msg);
|
||||
}
|
||||
@ -381,8 +392,8 @@ static void dir_up(char *path) {
|
||||
}
|
||||
|
||||
static void cmd_CWD_func(ftppsp_client_info_t *client) {
|
||||
char cmd_path[512];
|
||||
char tmp_path[1537];
|
||||
char cmd_path[512] = {0};
|
||||
char tmp_path[1537] = {0};
|
||||
SceUID pd;
|
||||
int n = std::sscanf(client->recv_cmd_args, "%[^\r\n\t]", cmd_path);
|
||||
|
||||
@ -412,12 +423,22 @@ static void cmd_CWD_func(ftppsp_client_info_t *client) {
|
||||
/* If the path is not "/", check if it exists */
|
||||
if (std::strcmp(tmp_path, "/") != 0) {
|
||||
/* Check if the path exists */
|
||||
#ifdef FS_DEBUG
|
||||
pd = sceIoDopen(get_psp_path(tmp_path));
|
||||
#else
|
||||
pd = pspIoOpenDir(get_psp_path(tmp_path));
|
||||
#endif
|
||||
|
||||
if (pd < 0) {
|
||||
client_send_ctrl_msg(client, "550 Invalid directory.\r\n");
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
sceIoDclose(pd);
|
||||
#else
|
||||
pspIoCloseDir(pd);
|
||||
#endif
|
||||
}
|
||||
std::strcpy(client->cur_path, tmp_path);
|
||||
}
|
||||
@ -427,7 +448,7 @@ static void cmd_CWD_func(ftppsp_client_info_t *client) {
|
||||
|
||||
static void cmd_TYPE_func(ftppsp_client_info_t *client) {
|
||||
char data_type;
|
||||
char format_control[8];
|
||||
char format_control[8] = {0};
|
||||
int n_args = std::sscanf(client->recv_cmd_args, "%c %s", &data_type, format_control);
|
||||
|
||||
if (n_args > 0) {
|
||||
@ -458,9 +479,14 @@ static void send_file(ftppsp_client_info_t *client, const char *path) {
|
||||
unsigned int bytes_read;
|
||||
|
||||
DEBUG("Opening: %s\n", path);
|
||||
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if ((fd = sceIoOpen(path, PSP_O_RDONLY, 0777)) >= 0) {
|
||||
sceIoLseek32(fd, client->restore_point, PSP_SEEK_SET);
|
||||
#else
|
||||
if ((fd = pspIoOpenFile(path, PSP_O_RDONLY, 0777)) >= 0) {
|
||||
pspIoLseek32(fd, client->restore_point, PSP_SEEK_SET);
|
||||
#endif
|
||||
|
||||
buffer = new unsigned char[file_buf_size];
|
||||
if (buffer == nullptr) {
|
||||
@ -471,10 +497,18 @@ static void send_file(ftppsp_client_info_t *client, const char *path) {
|
||||
client_open_data_connection(client);
|
||||
client_send_ctrl_msg(client, "150 Opening Image mode data transfer.\r\n");
|
||||
|
||||
while ((bytes_read = sceIoRead (fd, buffer, file_buf_size)) > 0)
|
||||
#ifdef FS_DEBUG
|
||||
while ((bytes_read = sceIoRead(fd, buffer, file_buf_size)) > 0)
|
||||
#else
|
||||
while ((bytes_read = pspIoReadFile(fd, buffer, file_buf_size)) > 0)
|
||||
#endif
|
||||
client_send_data_raw(client, buffer, bytes_read);
|
||||
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
sceIoClose(fd);
|
||||
#else
|
||||
pspIoCloseFile(fd);
|
||||
#endif
|
||||
delete[] buffer;
|
||||
client->restore_point = 0;
|
||||
client_send_ctrl_msg(client, "226 Transfer completed.\r\n");
|
||||
@ -487,7 +521,7 @@ static void send_file(ftppsp_client_info_t *client, const char *path) {
|
||||
/* This function generates an FTP full-path with the input path (relative or absolute)
|
||||
* from RETR, STOR, DELE, RMD, MKD, RNFR and RNTO commands */
|
||||
static void gen_ftp_fullpath(ftppsp_client_info_t *client, char *path, size_t path_size) {
|
||||
char cmd_path[512];
|
||||
char cmd_path[512] = {0};
|
||||
std::sscanf(client->recv_cmd_args, "%[^\r\n\t]", cmd_path);
|
||||
|
||||
if (cmd_path[0] == '/')
|
||||
@ -504,7 +538,7 @@ static void gen_ftp_fullpath(ftppsp_client_info_t *client, char *path, size_t pa
|
||||
}
|
||||
|
||||
static void cmd_RETR_func(ftppsp_client_info_t *client) {
|
||||
char dest_path[512];
|
||||
char dest_path[512] = {0};
|
||||
gen_ftp_fullpath(client, dest_path, sizeof(dest_path));
|
||||
send_file(client, get_psp_path(dest_path));
|
||||
}
|
||||
@ -523,8 +557,12 @@ static void receive_file(ftppsp_client_info_t *client, const char *path) {
|
||||
mode = mode | PSP_O_APPEND;
|
||||
else
|
||||
mode = mode | PSP_O_TRUNC;
|
||||
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if ((fd = sceIoOpen(path, mode, 0777)) >= 0) {
|
||||
#else
|
||||
if ((fd = pspIoOpenFile(path, mode, 0777)) >= 0) {
|
||||
#endif
|
||||
buffer = new unsigned char[file_buf_size];
|
||||
if (buffer == nullptr) {
|
||||
client_send_ctrl_msg(client, "550 Could not allocate memory.\r\n");
|
||||
@ -535,15 +573,27 @@ static void receive_file(ftppsp_client_info_t *client, const char *path) {
|
||||
client_send_ctrl_msg(client, "150 Opening Image mode data transfer.\r\n");
|
||||
|
||||
while ((bytes_recv = client_recv_data_raw(client, buffer, file_buf_size)) > 0)
|
||||
#ifdef FS_DEBUG
|
||||
sceIoWrite(fd, buffer, bytes_recv);
|
||||
|
||||
#else
|
||||
pspIoWriteFile(fd, buffer, bytes_recv);
|
||||
#endif
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
sceIoClose(fd);
|
||||
#else
|
||||
pspIoCloseFile(fd);
|
||||
#endif
|
||||
delete[] buffer;
|
||||
client->restore_point = 0;
|
||||
if (bytes_recv == 0)
|
||||
client_send_ctrl_msg(client, "226 Transfer completed.\r\n");
|
||||
else {
|
||||
#ifdef FS_DEBUG
|
||||
sceIoRemove(path);
|
||||
#else
|
||||
pspIoRemoveFile(path);
|
||||
#endif
|
||||
client_send_ctrl_msg(client, "426 Connection closed; transfer aborted.\r\n");
|
||||
}
|
||||
client_close_data_connection(client);
|
||||
@ -553,7 +603,7 @@ static void receive_file(ftppsp_client_info_t *client, const char *path) {
|
||||
}
|
||||
|
||||
static void cmd_STOR_func(ftppsp_client_info_t *client) {
|
||||
char dest_path[512];
|
||||
char dest_path[512] = {0};
|
||||
gen_ftp_fullpath(client, dest_path, sizeof(dest_path));
|
||||
receive_file(client, get_psp_path(dest_path));
|
||||
}
|
||||
@ -561,14 +611,18 @@ static void cmd_STOR_func(ftppsp_client_info_t *client) {
|
||||
static void delete_file(ftppsp_client_info_t *client, const char *path) {
|
||||
DEBUG("Deleting: %s\n", path);
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (sceIoRemove(path) >= 0)
|
||||
#else
|
||||
if (pspIoRemoveFile(path) >= 0)
|
||||
#endif
|
||||
client_send_ctrl_msg(client, "226 File deleted.\r\n");
|
||||
else
|
||||
client_send_ctrl_msg(client, "550 Could not delete the file.\r\n");
|
||||
}
|
||||
|
||||
static void cmd_DELE_func(ftppsp_client_info_t *client) {
|
||||
char dest_path[512];
|
||||
char dest_path[512] = {0};
|
||||
gen_ftp_fullpath(client, dest_path, sizeof(dest_path));
|
||||
delete_file(client, get_psp_path(dest_path));
|
||||
}
|
||||
@ -576,7 +630,12 @@ static void cmd_DELE_func(ftppsp_client_info_t *client) {
|
||||
static void delete_dir(ftppsp_client_info_t *client, const char *path) {
|
||||
unsigned int ret;
|
||||
DEBUG("Deleting: %s\n", path);
|
||||
#ifdef FS_DEBUG
|
||||
ret = sceIoRmdir(path);
|
||||
#else
|
||||
ret = pspIoRemoveDir(path);
|
||||
#endif
|
||||
|
||||
if (ret >= 0)
|
||||
client_send_ctrl_msg(client, "226 Directory deleted.\r\n");
|
||||
else if (ret == 0x8001005A) /* DIRECTORY_IS_NOT_EMPTY */
|
||||
@ -586,7 +645,7 @@ static void delete_dir(ftppsp_client_info_t *client, const char *path) {
|
||||
}
|
||||
|
||||
static void cmd_RMD_func(ftppsp_client_info_t *client) {
|
||||
char dest_path[512];
|
||||
char dest_path[512] = {0};
|
||||
gen_ftp_fullpath(client, dest_path, sizeof(dest_path));
|
||||
delete_dir(client, get_psp_path(dest_path));
|
||||
}
|
||||
@ -594,27 +653,31 @@ static void cmd_RMD_func(ftppsp_client_info_t *client) {
|
||||
static void create_dir(ftppsp_client_info_t *client, const char *path) {
|
||||
DEBUG("Creating: %s\n", path);
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (sceIoMkdir(path, 0777) >= 0)
|
||||
#else
|
||||
if (pspIoMakeDir(path, 0777) >= 0)
|
||||
#endif
|
||||
client_send_ctrl_msg(client, "226 Directory created.\r\n");
|
||||
else
|
||||
client_send_ctrl_msg(client, "550 Could not create the directory.\r\n");
|
||||
}
|
||||
|
||||
static void cmd_MKD_func(ftppsp_client_info_t *client) {
|
||||
char dest_path[512];
|
||||
char dest_path[512] = {0};
|
||||
gen_ftp_fullpath(client, dest_path, sizeof(dest_path));
|
||||
create_dir(client, get_psp_path(dest_path));
|
||||
}
|
||||
|
||||
static void cmd_RNFR_func(ftppsp_client_info_t *client) {
|
||||
char path_src[512];
|
||||
char path_src[512] = {0};
|
||||
const char *psp_path_src;
|
||||
/* Get the origin filename */
|
||||
gen_ftp_fullpath(client, path_src, sizeof(path_src));
|
||||
psp_path_src = get_psp_path(path_src);
|
||||
|
||||
/* Check if the file exists */
|
||||
if (!file_exists(psp_path_src)) {
|
||||
if (!FS::FileExists(psp_path_src)) {
|
||||
client_send_ctrl_msg(client, "550 The file doesn't exist.\r\n");
|
||||
return;
|
||||
}
|
||||
@ -625,7 +688,7 @@ static void cmd_RNFR_func(ftppsp_client_info_t *client) {
|
||||
}
|
||||
|
||||
static void cmd_RNTO_func(ftppsp_client_info_t *client) {
|
||||
char path_dst[512];
|
||||
char path_dst[512] = {0};
|
||||
const char *psp_path_dst;
|
||||
|
||||
/* Get the destination filename */
|
||||
@ -634,7 +697,11 @@ static void cmd_RNTO_func(ftppsp_client_info_t *client) {
|
||||
|
||||
DEBUG("Renaming: %s to %s\n", client->rename_path, psp_path_dst);
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (sceIoRename(client->rename_path, psp_path_dst) < 0)
|
||||
#else
|
||||
if (pspIoRename(client->rename_path, psp_path_dst) < 0)
|
||||
#endif
|
||||
client_send_ctrl_msg(client, "550 Error renaming the file.\r\n");
|
||||
|
||||
client_send_ctrl_msg(client, "226 Rename completed.\r\n");
|
||||
@ -642,13 +709,17 @@ static void cmd_RNTO_func(ftppsp_client_info_t *client) {
|
||||
|
||||
static void cmd_SIZE_func(ftppsp_client_info_t *client) {
|
||||
SceIoStat stat;
|
||||
char path[512];
|
||||
char cmd[64];
|
||||
char path[512] = {0};
|
||||
char cmd[64] = {0};
|
||||
/* Get the filename to retrieve its size */
|
||||
gen_ftp_fullpath(client, path, sizeof(path));
|
||||
|
||||
/* Check if the file exists */
|
||||
#ifdef FS_DEBUG
|
||||
if (sceIoGetstat(get_psp_path(path), &stat) < 0) {
|
||||
#else
|
||||
if (pspIoGetstat(get_psp_path(path), &stat) < 0) {
|
||||
#endif
|
||||
client_send_ctrl_msg(client, "550 The file doesn't exist.\r\n");
|
||||
return;
|
||||
}
|
||||
@ -659,7 +730,7 @@ static void cmd_SIZE_func(ftppsp_client_info_t *client) {
|
||||
}
|
||||
|
||||
static void cmd_REST_func(ftppsp_client_info_t *client) {
|
||||
char cmd[64];
|
||||
char cmd[64] = {0};
|
||||
std::sscanf(client->recv_buffer, "%*[^ ] %d", &client->restore_point);
|
||||
std::sprintf(cmd, "350 Resuming at %d\r\n", client->restore_point);
|
||||
client_send_ctrl_msg(client, cmd);
|
||||
@ -674,11 +745,11 @@ static void cmd_FEAT_func(ftppsp_client_info_t *client) {
|
||||
|
||||
static void cmd_APPE_func(ftppsp_client_info_t *client) {
|
||||
/* set restore point to not 0
|
||||
restore point numeric value only matters if we RETR file from vita.
|
||||
restore point numeric value only matters if we RETR file from psp.
|
||||
If we STOR or APPE, it is only used to indicate that we want to resume
|
||||
a broken transfer */
|
||||
client->restore_point = -1;
|
||||
char dest_path[512];
|
||||
char dest_path[512] = {0};
|
||||
gen_ftp_fullpath(client, dest_path, sizeof(dest_path));
|
||||
receive_file(client, get_psp_path(dest_path));
|
||||
}
|
||||
@ -800,13 +871,13 @@ static void client_list_thread_end(void) {
|
||||
}
|
||||
|
||||
static int client_thread(SceSize args, void *argp) {
|
||||
char cmd[16];
|
||||
char cmd[16] = {0};
|
||||
cmd_dispatch_func dispatch_func;
|
||||
ftppsp_client_info_t *client = *(ftppsp_client_info_t **)argp;
|
||||
|
||||
DEBUG("Client thread %i started!\n", client->num);
|
||||
|
||||
client_send_ctrl_msg(client, "220 FTPVita Server ready.\r\n");
|
||||
client_send_ctrl_msg(client, "220 FTPPSP Server ready.\r\n");
|
||||
|
||||
while (true) {
|
||||
std::memset(client->recv_buffer, 0, sizeof(client->recv_buffer));
|
||||
@ -910,13 +981,13 @@ static int server_thread(SceSize args, void *argp) {
|
||||
DEBUG("New connection, client fd: 0x%08X\n", client_sockfd);
|
||||
|
||||
/* Get the client's IP address */
|
||||
char remote_ip[16];
|
||||
char remote_ip[16] = {0};
|
||||
sceNetInetInetNtop(AF_INET, &clientaddr.sin_addr.s_addr, remote_ip, sizeof(remote_ip));
|
||||
|
||||
INFO("Client %i connected, IP: %s port: %i\n", number_clients, remote_ip, clientaddr.sin_port);
|
||||
|
||||
/* Create a new thread for the client */
|
||||
char client_thread_name[64];
|
||||
char client_thread_name[64] = {0};
|
||||
std::sprintf(client_thread_name, "FTPpsp_client_%i_thread", number_clients);
|
||||
|
||||
SceUID client_thid = sceKernelCreateThread(client_thread_name, client_thread, 0x12, 0x2000, PSP_THREAD_ATTR_USBWLAN, nullptr);
|
||||
@ -965,7 +1036,7 @@ int ftppsp_init(char *psp_ip, unsigned short int *psp_port) {
|
||||
|
||||
*psp_port = FTP_PORT;
|
||||
|
||||
/* Save the IP of PSVita to a global variable */
|
||||
/* Save the IP of PSP to a global variable */
|
||||
if (sceNetInetInetPton(AF_INET, info.ip, &psp_addr) < 0)
|
||||
return -1;
|
||||
|
||||
@ -1029,6 +1100,8 @@ int ftppsp_add_device(const char *devname) {
|
||||
for (int i = 0; i < MAX_DEVICES; i++) {
|
||||
if (!device_list[i].valid) {
|
||||
std::strcpy(device_list[i].name, devname);
|
||||
Log::Error("ftppsp_add_device device_list.name: [%d]%s\n", i, device_list[i].name);
|
||||
Log::Error("ftppsp_add_device devname: [%d]%s\n", i, devname);
|
||||
device_list[i].valid = 1;
|
||||
return 1;
|
||||
}
|
||||
|
@ -19,13 +19,13 @@
|
||||
|
||||
namespace CSO {
|
||||
typedef struct {
|
||||
u8 magic[4]; /* +00 : 'C','I','S','O' */
|
||||
unsigned long header_size; /* +04 : header size (==0x18) */
|
||||
unsigned long long total_bytes; /* +08 : number of original data size */
|
||||
unsigned long block_size; /* +10 : number of compressed block size */
|
||||
u8 ver; /* +14 : version 01 */
|
||||
u8 align; /* +15 : align of index value */
|
||||
u8 rsv_06[2]; /* +16 : reserved */
|
||||
u8 magic[4] = {0}; /* +00 : 'C','I','S','O' */
|
||||
unsigned long header_size = 0; /* +04 : header size (==0x18) */
|
||||
unsigned long long total_bytes = 0; /* +08 : number of original data size */
|
||||
unsigned long block_size = 0; /* +10 : number of compressed block size */
|
||||
u8 ver = 0; /* +14 : version 01 */
|
||||
u8 align = 0; /* +15 : align of index value */
|
||||
u8 rsv_06[2] = {0}; /* +16 : reserved */
|
||||
} CISOHeader;
|
||||
|
||||
constexpr SceOff SECTOR_SIZE = 0x800;
|
||||
@ -59,7 +59,7 @@ namespace CSO {
|
||||
int ReadFile(char *buf, SceUID fd, int pos, int size) {
|
||||
static CISOHeader ciso;
|
||||
int index = 0, index2 = 0;
|
||||
char tmp_buf[SECTOR_SIZE * 2], tmp_buf_2[SECTOR_SIZE * 2];
|
||||
char tmp_buf[SECTOR_SIZE * 2] = {0}, tmp_buf_2[SECTOR_SIZE * 2] = {0};
|
||||
int ret = 0, error = 0;
|
||||
|
||||
if (R_FAILED(error = sceIoLseek(fd, 0, PSP_SEEK_SET)))
|
||||
@ -180,7 +180,7 @@ namespace ISO {
|
||||
}
|
||||
|
||||
int GetInfo(int *pos, int *size, int *size_pos, const std::string &path, int type, const char *name) {
|
||||
char work[256], s_path[256], s_file[256];
|
||||
char work[256] = {0}, s_path[256] = {0}, s_file[256] = {0};
|
||||
int path_table_addr = 0, path_table_size = 0;
|
||||
int dir_recode_addr = 0;
|
||||
short int befor_dir_num = 0x0001;
|
||||
@ -205,7 +205,7 @@ namespace ISO {
|
||||
std::strcpy(s_file, ptr);
|
||||
|
||||
///////
|
||||
u8 header[8];
|
||||
u8 header[8] = {0};
|
||||
ISO::ReadFile(header, path, type, 0x8000, sizeof(header));
|
||||
u8 magic[8] = { 0x01, 0x43, 0x44, 0x30, 0x30, 0x31, 0x01, 0x00 };
|
||||
|
||||
@ -450,7 +450,7 @@ namespace GameLauncher {
|
||||
|
||||
static int GetEbootMeta(const std::string &path, EbootMeta *meta) {
|
||||
int ret = 0;
|
||||
char title_buf[128];
|
||||
char title_buf[128] = {0};
|
||||
SceUID file = 0;
|
||||
PBPHeader pbp_data = { { 0 } };
|
||||
|
||||
@ -568,7 +568,7 @@ namespace GameLauncher {
|
||||
if (meta.icon0_data)
|
||||
icon0 = Textures::LoadImageBufferPNG(meta.icon0_data, meta.icon0_size);
|
||||
|
||||
char install_date[128];
|
||||
char install_date[128] = {0};
|
||||
const char *months[] = { "Dec", "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sept", "Oct", "Nov" };
|
||||
snprintf(install_date, 128, "Installed %d %s %d", stat.st_ctime.day, months[stat.st_ctime.month], stat.st_ctime.year);
|
||||
|
||||
|
@ -5,6 +5,7 @@
|
||||
#include "colours.h"
|
||||
#include "g2d.h"
|
||||
#include "gui.h"
|
||||
#include "kernel_functions.h"
|
||||
#include "textures.h"
|
||||
#include "utils.h"
|
||||
|
||||
@ -65,7 +66,11 @@ namespace Options {
|
||||
std::string name = G2D::KeyboardGetText("Enter new name", filename);
|
||||
std::string dest_path = FS::BuildPath(cfg.cwd, name);
|
||||
|
||||
#ifdef FS_DEBUG
|
||||
if (R_SUCCEEDED(sceIoRename(src_path.c_str(), dest_path.c_str()))) {
|
||||
#else
|
||||
if (R_SUCCEEDED(pspIoRename(src_path.c_str(), dest_path.c_str()))) {
|
||||
#endif
|
||||
FS::GetDirList(cfg.cwd, item->entries);
|
||||
Options::ResetSelector();
|
||||
options_more = false;
|
||||
|
@ -24,7 +24,7 @@ namespace GUI {
|
||||
item->entries[item->selected].d_name);
|
||||
|
||||
if (!(FIO_S_ISDIR(item->entries[item->selected].d_stat.st_mode))) {
|
||||
char size[16];
|
||||
char size[16] = {0};
|
||||
Utils::GetSizeString(size, item->entries[item->selected].d_stat.st_size);
|
||||
intraFontPrintf(font, 140, 92, "Size: %s", size);
|
||||
intraFontPrintf(font, 140, 110, "Created: %s", FS::GetFileTimestamp(item->entries[item->selected].d_stat, FileCreatedTime));
|
||||
|
@ -158,7 +158,7 @@ namespace FTP {
|
||||
|
||||
bool Init(char *string) {
|
||||
int ret = 0;
|
||||
char psp_ip[16];
|
||||
char psp_ip[16] = {0};
|
||||
unsigned short int psp_port = 0;
|
||||
|
||||
scePowerLock(0);
|
||||
|
@ -13,7 +13,7 @@
|
||||
#include "textures.h"
|
||||
#include "utils.h"
|
||||
|
||||
char font_size_cache[256];
|
||||
char font_size_cache[256] = {0};
|
||||
|
||||
/*
|
||||
This is a back-port of VITAShell's text editor by TheOfficialFloW.
|
||||
@ -50,7 +50,7 @@ namespace TextViewer {
|
||||
struct TextListEntry *previous;
|
||||
int line_number;
|
||||
int selected;
|
||||
char line[MAX_LINE_CHARACTERS];
|
||||
char line[MAX_LINE_CHARACTERS] = {0};
|
||||
} TextListEntry;
|
||||
|
||||
typedef struct {
|
||||
@ -60,7 +60,7 @@ namespace TextViewer {
|
||||
} TextList;
|
||||
|
||||
typedef struct CopyEntry {
|
||||
char line[MAX_LINE_CHARACTERS];
|
||||
char line[MAX_LINE_CHARACTERS] = {0};
|
||||
} CopyEntry;
|
||||
|
||||
typedef struct TextEditorState {
|
||||
@ -69,13 +69,13 @@ namespace TextViewer {
|
||||
int size;
|
||||
int base_pos;
|
||||
int rel_pos;
|
||||
int offset_list[MAX_LINES];
|
||||
int selection_list[MAX_SELECTION];
|
||||
int offset_list[MAX_LINES] = {0};
|
||||
int selection_list[MAX_SELECTION] = {0};
|
||||
int n_selections;
|
||||
int n_copied_lines;
|
||||
int copy_reset;
|
||||
int modify_allowed;
|
||||
CopyEntry copy_buffer[MAX_COPY_BUFFER_SIZE];
|
||||
CopyEntry copy_buffer[MAX_COPY_BUFFER_SIZE] = {0};
|
||||
TextList list;
|
||||
int changed;
|
||||
int edit_line;
|
||||
@ -216,7 +216,7 @@ namespace TextViewer {
|
||||
static void DeleteLine(TextEditorState *state, int line_number) {
|
||||
// Get current line
|
||||
int line_start = state->offset_list[line_number];
|
||||
char line[MAX_LINE_CHARACTERS];
|
||||
char line[MAX_LINE_CHARACTERS] = {0};
|
||||
int length = TextViewer::ReadLine(state->buffer, line_start, state->size, line);
|
||||
|
||||
// Remove line
|
||||
@ -483,7 +483,7 @@ namespace TextViewer {
|
||||
if (s->edit_line <= 0 && Utils::IsButtonPressed(PSP_CTRL_ENTER)) {
|
||||
int line_start = s->offset_list[s->base_pos + s->rel_pos];
|
||||
|
||||
char line[MAX_LINE_CHARACTERS];
|
||||
char line[MAX_LINE_CHARACTERS] = {0};
|
||||
TextViewer::ReadLine(s->buffer, line_start, s->size, line);
|
||||
|
||||
new_line = G2D::KeyboardGetText("Text editor", line);
|
||||
@ -513,7 +513,7 @@ namespace TextViewer {
|
||||
if (!new_line.empty()) {
|
||||
int line_start = s->offset_list[s->edit_line];
|
||||
|
||||
char line[MAX_LINE_CHARACTERS];
|
||||
char line[MAX_LINE_CHARACTERS] = {0};
|
||||
int length = TextViewer::ReadLine(s->buffer, line_start, s->size, line);
|
||||
|
||||
// Don't count newline
|
||||
@ -564,7 +564,7 @@ namespace TextViewer {
|
||||
char *line = entry->line;
|
||||
|
||||
if (entry->line_number < s->n_lines) {
|
||||
char line_str[5];
|
||||
char line_str[5] = {0};
|
||||
snprintf(line_str, 5, "%04i", entry->line_number);
|
||||
G2D::FontSetStyle(font, 1.f, (s->rel_pos == i)? TITLE_COLOUR : TEXT_COLOUR, INTRAFONT_ALIGN_LEFT);
|
||||
G2D::DrawText(SHELL_MARGIN_X, START_Y + (i * FONT_Y_SPACE), line_str);
|
||||
|
@ -8,9 +8,21 @@ int pspDisplayEnable(void);
|
||||
int pspDisplayDisable(void);
|
||||
|
||||
// fs_driver functions
|
||||
int pspOpenDir(const char *dirname);
|
||||
int pspReadDir(SceUID dir, SceIoDirent *dirent);
|
||||
int pspCloseDir(SceUID dir);
|
||||
int pspIoOpenDir(const char *dirname);
|
||||
int pspIoReadDir(SceUID dir, SceIoDirent *dirent);
|
||||
int pspIoCloseDir(SceUID dir);
|
||||
int pspIoMakeDir(const char *dir, SceMode mode);
|
||||
int pspIoRemoveDir(const char *path);
|
||||
int pspIoOpenFile(const char *file, int flags, SceMode mode);
|
||||
int pspIoReadFile(SceUID file, void *data, SceSize size);
|
||||
int pspIoWriteFile(SceUID file, void *data, SceSize size);
|
||||
int pspIoCloseFile(SceUID file);
|
||||
int pspIoLseek(SceUID file, SceOff offset, int whence);
|
||||
int pspIoLseek32(SceUID file, SceOff offset, int whence);
|
||||
int pspIoGetstat(const char *file, SceIoStat *stat);
|
||||
int pspIoRename(const char *oldname, const char *newname);
|
||||
int pspIoRemoveFile(const char *file);
|
||||
int pspIoDevctl(const char *dev, unsigned int cmd, void *indata, int inlen, void *outdata, int outlen);
|
||||
|
||||
// input_driver functions
|
||||
unsigned int pspGetButtons(void);
|
||||
|
@ -41,7 +41,7 @@ namespace Services {
|
||||
|
||||
// Font size cache
|
||||
for (int i = 0; i < 256; i++) {
|
||||
char character[2];
|
||||
char character[2] = {0};
|
||||
character[0] = i;
|
||||
character[1] = '\0';
|
||||
font_size_cache[i] = intraFontMeasureText(font, character);
|
||||
|
@ -87,7 +87,7 @@ static int AudioChannelThread(int args, void *argp) {
|
||||
int pspAudioInit(int format) {
|
||||
int ret = 0;
|
||||
bool failed = false;
|
||||
char str[32];
|
||||
char str[32] = {0};
|
||||
|
||||
audio_terminate = false;
|
||||
audio_ready = false;
|
||||
|
@ -10,9 +10,21 @@ PSP_EXPORT_VAR(module_info)
|
||||
PSP_EXPORT_END
|
||||
|
||||
PSP_EXPORT_START(fs_driver, 0, 0x4001)
|
||||
PSP_EXPORT_FUNC(pspOpenDir)
|
||||
PSP_EXPORT_FUNC(pspReadDir)
|
||||
PSP_EXPORT_FUNC(pspCloseDir)
|
||||
PSP_EXPORT_FUNC(pspIoOpenDir)
|
||||
PSP_EXPORT_FUNC(pspIoReadDir)
|
||||
PSP_EXPORT_FUNC(pspIoCloseDir)
|
||||
PSP_EXPORT_FUNC(pspIoMakeDir)
|
||||
PSP_EXPORT_FUNC(pspIoRemoveDir)
|
||||
PSP_EXPORT_FUNC(pspIoOpenFile)
|
||||
PSP_EXPORT_FUNC(pspIoReadFile)
|
||||
PSP_EXPORT_FUNC(pspIoWriteFile)
|
||||
PSP_EXPORT_FUNC(pspIoCloseFile)
|
||||
PSP_EXPORT_FUNC(pspIoLseek)
|
||||
PSP_EXPORT_FUNC(pspIoLseek32)
|
||||
PSP_EXPORT_FUNC(pspIoGetstat)
|
||||
PSP_EXPORT_FUNC(pspIoRename)
|
||||
PSP_EXPORT_FUNC(pspIoRemoveFile)
|
||||
PSP_EXPORT_FUNC(pspIoDevctl)
|
||||
PSP_EXPORT_END
|
||||
|
||||
PSP_END_EXPORTS
|
||||
|
@ -3,32 +3,171 @@
|
||||
|
||||
#include "systemctrl.h"
|
||||
|
||||
PSP_MODULE_INFO("fs_driver", PSP_MODULE_KERNEL, 1, 1);
|
||||
PSP_MODULE_INFO("fs_driver", PSP_MODULE_KERNEL, 1, 2);
|
||||
PSP_NO_CREATE_MAIN_THREAD();
|
||||
|
||||
int pspOpenDir(const char *dirname) {
|
||||
u32 k1 = 0;
|
||||
int oldlevel = sctrlKernelSetUserLevel(4);
|
||||
k1 = pspSdkSetK1(0);
|
||||
int pspIoOpenDir(const char *dirname) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoDopen(dirname);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(oldlevel);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pspReadDir(SceUID dir, SceIoDirent *dirent) {
|
||||
int pspIoReadDir(SceUID dir, SceIoDirent *dirent) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoDread(dir, dirent);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pspCloseDir(SceUID dir) {
|
||||
int pspIoCloseDir(SceUID dir) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoDclose(dir);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pspIoMakeDir(const char *dir, SceMode mode) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoMkdir(dir, mode);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pspIoRemoveDir(const char *path) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoRmdir(path);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pspIoOpenFile(const char *file, int flags, SceMode mode) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoOpen(file, flags, mode);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pspIoReadFile(SceUID file, void *data, SceSize size) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoRead(file, data, size);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pspIoWriteFile(SceUID file, const void *data, SceSize size) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoWrite(file, data, size);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pspIoCloseFile(SceUID file) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoClose(file);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pspIoLseek(SceUID file, SceOff offset, int whence) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoLseek(file, offset, whence);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pspIoLseek32(SceUID file, SceOff offset, int whence) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoLseek32(file, offset, whence);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pspIoGetstat(const char *file, SceIoStat *stat) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoGetstat(file, stat);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pspIoRename(const char *oldname, const char *newname) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoRename(oldname, newname);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pspIoRemoveFile(const char *file) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoRemove(file);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
int pspIoDevctl(const char *dev, unsigned int cmd, void *indata, int inlen, void *outdata, int outlen) {
|
||||
u32 k1 = pspSdkSetK1(0);
|
||||
int level = sctrlKernelSetUserLevel(8);
|
||||
|
||||
int ret = sceIoDevctl(dev, cmd, indata, inlen, outdata, outlen);
|
||||
|
||||
pspSdkSetK1(k1);
|
||||
sctrlKernelSetUserLevel(level);
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user