libnx  v4.2.2
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+].
48 Result fsdevMountTemporaryStorage(const char *name);
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.
74 FsFileSystem* fsdevGetDeviceFileSystem(const char *name);
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).
89 Result fsdevDeleteDirectoryRecursively(const char *path);
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.
fsdevGetDeviceFileSystem
FsFileSystem * fsdevGetDeviceFileSystem(const char *name)
Returns the FsFileSystem for the specified device. Returns NULL when the specified device isn't found...
fsdevDirGetEntries
static FsDirectoryEntry * fsdevDirGetEntries(fsdev_dir_t *dir)
Retrieves a pointer to temporary stage for reading entries.
Definition: fs_dev.h:25
fsdevUnmountDevice
int fsdevUnmountDevice(const char *name)
Unmounts the specified device.
fsdevTranslatePath
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...
fsdev_dir_t::magic
u32 magic
"fsdv"
Definition: fs_dev.h:18
NX_CONSTEXPR
#define NX_CONSTEXPR
Flags a function as constexpr in C++14 and above; or as (always) inline otherwise.
Definition: types.h:92
fsdevCommitDevice
Result fsdevCommitDevice(const char *name)
Uses fsFsCommit() with the specified device.
AccountUid
Account UserId.
Definition: acc.h:25
fsdevDeleteDirectoryRecursively
Result fsdevDeleteDirectoryRecursively(const char *path)
Recursively deletes the directory specified by the input path (as used in stdio).
fsdevMountCacheStorage
Result fsdevMountCacheStorage(const char *name, u64 application_id, u16 save_data_index)
Mounts the specified CacheStorage.
FsSaveDataSpaceId
FsSaveDataSpaceId
SaveDataSpaceId.
Definition: fs.h:204
fsdev_dir_t::index
ssize_t index
Current entry index.
Definition: fs_dev.h:20
fsdevMountSdmc
Result fsdevMountSdmc(void)
Initializes and mounts the sdmc device if accessible.
fsdevUnmountAll
Result fsdevUnmountAll(void)
Unmounts all devices and cleans up any resources used by the FS driver.
u32
uint32_t u32
32-bit unsigned integer.
Definition: types.h:21
fsdevMountDevice
int fsdevMountDevice(const char *name, FsFileSystem fs)
Mounts the input fs with the specified device name.
fsdevMountTemporaryStorage
Result fsdevMountTemporaryStorage(const char *name)
Mounts the TemporaryStorage for the current process.
u64
uint64_t u64
64-bit unsigned integer.
Definition: types.h:22
fsdevMountBcatSaveData
Result fsdevMountBcatSaveData(const char *name, u64 application_id)
Mounts the specified BcatSaveData.
fsdevCreateFile
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).
fsdevSetConcatenationFileAttribute
Result fsdevSetConcatenationFileAttribute(const char *path)
This calls fsFsSetConcatenationFileAttribute on the filesystem specified by the input path (as used i...
Result
u32 Result
Function error code result type.
Definition: types.h:44
fsdevMountDeviceSaveData
Result fsdevMountDeviceSaveData(const char *name, u64 application_id)
Mounts the specified DeviceSaveData.
FsDirectoryEntry
Directory entry.
Definition: fs.h:56
FsDir
Definition: fs.h:35
fsdev_dir_t::fd
FsDir fd
File descriptor.
Definition: fs_dev.h:19
fsdev_dir_t::size
size_t size
Current batch size.
Definition: fs_dev.h:21
FsFileSystem
Definition: fs.h:27
fsdev_dir_t
Open directory struct.
Definition: fs_dev.h:16
fsdevGetLastResult
Result fsdevGetLastResult(void)
Retrieves the last native result code generated during a failed fsdev operation.
fsdevMountSaveDataReadOnly
Result fsdevMountSaveDataReadOnly(const char *name, u64 application_id, AccountUid uid)
Mounts the specified SaveData as ReadOnly.
fsdevMountSystemBcatSaveData
Result fsdevMountSystemBcatSaveData(const char *name, u64 system_save_data_id)
Mounts the specified SystemBcatSaveData.
fsdevMountSaveData
Result fsdevMountSaveData(const char *name, u64 application_id, AccountUid uid)
Mounts the specified SaveData.
u16
uint16_t u16
16-bit unsigned integer.
Definition: types.h:20
fsdevMountSystemSaveData
Result fsdevMountSystemSaveData(const char *name, FsSaveDataSpaceId save_data_space_id, u64 system_save_data_id, AccountUid uid)
Mounts the specified SystemSaveData.