11 #include <linux/errno.h>
12 #include <linux/time.h>
14 #include <linux/stat.h>
16 #include <linux/module.h>
17 #include <linux/slab.h>
22 #include <linux/bitops.h>
25 #include <asm/uaccess.h>
39 #define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
52 unsigned long long pos;
69 while ((nbytes > 0) && !eof) {
122 count, &eof, dp->
data);
137 "proc_file_read: Apparent buffer overflow!\n");
145 start = page + *ppos;
146 }
else if (start < page) {
149 "proc_file_read: Apparent buffer overflow!\n");
158 "proc_file_read: Read count exceeded\n");
161 unsigned long startoff = (
unsigned long)(start - page);
164 "proc_file_read: Apparent buffer overflow!\n");
178 *ppos += start < page ? (
unsigned long)start : n;
202 rv = __proc_file_read(file, buf, nbytes, ppos);
209 proc_file_write(
struct file *file,
const char __user *
buffer,
210 size_t count, loff_t *ppos)
233 proc_file_lseek(
struct file *file, loff_t
offset,
int orig)
238 offset += file->
f_pos;
249 .llseek = proc_file_lseek,
250 .read = proc_file_read,
251 .write = proc_file_write,
265 iattr->
ia_size != i_size_read(inode)) {
272 mark_inode_dirty(inode);
280 static int proc_getattr(
struct vfsmount *mnt,
struct dentry *dentry,
283 struct inode *inode = dentry->
d_inode;
293 .setattr = proc_notify_change,
319 if (proc_match(len, cp, de))
323 WARN(1,
"name '%s'\n", name);
333 static int xlate_proc_name(
const char *name,
struct proc_dir_entry **ret,
334 const char **residual)
338 spin_lock(&proc_subdir_lock);
339 rv = __xlate_proc_name(name, ret, residual);
340 spin_unlock(&proc_subdir_lock);
347 #define PROC_DYNAMIC_FIRST 0xF0000000U
353 static unsigned int get_inode_number(
void)
362 spin_lock(&proc_inum_lock);
364 spin_unlock(&proc_inum_lock);
371 spin_lock(&proc_inum_lock);
373 spin_unlock(&proc_inum_lock);
379 static void release_inode_number(
unsigned int inum)
381 spin_lock(&proc_inum_lock);
383 spin_unlock(&proc_inum_lock);
386 static void *proc_follow_link(
struct dentry *dentry,
struct nameidata *nd)
388 nd_set_link(nd, PDE(dentry->
d_inode)->data);
394 .follow_link = proc_follow_link,
403 static int proc_delete_dentry(
const struct dentry * dentry)
410 .d_delete = proc_delete_dentry,
418 struct dentry *dentry)
420 struct inode *inode =
NULL;
440 d_add(dentry, inode);
445 return ERR_PTR(error);
448 struct dentry *
proc_lookup(
struct inode *dir,
struct dentry *dentry,
468 struct inode *inode = filp->
f_path.dentry->d_inode;
475 if (filldir(dirent,
".", 1, i, ino,
DT_DIR) < 0)
481 if (filldir(dirent,
"..", 2, i,
530 struct inode *inode = filp->
f_path.dentry->d_inode;
551 .getattr = proc_getattr,
552 .setattr = proc_notify_change,
560 i = get_inode_number();
568 dp->
proc_iops = &proc_dir_inode_operations;
573 dp->
proc_iops = &proc_link_inode_operations;
578 dp->
proc_iops = &proc_file_inode_operations;
581 spin_lock(&proc_subdir_lock);
593 spin_unlock(&proc_subdir_lock);
608 if (!name || !
strlen(name))
611 if (xlate_proc_name(name, parent, &fn) != 0)
640 ent = __proc_create(&parent, name,
647 if (proc_register(parent, ent) < 0) {
666 ent = __proc_create(&parent, name,
S_IFDIR | mode, 2);
668 if (proc_register(parent, ent) < 0) {
685 if (proc_register(parent, ent) < 0) {
719 ent = __proc_create(&parent, name, mode, nlink);
721 if (proc_register(parent, ent) < 0) {
750 pde = __proc_create(&parent, name, mode, nlink);
755 if (proc_register(parent, pde) < 0)
767 release_inode_number(de->
low_ino);
777 free_proc_entry(pde);
787 const char *fn =
name;
791 if (__xlate_proc_name(name, &parent, &fn) != 0) {
797 for (p = &parent->
subdir; *p; p=&(*p)->
next ) {
798 if (proc_match(len, fn, *p)) {
807 WARN(1,
"name '%s'\n", name);
847 "'%s/%s', leaking at least '%s'\n", __func__,