1*99a2dd95SBruce Richardson /* SPDX-License-Identifier: BSD-3-Clause
2*99a2dd95SBruce Richardson * Copyright(c) 2010-2018 Intel Corporation
3*99a2dd95SBruce Richardson */
4*99a2dd95SBruce Richardson
5*99a2dd95SBruce Richardson /**
6*99a2dd95SBruce Richardson * @file
7*99a2dd95SBruce Richardson * Stores functions and path defines for files and directories
8*99a2dd95SBruce Richardson * on the filesystem for Linux, that are used by the Linux EAL.
9*99a2dd95SBruce Richardson */
10*99a2dd95SBruce Richardson
11*99a2dd95SBruce Richardson #ifndef EAL_FILESYSTEM_H
12*99a2dd95SBruce Richardson #define EAL_FILESYSTEM_H
13*99a2dd95SBruce Richardson
14*99a2dd95SBruce Richardson /** Path of rte config file. */
15*99a2dd95SBruce Richardson
16*99a2dd95SBruce Richardson #include <stdint.h>
17*99a2dd95SBruce Richardson #include <limits.h>
18*99a2dd95SBruce Richardson #include <unistd.h>
19*99a2dd95SBruce Richardson #include <stdlib.h>
20*99a2dd95SBruce Richardson
21*99a2dd95SBruce Richardson #include <rte_string_fns.h>
22*99a2dd95SBruce Richardson #include "eal_internal_cfg.h"
23*99a2dd95SBruce Richardson
24*99a2dd95SBruce Richardson /* sets up platform-specific runtime data dir */
25*99a2dd95SBruce Richardson int
26*99a2dd95SBruce Richardson eal_create_runtime_dir(void);
27*99a2dd95SBruce Richardson
28*99a2dd95SBruce Richardson int
29*99a2dd95SBruce Richardson eal_clean_runtime_dir(void);
30*99a2dd95SBruce Richardson
31*99a2dd95SBruce Richardson /** Function to return hugefile prefix that's currently set up */
32*99a2dd95SBruce Richardson const char *
33*99a2dd95SBruce Richardson eal_get_hugefile_prefix(void);
34*99a2dd95SBruce Richardson
35*99a2dd95SBruce Richardson #define RUNTIME_CONFIG_FNAME "config"
36*99a2dd95SBruce Richardson static inline const char *
eal_runtime_config_path(void)37*99a2dd95SBruce Richardson eal_runtime_config_path(void)
38*99a2dd95SBruce Richardson {
39*99a2dd95SBruce Richardson static char buffer[PATH_MAX]; /* static so auto-zeroed */
40*99a2dd95SBruce Richardson
41*99a2dd95SBruce Richardson snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
42*99a2dd95SBruce Richardson RUNTIME_CONFIG_FNAME);
43*99a2dd95SBruce Richardson return buffer;
44*99a2dd95SBruce Richardson }
45*99a2dd95SBruce Richardson
46*99a2dd95SBruce Richardson /** Path of primary/secondary communication unix socket file. */
47*99a2dd95SBruce Richardson #define MP_SOCKET_FNAME "mp_socket"
48*99a2dd95SBruce Richardson static inline const char *
eal_mp_socket_path(void)49*99a2dd95SBruce Richardson eal_mp_socket_path(void)
50*99a2dd95SBruce Richardson {
51*99a2dd95SBruce Richardson static char buffer[PATH_MAX]; /* static so auto-zeroed */
52*99a2dd95SBruce Richardson
53*99a2dd95SBruce Richardson snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
54*99a2dd95SBruce Richardson MP_SOCKET_FNAME);
55*99a2dd95SBruce Richardson return buffer;
56*99a2dd95SBruce Richardson }
57*99a2dd95SBruce Richardson
58*99a2dd95SBruce Richardson #define FBARRAY_NAME_FMT "%s/fbarray_%s"
59*99a2dd95SBruce Richardson static inline const char *
eal_get_fbarray_path(char * buffer,size_t buflen,const char * name)60*99a2dd95SBruce Richardson eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
61*99a2dd95SBruce Richardson snprintf(buffer, buflen, FBARRAY_NAME_FMT, rte_eal_get_runtime_dir(),
62*99a2dd95SBruce Richardson name);
63*99a2dd95SBruce Richardson return buffer;
64*99a2dd95SBruce Richardson }
65*99a2dd95SBruce Richardson
66*99a2dd95SBruce Richardson /** Path of hugepage info file. */
67*99a2dd95SBruce Richardson #define HUGEPAGE_INFO_FNAME "hugepage_info"
68*99a2dd95SBruce Richardson static inline const char *
eal_hugepage_info_path(void)69*99a2dd95SBruce Richardson eal_hugepage_info_path(void)
70*99a2dd95SBruce Richardson {
71*99a2dd95SBruce Richardson static char buffer[PATH_MAX]; /* static so auto-zeroed */
72*99a2dd95SBruce Richardson
73*99a2dd95SBruce Richardson snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
74*99a2dd95SBruce Richardson HUGEPAGE_INFO_FNAME);
75*99a2dd95SBruce Richardson return buffer;
76*99a2dd95SBruce Richardson }
77*99a2dd95SBruce Richardson
78*99a2dd95SBruce Richardson /** Path of hugepage data file. */
79*99a2dd95SBruce Richardson #define HUGEPAGE_DATA_FNAME "hugepage_data"
80*99a2dd95SBruce Richardson static inline const char *
eal_hugepage_data_path(void)81*99a2dd95SBruce Richardson eal_hugepage_data_path(void)
82*99a2dd95SBruce Richardson {
83*99a2dd95SBruce Richardson static char buffer[PATH_MAX]; /* static so auto-zeroed */
84*99a2dd95SBruce Richardson
85*99a2dd95SBruce Richardson snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(),
86*99a2dd95SBruce Richardson HUGEPAGE_DATA_FNAME);
87*99a2dd95SBruce Richardson return buffer;
88*99a2dd95SBruce Richardson }
89*99a2dd95SBruce Richardson
90*99a2dd95SBruce Richardson /** String format for hugepage map files. */
91*99a2dd95SBruce Richardson #define HUGEFILE_FMT "%s/%smap_%d"
92*99a2dd95SBruce Richardson static inline const char *
eal_get_hugefile_path(char * buffer,size_t buflen,const char * hugedir,int f_id)93*99a2dd95SBruce Richardson eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id)
94*99a2dd95SBruce Richardson {
95*99a2dd95SBruce Richardson snprintf(buffer, buflen, HUGEFILE_FMT, hugedir,
96*99a2dd95SBruce Richardson eal_get_hugefile_prefix(), f_id);
97*99a2dd95SBruce Richardson return buffer;
98*99a2dd95SBruce Richardson }
99*99a2dd95SBruce Richardson
100*99a2dd95SBruce Richardson /** define the default filename prefix for the %s values above */
101*99a2dd95SBruce Richardson #define HUGEFILE_PREFIX_DEFAULT "rte"
102*99a2dd95SBruce Richardson
103*99a2dd95SBruce Richardson /** Function to read a single numeric value from a file on the filesystem.
104*99a2dd95SBruce Richardson * Used to read information from files on /sys */
105*99a2dd95SBruce Richardson int eal_parse_sysfs_value(const char *filename, unsigned long *val);
106*99a2dd95SBruce Richardson
107*99a2dd95SBruce Richardson #endif /* EAL_FILESYSTEM_H */
108