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 DA656A034F; Sun, 21 Feb 2021 02:28:54 +0100 (CET) Received: from [217.70.189.124] (localhost [127.0.0.1]) by mails.dpdk.org (Postfix) with ESMTP id 7BB6E22A267; Sun, 21 Feb 2021 02:28:43 +0100 (CET) Received: from mail-lj1-f182.google.com (mail-lj1-f182.google.com [209.85.208.182]) by mails.dpdk.org (Postfix) with ESMTP id 5874822A25C for ; Sun, 21 Feb 2021 02:28:42 +0100 (CET) Received: by mail-lj1-f182.google.com with SMTP id g1so38589926ljj.13 for ; Sat, 20 Feb 2021 17:28:42 -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=7WcTPkjchmAK6UW9LkpoCQXdqH2MeezlhFTOaBsoJ4Q=; b=ORfXvxDi6blVrmYnquKYJ2WowaspvX4SVQl14Gqpfh/3xzVbg5U33oBcGoztBj3M+x qhiMuOTpqLdmBbc+v8PW5Y3HdFuqIl6xV7hQKXopELal+k0qN5BQdHWnwDVj34gt/OCO AHLMnDVJ78hSNKpnRbJ0yWOybggrQpfehdRfMvEi4l8BC0IIOOcJzv0O8AZejB6wt0lZ kZkBlzglfz1DnnnOQxzxVU9CFqjDFNat/UclILGT1gcU+CRhhzqhDZ5f9XFLj1wgfTSP c2dJ02uv43Gjz21ta/ag5R3VeadzxHeqajkx5TLfVvNjK3SH8OT5zs4Wan7SAUxtXMR5 dfoA== 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=7WcTPkjchmAK6UW9LkpoCQXdqH2MeezlhFTOaBsoJ4Q=; b=bNgA0tzprHPZQN+3PMCdkUdV0dy5z9942SHsDuIPZfVKoaqveAnX1dUj6cPcT64Ls+ z5E1ao7sS6x1bOwGlVvwAceFkk7jipofR+yzoFtjDUKfSTcqRL4GOXaQR5raTnESbb30 KvKxUHrdxwV7XVnQb/azULDBCVHdEiXWFz6lbktPLNlt7QW9qFQeaETG3DECsSne8Wib WetYKt4UcANJUrrnkQFrvItRwTAyqz+E8W9qYFLyPqe1QVdGP84sVPSgKDsI030zV1UK Uu2zDzJzIBrxDsrN/e1qs/Gqf8Jjs+7zuo6o9cx3coIc6cUDzvTCmGB/4xRZq+DJPEPW WJGA== X-Gm-Message-State: AOAM531WLXudzPCGw0K1GRKy4Qd+NkRSXAXp5XIABxQYo/XWLP7yc88L eTpSJK8yxmtj3R9KhID2+IM6AcHBUwM+Va1m X-Google-Smtp-Source: ABdhPJyxkp0ZgpM+0If+tr0A3PN+ibafViu2RL1z+bKAvm4D8BIstbN3fZZWWW9RWFMpDzMLK8Ae1g== X-Received: by 2002:a05:651c:327:: with SMTP id b7mr9825780ljp.100.1613870921651; Sat, 20 Feb 2021 17:28:41 -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 d5sm1401666lfe.232.2021.02.20.17.28.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Feb 2021 17:28:41 -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 04:28:26 +0300 Message-Id: <20210221012831.14643-3-dmitry.kozliuk@gmail.com> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20210221012831.14643-1-dmitry.kozliuk@gmail.com> References: <20210220232910.772-1-dmitry.kozliuk@gmail.com> <20210221012831.14643-1-dmitry.kozliuk@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [dpdk-dev] [PATCH v2 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 --- 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