Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * proc/fs/generic.c --- generic routines for the proc-fs |
| 3 | * |
| 4 | * This file contains generic proc-fs routines for handling |
| 5 | * directories and files. |
| 6 | * |
| 7 | * Copyright (C) 1991, 1992 Linus Torvalds. |
| 8 | * Copyright (C) 1997 Theodore Ts'o |
| 9 | */ |
| 10 | |
| 11 | #include <linux/errno.h> |
| 12 | #include <linux/time.h> |
| 13 | #include <linux/proc_fs.h> |
| 14 | #include <linux/stat.h> |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 15 | #include <linux/mm.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #include <linux/module.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 17 | #include <linux/slab.h> |
Andrew Morton | 87ebdc0 | 2013-02-27 17:03:16 -0800 | [diff] [blame] | 18 | #include <linux/printk.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/mount.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | #include <linux/init.h> |
| 21 | #include <linux/idr.h> |
| 22 | #include <linux/namei.h> |
| 23 | #include <linux/bitops.h> |
Steven Rostedt | 64a07bd | 2006-03-26 01:36:55 -0800 | [diff] [blame] | 24 | #include <linux/spinlock.h> |
Alexey Dobriyan | 786d7e1 | 2007-07-15 23:39:00 -0700 | [diff] [blame] | 25 | #include <linux/completion.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <asm/uaccess.h> |
| 27 | |
Adrian Bunk | fee781e | 2006-01-08 01:04:16 -0800 | [diff] [blame] | 28 | #include "internal.h" |
| 29 | |
Alexey Dobriyan | 4dcc03f | 2014-08-08 14:21:29 -0700 | [diff] [blame] | 30 | static DEFINE_SPINLOCK(proc_subdir_lock); |
Steven Rostedt | 64a07bd | 2006-03-26 01:36:55 -0800 | [diff] [blame] | 31 | |
Alexey Dobriyan | 312ec7e | 2011-03-23 16:42:52 -0700 | [diff] [blame] | 32 | static int proc_match(unsigned int len, const char *name, struct proc_dir_entry *de) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 33 | { |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 34 | if (len < de->namelen) |
| 35 | return -1; |
| 36 | if (len > de->namelen) |
| 37 | return 1; |
| 38 | |
| 39 | return memcmp(name, de->name, len); |
| 40 | } |
| 41 | |
| 42 | static struct proc_dir_entry *pde_subdir_first(struct proc_dir_entry *dir) |
| 43 | { |
| 44 | struct rb_node *node = rb_first(&dir->subdir); |
| 45 | |
| 46 | if (node == NULL) |
| 47 | return NULL; |
| 48 | |
| 49 | return rb_entry(node, struct proc_dir_entry, subdir_node); |
| 50 | } |
| 51 | |
| 52 | static struct proc_dir_entry *pde_subdir_next(struct proc_dir_entry *dir) |
| 53 | { |
| 54 | struct rb_node *node = rb_next(&dir->subdir_node); |
| 55 | |
| 56 | if (node == NULL) |
| 57 | return NULL; |
| 58 | |
| 59 | return rb_entry(node, struct proc_dir_entry, subdir_node); |
| 60 | } |
| 61 | |
| 62 | static struct proc_dir_entry *pde_subdir_find(struct proc_dir_entry *dir, |
| 63 | const char *name, |
| 64 | unsigned int len) |
| 65 | { |
| 66 | struct rb_node *node = dir->subdir.rb_node; |
| 67 | |
| 68 | while (node) { |
| 69 | struct proc_dir_entry *de = container_of(node, |
| 70 | struct proc_dir_entry, |
| 71 | subdir_node); |
| 72 | int result = proc_match(len, name, de); |
| 73 | |
| 74 | if (result < 0) |
| 75 | node = node->rb_left; |
| 76 | else if (result > 0) |
| 77 | node = node->rb_right; |
| 78 | else |
| 79 | return de; |
| 80 | } |
| 81 | return NULL; |
| 82 | } |
| 83 | |
| 84 | static bool pde_subdir_insert(struct proc_dir_entry *dir, |
| 85 | struct proc_dir_entry *de) |
| 86 | { |
| 87 | struct rb_root *root = &dir->subdir; |
| 88 | struct rb_node **new = &root->rb_node, *parent = NULL; |
| 89 | |
| 90 | /* Figure out where to put new node */ |
| 91 | while (*new) { |
| 92 | struct proc_dir_entry *this = |
| 93 | container_of(*new, struct proc_dir_entry, subdir_node); |
| 94 | int result = proc_match(de->namelen, de->name, this); |
| 95 | |
| 96 | parent = *new; |
| 97 | if (result < 0) |
| 98 | new = &(*new)->rb_left; |
| 99 | else if (result > 0) |
| 100 | new = &(*new)->rb_right; |
| 101 | else |
| 102 | return false; |
| 103 | } |
| 104 | |
| 105 | /* Add new node and rebalance tree. */ |
| 106 | rb_link_node(&de->subdir_node, parent, new); |
| 107 | rb_insert_color(&de->subdir_node, root); |
| 108 | return true; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | static int proc_notify_change(struct dentry *dentry, struct iattr *iattr) |
| 112 | { |
| 113 | struct inode *inode = dentry->d_inode; |
| 114 | struct proc_dir_entry *de = PDE(inode); |
| 115 | int error; |
| 116 | |
| 117 | error = inode_change_ok(inode, iattr); |
| 118 | if (error) |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 119 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 121 | setattr_copy(inode, iattr); |
| 122 | mark_inode_dirty(inode); |
Marco Stornelli | 46f6955 | 2012-12-15 11:48:48 +0100 | [diff] [blame] | 123 | |
Rui Xiang | cdf7e8d | 2014-01-23 15:55:41 -0800 | [diff] [blame] | 124 | proc_set_user(de, inode->i_uid, inode->i_gid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | de->mode = inode->i_mode; |
Christoph Hellwig | 1025774 | 2010-06-04 11:30:02 +0200 | [diff] [blame] | 126 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Miklos Szeredi | 2b579be | 2005-09-06 15:17:18 -0700 | [diff] [blame] | 129 | static int proc_getattr(struct vfsmount *mnt, struct dentry *dentry, |
| 130 | struct kstat *stat) |
| 131 | { |
| 132 | struct inode *inode = dentry->d_inode; |
| 133 | struct proc_dir_entry *de = PROC_I(inode)->pde; |
| 134 | if (de && de->nlink) |
Miklos Szeredi | bfe8684 | 2011-10-28 14:13:29 +0200 | [diff] [blame] | 135 | set_nlink(inode, de->nlink); |
Miklos Szeredi | 2b579be | 2005-09-06 15:17:18 -0700 | [diff] [blame] | 136 | |
| 137 | generic_fillattr(inode, stat); |
| 138 | return 0; |
| 139 | } |
| 140 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 141 | static const struct inode_operations proc_file_inode_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | .setattr = proc_notify_change, |
| 143 | }; |
| 144 | |
| 145 | /* |
| 146 | * This function parses a name such as "tty/driver/serial", and |
| 147 | * returns the struct proc_dir_entry for "/proc/tty/driver", and |
| 148 | * returns "serial" in residual. |
| 149 | */ |
Alexey Dobriyan | e17a576 | 2010-03-05 13:43:59 -0800 | [diff] [blame] | 150 | static int __xlate_proc_name(const char *name, struct proc_dir_entry **ret, |
| 151 | const char **residual) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 152 | { |
| 153 | const char *cp = name, *next; |
| 154 | struct proc_dir_entry *de; |
Alexey Dobriyan | 312ec7e | 2011-03-23 16:42:52 -0700 | [diff] [blame] | 155 | unsigned int len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | |
Alexey Dobriyan | 7cee4e0 | 2008-04-29 01:01:40 -0700 | [diff] [blame] | 157 | de = *ret; |
| 158 | if (!de) |
| 159 | de = &proc_root; |
| 160 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | while (1) { |
| 162 | next = strchr(cp, '/'); |
| 163 | if (!next) |
| 164 | break; |
| 165 | |
| 166 | len = next - cp; |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 167 | de = pde_subdir_find(de, cp, len); |
Alexey Dobriyan | 12bac0d | 2010-03-05 13:44:00 -0800 | [diff] [blame] | 168 | if (!de) { |
| 169 | WARN(1, "name '%s'\n", name); |
Alexey Dobriyan | e17a576 | 2010-03-05 13:43:59 -0800 | [diff] [blame] | 170 | return -ENOENT; |
Alexey Dobriyan | 12bac0d | 2010-03-05 13:44:00 -0800 | [diff] [blame] | 171 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 172 | cp += len + 1; |
| 173 | } |
| 174 | *residual = cp; |
| 175 | *ret = de; |
Alexey Dobriyan | e17a576 | 2010-03-05 13:43:59 -0800 | [diff] [blame] | 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | static int xlate_proc_name(const char *name, struct proc_dir_entry **ret, |
| 180 | const char **residual) |
| 181 | { |
| 182 | int rv; |
| 183 | |
| 184 | spin_lock(&proc_subdir_lock); |
| 185 | rv = __xlate_proc_name(name, ret, residual); |
Steven Rostedt | 64a07bd | 2006-03-26 01:36:55 -0800 | [diff] [blame] | 186 | spin_unlock(&proc_subdir_lock); |
Alexey Dobriyan | e17a576 | 2010-03-05 13:43:59 -0800 | [diff] [blame] | 187 | return rv; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | } |
| 189 | |
Alexey Dobriyan | 9a18540 | 2008-07-26 11:21:37 +0400 | [diff] [blame] | 190 | static DEFINE_IDA(proc_inum_ida); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | static DEFINE_SPINLOCK(proc_inum_lock); /* protects the above */ |
| 192 | |
Alexey Dobriyan | 67935df | 2008-07-26 11:18:28 +0400 | [diff] [blame] | 193 | #define PROC_DYNAMIC_FIRST 0xF0000000U |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | |
| 195 | /* |
| 196 | * Return an inode number between PROC_DYNAMIC_FIRST and |
| 197 | * 0xffffffff, or zero on failure. |
| 198 | */ |
Eric W. Biederman | 33d6dce | 2011-06-17 13:33:20 -0700 | [diff] [blame] | 199 | int proc_alloc_inum(unsigned int *inum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | { |
Alexey Dobriyan | 67935df | 2008-07-26 11:18:28 +0400 | [diff] [blame] | 201 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | int error; |
| 203 | |
| 204 | retry: |
Eric W. Biederman | 33d6dce | 2011-06-17 13:33:20 -0700 | [diff] [blame] | 205 | if (!ida_pre_get(&proc_inum_ida, GFP_KERNEL)) |
| 206 | return -ENOMEM; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Eric W. Biederman | dfb2ea4 | 2012-12-21 20:38:00 -0800 | [diff] [blame] | 208 | spin_lock_irq(&proc_inum_lock); |
Alexey Dobriyan | 9a18540 | 2008-07-26 11:21:37 +0400 | [diff] [blame] | 209 | error = ida_get_new(&proc_inum_ida, &i); |
Eric W. Biederman | dfb2ea4 | 2012-12-21 20:38:00 -0800 | [diff] [blame] | 210 | spin_unlock_irq(&proc_inum_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | if (error == -EAGAIN) |
| 212 | goto retry; |
| 213 | else if (error) |
Eric W. Biederman | 33d6dce | 2011-06-17 13:33:20 -0700 | [diff] [blame] | 214 | return error; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | |
Alexey Dobriyan | 67935df | 2008-07-26 11:18:28 +0400 | [diff] [blame] | 216 | if (i > UINT_MAX - PROC_DYNAMIC_FIRST) { |
Eric W. Biederman | dfb2ea4 | 2012-12-21 20:38:00 -0800 | [diff] [blame] | 217 | spin_lock_irq(&proc_inum_lock); |
Alexey Dobriyan | 9a18540 | 2008-07-26 11:21:37 +0400 | [diff] [blame] | 218 | ida_remove(&proc_inum_ida, i); |
Eric W. Biederman | dfb2ea4 | 2012-12-21 20:38:00 -0800 | [diff] [blame] | 219 | spin_unlock_irq(&proc_inum_lock); |
Eric W. Biederman | 33d6dce | 2011-06-17 13:33:20 -0700 | [diff] [blame] | 220 | return -ENOSPC; |
Alexey Dobriyan | 67935df | 2008-07-26 11:18:28 +0400 | [diff] [blame] | 221 | } |
Eric W. Biederman | 33d6dce | 2011-06-17 13:33:20 -0700 | [diff] [blame] | 222 | *inum = PROC_DYNAMIC_FIRST + i; |
| 223 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | } |
| 225 | |
Eric W. Biederman | 33d6dce | 2011-06-17 13:33:20 -0700 | [diff] [blame] | 226 | void proc_free_inum(unsigned int inum) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | { |
Eric W. Biederman | dfb2ea4 | 2012-12-21 20:38:00 -0800 | [diff] [blame] | 228 | unsigned long flags; |
| 229 | spin_lock_irqsave(&proc_inum_lock, flags); |
Alexey Dobriyan | 9a18540 | 2008-07-26 11:21:37 +0400 | [diff] [blame] | 230 | ida_remove(&proc_inum_ida, inum - PROC_DYNAMIC_FIRST); |
Eric W. Biederman | dfb2ea4 | 2012-12-21 20:38:00 -0800 | [diff] [blame] | 231 | spin_unlock_irqrestore(&proc_inum_lock, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | } |
| 233 | |
Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 234 | static void *proc_follow_link(struct dentry *dentry, struct nameidata *nd) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | { |
David Howells | c30480b | 2013-04-12 18:03:36 +0100 | [diff] [blame] | 236 | nd_set_link(nd, __PDE_DATA(dentry->d_inode)); |
Al Viro | 008b150 | 2005-08-20 00:17:39 +0100 | [diff] [blame] | 237 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | } |
| 239 | |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 240 | static const struct inode_operations proc_link_inode_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | .readlink = generic_readlink, |
| 242 | .follow_link = proc_follow_link, |
| 243 | }; |
| 244 | |
| 245 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | * Don't create negative dentries here, return -ENOENT by hand |
| 247 | * instead. |
| 248 | */ |
Pavel Emelyanov | e9720ac | 2008-03-07 11:08:40 -0800 | [diff] [blame] | 249 | struct dentry *proc_lookup_de(struct proc_dir_entry *de, struct inode *dir, |
| 250 | struct dentry *dentry) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | { |
Al Viro | d3d009c | 2013-01-25 20:11:22 -0500 | [diff] [blame] | 252 | struct inode *inode; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 253 | |
Steven Rostedt | 64a07bd | 2006-03-26 01:36:55 -0800 | [diff] [blame] | 254 | spin_lock(&proc_subdir_lock); |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 255 | de = pde_subdir_find(de, dentry->d_name.name, dentry->d_name.len); |
| 256 | if (de) { |
| 257 | pde_get(de); |
| 258 | spin_unlock(&proc_subdir_lock); |
| 259 | inode = proc_get_inode(dir->i_sb, de); |
| 260 | if (!inode) |
| 261 | return ERR_PTR(-ENOMEM); |
| 262 | d_set_d_op(dentry, &simple_dentry_operations); |
| 263 | d_add(dentry, inode); |
| 264 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | } |
Steven Rostedt | 64a07bd | 2006-03-26 01:36:55 -0800 | [diff] [blame] | 266 | spin_unlock(&proc_subdir_lock); |
Al Viro | d3d009c | 2013-01-25 20:11:22 -0500 | [diff] [blame] | 267 | return ERR_PTR(-ENOENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | } |
| 269 | |
Pavel Emelyanov | e9720ac | 2008-03-07 11:08:40 -0800 | [diff] [blame] | 270 | struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry, |
Al Viro | 00cd8dd | 2012-06-10 17:13:09 -0400 | [diff] [blame] | 271 | unsigned int flags) |
Pavel Emelyanov | e9720ac | 2008-03-07 11:08:40 -0800 | [diff] [blame] | 272 | { |
| 273 | return proc_lookup_de(PDE(dir), dir, dentry); |
| 274 | } |
| 275 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | /* |
| 277 | * This returns non-zero if at EOF, so that the /proc |
| 278 | * root directory can use this and check if it should |
| 279 | * continue with the <pid> entries.. |
| 280 | * |
| 281 | * Note that the VFS-layer doesn't care about the return |
| 282 | * value of the readdir() call, as long as it's non-negative |
| 283 | * for success.. |
| 284 | */ |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 285 | int proc_readdir_de(struct proc_dir_entry *de, struct file *file, |
| 286 | struct dir_context *ctx) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 289 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 290 | if (!dir_emit_dots(file, ctx)) |
| 291 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 293 | spin_lock(&proc_subdir_lock); |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 294 | de = pde_subdir_first(de); |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 295 | i = ctx->pos - 2; |
| 296 | for (;;) { |
| 297 | if (!de) { |
Steven Rostedt | 64a07bd | 2006-03-26 01:36:55 -0800 | [diff] [blame] | 298 | spin_unlock(&proc_subdir_lock); |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 299 | return 0; |
| 300 | } |
| 301 | if (!i) |
| 302 | break; |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 303 | de = pde_subdir_next(de); |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 304 | i--; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | } |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 306 | |
| 307 | do { |
| 308 | struct proc_dir_entry *next; |
| 309 | pde_get(de); |
| 310 | spin_unlock(&proc_subdir_lock); |
| 311 | if (!dir_emit(ctx, de->name, de->namelen, |
| 312 | de->low_ino, de->mode >> 12)) { |
| 313 | pde_put(de); |
| 314 | return 0; |
| 315 | } |
| 316 | spin_lock(&proc_subdir_lock); |
| 317 | ctx->pos++; |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 318 | next = pde_subdir_next(de); |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 319 | pde_put(de); |
| 320 | de = next; |
| 321 | } while (de); |
| 322 | spin_unlock(&proc_subdir_lock); |
Linus Torvalds | fd3930f | 2013-08-19 16:26:12 -0700 | [diff] [blame] | 323 | return 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | } |
| 325 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 326 | int proc_readdir(struct file *file, struct dir_context *ctx) |
Pavel Emelyanov | e9720ac | 2008-03-07 11:08:40 -0800 | [diff] [blame] | 327 | { |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 328 | struct inode *inode = file_inode(file); |
Pavel Emelyanov | e9720ac | 2008-03-07 11:08:40 -0800 | [diff] [blame] | 329 | |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 330 | return proc_readdir_de(PDE(inode), file, ctx); |
Pavel Emelyanov | e9720ac | 2008-03-07 11:08:40 -0800 | [diff] [blame] | 331 | } |
| 332 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 333 | /* |
| 334 | * These are the generic /proc directory operations. They |
| 335 | * use the in-memory "struct proc_dir_entry" tree to parse |
| 336 | * the /proc directory. |
| 337 | */ |
Arjan van de Ven | 00977a5 | 2007-02-12 00:55:34 -0800 | [diff] [blame] | 338 | static const struct file_operations proc_dir_operations = { |
Alexey Dobriyan | b4df2b9 | 2008-10-27 22:48:36 +0300 | [diff] [blame] | 339 | .llseek = generic_file_llseek, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 340 | .read = generic_read_dir, |
Al Viro | f0c3b50 | 2013-05-16 12:07:31 -0400 | [diff] [blame] | 341 | .iterate = proc_readdir, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | }; |
| 343 | |
| 344 | /* |
| 345 | * proc directories can do almost nothing.. |
| 346 | */ |
Arjan van de Ven | c5ef1c4 | 2007-02-12 00:55:40 -0800 | [diff] [blame] | 347 | static const struct inode_operations proc_dir_inode_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | .lookup = proc_lookup, |
Miklos Szeredi | 2b579be | 2005-09-06 15:17:18 -0700 | [diff] [blame] | 349 | .getattr = proc_getattr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 350 | .setattr = proc_notify_change, |
| 351 | }; |
| 352 | |
| 353 | static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp) |
| 354 | { |
Eric W. Biederman | 33d6dce | 2011-06-17 13:33:20 -0700 | [diff] [blame] | 355 | int ret; |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 356 | |
Eric W. Biederman | 33d6dce | 2011-06-17 13:33:20 -0700 | [diff] [blame] | 357 | ret = proc_alloc_inum(&dp->low_ino); |
| 358 | if (ret) |
| 359 | return ret; |
Steven Rostedt | 64a07bd | 2006-03-26 01:36:55 -0800 | [diff] [blame] | 360 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 361 | if (S_ISDIR(dp->mode)) { |
Al Viro | b6cdc73 | 2013-03-30 21:20:14 -0400 | [diff] [blame] | 362 | dp->proc_fops = &proc_dir_operations; |
| 363 | dp->proc_iops = &proc_dir_inode_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | dir->nlink++; |
| 365 | } else if (S_ISLNK(dp->mode)) { |
Al Viro | b6cdc73 | 2013-03-30 21:20:14 -0400 | [diff] [blame] | 366 | dp->proc_iops = &proc_link_inode_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | } else if (S_ISREG(dp->mode)) { |
David Howells | 3cb5bf1 | 2013-04-11 03:20:50 +0100 | [diff] [blame] | 368 | BUG_ON(dp->proc_fops == NULL); |
Al Viro | b6cdc73 | 2013-03-30 21:20:14 -0400 | [diff] [blame] | 369 | dp->proc_iops = &proc_file_inode_operations; |
| 370 | } else { |
| 371 | WARN_ON(1); |
Debabrata Banerjee | b208d54 | 2014-12-10 15:45:04 -0800 | [diff] [blame^] | 372 | proc_free_inum(dp->low_ino); |
Al Viro | b6cdc73 | 2013-03-30 21:20:14 -0400 | [diff] [blame] | 373 | return -EINVAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
Changli Gao | 99fc06d | 2007-07-15 23:40:09 -0700 | [diff] [blame] | 375 | |
| 376 | spin_lock(&proc_subdir_lock); |
Changli Gao | 99fc06d | 2007-07-15 23:40:09 -0700 | [diff] [blame] | 377 | dp->parent = dir; |
Debabrata Banerjee | b208d54 | 2014-12-10 15:45:04 -0800 | [diff] [blame^] | 378 | if (pde_subdir_insert(dir, dp) == false) { |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 379 | WARN(1, "proc_dir_entry '%s/%s' already registered\n", |
| 380 | dir->name, dp->name); |
Debabrata Banerjee | b208d54 | 2014-12-10 15:45:04 -0800 | [diff] [blame^] | 381 | spin_unlock(&proc_subdir_lock); |
| 382 | if (S_ISDIR(dp->mode)) |
| 383 | dir->nlink--; |
| 384 | proc_free_inum(dp->low_ino); |
| 385 | return -EEXIST; |
| 386 | } |
Changli Gao | 99fc06d | 2007-07-15 23:40:09 -0700 | [diff] [blame] | 387 | spin_unlock(&proc_subdir_lock); |
| 388 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | return 0; |
| 390 | } |
| 391 | |
Alexey Dobriyan | 2d3a4e3 | 2008-02-08 04:18:37 -0800 | [diff] [blame] | 392 | static struct proc_dir_entry *__proc_create(struct proc_dir_entry **parent, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | const char *name, |
Al Viro | d161a13 | 2011-07-24 03:36:29 -0400 | [diff] [blame] | 394 | umode_t mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 | nlink_t nlink) |
| 396 | { |
| 397 | struct proc_dir_entry *ent = NULL; |
Alexey Dobriyan | dbcdb50 | 2014-08-08 14:21:25 -0700 | [diff] [blame] | 398 | const char *fn; |
| 399 | struct qstr qstr; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | |
Alexey Dobriyan | 7cee4e0 | 2008-04-29 01:01:40 -0700 | [diff] [blame] | 401 | if (xlate_proc_name(name, parent, &fn) != 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 402 | goto out; |
Alexey Dobriyan | dbcdb50 | 2014-08-08 14:21:25 -0700 | [diff] [blame] | 403 | qstr.name = fn; |
| 404 | qstr.len = strlen(fn); |
| 405 | if (qstr.len == 0 || qstr.len >= 256) { |
| 406 | WARN(1, "name len %u\n", qstr.len); |
| 407 | return NULL; |
| 408 | } |
| 409 | if (*parent == &proc_root && name_to_int(&qstr) != ~0U) { |
| 410 | WARN(1, "create '/proc/%s' by hand\n", qstr.name); |
| 411 | return NULL; |
| 412 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
Alexey Dobriyan | dbcdb50 | 2014-08-08 14:21:25 -0700 | [diff] [blame] | 414 | ent = kzalloc(sizeof(struct proc_dir_entry) + qstr.len + 1, GFP_KERNEL); |
yan | 17baa2a | 2012-10-04 17:15:43 -0700 | [diff] [blame] | 415 | if (!ent) |
| 416 | goto out; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | |
Alexey Dobriyan | dbcdb50 | 2014-08-08 14:21:25 -0700 | [diff] [blame] | 418 | memcpy(ent->name, fn, qstr.len + 1); |
| 419 | ent->namelen = qstr.len; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | ent->mode = mode; |
| 421 | ent->nlink = nlink; |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 422 | ent->subdir = RB_ROOT; |
Alexey Dobriyan | 5a622f2 | 2007-12-04 23:45:28 -0800 | [diff] [blame] | 423 | atomic_set(&ent->count, 1); |
Alexey Dobriyan | 786d7e1 | 2007-07-15 23:39:00 -0700 | [diff] [blame] | 424 | spin_lock_init(&ent->pde_unload_lock); |
Alexey Dobriyan | 881adb8 | 2008-07-25 01:48:29 -0700 | [diff] [blame] | 425 | INIT_LIST_HEAD(&ent->pde_openers); |
yan | 17baa2a | 2012-10-04 17:15:43 -0700 | [diff] [blame] | 426 | out: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | return ent; |
| 428 | } |
| 429 | |
| 430 | struct proc_dir_entry *proc_symlink(const char *name, |
| 431 | struct proc_dir_entry *parent, const char *dest) |
| 432 | { |
| 433 | struct proc_dir_entry *ent; |
| 434 | |
Alexey Dobriyan | 2d3a4e3 | 2008-02-08 04:18:37 -0800 | [diff] [blame] | 435 | ent = __proc_create(&parent, name, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | (S_IFLNK | S_IRUGO | S_IWUGO | S_IXUGO),1); |
| 437 | |
| 438 | if (ent) { |
| 439 | ent->data = kmalloc((ent->size=strlen(dest))+1, GFP_KERNEL); |
| 440 | if (ent->data) { |
| 441 | strcpy((char*)ent->data,dest); |
| 442 | if (proc_register(parent, ent) < 0) { |
| 443 | kfree(ent->data); |
| 444 | kfree(ent); |
| 445 | ent = NULL; |
| 446 | } |
| 447 | } else { |
| 448 | kfree(ent); |
| 449 | ent = NULL; |
| 450 | } |
| 451 | } |
| 452 | return ent; |
| 453 | } |
Helight.Xu | 587d4a1 | 2009-12-30 13:24:41 +0800 | [diff] [blame] | 454 | EXPORT_SYMBOL(proc_symlink); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | |
David Howells | 270b5ac | 2013-04-12 02:48:30 +0100 | [diff] [blame] | 456 | struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode, |
| 457 | struct proc_dir_entry *parent, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 458 | { |
| 459 | struct proc_dir_entry *ent; |
| 460 | |
David Howells | 270b5ac | 2013-04-12 02:48:30 +0100 | [diff] [blame] | 461 | if (mode == 0) |
| 462 | mode = S_IRUGO | S_IXUGO; |
| 463 | |
Alexey Dobriyan | 2d3a4e3 | 2008-02-08 04:18:37 -0800 | [diff] [blame] | 464 | ent = __proc_create(&parent, name, S_IFDIR | mode, 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | if (ent) { |
David Howells | 270b5ac | 2013-04-12 02:48:30 +0100 | [diff] [blame] | 466 | ent->data = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 467 | if (proc_register(parent, ent) < 0) { |
| 468 | kfree(ent); |
| 469 | ent = NULL; |
| 470 | } |
| 471 | } |
| 472 | return ent; |
| 473 | } |
David Howells | 270b5ac | 2013-04-12 02:48:30 +0100 | [diff] [blame] | 474 | EXPORT_SYMBOL_GPL(proc_mkdir_data); |
| 475 | |
| 476 | struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode, |
| 477 | struct proc_dir_entry *parent) |
| 478 | { |
| 479 | return proc_mkdir_data(name, mode, parent, NULL); |
| 480 | } |
Alexey Dobriyan | 011159a | 2011-05-14 00:12:48 +0300 | [diff] [blame] | 481 | EXPORT_SYMBOL(proc_mkdir_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | |
| 483 | struct proc_dir_entry *proc_mkdir(const char *name, |
| 484 | struct proc_dir_entry *parent) |
| 485 | { |
David Howells | 270b5ac | 2013-04-12 02:48:30 +0100 | [diff] [blame] | 486 | return proc_mkdir_data(name, 0, parent, NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | } |
Helight.Xu | 587d4a1 | 2009-12-30 13:24:41 +0800 | [diff] [blame] | 488 | EXPORT_SYMBOL(proc_mkdir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | |
Al Viro | d161a13 | 2011-07-24 03:36:29 -0400 | [diff] [blame] | 490 | struct proc_dir_entry *proc_create_data(const char *name, umode_t mode, |
Denis V. Lunev | 59b7435 | 2008-04-29 01:02:00 -0700 | [diff] [blame] | 491 | struct proc_dir_entry *parent, |
| 492 | const struct file_operations *proc_fops, |
| 493 | void *data) |
Alexey Dobriyan | 2d3a4e3 | 2008-02-08 04:18:37 -0800 | [diff] [blame] | 494 | { |
| 495 | struct proc_dir_entry *pde; |
Al Viro | b6cdc73 | 2013-03-30 21:20:14 -0400 | [diff] [blame] | 496 | if ((mode & S_IFMT) == 0) |
| 497 | mode |= S_IFREG; |
Alexey Dobriyan | 2d3a4e3 | 2008-02-08 04:18:37 -0800 | [diff] [blame] | 498 | |
Al Viro | b6cdc73 | 2013-03-30 21:20:14 -0400 | [diff] [blame] | 499 | if (!S_ISREG(mode)) { |
| 500 | WARN_ON(1); /* use proc_mkdir() */ |
| 501 | return NULL; |
Alexey Dobriyan | 2d3a4e3 | 2008-02-08 04:18:37 -0800 | [diff] [blame] | 502 | } |
| 503 | |
Al Viro | b6cdc73 | 2013-03-30 21:20:14 -0400 | [diff] [blame] | 504 | if ((mode & S_IALLUGO) == 0) |
| 505 | mode |= S_IRUGO; |
| 506 | pde = __proc_create(&parent, name, mode, 1); |
Alexey Dobriyan | 2d3a4e3 | 2008-02-08 04:18:37 -0800 | [diff] [blame] | 507 | if (!pde) |
| 508 | goto out; |
| 509 | pde->proc_fops = proc_fops; |
Denis V. Lunev | 59b7435 | 2008-04-29 01:02:00 -0700 | [diff] [blame] | 510 | pde->data = data; |
Alexey Dobriyan | 2d3a4e3 | 2008-02-08 04:18:37 -0800 | [diff] [blame] | 511 | if (proc_register(parent, pde) < 0) |
| 512 | goto out_free; |
| 513 | return pde; |
| 514 | out_free: |
| 515 | kfree(pde); |
| 516 | out: |
| 517 | return NULL; |
| 518 | } |
Helight.Xu | 587d4a1 | 2009-12-30 13:24:41 +0800 | [diff] [blame] | 519 | EXPORT_SYMBOL(proc_create_data); |
David Howells | 271a15e | 2013-04-12 00:38:51 +0100 | [diff] [blame] | 520 | |
| 521 | void proc_set_size(struct proc_dir_entry *de, loff_t size) |
| 522 | { |
| 523 | de->size = size; |
| 524 | } |
| 525 | EXPORT_SYMBOL(proc_set_size); |
| 526 | |
| 527 | void proc_set_user(struct proc_dir_entry *de, kuid_t uid, kgid_t gid) |
| 528 | { |
| 529 | de->uid = uid; |
| 530 | de->gid = gid; |
| 531 | } |
| 532 | EXPORT_SYMBOL(proc_set_user); |
Alexey Dobriyan | 2d3a4e3 | 2008-02-08 04:18:37 -0800 | [diff] [blame] | 533 | |
Alexey Dobriyan | 135d565 | 2009-12-15 16:45:39 -0800 | [diff] [blame] | 534 | static void free_proc_entry(struct proc_dir_entry *de) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | { |
Eric W. Biederman | 33d6dce | 2011-06-17 13:33:20 -0700 | [diff] [blame] | 536 | proc_free_inum(de->low_ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 537 | |
Alexey Dobriyan | fd2cbe4 | 2008-02-08 04:18:28 -0800 | [diff] [blame] | 538 | if (S_ISLNK(de->mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | kfree(de->data); |
| 540 | kfree(de); |
| 541 | } |
| 542 | |
Alexey Dobriyan | 135d565 | 2009-12-15 16:45:39 -0800 | [diff] [blame] | 543 | void pde_put(struct proc_dir_entry *pde) |
| 544 | { |
| 545 | if (atomic_dec_and_test(&pde->count)) |
| 546 | free_proc_entry(pde); |
| 547 | } |
| 548 | |
Al Viro | 8ce584c | 2013-03-30 20:13:46 -0400 | [diff] [blame] | 549 | /* |
| 550 | * Remove a /proc entry and free it if it's not currently in use. |
| 551 | */ |
| 552 | void remove_proc_entry(const char *name, struct proc_dir_entry *parent) |
| 553 | { |
Al Viro | 8ce584c | 2013-03-30 20:13:46 -0400 | [diff] [blame] | 554 | struct proc_dir_entry *de = NULL; |
| 555 | const char *fn = name; |
| 556 | unsigned int len; |
| 557 | |
| 558 | spin_lock(&proc_subdir_lock); |
| 559 | if (__xlate_proc_name(name, &parent, &fn) != 0) { |
| 560 | spin_unlock(&proc_subdir_lock); |
| 561 | return; |
| 562 | } |
| 563 | len = strlen(fn); |
| 564 | |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 565 | de = pde_subdir_find(parent, fn, len); |
| 566 | if (de) |
| 567 | rb_erase(&de->subdir_node, &parent->subdir); |
Al Viro | 8ce584c | 2013-03-30 20:13:46 -0400 | [diff] [blame] | 568 | spin_unlock(&proc_subdir_lock); |
| 569 | if (!de) { |
| 570 | WARN(1, "name '%s'\n", name); |
| 571 | return; |
| 572 | } |
| 573 | |
Al Viro | 866ad9a7 | 2013-04-03 19:07:30 -0400 | [diff] [blame] | 574 | proc_entry_rundown(de); |
Alexey Dobriyan | 881adb8 | 2008-07-25 01:48:29 -0700 | [diff] [blame] | 575 | |
Alexey Dobriyan | f649d6d | 2008-04-29 01:01:39 -0700 | [diff] [blame] | 576 | if (S_ISDIR(de->mode)) |
| 577 | parent->nlink--; |
| 578 | de->nlink = 0; |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 579 | WARN(pde_subdir_first(de), |
| 580 | "%s: removing non-empty directory '%s/%s', leaking at least '%s'\n", |
| 581 | __func__, de->parent->name, de->name, pde_subdir_first(de)->name); |
Alexey Dobriyan | 135d565 | 2009-12-15 16:45:39 -0800 | [diff] [blame] | 582 | pde_put(de); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 | } |
Helight.Xu | 587d4a1 | 2009-12-30 13:24:41 +0800 | [diff] [blame] | 584 | EXPORT_SYMBOL(remove_proc_entry); |
Al Viro | 8ce584c | 2013-03-30 20:13:46 -0400 | [diff] [blame] | 585 | |
| 586 | int remove_proc_subtree(const char *name, struct proc_dir_entry *parent) |
| 587 | { |
Al Viro | 8ce584c | 2013-03-30 20:13:46 -0400 | [diff] [blame] | 588 | struct proc_dir_entry *root = NULL, *de, *next; |
| 589 | const char *fn = name; |
| 590 | unsigned int len; |
| 591 | |
| 592 | spin_lock(&proc_subdir_lock); |
| 593 | if (__xlate_proc_name(name, &parent, &fn) != 0) { |
| 594 | spin_unlock(&proc_subdir_lock); |
| 595 | return -ENOENT; |
| 596 | } |
| 597 | len = strlen(fn); |
| 598 | |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 599 | root = pde_subdir_find(parent, fn, len); |
Al Viro | 8ce584c | 2013-03-30 20:13:46 -0400 | [diff] [blame] | 600 | if (!root) { |
| 601 | spin_unlock(&proc_subdir_lock); |
| 602 | return -ENOENT; |
| 603 | } |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 604 | rb_erase(&root->subdir_node, &parent->subdir); |
| 605 | |
Al Viro | 8ce584c | 2013-03-30 20:13:46 -0400 | [diff] [blame] | 606 | de = root; |
| 607 | while (1) { |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 608 | next = pde_subdir_first(de); |
Al Viro | 8ce584c | 2013-03-30 20:13:46 -0400 | [diff] [blame] | 609 | if (next) { |
Nicolas Dichtel | 710585d | 2014-12-10 15:45:01 -0800 | [diff] [blame] | 610 | rb_erase(&next->subdir_node, &de->subdir); |
Al Viro | 8ce584c | 2013-03-30 20:13:46 -0400 | [diff] [blame] | 611 | de = next; |
| 612 | continue; |
| 613 | } |
| 614 | spin_unlock(&proc_subdir_lock); |
| 615 | |
Al Viro | 866ad9a7 | 2013-04-03 19:07:30 -0400 | [diff] [blame] | 616 | proc_entry_rundown(de); |
Al Viro | 8ce584c | 2013-03-30 20:13:46 -0400 | [diff] [blame] | 617 | next = de->parent; |
| 618 | if (S_ISDIR(de->mode)) |
| 619 | next->nlink--; |
| 620 | de->nlink = 0; |
| 621 | if (de == root) |
| 622 | break; |
| 623 | pde_put(de); |
| 624 | |
| 625 | spin_lock(&proc_subdir_lock); |
| 626 | de = next; |
| 627 | } |
| 628 | pde_put(root); |
| 629 | return 0; |
| 630 | } |
| 631 | EXPORT_SYMBOL(remove_proc_subtree); |
David Howells | 4a520d2 | 2013-04-12 14:06:01 +0100 | [diff] [blame] | 632 | |
| 633 | void *proc_get_parent_data(const struct inode *inode) |
| 634 | { |
| 635 | struct proc_dir_entry *de = PDE(inode); |
| 636 | return de->parent->data; |
| 637 | } |
| 638 | EXPORT_SYMBOL_GPL(proc_get_parent_data); |
David Howells | a8ca16e | 2013-04-12 17:27:28 +0100 | [diff] [blame] | 639 | |
| 640 | void proc_remove(struct proc_dir_entry *de) |
| 641 | { |
| 642 | if (de) |
| 643 | remove_proc_subtree(de->name, de->parent); |
| 644 | } |
| 645 | EXPORT_SYMBOL(proc_remove); |
David Howells | c30480b | 2013-04-12 18:03:36 +0100 | [diff] [blame] | 646 | |
| 647 | void *PDE_DATA(const struct inode *inode) |
| 648 | { |
| 649 | return __PDE_DATA(inode); |
| 650 | } |
| 651 | EXPORT_SYMBOL(PDE_DATA); |