Guest User

Untitled

a guest
Jul 20th, 2018
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.99 KB | None | 0 0
  1. Index: WII_IPC_HLE_Device_fs.cpp
  2. ===================================================================
  3. --- WII_IPC_HLE_Device_fs.cpp (revision 4682)
  4. +++ WII_IPC_HLE_Device_fs.cpp (working copy)
  5. @@ -29,48 +29,35 @@
  6.  
  7. #define MAX_NAME (12)
  8.  
  9. -
  10. CWII_IPC_HLE_Device_fs::CWII_IPC_HLE_Device_fs(u32 _DeviceID, const std::string& _rDeviceName)
  11. : IWII_IPC_HLE_Device(_DeviceID, _rDeviceName)
  12. -{}
  13. -
  14. -CWII_IPC_HLE_Device_fs::~CWII_IPC_HLE_Device_fs()
  15. -{}
  16. -
  17. -bool CWII_IPC_HLE_Device_fs::Open(u32 _CommandAddress, u32 _Mode)
  18. {
  19. - // clear tmp folder
  20. + // clear tmp and import folder
  21. {
  22. //std::string WiiTempFolder = File::GetUserDirectory() + FULL_WII_USER_DIR + std::string("tmp");
  23. std::string WiiTempFolder = FULL_WII_USER_DIR + std::string("tmp");
  24. File::DeleteDirRecursively(WiiTempFolder.c_str());
  25. File::CreateDir(WiiTempFolder.c_str());
  26. }
  27. -
  28. - // create home directory
  29. - if (VolumeHandler::IsValid())
  30. {
  31. - char Path[260+1];
  32. - u32 TitleID, GameID;
  33. - VolumeHandler::RAWReadToPtr((u8*)&TitleID, 0x0F8001DC, 4);
  34. -
  35. - TitleID = Common::swap32(TitleID);
  36. - GameID = VolumeHandler::Read32(0);
  37. + //std::string WiiTempFolder = File::GetUserDirectory() + FULL_WII_USER_DIR + std::string("tmp");
  38. + std::string WiiTempFolder = FULL_WII_USER_DIR + std::string("import");
  39. + File::DeleteDirRecursively(WiiTempFolder.c_str());
  40. + File::CreateDir(WiiTempFolder.c_str());
  41. + }
  42. +}
  43.  
  44. - _dbg_assert_(WII_IPC_FILEIO, GameID != 0);
  45. - if (GameID == 0) GameID = 0xF00DBEEF;
  46. - if (TitleID == 0) TitleID = 0x00010000;
  47. +CWII_IPC_HLE_Device_fs::~CWII_IPC_HLE_Device_fs()
  48. +{}
  49.  
  50. - sprintf(Path, FULL_WII_USER_DIR "title/%08x/%08x/data/nocopy/", TitleID, GameID);
  51. +bool CWII_IPC_HLE_Device_fs::Open(u32 _CommandAddress, u32 _Mode)
  52. +{
  53. + //Value is more or less magic but should be higher than max file handle count!
  54. + Memory::Write_U32( 150, _CommandAddress + 4 );
  55.  
  56. - File::CreateFullPath(Path);
  57. - }
  58. -
  59. - Memory::Write_U32(GetDeviceID(), _CommandAddress+4);
  60. - m_Active = true;
  61. + INFO_LOG(WII_IPC_FILEIO, "Open: /dev/fs");
  62. return true;
  63. }
  64. -
  65. bool CWII_IPC_HLE_Device_fs::Close(u32 _CommandAddress, bool _bForce)
  66. {
  67. INFO_LOG(WII_IPC_FILEIO, "Close");
  68. @@ -123,7 +110,7 @@
  69. if (!File::Exists(Filename.c_str()))
  70. {
  71. WARN_LOG(WII_IPC_FILEIO, "FS: Search not found: %s", Filename.c_str());
  72. - ReturnValue = FS_DIRFILE_NOT_FOUND;
  73. + ReturnValue = FS_FILE_NOT_EXIST;
  74. break;
  75. }
  76.  
  77. @@ -146,15 +133,17 @@
  78.  
  79. CFileSearch FileSearch(Extensions, Directories);
  80.  
  81. - // it is one
  82. + // If in- and outcount are both one only return the file count
  83. if ((CommandBuffer.InBuffer.size() == 1) && (CommandBuffer.PayloadBuffer.size() == 1))
  84. {
  85. size_t numFile = FileSearch.GetFileNames().size();
  86. INFO_LOG(WII_IPC_FILEIO, " %i Files found", numFile);
  87.  
  88. Memory::Write_U32((u32)numFile, CommandBuffer.PayloadBuffer[0].m_Address);
  89. +
  90. + ReturnValue = FS_RESULT_OK;
  91. }
  92. - else
  93. + else if ((CommandBuffer.InBuffer.size() == 2) && (CommandBuffer.PayloadBuffer.size() == 2)) // return filenames
  94. {
  95. u32 MaxEntries = Memory::Read_U32(CommandBuffer.InBuffer[0].m_Address);
  96.  
  97. @@ -181,9 +170,13 @@
  98. }
  99.  
  100. Memory::Write_U32((u32)numFiles, CommandBuffer.PayloadBuffer[1].m_Address);
  101. +
  102. + ReturnValue = FS_RESULT_OK;
  103. +
  104. + } else {
  105. + ReturnValue = FS_INVALID_ARGUMENT;
  106. }
  107.  
  108. - ReturnValue = FS_RESULT_OK;
  109. }
  110. break;
  111.  
  112. @@ -198,7 +191,7 @@
  113. // It should be correct, but don't count on it...
  114. std::string path(HLE_IPC_BuildFilename((const char*)Memory::GetPointer(CommandBuffer.InBuffer[0].m_Address), CommandBuffer.InBuffer[0].m_Size));
  115. u32 fsBlocks = 0;
  116. - u32 iNodes = 0;
  117. + u32 iNodes = 1;
  118.  
  119. INFO_LOG(WII_IPC_FILEIO, "IOCTL_GETUSAGE %s", path.c_str());
  120. if (File::IsDirectory(path.c_str()))
  121. @@ -218,7 +211,7 @@
  122. {
  123. fsBlocks = 0;
  124. iNodes = 0;
  125. - ReturnValue = FS_RESULT_OK;
  126. + ReturnValue = FS_FILE_NOT_EXIST;
  127. WARN_LOG(WII_IPC_FILEIO, "FS: fsBlock failed, cannot find directoy: %s", path.c_str());
  128. }
  129.  
  130. @@ -299,23 +292,36 @@
  131. Addr += 9; // owner attribs, permission
  132. u8 Attribs = Memory::Read_U8(Addr);
  133.  
  134. - INFO_LOG(WII_IPC_FILEIO, "FS: CREATE_DIR %s", DirName.c_str());
  135. + INFO_LOG( WII_IPC_FILEIO, "FS: CREATE_DIR %s", DirName.c_str() );
  136.  
  137. + if( File::IsDirectory(DirName.c_str()) )
  138. + return FS_FILE_EXIST;
  139. +
  140. DirName += DIR_SEP;
  141. - File::CreateFullPath(DirName.c_str());
  142. + File::CreateDir( DirName.c_str() );
  143. _dbg_assert_msg_(WII_IPC_FILEIO, File::IsDirectory(DirName.c_str()), "FS: CREATE_DIR %s failed", DirName.c_str());
  144.  
  145. - return FS_RESULT_OK;
  146. + if( File::IsDirectory( DirName.c_str() ) )
  147. + return FS_RESULT_OK;
  148. + else
  149. + return FS_INVALID_ARGUMENT;
  150. }
  151. break;
  152.  
  153. case IOCTL_SET_ATTR:
  154. {
  155. + std::string Filename;
  156. +
  157. + if( _BufferInSize == 0x4A || _BufferInSize == 0x4C )
  158. + Filename = HLE_IPC_BuildFilename( (const char*)Memory::GetPointer(_BufferIn+6), 64 );
  159. + else
  160. + return FS_INVALID_ARGUMENT;
  161. +
  162. u32 Addr = _BufferIn;
  163.  
  164. u32 OwnerID = Memory::Read_U32(Addr); Addr += 4;
  165. u16 GroupID = Memory::Read_U16(Addr); Addr += 2;
  166. - std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn), 64); Addr += 64;
  167. + /*std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn), 64); */Addr += 64;
  168. u8 OwnerPerm = Memory::Read_U8(Addr); Addr += 1;
  169. u8 GroupPerm = Memory::Read_U8(Addr); Addr += 1;
  170. u8 OtherPerm = Memory::Read_U8(Addr); Addr += 1;
  171. @@ -329,53 +335,50 @@
  172. DEBUG_LOG(WII_IPC_FILEIO, " OtherPerm: 0x%02x", OtherPerm);
  173. DEBUG_LOG(WII_IPC_FILEIO, " Attributes: 0x%02x", Attributes);
  174.  
  175. - return FS_RESULT_OK;
  176. + if( File::IsDirectory(Filename.c_str()) || File::Exists(Filename.c_str()) )
  177. + return FS_RESULT_OK;
  178. + else
  179. + return FS_FILE_NOT_EXIST;
  180. }
  181. break;
  182.  
  183. case IOCTL_GET_ATTR:
  184. - {
  185. - _dbg_assert_msg_(WII_IPC_FILEIO, _BufferOutSize == 76,
  186. - " GET_ATTR needs an 76 bytes large output buffer but it is %i bytes large",
  187. - _BufferOutSize);
  188. + {
  189. + std::string Filename;
  190.  
  191. - u32 OwnerID = 0;
  192. - u16 GroupID = 0;
  193. - std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn), 64);
  194. - u8 OwnerPerm = 0x3; // read/write
  195. - u8 GroupPerm = 0x3; // read/write
  196. - u8 OtherPerm = 0x3; // read/write
  197. - u8 Attributes = 0x00; // no attributes
  198. - if (File::IsDirectory(Filename.c_str()))
  199. + if( _BufferInSize == 0x4A )
  200. + Filename = HLE_IPC_BuildFilename( (const char*)Memory::GetPointer(_BufferIn+6), 64 );
  201. + else if( _BufferInSize == 0x40 )
  202. + Filename = HLE_IPC_BuildFilename( (const char*)Memory::GetPointer(_BufferIn), 64 );
  203. + else
  204. + return FS_INVALID_ARGUMENT;
  205. +
  206. + if( File::IsDirectory(Filename.c_str()) || File::Exists(Filename.c_str()) )
  207. {
  208. INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR Directory %s - all permission flags are set", Filename.c_str());
  209. - }
  210. - else
  211. - {
  212. - if (File::Exists(Filename.c_str()))
  213. - {
  214. - INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR %s - all permission flags are set", Filename.c_str());
  215. - }
  216. - else
  217. - {
  218. - INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR unknown %s", Filename.c_str());
  219. - return FS_FILE_NOT_EXIST;
  220. - }
  221. - }
  222.  
  223. - // write answer to buffer
  224. - if (_BufferOutSize == 76)
  225. - {
  226. + u32 OwnerID = 0x00000000;
  227. + u16 GroupID = 0x0000;
  228. + u8 OwnerPerm = 0x03; // read/write
  229. + u8 GroupPerm = 0x03; // read/write
  230. + u8 OtherPerm = 0x03; // read/write
  231. + u8 Attributes = 0x00; // no attributes
  232. +
  233. u32 Addr = _BufferOut;
  234. +
  235. Memory::Write_U32(OwnerID, Addr); Addr += 4;
  236. Memory::Write_U16(GroupID, Addr); Addr += 2;
  237. - memcpy(Memory::GetPointer(Addr), Filename.c_str(), Filename.size()); Addr += 64;
  238. + /*memcpy(Memory::GetPointer(Addr), Filename.c_str(), Filename.size());*/Addr += 64;
  239. Memory::Write_U8(OwnerPerm, Addr); Addr += 1;
  240. Memory::Write_U8(GroupPerm, Addr); Addr += 1;
  241. Memory::Write_U8(OtherPerm, Addr); Addr += 1;
  242. Memory::Write_U8(Attributes, Addr); Addr += 1;
  243. +
  244. + } else {
  245. + INFO_LOG(WII_IPC_FILEIO, "FS: GET_ATTR unknown %s", Filename.c_str());
  246. + return FS_FILE_NOT_EXIST;
  247. }
  248. -
  249. +
  250. return FS_RESULT_OK;
  251. }
  252. break;
  253. @@ -388,26 +391,34 @@
  254.  
  255. std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn+Offset), 64);
  256. Offset += 64;
  257. - if (File::Delete(Filename.c_str()))
  258. +
  259. + if ( File::IsDirectory(Filename.c_str()) || File::Exists(Filename.c_str()) )
  260. {
  261. - INFO_LOG(WII_IPC_FILEIO, "FS: DeleteFile %s", Filename.c_str());
  262. + if (File::Delete(Filename.c_str()))
  263. + {
  264. + INFO_LOG(WII_IPC_FILEIO, "FS: DeleteFile %s", Filename.c_str());
  265. + }
  266. + else if (File::DeleteDir(Filename.c_str()))
  267. + {
  268. + INFO_LOG(WII_IPC_FILEIO, "FS: DeleteDir %s", Filename.c_str());
  269. + }
  270. + else
  271. + {
  272. + WARN_LOG(WII_IPC_FILEIO, "FS: DeleteFile %s - failed!!!", Filename.c_str());
  273. + }
  274. +
  275. + return FS_RESULT_OK;
  276. +
  277. + } else {
  278. + return FS_FILE_NOT_EXIST;
  279. }
  280. - else if (File::DeleteDir(Filename.c_str()))
  281. - {
  282. - INFO_LOG(WII_IPC_FILEIO, "FS: DeleteDir %s", Filename.c_str());
  283. - }
  284. - else
  285. - {
  286. - WARN_LOG(WII_IPC_FILEIO, "FS: DeleteFile %s - failed!!!", Filename.c_str());
  287. - }
  288. -
  289. - return FS_RESULT_OK;
  290. }
  291. break;
  292.  
  293. case IOCTL_RENAME_FILE:
  294. {
  295. _dbg_assert_(WII_IPC_FILEIO, _BufferOutSize == 0);
  296. +
  297. int Offset = 0;
  298.  
  299. std::string Filename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn+Offset), 64);
  300. @@ -416,27 +427,26 @@
  301. std::string FilenameRename = HLE_IPC_BuildFilename((const char*)Memory::GetPointer(_BufferIn+Offset), 64);
  302. Offset += 64;
  303.  
  304. - // try to make the basis directory
  305. - File::CreateFullPath(FilenameRename.c_str());
  306. -
  307. - // if there is already a file, delete it
  308. - if (File::Exists(FilenameRename.c_str()))
  309. + if( File::Exists( Filename.c_str() ) )
  310. {
  311. - File::Delete(FilenameRename.c_str());
  312. - }
  313. -
  314. - // finally try to rename the file
  315. - if (File::Rename(Filename.c_str(), FilenameRename.c_str()))
  316. - {
  317. - INFO_LOG(WII_IPC_FILEIO, "FS: Rename %s to %s", Filename.c_str(), FilenameRename.c_str());
  318. - }
  319. - else
  320. - {
  321. - ERROR_LOG(WII_IPC_FILEIO, "FS: Rename %s to %s - failed", Filename.c_str(), FilenameRename.c_str());
  322. + if( File::Rename( Filename.c_str(), FilenameRename.c_str() ) )
  323. + {
  324. + INFO_LOG(WII_IPC_FILEIO, "FS: Rename %s to %s", Filename.c_str(), FilenameRename.c_str() );
  325. + return FS_RESULT_OK;
  326. + } else {
  327. + File::Delete( FilenameRename.c_str() );
  328. + if( File::Rename( Filename.c_str(), FilenameRename.c_str() ) )
  329. + {
  330. + INFO_LOG(WII_IPC_FILEIO, "FS: Rename %s to %s", Filename.c_str(), FilenameRename.c_str() );
  331. + return FS_RESULT_OK;
  332. + }
  333. + }
  334. + } else {
  335. + INFO_LOG( WII_IPC_FILEIO, "FS: Rename %s to %s - failed", Filename.c_str(), FilenameRename.c_str() );
  336. return FS_FILE_NOT_EXIST;
  337. }
  338.  
  339. - return FS_RESULT_OK;
  340. + return FS_INVALID;
  341. }
  342. break;
  343.  
  344. @@ -461,21 +471,19 @@
  345. DEBUG_LOG(WII_IPC_FILEIO, " OtherPerm: 0x%02x", OtherPerm);
  346. DEBUG_LOG(WII_IPC_FILEIO, " Attributes: 0x%02x", Attributes);
  347.  
  348. - // check if the file already exist
  349. - if (File::Exists(Filename.c_str()))
  350. + // check if the file already exists
  351. + if( File::Exists( Filename.c_str() ) )
  352. {
  353. WARN_LOG(WII_IPC_FILEIO, " result = FS_RESULT_EXISTS", Filename.c_str());
  354. return FS_FILE_EXIST;
  355. }
  356.  
  357. // create the file
  358. - File::CreateFullPath(Filename.c_str()); // just to be sure
  359. bool Result = File::CreateEmptyFile(Filename.c_str());
  360. if (!Result)
  361. {
  362. ERROR_LOG(WII_IPC_FILEIO, "CWII_IPC_HLE_Device_fs: couldn't create new file");
  363. - PanicAlert("CWII_IPC_HLE_Device_fs: couldn't create new file");
  364. - return FS_RESULT_FATAL;
  365. + return FS_FILE_NOT_EXIST;
  366. }
  367.  
  368. INFO_LOG(WII_IPC_FILEIO, "\tresult = FS_RESULT_OK");
Add Comment
Please, Sign In to add comment