libnx  v4.4.2
fs.h
Go to the documentation of this file.
1 /**
2  * @file fs.h
3  * @brief Filesystem (fsp-srv) service IPC wrapper.
4  * Normally applications should just use standard stdio not FS-serv directly. However this can be used if obtaining a FsFileSystem, FsFile, or FsStorage, for mounting with fs_dev/romfs_dev, etc.
5  * @author plutoo
6  * @author yellows8
7  * @copyright libnx Authors
8  */
9 #pragma once
10 #include "../types.h"
11 #include "../kernel/event.h"
12 #include "../services/ncm_types.h"
13 #include "../services/acc.h"
14 #include "../sf/service.h"
15 
16 // We use wrapped handles for type safety.
17 
18 #define FS_MAX_PATH 0x301
19 
20 /// For use with \ref FsSaveDataAttribute.
21 #define FS_SAVEDATA_CURRENT_APPLICATIONID 0
22 
23 typedef struct {
24  u8 c[0x10];
25 } FsRightsId;
26 
27 typedef struct {
28  Service s;
29 } FsFileSystem;
30 
31 typedef struct {
32  Service s;
33 } FsFile;
34 
35 typedef struct {
36  Service s;
37 } FsDir;
38 
39 typedef struct {
40  Service s;
41 } FsStorage;
42 
43 typedef struct {
44  Service s;
46 
47 typedef struct {
48  Service s;
50 
51 typedef struct {
52  Service s;
54 
55 /// Directory entry.
56 typedef struct {
57  char name[FS_MAX_PATH]; ///< Entry name.
58  u8 pad[3];
59  s8 type; ///< See FsDirEntryType.
60  u8 pad2[3]; ///< ?
61  s64 file_size; ///< File size.
63 
64 /// SaveDataAttribute
65 typedef struct {
66  u64 application_id; ///< ApplicationId of the savedata to access when accessing other programs' savedata via SaveData, otherwise FS_SAVEDATA_CURRENT_APPLICATIONID.
67  AccountUid uid; ///< \ref AccountUid for the user-specific savedata to access, otherwise 0 for common savedata.
68  u64 system_save_data_id; ///< SystemSaveDataId, 0 for ::FsSaveDataType_Account.
69  u8 save_data_type; ///< \ref FsSaveDataType
70  u8 save_data_rank; ///< \ref FsSaveDataRank
71  u16 save_data_index; ///< SaveDataIndex
72  u32 pad_x24; ///< Padding.
73  u64 unk_x28; ///< 0 for ::FsSaveDataType_System/::FsSaveDataType_Account.
74  u64 unk_x30; ///< 0 for ::FsSaveDataType_System/::FsSaveDataType_Account.
75  u64 unk_x38; ///< 0 for ::FsSaveDataType_System/::FsSaveDataType_Account.
77 
78 /// SaveDataExtraData
79 typedef struct {
80  FsSaveDataAttribute attr; ///< \ref FsSaveDataAttribute
81  u64 owner_id; ///< ProgramId of the owner of this save data. 0 for ::FsSaveDataType_System.
82  u64 timestamp; ///< POSIX timestamp.
83  u32 flags; ///< \ref FsSaveDataFlags
84  u32 unk_x54; ///< Normally 0. Possibly unused?
85  s64 data_size; ///< Usable save data size.
86  s64 journal_size; ///< Journal size of the save data.
87  u64 commit_id; ///< Id of the latest commit.
88  u8 unused[0x190]; ///< Uninitialized.
90 
91 /// SaveDataMetaInfo
92 typedef struct {
93  u32 size;
94  u8 type; ///< \ref FsSaveDataMetaType
95  u8 reserved[0x0B];
97 
98 /// SaveDataCreationInfo
99 typedef struct {
100  s64 save_data_size; ///< Size of the save data.
101  s64 journal_size; ///< Journal size of the save data.
102  u64 available_size; ///< AvailableSize
103  u64 owner_id; ///< ProgramId of the owner of this save data. 0 for ::FsSaveDataType_System.
104  u32 flags; ///< \ref FsSaveDataFlags
105  u8 save_data_space_id; ///< \ref FsSaveDataSpaceId
106  u8 unk; ///< 0 for ::FsSaveDataType_System.
107  u8 padding[0x1a]; ///< Uninitialized for ::FsSaveDataType_System.
109 
110 /// SaveDataInfo
111 typedef struct {
112  u64 save_data_id; ///< SaveDataId
113  u8 save_data_space_id; ///< \ref FsSaveDataSpaceId
114  u8 save_data_type; ///< \ref FsSaveDataType
115  u8 pad[6]; ///< Padding.
116  AccountUid uid; ///< FsSave::userID
117  u64 system_save_data_id; ///< FsSaveDataAttribute::system_save_data_id
118  u64 application_id; ///< ApplicationId for ::FsSaveDataType_Account.
119  u64 size; ///< Raw saveimage size.
120  u16 save_data_index; ///< SaveDataIndex
121  u8 save_data_rank; ///< \ref FsSaveDataRank
122  u8 unk_x3b[0x25]; ///< Unknown. Usually zeros?
124 
125 /// SaveDataFilter
126 typedef struct {
127  bool filter_by_application_id; ///< Filter by \ref FsSaveDataAttribute::application_id
128  bool filter_by_save_data_type; ///< Filter by \ref FsSaveDataAttribute::save_data_type
129  bool filter_by_user_id; ///< Filter by \ref FsSaveDataAttribute::uid
130  bool filter_by_system_save_data_id; ///< Filter by \ref FsSaveDataAttribute::system_save_data_id
131  bool filter_by_index; ///< Filter by \ref FsSaveDataAttribute::save_data_index
132  u8 save_data_rank; ///< \ref FsSaveDataRank
133  u8 padding[0x2]; ///< Padding
134  FsSaveDataAttribute attr; ///< \ref FsSaveDataAttribute
136 
137 typedef struct {
138  u64 created; ///< POSIX timestamp.
139  u64 modified; ///< POSIX timestamp.
140  u64 accessed; ///< POSIX timestamp.
141  u8 is_valid; ///< 0x1 when the timestamps are set.
142  u8 padding[7];
144 
145 /// This is nn::fssystem::ArchiveMacKey. Used by \ref setsysGetThemeKey and \ref setsysSetThemeKey. Does not appear to be in use elsewhere.
146 typedef struct {
147  u8 key[0x10];
149 
150 /// Returned by fsFsGetEntryType.
151 typedef enum {
152  FsDirEntryType_Dir = 0, ///< Entry is a directory.
153  FsDirEntryType_File = 1, ///< Entry is a file.
155 
156 /// For use with fsFsOpenFile.
157 typedef enum {
158  FsOpenMode_Read = BIT(0), ///< Open for reading.
159  FsOpenMode_Write = BIT(1), ///< Open for writing.
160  FsOpenMode_Append = BIT(2), ///< Append file.
161 } FsOpenMode;
162 
163 /// For use with fsFsCreateFile.
164 typedef enum {
165  FsCreateOption_BigFile = BIT(0), ///< Creates a ConcatenationFile (dir with archive bit) instead of file.
167 
168 /// For use with fsFsOpenDirectory.
169 typedef enum {
170  FsDirOpenMode_ReadDirs = BIT(0), ///< Enable reading directory entries.
171  FsDirOpenMode_ReadFiles = BIT(1), ///< Enable reading file entries.
172  FsDirOpenMode_NoFileSize = BIT(31), ///< Causes result entries to not contain filesize information (always 0).
173 } FsDirOpenMode;
174 
175 /// For use with fsFileRead.
176 typedef enum {
177  FsReadOption_None = 0, ///< No option.
178 } FsReadOption;
179 
180 /// For use with fsFileWrite.
181 typedef enum {
182  FsWriteOption_None = 0, ///< No option.
183  FsWriteOption_Flush = BIT(0), ///< Forces a flush after write.
184 } FsWriteOption;
185 
186 typedef enum {
187  FsContentStorageId_System = 0, ///< System
188  FsContentStorageId_User = 1, ///< User
189  FsContentStorageId_SdCard = 2, ///< SdCard
190  FsContentStorageId_System0 = 3, ///< [16.0.0+] System0
192 
193 typedef enum {
194  FsCustomStorageId_System = 0,
195  FsCustomStorageId_SdCard = 1,
196 } FsCustomStorageId;
197 
198 /// ImageDirectoryId
199 typedef enum {
200  FsImageDirectoryId_Nand = 0,
201  FsImageDirectoryId_Sd = 1,
203 
204 /// SaveDataSpaceId
205 typedef enum {
206  FsSaveDataSpaceId_System = 0, ///< System
207  FsSaveDataSpaceId_User = 1, ///< User
208  FsSaveDataSpaceId_SdSystem = 2, ///< SdSystem
209  FsSaveDataSpaceId_Temporary = 3, ///< [3.0.0+] Temporary
210  FsSaveDataSpaceId_SdUser = 4, ///< [4.0.0+] SdUser
211  FsSaveDataSpaceId_ProperSystem = 100, ///< [3.0.0+] ProperSystem
212  FsSaveDataSpaceId_SafeMode = 101, ///< [3.0.0+] SafeMode
213 
214  FsSaveDataSpaceId_All = -1, ///< Pseudo value for fsOpenSaveDataInfoReader().
216 
217 /// SaveDataType
218 typedef enum {
219  FsSaveDataType_System = 0, ///< System
220  FsSaveDataType_Account = 1, ///< Account
221  FsSaveDataType_Bcat = 2, ///< Bcat
222  FsSaveDataType_Device = 3, ///< Device
223  FsSaveDataType_Temporary = 4, ///< [3.0.0+] Temporary
224  FsSaveDataType_Cache = 5, ///< [3.0.0+] Cache
225  FsSaveDataType_SystemBcat = 6, ///< [4.0.0+] SystemBcat
227 
228 /// SaveDataRank
229 typedef enum {
230  FsSaveDataRank_Primary = 0, ///< Primary
231  FsSaveDataRank_Secondary = 1, ///< Secondary
233 
234 /// SaveDataFlags
235 typedef enum {
236  FsSaveDataFlags_KeepAfterResettingSystemSaveData = BIT(0),
237  FsSaveDataFlags_KeepAfterRefurbishment = BIT(1),
238  FsSaveDataFlags_KeepAfterResettingSystemSaveDataWithoutUserSaveData = BIT(2),
239  FsSaveDataFlags_NeedsSecureDelete = BIT(3),
241 
242 /// SaveDataMetaType
243 typedef enum {
244  FsSaveDataMetaType_None = 0,
245  FsSaveDataMetaType_Thumbnail = 1,
246  FsSaveDataMetaType_ExtensionContext = 2,
248 
249 typedef enum {
250  FsGameCardAttribute_AutoBootFlag = BIT(0), ///< Causes the cartridge to automatically start on bootup
251  FsGameCardAttribute_HistoryEraseFlag = BIT(1), ///< Causes NS to throw an error on attempt to load the cartridge
252  FsGameCardAttribute_RepairToolFlag = BIT(2), ///< [4.0.0+] Indicates that this gamecard is a repair tool.
253  FsGameCardAttribute_DifferentRegionCupToTerraDeviceFlag = BIT(3), ///< [9.0.0+] DifferentRegionCupToTerraDeviceFlag
254  FsGameCardAttribute_DifferentRegionCupToGlobalDeviceFlag = BIT(4), ///< [9.0.0+] DifferentRegionCupToGlobalDeviceFlag
256 
257 typedef enum {
258  FsGameCardPartition_Update = 0,
259  FsGameCardPartition_Normal = 1,
260  FsGameCardPartition_Secure = 2,
261  FsGameCardPartition_Logo = 3, ///< [4.0.0+]
263 
264 typedef struct {
265  u32 value;
267 
268 typedef struct {
269  u32 aes_ctr_key_type; ///< Contains bitflags describing how data is AES encrypted.
270  u32 speed_emulation_type; ///< Contains bitflags describing how data is emulated.
271  u32 reserved[0x38/sizeof(u32)];
272 } FsRangeInfo;
273 
274 typedef enum {
275  FsOperationId_Clear, ///< Fill range with zero for supported file/storage.
276  FsOperationId_ClearSignature, ///< Clears signature for supported file/storage.
277  FsOperationId_InvalidateCache, ///< Invalidates cache for supported file/storage.
278  FsOperationId_QueryRange, ///< Retrieves information on data for supported file/storage.
279 } FsOperationId;
280 
281 /// BisPartitionId
282 typedef enum {
283  FsBisPartitionId_BootPartition1Root = 0,
284 
285  FsBisPartitionId_BootPartition2Root = 10,
286 
287  FsBisPartitionId_UserDataRoot = 20,
288  FsBisPartitionId_BootConfigAndPackage2Part1 = 21,
289  FsBisPartitionId_BootConfigAndPackage2Part2 = 22,
290  FsBisPartitionId_BootConfigAndPackage2Part3 = 23,
291  FsBisPartitionId_BootConfigAndPackage2Part4 = 24,
292  FsBisPartitionId_BootConfigAndPackage2Part5 = 25,
293  FsBisPartitionId_BootConfigAndPackage2Part6 = 26,
294  FsBisPartitionId_CalibrationBinary = 27,
295  FsBisPartitionId_CalibrationFile = 28,
296  FsBisPartitionId_SafeMode = 29,
297  FsBisPartitionId_User = 30,
298  FsBisPartitionId_System = 31,
299  FsBisPartitionId_SystemProperEncryption = 32,
300  FsBisPartitionId_SystemProperPartition = 33,
301  FsBisPartitionId_SignedSystemPartitionOnSafeMode = 34,
302  FsBisPartitionId_DeviceTreeBlob = 35,
303  FsBisPartitionId_System0 = 36,
305 
306 /// FileSystemType
307 typedef enum {
308  FsFileSystemType_Logo = 2, ///< Logo
309  FsFileSystemType_ContentControl = 3, ///< ContentControl
310  FsFileSystemType_ContentManual = 4, ///< ContentManual
311  FsFileSystemType_ContentMeta = 5, ///< ContentMeta
312  FsFileSystemType_ContentData = 6, ///< ContentData
313  FsFileSystemType_ApplicationPackage = 7, ///< ApplicationPackage
314  FsFileSystemType_RegisteredUpdate = 8, ///< [4.0.0+] RegisteredUpdate
316 
317 /// FileSystemQueryId
318 typedef enum {
322 
323 /// FsPriority
324 typedef enum {
325  FsPriority_Normal = 0,
326  FsPriority_Realtime = 1,
327  FsPriority_Low = 2,
328  FsPriority_Background = 3,
329 } FsPriority;
330 
331 /// FsContentAttributes
332 typedef enum {
333  FsContentAttributes_None = 0x0,
334  FsContentAttributes_All = 0xF,
336 
337 /// For use with fsOpenHostFileSystemWithOption
338 typedef enum {
339  FsMountHostOptionFlag_None = 0, ///< Host filesystem will be case insensitive.
340  FsMountHostOptionFlag_PseudoCaseSensitive = BIT(0), ///< Host filesystem will be pseudo case sensitive.
342 
343 /// Initialize fsp-srv. Used automatically during app startup.
345 
346 /// Exit fsp-srv. Used automatically during app exit.
347 void fsExit(void);
348 
349 /// Gets the Service object for the actual fsp-srv service session.
351 
352 /// [5.0.0+] Configures the \ref FsPriority of all filesystem commands issued within the current thread.
354 
355 /// Mount requested filesystem type from content file
356 Result fsOpenFileSystem(FsFileSystem* out, FsFileSystemType fsType, const char* contentPath); ///< same as calling fsOpenFileSystemWithId with 0 as id
357 Result fsOpenDataFileSystemByCurrentProcess(FsFileSystem *out);
358 Result fsOpenFileSystemWithPatch(FsFileSystem* out, u64 id, FsFileSystemType fsType); ///< [2.0.0+], like OpenFileSystemWithId but without content path.
359 Result fsOpenFileSystemWithId(FsFileSystem* out, u64 id, FsFileSystemType fsType, const char* contentPath, FsContentAttributes attr); ///< works on all firmwares, id is ignored on [1.0.0], attr is ignored before [16.0.0]
360 Result fsOpenDataFileSystemByProgramId(FsFileSystem *out, u64 program_id); ///< [3.0.0+]
361 Result fsOpenBisFileSystem(FsFileSystem* out, FsBisPartitionId partitionId, const char* string);
362 Result fsOpenBisStorage(FsStorage* out, FsBisPartitionId partitionId);
363 
364 /// Do not call this directly, see fs_dev.h.
366 
367 Result fsOpenHostFileSystem(FsFileSystem* out, const char *path);
368 Result fsOpenHostFileSystemWithOption(FsFileSystem* out, const char *path, u32 flags); ///< [9.0.0+]
369 
370 Result fsDeleteSaveDataFileSystem(u64 application_id);
371 Result fsCreateSaveDataFileSystem(const FsSaveDataAttribute* attr, const FsSaveDataCreationInfo* creation_info, const FsSaveDataMetaInfo* meta);
372 Result fsCreateSaveDataFileSystemBySystemSaveDataId(const FsSaveDataAttribute* attr, const FsSaveDataCreationInfo* creation_info);
375 
376 Result fsIsExFatSupported(bool* out);
377 
378 Result fsOpenGameCardFileSystem(FsFileSystem* out, const FsGameCardHandle* handle, FsGameCardPartition partition);
379 
380 Result fsExtendSaveDataFileSystem(FsSaveDataSpaceId save_data_space_id, u64 saveID, s64 dataSize, s64 journalSize); ///< [3.0.0+]
381 
382 Result fsOpenSaveDataFileSystem(FsFileSystem* out, FsSaveDataSpaceId save_data_space_id, const FsSaveDataAttribute *attr);
383 Result fsOpenSaveDataFileSystemBySystemSaveDataId(FsFileSystem* out, FsSaveDataSpaceId save_data_space_id, const FsSaveDataAttribute *attr);
384 Result fsOpenReadOnlySaveDataFileSystem(FsFileSystem* out, FsSaveDataSpaceId save_data_space_id, const FsSaveDataAttribute *attr); ///< [2.0.0+].
385 
386 Result fsReadSaveDataFileSystemExtraDataBySaveDataSpaceId(void* buf, size_t len, FsSaveDataSpaceId save_data_space_id, u64 saveID);
387 Result fsReadSaveDataFileSystemExtraData(void* buf, size_t len, u64 saveID);
388 Result fsWriteSaveDataFileSystemExtraData(const void* buf, size_t len, FsSaveDataSpaceId save_data_space_id, u64 saveID);
389 
390 Result fsOpenSaveDataInfoReader(FsSaveDataInfoReader* out, FsSaveDataSpaceId save_data_space_id);
391 
392 Result fsOpenSaveDataInfoReaderWithFilter(FsSaveDataInfoReader* out, FsSaveDataSpaceId save_data_space_id, const FsSaveDataFilter *save_data_filter); ///< [6.0.0+]
393 
394 Result fsOpenImageDirectoryFileSystem(FsFileSystem* out, FsImageDirectoryId image_directory_id);
395 Result fsOpenContentStorageFileSystem(FsFileSystem* out, FsContentStorageId content_storage_id);
396 Result fsOpenCustomStorageFileSystem(FsFileSystem* out, FsCustomStorageId custom_storage_id); ///< [7.0.0+]
397 
398 Result fsOpenDataStorageByCurrentProcess(FsStorage* out);
399 Result fsOpenDataStorageByProgramId(FsStorage *out, u64 program_id); /// <[3.0.0+]
401 Result fsOpenPatchDataStorageByCurrentProcess(FsStorage* out);
402 
403 Result fsOpenDeviceOperator(FsDeviceOperator* out);
404 Result fsOpenSdCardDetectionEventNotifier(FsEventNotifier* out);
405 
406 Result fsIsSignedSystemPartitionOnSdCardValid(bool *out);
407 
408 /// Retrieves the rights id corresponding to the content path. Only available on [2.0.0-15.0.1].
409 Result fsGetRightsIdByPath(const char* path, FsRightsId* out_rights_id);
410 
411 /// Retrieves the rights id and key generation corresponding to the content path. Only available on [3.0.0+], attr is ignored before [16.0.0].
412 Result fsGetRightsIdAndKeyGenerationByPath(const char* path, FsContentAttributes attr, u8* out_key_generation, FsRightsId* out_rights_id);
413 
414 Result fsDisableAutoSaveDataCreation(void);
415 
416 Result fsSetGlobalAccessLogMode(u32 mode);
417 Result fsGetGlobalAccessLogMode(u32* out_mode);
418 Result fsOutputAccessLogToSdCard(const char *log, size_t size);
419 
420 /// Only available on [7.0.0+].
421 Result fsGetProgramIndexForAccessLog(u32 *out_program_index, u32 *out_program_count);
422 
423 // Wrapper(s) for fsCreateSaveDataFileSystem.
424 Result fsCreate_TemporaryStorage(u64 application_id, u64 owner_id, s64 size, u32 flags);
425 
426 // Wrapper(s) for fsCreateSaveDataFileSystemBySystemSaveDataId.
427 Result fsCreate_SystemSaveDataWithOwner(FsSaveDataSpaceId save_data_space_id, u64 system_save_data_id, AccountUid uid, u64 owner_id, s64 size, s64 journal_size, u32 flags);
428 Result fsCreate_SystemSaveData(FsSaveDataSpaceId save_data_space_id, u64 system_save_data_id, s64 size, s64 journal_size, u32 flags);
429 
430 /// Wrapper for fsOpenSaveDataFileSystem.
431 /// See \ref FsSaveDataAttribute for application_id and uid.
432 Result fsOpen_SaveData(FsFileSystem* out, u64 application_id, AccountUid uid);
433 
434 /// Wrapper for fsOpenReadOnlySaveDataFileSystem.
435 /// Only available on [2.0.0+].
436 /// See \ref FsSaveDataAttribute for application_id and uid.
438 
439 /// Wrapper for fsOpenSaveDataFileSystem, for opening BcatSaveData.
441 
442 /// Wrapper for fsOpenSaveDataFileSystem, for opening DeviceSaveData.
443 /// See \ref FsSaveDataAttribute for application_id.
445 
446 /// Wrapper for fsOpenSaveDataFileSystem, for opening TemporaryStorage.
447 /// Only available on [3.0.0+].
449 
450 /// Wrapper for fsOpenSaveDataFileSystem, for opening CacheStorage.
451 /// Only available on [3.0.0+].
452 /// See \ref FsSaveDataAttribute for application_id.
453 Result fsOpen_CacheStorage(FsFileSystem* out, u64 application_id, u16 save_data_index);
454 
455 /// Wrapper for fsOpenSaveDataFileSystemBySystemSaveDataId, for opening SystemSaveData.
456 /// WARNING: You can brick when writing to SystemSaveData, if the data is corrupted etc.
457 Result fsOpen_SystemSaveData(FsFileSystem* out, FsSaveDataSpaceId save_data_space_id, u64 system_save_data_id, AccountUid uid);
458 
459 /// Wrapper for fsOpenSaveDataFileSystemBySystemSaveDataId, for opening SystemBcatSaveData.
460 /// Only available on [4.0.0+].
462 
463 // IFileSystem
464 Result fsFsCreateFile(FsFileSystem* fs, const char* path, s64 size, u32 option);
465 Result fsFsDeleteFile(FsFileSystem* fs, const char* path);
466 Result fsFsCreateDirectory(FsFileSystem* fs, const char* path);
467 Result fsFsDeleteDirectory(FsFileSystem* fs, const char* path);
468 Result fsFsDeleteDirectoryRecursively(FsFileSystem* fs, const char* path);
469 Result fsFsRenameFile(FsFileSystem* fs, const char* cur_path, const char* new_path);
470 Result fsFsRenameDirectory(FsFileSystem* fs, const char* cur_path, const char* new_path);
471 Result fsFsGetEntryType(FsFileSystem* fs, const char* path, FsDirEntryType* out);
472 Result fsFsOpenFile(FsFileSystem* fs, const char* path, u32 mode, FsFile* out);
473 Result fsFsOpenDirectory(FsFileSystem* fs, const char* path, u32 mode, FsDir* out);
474 Result fsFsCommit(FsFileSystem* fs);
475 Result fsFsGetFreeSpace(FsFileSystem* fs, const char* path, s64* out);
476 Result fsFsGetTotalSpace(FsFileSystem* fs, const char* path, s64* out);
477 Result fsFsGetFileTimeStampRaw(FsFileSystem* fs, const char* path, FsTimeStampRaw *out); ///< [3.0.0+]
478 Result fsFsCleanDirectoryRecursively(FsFileSystem* fs, const char* path); ///< [3.0.0+]
479 Result fsFsQueryEntry(FsFileSystem* fs, void *out, size_t out_size, const void *in, size_t in_size, const char* path, FsFileSystemQueryId query_id); ///< [4.0.0+]
480 void fsFsClose(FsFileSystem* fs);
481 
482 /// Uses \ref fsFsQueryEntry to set the archive bit on the specified absolute directory path.
483 /// This will cause HOS to treat the directory as if it were a file containing the directory's concatenated contents.
485 
486 /// Wrapper for fsFsQueryEntry with FsFileSystemQueryId_IsValidSignedSystemPartitionOnSdCard.
487 /// Only available on [8.0.0+].
489 
490 // IFile
491 Result fsFileRead(FsFile* f, s64 off, void* buf, u64 read_size, u32 option, u64* bytes_read);
492 Result fsFileWrite(FsFile* f, s64 off, const void* buf, u64 write_size, u32 option);
493 Result fsFileFlush(FsFile* f);
494 Result fsFileSetSize(FsFile* f, s64 sz);
495 Result fsFileGetSize(FsFile* f, s64* out);
496 Result fsFileOperateRange(FsFile* f, FsOperationId op_id, s64 off, s64 len, FsRangeInfo* out); ///< [4.0.0+]
497 void fsFileClose(FsFile* f);
498 
499 // IDirectory
500 Result fsDirRead(FsDir* d, s64* total_entries, size_t max_entries, FsDirectoryEntry *buf);
501 Result fsDirGetEntryCount(FsDir* d, s64* count);
502 void fsDirClose(FsDir* d);
503 
504 // IStorage
505 Result fsStorageRead(FsStorage* s, s64 off, void* buf, u64 read_size);
506 Result fsStorageWrite(FsStorage* s, s64 off, const void* buf, u64 write_size);
507 Result fsStorageFlush(FsStorage* s);
508 Result fsStorageSetSize(FsStorage* s, s64 sz);
509 Result fsStorageGetSize(FsStorage* s, s64* out);
510 Result fsStorageOperateRange(FsStorage* s, FsOperationId op_id, s64 off, s64 len, FsRangeInfo* out); ///< [4.0.0+]
511 void fsStorageClose(FsStorage* s);
512 
513 // ISaveDataInfoReader
514 
515 /// Read FsSaveDataInfo data into the buf array.
516 Result fsSaveDataInfoReaderRead(FsSaveDataInfoReader *s, FsSaveDataInfo* buf, size_t max_entries, s64* total_entries);
517 void fsSaveDataInfoReaderClose(FsSaveDataInfoReader *s);
518 
519 // IEventNotifier
520 Result fsEventNotifierGetEventHandle(FsEventNotifier* e, Event* out, bool autoclear);
521 void fsEventNotifierClose(FsEventNotifier* e);
522 
523 // IDeviceOperator
524 Result fsDeviceOperatorIsSdCardInserted(FsDeviceOperator* d, bool* out);
525 Result fsDeviceOperatorIsGameCardInserted(FsDeviceOperator* d, bool* out);
526 Result fsDeviceOperatorGetGameCardHandle(FsDeviceOperator* d, FsGameCardHandle* out);
527 Result fsDeviceOperatorGetGameCardAttribute(FsDeviceOperator* d, const FsGameCardHandle* handle, u8 *out);
528 void fsDeviceOperatorClose(FsDeviceOperator* d);
Result fsOpen_SystemBcatSaveData(FsFileSystem *out, u64 system_save_data_id)
Wrapper for fsOpenSaveDataFileSystemBySystemSaveDataId, for opening SystemBcatSaveData.
FsCreateOption
For use with fsFsCreateFile.
Definition: fs.h:164
@ FsCreateOption_BigFile
Creates a ConcatenationFile (dir with archive bit) instead of file.
Definition: fs.h:165
FsOpenMode
For use with fsFsOpenFile.
Definition: fs.h:157
@ FsOpenMode_Read
Open for reading.
Definition: fs.h:158
@ FsOpenMode_Append
Append file.
Definition: fs.h:160
@ FsOpenMode_Write
Open for writing.
Definition: fs.h:159
Result fsOpen_CacheStorage(FsFileSystem *out, u64 application_id, u16 save_data_index)
Wrapper for fsOpenSaveDataFileSystem, for opening CacheStorage.
Result fsOpen_DeviceSaveData(FsFileSystem *out, u64 application_id)
Wrapper for fsOpenSaveDataFileSystem, for opening DeviceSaveData.
FsFileSystemQueryId
FileSystemQueryId.
Definition: fs.h:318
@ FsFileSystemQueryId_SetConcatenationFileAttribute
[4.0.0+]
Definition: fs.h:319
@ FsFileSystemQueryId_IsValidSignedSystemPartitionOnSdCard
[8.0.0+]
Definition: fs.h:320
Result fsStorageOperateRange(FsStorage *s, FsOperationId op_id, s64 off, s64 len, FsRangeInfo *out)
[4.0.0+]
void fsSetPriority(FsPriority prio)
[5.0.0+] Configures the FsPriority of all filesystem commands issued within the current thread.
FsOperationId
Definition: fs.h:274
@ FsOperationId_InvalidateCache
Invalidates cache for supported file/storage.
Definition: fs.h:277
@ FsOperationId_Clear
Fill range with zero for supported file/storage.
Definition: fs.h:275
@ FsOperationId_QueryRange
Retrieves information on data for supported file/storage.
Definition: fs.h:278
@ FsOperationId_ClearSignature
Clears signature for supported file/storage.
Definition: fs.h:276
FsContentStorageId
Definition: fs.h:186
@ FsContentStorageId_SdCard
SdCard.
Definition: fs.h:189
@ FsContentStorageId_User
User.
Definition: fs.h:188
@ FsContentStorageId_System
System.
Definition: fs.h:187
@ FsContentStorageId_System0
[16.0.0+] System0
Definition: fs.h:190
Result fsOpenReadOnlySaveDataFileSystem(FsFileSystem *out, FsSaveDataSpaceId save_data_space_id, const FsSaveDataAttribute *attr)
[2.0.0+].
Result fsFsIsValidSignedSystemPartitionOnSdCard(FsFileSystem *fs, bool *out)
Wrapper for fsFsQueryEntry with FsFileSystemQueryId_IsValidSignedSystemPartitionOnSdCard.
FsImageDirectoryId
ImageDirectoryId.
Definition: fs.h:199
Result fsOpen_SaveData(FsFileSystem *out, u64 application_id, AccountUid uid)
Wrapper for fsOpenSaveDataFileSystem.
void fsExit(void)
Exit fsp-srv. Used automatically during app exit.
Result fsOpenFileSystemWithId(FsFileSystem *out, u64 id, FsFileSystemType fsType, const char *contentPath, FsContentAttributes attr)
works on all firmwares, id is ignored on [1.0.0], attr is ignored before [16.0.0]
Result fsOpen_SystemSaveData(FsFileSystem *out, FsSaveDataSpaceId save_data_space_id, u64 system_save_data_id, AccountUid uid)
Wrapper for fsOpenSaveDataFileSystemBySystemSaveDataId, for opening SystemSaveData.
Result fsOpen_TemporaryStorage(FsFileSystem *out)
Wrapper for fsOpenSaveDataFileSystem, for opening TemporaryStorage.
Result fsDeleteSaveDataFileSystemBySaveDataAttribute(FsSaveDataSpaceId save_data_space_id, const FsSaveDataAttribute *attr)
[4.0.0+]
FsFileSystemType
FileSystemType.
Definition: fs.h:307
@ FsFileSystemType_RegisteredUpdate
[4.0.0+] RegisteredUpdate
Definition: fs.h:314
@ FsFileSystemType_ApplicationPackage
ApplicationPackage.
Definition: fs.h:313
@ FsFileSystemType_ContentManual
ContentManual.
Definition: fs.h:310
@ FsFileSystemType_ContentControl
ContentControl.
Definition: fs.h:309
@ FsFileSystemType_Logo
Logo.
Definition: fs.h:308
@ FsFileSystemType_ContentData
ContentData.
Definition: fs.h:312
@ FsFileSystemType_ContentMeta
ContentMeta.
Definition: fs.h:311
Result fsOpenFileSystem(FsFileSystem *out, FsFileSystemType fsType, const char *contentPath)
Mount requested filesystem type from content file.
Result fsOpen_BcatSaveData(FsFileSystem *out, u64 application_id)
Wrapper for fsOpenSaveDataFileSystem, for opening BcatSaveData.
FsBisPartitionId
BisPartitionId.
Definition: fs.h:282
FsContentAttributes
FsContentAttributes.
Definition: fs.h:332
Service * fsGetServiceSession(void)
Gets the Service object for the actual fsp-srv service session.
Result fsInitialize(void)
Initialize fsp-srv. Used automatically during app startup.
Result fsFileOperateRange(FsFile *f, FsOperationId op_id, s64 off, s64 len, FsRangeInfo *out)
[4.0.0+]
Result fsOpenHostFileSystemWithOption(FsFileSystem *out, const char *path, u32 flags)
[9.0.0+]
Result fsOpenSaveDataInfoReaderWithFilter(FsSaveDataInfoReader *out, FsSaveDataSpaceId save_data_space_id, const FsSaveDataFilter *save_data_filter)
[6.0.0+]
FsSaveDataSpaceId
SaveDataSpaceId.
Definition: fs.h:205
@ FsSaveDataSpaceId_All
Pseudo value for fsOpenSaveDataInfoReader().
Definition: fs.h:214
@ FsSaveDataSpaceId_System
System.
Definition: fs.h:206
@ FsSaveDataSpaceId_SdUser
[4.0.0+] SdUser
Definition: fs.h:210
@ FsSaveDataSpaceId_SdSystem
SdSystem.
Definition: fs.h:208
@ FsSaveDataSpaceId_SafeMode
[3.0.0+] SafeMode
Definition: fs.h:212
@ FsSaveDataSpaceId_ProperSystem
[3.0.0+] ProperSystem
Definition: fs.h:211
@ FsSaveDataSpaceId_User
User.
Definition: fs.h:207
@ FsSaveDataSpaceId_Temporary
[3.0.0+] Temporary
Definition: fs.h:209
Result fsGetProgramIndexForAccessLog(u32 *out_program_index, u32 *out_program_count)
Only available on [7.0.0+].
Result fsGetRightsIdByPath(const char *path, FsRightsId *out_rights_id)
Retrieves the rights id corresponding to the content path. Only available on [2.0....
FsReadOption
For use with fsFileRead.
Definition: fs.h:176
@ FsReadOption_None
No option.
Definition: fs.h:177
Result fsSaveDataInfoReaderRead(FsSaveDataInfoReader *s, FsSaveDataInfo *buf, size_t max_entries, s64 *total_entries)
Read FsSaveDataInfo data into the buf array.
FsDirEntryType
Returned by fsFsGetEntryType.
Definition: fs.h:151
@ FsDirEntryType_File
Entry is a file.
Definition: fs.h:153
@ FsDirEntryType_Dir
Entry is a directory.
Definition: fs.h:152
FsDirOpenMode
For use with fsFsOpenDirectory.
Definition: fs.h:169
@ FsDirOpenMode_ReadDirs
Enable reading directory entries.
Definition: fs.h:170
@ FsDirOpenMode_NoFileSize
Causes result entries to not contain filesize information (always 0).
Definition: fs.h:172
@ FsDirOpenMode_ReadFiles
Enable reading file entries.
Definition: fs.h:171
FsGameCardPartition
Definition: fs.h:257
@ FsGameCardPartition_Logo
[4.0.0+]
Definition: fs.h:261
Result fsExtendSaveDataFileSystem(FsSaveDataSpaceId save_data_space_id, u64 saveID, s64 dataSize, s64 journalSize)
[3.0.0+]
Result fsFsSetConcatenationFileAttribute(FsFileSystem *fs, const char *path)
Uses fsFsQueryEntry to set the archive bit on the specified absolute directory path.
Result fsOpenDataFileSystemByProgramId(FsFileSystem *out, u64 program_id)
[3.0.0+]
FsSaveDataRank
SaveDataRank.
Definition: fs.h:229
@ FsSaveDataRank_Primary
Primary.
Definition: fs.h:230
@ FsSaveDataRank_Secondary
Secondary.
Definition: fs.h:231
Result fsDeleteSaveDataFileSystemBySaveDataSpaceId(FsSaveDataSpaceId save_data_space_id, u64 saveID)
[2.0.0+]
Result fsFsCleanDirectoryRecursively(FsFileSystem *fs, const char *path)
[3.0.0+]
Result fsOpen_SaveDataReadOnly(FsFileSystem *out, u64 application_id, AccountUid uid)
Wrapper for fsOpenReadOnlySaveDataFileSystem.
FsPriority
FsPriority.
Definition: fs.h:324
Result fsFsQueryEntry(FsFileSystem *fs, void *out, size_t out_size, const void *in, size_t in_size, const char *path, FsFileSystemQueryId query_id)
[4.0.0+]
Result fsOpenFileSystemWithPatch(FsFileSystem *out, u64 id, FsFileSystemType fsType)
[2.0.0+], like OpenFileSystemWithId but without content path.
FsWriteOption
For use with fsFileWrite.
Definition: fs.h:181
@ FsWriteOption_None
No option.
Definition: fs.h:182
@ FsWriteOption_Flush
Forces a flush after write.
Definition: fs.h:183
FsMountHostOption
For use with fsOpenHostFileSystemWithOption.
Definition: fs.h:338
@ FsMountHostOptionFlag_PseudoCaseSensitive
Host filesystem will be pseudo case sensitive.
Definition: fs.h:340
@ FsMountHostOptionFlag_None
Host filesystem will be case insensitive.
Definition: fs.h:339
Result fsOpenSdCardFileSystem(FsFileSystem *out)
Do not call this directly, see fs_dev.h.
FsSaveDataMetaType
SaveDataMetaType.
Definition: fs.h:243
Result fsOpenDataStorageByDataId(FsStorage *out, u64 dataId, NcmStorageId storageId)
<[3.0.0+]
FsGameCardAttribute
Definition: fs.h:249
@ FsGameCardAttribute_AutoBootFlag
Causes the cartridge to automatically start on bootup.
Definition: fs.h:250
@ FsGameCardAttribute_HistoryEraseFlag
Causes NS to throw an error on attempt to load the cartridge.
Definition: fs.h:251
@ FsGameCardAttribute_RepairToolFlag
[4.0.0+] Indicates that this gamecard is a repair tool.
Definition: fs.h:252
@ FsGameCardAttribute_DifferentRegionCupToTerraDeviceFlag
[9.0.0+] DifferentRegionCupToTerraDeviceFlag
Definition: fs.h:253
@ FsGameCardAttribute_DifferentRegionCupToGlobalDeviceFlag
[9.0.0+] DifferentRegionCupToGlobalDeviceFlag
Definition: fs.h:254
FsSaveDataFlags
SaveDataFlags.
Definition: fs.h:235
Result fsFsGetFileTimeStampRaw(FsFileSystem *fs, const char *path, FsTimeStampRaw *out)
[3.0.0+]
FsSaveDataType
SaveDataType.
Definition: fs.h:218
@ FsSaveDataType_Device
Device.
Definition: fs.h:222
@ FsSaveDataType_Temporary
[3.0.0+] Temporary
Definition: fs.h:223
@ FsSaveDataType_System
System.
Definition: fs.h:219
@ FsSaveDataType_Cache
[3.0.0+] Cache
Definition: fs.h:224
@ FsSaveDataType_Account
Account.
Definition: fs.h:220
@ FsSaveDataType_SystemBcat
[4.0.0+] SystemBcat
Definition: fs.h:225
@ FsSaveDataType_Bcat
Bcat.
Definition: fs.h:221
Result fsGetRightsIdAndKeyGenerationByPath(const char *path, FsContentAttributes attr, u8 *out_key_generation, FsRightsId *out_rights_id)
Retrieves the rights id and key generation corresponding to the content path. Only available on [3....
Result fsOpenCustomStorageFileSystem(FsFileSystem *out, FsCustomStorageId custom_storage_id)
[7.0.0+]
NcmStorageId
StorageId.
Definition: ncm_types.h:12
Account UserId.
Definition: acc.h:25
Kernel-mode event structure.
Definition: event.h:13
This is nn::fssystem::ArchiveMacKey. Used by setsysGetThemeKey and setsysSetThemeKey....
Definition: fs.h:146
Definition: fs.h:51
Definition: fs.h:35
Directory entry.
Definition: fs.h:56
s64 file_size
File size.
Definition: fs.h:61
s8 type
See FsDirEntryType.
Definition: fs.h:59
Definition: fs.h:47
Definition: fs.h:27
Definition: fs.h:31
Definition: fs.h:264
Definition: fs.h:268
u32 speed_emulation_type
Contains bitflags describing how data is emulated.
Definition: fs.h:270
u32 aes_ctr_key_type
Contains bitflags describing how data is AES encrypted.
Definition: fs.h:269
Definition: fs.h:23
SaveDataAttribute.
Definition: fs.h:65
u16 save_data_index
SaveDataIndex.
Definition: fs.h:71
u64 unk_x38
0 for FsSaveDataType_System/FsSaveDataType_Account.
Definition: fs.h:75
AccountUid uid
AccountUid for the user-specific savedata to access, otherwise 0 for common savedata.
Definition: fs.h:67
u64 system_save_data_id
SystemSaveDataId, 0 for FsSaveDataType_Account.
Definition: fs.h:68
u64 unk_x28
0 for FsSaveDataType_System/FsSaveDataType_Account.
Definition: fs.h:73
u8 save_data_rank
FsSaveDataRank
Definition: fs.h:70
u64 application_id
ApplicationId of the savedata to access when accessing other programs' savedata via SaveData,...
Definition: fs.h:66
u8 save_data_type
FsSaveDataType
Definition: fs.h:69
u64 unk_x30
0 for FsSaveDataType_System/FsSaveDataType_Account.
Definition: fs.h:74
u32 pad_x24
Padding.
Definition: fs.h:72
SaveDataCreationInfo.
Definition: fs.h:99
s64 save_data_size
Size of the save data.
Definition: fs.h:100
u32 flags
FsSaveDataFlags
Definition: fs.h:104
u8 unk
0 for FsSaveDataType_System.
Definition: fs.h:106
u64 owner_id
ProgramId of the owner of this save data. 0 for FsSaveDataType_System.
Definition: fs.h:103
s64 journal_size
Journal size of the save data.
Definition: fs.h:101
u64 available_size
AvailableSize.
Definition: fs.h:102
u8 save_data_space_id
FsSaveDataSpaceId
Definition: fs.h:105
SaveDataExtraData.
Definition: fs.h:79
FsSaveDataAttribute attr
FsSaveDataAttribute
Definition: fs.h:80
u32 unk_x54
Normally 0. Possibly unused?
Definition: fs.h:84
u32 flags
FsSaveDataFlags
Definition: fs.h:83
s64 data_size
Usable save data size.
Definition: fs.h:85
u64 owner_id
ProgramId of the owner of this save data. 0 for FsSaveDataType_System.
Definition: fs.h:81
u64 commit_id
Id of the latest commit.
Definition: fs.h:87
u64 timestamp
POSIX timestamp.
Definition: fs.h:82
s64 journal_size
Journal size of the save data.
Definition: fs.h:86
SaveDataFilter.
Definition: fs.h:126
bool filter_by_save_data_type
Filter by FsSaveDataAttribute::save_data_type.
Definition: fs.h:128
u8 save_data_rank
FsSaveDataRank
Definition: fs.h:132
bool filter_by_application_id
Filter by FsSaveDataAttribute::application_id.
Definition: fs.h:127
FsSaveDataAttribute attr
FsSaveDataAttribute
Definition: fs.h:134
bool filter_by_index
Filter by FsSaveDataAttribute::save_data_index.
Definition: fs.h:131
bool filter_by_system_save_data_id
Filter by FsSaveDataAttribute::system_save_data_id.
Definition: fs.h:130
bool filter_by_user_id
Filter by FsSaveDataAttribute::uid.
Definition: fs.h:129
Definition: fs.h:43
SaveDataInfo.
Definition: fs.h:111
u8 save_data_space_id
FsSaveDataSpaceId
Definition: fs.h:113
u8 save_data_type
FsSaveDataType
Definition: fs.h:114
u64 application_id
ApplicationId for FsSaveDataType_Account.
Definition: fs.h:118
u8 save_data_rank
FsSaveDataRank
Definition: fs.h:121
u64 system_save_data_id
FsSaveDataAttribute::system_save_data_id.
Definition: fs.h:117
AccountUid uid
FsSave::userID.
Definition: fs.h:116
u64 save_data_id
SaveDataId.
Definition: fs.h:112
u16 save_data_index
SaveDataIndex.
Definition: fs.h:120
u64 size
Raw saveimage size.
Definition: fs.h:119
SaveDataMetaInfo.
Definition: fs.h:92
u8 type
FsSaveDataMetaType
Definition: fs.h:94
Definition: fs.h:39
Definition: fs.h:137
u64 created
POSIX timestamp.
Definition: fs.h:138
u8 is_valid
0x1 when the timestamps are set.
Definition: fs.h:141
u64 accessed
POSIX timestamp.
Definition: fs.h:140
u64 modified
POSIX timestamp.
Definition: fs.h:139
Service object structure.
Definition: service.h:13
int64_t s64
64-bit signed integer.
Definition: types.h:28
#define BIT(n)
Creates a bitmask from a bit number.
Definition: types.h:54
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
uint8_t u8
8-bit unsigned integer.
Definition: types.h:19
int8_t s8
8-bit signed integer.
Definition: types.h:25
uint16_t u16
16-bit unsigned integer.
Definition: types.h:20
u32 Result
Function error code result type.
Definition: types.h:44
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21