Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: WII_IPC_HLE_Device_fs.cpp
- ===================================================================
- --- WII_IPC_HLE_Device_fs.cpp (revision 4682)
- +++ WII_IPC_HLE_Device_fs.cpp (working copy)
- @@ -29,48 +29,35 @@
- #define MAX_NAME (12)
- -
- CWII_IPC_HLE_Device_fs::CWII_IPC_HLE_Device_fs(u32 _DeviceID, const std::string& _rDeviceName)
- : IWII_IPC_HLE_Device(_DeviceID, _rDeviceName)
- -{}
- -
- -CWII_IPC_HLE_Device_fs::~CWII_IPC_HLE_Device_fs()
- -{}
- -
- -bool CWII_IPC_HLE_Device_fs::Open(u32 _CommandAddress, u32 _Mode)
- {
- - // clear tmp folder
- + // clear tmp and import folder
- {
- //std::string WiiTempFolder = File::GetUserDirectory() + FULL_WII_USER_DIR + std::string("tmp");
- std::string WiiTempFolder = FULL_WII_USER_DIR + std::string("tmp");
- File::DeleteDirRecursively(WiiTempFolder.c_str());
- File::CreateDir(WiiTempFolder.c_str());
- }
- -
- - // create home directory
- - if (VolumeHandler::IsValid())
- {
- - char Path[260+1];
- - u32 TitleID, GameID;
- - VolumeHandler::RAWReadToPtr((u8*)&TitleID, 0x0F8001DC, 4);
- -
- - TitleID = Common::swap32(TitleID);
- - GameID = VolumeHandler::Read32(0);
- + //std::string WiiTempFolder = File::GetUserDirectory() + FULL_WII_USER_DIR + std::string("tmp");
- + std::string WiiTempFolder = FULL_WII_USER_DIR + std::string("import");
- + File::DeleteDirRecursively(WiiTempFolder.c_str());
- + File::CreateDir(WiiTempFolder.c_str());
- + }
- +}
- - _dbg_assert_(WII_IPC_FILEIO, GameID != 0);
- - if (GameID == 0) GameID = 0xF00DBEEF;
- - if (TitleID == 0) TitleID = 0x00010000;
- +CWII_IPC_HLE_Device_fs::~CWII_IPC_HLE_Device_fs()
- +{}
- - sprintf(Path, FULL_WII_USER_DIR "title/%08x/%08x/data/nocopy/", TitleID, GameID);
- +bool CWII_IPC_HLE_Device_fs::Open(u32 _CommandAddress, u32 _Mode)
- +{
- + //Value is more or less magic but should be higher than max file handle count!
- + Memory::Write_U32( 150, _CommandAddress + 4 );
- - File::CreateFullPath(Path);
- - }
- -
- - Memory::Write_U32(GetDeviceID(), _CommandAddress+4);
- - m_Active = true;
- + INFO_LOG(WII_IPC_FILEIO, "Open: /dev/fs");
- return true;
- }
- -
- bool CWII_IPC_HLE_Device_fs::Close(u32 _CommandAddress, bool _bForce)
- {
- INFO_LOG(WII_IPC_FILEIO, "Close");
- @@ -123,7 +110,7 @@
- if (!File::Exists(Filename.c_str()))
- {
- WARN_LOG(WII_IPC_FILEIO, "FS: Search not found: %s", Filename.c_str());
- - ReturnValue = FS_DIRFILE_NOT_FOUND;
- + ReturnValue = FS_FILE_NOT_EXIST;
- break;
- }
- @@ -146,15 +133,17 @@
- CFileSearch FileSearch(Extensions, Directories);
- - // it is one
- + // If in- and outcount are both one only return the file count
- if ((CommandBuffer.InBuffer.size() == 1) && (CommandBuffer.PayloadBuffer.size() == 1))
- {
- size_t numFile = FileSearch.GetFileNames().size();
- INFO_LOG(WII_IPC_FILEIO, " %i Files found", numFile);
- Memory::Write_U32((u32)numFile, CommandBuffer.PayloadBuffer[0].m_Address);
- +
- + ReturnValue = FS_RESULT_OK;
- }
- - else
- + else if ((CommandBuffer.InBuffer.size() == 2) && (CommandBuffer.PayloadBuffer.size() == 2)) // return filenames
- {
- u32 MaxEntries = Memory::Read_U32(CommandBuffer.InBuffer[0].m_Address);
- @@ -181,9 +170,13 @@
- }
- Memory::Write_U32((u32)numFiles, CommandBuffer.PayloadBuffer[1].m_Address);
- +
- + ReturnValue = FS_RESULT_OK;
- +
- + } else {
- + ReturnValue = FS_INVALID_ARGUMENT;
- }
- - ReturnValue = FS_RESULT_OK;
- }
- break;
- @@ -198,7 +191,7 @@
- // It should be correct, but don't count on it...
- std::string path(HLE_IPC_BuildFilename((const char*)Memory::GetPointer(CommandBuffer.InBuffer[0].m_Address), CommandBuffer.InBuffer[0].m_Size));
- u32 fsBlocks = 0;
- - u32 iNodes = 0;
- + u32 iNodes = 1;
- INFO_LOG(WII_IPC_FILEIO, "IOCTL_GETUSAGE %s", path.c_str());
- if (File::IsDirectory(path.c_str()))
- @@ -218,7 +211,7 @@
- {
- fsBlocks = 0;
- iNodes = 0;
- - ReturnValue = FS_RESULT_OK;
- + ReturnValue = FS_FILE_NOT_EXIST;
- WARN_LOG(WII_IPC_FILEIO, "FS: fsBlock failed, cannot find directoy: %s", path.c_str());
- }
- @@ -299,23 +292,36 @@
- Addr += 9; // owner attribs, permission
- u8 Attribs = Memory::Read_U8(Addr);
- - INFO_LOG(WII_IPC_FILEIO, "FS: CREATE_DIR %s", DirName.c_str());
- + INFO_LOG( WII_IPC_FILEIO, "FS: CREATE_DIR %s", DirName.c_str() );
- + if( File::IsDirectory(DirName.c_str()) )
- + return FS_FILE_EXIST;
- +
- DirName += DIR_SEP;
- - File::CreateFullPath(DirName.c_str());
- + File::CreateDir( DirName.c_str() );
- _dbg_assert_msg_(WII_IPC_FILEIO, File::IsDirectory(DirName.c_str()), "FS: CREATE_DIR %s failed", DirName.c_str());
- - return FS_RESULT_OK;
- + if( File::IsDirectory( DirName.c_str() ) )
- + return FS_RESULT_OK;
- + else
- + return FS_INVALID_ARGUMENT;
- }
- break;
- case IOCTL_SET_ATTR:
- {
- + std::string Filename;
- +
- + if( _BufferInSize == 0x4A || _BufferInSize == 0x4C )
- + Filename = HLE_IPC_BuildFilename( (const char*)Memory::GetPointer(_BufferIn+6), 64 );
- + else
- + return FS_INVALID_ARGUMENT;
- +
- u32 Addr = _BufferIn;
- u32 OwnerID = Memory::Read_U32(Addr); Addr += 4;
- u16 GroupID = Memory::Read_U16(Addr); Addr += 2;
- - std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn), 64); Addr += 64;
- + /*std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn), 64); */Addr += 64;
- u8 OwnerPerm = Memory::Read_U8(Addr); Addr += 1;
- u8 GroupPerm = Memory::Read_U8(Addr); Addr += 1;
- u8 OtherPerm = Memory::Read_U8(Addr); Addr += 1;
- @@ -329,53 +335,50 @@
- DEBUG_LOG(WII_IPC_FILEIO, " OtherPerm: 0x%02x", OtherPerm);
- DEBUG_LOG(WII_IPC_FILEIO, " Attributes: 0x%02x", Attributes);
- - return FS_RESULT_OK;
- + if( File::IsDirectory(Filename.c_str()) || File::Exists(Filename.c_str()) )
- + return FS_RESULT_OK;
- + else
- + return FS_FILE_NOT_EXIST;
- }
- break;
- case IOCTL_GET_ATTR:
- - {
- - _dbg_assert_msg_(WII_IPC_FILEIO, _BufferOutSize == 76,
- - " GET_ATTR needs an 76 bytes large output buffer but it is %i bytes large",
- - _BufferOutSize);
- + {
- + std::string Filename;
- - u32 OwnerID = 0;
- - u16 GroupID = 0;
- - std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn), 64);
- - u8 OwnerPerm = 0x3; // read/write
- - u8 GroupPerm = 0x3; // read/write
- - u8 OtherPerm = 0x3; // read/write
- - u8 Attributes = 0x00; // no attributes
- - if (File::IsDirectory(Filename.c_str()))
- + if( _BufferInSize == 0x4A )
- + Filename = HLE_IPC_BuildFilename( (const char*)Memory::GetPointer(_BufferIn+6), 64 );
- + else if( _BufferInSize == 0x40 )
- + Filename = HLE_IPC_BuildFilename( (const char*)Memory::GetPointer(_BufferIn), 64 );
- + else
- + return FS_INVALID_ARGUMENT;
- +
- + if( File::IsDirectory(Filename.c_str()) || File::Exists(Filename.c_str()) )
- {
- INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR Directory %s - all permission flags are set", Filename.c_str());
- - }
- - else
- - {
- - if (File::Exists(Filename.c_str()))
- - {
- - INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR %s - all permission flags are set", Filename.c_str());
- - }
- - else
- - {
- - INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR unknown %s", Filename.c_str());
- - return FS_FILE_NOT_EXIST;
- - }
- - }
- - // write answer to buffer
- - if (_BufferOutSize == 76)
- - {
- + u32 OwnerID = 0x00000000;
- + u16 GroupID = 0x0000;
- + u8 OwnerPerm = 0x03; // read/write
- + u8 GroupPerm = 0x03; // read/write
- + u8 OtherPerm = 0x03; // read/write
- + u8 Attributes = 0x00; // no attributes
- +
- u32 Addr = _BufferOut;
- +
- Memory::Write_U32(OwnerID, Addr); Addr += 4;
- Memory::Write_U16(GroupID, Addr); Addr += 2;
- - memcpy(Memory::GetPointer(Addr), Filename.c_str(), Filename.size()); Addr += 64;
- + /*memcpy(Memory::GetPointer(Addr), Filename.c_str(), Filename.size());*/Addr += 64;
- Memory::Write_U8(OwnerPerm, Addr); Addr += 1;
- Memory::Write_U8(GroupPerm, Addr); Addr += 1;
- Memory::Write_U8(OtherPerm, Addr); Addr += 1;
- Memory::Write_U8(Attributes, Addr); Addr += 1;
- +
- + } else {
- + INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR unknown %s", Filename.c_str());
- + return FS_FILE_NOT_EXIST;
- }
- -
- +
- return FS_RESULT_OK;
- }
- break;
- @@ -388,26 +391,34 @@
- std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn+Offset), 64);
- Offset += 64;
- - if (File::Delete(Filename.c_str()))
- +
- + if ( File::IsDirectory(Filename.c_str()) || File::Exists(Filename.c_str()) )
- {
- - INFO_LOG(WII_IPC_FILEIO, "FS: DeleteFile %s", Filename.c_str());
- + if (File::Delete(Filename.c_str()))
- + {
- + INFO_LOG(WII_IPC_FILEIO, "FS: DeleteFile %s", Filename.c_str());
- + }
- + else if (File::DeleteDir(Filename.c_str()))
- + {
- + INFO_LOG(WII_IPC_FILEIO, "FS: DeleteDir %s", Filename.c_str());
- + }
- + else
- + {
- + WARN_LOG(WII_IPC_FILEIO, "FS: DeleteFile %s - failed!!!", Filename.c_str());
- + }
- +
- + return FS_RESULT_OK;
- +
- + } else {
- + return FS_FILE_NOT_EXIST;
- }
- - else if (File::DeleteDir(Filename.c_str()))
- - {
- - INFO_LOG(WII_IPC_FILEIO, "FS: DeleteDir %s", Filename.c_str());
- - }
- - else
- - {
- - WARN_LOG(WII_IPC_FILEIO, "FS: DeleteFile %s - failed!!!", Filename.c_str());
- - }
- -
- - return FS_RESULT_OK;
- }
- break;
- case IOCTL_RENAME_FILE:
- {
- _dbg_assert_(WII_IPC_FILEIO, _BufferOutSize == 0);
- +
- int Offset = 0;
- std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn+Offset), 64);
- @@ -416,27 +427,26 @@
- std::string FilenameRename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn+Offset), 64);
- Offset += 64;
- - // try to make the basis directory
- - File::CreateFullPath(FilenameRename.c_str());
- -
- - // if there is already a file, delete it
- - if (File::Exists(FilenameRename.c_str()))
- + if( File::Exists( Filename.c_str() ) )
- {
- - File::Delete(FilenameRename.c_str());
- - }
- -
- - // finally try to rename the file
- - if (File::Rename(Filename.c_str(), FilenameRename.c_str()))
- - {
- - INFO_LOG(WII_IPC_FILEIO, "FS: Rename %s to %s", Filename.c_str(), FilenameRename.c_str());
- - }
- - else
- - {
- - ERROR_LOG(WII_IPC_FILEIO, "FS: Rename %s to %s - failed", Filename.c_str(), FilenameRename.c_str());
- + if( File::Rename( Filename.c_str(), FilenameRename.c_str() ) )
- + {
- + INFO_LOG(WII_IPC_FILEIO, "FS: Rename %s to %s", Filename.c_str(), FilenameRename.c_str() );
- + return FS_RESULT_OK;
- + } else {
- + File::Delete( FilenameRename.c_str() );
- + if( File::Rename( Filename.c_str(), FilenameRename.c_str() ) )
- + {
- + INFO_LOG(WII_IPC_FILEIO, "FS: Rename %s to %s", Filename.c_str(), FilenameRename.c_str() );
- + return FS_RESULT_OK;
- + }
- + }
- + } else {
- + INFO_LOG( WII_IPC_FILEIO, "FS: Rename %s to %s - failed", Filename.c_str(), FilenameRename.c_str() );
- return FS_FILE_NOT_EXIST;
- }
- - return FS_RESULT_OK;
- + return FS_INVALID;
- }
- break;
- @@ -461,21 +471,19 @@
- DEBUG_LOG(WII_IPC_FILEIO, " OtherPerm: 0x%02x", OtherPerm);
- DEBUG_LOG(WII_IPC_FILEIO, " Attributes: 0x%02x", Attributes);
- - // check if the file already exist
- - if (File::Exists(Filename.c_str()))
- + // check if the file already exists
- + if( File::Exists( Filename.c_str() ) )
- {
- WARN_LOG(WII_IPC_FILEIO, " result = FS_RESULT_EXISTS", Filename.c_str());
- return FS_FILE_EXIST;
- }
- // create the file
- - File::CreateFullPath(Filename.c_str()); // just to be sure
- bool Result = File::CreateEmptyFile(Filename.c_str());
- if (!Result)
- {
- ERROR_LOG(WII_IPC_FILEIO, "CWII_IPC_HLE_Device_fs: couldn't create new file");
- - PanicAlert("CWII_IPC_HLE_Device_fs: couldn't create new file");
- - return FS_RESULT_FATAL;
- + return FS_FILE_NOT_EXIST;
- }
- INFO_LOG(WII_IPC_FILEIO, "\tresult = FS_RESULT_OK");
Add Comment
Please, Sign In to add comment