diff --git a/libctru/include/3ds/services/am.h b/libctru/include/3ds/services/am.h index 06ce957..bf8bc95 100644 --- a/libctru/include/3ds/services/am.h +++ b/libctru/include/3ds/services/am.h @@ -116,3 +116,12 @@ About: Gets the product code of a title based on its title id. productcode buffer to output the product code to (should have a length of 16) */ Result AM_GetTitleProductCode(u8 mediatype, u64 titleID, char* productCode); + +/* AM_GetCiaFileInfo() +About: Reads a CIA file and returns a TitleList entry for it. + + mediatype destination mediatype + titleEntry ptr to a TitleList entry + fileHandle a fs:USER file handle for a CIA file +*/ +Result AM_GetCiaFileInfo(u8 mediatype, TitleList *titleEntry, Handle fileHandle); diff --git a/libctru/include/3ds/services/fs.h b/libctru/include/3ds/services/fs.h index b1498ae..be53a4d 100644 --- a/libctru/include/3ds/services/fs.h +++ b/libctru/include/3ds/services/fs.h @@ -142,6 +142,7 @@ Result FSUSER_CreateFile(Handle* handle, FS_archive archive, FS_path fileLowPath Result FSUSER_CreateDirectory(Handle* handle, FS_archive archive, FS_path dirLowPath); Result FSUSER_DeleteFile(Handle *handle, FS_archive archive, FS_path fileLowPath); Result FSUSER_DeleteDirectory(Handle *handle, FS_archive archive, FS_path dirLowPath); +Result FSUSER_DeleteDirectoryRecursively(Handle *handle, FS_archive archive, FS_path dirLowPath); Result FSUSER_RenameFile(Handle *handle, FS_archive srcArchive, FS_path srcFileLowPath, FS_archive destArchive, FS_path destFileLowPath); Result FSUSER_RenameDirectory(Handle *handle, FS_archive srcArchive, FS_path srcDirLowPath, FS_archive destArchive, FS_path destDirLowPath); Result FSUSER_GetSdmcArchiveResource(Handle *handle, u32 *sectorSize, u32 *clusterSize, u32 *numClusters, u32 *freeClusters); diff --git a/libctru/source/services/am.c b/libctru/source/services/am.c index a6f6cb3..8c0d530 100644 --- a/libctru/source/services/am.c +++ b/libctru/source/services/am.c @@ -200,3 +200,20 @@ Result AM_GetTitleProductCode(u8 mediatype, u64 titleID, char* productCode) return (Result)cmdbuf[1]; } + +Result AM_GetCiaFileInfo(u8 mediatype, TitleList *titleEntry, Handle fileHandle) +{ + Result ret = 0; + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = 0x04080042; + cmdbuf[1] = mediatype; + cmdbuf[2] = 0; + cmdbuf[3] = fileHandle; + + if((ret = svcSendSyncRequest(amHandle))!=0) return ret; + + if(titleEntry) memcpy(titleEntry, &cmdbuf[2], sizeof(TitleList)); + + return (Result)cmdbuf[1]; +} diff --git a/libctru/source/services/fs.c b/libctru/source/services/fs.c index 6a02044..cd48f6f 100644 --- a/libctru/source/services/fs.c +++ b/libctru/source/services/fs.c @@ -458,11 +458,60 @@ FSUSER_DeleteDirectory(Handle *handle, return cmdbuf[1]; } -/* stub */ +/*! Delete a directory and all sub directories/files recursively + * + * @param[in] handle fs:USER handle + * @param[in] archive Open archive + * @param[in] dirLowPath Directory path + * + * @returns error + * + * @internal + * + * #### Request + * + * Index Word | Description + * -----------|------------------------- + * 0 | Header code [0x08070142] + * 1 | 0 + * 2 | archive.handleLow + * 3 | archive.handleHigh + * 4 | dirLowPath.type + * 5 | dirLowPath.size + * 6 | (dirLowPath.size << 14) \| 0x2 + * 7 | dirLowPath.data + * + * #### Response + * + * Index Word | Description + * -----------|------------------------- + * 0 | Header code + * 1 | Result code + */ Result -FSUSER_DeleteDirectoryRecursively(void) +FSUSER_DeleteDirectoryRecursively(Handle *handle, + FS_archive archive, + FS_path dirLowPath) { - return -1; + if(!handle) + handle = &fsuHandle; + + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = 0x08070142; + cmdbuf[1] = 0; + cmdbuf[2] = archive.handleLow; + cmdbuf[3] = archive.handleHigh; + cmdbuf[4] = dirLowPath.type; + cmdbuf[5] = dirLowPath.size; + cmdbuf[6] = (dirLowPath.size << 14) | 0x2; + cmdbuf[7] = (u32)dirLowPath.data; + + Result ret = 0; + if((ret = svcSendSyncRequest(*handle))) + return ret; + + return cmdbuf[1]; } /*! Create a File