From 583b6d92ecaf6114dcf8575a0b5ffd41a1879476 Mon Sep 17 00:00:00 2001 From: Nekotekina Date: Thu, 12 Mar 2015 22:02:02 +0300 Subject: [PATCH] sys_fs syscalls detached from cellFs --- rpcs3/Emu/IdManager.h | 28 +- rpcs3/Emu/Memory/vm_var.h | 16 +- rpcs3/Emu/SysCalls/ErrorCodes.h | 2 +- rpcs3/Emu/SysCalls/ModuleManager.cpp | 4 +- rpcs3/Emu/SysCalls/Modules/cellFont.cpp | 4 +- rpcs3/Emu/SysCalls/Modules/cellFs.cpp | 769 ++++++++++++ rpcs3/Emu/SysCalls/Modules/cellFs.h | 40 + rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp | 41 +- rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp | 41 +- rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp | 44 +- rpcs3/Emu/SysCalls/Modules/cellResc.cpp | 2 +- rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp | 4 +- rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp | 6 +- rpcs3/Emu/SysCalls/SysCalls.cpp | 44 +- rpcs3/Emu/SysCalls/lv2/cellFs.cpp | 1091 ------------------ rpcs3/Emu/SysCalls/lv2/cellFs.h | 154 --- rpcs3/Emu/SysCalls/lv2/sys_fs.cpp | 511 ++++++++ rpcs3/Emu/SysCalls/lv2/sys_fs.h | 166 +++ rpcs3/emucore.vcxproj | 6 +- rpcs3/emucore.vcxproj.filters | 18 +- 20 files changed, 1635 insertions(+), 1356 deletions(-) create mode 100644 rpcs3/Emu/SysCalls/Modules/cellFs.cpp create mode 100644 rpcs3/Emu/SysCalls/Modules/cellFs.h delete mode 100644 rpcs3/Emu/SysCalls/lv2/cellFs.cpp delete mode 100644 rpcs3/Emu/SysCalls/lv2/cellFs.h create mode 100644 rpcs3/Emu/SysCalls/lv2/sys_fs.cpp create mode 100644 rpcs3/Emu/SysCalls/lv2/sys_fs.h diff --git a/rpcs3/Emu/IdManager.h b/rpcs3/Emu/IdManager.h index da2bc62b2c..eddb77e483 100644 --- a/rpcs3/Emu/IdManager.h +++ b/rpcs3/Emu/IdManager.h @@ -153,7 +153,9 @@ public: std::lock_guard lock(m_mtx_main); m_id_map.emplace(m_cur_id, ID(data, type)); - if (type < TYPE_OTHER) { + + if (type < TYPE_OTHER) + { m_types[type].insert(m_cur_id); } @@ -173,7 +175,8 @@ public: auto f = m_id_map.find(id); - if (f == m_id_map.end() || f->second.GetInfo() != typeid(T)) { + if (f == m_id_map.end() || f->second.GetInfo() != typeid(T)) + { return false; } @@ -182,6 +185,20 @@ public: return true; } + template std::shared_ptr GetIDData(const u32 id) + { + std::lock_guard lock(m_mtx_main); + + auto f = m_id_map.find(id); + + if (f == m_id_map.end() || f->second.GetInfo() != typeid(T)) + { + return nullptr; + } + + return f->second.GetData()->get(); + } + bool HasID(const u32 id) { std::lock_guard lock(m_mtx_main); @@ -195,10 +212,13 @@ public: auto item = m_id_map.find(id); - if (item == m_id_map.end() || item->second.GetInfo() != typeid(T)) { + if (item == m_id_map.end() || item->second.GetInfo() != typeid(T)) + { return false; } - if (item->second.GetType() < TYPE_OTHER) { + + if (item->second.GetType() < TYPE_OTHER) + { m_types[item->second.GetType()].erase(id); } diff --git a/rpcs3/Emu/Memory/vm_var.h b/rpcs3/Emu/Memory/vm_var.h index a8c380aac1..1a3d104c3d 100644 --- a/rpcs3/Emu/Memory/vm_var.h +++ b/rpcs3/Emu/Memory/vm_var.h @@ -108,14 +108,14 @@ namespace vm } */ - template operator const ps3::ptr() const + template operator _ptr_base() const { - return ps3::ptr::make(m_addr); + return _ptr_base::make(m_addr); } - template operator const ps3::ptr() const + template operator _ptr_base() const { - return ps3::ptr::make(m_addr); + return _ptr_base::make(m_addr); } operator T&() @@ -604,14 +604,14 @@ namespace vm } */ - template operator const ps3::ptr() const + template operator _ptr_base() const { - return ps3::ptr::make(m_data.addr); + return _ptr_base::make(m_data.addr); } - template operator const ps3::ptr() const + template operator _ptr_base() const { - return ps3::ptr::make(m_data.addr); + return _ptr_base::make(m_data.addr); } operator T&() diff --git a/rpcs3/Emu/SysCalls/ErrorCodes.h b/rpcs3/Emu/SysCalls/ErrorCodes.h index 5f5a512685..9cedbc510b 100644 --- a/rpcs3/Emu/SysCalls/ErrorCodes.h +++ b/rpcs3/Emu/SysCalls/ErrorCodes.h @@ -34,7 +34,7 @@ enum ErrorCode CELL_EFPOS = 0x8001001E, CELL_EINTR = 0x8001001F, CELL_EFBIG = 0x80010020, - CELL_EMLIN = 0x80010021, + CELL_EMLINK = 0x80010021, CELL_ENFILE = 0x80010022, CELL_ENOSPC = 0x80010023, CELL_ENOTTY = 0x80010024, diff --git a/rpcs3/Emu/SysCalls/ModuleManager.cpp b/rpcs3/Emu/SysCalls/ModuleManager.cpp index 02183c82e7..e0256fd20e 100644 --- a/rpcs3/Emu/SysCalls/ModuleManager.cpp +++ b/rpcs3/Emu/SysCalls/ModuleManager.cpp @@ -10,6 +10,7 @@ extern Module cellDmux; extern Module cellFiber; extern Module cellFont; extern Module cellFontFT; +extern Module cellFs; extern Module cellGame; extern Module cellGcmSys; extern Module cellGem; @@ -49,7 +50,6 @@ extern Module sceNpCommerce2; extern Module sceNpSns; extern Module sceNpTrophy; extern Module sceNpTus; -extern Module sys_fs; extern Module sys_io; extern Module sys_net; extern Module sysPrxForUser; @@ -77,7 +77,7 @@ static const g_module_list[] = { 0x000b, "cellOvis", &cellOvis }, { 0x000c, "cellSheap", nullptr }, { 0x000d, "sys_sync", &cellSync }, - { 0x000e, "sys_fs", &sys_fs }, + { 0x000e, "sys_fs", &cellFs }, { 0x000f, "cellJpgDec", &cellJpgDec }, { 0x0010, "cellGcmSys", &cellGcmSys }, { 0x0011, "cellAudio", &cellAudio }, diff --git a/rpcs3/Emu/SysCalls/Modules/cellFont.cpp b/rpcs3/Emu/SysCalls/Modules/cellFont.cpp index 6e58293669..3d574a2486 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellFont.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellFont.cpp @@ -30,7 +30,7 @@ int cellFontInitializeWithRevision(u64 revisionFlags, vm::ptr co return CELL_FONT_OK; } -int cellFontGetRevisionFlags(vm::ptr> revisionFlags) +int cellFontGetRevisionFlags(vm::ptr revisionFlags) { UNIMPLEMENTED_FUNC(cellFont); return CELL_FONT_OK; @@ -375,7 +375,7 @@ int cellFontSetEffectSlant(vm::ptr font, float slantParam) return CELL_FONT_OK; } -int cellFontGetEffectSlant(vm::ptr font, vm::ptr> slantParam) +int cellFontGetEffectSlant(vm::ptr font, vm::ptr slantParam) { cellFont.Warning("cellFontSetEffectSlant(font_addr=0x%x, slantParam_addr=0x%x)", font.addr(), slantParam.addr()); diff --git a/rpcs3/Emu/SysCalls/Modules/cellFs.cpp b/rpcs3/Emu/SysCalls/Modules/cellFs.cpp new file mode 100644 index 0000000000..d3ca1644ad --- /dev/null +++ b/rpcs3/Emu/SysCalls/Modules/cellFs.cpp @@ -0,0 +1,769 @@ +#include "stdafx.h" +#include "Emu/Memory/Memory.h" +#include "Emu/System.h" +#include "Emu/IdManager.h" +#include "Emu/SysCalls/Modules.h" +#include "Emu/SysCalls/Callback.h" +#include "Emu/SysCalls/CB_FUNC.h" + +#include "Emu/FS/VFS.h" +#include "Emu/FS/vfsFile.h" +#include "Emu/FS/vfsDir.h" + +#include "Emu/SysCalls/lv2/sys_fs.h" +#include "cellFs.h" + +extern Module cellFs; + +struct CellFsDirectoryEntry +{ + CellFsStat attribute; + CellFsDirent entry_name; +}; + +struct FsRingBufferConfig +{ + CellFsRingBuffer m_ring_buffer; // Currently unused after assignment + u32 m_buffer; + u64 m_fs_status; + u64 m_regid; + u32 m_alloc_mem_size; + u32 m_current_addr; + + FsRingBufferConfig() + : m_fs_status(CELL_FS_ST_NOT_INITIALIZED) + , m_regid(0) + , m_alloc_mem_size(0) + , m_current_addr(0) + , m_ring_buffer() { } + +} fs_config; + + +s32 cellFsOpen(vm::ptr path, s32 flags, vm::ptr fd, vm::ptr arg, u64 size) +{ + cellFs.Warning("cellFsOpen(path=*0x%x, flags=0x%x, fd=*0x%x, arg=*0x%x, size=0x%llx) -> sys_fs_open()", path, flags, fd, arg, size); + + // TODO + + // call the syscall + return sys_fs_open(path, flags, fd, 0, arg, size); +} + +s32 cellFsRead(PPUThread& CPU, u32 fd, vm::ptr buf, u64 nbytes, vm::ptr nread) +{ + cellFs.Log("cellFsRead(fd=0x%x, buf=0x%x, nbytes=0x%llx, nread=0x%x)", fd, buf, nbytes, nread); + + // call the syscall + return sys_fs_read(fd, buf, nbytes, nread ? nread : vm::stackvar>(CPU)); +} + +s32 cellFsWrite(PPUThread& CPU, u32 fd, vm::ptr buf, u64 nbytes, vm::ptr nwrite) +{ + cellFs.Log("cellFsWrite(fd=0x%x, buf=*0x%x, nbytes=0x%llx, nwrite=*0x%x)", fd, buf, nbytes, nwrite); + + // call the syscall + return sys_fs_write(fd, buf, nbytes, nwrite ? nwrite : vm::stackvar>(CPU)); +} + +s32 cellFsClose(u32 fd) +{ + cellFs.Log("cellFsClose(fd=0x%x)", fd); + + // call the syscall + return sys_fs_close(fd); +} + +s32 cellFsOpendir(vm::ptr path, vm::ptr fd) +{ + cellFs.Warning("cellFsOpendir(path=*0x%x, fd=*0x%x) -> sys_fs_opendir()", path, fd); + + // TODO + + // call the syscall + return sys_fs_opendir(path, fd); +} + +s32 cellFsReaddir(u32 fd, vm::ptr dir, vm::ptr nread) +{ + cellFs.Log("cellFsReaddir(fd=0x%x, dir=*0x%x, nread=*0x%x)", fd, dir, nread); + + // call the syscall + return dir && nread ? sys_fs_readdir(fd, dir, nread) : CELL_EFAULT; +} + +s32 cellFsClosedir(u32 fd) +{ + cellFs.Log("cellFsClosedir(fd=0x%x)", fd); + + // call the syscall + return sys_fs_closedir(fd); +} + +s32 cellFsStat(vm::ptr path, vm::ptr sb) +{ + cellFs.Warning("cellFsStat(path=*0x%x, sb=*0x%x) -> sys_fs_stat()", path, sb); + + // TODO + + // call the syscall + return sys_fs_stat(path, sb); +} + +s32 cellFsFstat(u32 fd, vm::ptr sb) +{ + cellFs.Log("cellFsFstat(fd=0x%x, sb=*0x%x)", fd, sb); + + // call the syscall + return sys_fs_fstat(fd, sb); +} + +s32 cellFsMkdir(vm::ptr path, CellFsMode mode) +{ + cellFs.Warning("cellFsMkdir(path=*0x%x, mode=%d) -> sys_fs_mkdir()", path, mode); + + // TODO + + // call the syscall + return sys_fs_mkdir(path, mode); +} + +s32 cellFsRename(vm::ptr from, vm::ptr to) +{ + cellFs.Warning("cellFsRename(from=*0x%x, to=*0x%x) -> sys_fs_rename()", from, to); + + // TODO + + // call the syscall + return sys_fs_rename(from, to); +} + +s32 cellFsRmdir(vm::ptr path) +{ + cellFs.Warning("cellFsRmdir(path=*0x%x) -> sys_fs_rmdir()", path); + + // TODO + + // call the syscall + return sys_fs_rmdir(path); +} + +s32 cellFsUnlink(vm::ptr path) +{ + cellFs.Warning("cellFsUnlink(path=*0x%x) -> sys_fs_unlink()", path); + + // TODO + + // call the syscall + return sys_fs_unlink(path); +} + +s32 cellFsLseek(u32 fd, s64 offset, u32 whence, vm::ptr pos) +{ + cellFs.Log("cellFsLseek(fd=0x%x, offset=0x%llx, whence=0x%x, pos=*0x%x)", fd, offset, whence, pos); + + // call the syscall + return pos ? sys_fs_lseek(fd, offset, whence, pos) : CELL_EFAULT; +} + +s32 cellFsFsync(u32 fd) +{ + cellFs.Todo("cellFsFsync(fd=0x%x)", fd); + + return CELL_OK; +} + +s32 cellFsFGetBlockSize(PPUThread& CPU, u32 fd, vm::ptr sector_size, vm::ptr block_size) +{ + cellFs.Log("cellFsFGetBlockSize(fd=0x%x, sector_size=*0x%x, block_size=*0x%x)", fd, sector_size, block_size); + + // call the syscall + return sector_size && block_size ? sys_fs_fget_block_size(fd, sector_size, block_size, vm::stackvar>(CPU), vm::stackvar>(CPU)) : CELL_EFAULT; +} + +s32 cellFsGetBlockSize(PPUThread& CPU, vm::ptr path, vm::ptr sector_size, vm::ptr block_size) +{ + cellFs.Warning("cellFsGetBlockSize(path=*0x%x, sector_size=*0x%x, block_size=*0x%x) -> sys_fs_get_block_size()", path, sector_size, block_size); + + // TODO + + // call the syscall + return sys_fs_get_block_size(path, sector_size, block_size, vm::stackvar>(CPU)); +} + +s32 cellFsTruncate(vm::ptr path, u64 size) +{ + cellFs.Warning("cellFsTruncate(path=*0x%x, size=0x%llx) -> sys_fs_truncate()", path, size); + + // TODO + + // call the syscall + return sys_fs_truncate(path, size); +} + +s32 cellFsFtruncate(u32 fd, u64 size) +{ + cellFs.Log("cellFsFtruncate(fd=0x%x, size=0x%llx)", fd, size); + + // call the syscall + return sys_fs_ftruncate(fd, size); +} + +s32 cellFsChmod(vm::ptr path, CellFsMode mode) +{ + cellFs.Warning("cellFsChmod(path=*0x%x, mode=%d) -> sys_fs_chmod()", path, mode); + + // TODO + + // call the syscall + return sys_fs_chmod(path, mode); +} + +s32 cellFsGetFreeSize(vm::ptr path, vm::ptr block_size, vm::ptr block_count) +{ + cellFs.Warning("cellFsGetFreeSize(path=*0x%x, block_size=*0x%x, block_count=*0x%x)", path, block_size, block_count); + cellFs.Warning("*** path = '%s'", path.get_ptr()); + + // TODO: Get real values. Currently, it always returns 40 GB of free space divided in 4 KB blocks + *block_size = 4096; // ? + *block_count = 10 * 1024 * 1024; // ? + + return CELL_OK; +} + +s32 cellFsGetDirectoryEntries(u32 fd, vm::ptr entries, u32 entries_size, vm::ptr data_count) +{ + cellFs.Warning("cellFsGetDirectoryEntries(fd=0x%x, entries=*0x%x, entries_size=0x%x, data_count=*0x%x)", fd, entries, entries_size, data_count); + + std::shared_ptr directory; + if (!Emu.GetIdManager().GetIDData(fd, directory)) + return CELL_ESRCH; + + const DirEntryInfo* info = directory->Read(); + if (info) + { + entries->attribute.mode = + CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR | + CELL_FS_S_IRGRP | CELL_FS_S_IWGRP | CELL_FS_S_IXGRP | + CELL_FS_S_IROTH | CELL_FS_S_IWOTH | CELL_FS_S_IXOTH; + + entries->attribute.uid = 0; + entries->attribute.gid = 0; + entries->attribute.atime = 0; //TODO + entries->attribute.mtime = 0; //TODO + entries->attribute.ctime = 0; //TODO + entries->attribute.blksize = 4096; + + entries->entry_name.d_type = (info->flags & DirEntry_TypeFile) ? CELL_FS_TYPE_REGULAR : CELL_FS_TYPE_DIRECTORY; + entries->entry_name.d_namlen = u8(std::min(info->name.length(), CELL_FS_MAX_FS_FILE_NAME_LENGTH)); + strcpy_trunc(entries->entry_name.d_name, info->name); + *data_count = 1; + } + else + { + *data_count = 0; + } + + return CELL_OK; +} + +s32 cellFsStReadInit(u32 fd, vm::ptr ringbuf) +{ + cellFs.Warning("cellFsStReadInit(fd=0x%x, ringbuf=*0x%x)", fd, ringbuf); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + fs_config.m_ring_buffer = *ringbuf; + + // If the size is less than 1MB + if (ringbuf->ringbuf_size < 0x40000000) + fs_config.m_alloc_mem_size = (((u32)ringbuf->ringbuf_size + 64 * 1024 - 1) / (64 * 1024)) * (64 * 1024); + else + fs_config.m_alloc_mem_size = (((u32)ringbuf->ringbuf_size + 1024 * 1024 - 1) / (1024 * 1024)) * (1024 * 1024); + + // alloc memory + fs_config.m_buffer = (u32)Memory.Alloc(fs_config.m_alloc_mem_size, 1024); + memset(vm::get_ptr(fs_config.m_buffer), 0, fs_config.m_alloc_mem_size); + + fs_config.m_fs_status = CELL_FS_ST_INITIALIZED; + + return CELL_OK; +} + +s32 cellFsStReadFinish(u32 fd) +{ + cellFs.Warning("cellFsStReadFinish(fd=0x%x)", fd); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + Memory.Free(fs_config.m_buffer); + fs_config.m_fs_status = CELL_FS_ST_NOT_INITIALIZED; + + return CELL_OK; +} + +s32 cellFsStReadGetRingBuf(u32 fd, vm::ptr ringbuf) +{ + cellFs.Warning("cellFsStReadGetRingBuf(fd=0x%x, ringbuf=*0x%x)", fd, ringbuf); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + *ringbuf = fs_config.m_ring_buffer; + + cellFs.Warning("*** fs stream config: block_size=0x%llx, copy=0x%x, ringbuf_size=0x%llx, transfer_rate=0x%llx", + ringbuf->block_size, ringbuf->copy, ringbuf->ringbuf_size, ringbuf->transfer_rate); + return CELL_OK; +} + +s32 cellFsStReadGetStatus(u32 fd, vm::ptr status) +{ + cellFs.Warning("cellFsStReadGetRingBuf(fd=0x%x, status=*0x%x)", fd, status); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + *status = fs_config.m_fs_status; + + return CELL_OK; +} + +s32 cellFsStReadGetRegid(u32 fd, vm::ptr regid) +{ + cellFs.Warning("cellFsStReadGetRingBuf(fd=0x%x, regid=*0x%x)", fd, regid); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + *regid = fs_config.m_regid; + + return CELL_OK; +} + +s32 cellFsStReadStart(u32 fd, u64 offset, u64 size) +{ + cellFs.Todo("cellFsStReadStart(fd=0x%x, offset=0x%llx, size=0x%llx)", fd, offset, size); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + fs_config.m_current_addr = fs_config.m_buffer + (u32)offset; + fs_config.m_fs_status = CELL_FS_ST_PROGRESS; + + return CELL_OK; +} + +s32 cellFsStReadStop(u32 fd) +{ + cellFs.Warning("cellFsStReadStop(fd=0x%x)", fd); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + fs_config.m_fs_status = CELL_FS_ST_STOP; + + return CELL_OK; +} + +s32 cellFsStRead(u32 fd, vm::ptr buf, u64 size, vm::ptr rsize) +{ + cellFs.Warning("cellFsStRead(fd=0x%x, buf=*0x%x, size=0x%llx, rsize=*0x%x)", fd, buf, size, rsize); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + // TODO: use ringbuffer (fs_config) + fs_config.m_regid += size; + + if (file->Eof()) + return CELL_FS_ERANGE; + + *rsize = file->Read(buf.get_ptr(), size); + + return CELL_OK; +} + +s32 cellFsStReadGetCurrentAddr(u32 fd, vm::ptr> addr, vm::ptr size) +{ + cellFs.Todo("cellFsStReadGetCurrentAddr(fd=0x%x, addr=*0x%x, size=*0x%x)", fd, addr, size); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + return CELL_OK; +} + +s32 cellFsStReadPutCurrentAddr(u32 fd, vm::ptr addr, u64 size) +{ + cellFs.Todo("cellFsStReadPutCurrentAddr(fd=0x%x, addr=*0x%x, size=0x%llx)", fd, addr, size); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + return CELL_OK; +} + +s32 cellFsStReadWait(u32 fd, u64 size) +{ + cellFs.Todo("cellFsStReadWait(fd=0x%x, size=0x%llx)", fd, size); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + return CELL_OK; +} + +s32 cellFsStReadWaitCallback(u32 fd, u64 size, vm::ptr func) +{ + cellFs.Todo("cellFsStReadWaitCallback(fd=0x%x, size=0x%llx, func=*0x%x)", fd, size, func); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + return CELL_OK; +} + +bool sdata_check(u32 version, u32 flags, u64 filesizeInput, u64 filesizeTmp) +{ + if (version > 4 || flags & 0x7EFFFFC0){ + printf("ERROR: unknown version"); + return false; + } + + if ((version == 1 && (flags & 0x7FFFFFFE)) || + (version == 2 && (flags & 0x7EFFFFC0))){ + printf("ERROR: unknown or unsupported type"); + return false; + } + + if (filesizeTmp > filesizeInput){ + printf("ERROR: input file size is too short."); + return false; + } + + if (!(flags & 0x80000000)){ + printf("ERROR: cannot extract finalized edata."); + return false; + } + + return true; +} + +int sdata_unpack(const std::string& packed_file, const std::string& unpacked_file) +{ + std::shared_ptr packed_stream(Emu.GetVFS().OpenFile(packed_file, vfsRead)); + std::shared_ptr unpacked_stream(Emu.GetVFS().OpenFile(unpacked_file, vfsWrite)); + + if (!packed_stream || !packed_stream->IsOpened()) + { + cellFs.Error("'%s' not found! flags: 0x%02x", packed_file.c_str(), vfsRead); + return CELL_ENOENT; + } + + if (!unpacked_stream || !unpacked_stream->IsOpened()) + { + cellFs.Error("'%s' couldn't be created! flags: 0x%02x", unpacked_file.c_str(), vfsWrite); + return CELL_ENOENT; + } + + char buffer[10200]; + packed_stream->Read(buffer, 256); + u32 format = re32(*(u32*)&buffer[0]); + if (format != 0x4E504400) // "NPD\x00" + { + cellFs.Error("Illegal format. Expected 0x4E504400, but got 0x%08x", format); + return CELL_EFSSPECIFIC; + } + + u32 version = re32(*(u32*)&buffer[0x04]); + u32 flags = re32(*(u32*)&buffer[0x80]); + u32 blockSize = re32(*(u32*)&buffer[0x84]); + u64 filesizeOutput = re64(*(u64*)&buffer[0x88]); + u64 filesizeInput = packed_stream->GetSize(); + u32 blockCount = (u32)((filesizeOutput + blockSize - 1) / blockSize); + + // SDATA file is compressed + if (flags & 0x1) + { + cellFs.Warning("cellFsSdataOpen: Compressed SDATA files are not supported yet."); + return CELL_EFSSPECIFIC; + } + + // SDATA file is NOT compressed + else + { + u32 t1 = (flags & 0x20) ? 0x20 : 0x10; + u32 startOffset = (blockCount * t1) + 0x100; + u64 filesizeTmp = (filesizeOutput + 0xF) & 0xFFFFFFF0 + startOffset; + + if (!sdata_check(version, flags, filesizeInput, filesizeTmp)) + { + cellFs.Error("cellFsSdataOpen: Wrong header information."); + return CELL_EFSSPECIFIC; + } + + if (flags & 0x20) + packed_stream->Seek(0x100); + else + packed_stream->Seek(startOffset); + + for (u32 i = 0; i < blockCount; i++) + { + if (flags & 0x20) + packed_stream->Seek(packed_stream->Tell() + t1); + + if (!(blockCount - i - 1)) + blockSize = (u32)(filesizeOutput - i * blockSize); + + packed_stream->Read(buffer + 256, blockSize); + unpacked_stream->Write(buffer + 256, blockSize); + } + } + + return CELL_OK; +} + +s32 cellFsSdataOpen(vm::ptr path, s32 flags, vm::ptr fd, vm::ptr arg, u64 size) +{ + cellFs.Warning("cellFsSdataOpen(path=*0x%x, flags=0x%x, fd=*0x%x, arg=*0x%x, size=0x%llx) -> sys_fs_open()", path, flags, fd, arg, size); + + /*if (flags != CELL_O_RDONLY) + return CELL_EINVAL; + + std::string suffix = path.substr(path.length() - 5, 5); + if (suffix != ".sdat" && suffix != ".SDAT") + return CELL_ENOTSDATA; + + std::string::size_type last_slash = path.rfind('/'); //TODO: use a filesystem library to solve this more robustly + last_slash = last_slash == std::string::npos ? 0 : last_slash+1; + std::string unpacked_path = "/dev_hdd1/"+path.substr(last_slash,path.length()-last_slash)+".unpacked"; + int ret = sdata_unpack(path, unpacked_path); + if (ret) return ret; + + fd = Emu.GetIdManager().GetNewID(Emu.GetVFS().OpenFile(unpacked_path, vfsRead), TYPE_FS_FILE); + + return CELL_OK;*/ + + return sys_fs_open(path, flags, fd, 0, arg, size); +} + +s32 cellFsSdataOpenByFd(u32 mself_fd, s32 flags, vm::ptr sdata_fd, u64 offset, vm::ptr arg, u64 size) +{ + cellFs.Todo("cellFsSdataOpenByFd(mself_fd=0x%x, flags=0x%x, sdata_fd=*0x%x, offset=0x%llx, arg=*0x%x, size=0x%llx)", mself_fd, flags, sdata_fd, offset, arg, size); + + // TODO: + + return CELL_OK; +} + +std::atomic g_FsAioReadID(0); +std::atomic g_FsAioReadCur(0); +bool aio_init = false; + +void fsAioRead(u32 fd, vm::ptr aio, int xid, vm::ptr xaio, int error, int xid, u64 size)> func) +{ + while (g_FsAioReadCur != xid) + { + std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack + if (Emu.IsStopped()) + { + cellFs.Warning("fsAioRead() aborted"); + return; + } + } + + u32 error = CELL_OK; + u64 res = 0; + { + std::shared_ptr orig_file; + if (!Emu.GetIdManager().GetIDData(fd, orig_file)) + { + cellFs.Error("Wrong fd (%s)", fd); + Emu.Pause(); + return; + } + + u64 nbytes = aio->size; + + vfsStream& file = *orig_file; + const u64 old_pos = file.Tell(); + file.Seek((u64)aio->offset); + + if (nbytes != (u32)nbytes) + { + error = CELL_ENOMEM; + } + else + { + res = nbytes ? file.Read(aio->buf.get_ptr(), nbytes) : 0; + } + + file.Seek(old_pos); + + cellFs.Log("*** fsAioRead(fd=%d, offset=0x%llx, buf=0x%x, size=0x%llx, error=0x%x, res=0x%llx, xid=0x%x)", + fd, aio->offset, aio->buf, aio->size, error, res, xid); + } + + if (func) + { + Emu.GetCallbackManager().Async([func, aio, error, xid, res](PPUThread& CPU) + { + func(CPU, aio, error, xid, res); + }); + } + + g_FsAioReadCur++; +} + +s32 cellFsAioRead(vm::ptr aio, vm::ptr id, vm::ptr xaio, s32 error, s32 xid, u64 size)> func) +{ + cellFs.Warning("cellFsAioRead(aio=*0x%x, id=*0x%x, func=*0x%x)", aio, id, func); + + if (!aio_init) + { + return CELL_ENXIO; + } + + std::shared_ptr orig_file; + u32 fd = aio->fd; + + if (!Emu.GetIdManager().GetIDData(fd, orig_file)) + { + return CELL_EBADF; + } + + //get a unique id for the callback (may be used by cellFsAioCancel) + const s32 xid = g_FsAioReadID++; + *id = xid; + + thread_t t("CellFsAio Reading Thread", std::bind(fsAioRead, fd, aio, xid, func)); + return CELL_OK; +} + +s32 cellFsAioWrite(vm::ptr aio, vm::ptr id, vm::ptr xaio, s32 error, s32 xid, u64 size)> func) +{ + cellFs.Todo("cellFsAioWrite(aio=*0x%x, id=*0x%x, func=*0x%x)", aio, id, func); + + // TODO: + + return CELL_OK; +} + +s32 cellFsAioInit(vm::ptr mount_point) +{ + cellFs.Warning("cellFsAioInit(mount_point=*0x%x)", mount_point); + cellFs.Warning("*** mount_point = '%s'", mount_point.get_ptr()); + + aio_init = true; + return CELL_OK; +} + +s32 cellFsAioFinish(vm::ptr mount_point) +{ + cellFs.Warning("cellFsAioFinish(mount_point=*0x%x)", mount_point); + cellFs.Warning("*** mount_point = '%s'", mount_point.get_ptr()); + + //aio_init = false; + return CELL_OK; +} + +s32 cellFsReadWithOffset(PPUThread& CPU, u32 fd, u64 offset, vm::ptr buf, u64 buffer_size, vm::ptr nread) +{ + cellFs.Warning("cellFsReadWithOffset(fd=%d, offset=0x%llx, buf=*0x%x, buffer_size=%lld, nread=*0x%llx)", fd, offset, buf, buffer_size, nread); + + int ret; + vm::stackvar> oldPos(CPU), newPos(CPU); + ret = cellFsLseek(fd, 0, CELL_FS_SEEK_CUR, oldPos); // Save the current position + if (ret) return ret; + ret = cellFsLseek(fd, offset, CELL_FS_SEEK_SET, newPos); // Move to the specified offset + if (ret) return ret; + ret = cellFsRead(CPU, fd, buf, buffer_size, nread); // Read the file + if (ret) return ret; + ret = cellFsLseek(fd, oldPos.value(), CELL_FS_SEEK_SET, newPos); // Return to the old position + if (ret) return ret; + + return CELL_OK; +} + +s32 cellFsSetDefaultContainer(u32 id, u32 total_limit) +{ + cellFs.Todo("cellFsSetDefaultContainer(id=%d, total_limit=%d)", id, total_limit); + + return CELL_OK; +} + +s32 cellFsSetIoBufferFromDefaultContainer(u32 fd, u32 buffer_size, u32 page_type) +{ + cellFs.Todo("cellFsSetIoBufferFromDefaultContainer(fd=%d, buffer_size=%d, page_type=%d)", fd, buffer_size, page_type); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + return CELL_OK; +} + +Module cellFs("cellFs", []() +{ + g_FsAioReadID = 0; + g_FsAioReadCur = 0; + aio_init = false; + + REG_FUNC(cellFs, cellFsOpen); + REG_FUNC(cellFs, cellFsSdataOpen); + REG_FUNC(cellFs, cellFsSdataOpenByFd); + REG_FUNC(cellFs, cellFsRead); + REG_FUNC(cellFs, cellFsWrite); + REG_FUNC(cellFs, cellFsClose); + REG_FUNC(cellFs, cellFsOpendir); + REG_FUNC(cellFs, cellFsReaddir); + REG_FUNC(cellFs, cellFsClosedir); + REG_FUNC(cellFs, cellFsStat); + REG_FUNC(cellFs, cellFsFstat); + REG_FUNC(cellFs, cellFsMkdir); + REG_FUNC(cellFs, cellFsRename); + REG_FUNC(cellFs, cellFsChmod); + REG_FUNC(cellFs, cellFsFsync); + REG_FUNC(cellFs, cellFsRmdir); + REG_FUNC(cellFs, cellFsUnlink); + REG_FUNC(cellFs, cellFsLseek); + REG_FUNC(cellFs, cellFsFtruncate); + REG_FUNC(cellFs, cellFsTruncate); + REG_FUNC(cellFs, cellFsFGetBlockSize); + REG_FUNC(cellFs, cellFsAioRead); + REG_FUNC(cellFs, cellFsAioWrite); + REG_FUNC(cellFs, cellFsAioInit); + REG_FUNC(cellFs, cellFsAioFinish); + REG_FUNC(cellFs, cellFsGetBlockSize); + REG_FUNC(cellFs, cellFsGetFreeSize); + REG_FUNC(cellFs, cellFsReadWithOffset); + REG_FUNC(cellFs, cellFsGetDirectoryEntries); + REG_FUNC(cellFs, cellFsStReadInit); + REG_FUNC(cellFs, cellFsStReadFinish); + REG_FUNC(cellFs, cellFsStReadGetRingBuf); + REG_FUNC(cellFs, cellFsStReadGetStatus); + REG_FUNC(cellFs, cellFsStReadGetRegid); + REG_FUNC(cellFs, cellFsStReadStart); + REG_FUNC(cellFs, cellFsStReadStop); + REG_FUNC(cellFs, cellFsStRead); + REG_FUNC(cellFs, cellFsStReadGetCurrentAddr); + REG_FUNC(cellFs, cellFsStReadPutCurrentAddr); + REG_FUNC(cellFs, cellFsStReadWait); + REG_FUNC(cellFs, cellFsStReadWaitCallback); + REG_FUNC(cellFs, cellFsSetDefaultContainer); + REG_FUNC(cellFs, cellFsSetIoBufferFromDefaultContainer); +}); diff --git a/rpcs3/Emu/SysCalls/Modules/cellFs.h b/rpcs3/Emu/SysCalls/Modules/cellFs.h new file mode 100644 index 0000000000..d45512d5ff --- /dev/null +++ b/rpcs3/Emu/SysCalls/Modules/cellFs.h @@ -0,0 +1,40 @@ +#pragma once + +// CellFsRingBuffer.copy +enum : s32 +{ + CELL_FS_ST_COPY = 0, + CELL_FS_ST_COPYLESS = 1, +}; + +struct CellFsRingBuffer +{ + be_t ringbuf_size; + be_t block_size; + be_t transfer_rate; + be_t copy; +}; + +// cellFsSt(Read|Write)GetStatus status +enum : u64 +{ + CELL_FS_ST_INITIALIZED = 0x0001, + CELL_FS_ST_NOT_INITIALIZED = 0x0002, + CELL_FS_ST_STOP = 0x0100, + CELL_FS_ST_PROGRESS = 0x0200, +}; + +enum : s32 +{ + CELL_FS_AIO_MAX_FS = 10, // cellFsAioInit limit + CELL_FS_AIO_MAX_REQUEST = 32, // cellFsAioRead request limit per mount point +}; + +struct CellFsAio +{ + be_t fd; + be_t offset; + vm::bptr buf; + be_t size; + be_t user_data; +}; diff --git a/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp index cbcb8f397f..28d570fbfe 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellGifDec.cpp @@ -6,7 +6,10 @@ #include "stblib/stb_image.h" #include "stblib/stb_image.c" // (TODO: Should we put this elsewhere?) -#include "Emu/SysCalls/lv2/cellFs.h" + +#include "Emu/FS/VFS.h" +#include "Emu/FS/vfsFileBase.h" + #include "cellGifDec.h" extern Module cellGifDec; @@ -39,19 +42,15 @@ int cellGifDecOpen(u32 mainHandle, vm::ptr subHandle, vm::ptr> fd; - int ret = cellFsOpen(src->fileName, 0, fd, vm::ptr::make(0), 0); - current_subHandle->fd = fd.value(); - if (ret != CELL_OK) return CELL_GIFDEC_ERROR_OPEN_FILE; - - // Get size of file - vm::var sb; // Alloc a CellFsStat struct - ret = cellFsFstat(current_subHandle->fd, sb); - if (ret != CELL_OK) return ret; - current_subHandle->fileSize = sb->st_size; // Get CellFsStat.st_size + { + // Get file descriptor and size + std::shared_ptr file(Emu.GetVFS().OpenFile(src->fileName.get_ptr(), vfsRead)); + if (!file) return CELL_GIFDEC_ERROR_OPEN_FILE; + current_subHandle->fd = Emu.GetIdManager().GetNewID(file, TYPE_FS_FILE); + current_subHandle->fileSize = file->GetSize(); break; } + } // From now, every u32 subHandle argument is a pointer to a CellGifDecSubHandle struct. *subHandle = Emu.GetIdManager().GetNewID(current_subHandle); @@ -74,7 +73,6 @@ int cellGifDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr //Write the header to buffer vm::var buffer; // Alloc buffer for GIF header - vm::var> pos, nread; switch(subHandle_data->src.srcSelect.data()) { @@ -83,10 +81,13 @@ int cellGifDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr break; case se32(CELL_GIFDEC_FILE): - cellFsLseek(fd, 0, CELL_SEEK_SET, pos); - cellFsRead(fd, vm::ptr::make(buffer.addr()), buffer.size(), nread); + { + auto file = Emu.GetIdManager().GetIDData(fd); + file->Seek(0); + file->Read(buffer.begin(), buffer.size()); break; } + } if (*buffer.To>(0) != 0x47494638 || (*buffer.To(4) != 0x6139 && *buffer.To(4) != 0x6137)) // Error: The first 6 bytes are not a valid GIF signature @@ -156,7 +157,6 @@ int cellGifDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::pt //Copy the GIF file to a buffer vm::var gif((u32)fileSize); - vm::var> pos, nread; switch(subHandle_data->src.srcSelect.data()) { @@ -165,10 +165,13 @@ int cellGifDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::pt break; case se32(CELL_GIFDEC_FILE): - cellFsLseek(fd, 0, CELL_SEEK_SET, pos); - cellFsRead(fd, vm::ptr::make(gif.addr()), gif.size(), nread); + { + auto file = Emu.GetIdManager().GetIDData(fd); + file->Seek(0); + file->Read(gif.ptr(), gif.size()); break; } + } //Decode GIF file. (TODO: Is there any faster alternative? Can we do it without external libraries?) int width, height, actual_components; @@ -265,7 +268,7 @@ int cellGifDecClose(u32 mainHandle, u32 subHandle) if(!Emu.GetIdManager().GetIDData(subHandle, subHandle_data)) return CELL_GIFDEC_ERROR_FATAL; - cellFsClose(subHandle_data->fd); + Emu.GetIdManager().RemoveID(subHandle_data->fd); Emu.GetIdManager().RemoveID(subHandle); return CELL_OK; diff --git a/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp index 322b763d9d..62ac42645f 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellJpgDec.cpp @@ -5,7 +5,10 @@ #include "Emu/SysCalls/Modules.h" #include "stblib/stb_image.h" -#include "Emu/SysCalls/lv2/cellFs.h" + +#include "Emu/FS/VFS.h" +#include "Emu/FS/vfsFileBase.h" + #include "cellJpgDec.h" extern Module cellJpgDec; @@ -45,19 +48,15 @@ int cellJpgDecOpen(u32 mainHandle, vm::ptr subHandle, vm::ptr> fd; - int ret = cellFsOpen(src->fileName, 0, fd, vm::ptr::make(0), 0); - current_subHandle->fd = fd.value(); - if (ret != CELL_OK) return CELL_JPGDEC_ERROR_OPEN_FILE; - - // Get size of file - vm::var sb; // Alloc a CellFsStat struct - ret = cellFsFstat(current_subHandle->fd, sb); - if (ret != CELL_OK) return ret; - current_subHandle->fileSize = sb->st_size; // Get CellFsStat.st_size + { + // Get file descriptor and size + std::shared_ptr file(Emu.GetVFS().OpenFile(src->fileName.get_ptr(), vfsRead)); + if (!file) return CELL_JPGDEC_ERROR_OPEN_FILE; + current_subHandle->fd = Emu.GetIdManager().GetNewID(file, TYPE_FS_FILE); + current_subHandle->fileSize = file->GetSize(); break; } + } // From now, every u32 subHandle argument is a pointer to a CellJpgDecSubHandle struct. *subHandle = Emu.GetIdManager().GetNewID(current_subHandle); @@ -74,7 +73,7 @@ int cellJpgDecClose(u32 mainHandle, u32 subHandle) if(!Emu.GetIdManager().GetIDData(subHandle, subHandle_data)) return CELL_JPGDEC_ERROR_FATAL; - cellFsClose(subHandle_data->fd); + Emu.GetIdManager().RemoveID(subHandle_data->fd); Emu.GetIdManager().RemoveID(subHandle); return CELL_OK; @@ -94,7 +93,6 @@ int cellJpgDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr //Write the header to buffer vm::var buffer((u32)fileSize); - vm::var> pos, nread; switch(subHandle_data->src.srcSelect.data()) { @@ -103,10 +101,13 @@ int cellJpgDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr break; case se32(CELL_JPGDEC_FILE): - cellFsLseek(fd, 0, CELL_SEEK_SET, pos); - cellFsRead(fd, vm::ptr::make(buffer.addr()), buffer.size(), nread); + { + auto file = Emu.GetIdManager().GetIDData(fd); + file->Seek(0); + file->Read(buffer.ptr(), buffer.size()); break; } + } if (*buffer.To(0) != 0xE0FFD8FF || // Error: Not a valid SOI header *buffer.To(6) != 0x4649464A) // Error: Not a valid JFIF string @@ -163,7 +164,6 @@ int cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::pt //Copy the JPG file to a buffer vm::var jpg((u32)fileSize); - vm::var> pos, nread; switch(subHandle_data->src.srcSelect.data()) { @@ -172,10 +172,13 @@ int cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr data, vm::pt break; case se32(CELL_JPGDEC_FILE): - cellFsLseek(fd, 0, CELL_SEEK_SET, pos); - cellFsRead(fd, vm::ptr::make(jpg.addr()), jpg.size(), nread); + { + auto file = Emu.GetIdManager().GetIDData(fd); + file->Seek(0); + file->Read(jpg.ptr(), jpg.size()); break; } + } //Decode JPG file. (TODO: Is there any faster alternative? Can we do it without external libraries?) int width, height, actual_components; diff --git a/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp index 9e10fdf8dc..6020324200 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellPngDec.cpp @@ -1,12 +1,15 @@ #include "stdafx.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" +#include "Emu/IdManager.h" #include "Emu/SysCalls/Modules.h" #include "stblib/stb_image.h" -#include "Emu/SysCalls/lv2/cellFs.h" + +#include "Emu/FS/VFS.h" +#include "Emu/FS/vfsFileBase.h" + #include "cellPngDec.h" -#include extern Module cellPngDec; @@ -76,19 +79,15 @@ s32 pngDecOpen( break; case se32(CELL_PNGDEC_FILE): - // Get file descriptor - vm::var> fd; - int ret = cellFsOpen(src->fileName, 0, fd, vm::ptr::make(0), 0); - stream->fd = fd.value(); - if (ret != CELL_OK) return CELL_PNGDEC_ERROR_OPEN_FILE; - - // Get size of file - vm::var sb; // Alloc a CellFsStat struct - ret = cellFsFstat(stream->fd, sb); - if (ret != CELL_OK) return ret; - stream->fileSize = sb->st_size; // Get CellFsStat.st_size + { + // Get file descriptor and size + std::shared_ptr file(Emu.GetVFS().OpenFile(src->fileName.get_ptr(), vfsRead)); + if (!file) return CELL_PNGDEC_ERROR_OPEN_FILE; + stream->fd = Emu.GetIdManager().GetNewID(file, TYPE_FS_FILE); + stream->fileSize = file->GetSize(); break; } + } if (cb) { @@ -111,7 +110,8 @@ s32 pngDecOpen( s32 pngDecClose(CellPngDecSubHandle stream) { - cellFsClose(stream->fd); + Emu.GetIdManager().RemoveID(stream->fd); + if (!Memory.Free(stream.addr())) { return CELL_PNGDEC_ERROR_FATAL; @@ -135,7 +135,6 @@ s32 pngReadHeader( //Write the header to buffer vm::var buffer; // Alloc buffer for PNG header auto buffer_32 = buffer.To>(); - vm::var> pos, nread; switch (stream->src.srcSelect.data()) { @@ -143,10 +142,13 @@ s32 pngReadHeader( memmove(buffer.begin(), stream->src.streamPtr.get_ptr(), buffer.size()); break; case se32(CELL_PNGDEC_FILE): - cellFsLseek(stream->fd, 0, CELL_SEEK_SET, pos); - cellFsRead(stream->fd, vm::ptr::make(buffer.addr()), buffer.size(), nread); + { + auto file = Emu.GetIdManager().GetIDData(stream->fd); + file->Seek(0); + file->Read(buffer, buffer.size()); break; } + } if (buffer_32[0].data() != se32(0x89504E47) || buffer_32[1].data() != se32(0x0D0A1A0A) || // Error: The first 8 bytes are not a valid PNG signature @@ -244,7 +246,6 @@ s32 pngDecodeData( //Copy the PNG file to a buffer vm::var png((u32)fileSize); - vm::var> pos, nread; switch (stream->src.srcSelect.data()) { @@ -253,10 +254,13 @@ s32 pngDecodeData( break; case se32(CELL_PNGDEC_FILE): - cellFsLseek(fd, 0, CELL_SEEK_SET, pos); - cellFsRead(fd, vm::ptr::make(png.addr()), png.size(), nread); + { + auto file = Emu.GetIdManager().GetIDData(stream->fd); + file->Seek(0); + file->Read(png.ptr(), png.size()); break; } + } //Decode PNG file. (TODO: Is there any faster alternative? Can we do it without external libraries?) int width, height, actual_components; diff --git a/rpcs3/Emu/SysCalls/Modules/cellResc.cpp b/rpcs3/Emu/SysCalls/Modules/cellResc.cpp index 0647516044..c280f9374f 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellResc.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellResc.cpp @@ -14,7 +14,7 @@ extern s32 cellVideoOutConfigure(u32 videoOut, vm::ptr handler); extern void cellGcmSetVBlankHandler(vm::ptr handler); -extern s32 cellGcmAddressToOffset(u32 address, vm::ptr> offset); +extern s32 cellGcmAddressToOffset(u32 address, vm::ptr offset); extern s32 cellGcmSetDisplayBuffer(u32 id, u32 offset, u32 pitch, u32 width, u32 height); extern s32 cellGcmSetPrepareFlip(vm::ptr ctx, u32 id); extern s32 cellGcmSetSecondVFrequency(u32 freq); diff --git a/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp b/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp index 7b78219c5d..720a9d1251 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSpurs.cpp @@ -2428,14 +2428,14 @@ s32 cellSpursCreateTask(vm::ptr taskset, vm::ptr taskId, return CELL_SPURS_TASK_ERROR_ALIGN; } - vm::var tmpTaskId; + vm::var> tmpTaskId; auto rc = spursCreateTask(taskset, tmpTaskId, vm::ptr::make(elf_addr), vm::ptr::make(context_addr), context_size, lsPattern, argument); if (rc != CELL_OK) { return rc; } - rc = spursTaskStart(taskset, tmpTaskId); + rc = spursTaskStart(taskset, tmpTaskId->value()); if (rc != CELL_OK) { return rc; diff --git a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp index 9274ccbdad..54ab1e2bb4 100644 --- a/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sysPrxForUser.cpp @@ -32,7 +32,7 @@ u32 g_tls_size; std::array, TLS_MAX> g_tls_owners; -waiter_map_t g_sys_spinlock_wm("sys_spinlock_wm"); // TODO +waiter_map_t g_sys_spinlock_wm("sys_spinlock_wm"); void sys_initialize_tls() { @@ -127,7 +127,7 @@ s32 sys_lwmutex_destroy(PPUThread& CPU, vm::ptr lwmutex) sysPrxForUser.Log("sys_lwmutex_destroy(lwmutex=*0x%x)", lwmutex); // check to prevent recursive locking in the next call - if (lwmutex->lock_var.read_relaxed().owner == CPU.GetId()) + if (lwmutex->owner.read_relaxed() == CPU.GetId()) { return CELL_EBUSY; } @@ -812,7 +812,7 @@ s32 sys_interrupt_thread_disestablish(PPUThread& CPU, u32 ih) { sysPrxForUser.Todo("sys_interrupt_thread_disestablish(ih=%d)", ih); - return _sys_interrupt_thread_disestablish(ih, vm::stackvar(CPU)); + return _sys_interrupt_thread_disestablish(ih, vm::stackvar>(CPU)); } int sys_process_is_stack(u32 p) diff --git a/rpcs3/Emu/SysCalls/SysCalls.cpp b/rpcs3/Emu/SysCalls/SysCalls.cpp index 1def24c74e..39f94edfd2 100644 --- a/rpcs3/Emu/SysCalls/SysCalls.cpp +++ b/rpcs3/Emu/SysCalls/SysCalls.cpp @@ -6,7 +6,6 @@ #include "Emu/System.h" #include "ModuleManager.h" -#include "lv2/cellFs.h" #include "lv2/sleep_queue.h" #include "lv2/sys_lwmutex.h" #include "lv2/sys_lwcond.h" @@ -29,6 +28,7 @@ #include "lv2/sys_trace.h" #include "lv2/sys_tty.h" #include "lv2/sys_vm.h" +#include "lv2/sys_fs.h" #include "Emu/SysCalls/Modules/cellGcmSys.h" @@ -696,28 +696,28 @@ const ppu_func_caller sc_table[1024] = null_func, null_func, null_func, null_func, null_func, //799 UNS null_func,//bind_func(sys_fs_test), //800 (0x320) - bind_func(cellFsOpen), //801 (0x321) - bind_func(cellFsRead), //802 (0x322) - bind_func(cellFsWrite), //803 (0x323) - bind_func(cellFsClose), //804 (0x324) - bind_func(cellFsOpendir), //805 (0x325) - bind_func(cellFsReaddir), //806 (0x326) - bind_func(cellFsClosedir), //807 (0x327) - bind_func(cellFsStat), //808 (0x328) - bind_func(cellFsFstat), //809 (0x329) + bind_func(sys_fs_open), //801 (0x321) + bind_func(sys_fs_read), //802 (0x322) + bind_func(sys_fs_write), //803 (0x323) + bind_func(sys_fs_close), //804 (0x324) + bind_func(sys_fs_opendir), //805 (0x325) + bind_func(sys_fs_readdir), //806 (0x326) + bind_func(sys_fs_closedir), //807 (0x327) + bind_func(sys_fs_stat), //808 (0x328) + bind_func(sys_fs_fstat), //809 (0x329) null_func,//bind_func(sys_fs_link), //810 (0x32A) - bind_func(cellFsMkdir), //811 (0x32B) - bind_func(cellFsRename), //812 (0x32C) - bind_func(cellFsRmdir), //813 (0x32D) - bind_func(cellFsUnlink), //814 (0x32E) - null_func,//bind_func(cellFsUtime), //815 (0x32F) + bind_func(sys_fs_mkdir), //811 (0x32B) + bind_func(sys_fs_rename), //812 (0x32C) + bind_func(sys_fs_rmdir), //813 (0x32D) + bind_func(sys_fs_unlink), //814 (0x32E) + null_func,//bind_func(sys_fs_utime), //815 (0x32F) null_func,//bind_func(sys_fs_access), //816 (0x330) null_func,//bind_func(sys_fs_fcntl), //817 (0x331) - bind_func(cellFsLseek), //818 (0x332) + bind_func(sys_fs_lseek), //818 (0x332) null_func,//bind_func(sys_fs_fdatasync), //819 (0x333) - null_func,//bind_func(cellFsFsync), //820 (0x334) - bind_func(cellFsFGetBlockSize), //821 (0x335) - bind_func(cellFsGetBlockSize), //822 (0x336) + null_func,//bind_func(sys_fs_fsync), //820 (0x334) + bind_func(sys_fs_fget_block_size), //821 (0x335) + bind_func(sys_fs_get_block_size), //822 (0x336) null_func,//bind_func(sys_fs_acl_read), //823 (0x337) null_func,//bind_func(sys_fs_acl_write), //824 (0x338) null_func,//bind_func(sys_fs_lsn_get_cda_size), //825 (0x339) @@ -726,10 +726,10 @@ const ppu_func_caller sc_table[1024] = null_func,//bind_func(sys_fs_lsn_unlock), //828 (0x33C) null_func,//bind_func(sys_fs_lsn_read), //829 (0x33D) null_func,//bind_func(sys_fs_lsn_write), //830 (0x33E) - bind_func(cellFsTruncate), //831 (0x33F) - bind_func(cellFsFtruncate), //832 (0x340) + bind_func(sys_fs_truncate), //831 (0x33F) + bind_func(sys_fs_ftruncate), //832 (0x340) null_func,//bind_func(sys_fs_symbolic_link), //833 (0x341) - null_func,//bind_func(cellFsChmod), //834 (0x342) + bind_func(sys_fs_chmod), //834 (0x342) null_func,//bind_func(sys_fs_chown), //835 (0x343) null_func,//bind_func(sys_fs_newfs), //836 (0x344) null_func,//bind_func(sys_fs_mount), //837 (0x345) diff --git a/rpcs3/Emu/SysCalls/lv2/cellFs.cpp b/rpcs3/Emu/SysCalls/lv2/cellFs.cpp deleted file mode 100644 index 8a332d3674..0000000000 --- a/rpcs3/Emu/SysCalls/lv2/cellFs.cpp +++ /dev/null @@ -1,1091 +0,0 @@ -#include "stdafx.h" -#include "Emu/Memory/Memory.h" -#include "Emu/System.h" -#include "Emu/IdManager.h" -#include "Emu/SysCalls/Modules.h" -#include "Emu/SysCalls/Callback.h" -#include "Emu/SysCalls/CB_FUNC.h" - -#ifdef _WIN32 - #include - #undef CreateFile -#else - #include - #include -#endif - -#include "Emu/FS/VFS.h" -#include "Emu/FS/vfsFile.h" -#include "Emu/FS/vfsDir.h" -#include "cellFs.h" - -extern Module sys_fs; - -struct FsRingBufferConfig -{ - CellFsRingBuffer m_ring_buffer; // Currently unused after assignment - u32 m_buffer; - u64 m_fs_status; - u64 m_regid; - u32 m_alloc_mem_size; - u32 m_current_addr; - - FsRingBufferConfig() - : m_fs_status(CELL_FS_ST_NOT_INITIALIZED) - , m_regid(0) - , m_alloc_mem_size(0) - , m_current_addr(0) - , m_ring_buffer() { } - -} fs_config; - - -s32 cellFsOpen(vm::ptr path, s32 flags, vm::ptr> fd, vm::ptr arg, u64 size) -{ - sys_fs.Log("cellFsOpen(path=*0x%x, flags=0x%x, fd=*0x%x, arg=*0x%x, size=0x%llx)", path, flags, fd, arg, size); - sys_fs.Log("*** path = '%s'", path.get_ptr()); - - const std::string _path = path.get_ptr(); - - s32 _oflags = flags; - if (flags & CELL_O_CREAT) - { - _oflags &= ~CELL_O_CREAT; - Emu.GetVFS().CreateFile(_path); - } - - vfsOpenMode o_mode; - - switch (flags & CELL_O_ACCMODE) - { - case CELL_O_RDONLY: - _oflags &= ~CELL_O_RDONLY; - o_mode = vfsRead; - break; - - case CELL_O_WRONLY: - _oflags &= ~CELL_O_WRONLY; - - if(flags & CELL_O_APPEND) - { - _oflags &= ~CELL_O_APPEND; - o_mode = vfsWriteAppend; - } - else if(flags & CELL_O_EXCL) - { - _oflags &= ~CELL_O_EXCL; - o_mode = vfsWriteExcl; - } - else //if (flags & CELL_O_TRUNC) - { - _oflags &= ~CELL_O_TRUNC; - o_mode = vfsWrite; - } - break; - - case CELL_O_RDWR: - _oflags &= ~CELL_O_RDWR; - if (flags & CELL_O_TRUNC) - { - _oflags &= ~CELL_O_TRUNC; - //truncate file before opening it as read/write - auto filePtr = Emu.GetVFS().OpenFile(_path, vfsWrite); - delete filePtr; - } - o_mode = vfsReadWrite; - break; - } - - if (_oflags != 0) - { - sys_fs.Error("cellFsOpen(): '%s' has unknown flags! flags: 0x%08x", path.get_ptr(), flags); - return CELL_EINVAL; - } - - if (!Emu.GetVFS().ExistsFile(_path)) - { - sys_fs.Error("cellFsOpen(): '%s' not found! flags: 0x%08x", path.get_ptr(), flags); - return CELL_ENOENT; - } - - std::shared_ptr stream((vfsStream*)Emu.GetVFS().OpenFile(_path, o_mode)); - - if (!stream || !stream->IsOpened()) - { - sys_fs.Error("cellFsOpen(): '%s' not found! flags: 0x%08x", path.get_ptr(), flags); - return CELL_ENOENT; - } - - u32 id = Emu.GetIdManager().GetNewID(stream, TYPE_FS_FILE); - *fd = id; - sys_fs.Notice("cellFsOpen(): '%s' opened, id -> 0x%x", path.get_ptr(), id); - - return CELL_OK; -} - -s32 cellFsRead(u32 fd, vm::ptr buf, u64 nbytes, vm::ptr> nread) -{ - sys_fs.Log("cellFsRead(fd=0x%x, buf=0x%x, nbytes=0x%llx, nread=0x%x)", fd, buf, nbytes, nread); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - // TODO: checks - - const u64 res = nbytes ? file->Read(buf.get_ptr(), nbytes) : 0; - - if (nread) *nread = res; - - return CELL_OK; -} - -s32 cellFsWrite(u32 fd, vm::ptr buf, u64 nbytes, vm::ptr nwrite) -{ - sys_fs.Log("cellFsWrite(fd=0x%x, buf=*0x%x, nbytes=0x%llx, nwrite=*0x%x)", fd, buf, nbytes, nwrite); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) return CELL_ESRCH; - - // TODO: checks - - const u64 res = nbytes ? file->Write(buf.get_ptr(), nbytes) : 0; - - if (nwrite) *nwrite = res; - - return CELL_OK; -} - -s32 cellFsClose(u32 fd) -{ - sys_fs.Warning("cellFsClose(fd=0x%x)", fd); - - if (!Emu.GetIdManager().RemoveID(fd)) - return CELL_ESRCH; - - return CELL_OK; -} - -s32 cellFsOpendir(vm::ptr path, vm::ptr fd) -{ - sys_fs.Warning("cellFsOpendir(path=*0x%x, fd=*0x%x)", path, fd); - sys_fs.Warning("*** path = '%s'", path.get_ptr()); - - std::shared_ptr dir(Emu.GetVFS().OpenDir(path.get_ptr())); - if (!dir || !dir->IsOpened()) - { - return CELL_ENOENT; - } - - *fd = Emu.GetIdManager().GetNewID(dir, TYPE_FS_DIR); - return CELL_OK; -} - -s32 cellFsReaddir(u32 fd, vm::ptr dir, vm::ptr nread) -{ - sys_fs.Warning("cellFsReaddir(fd=0x%x, dir=*0x%x, nread=*0x%x)", fd, dir, nread); - - std::shared_ptr directory; - if (!Emu.GetIdManager().GetIDData(fd, directory)) - return CELL_ESRCH; - - const DirEntryInfo* info = directory->Read(); - if (info) - { - dir->d_type = (info->flags & DirEntry_TypeFile) ? CELL_FS_TYPE_REGULAR : CELL_FS_TYPE_DIRECTORY; - dir->d_namlen = u8(std::min((u32)info->name.length(), (u32)CELL_MAX_FS_FILE_NAME_LENGTH)); - strcpy_trunc(dir->d_name, info->name); - *nread = sizeof(CellFsDirent); - } - else - { - *nread = 0; - } - - return CELL_OK; -} - -s32 cellFsClosedir(u32 fd) -{ - sys_fs.Warning("cellFsClosedir(fd=0x%x)", fd); - - if (!Emu.GetIdManager().RemoveID(fd)) - return CELL_ESRCH; - - return CELL_OK; -} - -s32 cellFsStat(vm::ptr path, vm::ptr sb) -{ - sys_fs.Warning("cellFsStat(path=*0x%x, sb=*0x%x)", path, sb); - sys_fs.Warning("*** path = '%s'", path.get_ptr()); - - const std::string _path = path.get_ptr(); - - u32 mode = 0; - s32 uid = 0; - s32 gid = 0; - u64 atime = 0; - u64 mtime = 0; - u64 ctime = 0; - u64 size = 0; - - std::string real_path; - - Emu.GetVFS().GetDevice(_path, real_path); - - int stat_result; -#ifdef _WIN32 - struct _stat64 buf; - stat_result = _stat64(real_path.c_str(), &buf); -#else - struct stat buf; - stat_result = stat(real_path.c_str(), &buf); -#endif - if (stat_result) - { - sys_fs.Error("cellFsStat(): stat('%s') failed -> 0x%x", real_path.c_str(), stat_result); - } - else - { - mode = buf.st_mode; - uid = buf.st_uid; - gid = buf.st_gid; - atime = buf.st_atime; - mtime = buf.st_mtime; - ctime = buf.st_ctime; - size = buf.st_size; - } - - sb->st_mode = - CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR | - CELL_FS_S_IRGRP | CELL_FS_S_IWGRP | CELL_FS_S_IXGRP | - CELL_FS_S_IROTH | CELL_FS_S_IWOTH | CELL_FS_S_IXOTH; - - if (sb->st_mode == mode) - sys_fs.Error("cellFsStat(): mode is the same (0x%x)", mode); - - sb->st_uid = uid; - sb->st_gid = gid; - sb->st_atime_ = atime; - sb->st_mtime_ = mtime; - sb->st_ctime_ = ctime; - sb->st_blksize = 4096; - - { - vfsDir dir(_path); - if(dir.IsOpened()) - { - sb->st_mode |= CELL_FS_S_IFDIR; - return CELL_OK; - } - } - - { - vfsFile f(_path); - if(f.IsOpened()) - { - sb->st_mode |= CELL_FS_S_IFREG; - sb->st_size = f.GetSize(); - return CELL_OK; - } - } - - if (sb->st_size == size && size != 0) - sys_fs.Error("cellFsStat(): size is the same (0x%x)", size); - - sys_fs.Warning("cellFsStat(): '%s' not found", path.get_ptr()); - return CELL_ENOENT; -} - -s32 cellFsFstat(u32 fd, vm::ptr sb) -{ - sys_fs.Warning("cellFsFstat(fd=0x%x, sb=*0x%x)", fd, sb); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - sb->st_mode = - CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR | - CELL_FS_S_IRGRP | CELL_FS_S_IWGRP | CELL_FS_S_IXGRP | - CELL_FS_S_IROTH | CELL_FS_S_IWOTH | CELL_FS_S_IXOTH; - - sb->st_mode |= CELL_FS_S_IFREG; //TODO: dir CELL_FS_S_IFDIR - sb->st_uid = 0; - sb->st_gid = 0; - sb->st_atime_ = 0; //TODO - sb->st_mtime_ = 0; //TODO - sb->st_ctime_ = 0; //TODO - sb->st_size = file->GetSize(); - sb->st_blksize = 4096; - - return CELL_OK; -} - -s32 cellFsMkdir(vm::ptr path, u32 mode) -{ - sys_fs.Warning("cellFsMkdir(path=*0x%x, mode=0x%x)", path, mode); - sys_fs.Warning("*** path = '%s'", path.get_ptr()); - - const std::string _path = path.get_ptr(); - - if (vfsDir().IsExists(_path)) - return CELL_EEXIST; - - if (!Emu.GetVFS().CreateDir(_path)) - return CELL_EBUSY; - - sys_fs.Notice("cellFsMkdir(): directory '%s' created", path.get_ptr()); - return CELL_OK; -} - -s32 cellFsRename(vm::ptr from, vm::ptr to) -{ - sys_fs.Warning("cellFsRename(from=*0x%x, to=*0x%x)", from, to); - sys_fs.Warning("*** from = '%s'", from.get_ptr()); - sys_fs.Warning("*** to = '%s'", to.get_ptr()); - - std::string _from = from.get_ptr(); - std::string _to = to.get_ptr(); - - { - vfsDir dir; - if(dir.IsExists(_from)) - { - if(!dir.Rename(_from, _to)) - return CELL_EBUSY; - - sys_fs.Notice("cellFsRename(): directory '%s' renamed to '%s'", from.get_ptr(), to.get_ptr()); - return CELL_OK; - } - } - - { - vfsFile f; - - if(f.Exists(_from)) - { - if(!f.Rename(_from, _to)) - return CELL_EBUSY; - - sys_fs.Notice("cellFsRename(): file '%s' renamed to '%s'", from.get_ptr(), to.get_ptr()); - return CELL_OK; - } - } - - return CELL_ENOENT; -} -s32 cellFsChmod(vm::ptr path, u32 mode) -{ - sys_fs.Todo("cellFsChmod(path=*0x%x, mode=0x%x)", path, mode); - sys_fs.Todo("*** path = '%s'", path.get_ptr()); - - // TODO: - - return CELL_OK; -} - -s32 cellFsFsync(u32 fd) -{ - sys_fs.Todo("cellFsFsync(fd=0x%x)", fd); - - // TODO: - - return CELL_OK; -} - -s32 cellFsRmdir(vm::ptr path) -{ - sys_fs.Warning("cellFsRmdir(path=*0x%x)", path); - sys_fs.Warning("*** path = '%s'", path.get_ptr()); - - std::string _path = path.get_ptr(); - - vfsDir d; - if (!d.IsExists(_path)) - return CELL_ENOENT; - - if (!d.Remove(_path)) - return CELL_EBUSY; - - sys_fs.Notice("cellFsRmdir(): directory '%s' removed", path.get_ptr()); - return CELL_OK; -} - -s32 cellFsUnlink(vm::ptr path) -{ - sys_fs.Warning("cellFsUnlink(path=*0x%x)", path); - sys_fs.Warning("*** path = '%s'", path.get_ptr()); - - std::string _path = path.get_ptr(); - - if (vfsDir().IsExists(_path)) - return CELL_EISDIR; - - if (!Emu.GetVFS().ExistsFile(_path)) - return CELL_ENOENT; - - if (!Emu.GetVFS().RemoveFile(_path)) - return CELL_EACCES; - - sys_fs.Notice("cellFsUnlink(): file '%s' removed", path.get_ptr()); - return CELL_OK; -} - -s32 cellFsLseek(u32 fd, s64 offset, u32 whence, vm::ptr> pos) -{ - sys_fs.Log("cellFsLseek(fd=0x%x, offset=0x%llx, whence=0x%x, pos=*0x%x)", fd, offset, whence, pos); - - vfsSeekMode seek_mode; - switch(whence) - { - case CELL_SEEK_SET: seek_mode = vfsSeekSet; break; - case CELL_SEEK_CUR: seek_mode = vfsSeekCur; break; - case CELL_SEEK_END: seek_mode = vfsSeekEnd; break; - default: - sys_fs.Error("cellFsLseek(fd=0x%x): Unknown seek whence! (0x%x)", fd, whence); - return CELL_EINVAL; - } - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - *pos = file->Seek(offset, seek_mode); - return CELL_OK; -} - -s32 cellFsFtruncate(u32 fd, u64 size) -{ - sys_fs.Warning("cellFsFtruncate(fd=0x%x, size=0x%llx)", fd, size); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - u64 initialSize = file->GetSize(); - - if (initialSize < size) - { - u64 last_pos = file->Tell(); - file->Seek(0, vfsSeekEnd); - static const char nullbyte = 0; - file->Seek(size-initialSize-1, vfsSeekCur); - file->Write(&nullbyte, sizeof(char)); - file->Seek(last_pos, vfsSeekSet); - } - - if (initialSize > size) - { - // (TODO) - } - - return CELL_OK; -} - -s32 cellFsTruncate(vm::ptr path, u64 size) -{ - sys_fs.Warning("cellFsTruncate(path=*0x%x, size=0x%llx)", path, size); - sys_fs.Warning("*** path = '%s'", path.get_ptr()); - - vfsFile f(path.get_ptr(), vfsReadWrite); - if (!f.IsOpened()) - { - sys_fs.Warning("cellFsTruncate(): '%s' not found", path.get_ptr()); - return CELL_ENOENT; - } - u64 initialSize = f.GetSize(); - - if (initialSize < size) - { - u64 last_pos = f.Tell(); - f.Seek(0, vfsSeekEnd); - static const char nullbyte = 0; - f.Seek(size-initialSize-1, vfsSeekCur); - f.Write(&nullbyte, sizeof(char)); - f.Seek(last_pos, vfsSeekSet); - } - - if (initialSize > size) - { - // (TODO) - } - - return CELL_OK; -} - -s32 cellFsFGetBlockSize(u32 fd, vm::ptr sector_size, vm::ptr block_size) -{ - sys_fs.Warning("cellFsFGetBlockSize(fd=0x%x, sector_size=*0x%x, block_size=*0x%x)", fd, sector_size, block_size); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - *sector_size = 4096; // ? - *block_size = 4096; // ? - - return CELL_OK; -} - -s32 cellFsGetBlockSize(vm::ptr path, vm::ptr sector_size, vm::ptr block_size) -{ - sys_fs.Warning("cellFsGetBlockSize(path=*0x%x, sector_size=*0x%x, block_size=*0x%x)", path, sector_size, block_size); - sys_fs.Warning("*** path = '%s'", path.get_ptr()); - - *sector_size = 4096; // ? - *block_size = 4096; // ? - - return CELL_OK; -} - -s32 cellFsGetFreeSize(vm::ptr path, vm::ptr block_size, vm::ptr block_count) -{ - sys_fs.Warning("cellFsGetFreeSize(path=*0x%x, block_size=*0x%x, block_count=*0x%x)", path, block_size, block_count); - sys_fs.Warning("*** path = '%s'", path.get_ptr()); - - // TODO: Get real values. Currently, it always returns 40 GB of free space divided in 4 KB blocks - *block_size = 4096; // ? - *block_count = 10 * 1024 * 1024; // ? - - return CELL_OK; -} - -s32 cellFsGetDirectoryEntries(u32 fd, vm::ptr entries, u32 entries_size, vm::ptr data_count) -{ - sys_fs.Warning("cellFsGetDirectoryEntries(fd=0x%x, entries=*0x%x, entries_size=0x%x, data_count=*0x%x)", fd, entries, entries_size, data_count); - - std::shared_ptr directory; - if (!Emu.GetIdManager().GetIDData(fd, directory)) - return CELL_ESRCH; - - const DirEntryInfo* info = directory->Read(); - if (info) - { - entries->attribute.st_mode = - CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR | - CELL_FS_S_IRGRP | CELL_FS_S_IWGRP | CELL_FS_S_IXGRP | - CELL_FS_S_IROTH | CELL_FS_S_IWOTH | CELL_FS_S_IXOTH; - - entries->attribute.st_uid = 0; - entries->attribute.st_gid = 0; - entries->attribute.st_atime_ = 0; //TODO - entries->attribute.st_mtime_ = 0; //TODO - entries->attribute.st_ctime_ = 0; //TODO - entries->attribute.st_blksize = 4096; - - entries->entry_name.d_type = (info->flags & DirEntry_TypeFile) ? CELL_FS_TYPE_REGULAR : CELL_FS_TYPE_DIRECTORY; - entries->entry_name.d_namlen = u8(std::min((u32)info->name.length(), (u32)CELL_MAX_FS_FILE_NAME_LENGTH)); - strcpy_trunc(entries->entry_name.d_name, info->name); - *data_count = 1; - } - else - { - *data_count = 0; - } - - return CELL_OK; -} - -s32 cellFsStReadInit(u32 fd, vm::ptr ringbuf) -{ - sys_fs.Warning("cellFsStReadInit(fd=0x%x, ringbuf=*0x%x)", fd, ringbuf); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - fs_config.m_ring_buffer = *ringbuf; - - // If the size is less than 1MB - if (ringbuf->ringbuf_size < 0x40000000) - fs_config.m_alloc_mem_size = (((u32)ringbuf->ringbuf_size + 64 * 1024 - 1) / (64 * 1024)) * (64 * 1024); - else - fs_config.m_alloc_mem_size = (((u32)ringbuf->ringbuf_size + 1024 * 1024 - 1) / (1024 * 1024)) * (1024 * 1024); - - // alloc memory - fs_config.m_buffer = (u32)Memory.Alloc(fs_config.m_alloc_mem_size, 1024); - memset(vm::get_ptr(fs_config.m_buffer), 0, fs_config.m_alloc_mem_size); - - fs_config.m_fs_status = CELL_FS_ST_INITIALIZED; - - return CELL_OK; -} - -s32 cellFsStReadFinish(u32 fd) -{ - sys_fs.Warning("cellFsStReadFinish(fd=0x%x)", fd); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - Memory.Free(fs_config.m_buffer); - fs_config.m_fs_status = CELL_FS_ST_NOT_INITIALIZED; - - return CELL_OK; -} - -s32 cellFsStReadGetRingBuf(u32 fd, vm::ptr ringbuf) -{ - sys_fs.Warning("cellFsStReadGetRingBuf(fd=0x%x, ringbuf=*0x%x)", fd, ringbuf); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - *ringbuf = fs_config.m_ring_buffer; - - sys_fs.Warning("*** fs stream config: block_size=0x%llx, copy=0x%x, ringbuf_size=0x%llx, transfer_rate=0x%llx", - ringbuf->block_size, ringbuf->copy, ringbuf->ringbuf_size, ringbuf->transfer_rate); - return CELL_OK; -} - -s32 cellFsStReadGetStatus(u32 fd, vm::ptr status) -{ - sys_fs.Warning("cellFsStReadGetRingBuf(fd=0x%x, status=*0x%x)", fd, status); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - *status = fs_config.m_fs_status; - - return CELL_OK; -} - -s32 cellFsStReadGetRegid(u32 fd, vm::ptr regid) -{ - sys_fs.Warning("cellFsStReadGetRingBuf(fd=0x%x, regid=*0x%x)", fd, regid); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - *regid = fs_config.m_regid; - - return CELL_OK; -} - -s32 cellFsStReadStart(u32 fd, u64 offset, u64 size) -{ - sys_fs.Todo("cellFsStReadStart(fd=0x%x, offset=0x%llx, size=0x%llx)", fd, offset, size); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - fs_config.m_current_addr = fs_config.m_buffer + (u32)offset; - fs_config.m_fs_status = CELL_FS_ST_PROGRESS; - - return CELL_OK; -} - -s32 cellFsStReadStop(u32 fd) -{ - sys_fs.Warning("cellFsStReadStop(fd=0x%x)", fd); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - fs_config.m_fs_status = CELL_FS_ST_STOP; - - return CELL_OK; -} - -s32 cellFsStRead(u32 fd, vm::ptr buf, u64 size, vm::ptr rsize) -{ - sys_fs.Warning("cellFsStRead(fd=0x%x, buf=*0x%x, size=0x%llx, rsize=*0x%x)", fd, buf, size, rsize); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - // TODO: use ringbuffer (fs_config) - fs_config.m_regid += size; - - if (file->Eof()) - return CELL_FS_ERANGE; - - *rsize = file->Read(buf.get_ptr(), size); - - return CELL_OK; -} - -s32 cellFsStReadGetCurrentAddr(u32 fd, vm::ptr> addr, vm::ptr size) -{ - sys_fs.Todo("cellFsStReadGetCurrentAddr(fd=0x%x, addr=*0x%x, size=*0x%x)", fd, addr, size); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - return CELL_OK; -} - -s32 cellFsStReadPutCurrentAddr(u32 fd, vm::ptr addr, u64 size) -{ - sys_fs.Todo("cellFsStReadPutCurrentAddr(fd=0x%x, addr=*0x%x, size=0x%llx)", fd, addr, size); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - return CELL_OK; -} - -s32 cellFsStReadWait(u32 fd, u64 size) -{ - sys_fs.Todo("cellFsStReadWait(fd=0x%x, size=0x%llx)", fd, size); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - return CELL_OK; -} - -s32 cellFsStReadWaitCallback(u32 fd, u64 size, vm::ptr func) -{ - sys_fs.Todo("cellFsStReadWaitCallback(fd=0x%x, size=0x%llx, func=*0x%x)", fd, size, func); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - return CELL_OK; -} - -bool sdata_check(u32 version, u32 flags, u64 filesizeInput, u64 filesizeTmp) -{ - if (version > 4 || flags & 0x7EFFFFC0){ - printf("ERROR: unknown version"); - return false; - } - - if ((version == 1 && (flags & 0x7FFFFFFE)) || - (version == 2 && (flags & 0x7EFFFFC0))){ - printf("ERROR: unknown or unsupported type"); - return false; - } - - if (filesizeTmp > filesizeInput){ - printf("ERROR: input file size is too short."); - return false; - } - - if (!(flags & 0x80000000)){ - printf("ERROR: cannot extract finalized edata."); - return false; - } - - return true; -} - -int sdata_unpack(const std::string& packed_file, const std::string& unpacked_file) -{ - std::shared_ptr packed_stream(Emu.GetVFS().OpenFile(packed_file, vfsRead)); - std::shared_ptr unpacked_stream(Emu.GetVFS().OpenFile(unpacked_file, vfsWrite)); - - if (!packed_stream || !packed_stream->IsOpened()) - { - sys_fs.Error("'%s' not found! flags: 0x%02x", packed_file.c_str(), vfsRead); - return CELL_ENOENT; - } - - if (!unpacked_stream || !unpacked_stream->IsOpened()) - { - sys_fs.Error("'%s' couldn't be created! flags: 0x%02x", unpacked_file.c_str(), vfsWrite); - return CELL_ENOENT; - } - - char buffer[10200]; - packed_stream->Read(buffer, 256); - u32 format = re32(*(u32*)&buffer[0]); - if (format != 0x4E504400) // "NPD\x00" - { - sys_fs.Error("Illegal format. Expected 0x4E504400, but got 0x%08x", format); - return CELL_EFSSPECIFIC; - } - - u32 version = re32(*(u32*)&buffer[0x04]); - u32 flags = re32(*(u32*)&buffer[0x80]); - u32 blockSize = re32(*(u32*)&buffer[0x84]); - u64 filesizeOutput = re64(*(u64*)&buffer[0x88]); - u64 filesizeInput = packed_stream->GetSize(); - u32 blockCount = (u32)((filesizeOutput + blockSize - 1) / blockSize); - - // SDATA file is compressed - if (flags & 0x1) - { - sys_fs.Warning("cellFsSdataOpen: Compressed SDATA files are not supported yet."); - return CELL_EFSSPECIFIC; - } - - // SDATA file is NOT compressed - else - { - u32 t1 = (flags & 0x20) ? 0x20 : 0x10; - u32 startOffset = (blockCount * t1) + 0x100; - u64 filesizeTmp = (filesizeOutput + 0xF) & 0xFFFFFFF0 + startOffset; - - if (!sdata_check(version, flags, filesizeInput, filesizeTmp)) - { - sys_fs.Error("cellFsSdataOpen: Wrong header information."); - return CELL_EFSSPECIFIC; - } - - if (flags & 0x20) - packed_stream->Seek(0x100); - else - packed_stream->Seek(startOffset); - - for (u32 i = 0; i < blockCount; i++) - { - if (flags & 0x20) - packed_stream->Seek(packed_stream->Tell() + t1); - - if (!(blockCount - i - 1)) - blockSize = (u32)(filesizeOutput - i * blockSize); - - packed_stream->Read(buffer + 256, blockSize); - unpacked_stream->Write(buffer + 256, blockSize); - } - } - - return CELL_OK; -} - -s32 cellFsSdataOpen(vm::ptr path, s32 flags, vm::ptr> fd, vm::ptr arg, u64 size) -{ - sys_fs.Warning("cellFsSdataOpen(path=*0x%x, flags=0x%x, fd=*0x%x, arg=*0x%x, size=0x%llx) -> cellFsOpen()", path, flags, fd, arg, size); - sys_fs.Warning("*** path = '%s'", path.get_ptr()); - - /*if (flags != CELL_O_RDONLY) - return CELL_EINVAL; - - std::string suffix = path.substr(path.length() - 5, 5); - if (suffix != ".sdat" && suffix != ".SDAT") - return CELL_ENOTSDATA; - - std::string::size_type last_slash = path.rfind('/'); //TODO: use a filesystem library to solve this more robustly - last_slash = last_slash == std::string::npos ? 0 : last_slash+1; - std::string unpacked_path = "/dev_hdd1/"+path.substr(last_slash,path.length()-last_slash)+".unpacked"; - int ret = sdata_unpack(path, unpacked_path); - if (ret) return ret; - - fd = Emu.GetIdManager().GetNewID(Emu.GetVFS().OpenFile(unpacked_path, vfsRead), TYPE_FS_FILE); - - return CELL_OK;*/ - - return cellFsOpen(path, flags, fd, arg, size); -} - -s32 cellFsSdataOpenByFd(u32 mself_fd, s32 flags, vm::ptr sdata_fd, u64 offset, vm::ptr arg, u64 size) -{ - sys_fs.Todo("cellFsSdataOpenByFd(mself_fd=0x%x, flags=0x%x, sdata_fd=*0x%x, offset=0x%llx, arg=*0x%x, size=0x%llx)", mself_fd, flags, sdata_fd, offset, arg, size); - - // TODO: - - return CELL_OK; -} - -std::atomic g_FsAioReadID(0); -std::atomic g_FsAioReadCur(0); -bool aio_init = false; - -void fsAioRead(u32 fd, vm::ptr aio, int xid, vm::ptr xaio, int error, int xid, u64 size)> func) -{ - while (g_FsAioReadCur != xid) - { - std::this_thread::sleep_for(std::chrono::milliseconds(1)); // hack - if (Emu.IsStopped()) - { - sys_fs.Warning("fsAioRead() aborted"); - return; - } - } - - u32 error = CELL_OK; - u64 res = 0; - { - std::shared_ptr orig_file; - if (!Emu.GetIdManager().GetIDData(fd, orig_file)) - { - sys_fs.Error("Wrong fd (%s)", fd); - Emu.Pause(); - return; - } - - u64 nbytes = aio->size; - - vfsStream& file = *orig_file; - const u64 old_pos = file.Tell(); - file.Seek((u64)aio->offset); - - if (nbytes != (u32)nbytes) - { - error = CELL_ENOMEM; - } - else - { - res = nbytes ? file.Read(aio->buf.get_ptr(), nbytes) : 0; - } - - file.Seek(old_pos); - - sys_fs.Log("*** fsAioRead(fd=%d, offset=0x%llx, buf=0x%x, size=0x%llx, error=0x%x, res=0x%llx, xid=0x%x)", - fd, aio->offset, aio->buf, aio->size, error, res, xid); - } - - if (func) - { - Emu.GetCallbackManager().Async([func, aio, error, xid, res](PPUThread& CPU) - { - func(CPU, aio, error, xid, res); - }); - } - - g_FsAioReadCur++; -} - -s32 cellFsAioRead(vm::ptr aio, vm::ptr id, vm::ptr xaio, s32 error, s32 xid, u64 size)> func) -{ - sys_fs.Warning("cellFsAioRead(aio=*0x%x, id=*0x%x, func=*0x%x)", aio, id, func); - - if (!aio_init) - { - return CELL_ENXIO; - } - - std::shared_ptr orig_file; - u32 fd = aio->fd; - - if (!Emu.GetIdManager().GetIDData(fd, orig_file)) - { - return CELL_EBADF; - } - - //get a unique id for the callback (may be used by cellFsAioCancel) - const s32 xid = g_FsAioReadID++; - *id = xid; - - thread_t t("CellFsAio Reading Thread", std::bind(fsAioRead, fd, aio, xid, func)); - return CELL_OK; -} - -s32 cellFsAioWrite(vm::ptr aio, vm::ptr id, vm::ptr xaio, s32 error, s32 xid, u64 size)> func) -{ - sys_fs.Todo("cellFsAioWrite(aio=*0x%x, id=*0x%x, func=*0x%x)", aio, id, func); - - // TODO: - - return CELL_OK; -} - -s32 cellFsAioInit(vm::ptr mount_point) -{ - sys_fs.Warning("cellFsAioInit(mount_point=*0x%x)", mount_point); - sys_fs.Warning("*** mount_point = '%s'", mount_point.get_ptr()); - - aio_init = true; - return CELL_OK; -} - -s32 cellFsAioFinish(vm::ptr mount_point) -{ - sys_fs.Warning("cellFsAioFinish(mount_point=*0x%x)", mount_point); - sys_fs.Warning("*** mount_point = '%s'", mount_point.get_ptr()); - - //aio_init = false; - return CELL_OK; -} - -s32 cellFsReadWithOffset(PPUThread& CPU, u32 fd, u64 offset, vm::ptr buf, u64 buffer_size, vm::ptr> nread) -{ - sys_fs.Warning("cellFsReadWithOffset(fd=%d, offset=0x%llx, buf=*0x%x, buffer_size=%lld, nread=*0x%llx)", fd, offset, buf, buffer_size, nread); - - int ret; - vm::stackvar> oldPos(CPU), newPos(CPU); - ret = cellFsLseek(fd, 0, CELL_SEEK_CUR, oldPos); // Save the current position - if (ret) return ret; - ret = cellFsLseek(fd, offset, CELL_SEEK_SET, newPos); // Move to the specified offset - if (ret) return ret; - ret = cellFsRead(fd, buf, buffer_size, nread); // Read the file - if (ret) return ret; - ret = cellFsLseek(fd, oldPos.value(), CELL_SEEK_SET, newPos); // Return to the old position - if (ret) return ret; - - return CELL_OK; -} - -s32 cellFsSetDefaultContainer(u32 id, u32 total_limit) -{ - sys_fs.Todo("cellFsSetDefaultContainer(id=%d, total_limit=%d)", id, total_limit); - - return CELL_OK; -} - -s32 cellFsSetIoBufferFromDefaultContainer(u32 fd, u32 buffer_size, u32 page_type) -{ - sys_fs.Todo("cellFsSetIoBufferFromDefaultContainer(fd=%d, buffer_size=%d, page_type=%d)", fd, buffer_size, page_type); - - std::shared_ptr file; - if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; - - return CELL_OK; -} - -Module sys_fs("sys_fs", []() -{ - g_FsAioReadID = 0; - g_FsAioReadCur = 0; - aio_init = false; - - REG_FUNC(sys_fs, cellFsOpen); - REG_FUNC(sys_fs, cellFsSdataOpen); - REG_FUNC(sys_fs, cellFsSdataOpenByFd); - REG_FUNC(sys_fs, cellFsRead); - REG_FUNC(sys_fs, cellFsWrite); - REG_FUNC(sys_fs, cellFsClose); - REG_FUNC(sys_fs, cellFsOpendir); - REG_FUNC(sys_fs, cellFsReaddir); - REG_FUNC(sys_fs, cellFsClosedir); - REG_FUNC(sys_fs, cellFsStat); - REG_FUNC(sys_fs, cellFsFstat); - REG_FUNC(sys_fs, cellFsMkdir); - REG_FUNC(sys_fs, cellFsRename); - REG_FUNC(sys_fs, cellFsChmod); - REG_FUNC(sys_fs, cellFsFsync); - REG_FUNC(sys_fs, cellFsRmdir); - REG_FUNC(sys_fs, cellFsUnlink); - REG_FUNC(sys_fs, cellFsLseek); - REG_FUNC(sys_fs, cellFsFtruncate); - REG_FUNC(sys_fs, cellFsTruncate); - REG_FUNC(sys_fs, cellFsFGetBlockSize); - REG_FUNC(sys_fs, cellFsAioRead); - REG_FUNC(sys_fs, cellFsAioWrite); - REG_FUNC(sys_fs, cellFsAioInit); - REG_FUNC(sys_fs, cellFsAioFinish); - REG_FUNC(sys_fs, cellFsGetBlockSize); - REG_FUNC(sys_fs, cellFsGetFreeSize); - REG_FUNC(sys_fs, cellFsReadWithOffset); - REG_FUNC(sys_fs, cellFsGetDirectoryEntries); - REG_FUNC(sys_fs, cellFsStReadInit); - REG_FUNC(sys_fs, cellFsStReadFinish); - REG_FUNC(sys_fs, cellFsStReadGetRingBuf); - REG_FUNC(sys_fs, cellFsStReadGetStatus); - REG_FUNC(sys_fs, cellFsStReadGetRegid); - REG_FUNC(sys_fs, cellFsStReadStart); - REG_FUNC(sys_fs, cellFsStReadStop); - REG_FUNC(sys_fs, cellFsStRead); - REG_FUNC(sys_fs, cellFsStReadGetCurrentAddr); - REG_FUNC(sys_fs, cellFsStReadPutCurrentAddr); - REG_FUNC(sys_fs, cellFsStReadWait); - REG_FUNC(sys_fs, cellFsStReadWaitCallback); - REG_FUNC(sys_fs, cellFsSetDefaultContainer); - REG_FUNC(sys_fs, cellFsSetIoBufferFromDefaultContainer); -}); diff --git a/rpcs3/Emu/SysCalls/lv2/cellFs.h b/rpcs3/Emu/SysCalls/lv2/cellFs.h deleted file mode 100644 index e114ef3464..0000000000 --- a/rpcs3/Emu/SysCalls/lv2/cellFs.h +++ /dev/null @@ -1,154 +0,0 @@ -#pragma once - -enum CellFsOflag -{ - CELL_O_RDONLY = 000000, - CELL_O_WRONLY = 000001, - CELL_O_RDWR = 000002, - CELL_O_ACCMODE = 000003, - CELL_O_CREAT = 000100, - CELL_O_EXCL = 000200, - CELL_O_TRUNC = 001000, - CELL_O_APPEND = 002000, - CELL_O_MSELF = 010000, -}; - -static const u32 CELL_FS_TYPE_UNKNOWN = 0; - -enum CellFsSeek -{ - CELL_SEEK_SET, - CELL_SEEK_CUR, - CELL_SEEK_END, -}; - -enum CellFsLength -{ - CELL_MAX_FS_PATH_LENGTH = 1024, - CELL_MAX_FS_FILE_NAME_LENGTH = 255, - CELL_MAX_FS_MP_LENGTH = 31, -}; - -enum -{ - CELL_FS_S_IFDIR = 0040000, //directory - CELL_FS_S_IFREG = 0100000, //regular - CELL_FS_S_IFLNK = 0120000, //symbolic link - CELL_FS_S_IFWHT = 0160000, //unknown - - CELL_FS_S_IRUSR = 0000400, //R for owner - CELL_FS_S_IWUSR = 0000200, //W for owner - CELL_FS_S_IXUSR = 0000100, //X for owner - - CELL_FS_S_IRGRP = 0000040, //R for group - CELL_FS_S_IWGRP = 0000020, //W for group - CELL_FS_S_IXGRP = 0000010, //X for group - - CELL_FS_S_IROTH = 0000004, //R for other - CELL_FS_S_IWOTH = 0000002, //W for other - CELL_FS_S_IXOTH = 0000001, //X for other -}; - -enum FsDirentType -{ - CELL_FS_TYPE_DIRECTORY = 1, - CELL_FS_TYPE_REGULAR = 2, - CELL_FS_TYPE_SYMLINK = 3, -}; - -enum CellFsRingBufferCopy -{ - CELL_FS_ST_COPY = 0, - CELL_FS_ST_COPYLESS = 1, -}; - -enum cellFsStStatus -{ - CELL_FS_ST_INITIALIZED = 0x0001, - CELL_FS_ST_NOT_INITIALIZED = 0x0002, - CELL_FS_ST_STOP = 0x0100, - CELL_FS_ST_PROGRESS = 0x0200, -}; - -enum cellFsErrors -{ - CELL_FS_ERANGE = 34 -}; - -#pragma pack(push, 4) - -struct CellFsStat -{ - be_t st_mode; - be_t st_uid; - be_t st_gid; - be_t st_atime_; - be_t st_mtime_; - be_t st_ctime_; - be_t st_size; - be_t st_blksize; -}; - -struct CellFsUtimbuf -{ - be_t actime; - be_t modtime; -}; - -struct CellFsDirent -{ - u8 d_type; - u8 d_namlen; - char d_name[CELL_MAX_FS_FILE_NAME_LENGTH + 1]; -}; - -#pragma pack(pop) - -struct CellFsAio -{ - be_t fd; - be_t offset; - vm::bptr buf; - be_t size; - be_t user_data; -}; - -struct CellFsDirectoryEntry -{ - CellFsStat attribute; - CellFsDirent entry_name; -}; - -struct CellFsRingBuffer -{ - be_t ringbuf_size; - be_t block_size; - be_t transfer_rate; - be_t copy; -}; - -// SysCalls -s32 cellFsOpen(vm::ptr path, s32 flags, vm::ptr> fd, vm::ptr arg, u64 size); -s32 cellFsRead(u32 fd, vm::ptr buf, u64 nbytes, vm::ptr> nread); -s32 cellFsWrite(u32 fd, vm::ptr buf, u64 nbytes, vm::ptr nwrite); -s32 cellFsClose(u32 fd); -s32 cellFsOpendir(vm::ptr path, vm::ptr fd); -s32 cellFsReaddir(u32 fd, vm::ptr dir, vm::ptr nread); -s32 cellFsClosedir(u32 fd); -s32 cellFsStat(vm::ptr path, vm::ptr sb); -s32 cellFsFstat(u32 fd, vm::ptr sb); -s32 cellFsMkdir(vm::ptr path, u32 mode); -s32 cellFsRename(vm::ptr from, vm::ptr to); -s32 cellFsChmod(vm::ptr path, u32 mode); -s32 cellFsFsync(u32 fd); -s32 cellFsRmdir(vm::ptr path); -s32 cellFsUnlink(vm::ptr path); -s32 cellFsLseek(u32 fd, s64 offset, u32 whence, vm::ptr> pos); -s32 cellFsFtruncate(u32 fd, u64 size); -s32 cellFsTruncate(vm::ptr path, u64 size); -s32 cellFsFGetBlockSize(u32 fd, vm::ptr sector_size, vm::ptr block_size); -s32 cellFsGetBlockSize(vm::ptr path, vm::ptr sector_size, vm::ptr block_size); -s32 cellFsGetFreeSize(vm::ptr path, vm::ptr block_size, vm::ptr block_count); -s32 cellFsGetDirectoryEntries(u32 fd, vm::ptr entries, u32 entries_size, vm::ptr data_count); - -// no need to add every function here diff --git a/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp b/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp new file mode 100644 index 0000000000..9050aa0f85 --- /dev/null +++ b/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp @@ -0,0 +1,511 @@ +#include "stdafx.h" +#include "Emu/Memory/Memory.h" +#include "Emu/System.h" +#include "Emu/IdManager.h" +#include "Emu/SysCalls/SysCalls.h" + +#ifdef _WIN32 +#include +#undef CreateFile +#else +#include +#include +#endif + +#include "Emu/FS/VFS.h" +#include "Emu/FS/vfsFile.h" +#include "Emu/FS/vfsDir.h" + +#include "sys_fs.h" + +SysCallBase sys_fs("sys_fs"); + +s32 sys_fs_open(vm::ptr path, s32 flags, vm::ptr fd, u64 mode, vm::ptr arg, u64 size) +{ + sys_fs.Warning("sys_fs_open(path=*0x%x, flags=0x%x, fd=*0x%x, arg=*0x%x, size=0x%llx)", path, flags, fd, arg, size); + sys_fs.Warning("*** path = '%s'", path.get_ptr()); + + const std::string _path = path.get_ptr(); + + s32 _oflags = flags; + if (flags & CELL_FS_O_CREAT) + { + _oflags &= ~CELL_FS_O_CREAT; + Emu.GetVFS().CreateFile(_path); + } + + vfsOpenMode o_mode; + + switch (flags & CELL_FS_O_ACCMODE) + { + case CELL_FS_O_RDONLY: + _oflags &= ~CELL_FS_O_RDONLY; + o_mode = vfsRead; + break; + + case CELL_FS_O_WRONLY: + _oflags &= ~CELL_FS_O_WRONLY; + + if (flags & CELL_FS_O_APPEND) + { + _oflags &= ~CELL_FS_O_APPEND; + o_mode = vfsWriteAppend; + } + else if (flags & CELL_FS_O_EXCL) + { + _oflags &= ~CELL_FS_O_EXCL; + o_mode = vfsWriteExcl; + } + else //if (flags & CELL_FS_O_TRUNC) + { + _oflags &= ~CELL_FS_O_TRUNC; + o_mode = vfsWrite; + } + break; + + case CELL_FS_O_RDWR: + _oflags &= ~CELL_FS_O_RDWR; + if (flags & CELL_FS_O_TRUNC) + { + _oflags &= ~CELL_FS_O_TRUNC; + //truncate file before opening it as read/write + auto filePtr = Emu.GetVFS().OpenFile(_path, vfsWrite); + delete filePtr; + } + o_mode = vfsReadWrite; + break; + } + + if (_oflags != 0) + { + sys_fs.Error("sys_fs_open(): '%s' has unknown flags! flags: 0x%08x", path.get_ptr(), flags); + return CELL_EINVAL; + } + + if (!Emu.GetVFS().ExistsFile(_path)) + { + sys_fs.Error("sys_fs_open(): '%s' not found! flags: 0x%08x", path.get_ptr(), flags); + return CELL_ENOENT; + } + + std::shared_ptr stream(Emu.GetVFS().OpenFile(_path, o_mode)); + + if (!stream || !stream->IsOpened()) + { + sys_fs.Error("sys_fs_open(): '%s' not found! flags: 0x%08x", path.get_ptr(), flags); + return CELL_ENOENT; + } + + u32 id = Emu.GetIdManager().GetNewID(stream, TYPE_FS_FILE); + *fd = id; + sys_fs.Notice("sys_fs_open(): '%s' opened, id -> 0x%x", path.get_ptr(), id); + + return CELL_OK; +} + +s32 sys_fs_read(u32 fd, vm::ptr buf, u64 nbytes, vm::ptr nread) +{ + sys_fs.Log("sys_fs_read(fd=0x%x, buf=0x%x, nbytes=0x%llx, nread=0x%x)", fd, buf, nbytes, nread); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + // TODO: checks + + const u64 res = nbytes ? file->Read(buf.get_ptr(), nbytes) : 0; + + if (nread) *nread = res; + + return CELL_OK; +} + +s32 sys_fs_write(u32 fd, vm::ptr buf, u64 nbytes, vm::ptr nwrite) +{ + sys_fs.Log("sys_fs_write(fd=0x%x, buf=*0x%x, nbytes=0x%llx, nwrite=*0x%x)", fd, buf, nbytes, nwrite); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) return CELL_ESRCH; + + // TODO: checks + + const u64 res = nbytes ? file->Write(buf.get_ptr(), nbytes) : 0; + + if (nwrite) *nwrite = res; + + return CELL_OK; +} + +s32 sys_fs_close(u32 fd) +{ + sys_fs.Warning("sys_fs_close(fd=0x%x)", fd); + + if (!Emu.GetIdManager().RemoveID(fd)) + return CELL_ESRCH; + + return CELL_OK; +} + +s32 sys_fs_opendir(vm::ptr path, vm::ptr fd) +{ + sys_fs.Warning("sys_fs_opendir(path=*0x%x, fd=*0x%x)", path, fd); + sys_fs.Warning("*** path = '%s'", path.get_ptr()); + + std::shared_ptr dir(Emu.GetVFS().OpenDir(path.get_ptr())); + if (!dir || !dir->IsOpened()) + { + return CELL_ENOENT; + } + + *fd = Emu.GetIdManager().GetNewID(dir, TYPE_FS_DIR); + return CELL_OK; +} + +s32 sys_fs_readdir(u32 fd, vm::ptr dir, vm::ptr nread) +{ + sys_fs.Warning("sys_fs_readdir(fd=0x%x, dir=*0x%x, nread=*0x%x)", fd, dir, nread); + + std::shared_ptr directory; + if (!Emu.GetIdManager().GetIDData(fd, directory)) + return CELL_ESRCH; + + const DirEntryInfo* info = directory->Read(); + if (info) + { + dir->d_type = (info->flags & DirEntry_TypeFile) ? CELL_FS_TYPE_REGULAR : CELL_FS_TYPE_DIRECTORY; + dir->d_namlen = u8(std::min(info->name.length(), CELL_FS_MAX_FS_FILE_NAME_LENGTH)); + strcpy_trunc(dir->d_name, info->name); + *nread = sizeof(CellFsDirent); + } + else + { + *nread = 0; + } + + return CELL_OK; +} + +s32 sys_fs_closedir(u32 fd) +{ + sys_fs.Warning("sys_fs_closedir(fd=0x%x)", fd); + + if (!Emu.GetIdManager().RemoveID(fd)) + return CELL_ESRCH; + + return CELL_OK; +} + +s32 sys_fs_stat(vm::ptr path, vm::ptr sb) +{ + sys_fs.Warning("sys_fs_stat(path=*0x%x, sb=*0x%x)", path, sb); + sys_fs.Warning("*** path = '%s'", path.get_ptr()); + + const std::string _path = path.get_ptr(); + + u32 mode = 0; + s32 uid = 0; + s32 gid = 0; + u64 atime = 0; + u64 mtime = 0; + u64 ctime = 0; + u64 size = 0; + + std::string real_path; + + Emu.GetVFS().GetDevice(_path, real_path); + + int stat_result; +#ifdef _WIN32 + struct _stat64 buf; + stat_result = _stat64(real_path.c_str(), &buf); +#else + struct stat buf; + stat_result = stat(real_path.c_str(), &buf); +#endif + if (stat_result) + { + sys_fs.Error("sys_fs_stat(): stat('%s') failed -> 0x%x", real_path.c_str(), stat_result); + } + else + { + mode = buf.st_mode; + uid = buf.st_uid; + gid = buf.st_gid; + atime = buf.st_atime; + mtime = buf.st_mtime; + ctime = buf.st_ctime; + size = buf.st_size; + } + + sb->mode = + CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR | + CELL_FS_S_IRGRP | CELL_FS_S_IWGRP | CELL_FS_S_IXGRP | + CELL_FS_S_IROTH | CELL_FS_S_IWOTH | CELL_FS_S_IXOTH; + + if (sb->mode == mode) + sys_fs.Error("sys_fs_stat(): mode is the same (0x%x)", mode); + + sb->uid = uid; + sb->gid = gid; + sb->atime = atime; + sb->mtime = mtime; + sb->ctime = ctime; + sb->blksize = 4096; + + { + vfsDir dir(_path); + if (dir.IsOpened()) + { + sb->mode |= CELL_FS_S_IFDIR; + return CELL_OK; + } + } + + { + vfsFile f(_path); + if (f.IsOpened()) + { + sb->mode |= CELL_FS_S_IFREG; + sb->size = f.GetSize(); + return CELL_OK; + } + } + + if (sb->size == size && size != 0) + sys_fs.Error("sys_fs_stat(): size is the same (0x%x)", size); + + sys_fs.Warning("sys_fs_stat(): '%s' not found", path.get_ptr()); + return CELL_ENOENT; +} + +s32 sys_fs_fstat(u32 fd, vm::ptr sb) +{ + sys_fs.Warning("sys_fs_fstat(fd=0x%x, sb=*0x%x)", fd, sb); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + sb->mode = + CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR | + CELL_FS_S_IRGRP | CELL_FS_S_IWGRP | CELL_FS_S_IXGRP | + CELL_FS_S_IROTH | CELL_FS_S_IWOTH | CELL_FS_S_IXOTH; + + sb->mode |= CELL_FS_S_IFREG; //TODO: dir CELL_FS_S_IFDIR + sb->uid = 0; + sb->gid = 0; + sb->atime = 0; //TODO + sb->mtime = 0; //TODO + sb->ctime = 0; //TODO + sb->size = file->GetSize(); + sb->blksize = 4096; + + return CELL_OK; +} + +s32 sys_fs_mkdir(vm::ptr path, CellFsMode mode) +{ + sys_fs.Warning("sys_fs_mkdir(path=*0x%x, mode=%d)", path, mode); + sys_fs.Warning("*** path = '%s'", path.get_ptr()); + + const std::string _path = path.get_ptr(); + + if (vfsDir().IsExists(_path)) + return CELL_EEXIST; + + if (!Emu.GetVFS().CreateDir(_path)) + return CELL_EBUSY; + + sys_fs.Notice("sys_fs_mkdir(): directory '%s' created", path.get_ptr()); + return CELL_OK; +} + +s32 sys_fs_rename(vm::ptr from, vm::ptr to) +{ + sys_fs.Warning("sys_fs_rename(from=*0x%x, to=*0x%x)", from, to); + sys_fs.Warning("*** from = '%s'", from.get_ptr()); + sys_fs.Warning("*** to = '%s'", to.get_ptr()); + + std::string _from = from.get_ptr(); + std::string _to = to.get_ptr(); + + { + vfsDir dir; + if (dir.IsExists(_from)) + { + if (!dir.Rename(_from, _to)) + return CELL_EBUSY; + + sys_fs.Notice("sys_fs_rename(): directory '%s' renamed to '%s'", from.get_ptr(), to.get_ptr()); + return CELL_OK; + } + } + + { + vfsFile f; + + if (f.Exists(_from)) + { + if (!f.Rename(_from, _to)) + return CELL_EBUSY; + + sys_fs.Notice("sys_fs_rename(): file '%s' renamed to '%s'", from.get_ptr(), to.get_ptr()); + return CELL_OK; + } + } + + return CELL_ENOENT; +} + +s32 sys_fs_rmdir(vm::ptr path) +{ + sys_fs.Warning("sys_fs_rmdir(path=*0x%x)", path); + sys_fs.Warning("*** path = '%s'", path.get_ptr()); + + std::string _path = path.get_ptr(); + + vfsDir d; + if (!d.IsExists(_path)) + return CELL_ENOENT; + + if (!d.Remove(_path)) + return CELL_EBUSY; + + sys_fs.Notice("sys_fs_rmdir(): directory '%s' removed", path.get_ptr()); + return CELL_OK; +} + +s32 sys_fs_unlink(vm::ptr path) +{ + sys_fs.Warning("sys_fs_unlink(path=*0x%x)", path); + sys_fs.Warning("*** path = '%s'", path.get_ptr()); + + std::string _path = path.get_ptr(); + + if (vfsDir().IsExists(_path)) + return CELL_EISDIR; + + if (!Emu.GetVFS().ExistsFile(_path)) + return CELL_ENOENT; + + if (!Emu.GetVFS().RemoveFile(_path)) + return CELL_EACCES; + + sys_fs.Notice("sys_fs_unlink(): file '%s' deleted", path.get_ptr()); + return CELL_OK; +} + +s32 sys_fs_lseek(u32 fd, s64 offset, s32 whence, vm::ptr pos) +{ + sys_fs.Log("sys_fs_lseek(fd=0x%x, offset=0x%llx, whence=0x%x, pos=*0x%x)", fd, offset, whence, pos); + + vfsSeekMode seek_mode; + switch (whence) + { + case CELL_FS_SEEK_SET: seek_mode = vfsSeekSet; break; + case CELL_FS_SEEK_CUR: seek_mode = vfsSeekCur; break; + case CELL_FS_SEEK_END: seek_mode = vfsSeekEnd; break; + default: + sys_fs.Error("sys_fs_lseek(fd=0x%x): unknown seek whence (0x%x)", fd, whence); + return CELL_EINVAL; + } + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + *pos = file->Seek(offset, seek_mode); + return CELL_OK; +} + +s32 sys_fs_fget_block_size(u32 fd, vm::ptr sector_size, vm::ptr block_size, vm::ptr arg4, vm::ptr arg5) +{ + sys_fs.Todo("sys_fs_fget_block_size(fd=%d, sector_size=*0x%x, block_size=*0x%x, arg4=*0x%x, arg5=*0x%x)", fd, sector_size, block_size, arg4, arg5); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + *sector_size = 4096; // ? + *block_size = 4096; // ? + + return CELL_OK; +} + +s32 sys_fs_get_block_size(vm::ptr path, vm::ptr sector_size, vm::ptr block_size, vm::ptr arg4) +{ + sys_fs.Todo("sys_fs_get_block_size(path=*0x%x, sector_size=*0x%x, block_size=*0x%x, arg4=*0x%x, arg5=*0x%x)", path, sector_size, block_size, arg4); + sys_fs.Todo("*** path = '%s'", path.get_ptr()); + + *sector_size = 4096; // ? + *block_size = 4096; // ? + + return CELL_OK; +} + +s32 sys_fs_truncate(vm::ptr path, u64 size) +{ + sys_fs.Warning("sys_fs_truncate(path=*0x%x, size=0x%llx)", path, size); + sys_fs.Warning("*** path = '%s'", path.get_ptr()); + + vfsFile f(path.get_ptr(), vfsReadWrite); + if (!f.IsOpened()) + { + sys_fs.Warning("sys_fs_truncate(): '%s' not found", path.get_ptr()); + return CELL_ENOENT; + } + u64 initialSize = f.GetSize(); + + if (initialSize < size) + { + u64 last_pos = f.Tell(); + f.Seek(0, vfsSeekEnd); + static const char nullbyte = 0; + f.Seek(size - initialSize - 1, vfsSeekCur); + f.Write(&nullbyte, sizeof(char)); + f.Seek(last_pos, vfsSeekSet); + } + + if (initialSize > size) + { + // (TODO) + } + + return CELL_OK; +} + +s32 sys_fs_ftruncate(u32 fd, u64 size) +{ + sys_fs.Warning("sys_fs_ftruncate(fd=0x%x, size=0x%llx)", fd, size); + + std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) + return CELL_ESRCH; + + u64 initialSize = file->GetSize(); + + if (initialSize < size) + { + u64 last_pos = file->Tell(); + file->Seek(0, vfsSeekEnd); + static const char nullbyte = 0; + file->Seek(size - initialSize - 1, vfsSeekCur); + file->Write(&nullbyte, sizeof(char)); + file->Seek(last_pos, vfsSeekSet); + } + + if (initialSize > size) + { + // (TODO) + } + + return CELL_OK; +} + +s32 sys_fs_chmod(vm::ptr path, CellFsMode mode) +{ + sys_fs.Todo("sys_fs_chmod(path=*0x%x, mode=%d) -> CELL_OK", path, mode); + sys_fs.Todo("*** path = '%s'", path.get_ptr()); + + return CELL_OK; +} diff --git a/rpcs3/Emu/SysCalls/lv2/sys_fs.h b/rpcs3/Emu/SysCalls/lv2/sys_fs.h new file mode 100644 index 0000000000..6ae94e60db --- /dev/null +++ b/rpcs3/Emu/SysCalls/lv2/sys_fs.h @@ -0,0 +1,166 @@ +#pragma once + +#pragma pack(push, 4) + +// Error Codes +enum : s32 +{ + CELL_FS_EDOM = CELL_EDOM, + CELL_FS_EFAULT = CELL_EFAULT, + CELL_FS_EFBIG = CELL_EFBIG, + CELL_FS_EFPOS = CELL_EFPOS, + CELL_FS_EMLINK = CELL_EMLINK, + CELL_FS_ENFILE = CELL_ENFILE, + CELL_FS_ENOENT = CELL_ENOENT, + CELL_FS_ENOSPC = CELL_ENOSPC, + CELL_FS_ENOTTY = CELL_ENOTTY, + CELL_FS_EPIPE = CELL_EPIPE, + CELL_FS_ERANGE = CELL_ERANGE, + CELL_FS_EROFS = CELL_EROFS, + CELL_FS_ESPIPE = CELL_ESPIPE, + CELL_FS_E2BIG = CELL_E2BIG, + CELL_FS_EACCES = CELL_EACCES, + CELL_FS_EAGAIN = CELL_EAGAIN, + CELL_FS_EBADF = CELL_EBADF, + CELL_FS_EBUSY = CELL_EBUSY, + //CELL_FS_ECHILD = CELL_ECHILD, + CELL_FS_EEXIST = CELL_EEXIST, + CELL_FS_EINTR = CELL_EINTR, + CELL_FS_EINVAL = CELL_EINVAL, + CELL_FS_EIO = CELL_EIO, + CELL_FS_EISDIR = CELL_EISDIR, + CELL_FS_EMFILE = CELL_EMFILE, + CELL_FS_ENODEV = CELL_ENODEV, + CELL_FS_ENOEXEC = CELL_ENOEXEC, + CELL_FS_ENOMEM = CELL_ENOMEM, + CELL_FS_ENOTDIR = CELL_ENOTDIR, + CELL_FS_ENXIO = CELL_ENXIO, + CELL_FS_EPERM = CELL_EPERM, + CELL_FS_ESRCH = CELL_ESRCH, + CELL_FS_EXDEV = CELL_EXDEV, + CELL_FS_EBADMSG = CELL_EBADMSG, + CELL_FS_ECANCELED = CELL_ECANCELED, + CELL_FS_EDEADLK = CELL_EDEADLK, + CELL_FS_EILSEQ = CELL_EILSEQ, + CELL_FS_EINPROGRESS = CELL_EINPROGRESS, + CELL_FS_EMSGSIZE = CELL_EMSGSIZE, + CELL_FS_ENAMETOOLONG = CELL_ENAMETOOLONG, + CELL_FS_ENOLCK = CELL_ENOLCK, + CELL_FS_ENOSYS = CELL_ENOSYS, + CELL_FS_ENOTEMPTY = CELL_ENOTEMPTY, + CELL_FS_ENOTSUP = CELL_ENOTSUP, + CELL_FS_ETIMEDOUT = CELL_ETIMEDOUT, + CELL_FS_EFSSPECIFIC = CELL_EFSSPECIFIC, + CELL_FS_EOVERFLOW = CELL_EOVERFLOW, + CELL_FS_ENOTMOUNTED = CELL_ENOTMOUNTED, + CELL_FS_ENOTMSELF = CELL_ENOTMSELF, + CELL_FS_ENOTSDATA = CELL_ENOTSDATA, + CELL_FS_EAUTHFATAL = CELL_EAUTHFATAL, +}; + +// Open Flags +enum : s32 +{ + CELL_FS_O_RDONLY = 000000, + CELL_FS_O_WRONLY = 000001, + CELL_FS_O_RDWR = 000002, + CELL_FS_O_ACCMODE = 000003, + CELL_FS_O_CREAT = 000100, + CELL_FS_O_EXCL = 000200, + CELL_FS_O_TRUNC = 001000, + CELL_FS_O_APPEND = 002000, + CELL_FS_O_MSELF = 010000, +}; + +// Seek Mode +enum : s32 +{ + CELL_FS_SEEK_SET, + CELL_FS_SEEK_CUR, + CELL_FS_SEEK_END, +}; + +enum : s32 +{ + CELL_FS_MAX_FS_PATH_LENGTH = 1024, + CELL_FS_MAX_FS_FILE_NAME_LENGTH = 255, + CELL_FS_MAX_MP_LENGTH = 31, +}; + +enum CellFsMode : s32 +{ + CELL_FS_S_IFMT = 0170000, + CELL_FS_S_IFDIR = 0040000, // directory + CELL_FS_S_IFREG = 0100000, // regular + CELL_FS_S_IFLNK = 0120000, // symbolic link + CELL_FS_S_IFWHT = 0160000, // unknown + + CELL_FS_S_IRUSR = 0000400, // R for owner + CELL_FS_S_IWUSR = 0000200, // W for owner + CELL_FS_S_IXUSR = 0000100, // X for owner + + CELL_FS_S_IRGRP = 0000040, // R for group + CELL_FS_S_IWGRP = 0000020, // W for group + CELL_FS_S_IXGRP = 0000010, // X for group + + CELL_FS_S_IROTH = 0000004, // R for other + CELL_FS_S_IWOTH = 0000002, // W for other + CELL_FS_S_IXOTH = 0000001, // X for other +}; + +// CellFsDirent.d_type +enum : u8 +{ + CELL_FS_TYPE_UNKNOWN = 0, + CELL_FS_TYPE_DIRECTORY = 1, + CELL_FS_TYPE_REGULAR = 2, + CELL_FS_TYPE_SYMLINK = 3, +}; + +struct CellFsDirent +{ + u8 d_type; + u8 d_namlen; + char d_name[256]; +}; + +struct CellFsStat +{ + be_t mode; + be_t uid; + be_t gid; + be_t atime; + be_t mtime; + be_t ctime; + be_t size; + be_t blksize; +}; + +struct CellFsUtimbuf +{ + be_t actime; + be_t modtime; +}; + +#pragma pack(pop) + +// SysCalls +s32 sys_fs_open(vm::ptr path, s32 flags, vm::ptr fd, u64 mode, vm::ptr arg, u64 size); +s32 sys_fs_read(u32 fd, vm::ptr buf, u64 nbytes, vm::ptr nread); +s32 sys_fs_write(u32 fd, vm::ptr buf, u64 nbytes, vm::ptr nwrite); +s32 sys_fs_close(u32 fd); +s32 sys_fs_opendir(vm::ptr path, vm::ptr fd); +s32 sys_fs_readdir(u32 fd, vm::ptr dir, vm::ptr nread); +s32 sys_fs_closedir(u32 fd); +s32 sys_fs_stat(vm::ptr path, vm::ptr sb); +s32 sys_fs_fstat(u32 fd, vm::ptr sb); +s32 sys_fs_mkdir(vm::ptr path, CellFsMode mode); +s32 sys_fs_rename(vm::ptr from, vm::ptr to); +s32 sys_fs_rmdir(vm::ptr path); +s32 sys_fs_unlink(vm::ptr path); +s32 sys_fs_lseek(u32 fd, s64 offset, s32 whence, vm::ptr pos); +s32 sys_fs_fget_block_size(u32 fd, vm::ptr sector_size, vm::ptr block_size, vm::ptr arg4, vm::ptr arg5); +s32 sys_fs_get_block_size(vm::ptr path, vm::ptr sector_size, vm::ptr block_size, vm::ptr arg4); +s32 sys_fs_truncate(vm::ptr path, u64 size); +s32 sys_fs_ftruncate(u32 fd, u64 size); +s32 sys_fs_chmod(vm::ptr path, CellFsMode mode); diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index d0f086572f..f7f0b774a9 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -39,6 +39,8 @@ + + @@ -177,7 +179,6 @@ - @@ -439,11 +440,11 @@ - + @@ -472,6 +473,7 @@ + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index c1fa6b8ea9..9d50d29f54 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -650,9 +650,6 @@ Emu\SysCalls - - Emu\SysCalls\lv2 - Utilities @@ -857,6 +854,12 @@ Emu\SysCalls\lv2 + + Emu\SysCalls\lv2 + + + Emu\SysCalls\Modules + @@ -1450,9 +1453,6 @@ Emu\CPU\ARMv7 - - Emu\SysCalls\lv2 - Utilities @@ -1537,5 +1537,11 @@ Emu\Memory + + Emu\SysCalls\lv2 + + + Emu\SysCalls\Modules + \ No newline at end of file