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