From a2d4699f1f840a4f62b052fa9c1fd18829753b85 Mon Sep 17 00:00:00 2001 From: Michael Scire Date: Fri, 9 Nov 2018 01:21:31 -0800 Subject: [PATCH] fs: Add fsFsSetArchiveBit --- nx/include/switch/services/fs.h | 8 ++++++ nx/source/services/fs.c | 44 +++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index dfa14822..080dcb89 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -178,6 +178,11 @@ typedef enum FsFileSystemType_ApplicationPackage = 7 } FsFileSystemType; +typedef enum +{ + FsFileSystemQueryType_SetArchiveBit = 0, +} FsFileSystemQueryType; + /// Mount requested filesystem type from content file Result fsOpenFileSystem(FsFileSystem* out, FsFileSystemType fsType, const char* contentPath); /// same as calling fsOpenFileSystemWithId with 0 as titleId Result fsOpenFileSystemWithId(FsFileSystem* out, u64 titleId, FsFileSystemType fsType, const char* contentPath); /// works on all firmwares, titleId is ignored on 1.0.0 @@ -197,6 +202,9 @@ Result fsFsCommit(FsFileSystem* fs); Result fsFsGetFreeSpace(FsFileSystem* fs, const char* path, u64* out); Result fsFsGetTotalSpace(FsFileSystem* fs, const char* path, u64* out); Result fsFsCleanDirectoryRecursively(FsFileSystem* fs, const char* path); +Result fsFsQueryEntry(FsFileSystem* fs, void *out, size_t out_size, const void *in, size_t in_size, const char* path, FsFileSystemQueryType query_type); +Result fsFsSetArchiveBit(FsFileSystem* fs, const char *path); + void fsFsClose(FsFileSystem* fs); // IFile diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index 2967b0c4..c6c0cf95 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -1007,6 +1007,50 @@ Result fsFsCleanDirectoryRecursively(FsFileSystem* fs, const char* path) { return rc; } +Result fsFsQueryEntry(FsFileSystem* fs, void *out, size_t out_size, const void *in, size_t in_size, const char* path, FsFileSystemQueryType query_type) { + char send_path[FS_MAX_PATH] = {0}; + strncpy(send_path, path, sizeof(send_path)-1); + + IpcCommand c; + ipcInitialize(&c); + ipcAddSendStatic(&c, send_path, sizeof(send_path), 0); + ipcAddSendBuffer(&c, in, in_size, BufferType_Type1); + ipcAddRecvBuffer(&c, out, out_size, BufferType_Type1); + + struct { + u64 magic; + u64 cmd_id; + u32 query_type; + } *raw; + + raw = serviceIpcPrepareHeader(&fs->s, &c, sizeof(*raw)); + + raw->magic = SFCI_MAGIC; + raw->cmd_id = 15; + raw->query_type = query_type; + + Result rc = serviceIpcDispatch(&fs->s); + + if (R_SUCCEEDED(rc)) { + IpcParsedCommand r; + struct { + u64 magic; + u64 result; + } *resp; + + serviceIpcParse(&fs->s, &r, sizeof(*resp)); + resp = r.Raw; + + rc = resp->result; + } + + return rc; +} + +Result fsFsSetArchiveBit(FsFileSystem* fs, const char *path) { + return fsFsQueryEntry(fs, NULL, 0, NULL, 0, path, FsFileSystemQueryType_SetArchiveBit); +} + void fsFsClose(FsFileSystem* fs) { serviceClose(&fs->s); }