[dpdk-dev] [PATCH 2/7] eal: add macro for maximum path length
From: Dmitry Kozlyuk <hidden>
Date: 2021-02-20 23:29:37
Subsystem:
library code, the rest · Maintainers:
Andrew Morton, Linus Torvalds
Path length limit is PATH_MAX on Unix and _MAX_PATH on Windows. Add RTE_PATH_MAX macro for use in OS-independent code. Keep PATH_MAX in "common" multiprocess code, because it's really Unix-specific. Signed-off-by: Dmitry Kozlyuk <redacted> --- PATH_MAX is not removed until the last patch to keep PCI building. lib/librte_eal/common/eal_common_config.c | 2 +- lib/librte_eal/common/eal_common_fbarray.c | 8 +++---- lib/librte_eal/common/eal_common_options.c | 20 +++++++++--------- .../common/eal_common_trace_utils.c | 9 ++++---- lib/librte_eal/common/eal_filesystem.h | 8 +++---- lib/librte_eal/common/eal_hugepages.h | 2 +- lib/librte_eal/common/eal_internal_cfg.h | 2 +- lib/librte_eal/common/eal_trace.h | 2 +- lib/librte_eal/freebsd/include/rte_os.h | 2 ++ lib/librte_eal/linux/include/rte_os.h | 2 ++ lib/librte_eal/windows/include/dirent.h | 21 +++++++------------ lib/librte_eal/windows/include/rte_os.h | 2 ++ 12 files changed, 41 insertions(+), 39 deletions(-)
diff --git a/lib/librte_eal/common/eal_common_config.c b/lib/librte_eal/common/eal_common_config.c
index 56d09dda7..33e5a076a 100644
--- a/lib/librte_eal/common/eal_common_config.c
+++ b/lib/librte_eal/common/eal_common_config.c@@ -18,7 +18,7 @@ static struct rte_config rte_config = { }; /* platform-specific runtime dir */ -static char runtime_dir[PATH_MAX]; +static char runtime_dir[RTE_PATH_MAX]; /* internal configuration */ static struct internal_config internal_config;
diff --git a/lib/librte_eal/common/eal_common_fbarray.c b/lib/librte_eal/common/eal_common_fbarray.c
index d974f3dab..c21b8ec66 100644
--- a/lib/librte_eal/common/eal_common_fbarray.c
+++ b/lib/librte_eal/common/eal_common_fbarray.c@@ -83,7 +83,7 @@ get_used_mask(void *data, unsigned int elt_sz, unsigned int len) static int resize_and_map(int fd, void *addr, size_t len) { - char path[PATH_MAX]; + char path[RTE_PATH_MAX]; void *map_addr; if (eal_file_truncate(fd, len)) {
@@ -710,7 +710,7 @@ rte_fbarray_init(struct rte_fbarray *arr, const char *name, unsigned int len, unsigned int elt_sz) { size_t page_sz, mmap_len; - char path[PATH_MAX]; + char path[RTE_PATH_MAX]; struct used_mask *msk; struct mem_area *ma = NULL; void *data = NULL;
@@ -836,7 +836,7 @@ rte_fbarray_attach(struct rte_fbarray *arr) { struct mem_area *ma = NULL, *tmp = NULL; size_t page_sz, mmap_len; - char path[PATH_MAX]; + char path[RTE_PATH_MAX]; void *data = NULL; int fd = -1;
@@ -978,7 +978,7 @@ rte_fbarray_destroy(struct rte_fbarray *arr) struct mem_area *tmp = NULL; size_t mmap_len; int fd, ret; - char path[PATH_MAX]; + char path[RTE_PATH_MAX]; const struct internal_config *internal_conf = eal_get_internal_configuration();
diff --git a/lib/librte_eal/common/eal_common_options.c b/lib/librte_eal/common/eal_common_options.c
index 3612ad441..bad389903 100644
--- a/lib/librte_eal/common/eal_common_options.c
+++ b/lib/librte_eal/common/eal_common_options.c@@ -120,7 +120,7 @@ TAILQ_HEAD(shared_driver_list, shared_driver); struct shared_driver { TAILQ_ENTRY(shared_driver) next; - char name[PATH_MAX]; + char name[RTE_PATH_MAX]; void* lib_handle; };
@@ -367,7 +367,7 @@ eal_plugin_add(const char *path) return -1; } memset(solib, 0, sizeof(*solib)); - strlcpy(solib->name, path, PATH_MAX); + strlcpy(solib->name, path, RTE_PATH_MAX); TAILQ_INSERT_TAIL(&solib_list, solib, next); return 0;
@@ -386,7 +386,7 @@ eal_plugindir_init(const char *path) { DIR *d = NULL; struct dirent *dent = NULL; - char sopath[PATH_MAX]; + char sopath[RTE_PATH_MAX]; if (path == NULL || *path == '\0') return 0;
@@ -430,16 +430,16 @@ verify_perms(const char *dirpath) /* if not root, check down one level first */ if (strcmp(dirpath, "/") != 0) { - static __thread char last_dir_checked[PATH_MAX]; - char copy[PATH_MAX]; + static __thread char last_dir_checked[RTE_PATH_MAX]; + char copy[RTE_PATH_MAX]; const char *dir; - strlcpy(copy, dirpath, PATH_MAX); + strlcpy(copy, dirpath, RTE_PATH_MAX); dir = dirname(copy); - if (strncmp(dir, last_dir_checked, PATH_MAX) != 0) { + if (strncmp(dir, last_dir_checked, RTE_PATH_MAX) != 0) { if (verify_perms(dir) != 0) return -1; - strlcpy(last_dir_checked, dir, PATH_MAX); + strlcpy(last_dir_checked, dir, RTE_PATH_MAX); } }
@@ -477,8 +477,8 @@ eal_dlopen(const char *pathname) pathname, strerror(errno)); goto out; } - if (strnlen(realp, PATH_MAX) == PATH_MAX) { - RTE_LOG(ERR, EAL, "Error, driver path greater than PATH_MAX\n"); + if (strnlen(realp, RTE_PATH_MAX) == RTE_PATH_MAX) { + RTE_LOG(ERR, EAL, "Error, driver path greater than RTE_PATH_MAX\n"); goto out; }
diff --git a/lib/librte_eal/common/eal_common_trace_utils.c b/lib/librte_eal/common/eal_common_trace_utils.c
index d541a5ea9..6b81fdeec 100644
--- a/lib/librte_eal/common/eal_common_trace_utils.c
+++ b/lib/librte_eal/common/eal_common_trace_utils.c@@ -369,11 +369,11 @@ trace_mkdir(void) static int trace_meta_save(struct trace *trace) { - char file_name[PATH_MAX]; + char file_name[RTE_PATH_MAX]; FILE *f; int rc; - rc = snprintf(file_name, PATH_MAX, "%s/metadata", trace->dir); + rc = snprintf(file_name, RTE_PATH_MAX, "%s/metadata", trace->dir); if (rc < 0) return rc;
@@ -400,11 +400,12 @@ static int trace_mem_save(struct trace *trace, struct __rte_trace_header *hdr, uint32_t cnt) { - char file_name[PATH_MAX]; + char file_name[RTE_PATH_MAX]; FILE *f; int rc; - rc = snprintf(file_name, PATH_MAX, "%s/channel0_%d", trace->dir, cnt); + rc = snprintf(file_name, RTE_PATH_MAX, "%s/channel0_%d", + trace->dir, cnt); if (rc < 0) return rc;
diff --git a/lib/librte_eal/common/eal_filesystem.h b/lib/librte_eal/common/eal_filesystem.h
index 5d21f07c2..d28a9b23d 100644
--- a/lib/librte_eal/common/eal_filesystem.h
+++ b/lib/librte_eal/common/eal_filesystem.h@@ -36,7 +36,7 @@ eal_get_hugefile_prefix(void); static inline const char * eal_runtime_config_path(void) { - static char buffer[PATH_MAX]; /* static so auto-zeroed */ + static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */ snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(), RUNTIME_CONFIG_FNAME);
@@ -48,7 +48,7 @@ eal_runtime_config_path(void) static inline const char * eal_mp_socket_path(void) { - static char buffer[PATH_MAX]; /* static so auto-zeroed */ + static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */ snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(), MP_SOCKET_FNAME);
@@ -68,7 +68,7 @@ eal_get_fbarray_path(char *buffer, size_t buflen, const char *name) { static inline const char * eal_hugepage_info_path(void) { - static char buffer[PATH_MAX]; /* static so auto-zeroed */ + static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */ snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(), HUGEPAGE_INFO_FNAME);
@@ -80,7 +80,7 @@ eal_hugepage_info_path(void) static inline const char * eal_hugepage_data_path(void) { - static char buffer[PATH_MAX]; /* static so auto-zeroed */ + static char buffer[RTE_PATH_MAX]; /* static so auto-zeroed */ snprintf(buffer, sizeof(buffer), "%s/%s", rte_eal_get_runtime_dir(), HUGEPAGE_DATA_FNAME);
diff --git a/lib/librte_eal/common/eal_hugepages.h b/lib/librte_eal/common/eal_hugepages.h
index 1b560d337..02b324ed1 100644
--- a/lib/librte_eal/common/eal_hugepages.h
+++ b/lib/librte_eal/common/eal_hugepages.h@@ -9,7 +9,7 @@ #include <stdint.h> #include <limits.h> -#define MAX_HUGEPAGE_PATH PATH_MAX +#define MAX_HUGEPAGE_PATH RTE_PATH_MAX /** * Structure used to store information about hugepages that we mapped
diff --git a/lib/librte_eal/common/eal_internal_cfg.h b/lib/librte_eal/common/eal_internal_cfg.h
index 51dbe86e2..c8ea3b8fc 100644
--- a/lib/librte_eal/common/eal_internal_cfg.h
+++ b/lib/librte_eal/common/eal_internal_cfg.h@@ -27,7 +27,7 @@ */ struct hugepage_info { uint64_t hugepage_sz; /**< size of a huge page */ - char hugedir[PATH_MAX]; /**< dir where hugetlbfs is mounted */ + char hugedir[RTE_PATH_MAX]; /**< dir where hugetlbfs is mounted */ uint32_t num_pages[RTE_MAX_NUMA_NODES]; /**< number of hugepages of that size on each socket */ int lock_descriptor; /**< file descriptor for hugepage dir */
diff --git a/lib/librte_eal/common/eal_trace.h b/lib/librte_eal/common/eal_trace.h
index 06751eb23..ab915eb10 100644
--- a/lib/librte_eal/common/eal_trace.h
+++ b/lib/librte_eal/common/eal_trace.h@@ -51,7 +51,7 @@ struct trace_arg { }; struct trace { - char dir[PATH_MAX]; + char dir[RTE_PATH_MAX]; int dir_offset; int register_errno; bool status;
diff --git a/lib/librte_eal/freebsd/include/rte_os.h b/lib/librte_eal/freebsd/include/rte_os.h
index eeb750cd8..b37d59b5e 100644
--- a/lib/librte_eal/freebsd/include/rte_os.h
+++ b/lib/librte_eal/freebsd/include/rte_os.h@@ -13,6 +13,8 @@ #include <pthread_np.h> +#define RTE_PATH_MAX PATH_MAX + typedef cpuset_t rte_cpuset_t; #define RTE_CPU_AND(dst, src1, src2) do \ { \
diff --git a/lib/librte_eal/linux/include/rte_os.h b/lib/librte_eal/linux/include/rte_os.h
index 218d4fa86..af7d052d9 100644
--- a/lib/librte_eal/linux/include/rte_os.h
+++ b/lib/librte_eal/linux/include/rte_os.h@@ -13,6 +13,8 @@ #include <sched.h> +#define RTE_PATH_MAX PATH_MAX + typedef cpu_set_t rte_cpuset_t; #define RTE_CPU_AND(dst, src1, src2) CPU_AND(dst, src1, src2) #define RTE_CPU_OR(dst, src1, src2) CPU_OR(dst, src1, src2)
diff --git a/lib/librte_eal/windows/include/dirent.h b/lib/librte_eal/windows/include/dirent.h
index 869a59837..3a9a694f4 100644
--- a/lib/librte_eal/windows/include/dirent.h
+++ b/lib/librte_eal/windows/include/dirent.h@@ -28,11 +28,6 @@ #include <sys/stat.h> #include <errno.h> -/* Maximum length of file name */ -#if !defined(PATH_MAX) -# define PATH_MAX MAX_PATH -#endif - /* File type flags for d_type */ #define DT_UNKNOWN 0 #define DT_REG S_IFREG
@@ -67,7 +62,7 @@ struct _wdirent { int d_type; /* File name */ - wchar_t d_name[PATH_MAX]; + wchar_t d_name[RTE_PATH_MAX]; }; typedef struct _wdirent _wdirent;
@@ -113,7 +108,7 @@ struct dirent { int d_type; /* File name */ - char d_name[PATH_MAX]; + char d_name[RTE_PATH_MAX]; }; typedef struct dirent dirent;
@@ -388,12 +383,12 @@ opendir(const char *dirname) /* Allocate memory for DIR structure */ dirp = (DIR *)malloc(sizeof(struct DIR)); if (dirp) { - wchar_t wname[PATH_MAX]; + wchar_t wname[RTE_PATH_MAX]; size_t n; /* Convert directory name to wide-character string */ - error = dirent_mbstowcs_s(&n, wname, PATH_MAX, - dirname, PATH_MAX); + error = dirent_mbstowcs_s(&n, wname, RTE_PATH_MAX, + dirname, RTE_PATH_MAX); if (!error) { /* Open directory stream using wide-character name */
@@ -457,7 +452,7 @@ readdir(DIR *dirp) /* Attempt to convert file name to multi-byte string */ error = dirent_wcstombs_s(&n, dirp->ent.d_name, - PATH_MAX, datap->cFileName, PATH_MAX); + RTE_PATH_MAX, datap->cFileName, RTE_PATH_MAX); /* * If the file name cannot be represented by a multi-byte
@@ -472,8 +467,8 @@ readdir(DIR *dirp) */ if (error && datap->cAlternateFileName[0] != '\0') { error = dirent_wcstombs_s( - &n, dirp->ent.d_name, PATH_MAX, - datap->cAlternateFileName, PATH_MAX); + &n, dirp->ent.d_name, RTE_PATH_MAX, + datap->cAlternateFileName, RTE_PATH_MAX); } if (!error) {
diff --git a/lib/librte_eal/windows/include/rte_os.h b/lib/librte_eal/windows/include/rte_os.h
index 7ef38ff06..edca11bd2 100644
--- a/lib/librte_eal/windows/include/rte_os.h
+++ b/lib/librte_eal/windows/include/rte_os.h@@ -20,6 +20,8 @@ extern "C" { #endif +#define RTE_PATH_MAX _MAX_PATH + /* limits.h replacement, value as in <windows.h> */ #ifndef PATH_MAX #define PATH_MAX _MAX_PATH
--
2.29.2