MCPcopy Create free account
hub / github.com/devkitPro/libctru / romfsMountSelf

Function romfsMountSelf

libctru/source/romfs_dev.c:234–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

232}
233
234Result romfsMountSelf(const char* name)
235{
236 // If we are not 3DSX, we need to mount this process' real RomFS
237 if (!envIsHomebrew())
238 return romfsMountFromCurrentProcess(name);
239
240 // Otherwise, we use the embedded RomFS inside the 3DSX file
241 // Retrieve the filename of our 3DSX file
242 const char* filename = __romfs_path;
243 if (__system_argc > 0 && __system_argv[0])
244 filename = __system_argv[0];
245 if (!filename)
246 return MAKERESULT(RL_USAGE, RS_INVALIDARG, RM_ROMFS, RD_NO_DATA);
247
248 // Adjust the path name
249 if (strncmp(filename, "sdmc:/", 6) == 0)
250 filename += 5;
251 else if (strncmp(filename, "3dslink:/", 9) == 0)
252 {
253 strncpy(__ctru_dev_path_buf, "/3ds", PATH_MAX);
254 strncat(__ctru_dev_path_buf, filename+8, PATH_MAX);
255 __ctru_dev_path_buf[PATH_MAX] = 0;
256 filename = __ctru_dev_path_buf;
257 }
258 else
259 return MAKERESULT(RL_USAGE, RS_NOTSUPPORTED, RM_ROMFS, RD_NOT_IMPLEMENTED);
260
261 // Convert the path to UTF-16
262 ssize_t units = utf8_to_utf16(__ctru_dev_utf16_buf, (const uint8_t*)filename, PATH_MAX);
263 if (units < 0 || units > PATH_MAX)
264 return MAKERESULT(RL_USAGE, RS_INVALIDARG, RM_ROMFS, RD_OUT_OF_RANGE);
265 __ctru_dev_utf16_buf[units] = 0;
266
267 // Open the file directly
268 Handle fd = 0;
269 FS_Path archPath = { PATH_EMPTY, 1, "" };
270 FS_Path filePath = { PATH_UTF16, (units+1)*2, __ctru_dev_utf16_buf };
271 Result rc = FSUSER_OpenFileDirectly(&fd, ARCHIVE_SDMC, archPath, filePath, FS_OPEN_READ, 0);
272 if (R_FAILED(rc))
273 return rc;
274
275 // Read and parse the header
276 _3DSX_Header hdr;
277 u32 bytesRead = 0;
278 rc = FSFILE_Read(fd, &bytesRead, 0, &hdr, sizeof(hdr));
279 if (R_FAILED(rc))
280 {
281 FSFILE_Close(fd);
282 return rc;
283 }
284
285 // Validate the 3DSX header
286 if (bytesRead != sizeof(hdr) || hdr.magic != _3DSX_MAGIC || hdr.headerSize < sizeof(hdr))
287 {
288 FSFILE_Close(fd);
289 return MAKERESULT(RL_FATAL, RS_NOTFOUND, RM_ROMFS, RD_NOT_FOUND);
290 }
291

Callers 1

romfsInitFunction · 0.85

Calls 7

envIsHomebrewFunction · 0.85
utf8_to_utf16Function · 0.85
FSUSER_OpenFileDirectlyFunction · 0.85
FSFILE_ReadFunction · 0.85
FSFILE_CloseFunction · 0.85
romfsMountFromFileFunction · 0.85

Tested by

no test coverage detected