]> Chaos Git - corbenik/ctrulib.git/commitdiff
Merge branch 'master' into great-refactor
authorfincs <fincs.alt1@gmail.com>
Thu, 19 Nov 2015 10:44:59 +0000 (11:44 +0100)
committerfincs <fincs.alt1@gmail.com>
Thu, 19 Nov 2015 10:44:59 +0000 (11:44 +0100)
# Conflicts:
# libctru/include/3ds/services/fs.h
# libctru/source/os.c
# libctru/source/romfs_dev.c
# libctru/source/services/fs.c

1  2 
libctru/include/3ds/os.h
libctru/source/os-versionbin.c

index db3db6d51e203e7fb5cfbb06b5d2891204c4c004,cc8b16c1817b49ff946acc51997287bb585c95cb..03004a55c52d6631417a0dda5dcfc5389c5c1319
@@@ -8,19 -8,23 +8,30 @@@
  #define SYSTEM_VERSION(major, minor, revision) \
        (((major)<<24)|((minor)<<16)|((revision)<<8))
  
 +/// Retrieves the major version from a packed system version.
  #define GET_VERSION_MAJOR(version)    ((version) >>24)
 +
 +/// Retrieves the minor version from a packed system version.
  #define GET_VERSION_MINOR(version)    (((version)>>16)&0xFF)
 +
 +/// Retrieves the revision version from a packed system version.
  #define GET_VERSION_REVISION(version) (((version)>> 8)&0xFF)
  
+ /*! OS_VersionBin. Format of the system version: "<major>.<minor>.<build>-<nupver><region>" */
+ typedef struct
+ {
+       u8 build;
+       u8 minor;
+       u8 mainver;//"major" in CVER, NUP version in NVer.
+       u8 reserved_x3;
+       char region;//"ASCII character for the system version region"
+       u8 reserved_x5[0x3];
+ } OS_VersionBin;
  /**
 - * Converts an address from virtual (process) memory to physical memory.
 + * @brief Converts an address from virtual (process) memory to physical memory.
 + * @param vaddr Input virtual address.
 + * @return The corresponding physical address.
   * It is sometimes required by services or when using the GPU command buffer.
   */
  u32 osConvertVirtToPhys(u32 vaddr);
@@@ -107,3 -90,23 +118,22 @@@ static inline float osGet3DSliderState(
   * @param enable Specifies whether to enable or disable the speedup.
   */
  void osSetSpeedupEnable(bool enable);
 -
+ /**
+  * @brief Gets the NAND system-version stored in NVer/CVer.
+  * The romfs device must not be already initialized(via romfsInit*()) at the time this function is called, since this code uses the romfs device.
+  * @param nver_versionbin Output OS_VersionBin structure for the data read from NVer.
+  * @param cver_versionbin Output OS_VersionBin structure for the data read from CVer.
+  * @return The result-code. This value can be positive if opening "romfs:/version.bin" fails with stdio, since errno would be returned in that case. In some cases the error can be special negative values as well.
+  */
+ Result osGetSystemVersionData(OS_VersionBin *nver_versionbin, OS_VersionBin *cver_versionbin);
+ /**
+  * @brief This is a wrapper for osGetSystemVersionData.
+  * @param nver_versionbin Optional output OS_VersionBin structure for the data read from NVer, can be NULL.
+  * @param cver_versionbin Optional output OS_VersionBin structure for the data read from CVer, can be NULL.
+  * @param sysverstr Output string where the printed system-version will be written, in the same format displayed by the System Settings title.
+  * @param sysverstr_maxsize Max size of the above string buffer, *including* NULL-terminator.
+  * @return See osGetSystemVersionData.
+  */
+ Result osGetSystemVersionDataString(OS_VersionBin *nver_versionbin, OS_VersionBin *cver_versionbin, char *sysverstr, u32 sysverstr_maxsize);
index 0000000000000000000000000000000000000000,0000000000000000000000000000000000000000..464903d0ee34cba5b5c3b66d741990abd0a8a9c3
new file mode 100644 (file)
--- /dev/null
--- /dev/null
@@@ -1,0 -1,0 +1,125 @@@
++#include <3ds/types.h>
++#include <3ds/result.h>
++#include <3ds/os.h>
++#include <3ds/svc.h>
++#include <3ds/romfs.h>
++#include <3ds/services/ptmsysm.h>
++#include <3ds/services/fs.h>
++#include <3ds/services/cfgu.h>
++
++#include <sys/time.h>
++#include <reent.h>
++#include <stdio.h>
++#include <errno.h>
++#include <string.h>
++
++//See here regarding regions: http://3dbrew.org/wiki/Nandrw/sys/SecureInfo_A
++
++static u32 __NVer_tidlow_regionarray[7] = {
++      0x00016202, //JPN
++      0x00016302, //USA
++      0x00016102, //EUR
++      0x00016202, //"AUS"
++      0x00016402, //CHN
++      0x00016502, //KOR
++      0x00016602, //TWN
++};
++
++static u32 __CVer_tidlow_regionarray[7] = {
++      0x00017202, //JPN
++      0x00017302, //USA
++      0x00017102, //EUR
++      0x00017202, //"AUS"
++      0x00017402, //CHN
++      0x00017502, //KOR
++      0x00017602 //TWN
++};
++
++
++static Result __read_versionbin(FS_Archive archive, FS_Path fileLowPath, OS_VersionBin *versionbin)
++{
++      Result ret = 0;
++      Handle filehandle = 0;
++      FILE *f = NULL;
++
++      ret = FSUSER_OpenFileDirectly(&filehandle, archive, fileLowPath, FS_OPEN_READ, 0x0);
++      if(R_FAILED(ret))return ret;
++
++      ret = romfsInitFromFile(filehandle, 0x0);
++      if(R_FAILED(ret))return ret;
++
++      f = fopen("romfs:/version.bin", "r");
++      if(f==NULL)
++      {
++              ret = errno;
++      }
++      else
++      {
++              if(fread(versionbin, 1, sizeof(OS_VersionBin), f) != sizeof(OS_VersionBin))ret = -10;
++              fclose(f);
++      }
++
++      romfsExit();
++
++      return ret;
++}
++
++Result osGetSystemVersionData(OS_VersionBin *nver_versionbin, OS_VersionBin *cver_versionbin)
++{
++      Result ret=0;
++      u8 region=0;
++
++      u32 archive_lowpath_data[0x10>>2];
++      u32 file_lowpath_data[0x14>>2];
++
++      FS_Archive archive;
++      FS_Path fileLowPath;
++
++      memset(archive_lowpath_data, 0, sizeof(archive_lowpath_data));
++      memset(file_lowpath_data,    0, sizeof(file_lowpath_data));
++
++      archive.id = 0x2345678a;
++      archive.lowPath.type = PATH_BINARY;
++      archive.lowPath.size = 0x10;
++      archive.lowPath.data = archive_lowpath_data;
++
++      fileLowPath.type = PATH_BINARY;
++      fileLowPath.size = 0x14;
++      fileLowPath.data = file_lowpath_data;
++
++      archive_lowpath_data[1] = 0x000400DB;
++
++      ret = cfguInit();
++      if(R_FAILED(ret))return ret;
++
++      ret = CFGU_SecureInfoGetRegion(&region);
++      if(R_FAILED(ret))return ret;
++
++      if(region>=7)return -9;
++
++      cfguExit();
++
++      archive_lowpath_data[0] = __NVer_tidlow_regionarray[region];
++      ret = __read_versionbin(archive, fileLowPath, nver_versionbin);
++      if(R_FAILED(ret))return ret;
++
++      archive_lowpath_data[0] = __CVer_tidlow_regionarray[region];
++      ret = __read_versionbin(archive, fileLowPath, cver_versionbin);
++      return ret;
++}
++
++Result osGetSystemVersionDataString(OS_VersionBin *nver_versionbin, OS_VersionBin *cver_versionbin, char *sysverstr, u32 sysverstr_maxsize)
++{
++      Result ret=0;
++      OS_VersionBin nver_versionbin_tmp, cver_versionbin_tmp;
++
++      if(nver_versionbin==NULL)nver_versionbin = &nver_versionbin_tmp;
++      if(cver_versionbin==NULL)cver_versionbin = &cver_versionbin_tmp;
++
++      ret = osGetSystemVersionData(nver_versionbin, cver_versionbin);
++      if(R_FAILED(ret))return ret;
++
++      snprintf(sysverstr, sysverstr_maxsize, "%u.%u.%u-%u%c\n", cver_versionbin->mainver, cver_versionbin->minor, cver_versionbin->build, nver_versionbin->mainver, nver_versionbin->region);
++
++      return 0;
++}