From 5182b57a1d7eab36e21f36fa79bb549a0d6ad2d8 Mon Sep 17 00:00:00 2001 From: yellows8 Date: Thu, 28 Nov 2019 18:51:52 -0500 Subject: [PATCH] fs/fs_dev: Added FsFileSystemQueryId_IsValidSignedSystemPartitionOnSdCard, fsFsIsValidSignedSystemPartitionOnSdCard, and fsdevIsValidSignedSystemPartitionOnSdCard. Improved docs. --- nx/include/switch/runtime/devices/fs_dev.h | 3 +++ nx/include/switch/services/fs.h | 8 +++++++- nx/source/runtime/devices/fs_dev.c | 10 ++++++++++ nx/source/services/fs.c | 10 ++++++++++ 4 files changed, 30 insertions(+), 1 deletion(-) diff --git a/nx/include/switch/runtime/devices/fs_dev.h b/nx/include/switch/runtime/devices/fs_dev.h index 86fdcf6b..0d36e609 100644 --- a/nx/include/switch/runtime/devices/fs_dev.h +++ b/nx/include/switch/runtime/devices/fs_dev.h @@ -56,6 +56,9 @@ int fsdevTranslatePath(const char *path, FsFileSystem** device, char *outpath); /// This calls fsFsSetConcatenationFileAttribute on the filesystem specified by the input path (as used in stdio). Result fsdevSetConcatenationFileAttribute(const char *path); +// Uses \ref fsFsIsValidSignedSystemPartitionOnSdCard with the specified device. +Result fsdevIsValidSignedSystemPartitionOnSdCard(const char *name, bool *out); + /// This calls fsFsCreateFile on the filesystem specified by the input path (as used in stdio). Result fsdevCreateFile(const char* path, size_t size, u32 flags); diff --git a/nx/include/switch/services/fs.h b/nx/include/switch/services/fs.h index 86a33de2..7d4ad8f5 100644 --- a/nx/include/switch/services/fs.h +++ b/nx/include/switch/services/fs.h @@ -272,8 +272,10 @@ typedef enum { FsFileSystemType_RegisteredUpdate = 8, ///< [4.0.0+] RegisteredUpdate } FsFileSystemType; +/// FileSystemQueryId typedef enum { - FsFileSystemQueryId_SetConcatenationFileAttribute = 0, + FsFileSystemQueryId_SetConcatenationFileAttribute = 0, ///< [4.0.0+] + FsFileSystemQueryId_IsValidSignedSystemPartitionOnSdCard = 2, ///< [8.0.0+] } FsFileSystemQueryId; /// FsPriority @@ -380,6 +382,10 @@ void fsFsClose(FsFileSystem* fs); /// This will cause HOS to treat the directory as if it were a file containing the directory's concatenated contents. Result fsFsSetConcatenationFileAttribute(FsFileSystem* fs, const char *path); +/// Wrapper for fsFsQueryEntry with FsFileSystemQueryId_IsValidSignedSystemPartitionOnSdCard. +/// Only available on [8.0.0+]. +Result fsFsIsValidSignedSystemPartitionOnSdCard(FsFileSystem* fs, bool *out); + // IFile Result fsFileRead(FsFile* f, s64 off, void* buf, u64 read_size, u32 option, u64* bytes_read); Result fsFileWrite(FsFile* f, s64 off, const void* buf, u64 write_size, u32 option); diff --git a/nx/source/runtime/devices/fs_dev.c b/nx/source/runtime/devices/fs_dev.c index 634552da..a70b7418 100644 --- a/nx/source/runtime/devices/fs_dev.c +++ b/nx/source/runtime/devices/fs_dev.c @@ -407,6 +407,16 @@ Result fsdevSetConcatenationFileAttribute(const char *path) { return fsFsSetConcatenationFileAttribute(&device->fs, fs_path); } +Result fsdevIsValidSignedSystemPartitionOnSdCard(const char *name, bool *out) { + fsdev_fsdevice *device; + + device = fsdevFindDevice(name); + if(device==NULL) + return MAKERESULT(Module_Libnx, LibnxError_NotFound); + + return fsFsIsValidSignedSystemPartitionOnSdCard(&device->fs, out); +} + Result fsdevCreateFile(const char* path, size_t size, u32 flags) { char *fs_path = __nx_dev_path_buf; fsdev_fsdevice *device = NULL; diff --git a/nx/source/services/fs.c b/nx/source/services/fs.c index 745a2c1e..8ab67afa 100644 --- a/nx/source/services/fs.c +++ b/nx/source/services/fs.c @@ -635,6 +635,16 @@ Result fsFsSetConcatenationFileAttribute(FsFileSystem* fs, const char *path) { return fsFsQueryEntry(fs, NULL, 0, NULL, 0, path, FsFileSystemQueryId_SetConcatenationFileAttribute); } +Result fsFsIsValidSignedSystemPartitionOnSdCard(FsFileSystem* fs, bool *out) { + if (hosversionBefore(8,0,0)) + return MAKERESULT(Module_Libnx, LibnxError_IncompatSysVer); + + u8 tmp=0; + Result rc = fsFsQueryEntry(fs, &tmp, sizeof(tmp), NULL, 0, "/", FsFileSystemQueryId_IsValidSignedSystemPartitionOnSdCard); + if (R_SUCCEEDED(rc) && out) *out = tmp & 1; + return rc; +} + void fsFsClose(FsFileSystem* fs) { _fsObjectClose(&fs->s); }