mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-04 01:24:12 +08:00
proc_map_files_readdir(): don't bother with grabbing files
all we need is their ->f_mode, so just collect _that_ Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
cb0942b812
commit
7b540d0646
@ -1805,7 +1805,7 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
struct map_files_info {
|
struct map_files_info {
|
||||||
struct file *file;
|
fmode_t mode;
|
||||||
unsigned long len;
|
unsigned long len;
|
||||||
unsigned char name[4*sizeof(long)+2]; /* max: %lx-%lx\0 */
|
unsigned char name[4*sizeof(long)+2]; /* max: %lx-%lx\0 */
|
||||||
};
|
};
|
||||||
@ -1814,13 +1814,10 @@ static struct dentry *
|
|||||||
proc_map_files_instantiate(struct inode *dir, struct dentry *dentry,
|
proc_map_files_instantiate(struct inode *dir, struct dentry *dentry,
|
||||||
struct task_struct *task, const void *ptr)
|
struct task_struct *task, const void *ptr)
|
||||||
{
|
{
|
||||||
const struct file *file = ptr;
|
fmode_t mode = (fmode_t)(unsigned long)ptr;
|
||||||
struct proc_inode *ei;
|
struct proc_inode *ei;
|
||||||
struct inode *inode;
|
struct inode *inode;
|
||||||
|
|
||||||
if (!file)
|
|
||||||
return ERR_PTR(-ENOENT);
|
|
||||||
|
|
||||||
inode = proc_pid_make_inode(dir->i_sb, task);
|
inode = proc_pid_make_inode(dir->i_sb, task);
|
||||||
if (!inode)
|
if (!inode)
|
||||||
return ERR_PTR(-ENOENT);
|
return ERR_PTR(-ENOENT);
|
||||||
@ -1832,9 +1829,9 @@ proc_map_files_instantiate(struct inode *dir, struct dentry *dentry,
|
|||||||
inode->i_size = 64;
|
inode->i_size = 64;
|
||||||
inode->i_mode = S_IFLNK;
|
inode->i_mode = S_IFLNK;
|
||||||
|
|
||||||
if (file->f_mode & FMODE_READ)
|
if (mode & FMODE_READ)
|
||||||
inode->i_mode |= S_IRUSR;
|
inode->i_mode |= S_IRUSR;
|
||||||
if (file->f_mode & FMODE_WRITE)
|
if (mode & FMODE_WRITE)
|
||||||
inode->i_mode |= S_IWUSR;
|
inode->i_mode |= S_IWUSR;
|
||||||
|
|
||||||
d_set_d_op(dentry, &tid_map_files_dentry_operations);
|
d_set_d_op(dentry, &tid_map_files_dentry_operations);
|
||||||
@ -1878,7 +1875,8 @@ static struct dentry *proc_map_files_lookup(struct inode *dir,
|
|||||||
if (!vma)
|
if (!vma)
|
||||||
goto out_no_vma;
|
goto out_no_vma;
|
||||||
|
|
||||||
result = proc_map_files_instantiate(dir, dentry, task, vma->vm_file);
|
result = proc_map_files_instantiate(dir, dentry, task,
|
||||||
|
(void *)(unsigned long)vma->vm_file->f_mode);
|
||||||
|
|
||||||
out_no_vma:
|
out_no_vma:
|
||||||
up_read(&mm->mmap_sem);
|
up_read(&mm->mmap_sem);
|
||||||
@ -1979,7 +1977,7 @@ proc_map_files_readdir(struct file *filp, void *dirent, filldir_t filldir)
|
|||||||
if (++pos <= filp->f_pos)
|
if (++pos <= filp->f_pos)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
info.file = get_file(vma->vm_file);
|
info.mode = vma->vm_file->f_mode;
|
||||||
info.len = snprintf(info.name,
|
info.len = snprintf(info.name,
|
||||||
sizeof(info.name), "%lx-%lx",
|
sizeof(info.name), "%lx-%lx",
|
||||||
vma->vm_start, vma->vm_end);
|
vma->vm_start, vma->vm_end);
|
||||||
@ -1994,19 +1992,11 @@ proc_map_files_readdir(struct file *filp, void *dirent, filldir_t filldir)
|
|||||||
ret = proc_fill_cache(filp, dirent, filldir,
|
ret = proc_fill_cache(filp, dirent, filldir,
|
||||||
p->name, p->len,
|
p->name, p->len,
|
||||||
proc_map_files_instantiate,
|
proc_map_files_instantiate,
|
||||||
task, p->file);
|
task,
|
||||||
|
(void *)(unsigned long)p->mode);
|
||||||
if (ret)
|
if (ret)
|
||||||
break;
|
break;
|
||||||
filp->f_pos++;
|
filp->f_pos++;
|
||||||
fput(p->file);
|
|
||||||
}
|
|
||||||
for (; i < nr_files; i++) {
|
|
||||||
/*
|
|
||||||
* In case of error don't forget
|
|
||||||
* to put rest of file refs.
|
|
||||||
*/
|
|
||||||
p = flex_array_get(fa, i);
|
|
||||||
fput(p->file);
|
|
||||||
}
|
}
|
||||||
if (fa)
|
if (fa)
|
||||||
flex_array_free(fa);
|
flex_array_free(fa);
|
||||||
|
Loading…
Reference in New Issue
Block a user