lib: use SPDX tag for Intel copyright files
[dpdk.git] / lib / librte_eal / common / eal_filesystem.h
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright(c) 2010-2014 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 #define RUNTIME_CONFIG_FMT "%s/.%s_config"
16
17 #include <stdint.h>
18 #include <limits.h>
19 #include <unistd.h>
20 #include <stdlib.h>
21
22 #include <rte_string_fns.h>
23 #include "eal_internal_cfg.h"
24
25 static const char *default_config_dir = "/var/run";
26
27 static inline const char *
28 eal_runtime_config_path(void)
29 {
30         static char buffer[PATH_MAX]; /* static so auto-zeroed */
31         const char *directory = default_config_dir;
32         const char *home_dir = getenv("HOME");
33
34         if (getuid() != 0 && home_dir != NULL)
35                 directory = home_dir;
36         snprintf(buffer, sizeof(buffer) - 1, RUNTIME_CONFIG_FMT, directory,
37                         internal_config.hugefile_prefix);
38         return buffer;
39 }
40
41 /** Path of hugepage info file. */
42 #define HUGEPAGE_INFO_FMT "%s/.%s_hugepage_info"
43
44 static inline const char *
45 eal_hugepage_info_path(void)
46 {
47         static char buffer[PATH_MAX]; /* static so auto-zeroed */
48         const char *directory = default_config_dir;
49         const char *home_dir = getenv("HOME");
50
51         if (getuid() != 0 && home_dir != NULL)
52                 directory = home_dir;
53         snprintf(buffer, sizeof(buffer) - 1, HUGEPAGE_INFO_FMT, directory,
54                         internal_config.hugefile_prefix);
55         return buffer;
56 }
57
58 /** String format for hugepage map files. */
59 #define HUGEFILE_FMT "%s/%smap_%d"
60 #define TEMP_HUGEFILE_FMT "%s/%smap_temp_%d"
61
62 static inline const char *
63 eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id)
64 {
65         snprintf(buffer, buflen, HUGEFILE_FMT, hugedir,
66                         internal_config.hugefile_prefix, f_id);
67         buffer[buflen - 1] = '\0';
68         return buffer;
69 }
70
71 /** define the default filename prefix for the %s values above */
72 #define HUGEFILE_PREFIX_DEFAULT "rte"
73
74 /** Function to read a single numeric value from a file on the filesystem.
75  * Used to read information from files on /sys */
76 int eal_parse_sysfs_value(const char *filename, unsigned long *val);
77
78 #endif /* EAL_FILESYSTEM_H */