From 2815cd84c40aba741cf02498d4faa84c8ce1c82b Mon Sep 17 00:00:00 2001 From: Yuri Kunde Schlesner Date: Sat, 22 Nov 2014 20:10:00 -0200 Subject: [PATCH] Add FSUSER_RenameFile and FSUSER_RenameDirectory --- libctru/include/3ds/services/fs.h | 2 + libctru/source/services/fs.c | 142 ++++++++++++++++++++++++++++-- 2 files changed, 138 insertions(+), 6 deletions(-) diff --git a/libctru/include/3ds/services/fs.h b/libctru/include/3ds/services/fs.h index 36526f9..073f3b6 100644 --- a/libctru/include/3ds/services/fs.h +++ b/libctru/include/3ds/services/fs.h @@ -156,6 +156,8 @@ Result FSUSER_CloseArchive(Handle* handle, FS_archive* archive); 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_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); Result FSUSER_IsSdmcDetected(Handle *handle, u32 *detected); Result FSUSER_IsSdmcWritable(Handle *handle, u32 *writable); diff --git a/libctru/source/services/fs.c b/libctru/source/services/fs.c index 47946f8..7d80569 100644 --- a/libctru/source/services/fs.c +++ b/libctru/source/services/fs.c @@ -298,11 +298,76 @@ FSUSER_DeleteFile(Handle *handle, return cmdbuf[1]; } -/* stub */ +/*! Renames or moves a file. + * + * @param[in] handle fs:USER handle + * @param[in] srcArchive Open archive of source + * @param[in] srcFileLowPath File path to source + * @param[in] destArchive Open archive of destination + * @param[in] destFileLowPath File path to destination + * + * @returns error + * + * @internal + * + * #### Request + * + * Index Word | Description + * -----------|------------------------- + * 0 | Header code [0x08050244] + * 1 | 0 + * 2 | srcArchive.handleLow + * 3 | srcArchive.handleHigh + * 4 | srcFileLowPath.type + * 5 | srcFileLowPath.size + * 6 | destArchive.handleLow + * 7 | destArchive.handleHigh + * 8 | destFileLowPath.type + * 9 | destFileLowPath.size + * 10 | (srcFileLowPath.size << 14) \| 0x2 + * 11 | srcFileLowPath.data + * 12 | (destFileLowPath.size << 14) \| 0x2 + * 13 | destFileLowPath.data + * + * #### Response + * + * Index Word | Description + * -----------|------------------------- + * 0 | Header code + * 1 | Result code + */ Result -FSUSER_RenameFile(void) +FSUSER_RenameFile(Handle *handle, + FS_archive srcArchive, + FS_path srcFileLowPath, + FS_archive destArchive, + FS_path destFileLowPath) { - return -1; + if(!handle) + handle = &fsuHandle; + + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = 0x08050244; + cmdbuf[1] = 0; + cmdbuf[2] = srcArchive.handleLow; + cmdbuf[3] = srcArchive.handleHigh; + cmdbuf[4] = srcFileLowPath.type; + cmdbuf[5] = srcFileLowPath.size; + cmdbuf[6] = destArchive.handleLow; + cmdbuf[7] = destArchive.handleHigh; + cmdbuf[8] = destFileLowPath.type; + cmdbuf[9] = destFileLowPath.size; + cmdbuf[10] = (srcFileLowPath.size << 14) | 0x402; + cmdbuf[11] = (u32)srcFileLowPath.data; + cmdbuf[12] = (destFileLowPath.size << 14) | 0x802; + cmdbuf[13] = (u32)destFileLowPath.data; + + Result ret = 0; + if((ret = svcSendSyncRequest(*handle))) + return ret; + + return cmdbuf[1]; } /*! Delete a directory @@ -433,11 +498,76 @@ FSUSER_CreateDirectory(Handle *handle, return cmdbuf[1]; } -/* stub */ +/*! Renames or moves a directory. + * + * @param[in] handle fs:USER handle + * @param[in] srcArchive Open archive of source + * @param[in] srcDirLowPath Dir path to source + * @param[in] destArchive Open archive of destination + * @param[in] destDirLowPath Dir path to destination + * + * @returns error + * + * @internal + * + * #### Request + * + * Index Word | Description + * -----------|------------------------- + * 0 | Header code [0x08050244] + * 1 | 0 + * 2 | srcArchive.handleLow + * 3 | srcArchive.handleHigh + * 4 | srcDirLowPath.type + * 5 | srcDirLowPath.size + * 6 | destArchive.handleLow + * 7 | destArchive.handleHigh + * 8 | destDirLowPath.type + * 9 | destDirLowPath.size + * 10 | (srcDirLowPath.size << 14) \| 0x2 + * 11 | srcDirLowPath.data + * 12 | (destDirLowPath.size << 14) \| 0x2 + * 13 | destDirLowPath.data + * + * #### Response + * + * Index Word | Description + * -----------|------------------------- + * 0 | Header code + * 1 | Result code + */ Result -FSUSER_RenameDirectory(void) +FSUSER_RenameDirectory(Handle *handle, + FS_archive srcArchive, + FS_path srcDirLowPath, + FS_archive destArchive, + FS_path destDirLowPath) { - return -1; + if(!handle) + handle = &fsuHandle; + + u32 *cmdbuf = getThreadCommandBuffer(); + + cmdbuf[0] = 0x080A0244; + cmdbuf[1] = 0; + cmdbuf[2] = srcArchive.handleLow; + cmdbuf[3] = srcArchive.handleHigh; + cmdbuf[4] = srcDirLowPath.type; + cmdbuf[5] = srcDirLowPath.size; + cmdbuf[6] = destArchive.handleLow; + cmdbuf[7] = destArchive.handleHigh; + cmdbuf[8] = destDirLowPath.type; + cmdbuf[9] = destDirLowPath.size; + cmdbuf[10] = (srcDirLowPath.size << 14) | 0x402; + cmdbuf[11] = (u32)srcDirLowPath.data; + cmdbuf[12] = (destDirLowPath.size << 14) | 0x802; + cmdbuf[13] = (u32)destDirLowPath.data; + + Result ret = 0; + if((ret = svcSendSyncRequest(*handle))) + return ret; + + return cmdbuf[1]; } /*! Open a directory