From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mails.dpdk.org (mails.dpdk.org [217.70.189.124]) by inbox.dpdk.org (Postfix) with ESMTP id CCD72A0524; Sun, 21 Feb 2021 00:29:36 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 511FA22A25E; Sun, 21 Feb 2021 00:29:23 +0100 (CET) Received: from mail-lj1-f176.google.com (mail-lj1-f176.google.com [209.85.208.176]) by mails.dpdk.org (Postfix) with ESMTP id 4DA4422A231 for ; Sun, 21 Feb 2021 00:29:21 +0100 (CET) Received: by mail-lj1-f176.google.com with SMTP id q14so44077793ljp.4 for ; Sat, 20 Feb 2021 15:29:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=O95C5jguH5R7dce3zUC7lq6Dgu8HddPybtOizsTLKQk=; b=ZTAyAYCK4LjmSPvFrYhzUrotoPQk+mrKCYaLLdjEQLXUVX6vFaxkrdeOiLAhokzImT ew1o1ReoAhO64s0MkyAJfgaf5eJD7wx90ri3XY47Hp+oaNChtqsI47LjYg18cw3d+Vz3 tZw8zNaghltIPDI52EQ9w/d6Pl87ykUwa8fMdRqGNOo7rD5ShWXGSyDkHAZEc8tuqN8z qfm+kV7K84+z2ZvIQLSVvzo9VuzVvH+3G2I3xYA5Y+omppyPg+pur4CzfdZgMzz4y6q9 9A7TgoY6MXdNNSsgHCGgOB3pxv3iGiDvtN9TDjT6JEn0fpEUx2kvReDTBRdtc6EaQdsi iwUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=O95C5jguH5R7dce3zUC7lq6Dgu8HddPybtOizsTLKQk=; b=dYbAVe8zDtXfQVHvOsefbJZ0dNXiH9P5CkD6l3KiD9qDNwNTiiym7HwHkHX8VkrXW2 6p17SqI+OjPkUqKTIJ2rg0epnMFpjE66RZZ/DRjzrDcq5xOGj2vAu172txC4flcB+vTr jx6B/x1qILMilRlI/Mie9DRG35f9SJgCnpJNWcD3fHdAOxVRFen2UHfQ5//4flE5fx4+ aHE2UBU3NoHBlUiHIetPaP65lozDuW0C8qy3kmeg1RvDyjXDJC7GumhQ9iDAFyjvPy/j 6KGHfc0qwrpwh4TUiBskFZEIPd7WaNl84hy9xxW242zCPp7gD8Q+HJdtUSZ0lEoGjSV6 bThg== X-Gm-Message-State: AOAM530Y5mYKJJ13E9h8AKVW6VXyJXJMFMPE7UphWoxuhNHQ5PGCB/qp MQElY4C4E/cDod4pOAIKEdGAGa/sKIXcVg== X-Google-Smtp-Source: ABdhPJzJRIsD7FSqnaBzxZTnOpPIy7LORu05fdKF/G4kxiZrzEuE5Rvb3DocDsCSYm88TlskhqlPqw== X-Received: by 2002:a2e:9b4a:: with SMTP id o10mr8724970ljj.3.1613863760563; Sat, 20 Feb 2021 15:29:20 -0800 (PST) Received: from localhost.localdomain (broadband-37-110-65-23.ip.moscow.rt.ru. [37.110.65.23]) by smtp.gmail.com with ESMTPSA id f5sm1462931ljc.8.2021.02.20.15.29.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Feb 2021 15:29:20 -0800 (PST) From: Dmitry Kozlyuk To: dev@dpdk.org Cc: Tyler Retzlaff , Nick Connolly , Dmitry Kozlyuk , Anatoly Burakov , Jerin Jacob , Sunil Kumar Kori , Bruce Richardson , Narcisa Ana Maria Vasile , Dmitry Malloy , Pallavi Kadam Date: Sun, 21 Feb 2021 02:29:05 +0300 Message-Id: <20210220232910.772-3-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210220232910.772-1-dmitry.kozliuk@gmail.com> References: <20210220232910.772-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH 2/7] eal: add macro for maximum path length X-BeenThere: dev@dpdk.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: DPDK patches and discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: dev-bounces@dpdk.org Sender: "dev" 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 --- 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 #include -#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 +#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 +#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 #include -/* 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 */ #ifndef PATH_MAX #define PATH_MAX _MAX_PATH -- 2.29.2