| 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))]; |