mirror of
				https://github.com/PabloMK7/citra.git
				synced 2025-10-31 13:50:03 +00:00 
			
		
		
		
	Added CreateFile to the FS_USER service
Tested with hwtests.
This commit is contained in:
		
							parent
							
								
									c2753d37a7
								
							
						
					
					
						commit
						0625dd09ea
					
				
					 8 changed files with 91 additions and 1 deletions
				
			
		|  | @ -199,6 +199,14 @@ public: | ||||||
|      */ |      */ | ||||||
|     virtual bool DeleteDirectory(const FileSys::Path& path) const = 0; |     virtual bool DeleteDirectory(const FileSys::Path& path) const = 0; | ||||||
| 
 | 
 | ||||||
|  |     /**
 | ||||||
|  |      * Create a file specified by its path | ||||||
|  |      * @param path Path relative to the Archive | ||||||
|  |      * @param size The size of the new file, filled with zeroes | ||||||
|  |      * @return File creation result code | ||||||
|  |      */ | ||||||
|  |     virtual ResultCode CreateFile(const Path& path, u32 size) const = 0; | ||||||
|  | 
 | ||||||
|     /**
 |     /**
 | ||||||
|      * Create a directory specified by its path |      * Create a directory specified by its path | ||||||
|      * @param path Path relative to the archive |      * @param path Path relative to the archive | ||||||
|  |  | ||||||
|  | @ -58,6 +58,12 @@ bool Archive_RomFS::DeleteDirectory(const FileSys::Path& path) const { | ||||||
|     return false; |     return false; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | ResultCode Archive_RomFS::CreateFile(const Path& path, u32 size) const { | ||||||
|  |     LOG_WARNING(Service_FS, "Attempted to create a file in ROMFS."); | ||||||
|  |     // TODO: Verify error code
 | ||||||
|  |     return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported, ErrorLevel::Permanent); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Create a directory specified by its path |  * Create a directory specified by its path | ||||||
|  * @param path Path relative to the archive |  * @param path Path relative to the archive | ||||||
|  |  | ||||||
|  | @ -53,6 +53,14 @@ public: | ||||||
|      */ |      */ | ||||||
|     bool DeleteDirectory(const FileSys::Path& path) const override; |     bool DeleteDirectory(const FileSys::Path& path) const override; | ||||||
| 
 | 
 | ||||||
|  |     /**
 | ||||||
|  |      * Create a file specified by its path | ||||||
|  |      * @param path Path relative to the Archive | ||||||
|  |      * @param size The size of the new file, filled with zeroes | ||||||
|  |      * @return File creation result code | ||||||
|  |      */ | ||||||
|  |     ResultCode CreateFile(const Path& path, u32 size) const override; | ||||||
|  | 
 | ||||||
|     /**
 |     /**
 | ||||||
|      * Create a directory specified by its path |      * Create a directory specified by its path | ||||||
|      * @param path Path relative to the archive |      * @param path Path relative to the archive | ||||||
|  |  | ||||||
|  | @ -35,6 +35,27 @@ bool DiskArchive::DeleteDirectory(const FileSys::Path& path) const { | ||||||
|     return FileUtil::DeleteDir(GetMountPoint() + path.AsString()); |     return FileUtil::DeleteDir(GetMountPoint() + path.AsString()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | ResultCode DiskArchive::CreateFile(const FileSys::Path& path, u32 size) const { | ||||||
|  |     std::string full_path = GetMountPoint() + path.AsString(); | ||||||
|  | 
 | ||||||
|  |     if (FileUtil::Exists(full_path)) | ||||||
|  |         return ResultCode(ErrorDescription::AlreadyExists, ErrorModule::FS, ErrorSummary::NothingHappened, ErrorLevel::Info); | ||||||
|  | 
 | ||||||
|  |     if (size == 0) { | ||||||
|  |         FileUtil::CreateEmptyFile(full_path); | ||||||
|  |         return RESULT_SUCCESS; | ||||||
|  |     } | ||||||
|  | 
 | ||||||
|  |     FileUtil::IOFile file(full_path, "wb"); | ||||||
|  |     // Creates a sparse file (or a normal file on filesystems without the concept of sparse files)
 | ||||||
|  |     // We do this by seeking to the right size, then writing a single null byte.
 | ||||||
|  |     if (file.Seek(size - 1, SEEK_SET) && file.WriteBytes("", 1) == 1) | ||||||
|  |         return RESULT_SUCCESS; | ||||||
|  | 
 | ||||||
|  |     return ResultCode(ErrorDescription::TooLarge, ErrorModule::FS, ErrorSummary::OutOfResource, ErrorLevel::Info); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
| bool DiskArchive::CreateDirectory(const Path& path) const { | bool DiskArchive::CreateDirectory(const Path& path) const { | ||||||
|     return FileUtil::CreateDir(GetMountPoint() + path.AsString()); |     return FileUtil::CreateDir(GetMountPoint() + path.AsString()); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -28,6 +28,7 @@ public: | ||||||
|     bool DeleteFile(const FileSys::Path& path) const override; |     bool DeleteFile(const FileSys::Path& path) const override; | ||||||
|     bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override; |     bool RenameFile(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override; | ||||||
|     bool DeleteDirectory(const FileSys::Path& path) const override; |     bool DeleteDirectory(const FileSys::Path& path) const override; | ||||||
|  |     ResultCode CreateFile(const Path& path, u32 size) const override; | ||||||
|     bool CreateDirectory(const Path& path) const override; |     bool CreateDirectory(const Path& path) const override; | ||||||
|     bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override; |     bool RenameDirectory(const FileSys::Path& src_path, const FileSys::Path& dest_path) const override; | ||||||
|     std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; |     std::unique_ptr<DirectoryBackend> OpenDirectory(const Path& path) const override; | ||||||
|  |  | ||||||
|  | @ -330,6 +330,14 @@ ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSy | ||||||
|                       ErrorSummary::Canceled, ErrorLevel::Status); |                       ErrorSummary::Canceled, ErrorLevel::Status); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | ResultCode CreateFileInArchive(Handle archive_handle, const FileSys::Path& path, u32 file_size) { | ||||||
|  |     Archive* archive = GetArchive(archive_handle); | ||||||
|  |     if (archive == nullptr) | ||||||
|  |         return InvalidHandle(ErrorModule::FS); | ||||||
|  | 
 | ||||||
|  |     return archive->backend->CreateFile(path, file_size); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| ResultCode CreateDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { | ResultCode CreateDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path) { | ||||||
|     Archive* archive = GetArchive(archive_handle); |     Archive* archive = GetArchive(archive_handle); | ||||||
|     if (archive == nullptr) |     if (archive == nullptr) | ||||||
|  |  | ||||||
|  | @ -82,6 +82,15 @@ ResultCode RenameFileBetweenArchives(ArchiveHandle src_archive_handle, const Fil | ||||||
|  */ |  */ | ||||||
| ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path); | ResultCode DeleteDirectoryFromArchive(ArchiveHandle archive_handle, const FileSys::Path& path); | ||||||
| 
 | 
 | ||||||
|  | /**
 | ||||||
|  |  * Create a File in an Archive | ||||||
|  |  * @param archive_handle Handle to an open Archive object | ||||||
|  |  * @param path Path to the File inside of the Archive | ||||||
|  |  * @param file_size The size of the new file, filled with zeroes | ||||||
|  |  * @return File creation result code | ||||||
|  |  */ | ||||||
|  | ResultCode CreateFileInArchive(Handle archive_handle, const FileSys::Path& path, u32 file_size); | ||||||
|  | 
 | ||||||
| /**
 | /**
 | ||||||
|  * Create a Directory from an Archive |  * Create a Directory from an Archive | ||||||
|  * @param archive_handle Handle to an open Archive object |  * @param archive_handle Handle to an open Archive object | ||||||
|  |  | ||||||
|  | @ -225,6 +225,35 @@ static void DeleteDirectory(Service::Interface* self) { | ||||||
|     cmd_buff[1] = DeleteDirectoryFromArchive(archive_handle, dir_path).raw; |     cmd_buff[1] = DeleteDirectoryFromArchive(archive_handle, dir_path).raw; | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | /*
 | ||||||
|  |  * FS_User::CreateFile service function | ||||||
|  |  *  Inputs: | ||||||
|  |  *      0 : Command header 0x08080202 | ||||||
|  |  *      2 : Archive handle lower word | ||||||
|  |  *      3 : Archive handle upper word | ||||||
|  |  *      4 : File path string type | ||||||
|  |  *      5 : File path string size | ||||||
|  |  *      7 : File size (filled with zeroes) | ||||||
|  |  *      10: File path string data | ||||||
|  |  *  Outputs: | ||||||
|  |  *      1 : Result of function, 0 on success, otherwise error code | ||||||
|  |  */ | ||||||
|  | static void CreateFile(Service::Interface* self) { | ||||||
|  |     u32* cmd_buff = Kernel::GetCommandBuffer(); | ||||||
|  | 
 | ||||||
|  |     ArchiveHandle archive_handle = MakeArchiveHandle(cmd_buff[2], cmd_buff[3]); | ||||||
|  |     auto filename_type    = static_cast<FileSys::LowPathType>(cmd_buff[4]); | ||||||
|  |     u32 filename_size     = cmd_buff[5]; | ||||||
|  |     u32 file_size         = cmd_buff[7]; | ||||||
|  |     u32 filename_ptr      = cmd_buff[10]; | ||||||
|  | 
 | ||||||
|  |     FileSys::Path file_path(filename_type, filename_size, filename_ptr); | ||||||
|  | 
 | ||||||
|  |     LOG_DEBUG(Service_FS, "type=%d size=%d data=%s", filename_type, filename_size, file_path.DebugStr().c_str()); | ||||||
|  | 
 | ||||||
|  |     cmd_buff[1] = CreateFileInArchive(archive_handle, file_path, file_size).raw; | ||||||
|  | } | ||||||
|  | 
 | ||||||
| /*
 | /*
 | ||||||
|  * FS_User::CreateDirectory service function |  * FS_User::CreateDirectory service function | ||||||
|  *  Inputs: |  *  Inputs: | ||||||
|  | @ -465,7 +494,7 @@ const FSUserInterface::FunctionInfo FunctionTable[] = { | ||||||
|     {0x08050244, RenameFile,            "RenameFile"}, |     {0x08050244, RenameFile,            "RenameFile"}, | ||||||
|     {0x08060142, DeleteDirectory,       "DeleteDirectory"}, |     {0x08060142, DeleteDirectory,       "DeleteDirectory"}, | ||||||
|     {0x08070142, nullptr,               "DeleteDirectoryRecursively"}, |     {0x08070142, nullptr,               "DeleteDirectoryRecursively"}, | ||||||
|     {0x08080202, nullptr,               "CreateFile"}, |     {0x08080202, CreateFile,            "CreateFile"}, | ||||||
|     {0x08090182, CreateDirectory,       "CreateDirectory"}, |     {0x08090182, CreateDirectory,       "CreateDirectory"}, | ||||||
|     {0x080A0244, RenameDirectory,       "RenameDirectory"}, |     {0x080A0244, RenameDirectory,       "RenameDirectory"}, | ||||||
|     {0x080B0102, OpenDirectory,         "OpenDirectory"}, |     {0x080B0102, OpenDirectory,         "OpenDirectory"}, | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue