My Project
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules
fs.h
Go to the documentation of this file.
1 #pragma once
2 #include <string.h>
3 #include <3ds/types.h>
4 
19 #define FS_OPEN_READ (1<<0)
20 
21 #define FS_OPEN_WRITE (1<<1)
22 
23 #define FS_OPEN_CREATE (1<<2)
24 /* @} */
25 
35 #define FS_ATTRIBUTE_NONE (0x00000000)
36 
37 #define FS_ATTRIBUTE_READONLY (0x00000001)
38 
39 #define FS_ATTRIBUTE_ARCHIVE (0x00000100)
40 
41 #define FS_ATTRIBUTE_HIDDEN (0x00010000)
42 
43 #define FS_ATTRIBUTE_DIRECTORY (0x01000000)
44 
54 #define FS_WRITE_NOFLUSH (0x00000000)
55 
56 #define FS_WRITE_FLUSH (0x00010001)
57 
58 /* @} */
59 
61 typedef enum
62 {
64  PATH_EMPTY = 1,
66  PATH_CHAR = 3,
67  PATH_WCHAR = 4,
68 } FS_pathType;
69 
71 typedef enum
72 {
73  ARCH_ROMFS = 0x3,
75  ARCH_EXTDATA = 0x6,
78  ARCH_SDMC = 0x9,
80  ARCH_BOSS_EXTDATA = 0x12345678,
81  ARCH_CARD_SPIFS = 0x12345679,
82  ARCH_NAND_RW = 0x1234567D,
83  ARCH_NAND_RO = 0x1234567E,
86 
88 typedef struct
89 {
92  const u8 *data;
93 } FS_path;
94 
96 typedef struct
97 {
98  u32 id;
102 } FS_archive;
103 
105 typedef struct
106 {
107  // 0x00
108  u16 name[0x106];
109  // 0x20C
110  u8 shortName[0x09];
111  // 0x215
113  // 0x216
114  u8 shortExt[0x04];
115  // 0x21A
117  // 0x21B
119  // 0x21C
121  // 0x21D
123  // 0x21E
125  // 0x21F
127  // 0x220
129 } FS_dirent;
130 
140 static inline FS_path
141 FS_makePath(FS_pathType type,
142  const char *path)
143 {
144  return (FS_path){type, strlen(path)+1, (const u8*)path};
145 }
146 
147 Result fsInit(void);
148 Result fsExit(void);
149 
151 Result FSUSER_OpenArchive(Handle* handle, FS_archive* archive);
152 Result FSUSER_OpenDirectory(Handle* handle, Handle* out, FS_archive archive, FS_path dirLowPath);
153 Result FSUSER_OpenFile(Handle* handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes);
154 Result FSUSER_OpenFileDirectly(Handle* handle, Handle* out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes);
155 Result FSUSER_CloseArchive(Handle* handle, FS_archive* archive);
156 Result FSUSER_CreateDirectory(Handle* handle, FS_archive archive, FS_path dirLowPath);
157 Result FSUSER_DeleteFile(Handle *handle, FS_archive archive, FS_path fileLowPath);
158 Result FSUSER_DeleteDirectory(Handle *handle, FS_archive archive, FS_path dirLowPath);
159 Result FSUSER_RenameFile(Handle *handle, FS_archive srcArchive, FS_path srcFileLowPath, FS_archive destArchive, FS_path destFileLowPath);
160 Result FSUSER_RenameDirectory(Handle *handle, FS_archive srcArchive, FS_path srcDirLowPath, FS_archive destArchive, FS_path destDirLowPath);
161 Result FSUSER_GetSdmcArchiveResource(Handle *handle, u32 *sectorSize, u32 *clusterSize, u32 *numClusters, u32 *freeClusters);
162 Result FSUSER_IsSdmcDetected(Handle *handle, u32 *detected);
163 Result FSUSER_IsSdmcWritable(Handle *handle, u32 *writable);
164 
165 Result FSFILE_Close(Handle handle);
166 Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, void *buffer, u32 size);
167 Result FSFILE_Write(Handle handle, u32 *bytesWritten, u64 offset, const void *buffer, u32 size, u32 flushFlags);
168 Result FSFILE_GetSize(Handle handle, u64 *size);
169 Result FSFILE_SetSize(Handle handle, u64 size);
170 Result FSFILE_GetAttributes(Handle handle, u32 *attributes);
171 Result FSFILE_SetAttributes(Handle handle, u32 attributes);
172 Result FSFILE_Flush(Handle handle);
173 
174 Result FSDIR_Read(Handle handle, u32 *entriesRead, u32 entrycount, FS_dirent *buffer);
175 Result FSDIR_Close(Handle handle);
Result FSUSER_IsSdmcWritable(Handle *handle, u32 *writable)
Definition: fs.c:869
Result FSDIR_Close(Handle handle)
Definition: fs.c:1325
Result fsInit(void)
Definition: fs.c:22
Definition: fs.h:105
Result FSFILE_SetAttributes(Handle handle, u32 attributes)
Definition: fs.c:1202
s32 Result
Definition: types.h:42
u8 unknown1
???
Definition: fs.h:112
u8 isArchive
archive bit
Definition: fs.h:124
uint16_t u16
Definition: types.h:22
FS_pathType type
FS path type.
Definition: fs.h:90
Result FSUSER_OpenArchive(Handle *handle, FS_archive *archive)
Definition: fs.c:663
Result FSUSER_RenameFile(Handle *handle, FS_archive srcArchive, FS_path srcFileLowPath, FS_archive destArchive, FS_path destFileLowPath)
Definition: fs.c:340
Specifies an invalid path.
Definition: fs.h:63
Result FSDIR_Read(Handle handle, u32 *entriesRead, u32 entrycount, FS_dirent *buffer)
Definition: fs.c:1281
u32 Handle
Definition: types.h:41
Result FSUSER_DeleteFile(Handle *handle, FS_archive archive, FS_path fileLowPath)
Definition: fs.c:276
Result FSFILE_Flush(Handle handle)
Definition: fs.c:1239
uint8_t u8
Definition: types.h:21
uint64_t u64
Definition: types.h:24
Result FSFILE_Close(Handle handle)
Definition: fs.c:911
Result FSFILE_SetSize(Handle handle, u64 size)
Definition: fs.c:1120
Result FSUSER_OpenDirectory(Handle *handle, Handle *out, FS_archive archive, FS_path dirLowPath)
Definition: fs.c:605
u32 id
Archive ID.
Definition: fs.h:98
Result FSFILE_GetSize(Handle handle, u64 *size)
Definition: fs.c:1078
Result FSUSER_CloseArchive(Handle *handle, FS_archive *archive)
Definition: fs.c:717
uint32_t u32
Definition: types.h:23
Specifies a text based path with a 16-bit short per character.
Definition: fs.h:67
Result FSFILE_Write(Handle handle, u32 *bytesWritten, u64 offset, const void *buffer, u32 size, u32 flushFlags)
Definition: fs.c:1026
Specifies a binary path, which is non-text based.
Definition: fs.h:65
u8 unknown2
???
Definition: fs.h:116
Result FSUSER_OpenFileDirectly(Handle *handle, Handle *out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes)
Definition: fs.c:209
Result FSUSER_IsSdmcDetected(Handle *handle, u32 *detected)
Definition: fs.c:825
Result FSUSER_GetSdmcArchiveResource(Handle *handle, u32 *sectorSize, u32 *clusterSize, u32 *numClusters, u32 *freeClusters)
Definition: fs.c:769
Result FSUSER_OpenFile(Handle *handle, Handle *out, FS_archive archive, FS_path fileLowPath, u32 openflags, u32 attributes)
Definition: fs.c:130
FS_path lowPath
FS path.
Definition: fs.h:99
u8 isHidden
hidden bit
Definition: fs.h:122
Result FSFILE_Read(Handle handle, u32 *bytesRead, u64 offset, void *buffer, u32 size)
Definition: fs.c:959
FS_pathType
Definition: fs.h:61
Result FSFILE_GetAttributes(Handle handle, u32 *attributes)
Definition: fs.c:1161
u8 isReadOnly
read-only bit
Definition: fs.h:126
const u8 * data
Pointer to FS path data.
Definition: fs.h:92
u8 isDirectory
directory bit
Definition: fs.h:120
Result FSUSER_CreateDirectory(Handle *handle, FS_archive archive, FS_path dirLowPath)
Definition: fs.c:475
Specifies a text based path with a 8-bit byte per character.
Definition: fs.h:66
Definition: fs.h:96
Specifies an empty path.
Definition: fs.h:64
Definition: fs.h:88
Handle handleLow
High word of handle.
Definition: fs.h:100
FS_archiveIds
Definition: fs.h:71
u8 unknown3
???
Definition: fs.h:118
Definition: fs.h:78
Handle handleHigh
Low word of handle.
Definition: fs.h:101
u64 fileSize
file size
Definition: fs.h:128
Result fsExit(void)
Definition: fs.c:35
Result FSUSER_RenameDirectory(Handle *handle, FS_archive srcArchive, FS_path srcDirLowPath, FS_archive destArchive, FS_path destDirLowPath)
Definition: fs.c:540
Result FSUSER_Initialize(Handle *handle)
Definition: fs.c:65
Result FSUSER_DeleteDirectory(Handle *handle, FS_archive archive, FS_path dirLowPath)
Definition: fs.c:404
Definition: fs.h:73
u32 size
FS path size.
Definition: fs.h:91