Skip to content

Commit

Permalink
cellFsUtime implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekotekina committed Jan 26, 2017
1 parent 1705638 commit 4ecf05a
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 6 deletions.
52 changes: 52 additions & 0 deletions Utilities/File.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ static time_t to_time(const FILETIME& ft)
return to_time(v);
}

static FILETIME from_time(s64 _time)
{
const ullong wtime = (_time + 11644473600ULL) * 10000000ULL;
FILETIME result;
result.dwLowDateTime = static_cast<DWORD>(wtime);
result.dwHighDateTime = static_cast<DWORD>(wtime >> 32);
return result;
}

static fs::error to_error(DWORD e)
{
switch (e)
Expand All @@ -94,6 +103,7 @@ static fs::error to_error(DWORD e)
#include <libgen.h>
#include <string.h>
#include <unistd.h>
#include <utime.h>

#if defined(__APPLE__) || defined(__FreeBSD__)
#include <copyfile.h>
Expand Down Expand Up @@ -603,6 +613,48 @@ bool fs::truncate_file(const std::string& path, u64 length)
#endif
}

bool fs::utime(const std::string& path, s64 atime, s64 mtime)
{
if (auto device = get_virtual_device(path))
{
return device->utime(path, atime, mtime);
}

#ifdef _WIN32
// Open the file
const auto handle = CreateFileW(to_wchar(path).get(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
if (handle == INVALID_HANDLE_VALUE)
{
g_tls_error = to_error(GetLastError());
return false;
}

FILETIME _atime = from_time(atime);
FILETIME _mtime = from_time(mtime);
if (!SetFileTime(handle, nullptr, &_atime, &_mtime))
{
g_tls_error = to_error(GetLastError());
CloseHandle(handle);
return false;
}

CloseHandle(handle);
return true;
#else
::utimbuf buf;
buf.actime = atime;
buf.modtime = mtime;

if (::utime(path.c_str(), &buf) != 0)
{
g_tls_error = to_error(errno);
return false;
}

return true;
#endif
}

void fs::file::xnull() const
{
fmt::throw_exception<std::logic_error>("fs::file is null");
Expand Down
4 changes: 4 additions & 0 deletions Utilities/File.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ namespace fs
virtual bool rename(const std::string& from, const std::string& to) = 0;
virtual bool remove(const std::string& path) = 0;
virtual bool trunc(const std::string& path, u64 length) = 0;
virtual bool utime(const std::string& path, s64 atime, s64 mtime) = 0;

virtual std::unique_ptr<file_base> open(const std::string& path, bs_t<open_mode> mode) = 0;
virtual std::unique_ptr<dir_base> open_dir(const std::string& path) = 0;
Expand Down Expand Up @@ -140,6 +141,9 @@ namespace fs
// Change file size (possibly appending zeros)
bool truncate_file(const std::string& path, u64 length);

// Set file access/modification time
bool utime(const std::string& path, s64 atime, s64 mtime);

class file final
{
std::unique_ptr<file_base> m_file;
Expand Down
15 changes: 10 additions & 5 deletions rpcs3/Emu/Cell/Modules/cellFs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,16 @@ s32 cellFsChmod(vm::cptr<char> path, s32 mode)
return sys_fs_chmod(path, mode);
}

s32 cellFsUtime(vm::cptr<char> path, vm::cptr<CellFsUtimbuf> timep)
{
cellFs.warning("cellFsUtime(path=%s, timep=*0x%x) -> sys_fs_utime()", path, timep);

// TODO

// Call the syscall
return sys_fs_utime(path, timep);
}

s32 cellFsGetFreeSize(vm::cptr<char> path, vm::ptr<u32> block_size, vm::ptr<u64> block_count)
{
cellFs.warning("cellFsGetFreeSize(path=%s, block_size=*0x%x, block_count=*0x%x)", path, block_size, block_count);
Expand Down Expand Up @@ -848,11 +858,6 @@ s32 cellFsSetIoBufferFromDefaultContainer(u32 fd, u32 buffer_size, u32 page_type
return CELL_OK;
}

s32 cellFsUtime()
{
fmt::throw_exception("Unimplemented" HERE);
}

s32 cellFsArcadeHddSerialNumber()
{
fmt::throw_exception("Unimplemented" HERE);
Expand Down
2 changes: 1 addition & 1 deletion rpcs3/Emu/Cell/lv2/lv2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ std::array<ppu_function_t, 1024> g_ppu_syscall_table
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)
BIND_FUNC(sys_fs_utime), //815 (0x32F)
null_func,//BIND_FUNC(sys_fs_access), //816 (0x330)
BIND_FUNC(sys_fs_fcntl), //817 (0x331)
BIND_FUNC(sys_fs_lseek), //818 (0x332)
Expand Down
18 changes: 18 additions & 0 deletions rpcs3/Emu/Cell/lv2/sys_fs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -592,3 +592,21 @@ error_code sys_fs_chmod(vm::cptr<char> path, s32 mode)

return CELL_OK;
}

error_code sys_fs_utime(vm::ps3::cptr<char> path, vm::ps3::cptr<CellFsUtimbuf> timep)
{
sys_fs.warning("sys_fs_utime(path=%s, timep=*0x%x)", path, timep);

if (!fs::utime(vfs::get(path.get_ptr()), timep->actime, timep->modtime))
{
switch (auto error = fs::g_tls_error)
{
case fs::error::noent: return CELL_ENOENT;
default: sys_fs.error("sys_fs_utime(): unknown error %s", error);
}

return CELL_EIO; // ???
}

return CELL_OK;
}
1 change: 1 addition & 0 deletions rpcs3/Emu/Cell/lv2/sys_fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,4 @@ error_code sys_fs_get_block_size(vm::ps3::cptr<char> path, vm::ps3::ptr<u64> sec
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);

0 comments on commit 4ecf05a

Please sign in to comment.