1 #include <linux/sched.h>
2 #include <linux/errno.h>
17 static int seq_show(
struct seq_file *
m,
void *
v)
24 task = get_proc_task(m->
private);
29 put_task_struct(task);
34 spin_lock(&files->file_lock);
35 file = fcheck_files(files, fd);
46 spin_unlock(&files->file_lock);
52 (
long long)file->
f_pos, f_flags);
59 static int seq_fdinfo_open(
struct inode *
inode,
struct file *file)
65 .open = seq_fdinfo_open,
83 task = get_proc_task(inode);
92 file = fcheck_files(files, fd);
99 if (task_dumpable(task)) {
120 put_task_struct(task);
126 put_task_struct(task);
134 .d_revalidate = tid_fd_revalidate,
135 .d_delete = pid_delete_dentry,
138 static int proc_fd_link(
struct dentry *dentry,
struct path *
path)
144 task = get_proc_task(dentry->
d_inode);
147 put_task_struct(task);
151 int fd = proc_fd(dentry->
d_inode);
152 struct file *fd_file;
154 spin_lock(&files->file_lock);
155 fd_file = fcheck_files(files, fd);
161 spin_unlock(&files->file_lock);
168 static struct dentry *
169 proc_fd_instantiate(
struct inode *dir,
struct dentry *dentry,
173 unsigned fd = (
unsigned long)ptr;
190 d_set_d_op(dentry, &tid_fd_dentry_operations);
191 d_add(dentry, inode);
194 if (tid_fd_revalidate(dentry, 0))
200 static struct dentry *proc_lookupfd_common(
struct inode *dir,
201 struct dentry *dentry,
206 unsigned fd = name_to_int(dentry);
213 result = instantiate(dir, dentry, task, (
void *)(
unsigned long)fd);
215 put_task_struct(task);
220 static int proc_readfd_common(
struct file * filp,
void *
dirent,
223 struct dentry *dentry = filp->
f_path.dentry;
224 struct inode *inode = dentry->
d_inode;
227 unsigned int fd,
ino;
238 if (filldir(dirent,
".", 1, 0, inode->
i_ino,
DT_DIR) < 0)
243 if (filldir(dirent,
"..", 2, 1, ino,
DT_DIR) < 0)
251 for (fd = filp->
f_pos - 2;
253 fd++, filp->
f_pos++) {
258 if (!fcheck_files(files, fd))
262 len =
snprintf(name,
sizeof(name),
"%d", fd);
264 name, len, instantiate, p,
265 (
void *)(
unsigned long)fd);
280 static int proc_readfd(
struct file *filp,
void *dirent,
filldir_t filldir)
282 return proc_readfd_common(filp, dirent, filldir, proc_fd_instantiate);
287 .readdir = proc_readfd,
291 static struct dentry *proc_lookupfd(
struct inode *dir,
struct dentry *dentry,
294 return proc_lookupfd_common(dir, dentry, proc_fd_instantiate);
306 if (task_pid(
current) == proc_pid(inode))
312 .lookup = proc_lookupfd,
317 static struct dentry *
318 proc_fdinfo_instantiate(
struct inode *dir,
struct dentry *dentry,
321 struct dentry *error = ERR_PTR(-
ENOENT);
322 unsigned fd = (
unsigned long)ptr;
334 inode->
i_fop = &proc_fdinfo_file_operations;
336 d_set_d_op(dentry, &tid_fd_dentry_operations);
337 d_add(dentry, inode);
340 if (tid_fd_revalidate(dentry, 0))
346 static struct dentry *
347 proc_lookupfdinfo(
struct inode *dir,
struct dentry *dentry,
unsigned int flags)
349 return proc_lookupfd_common(dir, dentry, proc_fdinfo_instantiate);
352 static int proc_readfdinfo(
struct file *filp,
void *dirent,
filldir_t filldir)
354 return proc_readfd_common(filp, dirent, filldir,
355 proc_fdinfo_instantiate);
359 .lookup = proc_lookupfdinfo,
365 .readdir = proc_readfdinfo,