mirror of
https://github.com/apache/nuttx.git
synced 2026-05-28 20:08:15 +08:00
fs/inode: add common function to get file count from list
common function to get file count from file list Signed-off-by: chao an <anchao@xiaomi.com>
This commit is contained in:
+31
-31
@@ -1188,17 +1188,24 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile,
|
||||
size_t buflen, off_t offset)
|
||||
{
|
||||
FAR struct task_group_s *group = tcb->group;
|
||||
FAR struct file *file;
|
||||
FAR struct file *filep;
|
||||
char path[PATH_MAX];
|
||||
size_t remaining;
|
||||
size_t linesize;
|
||||
size_t copysize;
|
||||
size_t totalsize;
|
||||
int count;
|
||||
int ret;
|
||||
int i;
|
||||
int j;
|
||||
|
||||
DEBUGASSERT(group != NULL);
|
||||
|
||||
count = files_countlist(&group->tg_filelist);
|
||||
if (count == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
remaining = buflen;
|
||||
totalsize = 0;
|
||||
|
||||
@@ -1219,41 +1226,34 @@ static ssize_t proc_groupfd(FAR struct proc_file_s *procfile,
|
||||
|
||||
/* Examine each open file descriptor */
|
||||
|
||||
for (i = 0; i < group->tg_filelist.fl_rows; i++)
|
||||
for (i = 0; i < count; i++)
|
||||
{
|
||||
for (j = 0, file = group->tg_filelist.fl_files[i];
|
||||
j < CONFIG_NFILE_DESCRIPTORS_PER_BLOCK;
|
||||
j++, file++)
|
||||
ret = fs_getfilep(i, &filep);
|
||||
if (ret != OK || filep == NULL)
|
||||
{
|
||||
/* Is there an inode associated with the file descriptor? */
|
||||
continue;
|
||||
}
|
||||
|
||||
if (file->f_inode == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if (file_ioctl(filep, FIOC_FILEPATH, path) < 0)
|
||||
{
|
||||
path[0] = '\0';
|
||||
}
|
||||
|
||||
if (file_ioctl(file, FIOC_FILEPATH, path) < 0)
|
||||
{
|
||||
path[0] = '\0';
|
||||
}
|
||||
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
||||
"%-3d %-7d %-4x %-9ld %s\n",
|
||||
i, filep->f_oflags,
|
||||
INODE_GET_TYPE(filep->f_inode),
|
||||
(long)filep->f_pos, path);
|
||||
copysize = procfs_memcpy(procfile->line, linesize,
|
||||
buffer, remaining, &offset);
|
||||
|
||||
linesize = procfs_snprintf(procfile->line, STATUS_LINELEN,
|
||||
"%-3d %-7d %-4x %-9ld %s\n",
|
||||
i * CONFIG_NFILE_DESCRIPTORS_PER_BLOCK
|
||||
+ j, file->f_oflags,
|
||||
INODE_GET_TYPE(file->f_inode),
|
||||
(long)file->f_pos, path);
|
||||
copysize = procfs_memcpy(procfile->line, linesize,
|
||||
buffer, remaining, &offset);
|
||||
totalsize += copysize;
|
||||
buffer += copysize;
|
||||
remaining -= copysize;
|
||||
|
||||
totalsize += copysize;
|
||||
buffer += copysize;
|
||||
remaining -= copysize;
|
||||
|
||||
if (totalsize >= buflen)
|
||||
{
|
||||
return totalsize;
|
||||
}
|
||||
if (totalsize >= buflen)
|
||||
{
|
||||
return totalsize;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user