diff --git a/Utilities/rFile.cpp b/Utilities/rFile.cpp index 39fa91eceb..88db8ad28e 100644 --- a/Utilities/rFile.cpp +++ b/Utilities/rFile.cpp @@ -125,10 +125,15 @@ bool rRename(const std::string &from, const std::string &to) { // TODO: Deal with case-sensitivity #ifdef _WIN32 - return (MoveFile(ConvertUTF8ToWString(from).c_str(), ConvertUTF8ToWString(to).c_str()) == TRUE); + if (!MoveFile(ConvertUTF8ToWString(from).c_str(), ConvertUTF8ToWString(to).c_str())) #else - return (0 == rename(from.c_str(), to.c_str())); + if (rename(from.c_str(), to.c_str())) #endif + { + LOG_ERROR(GENERAL, "Error renaming '%s' to '%s': 0x%llx", from.c_str(), to.c_str(), (u64)GET_API_ERROR); + return false; + } + return true; } bool rExists(const std::string &file) diff --git a/rpcs3/Emu/FS/VFS.cpp b/rpcs3/Emu/FS/VFS.cpp index 6af15b1f47..a44003e460 100644 --- a/rpcs3/Emu/FS/VFS.cpp +++ b/rpcs3/Emu/FS/VFS.cpp @@ -259,14 +259,18 @@ bool VFS::ExistsDir(const std::string& ps3_path) const bool VFS::RenameFile(const std::string& ps3_path_from, const std::string& ps3_path_to) const { - std::string path; - if (vfsDevice* dev = GetDevice(ps3_path_from, path)) - { - std::shared_ptr res(dev->GetNewFileStream()); + std::string path_from, path_to; - if (res) + if (vfsDevice* dev = GetDevice(ps3_path_from, path_from)) + { + if (vfsDevice* dev_ = GetDevice(ps3_path_to, path_to)) { - return res->Rename(path, ps3_path_to); + std::shared_ptr res(dev->GetNewFileStream()); + + if (res) + { + return res->Rename(path_from, path_to); + } } } @@ -275,14 +279,18 @@ bool VFS::RenameFile(const std::string& ps3_path_from, const std::string& ps3_pa bool VFS::RenameDir(const std::string& ps3_path_from, const std::string& ps3_path_to) const { - std::string path; - if (vfsDevice* dev = GetDevice(ps3_path_from, path)) - { - std::shared_ptr res(dev->GetNewDirStream()); + std::string path_from, path_to; - if (res) + if (vfsDevice* dev = GetDevice(ps3_path_from, path_from)) + { + if (vfsDevice* dev_ = GetDevice(ps3_path_to, path_to)) { - return res->Rename(path, ps3_path_to); + std::shared_ptr res(dev->GetNewDirStream()); + + if (res) + { + return res->Rename(path_from, path_to); + } } } diff --git a/rpcs3/Emu/FS/vfsLocalDir.cpp b/rpcs3/Emu/FS/vfsLocalDir.cpp index d6eb9e0e66..cad28f5a64 100644 --- a/rpcs3/Emu/FS/vfsLocalDir.cpp +++ b/rpcs3/Emu/FS/vfsLocalDir.cpp @@ -43,7 +43,7 @@ bool vfsLocalDir::Open(const std::string& path) bool vfsLocalDir::Create(const std::string& path) { - return rMkpath(path); + return rMkdir(path); } bool vfsLocalDir::IsExists(const std::string& path) const @@ -53,7 +53,7 @@ bool vfsLocalDir::IsExists(const std::string& path) const bool vfsLocalDir::Rename(const std::string& from, const std::string& to) { - return false; + return rRename(from, to); } bool vfsLocalDir::Remove(const std::string& path) diff --git a/rpcs3/Emu/FS/vfsLocalFile.cpp b/rpcs3/Emu/FS/vfsLocalFile.cpp index f33639bd1d..1542a49be5 100644 --- a/rpcs3/Emu/FS/vfsLocalFile.cpp +++ b/rpcs3/Emu/FS/vfsLocalFile.cpp @@ -124,4 +124,14 @@ bool vfsLocalFile::IsOpened() const bool vfsLocalFile::Exists(const std::string& path) { return rExists(path); -} \ No newline at end of file +} + +bool vfsLocalFile::Rename(const std::string& from, const std::string& to) +{ + return rRename(from, to); +} + +bool vfsLocalFile::Remove(const std::string& path) +{ + return rRemoveFile(path); +} diff --git a/rpcs3/Emu/FS/vfsLocalFile.h b/rpcs3/Emu/FS/vfsLocalFile.h index efef6328d5..42eb7a90bc 100644 --- a/rpcs3/Emu/FS/vfsLocalFile.h +++ b/rpcs3/Emu/FS/vfsLocalFile.h @@ -14,6 +14,8 @@ public: virtual bool Create(const std::string& path, bool overwrite = false) override; virtual bool Close() override; virtual bool Exists(const std::string& path) override; + virtual bool Rename(const std::string& from, const std::string& to) override; + virtual bool Remove(const std::string& path) override; virtual u64 GetSize() override; diff --git a/rpcs3/Emu/SysCalls/Modules/cellFs.cpp b/rpcs3/Emu/SysCalls/Modules/cellFs.cpp index 6f4a07d3b0..d24a129d62 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellFs.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellFs.cpp @@ -64,7 +64,7 @@ s32 cellFsReaddir(u32 fd, vm::ptr dir, vm::ptr nread) cellFs.Log("cellFsReaddir(fd=0x%x, dir=*0x%x, nread=*0x%x)", fd, dir, nread); // call the syscall - return dir && nread ? sys_fs_readdir(fd, dir, nread) : CELL_EFAULT; + return dir && nread ? sys_fs_readdir(fd, dir, nread) : CELL_FS_EFAULT; } s32 cellFsClosedir(u32 fd) @@ -138,7 +138,7 @@ s32 cellFsLseek(u32 fd, s64 offset, u32 whence, vm::ptr pos) cellFs.Log("cellFsLseek(fd=0x%x, offset=0x%llx, whence=0x%x, pos=*0x%x)", fd, offset, whence, pos); // call the syscall - return pos ? sys_fs_lseek(fd, offset, whence, pos) : CELL_EFAULT; + return pos ? sys_fs_lseek(fd, offset, whence, pos) : CELL_FS_EFAULT; } s32 cellFsFsync(u32 fd) @@ -153,7 +153,7 @@ s32 cellFsFGetBlockSize(PPUThread& CPU, u32 fd, vm::ptr sector_size, vm::pt cellFs.Log("cellFsFGetBlockSize(fd=0x%x, sector_size=*0x%x, block_size=*0x%x)", fd, sector_size, block_size); // call the syscall - return sector_size && block_size ? sys_fs_fget_block_size(fd, sector_size, block_size, vm::stackvar>(CPU), vm::stackvar>(CPU)) : CELL_EFAULT; + return sector_size && block_size ? sys_fs_fget_block_size(fd, sector_size, block_size, vm::stackvar>(CPU), vm::stackvar>(CPU)) : CELL_FS_EFAULT; } s32 cellFsGetBlockSize(PPUThread& CPU, vm::ptr path, vm::ptr sector_size, vm::ptr block_size) @@ -211,8 +211,11 @@ s32 cellFsGetDirectoryEntries(u32 fd, vm::ptr entries, u32 cellFs.Warning("cellFsGetDirectoryEntries(fd=0x%x, entries=*0x%x, entries_size=0x%x, data_count=*0x%x)", fd, entries, entries_size, data_count); std::shared_ptr directory; + if (!Emu.GetIdManager().GetIDData(fd, directory)) - return CELL_ESRCH; + { + return CELL_FS_EBADF; + } const DirEntryInfo* info = directory->Read(); if (info) @@ -502,9 +505,10 @@ s32 cellFsStReadStart(u32 fd, u64 offset, u64 size) const u32 position = vm::cast(file->st_buffer + file->st_total_read % file->st_ringbuf_size); // read data - auto old = file->file->Seek(offset + file->st_total_read); + auto old = file->file->Tell(); + file->file->Seek(offset + file->st_total_read); auto res = file->file->Read(vm::get_ptr(position), file->st_block_size); - file->file->Seek(old - file->st_block_size); + file->file->Seek(old); // notify file->st_total_read += res; @@ -829,7 +833,7 @@ s32 cellFsSdataOpen(PPUThread& CPU, vm::ptr path, s32 flags, vm::ptr if (flags != CELL_FS_O_RDONLY) { - return CELL_EINVAL; + return CELL_FS_EINVAL; } return cellFsOpen(path, CELL_FS_O_RDONLY, fd, vm::stackvar>(CPU), 8); @@ -976,8 +980,11 @@ s32 cellFsSetIoBufferFromDefaultContainer(u32 fd, u32 buffer_size, u32 page_type cellFs.Todo("cellFsSetIoBufferFromDefaultContainer(fd=%d, buffer_size=%d, page_type=%d)", fd, buffer_size, page_type); std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; + { + CELL_FS_EBADF; + } return CELL_OK; } diff --git a/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp b/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp index ab057c40b2..f252098984 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp @@ -213,7 +213,7 @@ s32 sys_fs_readdir(u32 fd, vm::ptr dir, vm::ptr nread) if (!Emu.GetIdManager().GetIDData(fd, directory)) { - return CELL_ESRCH; + return CELL_FS_EBADF; } const DirEntryInfo* info = directory->Read(); @@ -241,7 +241,7 @@ s32 sys_fs_closedir(u32 fd) if (!Emu.GetIdManager().GetIDData(fd, directory)) { - return CELL_ESRCH; + return CELL_FS_EBADF; } Emu.GetIdManager().RemoveID(fd); @@ -329,7 +329,7 @@ s32 sys_fs_stat(vm::ptr path, vm::ptr sb) 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; + return CELL_FS_ENOENT; } s32 sys_fs_fstat(u32 fd, vm::ptr sb) @@ -337,8 +337,11 @@ s32 sys_fs_fstat(u32 fd, vm::ptr sb) sys_fs.Warning("sys_fs_fstat(fd=0x%x, sb=*0x%x)", fd, sb); std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; + { + return CELL_FS_EBADF; + } sb->mode = CELL_FS_S_IRUSR | CELL_FS_S_IWUSR | CELL_FS_S_IXUSR | @@ -364,11 +367,15 @@ s32 sys_fs_mkdir(vm::ptr path, s32 mode) const std::string _path = path.get_ptr(); - if (vfsDir().IsExists(_path)) - return CELL_EEXIST; + if (Emu.GetVFS().ExistsDir(_path)) + { + return CELL_FS_EEXIST; + } if (!Emu.GetVFS().CreateDir(_path)) - return CELL_EBUSY; + { + return CELL_FS_EIO; // ??? + } sys_fs.Notice("sys_fs_mkdir(): directory '%s' created", path.get_ptr()); return CELL_OK; @@ -383,32 +390,29 @@ s32 sys_fs_rename(vm::ptr from, vm::ptr to) std::string _from = from.get_ptr(); std::string _to = to.get_ptr(); + if (Emu.GetVFS().ExistsDir(_from)) { - vfsDir dir; - if (dir.IsExists(_from)) + if (!Emu.GetVFS().RenameDir(_from, _to)) { - 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; + return CELL_FS_EIO; // ??? } + + sys_fs.Notice("sys_fs_rename(): directory '%s' renamed to '%s'", from.get_ptr(), to.get_ptr()); + return CELL_OK; } + if (Emu.GetVFS().ExistsFile(_from)) { - vfsFile f; - - if (f.Exists(_from)) + if (!Emu.GetVFS().RenameFile(_from, _to)) { - 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_FS_EIO; // ??? } + + sys_fs.Notice("sys_fs_rename(): file '%s' renamed to '%s'", from.get_ptr(), to.get_ptr()); + return CELL_OK; } - return CELL_ENOENT; + return CELL_FS_ENOENT; } s32 sys_fs_rmdir(vm::ptr path) @@ -418,12 +422,15 @@ s32 sys_fs_rmdir(vm::ptr path) std::string _path = path.get_ptr(); - vfsDir d; - if (!d.IsExists(_path)) - return CELL_ENOENT; + if (!Emu.GetVFS().RemoveDir(_path)) + { + if (Emu.GetVFS().ExistsDir(_path)) + { + return CELL_FS_EIO; // ??? + } - if (!d.Remove(_path)) - return CELL_EBUSY; + return CELL_FS_ENOENT; + } sys_fs.Notice("sys_fs_rmdir(): directory '%s' removed", path.get_ptr()); return CELL_OK; @@ -436,14 +443,15 @@ s32 sys_fs_unlink(vm::ptr path) 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; + { + if (Emu.GetVFS().ExistsFile(_path)) + { + return CELL_FS_EIO; // ??? + } + + return CELL_FS_ENOENT; + } sys_fs.Notice("sys_fs_unlink(): file '%s' deleted", path.get_ptr()); return CELL_OK; @@ -461,6 +469,7 @@ s32 sys_fs_lseek(u32 fd, s64 offset, s32 whence, vm::ptr pos) sys_fs.Log("sys_fs_lseek(fd=0x%x, offset=0x%llx, whence=0x%x, pos=*0x%x)", fd, offset, whence, pos); vfsSeekMode seek_mode; + switch (whence) { case CELL_FS_SEEK_SET: seek_mode = vfsSeekSet; break; @@ -468,15 +477,20 @@ s32 sys_fs_lseek(u32 fd, s64 offset, s32 whence, vm::ptr pos) 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; + return CELL_FS_EINVAL; } std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; + { + return CELL_FS_EBADF; + } std::lock_guard lock(file->mutex); + *pos = file->file->Seek(offset, seek_mode); + return CELL_OK; } @@ -485,8 +499,11 @@ s32 sys_fs_fget_block_size(u32 fd, vm::ptr sector_size, vm::ptr block_ sys_fs.Todo("sys_fs_fget_block_size(fd=%d, sector_size=*0x%x, block_size=*0x%x, arg4=*0x%x, arg5=*0x%x)", fd, sector_size, block_size, arg4, arg5); std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; + { + CELL_FS_EBADF; + } *sector_size = 4096; // ? *block_size = 4096; // ? @@ -514,8 +531,9 @@ s32 sys_fs_truncate(vm::ptr path, u64 size) if (!f.IsOpened()) { sys_fs.Warning("sys_fs_truncate(): '%s' not found", path.get_ptr()); - return CELL_ENOENT; + return CELL_FS_ENOENT; } + u64 initialSize = f.GetSize(); if (initialSize < size) @@ -541,8 +559,11 @@ s32 sys_fs_ftruncate(u32 fd, u64 size) sys_fs.Warning("sys_fs_ftruncate(fd=0x%x, size=0x%llx)", fd, size); std::shared_ptr file; + if (!Emu.GetIdManager().GetIDData(fd, file)) - return CELL_ESRCH; + { + CELL_FS_EBADF; + } u64 initialSize = file->file->GetSize();