47
47
#include <nuttx/fs/procfs.h>
48
48
49
49
#include "mount/mount.h"
50
+ #include "sched/sched.h"
50
51
51
52
/****************************************************************************
52
53
* External Definitions
@@ -315,8 +316,8 @@ struct procfs_level0_s
315
316
/* Our private data */
316
317
317
318
uint8_t lastlen ; /* length of last reported static dir */
318
- pid_t pid [CONFIG_FS_PROCFS_MAX_TASKS ]; /* Snapshot of all active task IDs */
319
319
FAR const char * lastread ; /* Pointer to last static dir read */
320
+ pid_t pid [1 ]; /* Snapshot of all active task IDs */
320
321
};
321
322
322
323
/* Level 1 is an internal virtual directory (such as /proc/fs) which
@@ -355,14 +356,14 @@ static void procfs_enum(FAR struct tcb_s *tcb, FAR void *arg)
355
356
356
357
/* Add the PID to the list */
357
358
358
- index = dir -> base .nentries ;
359
- if (index >= CONFIG_FS_PROCFS_MAX_TASKS )
359
+ if (dir -> base .index >= dir -> base .nentries )
360
360
{
361
361
return ;
362
362
}
363
363
364
+ index = dir -> base .index ;
364
365
dir -> pid [index ] = tcb -> pid ;
365
- dir -> base .nentries = index + 1 ;
366
+ dir -> base .index = index + 1 ;
366
367
}
367
368
368
369
/****************************************************************************
@@ -633,12 +634,18 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
633
634
634
635
if (!relpath || relpath [0 ] == '\0' )
635
636
{
637
+ size_t num = 0 ;
638
+
636
639
/* The path refers to the top level directory. Allocate the level0
637
640
* dirent structure.
638
641
*/
639
642
643
+ #ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS
644
+ num = g_npidhash ;
645
+ #endif
646
+
640
647
level0 = (FAR struct procfs_level0_s * )
641
- kmm_zalloc (sizeof (struct procfs_level0_s )) ;
648
+ kmm_zalloc (sizeof (struct procfs_level0_s ) + sizeof ( pid_t ) * num ) ;
642
649
if (!level0 )
643
650
{
644
651
ferr ("ERROR: Failed to allocate the level0 directory structure\n" );
@@ -653,7 +660,11 @@ static int procfs_opendir(FAR struct inode *mountpt, FAR const char *relpath,
653
660
*/
654
661
655
662
#ifndef CONFIG_FS_PROCFS_EXCLUDE_PROCESS
663
+ level0 -> base .index = 0 ;
664
+ level0 -> base .nentries = num ;
656
665
nxsched_foreach (procfs_enum , level0 );
666
+ level0 -> base .nentries = level0 -> base .index ;
667
+ level0 -> base .index = 0 ;
657
668
procfs_sort_pid (level0 );
658
669
#else
659
670
level0 -> base .index = 0 ;
0 commit comments