generic.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  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. #include <linux/errno.h>
  11. #include <linux/time.h>
  12. #include <linux/proc_fs.h>
  13. #include <linux/stat.h>
  14. #include <linux/module.h>
  15. #include <linux/mount.h>
  16. #include <linux/smp_lock.h>
  17. #include <linux/init.h>
  18. #include <linux/idr.h>
  19. #include <linux/namei.h>
  20. #include <linux/bitops.h>
  21. #include <linux/spinlock.h>
  22. #include <asm/uaccess.h>
  23. #include "internal.h"
  24. static ssize_t proc_file_read(struct file *file, char __user *buf,
  25. size_t nbytes, loff_t *ppos);
  26. static ssize_t proc_file_write(struct file *file, const char __user *buffer,
  27. size_t count, loff_t *ppos);
  28. static loff_t proc_file_lseek(struct file *, loff_t, int);
  29. DEFINE_SPINLOCK(proc_subdir_lock);
  30. static int proc_match(int len, const char *name, struct proc_dir_entry *de)
  31. {
  32. if (de->namelen != len)
  33. return 0;
  34. return !memcmp(name, de->name, len);
  35. }
  36. static const struct file_operations proc_file_operations = {
  37. .llseek = proc_file_lseek,
  38. .read = proc_file_read,
  39. .write = proc_file_write,
  40. };
  41. /* buffer size is one page but our output routines use some slack for overruns */
  42. #define PROC_BLOCK_SIZE (PAGE_SIZE - 1024)
  43. static ssize_t
  44. proc_file_read(struct file *file, char __user *buf, size_t nbytes,
  45. loff_t *ppos)
  46. {
  47. struct inode * inode = file->f_path.dentry->d_inode;
  48. char *page;
  49. ssize_t retval=0;
  50. int eof=0;
  51. ssize_t n, count;
  52. char *start;
  53. struct proc_dir_entry * dp;
  54. unsigned long long pos;
  55. /*
  56. * Gaah, please just use "seq_file" instead. The legacy /proc
  57. * interfaces cut loff_t down to off_t for reads, and ignore
  58. * the offset entirely for writes..
  59. */
  60. pos = *ppos;
  61. if (pos > MAX_NON_LFS)
  62. return 0;
  63. if (nbytes > MAX_NON_LFS - pos)
  64. nbytes = MAX_NON_LFS - pos;
  65. dp = PDE(inode);
  66. if (!(page = (char*) __get_free_page(GFP_KERNEL)))
  67. return -ENOMEM;
  68. while ((nbytes > 0) && !eof) {
  69. count = min_t(size_t, PROC_BLOCK_SIZE, nbytes);
  70. start = NULL;
  71. if (dp->get_info) {
  72. /* Handle old net routines */
  73. n = dp->get_info(page, &start, *ppos, count);
  74. if (n < count)
  75. eof = 1;
  76. } else if (dp->read_proc) {
  77. /*
  78. * How to be a proc read function
  79. * ------------------------------
  80. * Prototype:
  81. * int f(char *buffer, char **start, off_t offset,
  82. * int count, int *peof, void *dat)
  83. *
  84. * Assume that the buffer is "count" bytes in size.
  85. *
  86. * If you know you have supplied all the data you
  87. * have, set *peof.
  88. *
  89. * You have three ways to return data:
  90. * 0) Leave *start = NULL. (This is the default.)
  91. * Put the data of the requested offset at that
  92. * offset within the buffer. Return the number (n)
  93. * of bytes there are from the beginning of the
  94. * buffer up to the last byte of data. If the
  95. * number of supplied bytes (= n - offset) is
  96. * greater than zero and you didn't signal eof
  97. * and the reader is prepared to take more data
  98. * you will be called again with the requested
  99. * offset advanced by the number of bytes
  100. * absorbed. This interface is useful for files
  101. * no larger than the buffer.
  102. * 1) Set *start = an unsigned long value less than
  103. * the buffer address but greater than zero.
  104. * Put the data of the requested offset at the
  105. * beginning of the buffer. Return the number of
  106. * bytes of data placed there. If this number is
  107. * greater than zero and you didn't signal eof
  108. * and the reader is prepared to take more data
  109. * you will be called again with the requested
  110. * offset advanced by *start. This interface is
  111. * useful when you have a large file consisting
  112. * of a series of blocks which you want to count
  113. * and return as wholes.
  114. * (Hack by Paul.Russell@rustcorp.com.au)
  115. * 2) Set *start = an address within the buffer.
  116. * Put the data of the requested offset at *start.
  117. * Return the number of bytes of data placed there.
  118. * If this number is greater than zero and you
  119. * didn't signal eof and the reader is prepared to
  120. * take more data you will be called again with the
  121. * requested offset advanced by the number of bytes
  122. * absorbed.
  123. */
  124. n = dp->read_proc(page, &start, *ppos,
  125. count, &eof, dp->data);
  126. } else
  127. break;
  128. if (n == 0) /* end of file */
  129. break;
  130. if (n < 0) { /* error */
  131. if (retval == 0)
  132. retval = n;
  133. break;
  134. }
  135. if (start == NULL) {
  136. if (n > PAGE_SIZE) {
  137. printk(KERN_ERR
  138. "proc_file_read: Apparent buffer overflow!\n");
  139. n = PAGE_SIZE;
  140. }
  141. n -= *ppos;
  142. if (n <= 0)
  143. break;
  144. if (n > count)
  145. n = count;
  146. start = page + *ppos;
  147. } else if (start < page) {
  148. if (n > PAGE_SIZE) {
  149. printk(KERN_ERR
  150. "proc_file_read: Apparent buffer overflow!\n");
  151. n = PAGE_SIZE;
  152. }
  153. if (n > count) {
  154. /*
  155. * Don't reduce n because doing so might
  156. * cut off part of a data block.
  157. */
  158. printk(KERN_WARNING
  159. "proc_file_read: Read count exceeded\n");
  160. }
  161. } else /* start >= page */ {
  162. unsigned long startoff = (unsigned long)(start - page);
  163. if (n > (PAGE_SIZE - startoff)) {
  164. printk(KERN_ERR
  165. "proc_file_read: Apparent buffer overflow!\n");
  166. n = PAGE_SIZE - startoff;
  167. }
  168. if (n > count)
  169. n = count;
  170. }
  171. n -= copy_to_user(buf, start < page ? page : start, n);
  172. if (n == 0) {
  173. if (retval == 0)
  174. retval = -EFAULT;
  175. break;
  176. }
  177. *ppos += start < page ? (unsigned long)start : n;
  178. nbytes -= n;
  179. buf += n;
  180. retval += n;
  181. }
  182. free_page((unsigned long) page);
  183. return retval;
  184. }
  185. static ssize_t
  186. proc_file_write(struct file *file, const char __user *buffer,
  187. size_t count, loff_t *ppos)
  188. {
  189. struct inode *inode = file->f_path.dentry->d_inode;
  190. struct proc_dir_entry * dp;
  191. dp = PDE(inode);
  192. if (!dp->write_proc)
  193. return -EIO;
  194. /* FIXME: does this routine need ppos? probably... */
  195. return dp->write_proc(file, buffer, count, dp->data);
  196. }
  197. static loff_t
  198. proc_file_lseek(struct file *file, loff_t offset, int orig)
  199. {
  200. loff_t retval = -EINVAL;
  201. switch (orig) {
  202. case 1:
  203. offset += file->f_pos;
  204. /* fallthrough */
  205. case 0:
  206. if (offset < 0 || offset > MAX_NON_LFS)
  207. break;
  208. file->f_pos = retval = offset;
  209. }
  210. return retval;
  211. }
  212. static int proc_notify_change(struct dentry *dentry, struct iattr *iattr)
  213. {
  214. struct inode *inode = dentry->d_inode;
  215. struct proc_dir_entry *de = PDE(inode);
  216. int error;
  217. error = inode_change_ok(inode, iattr);
  218. if (error)
  219. goto out;
  220. error = inode_setattr(inode, iattr);
  221. if (error)
  222. goto out;
  223. de->uid = inode->i_uid;
  224. de->gid = inode->i_gid;
  225. de->mode = inode->i_mode;
  226. out:
  227. return error;
  228. }
  229. static int proc_getattr(struct vfsmount *mnt, struct dentry *dentry,
  230. struct kstat *stat)
  231. {
  232. struct inode *inode = dentry->d_inode;
  233. struct proc_dir_entry *de = PROC_I(inode)->pde;
  234. if (de && de->nlink)
  235. inode->i_nlink = de->nlink;
  236. generic_fillattr(inode, stat);
  237. return 0;
  238. }
  239. static const struct inode_operations proc_file_inode_operations = {
  240. .setattr = proc_notify_change,
  241. };
  242. /*
  243. * This function parses a name such as "tty/driver/serial", and
  244. * returns the struct proc_dir_entry for "/proc/tty/driver", and
  245. * returns "serial" in residual.
  246. */
  247. static int xlate_proc_name(const char *name,
  248. struct proc_dir_entry **ret, const char **residual)
  249. {
  250. const char *cp = name, *next;
  251. struct proc_dir_entry *de;
  252. int len;
  253. int rtn = 0;
  254. spin_lock(&proc_subdir_lock);
  255. de = &proc_root;
  256. while (1) {
  257. next = strchr(cp, '/');
  258. if (!next)
  259. break;
  260. len = next - cp;
  261. for (de = de->subdir; de ; de = de->next) {
  262. if (proc_match(len, cp, de))
  263. break;
  264. }
  265. if (!de) {
  266. rtn = -ENOENT;
  267. goto out;
  268. }
  269. cp += len + 1;
  270. }
  271. *residual = cp;
  272. *ret = de;
  273. out:
  274. spin_unlock(&proc_subdir_lock);
  275. return rtn;
  276. }
  277. static DEFINE_IDR(proc_inum_idr);
  278. static DEFINE_SPINLOCK(proc_inum_lock); /* protects the above */
  279. #define PROC_DYNAMIC_FIRST 0xF0000000UL
  280. /*
  281. * Return an inode number between PROC_DYNAMIC_FIRST and
  282. * 0xffffffff, or zero on failure.
  283. */
  284. static unsigned int get_inode_number(void)
  285. {
  286. int i, inum = 0;
  287. int error;
  288. retry:
  289. if (idr_pre_get(&proc_inum_idr, GFP_KERNEL) == 0)
  290. return 0;
  291. spin_lock(&proc_inum_lock);
  292. error = idr_get_new(&proc_inum_idr, NULL, &i);
  293. spin_unlock(&proc_inum_lock);
  294. if (error == -EAGAIN)
  295. goto retry;
  296. else if (error)
  297. return 0;
  298. inum = (i & MAX_ID_MASK) + PROC_DYNAMIC_FIRST;
  299. /* inum will never be more than 0xf0ffffff, so no check
  300. * for overflow.
  301. */
  302. return inum;
  303. }
  304. static void release_inode_number(unsigned int inum)
  305. {
  306. int id = (inum - PROC_DYNAMIC_FIRST) | ~MAX_ID_MASK;
  307. spin_lock(&proc_inum_lock);
  308. idr_remove(&proc_inum_idr, id);
  309. spin_unlock(&proc_inum_lock);
  310. }
  311. static void *proc_follow_link(struct dentry *dentry, struct nameidata *nd)
  312. {
  313. nd_set_link(nd, PDE(dentry->d_inode)->data);
  314. return NULL;
  315. }
  316. static const struct inode_operations proc_link_inode_operations = {
  317. .readlink = generic_readlink,
  318. .follow_link = proc_follow_link,
  319. };
  320. /*
  321. * As some entries in /proc are volatile, we want to
  322. * get rid of unused dentries. This could be made
  323. * smarter: we could keep a "volatile" flag in the
  324. * inode to indicate which ones to keep.
  325. */
  326. static int proc_delete_dentry(struct dentry * dentry)
  327. {
  328. return 1;
  329. }
  330. static struct dentry_operations proc_dentry_operations =
  331. {
  332. .d_delete = proc_delete_dentry,
  333. };
  334. /*
  335. * Don't create negative dentries here, return -ENOENT by hand
  336. * instead.
  337. */
  338. struct dentry *proc_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
  339. {
  340. struct inode *inode = NULL;
  341. struct proc_dir_entry * de;
  342. int error = -ENOENT;
  343. lock_kernel();
  344. spin_lock(&proc_subdir_lock);
  345. de = PDE(dir);
  346. if (de) {
  347. for (de = de->subdir; de ; de = de->next) {
  348. if (de->namelen != dentry->d_name.len)
  349. continue;
  350. if (!memcmp(dentry->d_name.name, de->name, de->namelen)) {
  351. unsigned int ino = de->low_ino;
  352. spin_unlock(&proc_subdir_lock);
  353. error = -EINVAL;
  354. inode = proc_get_inode(dir->i_sb, ino, de);
  355. spin_lock(&proc_subdir_lock);
  356. break;
  357. }
  358. }
  359. }
  360. spin_unlock(&proc_subdir_lock);
  361. unlock_kernel();
  362. if (inode) {
  363. dentry->d_op = &proc_dentry_operations;
  364. d_add(dentry, inode);
  365. return NULL;
  366. }
  367. return ERR_PTR(error);
  368. }
  369. /*
  370. * This returns non-zero if at EOF, so that the /proc
  371. * root directory can use this and check if it should
  372. * continue with the <pid> entries..
  373. *
  374. * Note that the VFS-layer doesn't care about the return
  375. * value of the readdir() call, as long as it's non-negative
  376. * for success..
  377. */
  378. int proc_readdir(struct file * filp,
  379. void * dirent, filldir_t filldir)
  380. {
  381. struct proc_dir_entry * de;
  382. unsigned int ino;
  383. int i;
  384. struct inode *inode = filp->f_path.dentry->d_inode;
  385. int ret = 0;
  386. lock_kernel();
  387. ino = inode->i_ino;
  388. de = PDE(inode);
  389. if (!de) {
  390. ret = -EINVAL;
  391. goto out;
  392. }
  393. i = filp->f_pos;
  394. switch (i) {
  395. case 0:
  396. if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0)
  397. goto out;
  398. i++;
  399. filp->f_pos++;
  400. /* fall through */
  401. case 1:
  402. if (filldir(dirent, "..", 2, i,
  403. parent_ino(filp->f_path.dentry),
  404. DT_DIR) < 0)
  405. goto out;
  406. i++;
  407. filp->f_pos++;
  408. /* fall through */
  409. default:
  410. spin_lock(&proc_subdir_lock);
  411. de = de->subdir;
  412. i -= 2;
  413. for (;;) {
  414. if (!de) {
  415. ret = 1;
  416. spin_unlock(&proc_subdir_lock);
  417. goto out;
  418. }
  419. if (!i)
  420. break;
  421. de = de->next;
  422. i--;
  423. }
  424. do {
  425. /* filldir passes info to user space */
  426. spin_unlock(&proc_subdir_lock);
  427. if (filldir(dirent, de->name, de->namelen, filp->f_pos,
  428. de->low_ino, de->mode >> 12) < 0)
  429. goto out;
  430. spin_lock(&proc_subdir_lock);
  431. filp->f_pos++;
  432. de = de->next;
  433. } while (de);
  434. spin_unlock(&proc_subdir_lock);
  435. }
  436. ret = 1;
  437. out: unlock_kernel();
  438. return ret;
  439. }
  440. /*
  441. * These are the generic /proc directory operations. They
  442. * use the in-memory "struct proc_dir_entry" tree to parse
  443. * the /proc directory.
  444. */
  445. static const struct file_operations proc_dir_operations = {
  446. .read = generic_read_dir,
  447. .readdir = proc_readdir,
  448. };
  449. /*
  450. * proc directories can do almost nothing..
  451. */
  452. static const struct inode_operations proc_dir_inode_operations = {
  453. .lookup = proc_lookup,
  454. .getattr = proc_getattr,
  455. .setattr = proc_notify_change,
  456. };
  457. static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
  458. {
  459. unsigned int i;
  460. i = get_inode_number();
  461. if (i == 0)
  462. return -EAGAIN;
  463. dp->low_ino = i;
  464. spin_lock(&proc_subdir_lock);
  465. dp->next = dir->subdir;
  466. dp->parent = dir;
  467. dir->subdir = dp;
  468. spin_unlock(&proc_subdir_lock);
  469. if (S_ISDIR(dp->mode)) {
  470. if (dp->proc_iops == NULL) {
  471. dp->proc_fops = &proc_dir_operations;
  472. dp->proc_iops = &proc_dir_inode_operations;
  473. }
  474. dir->nlink++;
  475. } else if (S_ISLNK(dp->mode)) {
  476. if (dp->proc_iops == NULL)
  477. dp->proc_iops = &proc_link_inode_operations;
  478. } else if (S_ISREG(dp->mode)) {
  479. if (dp->proc_fops == NULL)
  480. dp->proc_fops = &proc_file_operations;
  481. if (dp->proc_iops == NULL)
  482. dp->proc_iops = &proc_file_inode_operations;
  483. }
  484. return 0;
  485. }
  486. /*
  487. * Kill an inode that got unregistered..
  488. */
  489. static void proc_kill_inodes(struct proc_dir_entry *de)
  490. {
  491. struct list_head *p;
  492. struct super_block *sb = proc_mnt->mnt_sb;
  493. /*
  494. * Actually it's a partial revoke().
  495. */
  496. file_list_lock();
  497. list_for_each(p, &sb->s_files) {
  498. struct file * filp = list_entry(p, struct file, f_u.fu_list);
  499. struct dentry * dentry = filp->f_path.dentry;
  500. struct inode * inode;
  501. const struct file_operations *fops;
  502. if (dentry->d_op != &proc_dentry_operations)
  503. continue;
  504. inode = dentry->d_inode;
  505. if (PDE(inode) != de)
  506. continue;
  507. fops = filp->f_op;
  508. filp->f_op = NULL;
  509. fops_put(fops);
  510. }
  511. file_list_unlock();
  512. }
  513. static struct proc_dir_entry *proc_create(struct proc_dir_entry **parent,
  514. const char *name,
  515. mode_t mode,
  516. nlink_t nlink)
  517. {
  518. struct proc_dir_entry *ent = NULL;
  519. const char *fn = name;
  520. int len;
  521. /* make sure name is valid */
  522. if (!name || !strlen(name)) goto out;
  523. if (!(*parent) && xlate_proc_name(name, parent, &fn) != 0)
  524. goto out;
  525. /* At this point there must not be any '/' characters beyond *fn */
  526. if (strchr(fn, '/'))
  527. goto out;
  528. len = strlen(fn);
  529. ent = kmalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL);
  530. if (!ent) goto out;
  531. memset(ent, 0, sizeof(struct proc_dir_entry));
  532. memcpy(((char *) ent) + sizeof(struct proc_dir_entry), fn, len + 1);
  533. ent->name = ((char *) ent) + sizeof(*ent);
  534. ent->namelen = len;
  535. ent->mode = mode;
  536. ent->nlink = nlink;
  537. out:
  538. return ent;
  539. }
  540. struct proc_dir_entry *proc_symlink(const char *name,
  541. struct proc_dir_entry *parent, const char *dest)
  542. {
  543. struct proc_dir_entry *ent;
  544. ent = proc_create(&parent,name,
  545. (S_IFLNK | S_IRUGO | S_IWUGO | S_IXUGO),1);
  546. if (ent) {
  547. ent->data = kmalloc((ent->size=strlen(dest))+1, GFP_KERNEL);
  548. if (ent->data) {
  549. strcpy((char*)ent->data,dest);
  550. if (proc_register(parent, ent) < 0) {
  551. kfree(ent->data);
  552. kfree(ent);
  553. ent = NULL;
  554. }
  555. } else {
  556. kfree(ent);
  557. ent = NULL;
  558. }
  559. }
  560. return ent;
  561. }
  562. struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
  563. struct proc_dir_entry *parent)
  564. {
  565. struct proc_dir_entry *ent;
  566. ent = proc_create(&parent, name, S_IFDIR | mode, 2);
  567. if (ent) {
  568. ent->proc_fops = &proc_dir_operations;
  569. ent->proc_iops = &proc_dir_inode_operations;
  570. if (proc_register(parent, ent) < 0) {
  571. kfree(ent);
  572. ent = NULL;
  573. }
  574. }
  575. return ent;
  576. }
  577. struct proc_dir_entry *proc_mkdir(const char *name,
  578. struct proc_dir_entry *parent)
  579. {
  580. return proc_mkdir_mode(name, S_IRUGO | S_IXUGO, parent);
  581. }
  582. struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
  583. struct proc_dir_entry *parent)
  584. {
  585. struct proc_dir_entry *ent;
  586. nlink_t nlink;
  587. if (S_ISDIR(mode)) {
  588. if ((mode & S_IALLUGO) == 0)
  589. mode |= S_IRUGO | S_IXUGO;
  590. nlink = 2;
  591. } else {
  592. if ((mode & S_IFMT) == 0)
  593. mode |= S_IFREG;
  594. if ((mode & S_IALLUGO) == 0)
  595. mode |= S_IRUGO;
  596. nlink = 1;
  597. }
  598. ent = proc_create(&parent,name,mode,nlink);
  599. if (ent) {
  600. if (S_ISDIR(mode)) {
  601. ent->proc_fops = &proc_dir_operations;
  602. ent->proc_iops = &proc_dir_inode_operations;
  603. }
  604. if (proc_register(parent, ent) < 0) {
  605. kfree(ent);
  606. ent = NULL;
  607. }
  608. }
  609. return ent;
  610. }
  611. void free_proc_entry(struct proc_dir_entry *de)
  612. {
  613. unsigned int ino = de->low_ino;
  614. if (ino < PROC_DYNAMIC_FIRST)
  615. return;
  616. release_inode_number(ino);
  617. if (S_ISLNK(de->mode) && de->data)
  618. kfree(de->data);
  619. kfree(de);
  620. }
  621. /*
  622. * Remove a /proc entry and free it if it's not currently in use.
  623. * If it is in use, we set the 'deleted' flag.
  624. */
  625. void remove_proc_entry(const char *name, struct proc_dir_entry *parent)
  626. {
  627. struct proc_dir_entry **p;
  628. struct proc_dir_entry *de;
  629. const char *fn = name;
  630. int len;
  631. if (!parent && xlate_proc_name(name, &parent, &fn) != 0)
  632. goto out;
  633. len = strlen(fn);
  634. spin_lock(&proc_subdir_lock);
  635. for (p = &parent->subdir; *p; p=&(*p)->next ) {
  636. if (!proc_match(len, fn, *p))
  637. continue;
  638. de = *p;
  639. *p = de->next;
  640. de->next = NULL;
  641. if (S_ISDIR(de->mode))
  642. parent->nlink--;
  643. proc_kill_inodes(de);
  644. de->nlink = 0;
  645. WARN_ON(de->subdir);
  646. if (!atomic_read(&de->count))
  647. free_proc_entry(de);
  648. else {
  649. de->deleted = 1;
  650. printk("remove_proc_entry: %s/%s busy, count=%d\n",
  651. parent->name, de->name, atomic_read(&de->count));
  652. }
  653. break;
  654. }
  655. spin_unlock(&proc_subdir_lock);
  656. out:
  657. return;
  658. }