MCPcopy Create free account
hub / github.com/Atmosphere-NX/Atmosphere / SetFileSize

Function SetFileSize

fusee/program/source/fs/fusee_fs_api.cpp:292–314  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

290 }
291
292 Result SetFileSize(FileHandle handle, s64 size) {
293 FIL *fp = GetInternalFile(handle);
294
295 /* Check if we have nothing to do. */
296 const size_t fsize = f_size(fp);
297 R_SUCCEED_IF(static_cast<FSIZE_t>(size) == fsize);
298
299 /* NOTE/TODO: This may not preserve file data. Do this in a way that does? */
300
301 /* Truncate the file. */
302 R_TRY(TranslateFatFsError(f_truncate(fp)));
303
304 /* Expand the file. */
305 R_TRY(TranslateFatFsError(f_expand(fp, size, 1)));
306
307 /* Ensure the file is synchronized. */
308 R_TRY(FlushFile(handle));
309
310 /* Check that our expansion succeeded. */
311 AMS_ASSERT(f_size(fp) == static_cast<FSIZE_t>(size));
312
313 R_SUCCEED();
314 }
315
316 int GetFileOpenMode(FileHandle handle) {
317 return g_open_modes[GetFileIndex(GetInternalFile(handle))];

Callers 4

SetSizeMethod · 0.70
ProcessRequestMethod · 0.50
DoFsTestsFunction · 0.50

Calls 5

GetInternalFileFunction · 0.70
TranslateFatFsErrorFunction · 0.70
FlushFileFunction · 0.70
f_truncateFunction · 0.50
f_expandFunction · 0.50

Tested by 1

DoFsTestsFunction · 0.40