1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2018 Intel Corporation
7 * Stores functions and path defines for files and directories
8 * on the filesystem for Linux, that are used by the Linux EAL.
11 #ifndef EAL_FILESYSTEM_H
12 #define EAL_FILESYSTEM_H
14 /** Path of rte config file. */
15 #define RUNTIME_CONFIG_FMT "%s/.%s_config"
16 #define FBARRAY_FMT "%s/%s_%s"
23 #include <rte_string_fns.h>
24 #include "eal_internal_cfg.h"
26 static const char *default_config_dir = "/var/run";
28 static inline const char *
29 eal_runtime_config_path(void)
31 static char buffer[PATH_MAX]; /* static so auto-zeroed */
32 const char *directory = default_config_dir;
33 const char *home_dir = getenv("HOME");
35 if (getuid() != 0 && home_dir != NULL)
37 snprintf(buffer, sizeof(buffer) - 1, RUNTIME_CONFIG_FMT, directory,
38 internal_config.hugefile_prefix);
42 /** Path of primary/secondary communication unix socket file. */
43 #define MP_SOCKET_PATH_FMT "%s/.%s_unix"
44 static inline const char *
45 eal_mp_socket_path(void)
47 static char buffer[PATH_MAX]; /* static so auto-zeroed */
48 const char *directory = default_config_dir;
49 const char *home_dir = getenv("HOME");
51 if (getuid() != 0 && home_dir != NULL)
53 snprintf(buffer, sizeof(buffer) - 1, MP_SOCKET_PATH_FMT,
54 directory, internal_config.hugefile_prefix);
59 static inline const char *
60 eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
61 const char *directory = "/tmp";
62 const char *home_dir = getenv("HOME");
64 if (getuid() != 0 && home_dir != NULL)
66 snprintf(buffer, buflen - 1, FBARRAY_FMT, directory,
67 internal_config.hugefile_prefix, name);
71 /** Path of hugepage info file. */
72 #define HUGEPAGE_INFO_FMT "%s/.%s_hugepage_info"
74 static inline const char *
75 eal_hugepage_info_path(void)
77 static char buffer[PATH_MAX]; /* static so auto-zeroed */
78 const char *directory = default_config_dir;
79 const char *home_dir = getenv("HOME");
81 if (getuid() != 0 && home_dir != NULL)
83 snprintf(buffer, sizeof(buffer) - 1, HUGEPAGE_INFO_FMT, directory,
84 internal_config.hugefile_prefix);
88 /** Path of hugepage info file. */
89 #define HUGEPAGE_FILE_FMT "%s/.%s_hugepage_file"
91 static inline const char *
92 eal_hugepage_file_path(void)
94 static char buffer[PATH_MAX]; /* static so auto-zeroed */
95 const char *directory = default_config_dir;
96 const char *home_dir = getenv("HOME");
98 if (getuid() != 0 && home_dir != NULL)
100 snprintf(buffer, sizeof(buffer) - 1, HUGEPAGE_FILE_FMT, directory,
101 internal_config.hugefile_prefix);
105 /** String format for hugepage map files. */
106 #define HUGEFILE_FMT "%s/%smap_%d"
107 #define TEMP_HUGEFILE_FMT "%s/%smap_temp_%d"
109 static inline const char *
110 eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id)
112 snprintf(buffer, buflen, HUGEFILE_FMT, hugedir,
113 internal_config.hugefile_prefix, f_id);
114 buffer[buflen - 1] = '\0';
118 /** define the default filename prefix for the %s values above */
119 #define HUGEFILE_PREFIX_DEFAULT "rte"
121 /** Function to read a single numeric value from a file on the filesystem.
122 * Used to read information from files on /sys */
123 int eal_parse_sysfs_value(const char *filename, unsigned long *val);
125 #endif /* EAL_FILESYSTEM_H */