New upstream version 18.11-rc1
[deb_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 /* returns runtime dir */
29 const char *
30 rte_eal_get_runtime_dir(void);
31
32 #define RUNTIME_CONFIG_FNAME "config"
33 static inline const char *
34 eal_runtime_config_path(void)
35 {
36         static char buffer[PATH_MAX]; /* static so auto-zeroed */
37
38         snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
39                         RUNTIME_CONFIG_FNAME);
40         return buffer;
41 }
42
43 /** Path of primary/secondary communication unix socket file. */
44 #define MP_SOCKET_FNAME "mp_socket"
45 static inline const char *
46 eal_mp_socket_path(void)
47 {
48         static char buffer[PATH_MAX]; /* static so auto-zeroed */
49
50         snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
51                         MP_SOCKET_FNAME);
52         return buffer;
53 }
54
55 #define FBARRAY_NAME_FMT "%s/fbarray_%s"
56 static inline const char *
57 eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) {
58         snprintf(buffer, buflen, FBARRAY_NAME_FMT, rte_eal_get_runtime_dir(),
59                         name);
60         return buffer;
61 }
62
63 /** Path of hugepage info file. */
64 #define HUGEPAGE_INFO_FNAME "hugepage_info"
65 static inline const char *
66 eal_hugepage_info_path(void)
67 {
68         static char buffer[PATH_MAX]; /* static so auto-zeroed */
69
70         snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
71                         HUGEPAGE_INFO_FNAME);
72         return buffer;
73 }
74
75 /** Path of hugepage data file. */
76 #define HUGEPAGE_DATA_FNAME "hugepage_data"
77 static inline const char *
78 eal_hugepage_data_path(void)
79 {
80         static char buffer[PATH_MAX]; /* static so auto-zeroed */
81
82         snprintf(buffer, sizeof(buffer) - 1, "%s/%s", rte_eal_get_runtime_dir(),
83                         HUGEPAGE_DATA_FNAME);
84         return buffer;
85 }
86
87 /** String format for hugepage map files. */
88 #define HUGEFILE_FMT "%s/%smap_%d"
89 static inline const char *
90 eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id)
91 {
92         snprintf(buffer, buflen, HUGEFILE_FMT, hugedir,
93                         internal_config.hugefile_prefix, f_id);
94         buffer[buflen - 1] = '\0';
95         return buffer;
96 }
97
98 /** String format for hugepage map lock files. */
99 #define HUGEFILE_LOCK_FMT "%s/map_%d.lock"
100 static inline const char *
101 eal_get_hugefile_lock_path(char *buffer, size_t buflen, int f_id)
102 {
103         snprintf(buffer, buflen, HUGEFILE_LOCK_FMT, rte_eal_get_runtime_dir(),
104                         f_id);
105         buffer[buflen - 1] = '\0';
106         return buffer;
107 }
108
109 /** define the default filename prefix for the %s values above */
110 #define HUGEFILE_PREFIX_DEFAULT "rte"
111
112 /** Function to read a single numeric value from a file on the filesystem.
113  * Used to read information from files on /sys */
114 int eal_parse_sysfs_value(const char *filename, unsigned long *val);
115
116 #endif /* EAL_FILESYSTEM_H */