libnx  v4.8.0
fs_dev.h
Go to the documentation of this file.
1 /**
2  * @file fs_dev.h
3  * @brief FS driver, using devoptab.
4  * @author yellows8
5  * @author mtheall
6  * @copyright libnx Authors
7  */
8 #pragma once
9 
10 #include <sys/types.h>
11 #include "../../services/fs.h"
12 
13 #define FSDEV_DIRITER_MAGIC 0x66736476 ///< "fsdv"
14 
15 /// Open directory struct
16 typedef struct
17 {
18  u32 magic; ///< "fsdv"
19  FsDir fd; ///< File descriptor
20  ssize_t index; ///< Current entry index
21  size_t size; ///< Current batch size
22 } fsdev_dir_t;
23 
24 /// Retrieves a pointer to temporary stage for reading entries
26 {
27  return (FsDirectoryEntry*)(void*)(dir+1);
28 }
29 
30 /// Initializes and mounts the sdmc device if accessible.
32 
33 /// Mounts the specified SaveData.
34 Result fsdevMountSaveData(const char *name, u64 application_id, AccountUid uid);
35 
36 /// Mounts the specified SaveData as ReadOnly.
37 /// Only available on [2.0.0+].
38 Result fsdevMountSaveDataReadOnly(const char *name, u64 application_id, AccountUid uid);
39 
40 /// Mounts the specified BcatSaveData.
41 Result fsdevMountBcatSaveData(const char *name, u64 application_id);
42 
43 /// Mounts the specified DeviceSaveData.
44 Result fsdevMountDeviceSaveData(const char *name, u64 application_id);
45 
46 /// Mounts the TemporaryStorage for the current process.
47 /// Only available on [3.0.0+].
49 
50 /// Mounts the specified CacheStorage.
51 /// Only available on [3.0.0+].
52 Result fsdevMountCacheStorage(const char *name, u64 application_id, u16 save_data_index);
53 
54 /// Mounts the specified SystemSaveData.
55 Result fsdevMountSystemSaveData(const char *name, FsSaveDataSpaceId save_data_space_id, u64 system_save_data_id, AccountUid uid);
56 
57 /// Mounts the specified SystemBcatSaveData.
58 /// Only available on [4.0.0+].
59 Result fsdevMountSystemBcatSaveData(const char *name, u64 system_save_data_id);
60 
61 /// Mounts the input fs with the specified device name. fsdev will handle closing the fs when required, including when fsdevMountDevice() fails.
62 /// Returns -1 when any errors occur.
63 /// Input device name string shouldn't exceed 31 characters, and shouldn't have a trailing colon.
64 int fsdevMountDevice(const char *name, FsFileSystem fs);
65 
66 /// Unmounts the specified device.
67 int fsdevUnmountDevice(const char *name);
68 
69 /// Uses fsFsCommit() with the specified device. This must be used after any savedata-write operations(not just file-write). This should be used after each file-close where file-writing was done.
70 /// This is not used automatically at device unmount.
71 Result fsdevCommitDevice(const char *name);
72 
73 /// Returns the FsFileSystem for the specified device. Returns NULL when the specified device isn't found.
75 
76 /// Writes the FS-path to outpath (which has buffer size FS_MAX_PATH), for the input path (as used in stdio). The FsFileSystem is also written to device when not NULL.
77 int fsdevTranslatePath(const char *path, FsFileSystem** device, char *outpath);
78 
79 /// This calls fsFsSetConcatenationFileAttribute on the filesystem specified by the input path (as used in stdio).
81 
82 // Uses \ref fsFsIsValidSignedSystemPartitionOnSdCard with the specified device.
83 Result fsdevIsValidSignedSystemPartitionOnSdCard(const char *name, bool *out);
84 
85 /// This calls fsFsCreateFile on the filesystem specified by the input path (as used in stdio).
86 Result fsdevCreateFile(const char* path, size_t size, u32 flags);
87 
88 /// Recursively deletes the directory specified by the input path (as used in stdio).
90 
91 /// Unmounts all devices and cleans up any resources used by the FS driver.
93 
94 /// Retrieves the last native result code generated during a failed fsdev operation.
FsSaveDataSpaceId
SaveDataSpaceId.
Definition: fs.h:205
Result fsdevMountSaveDataReadOnly(const char *name, u64 application_id, AccountUid uid)
Mounts the specified SaveData as ReadOnly.
Result fsdevDeleteDirectoryRecursively(const char *path)
Recursively deletes the directory specified by the input path (as used in stdio).
int fsdevTranslatePath(const char *path, FsFileSystem **device, char *outpath)
Writes the FS-path to outpath (which has buffer size FS_MAX_PATH), for the input path (as used in std...
Result fsdevMountTemporaryStorage(const char *name)
Mounts the TemporaryStorage for the current process.
Result fsdevMountCacheStorage(const char *name, u64 application_id, u16 save_data_index)
Mounts the specified CacheStorage.
Result fsdevMountSystemSaveData(const char *name, FsSaveDataSpaceId save_data_space_id, u64 system_save_data_id, AccountUid uid)
Mounts the specified SystemSaveData.
Result fsdevMountBcatSaveData(const char *name, u64 application_id)
Mounts the specified BcatSaveData.
static FsDirectoryEntry * fsdevDirGetEntries(fsdev_dir_t *dir)
Retrieves a pointer to temporary stage for reading entries.
Definition: fs_dev.h:25
Result fsdevGetLastResult(void)
Retrieves the last native result code generated during a failed fsdev operation.
Result fsdevCreateFile(const char *path, size_t size, u32 flags)
This calls fsFsCreateFile on the filesystem specified by the input path (as used in stdio).
Result fsdevSetConcatenationFileAttribute(const char *path)
This calls fsFsSetConcatenationFileAttribute on the filesystem specified by the input path (as used i...
Result fsdevMountDeviceSaveData(const char *name, u64 application_id)
Mounts the specified DeviceSaveData.
int fsdevMountDevice(const char *name, FsFileSystem fs)
Mounts the input fs with the specified device name.
Result fsdevCommitDevice(const char *name)
Uses fsFsCommit() with the specified device.
Result fsdevMountSaveData(const char *name, u64 application_id, AccountUid uid)
Mounts the specified SaveData.
Result fsdevUnmountAll(void)
Unmounts all devices and cleans up any resources used by the FS driver.
int fsdevUnmountDevice(const char *name)
Unmounts the specified device.
Result fsdevMountSdmc(void)
Initializes and mounts the sdmc device if accessible.
Result fsdevMountSystemBcatSaveData(const char *name, u64 system_save_data_id)
Mounts the specified SystemBcatSaveData.
FsFileSystem * fsdevGetDeviceFileSystem(const char *name)
Returns the FsFileSystem for the specified device. Returns NULL when the specified device isn't found...
Account UserId.
Definition: acc.h:25
Definition: fs.h:35
Directory entry.
Definition: fs.h:56
Definition: fs.h:27
Open directory struct.
Definition: fs_dev.h:17
size_t size
Current batch size.
Definition: fs_dev.h:21
u32 magic
"fsdv"
Definition: fs_dev.h:18
FsDir fd
File descriptor.
Definition: fs_dev.h:19
ssize_t index
Current entry index.
Definition: fs_dev.h:20
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
uint16_t u16
16-bit unsigned integer.
Definition: types.h:20
u32 Result
Function error code result type.
Definition: types.h:44
#define NX_CONSTEXPR
Flags a function as constexpr in C++14 and above; or as (always) inline otherwise.
Definition: types.h:92
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21