]> Chaos Git - corbenik/ctrulib.git/commitdiff
Added CreateFile implementation, tested on hardware.
authorarchshift <admin@archshift.com>
Wed, 10 Dec 2014 08:33:08 +0000 (00:33 -0800)
committerarchshift <admin@archshift.com>
Wed, 10 Dec 2014 08:33:08 +0000 (00:33 -0800)
Information about using CreateFile was taken from Steel Diver: Sub Wars with the wonderful help of Citra.

libctru/include/3ds/services/fs.h
libctru/source/services/fs.c

index b062f8daca525fad5b4a35ef6e207b4ae6f15bdd..a20fb9b7effff84992ef16b398be69021a8e244c 100644 (file)
@@ -138,6 +138,7 @@ Result FSUSER_OpenDirectory(Handle* handle, Handle* out, FS_archive archive, FS_
 Result FSUSER_OpenFile(Handle* handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes);
 Result FSUSER_OpenFileDirectly(Handle* handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes);
 Result FSUSER_CloseArchive(Handle* handle, FS_archive* archive);
+Result FSUSER_CreateFile(Handle* handle, FS_archive archive, FS_path fileLowPath, u32 fileSize);
 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);
index e0c37fc4bc7460de6a86c0972a3fbbee697c8706..37d1796825c8bd7a8996e4f2fc273d96a4077538 100644 (file)
@@ -449,11 +449,68 @@ FSUSER_DeleteDirectoryRecursively(void)
        return -1;
 }
 
-/* stub */
+/*! Create a File
+ *
+ *  @param[in] handle      fs:USER handle
+ *  @param[in] archive     Open archive
+ *  @param[in] fileLowPath File path
+ *  @param[in] fileSize    Size of new file in bytes
+ *
+ *  @returns error
+ *
+ *  @internal
+ *
+ *  #### Request
+ *
+ *  Index Word | Description
+ *  -----------|-------------------------
+ *  0          | Header code [0x08060142]
+ *  1          | 0
+ *  2          | archive.handleLow
+ *  3          | archive.handleHigh
+ *  4          | fileLowPath.type
+ *  5          | fileLowPath.size
+ *  6          | 0
+ *  7          | fileSize
+ *  8          | 0
+ *  9          | (fileLowPath.size << 14) \| 0x2
+ *  10         | fileLowPath.data
+ *
+ *  #### Response
+ *
+ *  Index Word | Description
+ *  -----------|-------------------------
+ *  0          | Header code
+ *  1          | Result code
+ */
 Result
-FSUSER_CreateFile(void)
+FSUSER_CreateFile(Handle*    handle, 
+                  FS_archive archive, 
+                  FS_path    fileLowPath, 
+                  u32        fileSize)
 {
-       return -1;
+    if(!handle)
+        handle = &fsuHandle;
+
+    u32 *cmdbuf = getThreadCommandBuffer();
+
+    cmdbuf[0]  = 0x08080202;
+    cmdbuf[1]  = 0;
+    cmdbuf[2]  = archive.handleLow;
+    cmdbuf[3]  = archive.handleHigh;
+    cmdbuf[4]  = fileLowPath.type;
+    cmdbuf[5]  = fileLowPath.size;
+    cmdbuf[6]  = 0;
+    cmdbuf[7]  = fileSize;
+    cmdbuf[8]  = 0;
+    cmdbuf[9]  = (fileLowPath.size << 14) | 0x2;
+    cmdbuf[10] = (u32)fileLowPath.data;
+
+    Result ret = 0;
+    if((ret = svcSendSyncRequest(*handle)))
+        return ret;
+
+    return cmdbuf[1];
 }
 
 /*! Create a directory