sys_fs_lsn_lock implemented

This commit is contained in:
Nekotekina 2017-04-24 23:30:15 +03:00
parent 1bbb76fa20
commit a95a63a58a
3 changed files with 70 additions and 8 deletions

View File

@ -746,8 +746,8 @@ std::array<ppu_function_t, 1024> g_ppu_syscall_table
null_func,//BIND_FUNC(sys_fs_acl_write), //824 (0x338)
null_func,//BIND_FUNC(sys_fs_lsn_get_cda_size), //825 (0x339)
null_func,//BIND_FUNC(sys_fs_lsn_get_cda), //826 (0x33A)
null_func,//BIND_FUNC(sys_fs_lsn_lock), //827 (0x33B)
null_func,//BIND_FUNC(sys_fs_lsn_unlock), //828 (0x33C)
BIND_FUNC(sys_fs_lsn_lock), //827 (0x33B)
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(sys_fs_truncate), //831 (0x33F)

View File

@ -377,10 +377,13 @@ error_code sys_fs_write(u32 fd, vm::cptr<void> buf, u64 nbytes, vm::ptr<u64> nwr
return CELL_EBADF;
}
// TODO: return CELL_EBUSY if locked by stream
std::lock_guard<std::mutex> lock(file->mp->mutex);
if (file->lock)
{
return CELL_EBUSY;
}
*nwrite = file->op_write(buf, nbytes);
return CELL_OK;
@ -390,16 +393,25 @@ error_code sys_fs_close(u32 fd)
{
sys_fs.trace("sys_fs_close(fd=%d)", fd);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
const auto file = idm::withdraw<lv2_fs_object, lv2_file>(fd, [](lv2_file& file) -> CellError
{
if (file.lock)
{
return CELL_EBUSY;
}
return {};
});
if (!file)
{
return CELL_EBADF;
}
// TODO: return CELL_EBUSY if locked
idm::remove<lv2_fs_object, lv2_file>(fd);
if (file.ret)
{
return file.ret;
}
return CELL_OK;
}
@ -651,6 +663,11 @@ error_code sys_fs_fcntl(u32 fd, u32 op, vm::ptr<void> _arg, u32 _size)
std::lock_guard<std::mutex> lock(file->mp->mutex);
if (op == 0x8000000B && file->lock)
{
return CELL_EBUSY;
}
const u64 old_pos = file->file.pos();
const u64 new_pos = file->file.seek(arg->offset);
@ -929,3 +946,43 @@ error_code sys_fs_utime(vm::ps3::cptr<char> path, vm::ps3::cptr<CellFsUtimbuf> t
return CELL_OK;
}
error_code sys_fs_lsn_lock(u32 fd)
{
sys_fs.trace("sys_fs_lsn_lock(fd=%d)", fd);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF;
}
// TODO: research correct implementation
if (!file->lock.compare_and_swap_test(0, 1))
{
return CELL_EBUSY;
}
return CELL_OK;
}
error_code sys_fs_lsn_unlock(u32 fd)
{
sys_fs.trace("sys_fs_lsn_unlock(fd=%d)", fd);
const auto file = idm::get<lv2_fs_object, lv2_file>(fd);
if (!file)
{
return CELL_EBADF;
}
// TODO: research correct implementation
if (!file->lock.compare_and_swap_test(1, 0))
{
return CELL_EPERM;
}
return CELL_OK;
}

View File

@ -166,6 +166,9 @@ struct lv2_file final : lv2_fs_object
const s32 mode;
const s32 flags;
// Stream lock
atomic_t<u32> lock{0};
lv2_file(const char* filename, fs::file&& file, s32 mode, s32 flags)
: lv2_fs_object(lv2_fs_object::get_mp(filename), filename)
, file(std::move(file))
@ -330,3 +333,5 @@ error_code sys_fs_truncate(vm::ps3::cptr<char> path, u64 size);
error_code sys_fs_ftruncate(u32 fd, u64 size);
error_code sys_fs_chmod(vm::ps3::cptr<char> path, s32 mode);
error_code sys_fs_utime(vm::ps3::cptr<char> path, vm::ps3::cptr<CellFsUtimbuf> timep);
error_code sys_fs_lsn_lock(u32 fd);
error_code sys_fs_lsn_unlock(u32 fd);