1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
|
// Copyright 2014 Citra Emulator Project
// Licensed under GPLv2 or any later version
// Refer to the license.txt file included.
#include "common/archives.h"
#include "common/assert.h"
#include "common/common_types.h"
#include "common/file_util.h"
#include "common/logging/log.h"
#include "common/scope_exit.h"
#include "common/settings.h"
#include "common/string_util.h"
#include "core/core.h"
#include "core/file_sys/errors.h"
#include "core/file_sys/ncch_container.h"
#include "core/file_sys/seed_db.h"
#include "core/hle/ipc.h"
#include "core/hle/ipc_helpers.h"
#include "core/hle/kernel/client_port.h"
#include "core/hle/kernel/client_session.h"
#include "core/hle/kernel/event.h"
#include "core/hle/kernel/process.h"
#include "core/hle/kernel/server_session.h"
#include "core/hle/result.h"
#include "core/hle/service/am/am.h"
#include "core/hle/service/fs/archive.h"
#include "core/hle/service/fs/fs_user.h"
SERVICE_CONSTRUCT_IMPL(Service::FS::FS_USER)
SERIALIZE_EXPORT_IMPL(Service::FS::FS_USER)
SERIALIZE_EXPORT_IMPL(Service::FS::ClientSlot)
using Kernel::ClientSession;
using Kernel::ServerSession;
namespace Service::FS {
void FS_USER::Initialize(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
u32 pid = rp.PopPID();
ClientSlot* slot = GetSessionData(ctx.Session());
slot->program_id = system.Kernel().GetProcessById(pid)->codeset->program_id;
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultSuccess);
}
void FS_USER::OpenFile(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
rp.Skip(1, false); // Transaction.
const auto archive_handle = rp.PopRaw<ArchiveHandle>();
const auto filename_type = rp.PopEnum<FileSys::LowPathType>();
const auto filename_size = rp.Pop<u32>();
const FileSys::Mode mode{rp.Pop<u32>()};
const auto attributes = rp.Pop<u32>(); // TODO(Link Mauve): do something with those attributes.
std::vector<u8> filename = rp.PopStaticBuffer();
ASSERT(filename.size() == filename_size);
const FileSys::Path file_path(filename_type, std::move(filename));
LOG_DEBUG(Service_FS, "path={}, mode={} attrs={}", file_path.DebugStr(), mode.hex, attributes);
const auto [file_res, open_timeout_ns] =
archives.OpenFileFromArchive(archive_handle, file_path, mode);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
rb.Push(file_res.Code());
if (file_res.Succeeded()) {
std::shared_ptr<File> file = *file_res;
rb.PushMoveObjects(file->Connect());
} else {
rb.PushMoveObjects<Kernel::Object>(nullptr);
LOG_DEBUG(Service_FS, "failed to get a handle for file {}", file_path.DebugStr());
}
ctx.SleepClientThread("fs_user::open", open_timeout_ns, nullptr);
}
void FS_USER::OpenFileDirectly(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
rp.Skip(1, false); // Transaction
const auto archive_id = rp.PopEnum<ArchiveIdCode>();
const auto archivename_type = rp.PopEnum<FileSys::LowPathType>();
const auto archivename_size = rp.Pop<u32>();
const auto filename_type = rp.PopEnum<FileSys::LowPathType>();
const auto filename_size = rp.Pop<u32>();
const FileSys::Mode mode{rp.Pop<u32>()};
const auto attributes = rp.Pop<u32>(); // TODO(Link Mauve): do something with those attributes.
std::vector<u8> archivename = rp.PopStaticBuffer();
std::vector<u8> filename = rp.PopStaticBuffer();
ASSERT(archivename.size() == archivename_size);
ASSERT(filename.size() == filename_size);
const FileSys::Path archive_path(archivename_type, std::move(archivename));
const FileSys::Path file_path(filename_type, std::move(filename));
LOG_DEBUG(Service_FS, "archive_id=0x{:08X} archive_path={} file_path={}, mode={} attributes={}",
archive_id, archive_path.DebugStr(), file_path.DebugStr(), mode.hex, attributes);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
ClientSlot* slot = GetSessionData(ctx.Session());
ResultVal<ArchiveHandle> archive_handle =
archives.OpenArchive(archive_id, archive_path, slot->program_id);
if (archive_handle.Failed()) {
LOG_ERROR(Service_FS,
"Failed to get a handle for archive archive_id=0x{:08X} archive_path={}",
archive_id, archive_path.DebugStr());
rb.Push(archive_handle.Code());
rb.PushMoveObjects<Kernel::Object>(nullptr);
return;
}
SCOPE_EXIT({ archives.CloseArchive(*archive_handle); });
const auto [file_res, open_timeout_ns] =
archives.OpenFileFromArchive(*archive_handle, file_path, mode);
rb.Push(file_res.Code());
if (file_res.Succeeded()) {
std::shared_ptr<File> file = *file_res;
rb.PushMoveObjects(file->Connect());
} else {
rb.PushMoveObjects<Kernel::Object>(nullptr);
LOG_ERROR(Service_FS, "failed to get a handle for file {} mode={} attributes={}",
file_path.DebugStr(), mode.hex, attributes);
}
ctx.SleepClientThread("fs_user::open_directly", open_timeout_ns, nullptr);
}
void FS_USER::DeleteFile(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
rp.Skip(1, false); // TransactionId
const auto archive_handle = rp.PopRaw<ArchiveHandle>();
const auto filename_type = rp.PopEnum<FileSys::LowPathType>();
const auto filename_size = rp.Pop<u32>();
std::vector<u8> filename = rp.PopStaticBuffer();
ASSERT(filename.size() == filename_size);
const FileSys::Path file_path(filename_type, std::move(filename));
LOG_DEBUG(Service_FS, "type={} size={} data={}", filename_type, filename_size,
file_path.DebugStr());
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(archives.DeleteFileFromArchive(archive_handle, file_path));
}
void FS_USER::RenameFile(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
rp.Skip(1, false); // TransactionId
const auto src_archive_handle = rp.PopRaw<ArchiveHandle>();
const auto src_filename_type = rp.PopEnum<FileSys::LowPathType>();
const auto src_filename_size = rp.Pop<u32>();
const auto dest_archive_handle = rp.PopRaw<ArchiveHandle>();
const auto dest_filename_type = rp.PopEnum<FileSys::LowPathType>();
const auto dest_filename_size = rp.Pop<u32>();
std::vector<u8> src_filename = rp.PopStaticBuffer();
std::vector<u8> dest_filename = rp.PopStaticBuffer();
ASSERT(src_filename.size() == src_filename_size);
ASSERT(dest_filename.size() == dest_filename_size);
const FileSys::Path src_file_path(src_filename_type, std::move(src_filename));
const FileSys::Path dest_file_path(dest_filename_type, std::move(dest_filename));
LOG_DEBUG(Service_FS,
"src_type={} src_size={} src_data={} dest_type={} dest_size={} dest_data={}",
src_filename_type, src_filename_size, src_file_path.DebugStr(), dest_filename_type,
dest_filename_size, dest_file_path.DebugStr());
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(archives.RenameFileBetweenArchives(src_archive_handle, src_file_path,
dest_archive_handle, dest_file_path));
}
void FS_USER::DeleteDirectory(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
rp.Skip(1, false); // TransactionId
const auto archive_handle = rp.PopRaw<ArchiveHandle>();
const auto dirname_type = rp.PopEnum<FileSys::LowPathType>();
const auto dirname_size = rp.Pop<u32>();
std::vector<u8> dirname = rp.PopStaticBuffer();
ASSERT(dirname.size() == dirname_size);
const FileSys::Path dir_path(dirname_type, std::move(dirname));
LOG_DEBUG(Service_FS, "type={} size={} data={}", dirname_type, dirname_size,
dir_path.DebugStr());
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(archives.DeleteDirectoryFromArchive(archive_handle, dir_path));
}
void FS_USER::DeleteDirectoryRecursively(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
rp.Skip(1, false); // TransactionId
const auto archive_handle = rp.PopRaw<ArchiveHandle>();
const auto dirname_type = rp.PopEnum<FileSys::LowPathType>();
const auto dirname_size = rp.Pop<u32>();
std::vector<u8> dirname = rp.PopStaticBuffer();
ASSERT(dirname.size() == dirname_size);
const FileSys::Path dir_path(dirname_type, std::move(dirname));
LOG_DEBUG(Service_FS, "type={} size={} data={}", dirname_type, dirname_size,
dir_path.DebugStr());
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(archives.DeleteDirectoryRecursivelyFromArchive(archive_handle, dir_path));
}
void FS_USER::CreateFile(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
rp.Skip(1, false); // TransactionId
const auto archive_handle = rp.PopRaw<ArchiveHandle>();
const auto filename_type = rp.PopEnum<FileSys::LowPathType>();
const auto filename_size = rp.Pop<u32>();
const auto attributes = rp.Pop<u32>();
const auto file_size = rp.Pop<u64>();
std::vector<u8> filename = rp.PopStaticBuffer();
ASSERT(filename.size() == filename_size);
const FileSys::Path file_path(filename_type, std::move(filename));
LOG_DEBUG(Service_FS, "type={} attributes={} size={:x} data={}", filename_type, attributes,
file_size, file_path.DebugStr());
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(archives.CreateFileInArchive(archive_handle, file_path, file_size));
}
void FS_USER::CreateDirectory(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
rp.Skip(1, false); // TransactionId
const auto archive_handle = rp.PopRaw<ArchiveHandle>();
const auto dirname_type = rp.PopEnum<FileSys::LowPathType>();
const auto dirname_size = rp.Pop<u32>();
[[maybe_unused]] const auto attributes = rp.Pop<u32>();
std::vector<u8> dirname = rp.PopStaticBuffer();
ASSERT(dirname.size() == dirname_size);
const FileSys::Path dir_path(dirname_type, std::move(dirname));
LOG_DEBUG(Service_FS, "type={} size={} data={}", dirname_type, dirname_size,
dir_path.DebugStr());
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(archives.CreateDirectoryFromArchive(archive_handle, dir_path));
}
void FS_USER::RenameDirectory(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
rp.Skip(1, false); // TransactionId
const auto src_archive_handle = rp.PopRaw<ArchiveHandle>();
const auto src_dirname_type = rp.PopEnum<FileSys::LowPathType>();
const auto src_dirname_size = rp.Pop<u32>();
const auto dest_archive_handle = rp.PopRaw<ArchiveHandle>();
const auto dest_dirname_type = rp.PopEnum<FileSys::LowPathType>();
const auto dest_dirname_size = rp.Pop<u32>();
std::vector<u8> src_dirname = rp.PopStaticBuffer();
std::vector<u8> dest_dirname = rp.PopStaticBuffer();
ASSERT(src_dirname.size() == src_dirname_size);
ASSERT(dest_dirname.size() == dest_dirname_size);
const FileSys::Path src_dir_path(src_dirname_type, std::move(src_dirname));
const FileSys::Path dest_dir_path(dest_dirname_type, std::move(dest_dirname));
LOG_DEBUG(Service_FS,
"src_type={} src_size={} src_data={} dest_type={} dest_size={} dest_data={}",
src_dirname_type, src_dirname_size, src_dir_path.DebugStr(), dest_dirname_type,
dest_dirname_size, dest_dir_path.DebugStr());
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(archives.RenameDirectoryBetweenArchives(src_archive_handle, src_dir_path,
dest_archive_handle, dest_dir_path));
}
void FS_USER::OpenDirectory(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const auto archive_handle = rp.PopRaw<ArchiveHandle>();
const auto dirname_type = rp.PopEnum<FileSys::LowPathType>();
const auto dirname_size = rp.Pop<u32>();
std::vector<u8> dirname = rp.PopStaticBuffer();
ASSERT(dirname.size() == dirname_size);
const FileSys::Path dir_path(dirname_type, std::move(dirname));
LOG_DEBUG(Service_FS, "type={} size={} data={}", dirname_type, dirname_size,
dir_path.DebugStr());
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
ResultVal<std::shared_ptr<Directory>> dir_res =
archives.OpenDirectoryFromArchive(archive_handle, dir_path);
rb.Push(dir_res.Code());
if (dir_res.Succeeded()) {
std::shared_ptr<Directory> directory = *dir_res;
auto [server, client] = system.Kernel().CreateSessionPair(directory->GetName());
directory->ClientConnected(server);
rb.PushMoveObjects(client);
} else {
LOG_ERROR(Service_FS, "failed to get a handle for directory type={} size={} data={}",
dirname_type, dirname_size, dir_path.DebugStr());
rb.PushMoveObjects<Kernel::Object>(nullptr);
}
}
void FS_USER::OpenArchive(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const auto archive_id = rp.PopEnum<FS::ArchiveIdCode>();
const auto archivename_type = rp.PopEnum<FileSys::LowPathType>();
const auto archivename_size = rp.Pop<u32>();
std::vector<u8> archivename = rp.PopStaticBuffer();
ASSERT(archivename.size() == archivename_size);
const FileSys::Path archive_path(archivename_type, std::move(archivename));
LOG_DEBUG(Service_FS, "archive_id=0x{:08X} archive_path={}", archive_id,
archive_path.DebugStr());
IPC::RequestBuilder rb = rp.MakeBuilder(3, 0);
ClientSlot* slot = GetSessionData(ctx.Session());
const ResultVal<ArchiveHandle> handle =
archives.OpenArchive(archive_id, archive_path, slot->program_id);
rb.Push(handle.Code());
if (handle.Succeeded()) {
rb.PushRaw(*handle);
} else {
rb.Push<u64>(0);
LOG_ERROR(Service_FS,
"failed to get a handle for archive archive_id=0x{:08X} archive_path={}",
archive_id, archive_path.DebugStr());
}
}
void FS_USER::ControlArchive(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const auto archive_handle = rp.PopRaw<ArchiveHandle>();
const auto action = rp.Pop<u32>();
const auto input_size = rp.Pop<u32>();
const auto output_size = rp.Pop<u32>();
[[maybe_unused]] const auto input = rp.PopMappedBuffer();
[[maybe_unused]] const auto output = rp.PopMappedBuffer();
LOG_WARNING(Service_FS,
"(STUBBED) called, archive_handle={:016X}, action={:08X}, input_size={:08X}, "
"output_size={:08X}",
archive_handle, action, input_size, output_size);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultSuccess);
}
void FS_USER::CloseArchive(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const auto archive_handle = rp.PopRaw<ArchiveHandle>();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(archives.CloseArchive(archive_handle));
}
void FS_USER::IsSdmcDetected(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(ResultSuccess);
rb.Push(Settings::values.use_virtual_sd.GetValue());
}
void FS_USER::IsSdmcWriteable(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(ResultSuccess);
// If the SD isn't enabled, it can't be writeable...else, stubbed true
rb.Push(Settings::values.use_virtual_sd.GetValue());
LOG_DEBUG(Service_FS, " (STUBBED)");
}
void FS_USER::FormatSaveData(Kernel::HLERequestContext& ctx) {
LOG_WARNING(Service_FS, "(STUBBED)");
IPC::RequestParser rp(ctx);
const auto archive_id = rp.PopEnum<ArchiveIdCode>();
const auto archivename_type = rp.PopEnum<FileSys::LowPathType>();
const auto archivename_size = rp.Pop<u32>();
const auto block_size = rp.Pop<u32>();
const auto number_directories = rp.Pop<u32>();
const auto number_files = rp.Pop<u32>();
[[maybe_unused]] const auto directory_buckets = rp.Pop<u32>();
[[maybe_unused]] const auto file_buckets = rp.Pop<u32>();
const bool duplicate_data = rp.Pop<bool>();
std::vector<u8> archivename = rp.PopStaticBuffer();
ASSERT(archivename.size() == archivename_size);
const FileSys::Path archive_path(archivename_type, std::move(archivename));
LOG_DEBUG(Service_FS, "archive_path={}", archive_path.DebugStr());
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
if (archive_id != FS::ArchiveIdCode::SaveData) {
LOG_ERROR(Service_FS, "tried to format an archive different than SaveData, {}", archive_id);
rb.Push(FileSys::ResultInvalidPath);
return;
}
if (archive_path.GetType() != FileSys::LowPathType::Empty) {
// TODO(Subv): Implement formatting the SaveData of other games
LOG_ERROR(Service_FS, "archive LowPath type other than empty is currently unsupported");
rb.Push(UnimplementedFunction(ErrorModule::FS));
return;
}
FileSys::ArchiveFormatInfo format_info;
format_info.duplicate_data = duplicate_data;
format_info.number_directories = number_directories;
format_info.number_files = number_files;
format_info.total_size = block_size * 512;
ClientSlot* slot = GetSessionData(ctx.Session());
rb.Push(archives.FormatArchive(ArchiveIdCode::SaveData, format_info, archive_path,
slot->program_id));
}
void FS_USER::FormatThisUserSaveData(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const auto block_size = rp.Pop<u32>();
const auto number_directories = rp.Pop<u32>();
const auto number_files = rp.Pop<u32>();
[[maybe_unused]] const auto directory_buckets = rp.Pop<u32>();
[[maybe_unused]] const auto file_buckets = rp.Pop<u32>();
const auto duplicate_data = rp.Pop<bool>();
FileSys::ArchiveFormatInfo format_info;
format_info.duplicate_data = duplicate_data;
format_info.number_directories = number_directories;
format_info.number_files = number_files;
format_info.total_size = block_size * 512;
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
ClientSlot* slot = GetSessionData(ctx.Session());
rb.Push(archives.FormatArchive(ArchiveIdCode::SaveData, format_info, FileSys::Path(),
slot->program_id));
LOG_TRACE(Service_FS, "called");
}
void FS_USER::GetFreeBytes(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const auto archive_handle = rp.PopRaw<ArchiveHandle>();
ResultVal<u64> bytes_res = archives.GetFreeBytesInArchive(archive_handle);
IPC::RequestBuilder rb = rp.MakeBuilder(3, 0);
rb.Push(bytes_res.Code());
if (bytes_res.Succeeded()) {
rb.Push<u64>(bytes_res.Unwrap());
} else {
rb.Push<u64>(0);
}
}
void FS_USER::GetSdmcArchiveResource(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
LOG_WARNING(Service_FS, "(STUBBED) called");
auto resource = archives.GetArchiveResource(MediaType::SDMC);
if (resource.Failed()) {
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(resource.Code());
return;
}
IPC::RequestBuilder rb = rp.MakeBuilder(5, 0);
rb.Push(ResultSuccess);
rb.PushRaw(*resource);
}
void FS_USER::GetNandArchiveResource(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
LOG_WARNING(Service_FS, "(STUBBED) called");
auto resource = archives.GetArchiveResource(MediaType::NAND);
if (resource.Failed()) {
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(resource.Code());
return;
}
IPC::RequestBuilder rb = rp.MakeBuilder(5, 0);
rb.Push(ResultSuccess);
rb.PushRaw(*resource);
}
void FS_USER::CreateExtSaveData(Kernel::HLERequestContext& ctx) {
// TODO(Subv): Figure out the other parameters.
IPC::RequestParser rp(ctx);
MediaType media_type = static_cast<MediaType>(rp.Pop<u32>()); // the other bytes are unknown
u32 save_low = rp.Pop<u32>();
u32 save_high = rp.Pop<u32>();
u32 unknown = rp.Pop<u32>();
u32 directories = rp.Pop<u32>();
u32 files = rp.Pop<u32>();
u64 size_limit = rp.Pop<u64>();
u32 icon_size = rp.Pop<u32>();
auto icon_buffer = rp.PopMappedBuffer();
std::vector<u8> icon(icon_size);
icon_buffer.Read(icon.data(), 0, icon_size);
FileSys::ArchiveFormatInfo format_info;
format_info.number_directories = directories;
format_info.number_files = files;
format_info.duplicate_data = false;
format_info.total_size = 0;
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
ClientSlot* slot = GetSessionData(ctx.Session());
rb.Push(archives.CreateExtSaveData(media_type, save_high, save_low, icon, format_info,
slot->program_id));
rb.PushMappedBuffer(icon_buffer);
LOG_DEBUG(Service_FS,
"called, savedata_high={:08X} savedata_low={:08X} unknown={:08X} "
"files={:08X} directories={:08X} size_limit={:016x} icon_size={:08X}",
save_high, save_low, unknown, directories, files, size_limit, icon_size);
}
void FS_USER::DeleteExtSaveData(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
MediaType media_type = static_cast<MediaType>(rp.Pop<u32>()); // the other bytes are unknown
u32 save_low = rp.Pop<u32>();
u32 save_high = rp.Pop<u32>();
u32 unknown = rp.Pop<u32>(); // TODO(Subv): Figure out what this is
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(archives.DeleteExtSaveData(media_type, save_high, save_low));
LOG_DEBUG(Service_FS,
"called, save_low={:08X} save_high={:08X} media_type={:08X} unknown={:08X}", save_low,
save_high, media_type, unknown);
}
void FS_USER::CardSlotIsInserted(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(ResultSuccess);
rb.Push(false);
LOG_WARNING(Service_FS, "(STUBBED) called");
}
void FS_USER::DeleteSystemSaveData(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
u32 savedata_high = rp.Pop<u32>();
u32 savedata_low = rp.Pop<u32>();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(archives.DeleteSystemSaveData(savedata_high, savedata_low));
}
void FS_USER::CreateSystemSaveData(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
u32 savedata_high = rp.Pop<u32>();
u32 savedata_low = rp.Pop<u32>();
u32 total_size = rp.Pop<u32>();
u32 block_size = rp.Pop<u32>();
u32 directories = rp.Pop<u32>();
u32 files = rp.Pop<u32>();
u32 directory_buckets = rp.Pop<u32>();
u32 file_buckets = rp.Pop<u32>();
bool duplicate = rp.Pop<bool>();
LOG_WARNING(
Service_FS,
"(STUBBED) savedata_high={:08X} savedata_low={:08X} total_size={:08X} block_size={:08X} "
"directories={} files={} directory_buckets={} file_buckets={} duplicate={}",
savedata_high, savedata_low, total_size, block_size, directories, files, directory_buckets,
file_buckets, duplicate);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(archives.CreateSystemSaveData(savedata_high, savedata_low));
}
void FS_USER::CreateLegacySystemSaveData(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
u32 savedata_id = rp.Pop<u32>();
u32 total_size = rp.Pop<u32>();
u32 block_size = rp.Pop<u32>();
u32 directories = rp.Pop<u32>();
u32 files = rp.Pop<u32>();
u32 directory_buckets = rp.Pop<u32>();
u32 file_buckets = rp.Pop<u32>();
bool duplicate = rp.Pop<bool>();
LOG_WARNING(Service_FS,
"(STUBBED) savedata_id={:08X} total_size={:08X} block_size={:08X} directories={} "
"files={} directory_buckets={} file_buckets={} duplicate={}",
savedata_id, total_size, block_size, directories, files, directory_buckets,
file_buckets, duplicate);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
// With this command, the SystemSaveData always has save_high = 0 (Always created in the NAND)
rb.Push(archives.CreateSystemSaveData(0, savedata_id));
}
void FS_USER::InitializeWithSdkVersion(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u32 version = rp.Pop<u32>();
u32 pid = rp.PopPID();
ClientSlot* slot = GetSessionData(ctx.Session());
slot->program_id = system.Kernel().GetProcessById(pid)->codeset->program_id;
LOG_WARNING(Service_FS, "(STUBBED) called, version: 0x{:08X}", version);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultSuccess);
}
void FS_USER::SetPriority(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
priority = rp.Pop<u32>();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultSuccess);
LOG_DEBUG(Service_FS, "called priority=0x{:X}", priority);
}
void FS_USER::GetPriority(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
if (priority == UINT32_MAX) {
LOG_INFO(Service_FS, "priority was not set, priority=0x{:X}", priority);
}
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(ResultSuccess);
rb.Push(priority);
LOG_DEBUG(Service_FS, "called priority=0x{:X}", priority);
}
void FS_USER::GetArchiveResource(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
auto media_type = rp.PopEnum<MediaType>();
LOG_WARNING(Service_FS, "(STUBBED) called Media type=0x{:08X}", media_type);
auto resource = archives.GetArchiveResource(media_type);
if (resource.Failed()) {
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(resource.Code());
return;
}
IPC::RequestBuilder rb = rp.MakeBuilder(5, 0);
rb.Push(ResultSuccess);
rb.PushRaw(*resource);
}
void FS_USER::GetFormatInfo(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const auto archive_id = rp.PopEnum<FS::ArchiveIdCode>();
const auto archivename_type = rp.PopEnum<FileSys::LowPathType>();
const auto archivename_size = rp.Pop<u32>();
std::vector<u8> archivename = rp.PopStaticBuffer();
ASSERT(archivename.size() == archivename_size);
const FileSys::Path archive_path(archivename_type, std::move(archivename));
LOG_DEBUG(Service_FS, "archive_path={}", archive_path.DebugStr());
IPC::RequestBuilder rb = rp.MakeBuilder(5, 0);
ClientSlot* slot = GetSessionData(ctx.Session());
auto format_info = archives.GetArchiveFormatInfo(archive_id, archive_path, slot->program_id);
rb.Push(format_info.Code());
if (format_info.Failed()) {
LOG_ERROR(Service_FS, "Failed to retrieve the format info");
rb.Skip(4, true);
return;
}
rb.Push<u32>(format_info->total_size);
rb.Push<u32>(format_info->number_directories);
rb.Push<u32>(format_info->number_files);
rb.Push<bool>(format_info->duplicate_data != 0);
}
void FS_USER::GetProductInfo(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
u32 process_id = rp.Pop<u32>();
LOG_DEBUG(Service_FS, "called, process_id={}", process_id);
IPC::RequestBuilder rb = rp.MakeBuilder(6, 0);
const auto product_info = GetProductInfo(process_id);
if (!product_info.has_value()) {
rb.Push(Result(FileSys::ErrCodes::ArchiveNotMounted, ErrorModule::FS,
ErrorSummary::NotFound, ErrorLevel::Status));
return;
}
rb.Push(ResultSuccess);
rb.PushRaw<ProductInfo>(product_info.value());
}
void FS_USER::GetProgramLaunchInfo(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const auto process_id = rp.Pop<u32>();
LOG_DEBUG(Service_FS, "process_id={}", process_id);
IPC::RequestBuilder rb = rp.MakeBuilder(5, 0);
auto program_info_result = GetProgramLaunchInfo(process_id);
if (program_info_result.Failed()) {
// Note: In this case, the rest of the parameters are not changed but the command header
// remains the same.
rb.Push(program_info_result.Code());
rb.Skip(4, false);
return;
}
ProgramInfo program_info = program_info_result.Unwrap();
// Always report the launched program mediatype is SD if the friends module is requesting this
// information and the media type is game card. Otherwise, friends will append a "romid" field
// to the NASC request with a cartridge unique identifier. Using a dump of a game card and the
// game card itself at the same time online is known to have caused issues in the past.
auto process = ctx.ClientThread()->owner_process.lock();
if (process && process->codeset->name == "friends" &&
program_info.media_type == MediaType::GameCard) {
program_info.media_type = MediaType::SDMC;
}
rb.Push(ResultSuccess);
rb.PushRaw<ProgramInfo>(program_info);
}
void FS_USER::ObsoletedCreateExtSaveData(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
MediaType media_type = static_cast<MediaType>(rp.Pop<u8>());
u32 save_low = rp.Pop<u32>();
u32 save_high = rp.Pop<u32>();
u32 icon_size = rp.Pop<u32>();
u32 directories = rp.Pop<u32>();
u32 files = rp.Pop<u32>();
auto icon_buffer = rp.PopMappedBuffer();
std::vector<u8> icon(icon_size);
icon_buffer.Read(icon.data(), 0, icon_size);
FileSys::ArchiveFormatInfo format_info;
format_info.number_directories = directories;
format_info.number_files = files;
format_info.duplicate_data = false;
format_info.total_size = 0;
IPC::RequestBuilder rb = rp.MakeBuilder(1, 2);
ClientSlot* slot = GetSessionData(ctx.Session());
rb.Push(archives.CreateExtSaveData(media_type, save_high, save_low, icon, format_info,
slot->program_id));
rb.PushMappedBuffer(icon_buffer);
LOG_DEBUG(Service_FS,
"called, savedata_high={:08X} savedata_low={:08X} "
"icon_size={:08X} files={:08X} directories={:08X}",
save_high, save_low, icon_size, directories, files);
}
void FS_USER::ObsoletedDeleteExtSaveData(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
MediaType media_type = static_cast<MediaType>(rp.Pop<u8>());
u32 save_low = rp.Pop<u32>();
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(archives.DeleteExtSaveData(media_type, 0, save_low));
LOG_DEBUG(Service_FS, "called, save_low={:08X} media_type={:08X}", save_low, media_type);
}
void FS_USER::GetSpecialContentIndex(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const MediaType media_type = static_cast<MediaType>(rp.Pop<u8>());
const u64 title_id = rp.Pop<u64>();
const auto type = rp.PopEnum<SpecialContentType>();
LOG_DEBUG(Service_FS, "called, media_type={:08X} type={:08X}, title_id={:016X}", media_type,
type, title_id);
ResultVal<u16> index;
if (media_type == MediaType::GameCard) {
index = GetSpecialContentIndexFromGameCard(title_id, type);
} else {
index = GetSpecialContentIndexFromTMD(media_type, title_id, type);
}
if (index.Succeeded()) {
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(ResultSuccess);
rb.Push(index.Unwrap());
} else {
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(index.Code());
}
}
void FS_USER::GetNumSeeds(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
IPC::RequestBuilder rb = rp.MakeBuilder(2, 0);
rb.Push(ResultSuccess);
rb.Push<u32>(FileSys::GetSeedCount());
}
void FS_USER::AddSeed(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
u64 title_id{rp.Pop<u64>()};
FileSys::Seed::Data seed{rp.PopRaw<FileSys::Seed::Data>()};
FileSys::AddSeed({title_id, seed, {}});
IPC::RequestBuilder rb{rp.MakeBuilder(1, 0)};
rb.Push(ResultSuccess);
}
void FS_USER::ObsoletedSetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u64 value = rp.Pop<u64>();
const u32 secure_value_slot = rp.Pop<u32>();
const u32 unique_id = rp.Pop<u32>();
const u8 title_variation = rp.Pop<u8>();
// TODO: Generate and Save the Secure Value
LOG_WARNING(Service_FS,
"(STUBBED) called, value=0x{:016x} secure_value_slot=0x{:08X} "
"unqiue_id=0x{:08X} title_variation=0x{:02X}",
value, secure_value_slot, unique_id, title_variation);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultSuccess);
}
void FS_USER::ObsoletedGetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u32 secure_value_slot = rp.Pop<u32>();
const u32 unique_id = rp.Pop<u32>();
const u8 title_variation = rp.Pop<u8>();
LOG_WARNING(
Service_FS,
"(STUBBED) called secure_value_slot=0x{:08X} unqiue_id=0x{:08X} title_variation=0x{:02X}",
secure_value_slot, unique_id, title_variation);
IPC::RequestBuilder rb = rp.MakeBuilder(4, 0);
rb.Push(ResultSuccess);
// TODO: Implement Secure Value Lookup & Generation
rb.Push<bool>(false); // indicates that the secure value doesn't exist
rb.Push<u64>(0); // the secure value
}
void FS_USER::SetThisSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u32 secure_value_slot = rp.Pop<u32>();
const u64 value = rp.Pop<u64>();
// TODO: Generate and Save the Secure Value
LOG_WARNING(Service_FS, "(STUBBED) called, value=0x{:016x} secure_value_slot=0x{:08X}", value,
secure_value_slot);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultSuccess);
}
void FS_USER::GetThisSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const u32 secure_value_slot = rp.Pop<u32>();
LOG_WARNING(Service_FS, "(STUBBED) called secure_value_slot=0x{:08X}", secure_value_slot);
IPC::RequestBuilder rb = rp.MakeBuilder(5, 0);
rb.Push(ResultSuccess);
// TODO: Implement Secure Value Lookup & Generation
rb.Push<bool>(false); // indicates that the secure value doesn't exist
rb.Push<bool>(true); // indicates the requesting process is a gamecard, overriding the check
rb.Push<u64>(0); // the secure value
}
void FS_USER::SetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const auto archive_handle = rp.PopRaw<ArchiveHandle>();
const u32 secure_value_slot = rp.Pop<u32>();
const u64 value = rp.Pop<u64>();
const bool flush = rp.Pop<bool>();
// TODO: Generate and Save the Secure Value
LOG_WARNING(Service_FS,
"(STUBBED) called, value=0x{:016x} secure_value_slot=0x{:04X} "
"archive_handle=0x{:08X} flush={}",
value, secure_value_slot, archive_handle, flush);
IPC::RequestBuilder rb = rp.MakeBuilder(1, 0);
rb.Push(ResultSuccess);
}
void FS_USER::GetSaveDataSecureValue(Kernel::HLERequestContext& ctx) {
IPC::RequestParser rp(ctx);
const auto archive_handle = rp.PopRaw<ArchiveHandle>();
const u32 secure_value_slot = rp.Pop<u32>();
LOG_WARNING(Service_FS, "(STUBBED) called secure_value_slot=0x{:08X} archive_handle=0x{:08X}",
secure_value_slot, archive_handle);
IPC::RequestBuilder rb = rp.MakeBuilder(5, 0);
rb.Push(ResultSuccess);
// TODO: Implement Secure Value Lookup & Generation
rb.Push<bool>(false); // indicates that the secure value doesn't exist
rb.Push<bool>(true); // indicates the requesting process is a gamecard, overriding the check
rb.Push<u64>(0); // the secure value
}
void FS_USER::RegisterProgramInfo(u32 process_id, u64 program_id, const std::string& filepath) {
const MediaType media_type = GetMediaTypeFromPath(filepath);
program_info_map.insert_or_assign(process_id, ProgramInfo{program_id, media_type});
if (media_type == MediaType::GameCard) {
current_gamecard_path = filepath;
}
}
std::string FS_USER::GetCurrentGamecardPath() const {
return current_gamecard_path;
}
void FS_USER::RegisterProductInfo(u32 process_id, const ProductInfo& product_info) {
product_info_map.insert_or_assign(process_id, product_info);
}
std::optional<FS_USER::ProductInfo> FS_USER::GetProductInfo(u32 process_id) {
auto it = product_info_map.find(process_id);
if (it != product_info_map.end()) {
return it->second;
} else {
return {};
}
}
ResultVal<u16> FS_USER::GetSpecialContentIndexFromGameCard(u64 title_id, SpecialContentType type) {
// TODO(B3N30) check if on real 3DS NCSD is checked if partition exists
if (type > SpecialContentType::DLPChild) {
// Maybe type 4 is New 3DS update/partition 6 but this needs more research
// TODO(B3N30): Find correct result code
return ResultUnknown;
}
switch (type) {
case SpecialContentType::Update:
return static_cast<u16>(NCSDContentIndex::Update);
case SpecialContentType::Manual:
return static_cast<u16>(NCSDContentIndex::Manual);
case SpecialContentType::DLPChild:
return static_cast<u16>(NCSDContentIndex::DLP);
default:
UNREACHABLE();
}
}
ResultVal<u16> FS_USER::GetSpecialContentIndexFromTMD(MediaType media_type, u64 title_id,
SpecialContentType type) {
if (type > SpecialContentType::DLPChild) {
// TODO(B3N30): Find correct result code
return ResultUnknown;
}
std::string tmd_path = AM::GetTitleMetadataPath(media_type, title_id);
FileSys::TitleMetadata tmd;
if (tmd.Load(tmd_path) != Loader::ResultStatus::Success || type == SpecialContentType::Update) {
// TODO(B3N30): Find correct result code
return ResultUnknown;
}
// TODO(B3N30): Does real 3DS check if content exists in TMD?
switch (type) {
case SpecialContentType::Manual:
return static_cast<u16>(FileSys::TMDContentIndex::Manual);
case SpecialContentType::DLPChild:
return static_cast<u16>(FileSys::TMDContentIndex::DLP);
default:
ASSERT(false);
}
return ResultUnknown;
}
FS_USER::FS_USER(Core::System& system)
: ServiceFramework("fs:USER", 30), system(system), archives(system.ArchiveManager()) {
static const FunctionInfo functions[] = {
// clang-format off
{0x0001, nullptr, "Dummy1"},
{0x0401, nullptr, "Control"},
{0x0801, &FS_USER::Initialize, "Initialize"},
{0x0802, &FS_USER::OpenFile, "OpenFile"},
{0x0803, &FS_USER::OpenFileDirectly, "OpenFileDirectly"},
{0x0804, &FS_USER::DeleteFile, "DeleteFile"},
{0x0805, &FS_USER::RenameFile, "RenameFile"},
{0x0806, &FS_USER::DeleteDirectory, "DeleteDirectory"},
{0x0807, &FS_USER::DeleteDirectoryRecursively, "DeleteDirectoryRecursively"},
{0x0808, &FS_USER::CreateFile, "CreateFile"},
{0x0809, &FS_USER::CreateDirectory, "CreateDirectory"},
{0x080A, &FS_USER::RenameDirectory, "RenameDirectory"},
{0x080B, &FS_USER::OpenDirectory, "OpenDirectory"},
{0x080C, &FS_USER::OpenArchive, "OpenArchive"},
{0x080D, &FS_USER::ControlArchive, "ControlArchive"},
{0x080E, &FS_USER::CloseArchive, "CloseArchive"},
{0x080F, &FS_USER::FormatThisUserSaveData, "FormatThisUserSaveData"},
{0x0810, &FS_USER::CreateLegacySystemSaveData, "CreateLegacySystemSaveData"},
{0x0811, nullptr, "DeleteSystemSaveData"},
{0x0812, &FS_USER::GetFreeBytes, "GetFreeBytes"},
{0x0813, nullptr, "GetCardType"},
{0x0814, &FS_USER::GetSdmcArchiveResource, "GetSdmcArchiveResource"},
{0x0815, &FS_USER::GetNandArchiveResource, "GetNandArchiveResource"},
{0x0816, nullptr, "GetSdmcFatfsError"},
{0x0817, &FS_USER::IsSdmcDetected, "IsSdmcDetected"},
{0x0818, &FS_USER::IsSdmcWriteable, "IsSdmcWritable"},
{0x0819, nullptr, "GetSdmcCid"},
{0x081A, nullptr, "GetNandCid"},
{0x081B, nullptr, "GetSdmcSpeedInfo"},
{0x081C, nullptr, "GetNandSpeedInfo"},
{0x081D, nullptr, "GetSdmcLog"},
{0x081E, nullptr, "GetNandLog"},
{0x081F, nullptr, "ClearSdmcLog"},
{0x0820, nullptr, "ClearNandLog"},
{0x0821, &FS_USER::CardSlotIsInserted, "CardSlotIsInserted"},
{0x0822, nullptr, "CardSlotPowerOn"},
{0x0823, nullptr, "CardSlotPowerOff"},
{0x0824, nullptr, "CardSlotGetCardIFPowerStatus"},
{0x0825, nullptr, "CardNorDirectCommand"},
{0x0826, nullptr, "CardNorDirectCommandWithAddress"},
{0x0827, nullptr, "CardNorDirectRead"},
{0x0828, nullptr, "CardNorDirectReadWithAddress"},
{0x0829, nullptr, "CardNorDirectWrite"},
{0x082A, nullptr, "CardNorDirectWriteWithAddress"},
{0x082B, nullptr, "CardNorDirectRead_4xIO"},
{0x082C, nullptr, "CardNorDirectCpuWriteWithoutVerify"},
{0x082D, nullptr, "CardNorDirectSectorEraseWithoutVerify"},
{0x082E, &FS_USER::GetProductInfo, "GetProductInfo"},
{0x082F, &FS_USER::GetProgramLaunchInfo, "GetProgramLaunchInfo"},
{0x0830, &FS_USER::ObsoletedCreateExtSaveData, "Obsoleted_3_0_CreateExtSaveData"},
{0x0831, nullptr, "CreateSharedExtSaveData"},
{0x0832, nullptr, "ReadExtSaveDataIcon"},
{0x0833, nullptr, "EnumerateExtSaveData"},
{0x0834, nullptr, "EnumerateSharedExtSaveData"},
{0x0835, &FS_USER::ObsoletedDeleteExtSaveData, "Obsoleted_3_0_DeleteExtSaveData"},
{0x0836, nullptr, "DeleteSharedExtSaveData"},
{0x0837, nullptr, "SetCardSpiBaudRate"},
{0x0838, nullptr, "SetCardSpiBusMode"},
{0x0839, nullptr, "SendInitializeInfoTo9"},
{0x083A, &FS_USER::GetSpecialContentIndex, "GetSpecialContentIndex"},
{0x083B, nullptr, "GetLegacyRomHeader"},
{0x083C, nullptr, "GetLegacyBannerData"},
{0x083D, nullptr, "CheckAuthorityToAccessExtSaveData"},
{0x083E, nullptr, "QueryTotalQuotaSize"},
{0x083F, nullptr, "GetExtDataBlockSize"},
{0x0840, nullptr, "AbnegateAccessRight"},
{0x0841, nullptr, "DeleteSdmcRoot"},
{0x0842, nullptr, "DeleteAllExtSaveDataOnNand"},
{0x0843, nullptr, "InitializeCtrFileSystem"},
{0x0844, nullptr, "CreateSeed"},
{0x0845, &FS_USER::GetFormatInfo, "GetFormatInfo"},
{0x0846, nullptr, "GetLegacyRomHeader2"},
{0x0847, nullptr, "FormatCtrCardUserSaveData"},
{0x0848, nullptr, "GetSdmcCtrRootPath"},
{0x0849, &FS_USER::GetArchiveResource, "GetArchiveResource"},
{0x084A, nullptr, "ExportIntegrityVerificationSeed"},
{0x084B, nullptr, "ImportIntegrityVerificationSeed"},
{0x084C, &FS_USER::FormatSaveData, "FormatSaveData"},
{0x084D, nullptr, "GetLegacySubBannerData"},
{0x084E, nullptr, "UpdateSha256Context"},
{0x084F, nullptr, "ReadSpecialFile"},
{0x0850, nullptr, "GetSpecialFileSize"},
{0x0851, &FS_USER::CreateExtSaveData, "CreateExtSaveData"},
{0x0852, &FS_USER::DeleteExtSaveData, "DeleteExtSaveData"},
{0x0853, nullptr, "ReadExtSaveDataIcon"},
{0x0854, nullptr, "GetExtDataBlockSize"},
{0x0855, nullptr, "EnumerateExtSaveData"},
{0x0856, &FS_USER::CreateSystemSaveData, "CreateSystemSaveData"},
{0x0857, &FS_USER::DeleteSystemSaveData, "DeleteSystemSaveData"},
{0x0858, nullptr, "StartDeviceMoveAsSource"},
{0x0859, nullptr, "StartDeviceMoveAsDestination"},
{0x085A, nullptr, "SetArchivePriority"},
{0x085B, nullptr, "GetArchivePriority"},
{0x085C, nullptr, "SetCtrCardLatencyParameter"},
{0x085D, nullptr, "SetFsCompatibilityInfo"},
{0x085E, nullptr, "ResetCardCompatibilityParameter"},
{0x085F, nullptr, "SwitchCleanupInvalidSaveData"},
{0x0860, nullptr, "EnumerateSystemSaveData"},
{0x0861, &FS_USER::InitializeWithSdkVersion, "InitializeWithSdkVersion"},
{0x0862, &FS_USER::SetPriority, "SetPriority"},
{0x0863, &FS_USER::GetPriority, "GetPriority"},
{0x0864, nullptr, "GetNandInfo"},
{0x0865, &FS_USER::ObsoletedSetSaveDataSecureValue, "SetSaveDataSecureValue"},
{0x0866, &FS_USER::ObsoletedGetSaveDataSecureValue, "GetSaveDataSecureValue"},
{0x0867, nullptr, "ControlSecureSave"},
{0x0868, nullptr, "GetMediaType"},
{0x0869, nullptr, "GetNandEraseCount"},
{0x086A, nullptr, "ReadNandReport"},
{0x086E, &FS_USER::SetThisSaveDataSecureValue, "SetThisSaveDataSecureValue" },
{0x086F, &FS_USER::GetThisSaveDataSecureValue, "GetThisSaveDataSecureValue" },
{0x0875, &FS_USER::SetSaveDataSecureValue, "SetSaveDataSecureValue" },
{0x0876, &FS_USER::GetSaveDataSecureValue, "GetSaveDataSecureValue" },
{0x087A, &FS_USER::AddSeed, "AddSeed"},
{0x087D, &FS_USER::GetNumSeeds, "GetNumSeeds"},
{0x0886, nullptr, "CheckUpdatedDat"},
// clang-format on
};
RegisterHandlers(functions);
}
void InstallInterfaces(Core::System& system) {
auto& service_manager = system.ServiceManager();
std::make_shared<FS_USER>(system)->InstallAsService(service_manager);
}
} // namespace Service::FS
|