> For the complete documentation index, see [llms.txt](https://sandbox-docs.verifone.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sandbox-docs.verifone.com/s-adk-5.1-programmers-guide/filesystem_8h_source.md).

# filesystem.h

[Go to the documentation of this file.](/s-adk-5.1-programmers-guide/readme/files/dir_44d926a17fc606d3c25449ba60427c63/dir_048f823fee1bfb22502a8732b9a001aa/filesystem_8h.md)

```cpp
 1 #ifndef _FILESYSTEM_
 2 #define _FILESYSTEM_
 3 
 4 #include <string>
 5 #include <vector>
 6 #include "config/sdi_sysconfig.h"
 7 
 8 /****** SDI-SERVER FILENAME DEFINITIONS ******/
 9 
 10 // subfolder for COM files
 11 #define COM_PREFIX "com/"
 12 // subfolder for COM files used on CM5/M424/M440
 13 #define COM_ANDROID "com/android/"
 14 
 15 // ADKCOM connection profiles
 16 #define CONNECT_LAN_FILE "CONNECT_LAN.XML" // COM_PREFIX added later in code
 17 #define CONNECT_BT_FILE "CONNECT_BT.XML" // COM_PREFIX added later in code
 18 #define CONNECT_WIFI_FILE "CONNECT_WIFI.XML" // COM_PREFIX added later in code
 19 #define CONNECT_USB_SER_FILE "CONNECT_USB_SER.XML" // COM_PREFIX added later in code
 20 #define CONNECT_USB_LAN_FILE "CONNECT_USB_LAN.XML" // COM_PREFIX added later in code
 21 #define CONNECT_COM1A_FILE "CONNECT_COM1A.XML" // COM_PREFIX added later in code
 22 #define CONNECT_BLE_FILE "CONNECT_BLE.XML" // COM_PREFIX added later in code
 23 #define CONNECT_COM1_FILE "CONNECT_COM1.XML" // COM_PREFIX added later in code
 24 #define CONNECT_ANY_FILE "CONNECT_ANY.XML" // COM_PREFIX added later in code
 25 #define CONNECT_LO_FILE "CONNECT_LO.XML" // COM_PREFIX added later in code
 26 #define CONNECT_ANDROID_FILE "CONNECT_ANDROID.XML" // COM_PREFIX added later in code
 27 // name of ADKCOM GATT server configuration file (BLE)
 28 #define BLE_GATT_FILE "gatt.xml" // COM_PREFIX added later in code
 29 // name of ADKCOM BT network profile copy in flash
 30 #define LOCAL_NET_BT_PAN_FILE "LOCAL_NET_BT_PAN.xml" // COM_PREFIX added later in code
 31 
 32 // name of ADKCOM CCP database file (under $HOME/flash/sdi/com)
 33 #define CCP_DATABASE_FILE "ccp.db" // COM_PREFIX added later in code
 34 // COM configuration file
 35 #define COM_IF_CONFIG_FILE "COM_IF.CFG" // COM_PREFIX added later in code
 36 
 37 /* subfolder for ADKSEC files (recently used for Android user configuration package)
 38  * Note: This prefix is also used by VOS user configuration packages. ADKSEC
 39  * knows this path, since it set with environment variable SCAPPCFG in start file */
 40 #define SEC_PREFIX "sec/"
 41 // ADKSEC configuration file
 42 #define ADKSEC_CONFIG_FILE "sccfg.json" // SEC_PREFIX added later in code
 43 
 44 // subfolder for EPP files
 45 #define EPP_PREFIX "epp/"
 46 // subfolder for CT files
 47 #define CT_PREFIX "ct/"
 48 // EPP configuration file
 49 #define EPP_CONFIG_FILE "epp.json" // EPP_PREFIX/CT_PREFIX added later in code
 50 // CT/EPP network profiles
 51 #define LOCAL_NET_USB_CT "LOCAL_NET_USB_CT.xml" // CT_PREFIX added later in code
 52 #define LOCAL_NET_USB_EPP "LOCAL_NET_USB_EPP.xml" // EPP_PREFIX added later in code
 53 // ADKCOM connection profile used by EPP
 54 #define CONNECT_EPP_TLS "CONNECT_EPP_TLS.XML" // EPP_PREFIX added later in code
 55 
 56 /* subfolder for EMV files (recently used for Android user configuration package)
 57  * Note: ADKEMV specifies "adkemv" as prefix for internal EMV files, but this is handled
 58  * by functions emv_flash_dir() and emv_config_dir(), which already add this prefix. */
 59 #define EMV_PREFIX "emv/"
 60 // EMV (read-only) config file emv-desired.xml
 61 #define EMV_DESIRED_FILE "emv-desired.xml"
 62 // reg-ex pattern for EMV flash configuration files
 63 #define EMV_FLASH_CONFIG_FILES "EMV_.*\\.xml"
 64 
 65 // SDI server specific files (don't use a prefix)
 66 #define SDI_TRX_DATA_FILE "sdi_trx.dat"
 67 #define WHITELIST_FILE "whitelist.json"
 68 #define SENSITIVE_TAGS_FILE "sensitivetags.json"
 69 #define CARD_RANGES_FILE "cardranges.json"
 70 #define STATUS_CFG_FILE "STATUS.CFG"
 71 #define IDLETEXT_CFG_FILE "IDLETEXT.CFG"
 72 #define SDI_CONFIG_FILE "config.json"
 73 #define SDI_ACL_FILE "acl.json"
 74 #define FS_CHECKSUMS_FILE "checksums.json"
 75 
 76 /* Android, Titus, x86: removal file for command
 77  * 20-1D (Check for update) with upload type 8 (user config removal)
 78  * or with upload type 10 (plugin removal) */
 79 #define UPDATE_REMOVE_FILE "remove.json"
 80 
 81 /* On Android/x86 this file used as indicator in sdi_persist_dir()
 82  * that all files in this folder are gzip compressed */
 83 #define PERSIST_COMPRESSED_FILE ".gzip_compressed"
 84 /* Android/x86 use PERSIST_COMPRESSED_FILE on persist partition. This must be ignored
 85  * by install_configuration() with this pattern for recorery with factory reset. */
 86 #define REGEX_NO_HIDDEN_FILES "^[^\\.].*"
 87 /* On Android the /persist folder contains a kpi folder (with K81 update log file etc.),
 88  * which must be ignored for compression. This regex is used to ignored it. */
 89 #define REGEX_KPI_FOLDER ".*\\/kpi\\/[^\\/ ]+$"
 90 
 91 // subfolder for SDI plugins (recently used for Android user configuration package)
 92 #define PLUGIN_PREFIX "plugin/"
 93 // plugin file extension
 94 #define PLUGIN_EXT ".so"
 95 // reg-ex pattern to match SDI plugins
 96 #define PLUGIN_PATTERN "libsdiplugin.*\\" PLUGIN_EXT
 97 // reg-ex pattern to match SDI plugin configuration
 98 #define PLUGIN_CONFIG_PATTERN "libsdiplugin.*\\.(cfg|json)"
 99 // reg-ex pattern for EMV-ADK girocard kernel wrapper, any version
 100 #define GCKERNEL_PATTERN "libEMV_CTLS_GC[0-9]{6}\\.so"
 101 // devtool service library name
 102 #define LIBDEVTOOLSVC_NAME "libsdidevtoolsvc.so"
 103 
 104 // subfolder for ADKLOG configuration files (recently used for Android user configuration package)
 105 #define LOG_PREFIX "log/"
 106 // ADKLOG configuration files
 107 #define LOG_CONFIG_FILES ".*_log\\.conf"
 108 
 109 // subfolder for ADKNFC configuration files (recently used for Android user configuration package)
 110 #define NFC_PREFIX "nfc/"
 111 // ADKNFC wallet key files (wky) files
 112 #define NFC_WKY_FILES ".*\\.wky"
 113 
 114 // subfolder for fonts (recently used by ADKPRT for Android user configuration package only)
 115 #define FONT_PREFIX "fonts/"
 116 // fonts files (true type font)
 117 #define FONT_FILES ".*\\.(afm|fnt|fon|gsf|otf|pfa|pfb|pfm|ttc|ttf)"
 118 
 119 #if defined _VOS // grsec on VOS/VOS2 requires to put global shared files to /tmp/share
 120  // lock file to check another running SDI instance
 121  #define SDI_LOCK_FILE "/tmp/share/sdi.lock"
 122  // file to signal SDI server that sdi_cleaner has finished
 123  #define SDI_CLEANUP_DONE_FILE "/tmp/share/sdi.cleanup_done"
 124 #elif defined _VOS3
 125  // lock file to check another running SDI instance
 126  #define SDI_LOCK_FILE "/tmp/sdi.lock"
 127 #endif
 128 
 129 #if defined(__ANDROID__) || defined(_VOS3)
 130  // default name of PEM output file containing CA for CT (EPP client), usually contains AuthEx/AuthN CA
 131  #define EPP_CA_PEM_FILE "epp_ca.pem"
 132 #endif
 133 
 134 // internal file names used by SW upload 20-14/20-15/20-16
 135 #define EMV_CONFIG_TARBALL "emv-config.tar"
 136 #ifdef _STM32
 137  // filename of uploaded download package stored in upload_install_dir()
 138  #define STM32_DL_FILENAME "update.tar"
 139  // file name of uploaded VRK package stored in upload_install_dir()
 140  #define STM32_UVRK_FILENAME "vrkpkg.tar"
 141  // folder prefix in upload_install_dir() to store manifest.json of last DL package
 142  #define STM32_INSTALL_RESULT_PREFIX "result"
 143  /* POSIX regular expression syntax doesn't allow modifier "(?i)", in addition, interface
 144  * of matchRegex() would require new parameter to pass regex option REG_ICASE. Therefore,
 145  * we use character class [Mm]... to match manifest file name case insensitive. */
 146  #define STM32_MANIFEST_PATTERN "[Mm][Aa][Nn][Ii][Ff][Ee][Ss][Tt]\\.[Jj][Ss][Oo][Nn]$"
 147  // name of Titus installation report file
 148  #define STM32_INSTALL_REPORT_FILE "report.json"
 149 #endif
 150 
 151 /****** FILESYSTEM NAMESPACE & FUNCTIONS ******/
 152 
 153 namespace sdi
 154 {
 155  namespace filesystem
 156  {
 157 
 203  void init(enum config::SdiSysConfig::SDIMode sdi_mode);
 204 
 221  void factory_reset();
 222 
 227  bool read_file(const char *file, std::string &data);
 228 
 233  bool write_file(const char *file, const std::string &data);
 234 
 239  bool copy_file(const std::string &src, const std::string &dest);
 240 
 245  bool move_file(const std::string &src, const std::string &dest);
 246 
 247  enum DirModes
 248  {
 249  DM_Default = 0,
 250  DM_Recursive = 1,
 251  DM_Relative = 2,
 252  DM_NoAbort = 4,
 253  DM_MatchFileOnly = 8,
 254  DM_MatchInverted = 16
 256  };
 257 
 272  int get_dir_files(const char *dir, std::vector<std::string> *files = 0, const char *regex = 0, unsigned modes = DM_Default);
 273 
 275  enum FilesModes
 276  {
 277  FM_Default = 0,
 278  FM_NoAbort = 1,
 281  FM_Quiet = 2,
 283  FM_KeepTopDir = 4
 285  };
 286 
 294  int copy_files(const std::vector<std::string> &files, const char *dst_dir, unsigned modes = FM_Default);
 295 
 302  int remove_files(const std::vector<std::string> &files, unsigned modes = FM_Default);
 303 
 310  int remove_dir(const std::string &path, unsigned modes = FM_Default);
 311 
 330  int extract_tar(const std::string &tarfile, const std::string &destdir, const char *regex = 0);
 331 
 335  const char* binary_dir();
 336 
 346  const char* home_flash_dir();
 350  std::string home_flash_file(const std::string &file);
 351 
 361  const char* home_config_dir();
 362 
 368  std::string home_config_file(const std::string &file);
 369 
 384  const char* ext_config_dir();
 396  std::string lookup_config_file(const std::string &file);
 397 
 407  const char* emv_flash_dir();
 408 
 416  const char* emv_config_dir();
 417 
 425  const char* log_config_dir();
 426 
 433  const char* nfc_flash_dir();
 434 
 441  const char* home_lib_dir();
 442 
 453  const char* ext_plugin_dir();
 454 
 465  const char* plugin_config_dir();
 466 
 476  const char* ext_font_dir();
 477 
 485  const char* tmp_dir();
 486 
 501  const char* upload_install_dir(bool flash = true);
 502 
 510  const char* sys_remove_sponsor_dir();
 511 
 520  const char* ccp_resource_dir();
 521 
 528  const char* ccp_database_dir();
 529 
 540  const char* sdi_update_dir();
 541 
 553  const char* sdi_persist_dir(bool system = false);
 554 
 560  const char* sdi_certstore_dir();
 561 
 562  /**** Functions required for command "EMV config upload (20-14/20-15/20-16)" ****/
 563 
 571  unsigned short install_emv_config_package(const std::string &emv_config_pkg);
 572 
 573  // x86, ANDROID & Co.
 574 #if !defined (_VOS) && !defined (_VOS3) && !defined (_STM32)
 575  /**** Functions required for command "Check for update (20-1D)" (not supported for VOS/VOS2/VOS3) ****/
 576 
 594  unsigned short install_user_configuration(bool recover = false);
 595 
 627  unsigned short remove_user_configuration();
 628 
 648  unsigned short install_sdi_plugins(bool recover = false);
 649 
 680  unsigned short remove_sdi_plugins();
 681 
 682 #endif // #if !defined (_VOS) && !defined (_VOS3)
 683 
 684  }
 685 } // namespace sdi::filesystem
 686 
 687 #endif
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sandbox-docs.verifone.com/s-adk-5.1-programmers-guide/filesystem_8h_source.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
