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

Function archiveMountSdmc

libctru/source/archive_dev.c:349–413  ·  view source on GitHub ↗

! Initialize SDMC device */

Source from the content-addressed store, hash-verified

347
348/*! Initialize SDMC device */
349Result archiveMountSdmc(void)
350{
351 ssize_t units;
352 uint32_t code;
353 char *p;
354 FS_Path sdmcPath = { PATH_EMPTY, 1, "" };
355 FS_Archive sdmcArchive;
356 Result rc = 0;
357
358 _archiveInit();
359
360 rc = FSUSER_OpenArchive(&sdmcArchive, ARCHIVE_SDMC, sdmcPath);
361 if(R_SUCCEEDED(rc))
362 {
363 fsExemptFromSession(sdmcArchive);
364 archive_fsdevice* device;
365 rc = _archiveMountDevice(sdmcArchive, "sdmc", &device);
366
367 if (rc != -1)
368 {
369 if (device)
370 {
371 device->device.statvfs_r = sdmc_statvfs; // set SDMC's statvfs to the device
372 }
373 if(__system_argc != 0 && __system_argv[0] != NULL)
374 {
375 if(FindDevice(__system_argv[0]) == rc)
376 {
377 strncpy(__ctru_dev_path_buf,__system_argv[0],PATH_MAX);
378 if(__ctru_dev_path_buf[PATH_MAX] != 0)
379 {
380 __ctru_dev_path_buf[PATH_MAX] = 0;
381 }
382 else
383 {
384 char *last_slash = NULL;
385 p = __ctru_dev_path_buf;
386 do
387 {
388 units = decode_utf8(&code, (const uint8_t*)p);
389 if(units < 0)
390 {
391 last_slash = NULL;
392 break;
393 }
394
395 if(code == '/')
396 last_slash = p;
397
398 p += units;
399 } while(code != 0);
400
401 if(last_slash != NULL)
402 {
403 last_slash[0] = 0;
404 chdir(__ctru_dev_path_buf);
405 }
406 }

Callers 1

__appInitFunction · 0.85

Calls 5

_archiveInitFunction · 0.85
FSUSER_OpenArchiveFunction · 0.85
fsExemptFromSessionFunction · 0.85
_archiveMountDeviceFunction · 0.85
decode_utf8Function · 0.85

Tested by

no test coverage detected