sys_fs syscalls detached from cellFs

This commit is contained in:
Nekotekina 2015-03-12 22:02:02 +03:00
parent 0cf7bb056e
commit 583b6d92ec
20 changed files with 1635 additions and 1356 deletions

View File

@ -153,7 +153,9 @@ public:
std::lock_guard<std::mutex> 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<typename T> std::shared_ptr<T> GetIDData(const u32 id)
{
std::lock_guard<std::mutex> 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<T>();
}
bool HasID(const u32 id)
{
std::lock_guard<std::mutex> 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);
}

View File

@ -108,14 +108,14 @@ namespace vm
}
*/
template<typename AT> operator const ps3::ptr<T, 1, AT>() const
template<typename AT> operator _ptr_base<T, 1, AT>() const
{
return ps3::ptr<T, 1, AT>::make(m_addr);
return _ptr_base<T, 1, AT>::make(m_addr);
}
template<typename AT> operator const ps3::ptr<const T, 1, AT>() const
template<typename AT> operator _ptr_base<const T, 1, AT>() const
{
return ps3::ptr<const T, 1, AT>::make(m_addr);
return _ptr_base<const T, 1, AT>::make(m_addr);
}
operator T&()
@ -604,14 +604,14 @@ namespace vm
}
*/
template<typename AT> operator const ps3::ptr<T, 1, AT>() const
template<typename AT> operator _ptr_base<T, 1, AT>() const
{
return ps3::ptr<T, 1, AT>::make(m_data.addr);
return _ptr_base<T, 1, AT>::make(m_data.addr);
}
template<typename AT> operator const ps3::ptr<const T, 1, AT>() const
template<typename AT> operator _ptr_base<const T, 1, AT>() const
{
return ps3::ptr<const T, 1, AT>::make(m_data.addr);
return _ptr_base<const T, 1, AT>::make(m_data.addr);
}
operator T&()

View File

@ -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,

View File

@ -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 },

View File

@ -30,7 +30,7 @@ int cellFontInitializeWithRevision(u64 revisionFlags, vm::ptr<CellFontConfig> co
return CELL_FONT_OK;
}
int cellFontGetRevisionFlags(vm::ptr<be_t<u64>> revisionFlags)
int cellFontGetRevisionFlags(vm::ptr<u64> revisionFlags)
{
UNIMPLEMENTED_FUNC(cellFont);
return CELL_FONT_OK;
@ -375,7 +375,7 @@ int cellFontSetEffectSlant(vm::ptr<CellFont> font, float slantParam)
return CELL_FONT_OK;
}
int cellFontGetEffectSlant(vm::ptr<CellFont> font, vm::ptr<be_t<float>> slantParam)
int cellFontGetEffectSlant(vm::ptr<CellFont> font, vm::ptr<float> slantParam)
{
cellFont.Warning("cellFontSetEffectSlant(font_addr=0x%x, slantParam_addr=0x%x)", font.addr(), slantParam.addr());

View File

@ -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<const char> path, s32 flags, vm::ptr<u32> fd, vm::ptr<const void> 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<void> buf, u64 nbytes, vm::ptr<u64> 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<be_t<u64>>(CPU));
}
s32 cellFsWrite(PPUThread& CPU, u32 fd, vm::ptr<const void> buf, u64 nbytes, vm::ptr<u64> 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<be_t<u64>>(CPU));
}
s32 cellFsClose(u32 fd)
{
cellFs.Log("cellFsClose(fd=0x%x)", fd);
// call the syscall
return sys_fs_close(fd);
}
s32 cellFsOpendir(vm::ptr<const char> path, vm::ptr<u32> 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<CellFsDirent> dir, vm::ptr<u64> 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<const char> path, vm::ptr<CellFsStat> 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<CellFsStat> 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<const char> 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<const char> from, vm::ptr<const char> 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<const char> path)
{
cellFs.Warning("cellFsRmdir(path=*0x%x) -> sys_fs_rmdir()", path);
// TODO
// call the syscall
return sys_fs_rmdir(path);
}
s32 cellFsUnlink(vm::ptr<const char> 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<u64> 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<u64> sector_size, vm::ptr<u64> 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<be_t<u64>>(CPU), vm::stackvar<be_t<u64>>(CPU)) : CELL_EFAULT;
}
s32 cellFsGetBlockSize(PPUThread& CPU, vm::ptr<const char> path, vm::ptr<u64> sector_size, vm::ptr<u64> 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<be_t<u64>>(CPU));
}
s32 cellFsTruncate(vm::ptr<const char> 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<const char> 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<const char> path, vm::ptr<u32> block_size, vm::ptr<u64> 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<CellFsDirectoryEntry> entries, u32 entries_size, vm::ptr<u32> 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<vfsDirBase> 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<size_t>(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<CellFsRingBuffer> ringbuf)
{
cellFs.Warning("cellFsStReadInit(fd=0x%x, ringbuf=*0x%x)", fd, ringbuf);
std::shared_ptr<vfsStream> 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<void>(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<vfsStream> 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<CellFsRingBuffer> ringbuf)
{
cellFs.Warning("cellFsStReadGetRingBuf(fd=0x%x, ringbuf=*0x%x)", fd, ringbuf);
std::shared_ptr<vfsStream> 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<u64> status)
{
cellFs.Warning("cellFsStReadGetRingBuf(fd=0x%x, status=*0x%x)", fd, status);
std::shared_ptr<vfsStream> 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<u64> regid)
{
cellFs.Warning("cellFsStReadGetRingBuf(fd=0x%x, regid=*0x%x)", fd, regid);
std::shared_ptr<vfsStream> 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<vfsStream> 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<vfsStream> 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<u8> buf, u64 size, vm::ptr<u64> rsize)
{
cellFs.Warning("cellFsStRead(fd=0x%x, buf=*0x%x, size=0x%llx, rsize=*0x%x)", fd, buf, size, rsize);
std::shared_ptr<vfsStream> 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<vm::ptr<u8>> addr, vm::ptr<u64> size)
{
cellFs.Todo("cellFsStReadGetCurrentAddr(fd=0x%x, addr=*0x%x, size=*0x%x)", fd, addr, size);
std::shared_ptr<vfsStream> file;
if (!Emu.GetIdManager().GetIDData(fd, file))
return CELL_ESRCH;
return CELL_OK;
}
s32 cellFsStReadPutCurrentAddr(u32 fd, vm::ptr<u8> addr, u64 size)
{
cellFs.Todo("cellFsStReadPutCurrentAddr(fd=0x%x, addr=*0x%x, size=0x%llx)", fd, addr, size);
std::shared_ptr<vfsStream> 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<vfsStream> file;
if (!Emu.GetIdManager().GetIDData(fd, file))
return CELL_ESRCH;
return CELL_OK;
}
s32 cellFsStReadWaitCallback(u32 fd, u64 size, vm::ptr<void(int xfd, u64 xsize)> func)
{
cellFs.Todo("cellFsStReadWaitCallback(fd=0x%x, size=0x%llx, func=*0x%x)", fd, size, func);
std::shared_ptr<vfsStream> 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<vfsFileBase> packed_stream(Emu.GetVFS().OpenFile(packed_file, vfsRead));
std::shared_ptr<vfsFileBase> 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<const char> path, s32 flags, vm::ptr<u32> fd, vm::ptr<const void> 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<u32> sdata_fd, u64 offset, vm::ptr<const void> 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<s32> g_FsAioReadID(0);
std::atomic<s32> g_FsAioReadCur(0);
bool aio_init = false;
void fsAioRead(u32 fd, vm::ptr<CellFsAio> aio, int xid, vm::ptr<void(vm::ptr<CellFsAio> 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<vfsStream> 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<CellFsAio> aio, vm::ptr<s32> id, vm::ptr<void(vm::ptr<CellFsAio> 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<vfsStream> 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<CellFsAio> aio, vm::ptr<s32> id, vm::ptr<void(vm::ptr<CellFsAio> 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<const char> 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<const char> 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<void> buf, u64 buffer_size, vm::ptr<u64> 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<be_t<u64>> 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<vfsStream> 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);
});

View File

@ -0,0 +1,40 @@
#pragma once
// CellFsRingBuffer.copy
enum : s32
{
CELL_FS_ST_COPY = 0,
CELL_FS_ST_COPYLESS = 1,
};
struct CellFsRingBuffer
{
be_t<u64> ringbuf_size;
be_t<u64> block_size;
be_t<u64> transfer_rate;
be_t<s32> 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<u32> fd;
be_t<u64> offset;
vm::bptr<void> buf;
be_t<u64> size;
be_t<u64> user_data;
};

View File

@ -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<u32> subHandle, vm::ptr<CellGifDecSrc
break;
case se32(CELL_GIFDEC_FILE):
// Get file descriptor
vm::var<be_t<u32>> fd;
int ret = cellFsOpen(src->fileName, 0, fd, vm::ptr<const void>::make(0), 0);
current_subHandle->fd = fd.value();
if (ret != CELL_OK) return CELL_GIFDEC_ERROR_OPEN_FILE;
// Get size of file
vm::var<CellFsStat> 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<vfsStream> 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<CellGifDecInfo>
//Write the header to buffer
vm::var<u8[13]> buffer; // Alloc buffer for GIF header
vm::var<be_t<u64>> pos, nread;
switch(subHandle_data->src.srcSelect.data())
{
@ -83,10 +81,13 @@ int cellGifDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr<CellGifDecInfo>
break;
case se32(CELL_GIFDEC_FILE):
cellFsLseek(fd, 0, CELL_SEEK_SET, pos);
cellFsRead(fd, vm::ptr<void>::make(buffer.addr()), buffer.size(), nread);
{
auto file = Emu.GetIdManager().GetIDData<vfsStream>(fd);
file->Seek(0);
file->Read(buffer.begin(), buffer.size());
break;
}
}
if (*buffer.To<be_t<u32>>(0) != 0x47494638 ||
(*buffer.To<u16>(4) != 0x6139 && *buffer.To<u16>(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<u8> data, vm::pt
//Copy the GIF file to a buffer
vm::var<unsigned char[]> gif((u32)fileSize);
vm::var<be_t<u64>> pos, nread;
switch(subHandle_data->src.srcSelect.data())
{
@ -165,10 +165,13 @@ int cellGifDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr<u8> data, vm::pt
break;
case se32(CELL_GIFDEC_FILE):
cellFsLseek(fd, 0, CELL_SEEK_SET, pos);
cellFsRead(fd, vm::ptr<void>::make(gif.addr()), gif.size(), nread);
{
auto file = Emu.GetIdManager().GetIDData<vfsStream>(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<vfsStream>(subHandle_data->fd);
Emu.GetIdManager().RemoveID<CellGifDecSubHandle>(subHandle);
return CELL_OK;

View File

@ -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<u32> subHandle, vm::ptr<CellJpgDecSrc
break;
case se32(CELL_JPGDEC_FILE):
// Get file descriptor
vm::var<be_t<u32>> fd;
int ret = cellFsOpen(src->fileName, 0, fd, vm::ptr<const void>::make(0), 0);
current_subHandle->fd = fd.value();
if (ret != CELL_OK) return CELL_JPGDEC_ERROR_OPEN_FILE;
// Get size of file
vm::var<CellFsStat> 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<vfsStream> 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<vfsStream>(subHandle_data->fd);
Emu.GetIdManager().RemoveID<CellJpgDecSubHandle>(subHandle);
return CELL_OK;
@ -94,7 +93,6 @@ int cellJpgDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr<CellJpgDecInfo>
//Write the header to buffer
vm::var<u8[]> buffer((u32)fileSize);
vm::var<be_t<u64>> pos, nread;
switch(subHandle_data->src.srcSelect.data())
{
@ -103,10 +101,13 @@ int cellJpgDecReadHeader(u32 mainHandle, u32 subHandle, vm::ptr<CellJpgDecInfo>
break;
case se32(CELL_JPGDEC_FILE):
cellFsLseek(fd, 0, CELL_SEEK_SET, pos);
cellFsRead(fd, vm::ptr<void>::make(buffer.addr()), buffer.size(), nread);
{
auto file = Emu.GetIdManager().GetIDData<vfsStream>(fd);
file->Seek(0);
file->Read(buffer.ptr(), buffer.size());
break;
}
}
if (*buffer.To<u32>(0) != 0xE0FFD8FF || // Error: Not a valid SOI header
*buffer.To<u32>(6) != 0x4649464A) // Error: Not a valid JFIF string
@ -163,7 +164,6 @@ int cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr<u8> data, vm::pt
//Copy the JPG file to a buffer
vm::var<unsigned char[]> jpg((u32)fileSize);
vm::var<be_t<u64>> pos, nread;
switch(subHandle_data->src.srcSelect.data())
{
@ -172,10 +172,13 @@ int cellJpgDecDecodeData(u32 mainHandle, u32 subHandle, vm::ptr<u8> data, vm::pt
break;
case se32(CELL_JPGDEC_FILE):
cellFsLseek(fd, 0, CELL_SEEK_SET, pos);
cellFsRead(fd, vm::ptr<void>::make(jpg.addr()), jpg.size(), nread);
{
auto file = Emu.GetIdManager().GetIDData<vfsStream>(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;

View File

@ -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 <map>
extern Module cellPngDec;
@ -76,19 +79,15 @@ s32 pngDecOpen(
break;
case se32(CELL_PNGDEC_FILE):
// Get file descriptor
vm::var<be_t<u32>> fd;
int ret = cellFsOpen(src->fileName, 0, fd, vm::ptr<const void>::make(0), 0);
stream->fd = fd.value();
if (ret != CELL_OK) return CELL_PNGDEC_ERROR_OPEN_FILE;
// Get size of file
vm::var<CellFsStat> 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<vfsStream> 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<vfsStream>(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<u8[34]> buffer; // Alloc buffer for PNG header
auto buffer_32 = buffer.To<be_t<u32>>();
vm::var<be_t<u64>> 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<void>::make(buffer.addr()), buffer.size(), nread);
{
auto file = Emu.GetIdManager().GetIDData<vfsStream>(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<unsigned char[]> png((u32)fileSize);
vm::var<be_t<u64>> 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<void>::make(png.addr()), png.size(), nread);
{
auto file = Emu.GetIdManager().GetIDData<vfsStream>(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;

View File

@ -14,7 +14,7 @@ extern s32 cellVideoOutConfigure(u32 videoOut, vm::ptr<CellVideoOutConfiguration
extern s32 cellGcmSetFlipMode(u32 mode);
extern void cellGcmSetFlipHandler(vm::ptr<void(u32)> handler);
extern void cellGcmSetVBlankHandler(vm::ptr<void(u32)> handler);
extern s32 cellGcmAddressToOffset(u32 address, vm::ptr<be_t<u32>> offset);
extern s32 cellGcmAddressToOffset(u32 address, vm::ptr<u32> offset);
extern s32 cellGcmSetDisplayBuffer(u32 id, u32 offset, u32 pitch, u32 width, u32 height);
extern s32 cellGcmSetPrepareFlip(vm::ptr<CellGcmContextData> ctx, u32 id);
extern s32 cellGcmSetSecondVFrequency(u32 freq);

View File

@ -2428,14 +2428,14 @@ s32 cellSpursCreateTask(vm::ptr<CellSpursTaskset> taskset, vm::ptr<u32> taskId,
return CELL_SPURS_TASK_ERROR_ALIGN;
}
vm::var<u32> tmpTaskId;
vm::var<be_t<u32>> tmpTaskId;
auto rc = spursCreateTask(taskset, tmpTaskId, vm::ptr<u32>::make(elf_addr), vm::ptr<u32>::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;

View File

@ -32,7 +32,7 @@ u32 g_tls_size;
std::array<std::atomic<u32>, 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<sys_lwmutex_t> 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<u64>(CPU));
return _sys_interrupt_thread_disestablish(ih, vm::stackvar<be_t<u64>>(CPU));
}
int sys_process_is_stack(u32 p)

View File

@ -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)

File diff suppressed because it is too large Load Diff

View File

@ -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<u32> st_mode;
be_t<s32> st_uid;
be_t<s32> st_gid;
be_t<u64> st_atime_;
be_t<u64> st_mtime_;
be_t<u64> st_ctime_;
be_t<u64> st_size;
be_t<u64> st_blksize;
};
struct CellFsUtimbuf
{
be_t<u64> actime;
be_t<u64> 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<u32> fd;
be_t<u64> offset;
vm::bptr<void> buf;
be_t<u64> size;
be_t<u64> user_data;
};
struct CellFsDirectoryEntry
{
CellFsStat attribute;
CellFsDirent entry_name;
};
struct CellFsRingBuffer
{
be_t<u64> ringbuf_size;
be_t<u64> block_size;
be_t<u64> transfer_rate;
be_t<u32> copy;
};
// SysCalls
s32 cellFsOpen(vm::ptr<const char> path, s32 flags, vm::ptr<be_t<u32>> fd, vm::ptr<const void> arg, u64 size);
s32 cellFsRead(u32 fd, vm::ptr<void> buf, u64 nbytes, vm::ptr<be_t<u64>> nread);
s32 cellFsWrite(u32 fd, vm::ptr<const void> buf, u64 nbytes, vm::ptr<u64> nwrite);
s32 cellFsClose(u32 fd);
s32 cellFsOpendir(vm::ptr<const char> path, vm::ptr<u32> fd);
s32 cellFsReaddir(u32 fd, vm::ptr<CellFsDirent> dir, vm::ptr<u64> nread);
s32 cellFsClosedir(u32 fd);
s32 cellFsStat(vm::ptr<const char> path, vm::ptr<CellFsStat> sb);
s32 cellFsFstat(u32 fd, vm::ptr<CellFsStat> sb);
s32 cellFsMkdir(vm::ptr<const char> path, u32 mode);
s32 cellFsRename(vm::ptr<const char> from, vm::ptr<const char> to);
s32 cellFsChmod(vm::ptr<const char> path, u32 mode);
s32 cellFsFsync(u32 fd);
s32 cellFsRmdir(vm::ptr<const char> path);
s32 cellFsUnlink(vm::ptr<const char> path);
s32 cellFsLseek(u32 fd, s64 offset, u32 whence, vm::ptr<be_t<u64>> pos);
s32 cellFsFtruncate(u32 fd, u64 size);
s32 cellFsTruncate(vm::ptr<const char> path, u64 size);
s32 cellFsFGetBlockSize(u32 fd, vm::ptr<u64> sector_size, vm::ptr<u64> block_size);
s32 cellFsGetBlockSize(vm::ptr<const char> path, vm::ptr<u64> sector_size, vm::ptr<u64> block_size);
s32 cellFsGetFreeSize(vm::ptr<const char> path, vm::ptr<u32> block_size, vm::ptr<u64> block_count);
s32 cellFsGetDirectoryEntries(u32 fd, vm::ptr<CellFsDirectoryEntry> entries, u32 entries_size, vm::ptr<u32> data_count);
// no need to add every function here

View File

@ -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 <windows.h>
#undef CreateFile
#else
#include <sys/types.h>
#include <sys/stat.h>
#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<const char> path, s32 flags, vm::ptr<u32> fd, u64 mode, vm::ptr<const void> 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<vfsStream> 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<void> buf, u64 nbytes, vm::ptr<u64> 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<vfsStream> 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<const void> buf, u64 nbytes, vm::ptr<u64> 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<vfsStream> 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<vfsStream>(fd))
return CELL_ESRCH;
return CELL_OK;
}
s32 sys_fs_opendir(vm::ptr<const char> path, vm::ptr<u32> 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<vfsDirBase> 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<CellFsDirent> dir, vm::ptr<u64> nread)
{
sys_fs.Warning("sys_fs_readdir(fd=0x%x, dir=*0x%x, nread=*0x%x)", fd, dir, nread);
std::shared_ptr<vfsDirBase> 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<size_t>(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<vfsDirBase>(fd))
return CELL_ESRCH;
return CELL_OK;
}
s32 sys_fs_stat(vm::ptr<const char> path, vm::ptr<CellFsStat> 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<CellFsStat> sb)
{
sys_fs.Warning("sys_fs_fstat(fd=0x%x, sb=*0x%x)", fd, sb);
std::shared_ptr<vfsStream> 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<const char> 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<const char> from, vm::ptr<const char> 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<const char> 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<const char> 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<u64> 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<vfsStream> 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<u64> sector_size, vm::ptr<u64> block_size, vm::ptr<u64> arg4, vm::ptr<u64> 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<vfsStream> 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<const char> path, vm::ptr<u64> sector_size, vm::ptr<u64> block_size, vm::ptr<u64> 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<const char> 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<vfsStream> 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<const char> 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;
}

View File

@ -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<u32> mode;
be_t<s32> uid;
be_t<s32> gid;
be_t<s64> atime;
be_t<s64> mtime;
be_t<s64> ctime;
be_t<u64> size;
be_t<u64> blksize;
};
struct CellFsUtimbuf
{
be_t<s64> actime;
be_t<s64> modtime;
};
#pragma pack(pop)
// SysCalls
s32 sys_fs_open(vm::ptr<const char> path, s32 flags, vm::ptr<u32> fd, u64 mode, vm::ptr<const void> arg, u64 size);
s32 sys_fs_read(u32 fd, vm::ptr<void> buf, u64 nbytes, vm::ptr<u64> nread);
s32 sys_fs_write(u32 fd, vm::ptr<const void> buf, u64 nbytes, vm::ptr<u64> nwrite);
s32 sys_fs_close(u32 fd);
s32 sys_fs_opendir(vm::ptr<const char> path, vm::ptr<u32> fd);
s32 sys_fs_readdir(u32 fd, vm::ptr<CellFsDirent> dir, vm::ptr<u64> nread);
s32 sys_fs_closedir(u32 fd);
s32 sys_fs_stat(vm::ptr<const char> path, vm::ptr<CellFsStat> sb);
s32 sys_fs_fstat(u32 fd, vm::ptr<CellFsStat> sb);
s32 sys_fs_mkdir(vm::ptr<const char> path, CellFsMode mode);
s32 sys_fs_rename(vm::ptr<const char> from, vm::ptr<const char> to);
s32 sys_fs_rmdir(vm::ptr<const char> path);
s32 sys_fs_unlink(vm::ptr<const char> path);
s32 sys_fs_lseek(u32 fd, s64 offset, s32 whence, vm::ptr<u64> pos);
s32 sys_fs_fget_block_size(u32 fd, vm::ptr<u64> sector_size, vm::ptr<u64> block_size, vm::ptr<u64> arg4, vm::ptr<u64> arg5);
s32 sys_fs_get_block_size(vm::ptr<const char> path, vm::ptr<u64> sector_size, vm::ptr<u64> block_size, vm::ptr<u64> arg4);
s32 sys_fs_truncate(vm::ptr<const char> path, u64 size);
s32 sys_fs_ftruncate(u32 fd, u64 size);
s32 sys_fs_chmod(vm::ptr<const char> path, CellFsMode mode);

View File

@ -39,6 +39,8 @@
<ClCompile Include="..\Utilities\Thread.cpp" />
<ClCompile Include="Emu\RSX\CgBinaryFragmentProgram.cpp" />
<ClCompile Include="Emu\RSX\CgBinaryVertexProgram.cpp" />
<ClCompile Include="Emu\SysCalls\lv2\sys_fs.cpp" />
<ClCompile Include="Emu\SysCalls\Modules\cellFs.cpp" />
<ClCompile Include="Emu\SysCalls\Modules\cellSpursSpu.cpp" />
<ClCompile Include="Crypto\aes.cpp" />
<ClCompile Include="Crypto\ec.cpp" />
@ -177,7 +179,6 @@
<ClCompile Include="Emu\SysCalls\Callback.cpp" />
<ClCompile Include="Emu\SysCalls\FuncList.cpp" />
<ClCompile Include="Emu\SysCalls\LogBase.cpp" />
<ClCompile Include="Emu\SysCalls\lv2\cellFs.cpp" />
<ClCompile Include="Emu\SysCalls\lv2\sleep_queue.cpp" />
<ClCompile Include="Emu\SysCalls\lv2\sys_cond.cpp" />
<ClCompile Include="Emu\SysCalls\lv2\sys_event.cpp" />
@ -439,11 +440,11 @@
<ClInclude Include="Emu\SysCalls\CB_FUNC.h" />
<ClInclude Include="Emu\SysCalls\ErrorCodes.h" />
<ClInclude Include="Emu\SysCalls\LogBase.h" />
<ClInclude Include="Emu\SysCalls\lv2\cellFs.h" />
<ClInclude Include="Emu\SysCalls\lv2\sleep_queue.h" />
<ClInclude Include="Emu\SysCalls\lv2\sys_cond.h" />
<ClInclude Include="Emu\SysCalls\lv2\sys_event.h" />
<ClInclude Include="Emu\SysCalls\lv2\sys_event_flag.h" />
<ClInclude Include="Emu\SysCalls\lv2\sys_fs.h" />
<ClInclude Include="Emu\SysCalls\lv2\sys_interrupt.h" />
<ClInclude Include="Emu\SysCalls\lv2\sys_lwcond.h" />
<ClInclude Include="Emu\SysCalls\lv2\sys_lwmutex.h" />
@ -472,6 +473,7 @@
<ClInclude Include="Emu\SysCalls\Modules\cellFiber.h" />
<ClInclude Include="Emu\SysCalls\Modules\cellFont.h" />
<ClInclude Include="Emu\SysCalls\Modules\cellFontFT.h" />
<ClInclude Include="Emu\SysCalls\Modules\cellFs.h" />
<ClInclude Include="Emu\SysCalls\Modules\cellGame.h" />
<ClInclude Include="Emu\SysCalls\Modules\cellGcmSys.h" />
<ClInclude Include="Emu\SysCalls\Modules\cellGem.h" />

View File

@ -650,9 +650,6 @@
<ClCompile Include="Emu\SysCalls\SyncPrimitivesManager.cpp">
<Filter>Emu\SysCalls</Filter>
</ClCompile>
<ClCompile Include="Emu\SysCalls\lv2\cellFs.cpp">
<Filter>Emu\SysCalls\lv2</Filter>
</ClCompile>
<ClCompile Include="..\Utilities\Thread.cpp">
<Filter>Utilities</Filter>
</ClCompile>
@ -857,6 +854,12 @@
<ClCompile Include="Emu\SysCalls\lv2\sleep_queue.cpp">
<Filter>Emu\SysCalls\lv2</Filter>
</ClCompile>
<ClCompile Include="Emu\SysCalls\lv2\sys_fs.cpp">
<Filter>Emu\SysCalls\lv2</Filter>
</ClCompile>
<ClCompile Include="Emu\SysCalls\Modules\cellFs.cpp">
<Filter>Emu\SysCalls\Modules</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="Crypto\aes.h">
@ -1450,9 +1453,6 @@
<ClInclude Include="Emu\ARMv7\PSVFuncList.h">
<Filter>Emu\CPU\ARMv7</Filter>
</ClInclude>
<ClInclude Include="Emu\SysCalls\lv2\cellFs.h">
<Filter>Emu\SysCalls\lv2</Filter>
</ClInclude>
<ClInclude Include="..\Utilities\Thread.h">
<Filter>Utilities</Filter>
</ClInclude>
@ -1537,5 +1537,11 @@
<ClInclude Include="Emu\Memory\refcnt.h">
<Filter>Emu\Memory</Filter>
</ClInclude>
<ClInclude Include="Emu\SysCalls\lv2\sys_fs.h">
<Filter>Emu\SysCalls\lv2</Filter>
</ClInclude>
<ClInclude Include="Emu\SysCalls\Modules\cellFs.h">
<Filter>Emu\SysCalls\Modules</Filter>
</ClInclude>
</ItemGroup>
</Project>