anchao commented on code in PR #6997: URL: https://github.com/apache/incubator-nuttx/pull/6997#discussion_r964865348
########## net/procfs/net_procfs.c: ########## @@ -283,41 +307,10 @@ static ssize_t netprocfs_read(FAR struct file *filep, FAR char *buffer, /* Read according to the sub-directory */ - switch (priv->entry) + if (g_net_entries[priv->entry].u.stat != NULL) Review Comment: Done ########## net/procfs/net_procfs.c: ########## @@ -155,44 +196,29 @@ static int netprocfs_open(FAR struct file *filep, FAR const char *relpath, return -EACCES; } -#ifdef CONFIG_NET_STATISTICS - /* "net/stat" is an acceptable value for the relpath only if network layer - * statistics are enabled. - */ + /* For each net entries */ - if (strcmp(relpath, "net/stat") == 0) + for (i = 0; i < ARRAY_SIZE(g_net_entries); i++) { - entry = NETPROCFS_SUBDIR_STAT; - dev = NULL; - } - else -#ifdef CONFIG_NET_MLD - /* "net/mld" is an acceptable value for the relpath only if MLD is - * enabled. - */ - - if (strcmp(relpath, "net/mld") == 0) - { - entry = NETPROCFS_SUBDIR_MLD; - dev = NULL; - } - else -#endif -#endif - -#ifdef CONFIG_NET_ROUTE - /* "net/route" is an acceptable value for the relpath only if routing - * table support is initialized. - */ + if (strncmp(relpath + 4, g_net_entries[i].name, + strlen(g_net_entries[i].name))) + { + continue; + } - if (fnmatch("net/route/**", relpath, 0) == 0) - { - /* Use the /net/route directory */ + if (g_net_entries[i].type == DTYPE_FILE) + { + break; + } - return net_procfs_routeoperations.open(filep, relpath, oflags, mode); + else if (g_net_entries[i].type == DTYPE_DIRECTORY && + g_net_entries[i].u.ops != NULL) Review Comment: Done ########## net/procfs/net_procfs.c: ########## @@ -510,36 +502,19 @@ static int netprocfs_readdir(FAR struct fs_dirent_s *dir, return -ENOENT; } -#ifdef CONFIG_NET_STATISTICS - if (index == STAT_INDEX) - { - /* Copy the network statistics directory entry */ + /* Process other enabled net components, except netdev */ - entry->d_type = DTYPE_FILE; - strlcpy(entry->d_name, "stat", sizeof(entry->d_name)); - } - else -#ifdef CONFIG_NET_MLD - if (index == MLD_INDEX) + if (index < ARRAY_SIZE(g_net_entries) - 1 && + g_net_entries[index].name) Review Comment: Done ########## net/procfs/net_procfs.c: ########## @@ -384,23 +377,27 @@ static int netprocfs_opendir(FAR const char *relpath, FAR struct netprocfs_level1_s *level1; int ndevs; int ret; + int i; finfo("relpath: \"%s\"\n", relpath ? relpath : "NULL"); DEBUGASSERT(relpath && dir); - /* "net" and "net/route" are the only values of relpath that are - * directories. - */ + /* Subdirectory ? */ -#ifdef CONFIG_NET_ROUTE - if (fnmatch("net/route", relpath, 0) == 0 || - fnmatch("net/route/**", relpath, 0) == 0) + for (i = 0; i < ARRAY_SIZE(g_net_entries); i++) { - /* Use the /net/route directory */ + if (strncmp(relpath + 4, g_net_entries[i].name, + strlen(g_net_entries[i].name))) + { + continue; + } - return net_procfs_routeoperations.opendir(relpath, dir); + if (g_net_entries[i].type == DTYPE_DIRECTORY && + g_net_entries[i].u.ops != NULL) + { + return g_net_entries[i].u.ops->opendir(relpath, dir); + } Review Comment: Done ########## net/procfs/net_procfs.c: ########## @@ -384,23 +377,27 @@ static int netprocfs_opendir(FAR const char *relpath, FAR struct netprocfs_level1_s *level1; int ndevs; int ret; + int i; finfo("relpath: \"%s\"\n", relpath ? relpath : "NULL"); DEBUGASSERT(relpath && dir); - /* "net" and "net/route" are the only values of relpath that are - * directories. - */ + /* Subdirectory ? */ -#ifdef CONFIG_NET_ROUTE - if (fnmatch("net/route", relpath, 0) == 0 || - fnmatch("net/route/**", relpath, 0) == 0) + for (i = 0; i < ARRAY_SIZE(g_net_entries); i++) { - /* Use the /net/route directory */ + if (strncmp(relpath + 4, g_net_entries[i].name, + strlen(g_net_entries[i].name))) + { + continue; + } - return net_procfs_routeoperations.opendir(relpath, dir); + if (g_net_entries[i].type == DTYPE_DIRECTORY && + g_net_entries[i].u.ops != NULL) Review Comment: Done -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@nuttx.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org