Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * linux/fs/proc/inode.c |
| 3 | * |
| 4 | * Copyright (C) 1991, 1992 Linus Torvalds |
| 5 | */ |
| 6 | |
| 7 | #include <linux/time.h> |
| 8 | #include <linux/proc_fs.h> |
| 9 | #include <linux/kernel.h> |
| 10 | #include <linux/mm.h> |
| 11 | #include <linux/string.h> |
| 12 | #include <linux/stat.h> |
Alexey Dobriyan | 786d7e1 | 2007-07-15 23:39:00 -0700 | [diff] [blame] | 13 | #include <linux/completion.h> |
Alexey Dobriyan | dd23aae | 2007-09-11 15:23:55 -0700 | [diff] [blame] | 14 | #include <linux/poll.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | #include <linux/file.h> |
| 16 | #include <linux/limits.h> |
| 17 | #include <linux/init.h> |
| 18 | #include <linux/module.h> |
| 19 | #include <linux/smp_lock.h> |
| 20 | |
| 21 | #include <asm/system.h> |
| 22 | #include <asm/uaccess.h> |
| 23 | |
Adrian Bunk | fee781e | 2006-01-08 01:04:16 -0800 | [diff] [blame] | 24 | #include "internal.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 25 | |
Alexey Dobriyan | 7695650 | 2007-05-08 00:25:45 -0700 | [diff] [blame] | 26 | struct proc_dir_entry *de_get(struct proc_dir_entry *de) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | { |
Alexey Dobriyan | 5e971dc | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 28 | atomic_inc(&de->count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | return de; |
| 30 | } |
| 31 | |
| 32 | /* |
| 33 | * Decrements the use count and checks for deferred deletion. |
| 34 | */ |
Alexey Dobriyan | 7695650 | 2007-05-08 00:25:45 -0700 | [diff] [blame] | 35 | void de_put(struct proc_dir_entry *de) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | { |
Alexey Dobriyan | 5e971dc | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 37 | lock_kernel(); |
| 38 | if (!atomic_read(&de->count)) { |
| 39 | printk("de_put: entry %s already free!\n", de->name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | unlock_kernel(); |
Alexey Dobriyan | 5e971dc | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 41 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | } |
Alexey Dobriyan | 5e971dc | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 43 | |
| 44 | if (atomic_dec_and_test(&de->count)) |
| 45 | free_proc_entry(de); |
| 46 | unlock_kernel(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | /* |
| 50 | * Decrement the use count of the proc_dir_entry. |
| 51 | */ |
| 52 | static void proc_delete_inode(struct inode *inode) |
| 53 | { |
| 54 | struct proc_dir_entry *de; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Mark Fasheh | fef2665 | 2005-09-09 13:01:31 -0700 | [diff] [blame] | 56 | truncate_inode_pages(&inode->i_data, 0); |
| 57 | |
Eric W. Biederman | 99f8955 | 2006-06-26 00:25:55 -0700 | [diff] [blame] | 58 | /* Stop tracking associated processes */ |
Eric W. Biederman | 13b41b0 | 2006-06-26 00:25:56 -0700 | [diff] [blame] | 59 | put_pid(PROC_I(inode)->pid); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | |
| 61 | /* Let go of any associated proc directory entry */ |
| 62 | de = PROC_I(inode)->pde; |
| 63 | if (de) { |
| 64 | if (de->owner) |
| 65 | module_put(de->owner); |
| 66 | de_put(de); |
| 67 | } |
| 68 | clear_inode(inode); |
| 69 | } |
| 70 | |
| 71 | struct vfsmount *proc_mnt; |
| 72 | |
Christoph Lameter | e18b890 | 2006-12-06 20:33:20 -0800 | [diff] [blame] | 73 | static struct kmem_cache * proc_inode_cachep; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 74 | |
| 75 | static struct inode *proc_alloc_inode(struct super_block *sb) |
| 76 | { |
| 77 | struct proc_inode *ei; |
| 78 | struct inode *inode; |
| 79 | |
Christoph Lameter | e94b176 | 2006-12-06 20:33:17 -0800 | [diff] [blame] | 80 | ei = (struct proc_inode *)kmem_cache_alloc(proc_inode_cachep, GFP_KERNEL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | if (!ei) |
| 82 | return NULL; |
Eric W. Biederman | 13b41b0 | 2006-06-26 00:25:56 -0700 | [diff] [blame] | 83 | ei->pid = NULL; |
Eric W. Biederman | aed7a6c | 2006-06-26 00:25:44 -0700 | [diff] [blame] | 84 | ei->fd = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | ei->op.proc_get_link = NULL; |
| 86 | ei->pde = NULL; |
| 87 | inode = &ei->vfs_inode; |
| 88 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; |
| 89 | return inode; |
| 90 | } |
| 91 | |
| 92 | static void proc_destroy_inode(struct inode *inode) |
| 93 | { |
| 94 | kmem_cache_free(proc_inode_cachep, PROC_I(inode)); |
| 95 | } |
| 96 | |
Christoph Lameter | 4ba9b9d | 2007-10-16 23:25:51 -0700 | [diff] [blame] | 97 | static void init_once(struct kmem_cache * cachep, void *foo) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
| 99 | struct proc_inode *ei = (struct proc_inode *) foo; |
| 100 | |
Christoph Lameter | a35afb8 | 2007-05-16 22:10:57 -0700 | [diff] [blame] | 101 | inode_init_once(&ei->vfs_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | } |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 103 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | int __init proc_init_inodecache(void) |
| 105 | { |
| 106 | proc_inode_cachep = kmem_cache_create("proc_inode_cache", |
| 107 | sizeof(struct proc_inode), |
Paul Jackson | fffb60f | 2006-03-24 03:16:06 -0800 | [diff] [blame] | 108 | 0, (SLAB_RECLAIM_ACCOUNT| |
Alexey Dobriyan | 040b5c6 | 2007-10-16 23:26:10 -0700 | [diff] [blame] | 109 | SLAB_MEM_SPREAD|SLAB_PANIC), |
Paul Mundt | 20c2df8 | 2007-07-20 10:11:58 +0900 | [diff] [blame] | 110 | init_once); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | return 0; |
| 112 | } |
| 113 | |
| 114 | static int proc_remount(struct super_block *sb, int *flags, char *data) |
| 115 | { |
| 116 | *flags |= MS_NODIRATIME; |
| 117 | return 0; |
| 118 | } |
| 119 | |
Josef 'Jeff' Sipek | ee9b6d6 | 2007-02-12 00:55:41 -0800 | [diff] [blame] | 120 | static const struct super_operations proc_sops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | .alloc_inode = proc_alloc_inode, |
| 122 | .destroy_inode = proc_destroy_inode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 123 | .drop_inode = generic_delete_inode, |
| 124 | .delete_inode = proc_delete_inode, |
| 125 | .statfs = simple_statfs, |
| 126 | .remount_fs = proc_remount, |
| 127 | }; |
| 128 | |
Alexey Dobriyan | 786d7e1 | 2007-07-15 23:39:00 -0700 | [diff] [blame] | 129 | static void pde_users_dec(struct proc_dir_entry *pde) |
| 130 | { |
| 131 | spin_lock(&pde->pde_unload_lock); |
| 132 | pde->pde_users--; |
| 133 | if (pde->pde_unload_completion && pde->pde_users == 0) |
| 134 | complete(pde->pde_unload_completion); |
| 135 | spin_unlock(&pde->pde_unload_lock); |
| 136 | } |
| 137 | |
| 138 | static loff_t proc_reg_llseek(struct file *file, loff_t offset, int whence) |
| 139 | { |
| 140 | struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode); |
| 141 | loff_t rv = -EINVAL; |
| 142 | loff_t (*llseek)(struct file *, loff_t, int); |
| 143 | |
| 144 | spin_lock(&pde->pde_unload_lock); |
| 145 | /* |
| 146 | * remove_proc_entry() is going to delete PDE (as part of module |
| 147 | * cleanup sequence). No new callers into module allowed. |
| 148 | */ |
| 149 | if (!pde->proc_fops) { |
| 150 | spin_unlock(&pde->pde_unload_lock); |
| 151 | return rv; |
| 152 | } |
| 153 | /* |
| 154 | * Bump refcount so that remove_proc_entry will wail for ->llseek to |
| 155 | * complete. |
| 156 | */ |
| 157 | pde->pde_users++; |
| 158 | /* |
| 159 | * Save function pointer under lock, to protect against ->proc_fops |
| 160 | * NULL'ifying right after ->pde_unload_lock is dropped. |
| 161 | */ |
| 162 | llseek = pde->proc_fops->llseek; |
| 163 | spin_unlock(&pde->pde_unload_lock); |
| 164 | |
| 165 | if (!llseek) |
| 166 | llseek = default_llseek; |
| 167 | rv = llseek(file, offset, whence); |
| 168 | |
| 169 | pde_users_dec(pde); |
| 170 | return rv; |
| 171 | } |
| 172 | |
| 173 | static ssize_t proc_reg_read(struct file *file, char __user *buf, size_t count, loff_t *ppos) |
| 174 | { |
| 175 | struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode); |
| 176 | ssize_t rv = -EIO; |
| 177 | ssize_t (*read)(struct file *, char __user *, size_t, loff_t *); |
| 178 | |
| 179 | spin_lock(&pde->pde_unload_lock); |
| 180 | if (!pde->proc_fops) { |
| 181 | spin_unlock(&pde->pde_unload_lock); |
| 182 | return rv; |
| 183 | } |
| 184 | pde->pde_users++; |
| 185 | read = pde->proc_fops->read; |
| 186 | spin_unlock(&pde->pde_unload_lock); |
| 187 | |
| 188 | if (read) |
| 189 | rv = read(file, buf, count, ppos); |
| 190 | |
| 191 | pde_users_dec(pde); |
| 192 | return rv; |
| 193 | } |
| 194 | |
| 195 | static ssize_t proc_reg_write(struct file *file, const char __user *buf, size_t count, loff_t *ppos) |
| 196 | { |
| 197 | struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode); |
| 198 | ssize_t rv = -EIO; |
| 199 | ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *); |
| 200 | |
| 201 | spin_lock(&pde->pde_unload_lock); |
| 202 | if (!pde->proc_fops) { |
| 203 | spin_unlock(&pde->pde_unload_lock); |
| 204 | return rv; |
| 205 | } |
| 206 | pde->pde_users++; |
| 207 | write = pde->proc_fops->write; |
| 208 | spin_unlock(&pde->pde_unload_lock); |
| 209 | |
| 210 | if (write) |
| 211 | rv = write(file, buf, count, ppos); |
| 212 | |
| 213 | pde_users_dec(pde); |
| 214 | return rv; |
| 215 | } |
| 216 | |
| 217 | static unsigned int proc_reg_poll(struct file *file, struct poll_table_struct *pts) |
| 218 | { |
| 219 | struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode); |
Alexey Dobriyan | dd23aae | 2007-09-11 15:23:55 -0700 | [diff] [blame] | 220 | unsigned int rv = DEFAULT_POLLMASK; |
Alexey Dobriyan | 786d7e1 | 2007-07-15 23:39:00 -0700 | [diff] [blame] | 221 | unsigned int (*poll)(struct file *, struct poll_table_struct *); |
| 222 | |
| 223 | spin_lock(&pde->pde_unload_lock); |
| 224 | if (!pde->proc_fops) { |
| 225 | spin_unlock(&pde->pde_unload_lock); |
| 226 | return rv; |
| 227 | } |
| 228 | pde->pde_users++; |
| 229 | poll = pde->proc_fops->poll; |
| 230 | spin_unlock(&pde->pde_unload_lock); |
| 231 | |
| 232 | if (poll) |
| 233 | rv = poll(file, pts); |
| 234 | |
| 235 | pde_users_dec(pde); |
| 236 | return rv; |
| 237 | } |
| 238 | |
| 239 | static long proc_reg_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 240 | { |
| 241 | struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode); |
| 242 | long rv = -ENOTTY; |
| 243 | long (*unlocked_ioctl)(struct file *, unsigned int, unsigned long); |
| 244 | int (*ioctl)(struct inode *, struct file *, unsigned int, unsigned long); |
| 245 | |
| 246 | spin_lock(&pde->pde_unload_lock); |
| 247 | if (!pde->proc_fops) { |
| 248 | spin_unlock(&pde->pde_unload_lock); |
| 249 | return rv; |
| 250 | } |
| 251 | pde->pde_users++; |
| 252 | unlocked_ioctl = pde->proc_fops->unlocked_ioctl; |
| 253 | ioctl = pde->proc_fops->ioctl; |
| 254 | spin_unlock(&pde->pde_unload_lock); |
| 255 | |
| 256 | if (unlocked_ioctl) { |
| 257 | rv = unlocked_ioctl(file, cmd, arg); |
| 258 | if (rv == -ENOIOCTLCMD) |
| 259 | rv = -EINVAL; |
| 260 | } else if (ioctl) { |
| 261 | lock_kernel(); |
| 262 | rv = ioctl(file->f_path.dentry->d_inode, file, cmd, arg); |
| 263 | unlock_kernel(); |
| 264 | } |
| 265 | |
| 266 | pde_users_dec(pde); |
| 267 | return rv; |
| 268 | } |
| 269 | |
| 270 | #ifdef CONFIG_COMPAT |
| 271 | static long proc_reg_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) |
| 272 | { |
| 273 | struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode); |
| 274 | long rv = -ENOTTY; |
| 275 | long (*compat_ioctl)(struct file *, unsigned int, unsigned long); |
| 276 | |
| 277 | spin_lock(&pde->pde_unload_lock); |
| 278 | if (!pde->proc_fops) { |
| 279 | spin_unlock(&pde->pde_unload_lock); |
| 280 | return rv; |
| 281 | } |
| 282 | pde->pde_users++; |
| 283 | compat_ioctl = pde->proc_fops->compat_ioctl; |
| 284 | spin_unlock(&pde->pde_unload_lock); |
| 285 | |
| 286 | if (compat_ioctl) |
| 287 | rv = compat_ioctl(file, cmd, arg); |
| 288 | |
| 289 | pde_users_dec(pde); |
| 290 | return rv; |
| 291 | } |
| 292 | #endif |
| 293 | |
| 294 | static int proc_reg_mmap(struct file *file, struct vm_area_struct *vma) |
| 295 | { |
| 296 | struct proc_dir_entry *pde = PDE(file->f_path.dentry->d_inode); |
| 297 | int rv = -EIO; |
| 298 | int (*mmap)(struct file *, struct vm_area_struct *); |
| 299 | |
| 300 | spin_lock(&pde->pde_unload_lock); |
| 301 | if (!pde->proc_fops) { |
| 302 | spin_unlock(&pde->pde_unload_lock); |
| 303 | return rv; |
| 304 | } |
| 305 | pde->pde_users++; |
| 306 | mmap = pde->proc_fops->mmap; |
| 307 | spin_unlock(&pde->pde_unload_lock); |
| 308 | |
| 309 | if (mmap) |
| 310 | rv = mmap(file, vma); |
| 311 | |
| 312 | pde_users_dec(pde); |
| 313 | return rv; |
| 314 | } |
| 315 | |
| 316 | static int proc_reg_open(struct inode *inode, struct file *file) |
| 317 | { |
| 318 | struct proc_dir_entry *pde = PDE(inode); |
| 319 | int rv = 0; |
| 320 | int (*open)(struct inode *, struct file *); |
| 321 | |
| 322 | spin_lock(&pde->pde_unload_lock); |
| 323 | if (!pde->proc_fops) { |
| 324 | spin_unlock(&pde->pde_unload_lock); |
| 325 | return rv; |
| 326 | } |
| 327 | pde->pde_users++; |
| 328 | open = pde->proc_fops->open; |
| 329 | spin_unlock(&pde->pde_unload_lock); |
| 330 | |
| 331 | if (open) |
| 332 | rv = open(inode, file); |
| 333 | |
| 334 | pde_users_dec(pde); |
| 335 | return rv; |
| 336 | } |
| 337 | |
| 338 | static int proc_reg_release(struct inode *inode, struct file *file) |
| 339 | { |
| 340 | struct proc_dir_entry *pde = PDE(inode); |
| 341 | int rv = 0; |
| 342 | int (*release)(struct inode *, struct file *); |
| 343 | |
| 344 | spin_lock(&pde->pde_unload_lock); |
| 345 | if (!pde->proc_fops) { |
| 346 | spin_unlock(&pde->pde_unload_lock); |
| 347 | return rv; |
| 348 | } |
| 349 | pde->pde_users++; |
| 350 | release = pde->proc_fops->release; |
| 351 | spin_unlock(&pde->pde_unload_lock); |
| 352 | |
| 353 | if (release) |
| 354 | rv = release(inode, file); |
| 355 | |
| 356 | pde_users_dec(pde); |
| 357 | return rv; |
| 358 | } |
| 359 | |
| 360 | static const struct file_operations proc_reg_file_ops = { |
| 361 | .llseek = proc_reg_llseek, |
| 362 | .read = proc_reg_read, |
| 363 | .write = proc_reg_write, |
| 364 | .poll = proc_reg_poll, |
| 365 | .unlocked_ioctl = proc_reg_unlocked_ioctl, |
| 366 | #ifdef CONFIG_COMPAT |
| 367 | .compat_ioctl = proc_reg_compat_ioctl, |
| 368 | #endif |
| 369 | .mmap = proc_reg_mmap, |
| 370 | .open = proc_reg_open, |
| 371 | .release = proc_reg_release, |
| 372 | }; |
| 373 | |
David Miller | 778f3dd | 2007-07-27 22:58:37 -0700 | [diff] [blame] | 374 | #ifdef CONFIG_COMPAT |
| 375 | static const struct file_operations proc_reg_file_ops_no_compat = { |
| 376 | .llseek = proc_reg_llseek, |
| 377 | .read = proc_reg_read, |
| 378 | .write = proc_reg_write, |
| 379 | .poll = proc_reg_poll, |
| 380 | .unlocked_ioctl = proc_reg_unlocked_ioctl, |
| 381 | .mmap = proc_reg_mmap, |
| 382 | .open = proc_reg_open, |
| 383 | .release = proc_reg_release, |
| 384 | }; |
| 385 | #endif |
| 386 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | struct inode *proc_get_inode(struct super_block *sb, unsigned int ino, |
| 388 | struct proc_dir_entry *de) |
| 389 | { |
| 390 | struct inode * inode; |
| 391 | |
Alexey Dobriyan | 5e971dc | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 392 | if (!try_module_get(de->owner)) |
Kirill Korotaev | e954365 | 2005-10-30 15:02:26 -0800 | [diff] [blame] | 393 | goto out_mod; |
| 394 | |
David Howells | a1d4aeb | 2008-02-07 00:15:45 -0800 | [diff] [blame] | 395 | inode = iget_locked(sb, ino); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | if (!inode) |
Kirill Korotaev | e954365 | 2005-10-30 15:02:26 -0800 | [diff] [blame] | 397 | goto out_ino; |
David Howells | a1d4aeb | 2008-02-07 00:15:45 -0800 | [diff] [blame] | 398 | if (inode->i_state & I_NEW) { |
| 399 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; |
| 400 | PROC_I(inode)->fd = 0; |
| 401 | PROC_I(inode)->pde = de; |
Alexey Dobriyan | 5e971dc | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 402 | |
| 403 | if (de->mode) { |
| 404 | inode->i_mode = de->mode; |
| 405 | inode->i_uid = de->uid; |
| 406 | inode->i_gid = de->gid; |
| 407 | } |
| 408 | if (de->size) |
| 409 | inode->i_size = de->size; |
| 410 | if (de->nlink) |
| 411 | inode->i_nlink = de->nlink; |
| 412 | if (de->proc_iops) |
| 413 | inode->i_op = de->proc_iops; |
| 414 | if (de->proc_fops) { |
| 415 | if (S_ISREG(inode->i_mode)) { |
David Howells | a1d4aeb | 2008-02-07 00:15:45 -0800 | [diff] [blame] | 416 | #ifdef CONFIG_COMPAT |
Alexey Dobriyan | 5e971dc | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 417 | if (!de->proc_fops->compat_ioctl) |
| 418 | inode->i_fop = |
| 419 | &proc_reg_file_ops_no_compat; |
| 420 | else |
David Howells | a1d4aeb | 2008-02-07 00:15:45 -0800 | [diff] [blame] | 421 | #endif |
Alexey Dobriyan | 5e971dc | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 422 | inode->i_fop = &proc_reg_file_ops; |
| 423 | } else { |
| 424 | inode->i_fop = de->proc_fops; |
David Howells | a1d4aeb | 2008-02-07 00:15:45 -0800 | [diff] [blame] | 425 | } |
Alexey Dobriyan | 786d7e1 | 2007-07-15 23:39:00 -0700 | [diff] [blame] | 426 | } |
David Howells | a1d4aeb | 2008-02-07 00:15:45 -0800 | [diff] [blame] | 427 | unlock_new_inode(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | return inode; |
| 430 | |
Kirill Korotaev | e954365 | 2005-10-30 15:02:26 -0800 | [diff] [blame] | 431 | out_ino: |
Alexey Dobriyan | 5e971dc | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 432 | module_put(de->owner); |
Kirill Korotaev | e954365 | 2005-10-30 15:02:26 -0800 | [diff] [blame] | 433 | out_mod: |
Kirill Korotaev | e954365 | 2005-10-30 15:02:26 -0800 | [diff] [blame] | 434 | return NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | } |
| 436 | |
Pavel Emelyanov | 07543f5 | 2007-10-18 23:40:08 -0700 | [diff] [blame] | 437 | int proc_fill_super(struct super_block *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | { |
| 439 | struct inode * root_inode; |
| 440 | |
Linus Torvalds | 92d0328 | 2006-07-15 12:20:05 -0700 | [diff] [blame] | 441 | s->s_flags |= MS_NODIRATIME | MS_NOSUID | MS_NOEXEC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | s->s_blocksize = 1024; |
| 443 | s->s_blocksize_bits = 10; |
| 444 | s->s_magic = PROC_SUPER_MAGIC; |
| 445 | s->s_op = &proc_sops; |
| 446 | s->s_time_gran = 1; |
| 447 | |
Alexey Dobriyan | 7695650 | 2007-05-08 00:25:45 -0700 | [diff] [blame] | 448 | de_get(&proc_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | root_inode = proc_get_inode(s, PROC_ROOT_INO, &proc_root); |
| 450 | if (!root_inode) |
| 451 | goto out_no_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | root_inode->i_uid = 0; |
| 453 | root_inode->i_gid = 0; |
| 454 | s->s_root = d_alloc_root(root_inode); |
| 455 | if (!s->s_root) |
| 456 | goto out_no_root; |
| 457 | return 0; |
| 458 | |
| 459 | out_no_root: |
| 460 | printk("proc_read_super: get root inode failed\n"); |
| 461 | iput(root_inode); |
Alexey Dobriyan | 7695650 | 2007-05-08 00:25:45 -0700 | [diff] [blame] | 462 | de_put(&proc_root); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 463 | return -ENOMEM; |
| 464 | } |