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 /* sets up platform-specific runtime data dir */
30 eal_create_runtime_dir(void);
32 /* returns runtime dir */
34 eal_get_runtime_dir(void);
36 static inline const char *
37 eal_runtime_config_path(void)
39 static char buffer[PATH_MAX]; /* static so auto-zeroed */
40 const char *directory = default_config_dir;
41 const char *home_dir = getenv("HOME");
43 if (getuid() != 0 && home_dir != NULL)
45 snprintf(buffer, sizeof(buffer) - 1, RUNTIME_CONFIG_FMT, directory,
46 internal_config.hugefile_prefix);
50 /** Path of primary/secondary communication unix socket file. */
51 #define MP_SOCKET_PATH_FMT "%s/.%s_unix"
52 static inline const char *
53 eal_mp_socket_path(void)
55 static char buffer[PATH_MAX]; /* static so auto-zeroed */
56 const char *directory = default_config_dir;
57 const char *home_dir = getenv("HOME");
59 if (getuid() != 0 && home_dir != NULL)
61 snprintf(buffer, sizeof(buffer) - 1, MP_SOCKET_PATH_FMT,
62 directory, internal_config.hugefile_prefix);
67 static inline const char *
68 eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
69 const char *directory = "/tmp";
70 const char *home_dir = getenv("HOME");
72 if (getuid() != 0 && home_dir != NULL)
74 snprintf(buffer, buflen - 1, FBARRAY_FMT, directory,
75 internal_config.hugefile_prefix, name);
79 /** Path of hugepage info file. */
80 #define HUGEPAGE_INFO_FMT "%s/.%s_hugepage_info"
82 static inline const char *
83 eal_hugepage_info_path(void)
85 static char buffer[PATH_MAX]; /* static so auto-zeroed */
86 const char *directory = default_config_dir;
87 const char *home_dir = getenv("HOME");
89 if (getuid() != 0 && home_dir != NULL)
91 snprintf(buffer, sizeof(buffer) - 1, HUGEPAGE_INFO_FMT, directory,
92 internal_config.hugefile_prefix);
96 /** Path of hugepage info file. */
97 #define HUGEPAGE_FILE_FMT "%s/.%s_hugepage_file"
99 static inline const char *
100 eal_hugepage_data_path(void)
102 static char buffer[PATH_MAX]; /* static so auto-zeroed */
103 const char *directory = default_config_dir;
104 const char *home_dir = getenv("HOME");
106 if (getuid() != 0 && home_dir != NULL)
107 directory = home_dir;
108 snprintf(buffer, sizeof(buffer) - 1, HUGEPAGE_FILE_FMT, directory,
109 internal_config.hugefile_prefix);
113 /** String format for hugepage map files. */
114 #define HUGEFILE_FMT "%s/%smap_%d"
115 static inline const char *
116 eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id)
118 snprintf(buffer, buflen, HUGEFILE_FMT, hugedir,
119 internal_config.hugefile_prefix, f_id);
120 buffer[buflen - 1] = '\0';
124 /** String format for hugepage map lock files. */
125 #define HUGEFILE_LOCK_FMT "%s/.%smap_%d.lock"
127 static inline const char *
128 eal_get_hugefile_lock_path(char *buffer, size_t buflen, int f_id)
130 const char *directory = default_config_dir;
131 const char *home_dir = getenv("HOME");
133 if (getuid() != 0 && home_dir != NULL)
134 directory = home_dir;
135 snprintf(buffer, buflen - 1, HUGEFILE_LOCK_FMT, directory,
136 internal_config.hugefile_prefix, f_id);
137 buffer[buflen - 1] = '\0';
141 /** define the default filename prefix for the %s values above */
142 #define HUGEFILE_PREFIX_DEFAULT "rte"
144 /** Function to read a single numeric value from a file on the filesystem.
145 * Used to read information from files on /sys */
146 int eal_parse_sysfs_value(const char *filename, unsigned long *val);
148 #endif /* EAL_FILESYSTEM_H */