2015-03-12 20:02:02 +01:00
|
|
|
#include "stdafx.h"
|
|
|
|
|
#include "Emu/System.h"
|
|
|
|
|
#include "Emu/IdManager.h"
|
2016-03-21 20:43:03 +01:00
|
|
|
#include "Emu/Cell/PPUModule.h"
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-03-21 20:43:03 +01:00
|
|
|
#include "Emu/Cell/lv2/sys_fs.h"
|
2015-03-12 20:02:02 +01:00
|
|
|
#include "cellFs.h"
|
|
|
|
|
|
2016-04-27 00:27:24 +02:00
|
|
|
#include "Utilities/StrUtil.h"
|
|
|
|
|
|
2016-07-27 23:43:22 +02:00
|
|
|
#include <mutex>
|
|
|
|
|
|
2016-05-13 15:55:34 +02:00
|
|
|
logs::channel cellFs("cellFs", logs::level::notice);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2015-06-22 00:27:58 +02:00
|
|
|
s32 cellFsOpen(vm::cptr<char> path, s32 flags, vm::ptr<u32> fd, vm::cptr<void> arg, u64 size)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.warning("cellFsOpen(path=%s, flags=%#o, fd=*0x%x, arg=*0x%x, size=0x%llx) -> sys_fs_open()", path, flags, fd, arg, size);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
// call the syscall
|
2015-03-13 21:43:11 +01:00
|
|
|
return sys_fs_open(path, flags, fd, flags & CELL_FS_O_CREAT ? CELL_FS_S_IRUSR | CELL_FS_S_IWUSR : 0, arg, size);
|
2015-03-12 20:02:02 +01:00
|
|
|
}
|
|
|
|
|
|
2015-09-26 22:46:04 +02:00
|
|
|
s32 cellFsRead(u32 fd, vm::ptr<void> buf, u64 nbytes, vm::ptr<u64> nread)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.trace("cellFsRead(fd=0x%x, buf=0x%x, nbytes=0x%llx, nread=0x%x)", fd, buf, nbytes, nread);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// call the syscall
|
2015-09-26 22:46:04 +02:00
|
|
|
return sys_fs_read(fd, buf, nbytes, nread ? nread : vm::var<u64>{});
|
2015-03-12 20:02:02 +01:00
|
|
|
}
|
|
|
|
|
|
2015-09-26 22:46:04 +02:00
|
|
|
s32 cellFsWrite(u32 fd, vm::cptr<void> buf, u64 nbytes, vm::ptr<u64> nwrite)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.trace("cellFsWrite(fd=0x%x, buf=*0x%x, nbytes=0x%llx, nwrite=*0x%x)", fd, buf, nbytes, nwrite);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// call the syscall
|
2015-09-26 22:46:04 +02:00
|
|
|
return sys_fs_write(fd, buf, nbytes, nwrite ? nwrite : vm::var<u64>{});
|
2015-03-12 20:02:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsClose(u32 fd)
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.trace("cellFsClose(fd=0x%x)", fd);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// call the syscall
|
|
|
|
|
return sys_fs_close(fd);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 00:27:58 +02:00
|
|
|
s32 cellFsOpendir(vm::cptr<char> path, vm::ptr<u32> fd)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.warning("cellFsOpendir(path=%s, fd=*0x%x) -> sys_fs_opendir()", path, fd);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
// call the syscall
|
|
|
|
|
return sys_fs_opendir(path, fd);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsReaddir(u32 fd, vm::ptr<CellFsDirent> dir, vm::ptr<u64> nread)
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.trace("cellFsReaddir(fd=0x%x, dir=*0x%x, nread=*0x%x)", fd, dir, nread);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
if (!dir || !nread)
|
|
|
|
|
{
|
|
|
|
|
return CELL_EFAULT;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-12 20:02:02 +01:00
|
|
|
// call the syscall
|
2016-06-02 17:16:01 +02:00
|
|
|
return sys_fs_readdir(fd, dir, nread);
|
2015-03-12 20:02:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsClosedir(u32 fd)
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.trace("cellFsClosedir(fd=0x%x)", fd);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// call the syscall
|
|
|
|
|
return sys_fs_closedir(fd);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 00:27:58 +02:00
|
|
|
s32 cellFsStat(vm::cptr<char> path, vm::ptr<CellFsStat> sb)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.warning("cellFsStat(path=%s, sb=*0x%x) -> sys_fs_stat()", path, sb);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
// call the syscall
|
|
|
|
|
return sys_fs_stat(path, sb);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsFstat(u32 fd, vm::ptr<CellFsStat> sb)
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.trace("cellFsFstat(fd=0x%x, sb=*0x%x)", fd, sb);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// call the syscall
|
|
|
|
|
return sys_fs_fstat(fd, sb);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 00:27:58 +02:00
|
|
|
s32 cellFsMkdir(vm::cptr<char> path, s32 mode)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.warning("cellFsMkdir(path=%s, mode=%#o) -> sys_fs_mkdir()", path, mode);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
// call the syscall
|
|
|
|
|
return sys_fs_mkdir(path, mode);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 00:27:58 +02:00
|
|
|
s32 cellFsRename(vm::cptr<char> from, vm::cptr<char> to)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.warning("cellFsRename(from=%s, to=%s) -> sys_fs_rename()", from, to);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
// call the syscall
|
|
|
|
|
return sys_fs_rename(from, to);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 00:27:58 +02:00
|
|
|
s32 cellFsRmdir(vm::cptr<char> path)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.warning("cellFsRmdir(path=%s) -> sys_fs_rmdir()", path);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
// call the syscall
|
|
|
|
|
return sys_fs_rmdir(path);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 00:27:58 +02:00
|
|
|
s32 cellFsUnlink(vm::cptr<char> path)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.warning("cellFsUnlink(path=%s) -> sys_fs_unlink()", path);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
// call the syscall
|
|
|
|
|
return sys_fs_unlink(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsLseek(u32 fd, s64 offset, u32 whence, vm::ptr<u64> pos)
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.trace("cellFsLseek(fd=0x%x, offset=0x%llx, whence=0x%x, pos=*0x%x)", fd, offset, whence, pos);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
if (!pos)
|
|
|
|
|
{
|
|
|
|
|
return CELL_EFAULT;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-12 20:02:02 +01:00
|
|
|
// call the syscall
|
2016-06-02 17:16:01 +02:00
|
|
|
return sys_fs_lseek(fd, offset, whence, pos);
|
2015-03-12 20:02:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsFsync(u32 fd)
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.todo("cellFsFsync(fd=0x%x)", fd);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-26 22:46:04 +02:00
|
|
|
s32 cellFsFGetBlockSize(u32 fd, vm::ptr<u64> sector_size, vm::ptr<u64> block_size)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.trace("cellFsFGetBlockSize(fd=0x%x, sector_size=*0x%x, block_size=*0x%x)", fd, sector_size, block_size);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
if (!sector_size || !block_size)
|
|
|
|
|
{
|
|
|
|
|
return CELL_EFAULT;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-12 20:02:02 +01:00
|
|
|
// call the syscall
|
2016-06-02 17:16:01 +02:00
|
|
|
return sys_fs_fget_block_size(fd, sector_size, block_size, vm::var<u64>{}, vm::var<u64>{});
|
2015-03-12 20:02:02 +01:00
|
|
|
}
|
|
|
|
|
|
2015-09-26 22:46:04 +02:00
|
|
|
s32 cellFsGetBlockSize(vm::cptr<char> path, vm::ptr<u64> sector_size, vm::ptr<u64> block_size)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.warning("cellFsGetBlockSize(path=%s, sector_size=*0x%x, block_size=*0x%x) -> sys_fs_get_block_size()", path, sector_size, block_size);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
// call the syscall
|
2015-09-26 22:46:04 +02:00
|
|
|
return sys_fs_get_block_size(path, sector_size, block_size, vm::var<u64>{});
|
2015-03-12 20:02:02 +01:00
|
|
|
}
|
|
|
|
|
|
2015-06-22 00:27:58 +02:00
|
|
|
s32 cellFsTruncate(vm::cptr<char> path, u64 size)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.warning("cellFsTruncate(path=%s, size=0x%llx) -> sys_fs_truncate()", path, size);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
// call the syscall
|
|
|
|
|
return sys_fs_truncate(path, size);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsFtruncate(u32 fd, u64 size)
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.trace("cellFsFtruncate(fd=0x%x, size=0x%llx)", fd, size);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// call the syscall
|
|
|
|
|
return sys_fs_ftruncate(fd, size);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 00:27:58 +02:00
|
|
|
s32 cellFsChmod(vm::cptr<char> path, s32 mode)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.warning("cellFsChmod(path=%s, mode=%#o) -> sys_fs_chmod()", path, mode);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
|
|
|
|
|
|
// call the syscall
|
|
|
|
|
return sys_fs_chmod(path, mode);
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 00:27:58 +02:00
|
|
|
s32 cellFsGetFreeSize(vm::cptr<char> path, vm::ptr<u32> block_size, vm::ptr<u64> block_count)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.warning("cellFsGetFreeSize(path=%s, block_size=*0x%x, block_count=*0x%x)", path, block_size, block_count);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// 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)
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.warning("cellFsGetDirectoryEntries(fd=%d, entries=*0x%x, entries_size=0x%x, data_count=*0x%x)", fd, entries, entries_size, data_count);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto directory = idm::get<lv2_fs_object, lv2_dir>(fd);
|
2015-03-16 17:20:02 +01:00
|
|
|
|
2015-04-12 22:16:30 +02:00
|
|
|
if (!directory)
|
2015-03-16 17:20:02 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EBADF;
|
2015-03-16 17:20:02 +01:00
|
|
|
}
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2015-04-19 21:25:04 +02:00
|
|
|
u32 count = 0;
|
|
|
|
|
|
|
|
|
|
entries_size /= sizeof(CellFsDirectoryEntry);
|
|
|
|
|
|
|
|
|
|
for (; count < entries_size; count++)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-03-21 20:43:03 +01:00
|
|
|
fs::dir_entry info;
|
|
|
|
|
|
|
|
|
|
if (directory->dir.read(info))
|
2015-04-19 21:25:04 +02:00
|
|
|
{
|
2016-03-21 20:43:03 +01:00
|
|
|
entries[count].attribute.mode = info.is_directory ? CELL_FS_S_IFDIR | 0777 : CELL_FS_S_IFREG | 0666;
|
2015-04-19 21:25:04 +02:00
|
|
|
entries[count].attribute.uid = 1; // ???
|
|
|
|
|
entries[count].attribute.gid = 1; // ???
|
2016-03-21 20:43:03 +01:00
|
|
|
entries[count].attribute.atime = info.atime;
|
|
|
|
|
entries[count].attribute.mtime = info.mtime;
|
|
|
|
|
entries[count].attribute.ctime = info.ctime;
|
|
|
|
|
entries[count].attribute.size = info.size;
|
2015-04-21 20:18:15 +02:00
|
|
|
entries[count].attribute.blksize = 4096; // ???
|
2015-04-19 21:25:04 +02:00
|
|
|
|
2016-03-21 20:43:03 +01:00
|
|
|
entries[count].entry_name.d_type = info.is_directory ? CELL_FS_TYPE_DIRECTORY : CELL_FS_TYPE_REGULAR;
|
|
|
|
|
entries[count].entry_name.d_namlen = u8(std::min<size_t>(info.name.size(), CELL_FS_MAX_FS_FILE_NAME_LENGTH));
|
|
|
|
|
strcpy_trunc(entries[count].entry_name.d_name, info.name);
|
2015-04-19 21:25:04 +02:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
break;
|
|
|
|
|
}
|
2015-03-12 20:02:02 +01:00
|
|
|
}
|
|
|
|
|
|
2015-04-19 21:25:04 +02:00
|
|
|
*data_count = count;
|
|
|
|
|
|
2015-03-12 20:02:02 +01:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-08-16 17:46:24 +02:00
|
|
|
error_code cellFsReadWithOffset(u32 fd, u64 offset, vm::ptr<void> buf, u64 buffer_size, vm::ptr<u64> nread)
|
2015-03-13 23:05:48 +01:00
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.trace("cellFsReadWithOffset(fd=%d, offset=0x%llx, buf=*0x%x, buffer_size=0x%llx, nread=*0x%x)", fd, offset, buf, buffer_size, nread);
|
2015-03-13 23:05:48 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
if (fd - 3 > 252)
|
2015-03-13 23:05:48 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
if (nread) *nread = 0;
|
|
|
|
|
return CELL_EBADF;
|
2015-03-13 23:05:48 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
vm::var<lv2_file_op_rw> arg;
|
2015-03-13 23:05:48 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
arg->_vtable = vm::cast(0xfa8a0000); // Intentionally wrong (provide correct vtable if necessary)
|
|
|
|
|
|
|
|
|
|
arg->op = 0x8000000a;
|
|
|
|
|
arg->fd = fd;
|
|
|
|
|
arg->buf = buf;
|
|
|
|
|
arg->offset = offset;
|
|
|
|
|
arg->size = buffer_size;
|
2015-03-13 23:05:48 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// Call the syscall
|
|
|
|
|
const s32 rc = sys_fs_fcntl(fd, 0x8000000a, arg, arg.size());
|
2015-03-13 23:05:48 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// Write size read
|
|
|
|
|
if (nread) *nread = rc && rc != CELL_EFSSPECIFIC ? 0 : arg->out_size.value();
|
2015-03-13 23:05:48 +01:00
|
|
|
|
2016-08-15 17:30:33 +02:00
|
|
|
return not_an_error(rc ? rc : arg->out_code.value());
|
2015-03-13 23:05:48 +01:00
|
|
|
}
|
|
|
|
|
|
2016-08-16 17:46:24 +02:00
|
|
|
error_code cellFsWriteWithOffset(u32 fd, u64 offset, vm::cptr<void> buf, u64 data_size, vm::ptr<u64> nwrite)
|
2015-03-13 23:05:48 +01:00
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.trace("cellFsWriteWithOffset(fd=%d, offset=0x%llx, buf=*0x%x, data_size=0x%llx, nwrite=*0x%x)", fd, offset, buf, data_size, nwrite);
|
2015-03-13 23:05:48 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
if (!buf)
|
2015-03-13 23:05:48 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
if (nwrite) *nwrite = 0;
|
|
|
|
|
return CELL_EFAULT;
|
2015-03-13 23:05:48 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
if (fd - 3 > 252)
|
|
|
|
|
{
|
|
|
|
|
if (nwrite) *nwrite = 0;
|
|
|
|
|
return CELL_EBADF;
|
|
|
|
|
}
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
vm::var<lv2_file_op_rw> arg;
|
2015-03-13 23:05:48 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
arg->_vtable = vm::cast(0xfa8b0000); // Intentionally wrong (provide correct vtable if necessary)
|
|
|
|
|
|
|
|
|
|
arg->op = 0x8000000b;
|
|
|
|
|
arg->fd = fd;
|
|
|
|
|
arg->buf = vm::const_ptr_cast<void>(buf);
|
|
|
|
|
arg->offset = offset;
|
|
|
|
|
arg->size = data_size;
|
2015-03-13 23:05:48 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// Call the syscall
|
|
|
|
|
const s32 rc = sys_fs_fcntl(fd, 0x8000000b, arg, arg.size());
|
2015-03-13 23:05:48 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// Write size written
|
|
|
|
|
if (nwrite) *nwrite = rc && rc != CELL_EFSSPECIFIC ? 0 : arg->out_size.value();
|
2015-03-13 23:05:48 +01:00
|
|
|
|
2016-08-15 17:30:33 +02:00
|
|
|
return not_an_error(rc ? rc : arg->out_code.value());
|
2015-03-13 23:05:48 +01:00
|
|
|
}
|
|
|
|
|
|
2015-06-22 00:27:58 +02:00
|
|
|
s32 cellFsStReadInit(u32 fd, vm::cptr<CellFsRingBuffer> ringbuf)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
cellFs.todo("cellFsStReadInit(fd=%d, ringbuf=*0x%x)", fd, ringbuf);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2015-06-24 18:25:37 +02:00
|
|
|
if (ringbuf->copy & ~CELL_FS_ST_COPYLESS)
|
2015-03-16 01:21:40 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EINVAL;
|
2015-03-16 01:21:40 +01:00
|
|
|
}
|
|
|
|
|
|
2015-06-24 13:53:47 +02:00
|
|
|
if (ringbuf->block_size & 0xfff) // check if a multiple of sector size
|
2015-03-16 01:21:40 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EINVAL;
|
2015-03-16 01:21:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (ringbuf->ringbuf_size % ringbuf->block_size) // check if a multiple of block_size
|
|
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EINVAL;
|
2015-03-16 01:21:40 +01:00
|
|
|
}
|
|
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2015-04-12 22:16:30 +02:00
|
|
|
if (!file)
|
2015-03-16 01:21:40 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EBADF;
|
2015-03-16 01:21:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (file->flags & CELL_FS_O_WRONLY)
|
|
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EPERM;
|
2015-03-16 01:21:40 +01:00
|
|
|
}
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// TODO
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsStReadFinish(u32 fd)
|
|
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
cellFs.todo("cellFsStReadFinish(fd=%d)", fd);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2015-04-12 22:16:30 +02:00
|
|
|
if (!file)
|
2015-03-16 01:21:40 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EBADF; // ???
|
2015-03-16 01:21:40 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// TODO
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsStReadGetRingBuf(u32 fd, vm::ptr<CellFsRingBuffer> ringbuf)
|
|
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
cellFs.todo("cellFsStReadGetRingBuf(fd=%d, ringbuf=*0x%x)", fd, ringbuf);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2015-04-12 22:16:30 +02:00
|
|
|
if (!file)
|
2015-03-16 01:21:40 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EBADF;
|
2015-03-16 01:21:40 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// TODO
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsStReadGetStatus(u32 fd, vm::ptr<u64> status)
|
|
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
cellFs.todo("cellFsStReadGetRingBuf(fd=%d, status=*0x%x)", fd, status);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2015-04-12 22:16:30 +02:00
|
|
|
if (!file)
|
2015-03-16 01:21:40 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EBADF;
|
2015-03-16 01:21:40 +01:00
|
|
|
}
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// TODO
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsStReadGetRegid(u32 fd, vm::ptr<u64> regid)
|
|
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
cellFs.todo("cellFsStReadGetRingBuf(fd=%d, regid=*0x%x)", fd, regid);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2015-04-12 22:16:30 +02:00
|
|
|
if (!file)
|
2015-03-16 01:21:40 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EBADF;
|
2015-03-16 01:21:40 +01:00
|
|
|
}
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// TODO
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsStReadStart(u32 fd, u64 offset, u64 size)
|
|
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
cellFs.todo("cellFsStReadStart(fd=%d, offset=0x%llx, size=0x%llx)", fd, offset, size);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2015-04-12 22:16:30 +02:00
|
|
|
if (!file)
|
2015-03-16 01:21:40 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EBADF;
|
2015-03-16 01:21:40 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// TODO
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsStReadStop(u32 fd)
|
|
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
cellFs.todo("cellFsStReadStop(fd=%d)", fd);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2015-04-12 22:16:30 +02:00
|
|
|
if (!file)
|
2015-03-16 01:21:40 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EBADF;
|
2015-03-16 01:21:40 +01:00
|
|
|
}
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// TODO
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsStRead(u32 fd, vm::ptr<u8> buf, u64 size, vm::ptr<u64> rsize)
|
|
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
cellFs.todo("cellFsStRead(fd=%d, buf=*0x%x, size=0x%llx, rsize=*0x%x)", fd, buf, size, rsize);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2015-04-12 22:16:30 +02:00
|
|
|
if (!file)
|
2015-03-16 01:21:40 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EBADF;
|
2015-03-16 01:21:40 +01:00
|
|
|
}
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// TODO
|
2015-03-16 14:15:52 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_OK;
|
2015-03-12 20:02:02 +01:00
|
|
|
}
|
|
|
|
|
|
2015-03-16 14:15:52 +01:00
|
|
|
s32 cellFsStReadGetCurrentAddr(u32 fd, vm::ptr<u32> addr, vm::ptr<u64> size)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
cellFs.todo("cellFsStReadGetCurrentAddr(fd=%d, addr=*0x%x, size=*0x%x)", fd, addr, size);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2015-04-12 22:16:30 +02:00
|
|
|
if (!file)
|
2015-03-16 01:21:40 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EBADF;
|
2015-03-16 14:15:52 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// TODO
|
2015-03-16 14:15:52 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_OK;
|
2015-03-12 20:02:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsStReadPutCurrentAddr(u32 fd, vm::ptr<u8> addr, u64 size)
|
|
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
cellFs.todo("cellFsStReadPutCurrentAddr(fd=%d, addr=*0x%x, size=0x%llx)", fd, addr, size);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2015-04-12 22:16:30 +02:00
|
|
|
if (!file)
|
2015-03-16 01:21:40 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EBADF;
|
2015-03-16 14:15:52 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// TODO
|
2015-03-16 14:15:52 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_OK;
|
2015-03-12 20:02:02 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsStReadWait(u32 fd, u64 size)
|
|
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
cellFs.todo("cellFsStReadWait(fd=%d, size=0x%llx)", fd, size);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2015-04-12 22:16:30 +02:00
|
|
|
if (!file)
|
2015-03-16 01:21:40 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EBADF;
|
2015-03-16 14:15:52 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// TODO
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
s32 cellFsStReadWaitCallback(u32 fd, u64 size, vm::ptr<void(s32 xfd, u64 xsize)> func)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
cellFs.todo("cellFsStReadWaitCallback(fd=%d, size=0x%llx, func=*0x%x)", fd, size, func);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2015-04-12 22:16:30 +02:00
|
|
|
if (!file)
|
2015-03-16 01:21:40 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EBADF;
|
2015-03-16 14:15:52 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// TODO
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
2015-07-09 17:30:37 +02:00
|
|
|
s32 sdata_unpack(const std::string& packed_file, const std::string& unpacked_file)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-03-21 20:43:03 +01:00
|
|
|
fs::file packed_stream(vfs::get(packed_file));
|
|
|
|
|
fs::file unpacked_stream(vfs::get(unpacked_file), fs::rewrite);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-03-21 20:43:03 +01:00
|
|
|
if (!packed_stream)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-03-21 20:43:03 +01:00
|
|
|
cellFs.error("File '%s' not found!", packed_file);
|
2015-03-12 20:02:02 +01:00
|
|
|
return CELL_ENOENT;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-21 20:43:03 +01:00
|
|
|
if (!unpacked_stream)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-03-21 20:43:03 +01:00
|
|
|
cellFs.error("File '%s' couldn't be created!", unpacked_file);
|
2015-03-12 20:02:02 +01:00
|
|
|
return CELL_ENOENT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
char buffer[10200];
|
2016-03-21 20:43:03 +01:00
|
|
|
packed_stream.read(buffer, 256);
|
2015-06-24 18:25:37 +02:00
|
|
|
u32 format = *(be_t<u32>*)&buffer[0];
|
2015-03-12 20:02:02 +01:00
|
|
|
if (format != 0x4E504400) // "NPD\x00"
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.error("Illegal format. Expected 0x4E504400, but got 0x%08x", format);
|
2015-03-12 20:02:02 +01:00
|
|
|
return CELL_EFSSPECIFIC;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-24 18:25:37 +02:00
|
|
|
u32 version = *(be_t<u32>*)&buffer[0x04];
|
|
|
|
|
u32 flags = *(be_t<u32>*)&buffer[0x80];
|
|
|
|
|
u32 blockSize = *(be_t<u32>*)&buffer[0x84];
|
|
|
|
|
u64 filesizeOutput = *(be_t<u64>*)&buffer[0x88];
|
2016-03-21 20:43:03 +01:00
|
|
|
u64 filesizeInput = packed_stream.size();
|
2015-03-12 20:02:02 +01:00
|
|
|
u32 blockCount = (u32)((filesizeOutput + blockSize - 1) / blockSize);
|
|
|
|
|
|
|
|
|
|
// SDATA file is compressed
|
|
|
|
|
if (flags & 0x1)
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.warning("cellFsSdataOpen: Compressed SDATA files are not supported yet.");
|
2015-03-12 20:02:02 +01:00
|
|
|
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))
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.error("cellFsSdataOpen: Wrong header information.");
|
2015-03-12 20:02:02 +01:00
|
|
|
return CELL_EFSSPECIFIC;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (flags & 0x20)
|
2015-11-08 12:42:41 +01:00
|
|
|
{
|
2016-04-25 12:49:12 +02:00
|
|
|
packed_stream.seek(0x100);
|
2015-11-08 12:42:41 +01:00
|
|
|
}
|
2015-03-12 20:02:02 +01:00
|
|
|
else
|
2015-11-08 12:42:41 +01:00
|
|
|
{
|
2016-04-25 12:49:12 +02:00
|
|
|
packed_stream.seek(startOffset);
|
2015-11-08 12:42:41 +01:00
|
|
|
}
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
for (u32 i = 0; i < blockCount; i++)
|
|
|
|
|
{
|
|
|
|
|
if (flags & 0x20)
|
2015-11-08 12:42:41 +01:00
|
|
|
{
|
2016-03-21 20:43:03 +01:00
|
|
|
packed_stream.seek(t1, fs::seek_cur);
|
2015-11-08 12:42:41 +01:00
|
|
|
}
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
if (!(blockCount - i - 1))
|
2015-11-08 12:42:41 +01:00
|
|
|
{
|
2015-03-12 20:02:02 +01:00
|
|
|
blockSize = (u32)(filesizeOutput - i * blockSize);
|
2015-11-08 12:42:41 +01:00
|
|
|
}
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-03-21 20:43:03 +01:00
|
|
|
packed_stream.read(buffer + 256, blockSize);
|
|
|
|
|
unpacked_stream.write(buffer + 256, blockSize);
|
2015-03-12 20:02:02 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2015-09-26 22:46:04 +02:00
|
|
|
s32 cellFsSdataOpen(vm::cptr<char> path, s32 flags, vm::ptr<u32> fd, vm::cptr<void> arg, u64 size)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.notice("cellFsSdataOpen(path=%s, flags=%#o, fd=*0x%x, arg=*0x%x, size=0x%llx)", path, flags, fd, arg, size);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2015-03-13 16:06:27 +01:00
|
|
|
if (flags != CELL_FS_O_RDONLY)
|
|
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EINVAL;
|
2015-03-13 16:06:27 +01:00
|
|
|
}
|
|
|
|
|
|
2015-09-26 22:46:04 +02:00
|
|
|
return cellFsOpen(path, CELL_FS_O_RDONLY, fd, vm::make_var<be_t<u32>[2]>({ 0x180, 0x10 }), 8);
|
2015-03-13 16:06:27 +01:00
|
|
|
|
|
|
|
|
// Don't implement sdata decryption in this function, it should be done in sys_fs_open() syscall or somewhere else
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2015-03-13 16:06:27 +01:00
|
|
|
/*
|
2015-03-12 20:02:02 +01:00
|
|
|
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";
|
2015-07-09 17:30:37 +02:00
|
|
|
s32 ret = sdata_unpack(path, unpacked_path);
|
2015-03-12 20:02:02 +01:00
|
|
|
if (ret) return ret;
|
|
|
|
|
|
2015-08-05 17:30:32 +02:00
|
|
|
fd = idm::GetNewID(Emu.GetVFS().OpenFile(unpacked_path, vfsRead), TYPE_FS_FILE);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2015-03-13 16:06:27 +01:00
|
|
|
return CELL_OK;
|
|
|
|
|
*/
|
2015-03-12 20:02:02 +01:00
|
|
|
}
|
|
|
|
|
|
2015-06-22 00:27:58 +02:00
|
|
|
s32 cellFsSdataOpenByFd(u32 mself_fd, s32 flags, vm::ptr<u32> sdata_fd, u64 offset, vm::cptr<void> arg, u64 size)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.todo("cellFsSdataOpenByFd(mself_fd=0x%x, flags=%#o, sdata_fd=*0x%x, offset=0x%llx, arg=*0x%x, size=0x%llx)", mself_fd, flags, sdata_fd, offset, arg, size);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
// TODO:
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 12:29:26 +01:00
|
|
|
using fs_aio_cb_t = vm::ptr<void(vm::ptr<CellFsAio> xaio, s32 error, s32 xid, u64 size)>;
|
|
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// temporarily
|
|
|
|
|
struct lv2_fs_mount_point
|
|
|
|
|
{
|
|
|
|
|
std::mutex mutex;
|
|
|
|
|
};
|
|
|
|
|
|
2016-07-27 23:43:22 +02:00
|
|
|
struct fs_aio_thread : ppu_thread
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-07-27 23:43:22 +02:00
|
|
|
using ppu_thread::ppu_thread;
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-07-27 23:43:22 +02:00
|
|
|
virtual void cpu_task() override
|
|
|
|
|
{
|
2016-08-09 16:14:41 +02:00
|
|
|
while (cmd64 cmd = cmd_wait())
|
2016-07-27 23:43:22 +02:00
|
|
|
{
|
|
|
|
|
const u32 type = cmd.arg1<u32>();
|
|
|
|
|
const s32 xid = cmd.arg2<s32>();
|
2016-08-09 16:14:41 +02:00
|
|
|
const cmd64 cmd2 = cmd_get(1);
|
2016-07-27 23:43:22 +02:00
|
|
|
const auto aio = cmd2.arg1<vm::ptr<CellFsAio>>();
|
|
|
|
|
const auto func = cmd2.arg2<fs_aio_cb_t>();
|
|
|
|
|
cmd_pop(1);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-07-27 23:43:22 +02:00
|
|
|
s32 error = CELL_OK;
|
|
|
|
|
u64 result = 0;
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto file = idm::get<lv2_fs_object, lv2_file>(aio->fd);
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2016-07-27 23:43:22 +02:00
|
|
|
if (!file || (type == 1 && file->flags & CELL_FS_O_WRONLY) || (type == 2 && !(file->flags & CELL_FS_O_ACCMODE)))
|
|
|
|
|
{
|
|
|
|
|
error = CELL_EBADF;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
std::lock_guard<std::mutex> lock(file->mp->mutex);
|
|
|
|
|
|
|
|
|
|
const auto old_pos = file->file.pos(); file->file.seek(aio->offset);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-07-27 23:43:22 +02:00
|
|
|
result = type == 2
|
|
|
|
|
? file->op_write(aio->buf, aio->size)
|
|
|
|
|
: file->op_read(aio->buf, aio->size);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2016-07-27 23:43:22 +02:00
|
|
|
file->file.seek(old_pos);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func(*this, aio, error, xid, result);
|
|
|
|
|
}
|
2015-03-14 12:29:26 +01:00
|
|
|
}
|
2016-07-27 23:43:22 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct fs_aio_manager
|
|
|
|
|
{
|
2016-08-01 01:26:55 +02:00
|
|
|
std::shared_ptr<fs_aio_thread> thread;
|
2016-07-27 23:43:22 +02:00
|
|
|
};
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2015-06-22 00:27:58 +02:00
|
|
|
s32 cellFsAioInit(vm::cptr<char> mount_point)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.warning("cellFsAioInit(mount_point=%s)", mount_point);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2015-03-14 12:29:26 +01:00
|
|
|
// TODO: create AIO thread (if not exists) for specified mount point
|
2017-01-26 02:03:03 +01:00
|
|
|
const auto m = fxm::make<fs_aio_manager>();
|
|
|
|
|
|
|
|
|
|
if (m)
|
|
|
|
|
{
|
|
|
|
|
m->thread = idm::make_ptr<ppu_thread, fs_aio_thread>("FS AIO Thread", 500);
|
|
|
|
|
m->thread->run();
|
|
|
|
|
}
|
2015-03-14 12:29:26 +01:00
|
|
|
|
2015-03-12 20:02:02 +01:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-22 00:27:58 +02:00
|
|
|
s32 cellFsAioFinish(vm::cptr<char> mount_point)
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.warning("cellFsAioFinish(mount_point=%s)", mount_point);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2015-03-14 12:29:26 +01:00
|
|
|
// TODO: delete existing AIO thread for specified mount point
|
|
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2016-03-21 20:43:03 +01:00
|
|
|
atomic_t<s32> g_fs_aio_id;
|
2015-03-14 12:29:26 +01:00
|
|
|
|
|
|
|
|
s32 cellFsAioRead(vm::ptr<CellFsAio> aio, vm::ptr<s32> id, fs_aio_cb_t func)
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.warning("cellFsAioRead(aio=*0x%x, id=*0x%x, func=*0x%x)", aio, id, func);
|
2015-03-14 12:29:26 +01:00
|
|
|
|
|
|
|
|
// TODO: detect mount point and send AIO request to the AIO thread of this mount point
|
|
|
|
|
|
2017-01-26 02:03:03 +01:00
|
|
|
const auto m = fxm::get<fs_aio_manager>();
|
|
|
|
|
|
|
|
|
|
if (!m)
|
|
|
|
|
{
|
|
|
|
|
return CELL_ENXIO;
|
|
|
|
|
}
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2017-01-26 02:03:03 +01:00
|
|
|
const s32 xid = (*id = ++g_fs_aio_id);
|
2016-07-27 23:43:22 +02:00
|
|
|
|
2016-08-01 01:26:55 +02:00
|
|
|
m->thread->cmd_list
|
2016-07-27 23:43:22 +02:00
|
|
|
({
|
|
|
|
|
{ 1, xid },
|
|
|
|
|
{ aio, func },
|
|
|
|
|
});
|
|
|
|
|
|
2016-08-01 01:26:55 +02:00
|
|
|
m->thread->lock_notify();
|
2015-03-14 12:29:26 +01:00
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsAioWrite(vm::ptr<CellFsAio> aio, vm::ptr<s32> id, fs_aio_cb_t func)
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.warning("cellFsAioWrite(aio=*0x%x, id=*0x%x, func=*0x%x)", aio, id, func);
|
2015-03-14 12:29:26 +01:00
|
|
|
|
|
|
|
|
// TODO: detect mount point and send AIO request to the AIO thread of this mount point
|
|
|
|
|
|
2017-01-26 02:03:03 +01:00
|
|
|
const auto m = fxm::get<fs_aio_manager>();
|
2015-03-16 01:21:40 +01:00
|
|
|
|
2017-01-26 02:03:03 +01:00
|
|
|
if (!m)
|
|
|
|
|
{
|
|
|
|
|
return CELL_ENXIO;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const s32 xid = (*id = ++g_fs_aio_id);
|
2016-07-27 23:43:22 +02:00
|
|
|
|
2016-08-01 01:26:55 +02:00
|
|
|
m->thread->cmd_list
|
2016-07-27 23:43:22 +02:00
|
|
|
({
|
|
|
|
|
{ 2, xid },
|
|
|
|
|
{ aio, func },
|
|
|
|
|
});
|
|
|
|
|
|
2016-08-01 01:26:55 +02:00
|
|
|
m->thread->lock_notify();
|
2015-03-14 12:29:26 +01:00
|
|
|
|
2015-03-12 20:02:02 +01:00
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2015-03-14 12:29:26 +01:00
|
|
|
s32 cellFsAioCancel(s32 id)
|
|
|
|
|
{
|
2016-07-27 23:43:22 +02:00
|
|
|
cellFs.todo("cellFsAioCancel(id=%d) -> CELL_EINVAL", id);
|
2015-03-14 12:29:26 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
// TODO: cancelled requests return CELL_ECANCELED through their own callbacks
|
2015-03-14 12:29:26 +01:00
|
|
|
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EINVAL;
|
2015-03-14 12:29:26 +01:00
|
|
|
}
|
|
|
|
|
|
2015-03-12 20:02:02 +01:00
|
|
|
s32 cellFsSetDefaultContainer(u32 id, u32 total_limit)
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.todo("cellFsSetDefaultContainer(id=0x%x, total_limit=%d)", id, total_limit);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsSetIoBufferFromDefaultContainer(u32 fd, u32 buffer_size, u32 page_type)
|
|
|
|
|
{
|
2016-01-12 22:57:16 +01:00
|
|
|
cellFs.todo("cellFsSetIoBufferFromDefaultContainer(fd=%d, buffer_size=%d, page_type=%d)", fd, buffer_size, page_type);
|
2015-03-12 20:02:02 +01:00
|
|
|
|
2017-01-26 02:12:50 +01:00
|
|
|
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
|
2015-03-16 17:20:02 +01:00
|
|
|
|
2015-04-12 22:16:30 +02:00
|
|
|
if (!file)
|
2015-03-16 17:20:02 +01:00
|
|
|
{
|
2016-06-02 17:16:01 +02:00
|
|
|
return CELL_EBADF;
|
2015-03-16 17:20:02 +01:00
|
|
|
}
|
2015-03-12 20:02:02 +01:00
|
|
|
|
|
|
|
|
return CELL_OK;
|
|
|
|
|
}
|
|
|
|
|
|
2015-08-03 00:00:00 +02:00
|
|
|
s32 cellFsUtime()
|
|
|
|
|
{
|
2016-08-08 18:01:06 +02:00
|
|
|
fmt::throw_exception("Unimplemented" HERE);
|
2015-08-03 00:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsArcadeHddSerialNumber()
|
|
|
|
|
{
|
2016-08-08 18:01:06 +02:00
|
|
|
fmt::throw_exception("Unimplemented" HERE);
|
2015-08-03 00:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsAllocateFileAreaWithInitialData()
|
|
|
|
|
{
|
2016-08-08 18:01:06 +02:00
|
|
|
fmt::throw_exception("Unimplemented" HERE);
|
2015-08-03 00:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsAllocateFileAreaByFdWithoutZeroFill()
|
|
|
|
|
{
|
2016-08-08 18:01:06 +02:00
|
|
|
fmt::throw_exception("Unimplemented" HERE);
|
2015-08-03 00:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsSetIoBuffer()
|
|
|
|
|
{
|
2016-08-08 18:01:06 +02:00
|
|
|
fmt::throw_exception("Unimplemented" HERE);
|
2015-08-03 00:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsAllocateFileAreaByFdWithInitialData()
|
|
|
|
|
{
|
2016-08-08 18:01:06 +02:00
|
|
|
fmt::throw_exception("Unimplemented" HERE);
|
2015-08-03 00:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsTruncate2()
|
|
|
|
|
{
|
2016-08-08 18:01:06 +02:00
|
|
|
fmt::throw_exception("Unimplemented" HERE);
|
2015-08-03 00:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsChangeFileSizeWithoutAllocation()
|
|
|
|
|
{
|
2016-08-08 18:01:06 +02:00
|
|
|
fmt::throw_exception("Unimplemented" HERE);
|
2015-08-03 00:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
2016-04-09 11:45:45 +02:00
|
|
|
s32 cellFsAllocateFileAreaWithoutZeroFill(vm::cptr<char> path, u64 size)
|
2015-08-03 00:00:00 +02:00
|
|
|
{
|
2016-08-11 01:29:59 +02:00
|
|
|
cellFs.warning("cellFsAllocateFileAreaWithoutZeroFill(path=%s, size=0x%llx)", path, size);
|
2016-06-02 17:16:01 +02:00
|
|
|
|
2016-04-09 11:45:45 +02:00
|
|
|
return sys_fs_truncate(path, size);
|
2015-08-03 00:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsChangeFileSizeByFdWithoutAllocation()
|
|
|
|
|
{
|
2016-08-08 18:01:06 +02:00
|
|
|
fmt::throw_exception("Unimplemented" HERE);
|
2015-08-03 00:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsSetDiscReadRetrySetting()
|
|
|
|
|
{
|
2016-08-08 18:01:06 +02:00
|
|
|
fmt::throw_exception("Unimplemented" HERE);
|
2015-08-03 00:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsRegisterConversionCallback()
|
|
|
|
|
{
|
2016-08-08 18:01:06 +02:00
|
|
|
fmt::throw_exception("Unimplemented" HERE);
|
2015-08-03 00:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
s32 cellFsUnregisterL10nCallbacks()
|
|
|
|
|
{
|
2016-08-08 18:01:06 +02:00
|
|
|
fmt::throw_exception("Unimplemented" HERE);
|
2015-08-03 00:00:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2016-03-21 20:43:03 +01:00
|
|
|
DECLARE(ppu_module_manager::cellFs)("sys_fs", []()
|
2015-03-12 20:02:02 +01:00
|
|
|
{
|
2016-03-21 20:43:03 +01:00
|
|
|
REG_FUNC(sys_fs, cellFsOpen);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsSdataOpen);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsSdataOpenByFd);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsRead, MFF_PERFECT);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsWrite, MFF_PERFECT);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsClose, MFF_PERFECT);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsOpendir);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsReaddir, MFF_PERFECT);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsClosedir, MFF_PERFECT);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsStat);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsFstat, MFF_PERFECT);
|
|
|
|
|
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, MFF_PERFECT);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsFtruncate, MFF_PERFECT);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsTruncate);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsFGetBlockSize, MFF_PERFECT);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsAioInit);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsAioFinish);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsAioRead);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsAioWrite);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsAioCancel);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsGetBlockSize);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsGetFreeSize);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsReadWithOffset);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsWriteWithOffset);
|
|
|
|
|
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);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsUtime);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsArcadeHddSerialNumber);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsAllocateFileAreaWithInitialData);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsAllocateFileAreaByFdWithoutZeroFill);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsSetIoBuffer);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsAllocateFileAreaByFdWithInitialData);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsTruncate2);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsChangeFileSizeWithoutAllocation);
|
2016-06-02 17:16:01 +02:00
|
|
|
REG_FUNC(sys_fs, cellFsAllocateFileAreaWithoutZeroFill, MFF_FORCED_HLE);
|
2016-03-21 20:43:03 +01:00
|
|
|
REG_FUNC(sys_fs, cellFsChangeFileSizeByFdWithoutAllocation);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsSetDiscReadRetrySetting);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsRegisterConversionCallback);
|
|
|
|
|
REG_FUNC(sys_fs, cellFsUnregisterL10nCallbacks);
|
2015-03-12 20:02:02 +01:00
|
|
|
});
|