generic.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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. de_get(de);
  353. spin_unlock(&proc_subdir_lock);
  354. error = -EINVAL;
  355. inode = proc_get_inode(dir->i_sb, ino, de);
  356. spin_lock(&proc_subdir_lock);
  357. break;
  358. }
  359. }
  360. }
  361. spin_unlock(&proc_subdir_lock);
  362. unlock_kernel();
  363. if (inode) {
  364. dentry->d_op = &proc_dentry_operations;
  365. d_add(dentry, inode);
  366. return NULL;
  367. }
  368. de_put(de);
  369. return ERR_PTR(error);
  370. }
  371. /*
  372. * This returns non-zero if at EOF, so that the /proc
  373. * root directory can use this and check if it should
  374. * continue with the <pid> entries..
  375. *
  376. * Note that the VFS-layer doesn't care about the return
  377. * value of the readdir() call, as long as it's non-negative
  378. * for success..
  379. */
  380. int proc_readdir(struct file * filp,
  381. void * dirent, filldir_t filldir)
  382. {
  383. struct proc_dir_entry * de;
  384. unsigned int ino;
  385. int i;
  386. struct inode *inode = filp->f_path.dentry->d_inode;
  387. int ret = 0;
  388. lock_kernel();
  389. ino = inode->i_ino;
  390. de = PDE(inode);
  391. if (!de) {
  392. ret = -EINVAL;
  393. goto out;
  394. }
  395. i = filp->f_pos;
  396. switch (i) {
  397. case 0:
  398. if (filldir(dirent, ".", 1, i, ino, DT_DIR) < 0)
  399. goto out;
  400. i++;
  401. filp->f_pos++;
  402. /* fall through */
  403. case 1:
  404. if (filldir(dirent, "..", 2, i,
  405. parent_ino(filp->f_path.dentry),
  406. DT_DIR) < 0)
  407. goto out;
  408. i++;
  409. filp->f_pos++;
  410. /* fall through */
  411. default:
  412. spin_lock(&proc_subdir_lock);
  413. de = de->subdir;
  414. i -= 2;
  415. for (;;) {
  416. if (!de) {
  417. ret = 1;
  418. spin_unlock(&proc_subdir_lock);
  419. goto out;
  420. }
  421. if (!i)
  422. break;
  423. de = de->next;
  424. i--;
  425. }
  426. do {
  427. /* filldir passes info to user space */
  428. spin_unlock(&proc_subdir_lock);
  429. if (filldir(dirent, de->name, de->namelen, filp->f_pos,
  430. de->low_ino, de->mode >> 12) < 0)
  431. goto out;
  432. spin_lock(&proc_subdir_lock);
  433. filp->f_pos++;
  434. de = de->next;
  435. } while (de);
  436. spin_unlock(&proc_subdir_lock);
  437. }
  438. ret = 1;
  439. out: unlock_kernel();
  440. return ret;
  441. }
  442. /*
  443. * These are the generic /proc directory operations. They
  444. * use the in-memory "struct proc_dir_entry" tree to parse
  445. * the /proc directory.
  446. */
  447. static const struct file_operations proc_dir_operations = {
  448. .read = generic_read_dir,
  449. .readdir = proc_readdir,
  450. };
  451. /*
  452. * proc directories can do almost nothing..
  453. */
  454. static const struct inode_operations proc_dir_inode_operations = {
  455. .lookup = proc_lookup,
  456. .getattr = proc_getattr,
  457. .setattr = proc_notify_change,
  458. };
  459. static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
  460. {
  461. unsigned int i;
  462. i = get_inode_number();
  463. if (i == 0)
  464. return -EAGAIN;
  465. dp->low_ino = i;
  466. spin_lock(&proc_subdir_lock);
  467. dp->next = dir->subdir;
  468. dp->parent = dir;
  469. dir->subdir = dp;
  470. spin_unlock(&proc_subdir_lock);
  471. if (S_ISDIR(dp->mode)) {
  472. if (dp->proc_iops == NULL) {
  473. dp->proc_fops = &proc_dir_operations;
  474. dp->proc_iops = &proc_dir_inode_operations;
  475. }
  476. dir->nlink++;
  477. } else if (S_ISLNK(dp->mode)) {
  478. if (dp->proc_iops == NULL)
  479. dp->proc_iops = &proc_link_inode_operations;
  480. } else if (S_ISREG(dp->mode)) {
  481. if (dp->proc_fops == NULL)
  482. dp->proc_fops = &proc_file_operations;
  483. if (dp->proc_iops == NULL)
  484. dp->proc_iops = &proc_file_inode_operations;
  485. }
  486. return 0;
  487. }
  488. /*
  489. * Kill an inode that got unregistered..
  490. */
  491. static void proc_kill_inodes(struct proc_dir_entry *de)
  492. {
  493. struct list_head *p;
  494. struct super_block *sb = proc_mnt->mnt_sb;
  495. /*
  496. * Actually it's a partial revoke().
  497. */
  498. file_list_lock();
  499. list_for_each(p, &sb->s_files) {
  500. struct file * filp = list_entry(p, struct file, f_u.fu_list);
  501. struct dentry * dentry = filp->f_path.dentry;
  502. struct inode * inode;
  503. const struct file_operations *fops;
  504. if (dentry->d_op != &proc_dentry_operations)
  505. continue;
  506. inode = dentry->d_inode;
  507. if (PDE(inode) != de)
  508. continue;
  509. fops = filp->f_op;
  510. filp->f_op = NULL;
  511. fops_put(fops);
  512. }
  513. file_list_unlock();
  514. }
  515. static struct proc_dir_entry *proc_create(struct proc_dir_entry **parent,
  516. const char *name,
  517. mode_t mode,
  518. nlink_t nlink)
  519. {
  520. struct proc_dir_entry *ent = NULL;
  521. const char *fn = name;
  522. int len;
  523. /* make sure name is valid */
  524. if (!name || !strlen(name)) goto out;
  525. if (!(*parent) && xlate_proc_name(name, parent, &fn) != 0)
  526. goto out;
  527. /* At this point there must not be any '/' characters beyond *fn */
  528. if (strchr(fn, '/'))
  529. goto out;
  530. len = strlen(fn);
  531. ent = kmalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL);
  532. if (!ent) goto out;
  533. memset(ent, 0, sizeof(struct proc_dir_entry));
  534. memcpy(((char *) ent) + sizeof(struct proc_dir_entry), fn, len + 1);
  535. ent->name = ((char *) ent) + sizeof(*ent);
  536. ent->namelen = len;
  537. ent->mode = mode;
  538. ent->nlink = nlink;
  539. out:
  540. return ent;
  541. }
  542. struct proc_dir_entry *proc_symlink(const char *name,
  543. struct proc_dir_entry *parent, const char *dest)
  544. {
  545. struct proc_dir_entry *ent;
  546. ent = proc_create(&parent,name,
  547. (S_IFLNK | S_IRUGO | S_IWUGO | S_IXUGO),1);
  548. if (ent) {
  549. ent->data = kmalloc((ent->size=strlen(dest))+1, GFP_KERNEL);
  550. if (ent->data) {
  551. strcpy((char*)ent->data,dest);
  552. if (proc_register(parent, ent) < 0) {
  553. kfree(ent->data);
  554. kfree(ent);
  555. ent = NULL;
  556. }
  557. } else {
  558. kfree(ent);
  559. ent = NULL;
  560. }
  561. }
  562. return ent;
  563. }
  564. struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
  565. struct proc_dir_entry *parent)
  566. {
  567. struct proc_dir_entry *ent;
  568. ent = proc_create(&parent, name, S_IFDIR | mode, 2);
  569. if (ent) {
  570. ent->proc_fops = &proc_dir_operations;
  571. ent->proc_iops = &proc_dir_inode_operations;
  572. if (proc_register(parent, ent) < 0) {
  573. kfree(ent);
  574. ent = NULL;
  575. }
  576. }
  577. return ent;
  578. }
  579. struct proc_dir_entry *proc_mkdir(const char *name,
  580. struct proc_dir_entry *parent)
  581. {
  582. return proc_mkdir_mode(name, S_IRUGO | S_IXUGO, parent);
  583. }
  584. struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
  585. struct proc_dir_entry *parent)
  586. {
  587. struct proc_dir_entry *ent;
  588. nlink_t nlink;
  589. if (S_ISDIR(mode)) {
  590. if ((mode & S_IALLUGO) == 0)
  591. mode |= S_IRUGO | S_IXUGO;
  592. nlink = 2;
  593. } else {
  594. if ((mode & S_IFMT) == 0)
  595. mode |= S_IFREG;
  596. if ((mode & S_IALLUGO) == 0)
  597. mode |= S_IRUGO;
  598. nlink = 1;
  599. }
  600. ent = proc_create(&parent,name,mode,nlink);
  601. if (ent) {
  602. if (S_ISDIR(mode)) {
  603. ent->proc_fops = &proc_dir_operations;
  604. ent->proc_iops = &proc_dir_inode_operations;
  605. }
  606. if (proc_register(parent, ent) < 0) {
  607. kfree(ent);
  608. ent = NULL;
  609. }
  610. }
  611. return ent;
  612. }
  613. void free_proc_entry(struct proc_dir_entry *de)
  614. {
  615. unsigned int ino = de->low_ino;
  616. if (ino < PROC_DYNAMIC_FIRST)
  617. return;
  618. release_inode_number(ino);
  619. if (S_ISLNK(de->mode) && de->data)
  620. kfree(de->data);
  621. kfree(de);
  622. }
  623. /*
  624. * Remove a /proc entry and free it if it's not currently in use.
  625. * If it is in use, we set the 'deleted' flag.
  626. */
  627. void remove_proc_entry(const char *name, struct proc_dir_entry *parent)
  628. {
  629. struct proc_dir_entry **p;
  630. struct proc_dir_entry *de;
  631. const char *fn = name;
  632. int len;
  633. if (!parent && xlate_proc_name(name, &parent, &fn) != 0)
  634. goto out;
  635. len = strlen(fn);
  636. spin_lock(&proc_subdir_lock);
  637. for (p = &parent->subdir; *p; p=&(*p)->next ) {
  638. if (!proc_match(len, fn, *p))
  639. continue;
  640. de = *p;
  641. *p = de->next;
  642. de->next = NULL;
  643. if (S_ISDIR(de->mode))
  644. parent->nlink--;
  645. proc_kill_inodes(de);
  646. de->nlink = 0;
  647. WARN_ON(de->subdir);
  648. if (!atomic_read(&de->count))
  649. free_proc_entry(de);
  650. else {
  651. de->deleted = 1;
  652. printk("remove_proc_entry: %s/%s busy, count=%d\n",
  653. parent->name, de->name, atomic_read(&de->count));
  654. }
  655. break;
  656. }
  657. spin_unlock(&proc_subdir_lock);
  658. out:
  659. return;
  660. }