Branch data Line data Source code
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 : : /** Function to return hugefile prefix that's currently set up */ 32 : : const char * 33 : : eal_get_hugefile_prefix(void); 34 : : 35 : : #define RUNTIME_CONFIG_FNAME "config" 36 : : static inline const char * 37 : 213 : eal_runtime_config_path(void) 38 : : { 39 : : static char buffer[PATH_MAX]; /* static so auto-zeroed */ 40 : : 41 : 213 : snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(), 42 : : RUNTIME_CONFIG_FNAME); 43 : 213 : return buffer; 44 : : } 45 : : 46 : : /** Path of primary/secondary communication unix socket file. */ 47 : : #define MP_SOCKET_FNAME "mp_socket" 48 : : 49 : : #ifdef RTE_EXEC_ENV_WINDOWS 50 : : /* 51 : : * UNIX_PATH_MAX is defined in afunux.h but that file is not in MinGW 9 52 : : * which is the version in Ubuntu 22.04, in future this can change. 53 : : * Also, Unix domain sockets are not used in DPDK on Windows (yet). 54 : : */ 55 : : #define UNIX_PATH_MAX 108 56 : : #else 57 : : #include <sys/un.h> 58 : : 59 : : /** Maximum length of unix domain socket path. */ 60 : : #define UNIX_PATH_MAX (sizeof(((struct sockaddr_un *)0)->sun_path)) 61 : : #endif 62 : : 63 : : static inline const char * 64 : 660 : eal_mp_socket_path(void) 65 : : { 66 : : static char buffer[UNIX_PATH_MAX]; /* static so auto-zeroed */ 67 : : 68 : 660 : snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(), 69 : : MP_SOCKET_FNAME); 70 : 660 : return buffer; 71 : : } 72 : : 73 : : #define FBARRAY_NAME_FMT "%s/fbarray_%s" 74 : : static inline const char * 75 : 1420 : eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) { 76 : 1420 : snprintf(buffer, buflen, FBARRAY_NAME_FMT, rte_eal_get_runtime_dir(), 77 : : name); 78 : 1420 : return buffer; 79 : : } 80 : : 81 : : /** Path of hugepage info file. */ 82 : : #define HUGEPAGE_INFO_FNAME "hugepage_info" 83 : : static inline const char * 84 : 83 : eal_hugepage_info_path(void) 85 : : { 86 : : static char buffer[PATH_MAX]; /* static so auto-zeroed */ 87 : : 88 : 83 : snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(), 89 : : HUGEPAGE_INFO_FNAME); 90 : 83 : return buffer; 91 : : } 92 : : 93 : : /** Path of hugepage data file. */ 94 : : #define HUGEPAGE_DATA_FNAME "hugepage_data" 95 : : static inline const char * 96 : 2 : eal_hugepage_data_path(void) 97 : : { 98 : : static char buffer[PATH_MAX]; /* static so auto-zeroed */ 99 : : 100 : 2 : snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(), 101 : : HUGEPAGE_DATA_FNAME); 102 : 2 : return buffer; 103 : : } 104 : : 105 : : /** String format for hugepage map files. */ 106 : : #define HUGEFILE_FMT "%s/%smap_%d" 107 : : static inline __rte_warn_unused_result const char * 108 : 4107 : eal_get_hugefile_path(char *buffer, size_t buflen, const char *hugedir, int f_id) 109 : : { 110 : 4107 : if (snprintf(buffer, buflen, HUGEFILE_FMT, hugedir, eal_get_hugefile_prefix(), f_id) 111 [ + - ]: 4107 : >= (int)buflen) 112 : : return NULL; 113 : : else 114 : 4107 : return buffer; 115 : : } 116 : : 117 : : /** define the default filename prefix for the %s values above */ 118 : : #define HUGEFILE_PREFIX_DEFAULT "rte" 119 : : 120 : : /** Function to read a single numeric value from a file on the filesystem. 121 : : * Used to read information from files on /sys */ 122 : : int eal_parse_sysfs_value(const char *filename, unsigned long *val); 123 : : 124 : : #endif /* EAL_FILESYSTEM_H */