generic.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  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. struct proc_dir_entry *next;
  428. /* filldir passes info to user space */
  429. de_get(de);
  430. spin_unlock(&proc_subdir_lock);
  431. if (filldir(dirent, de->name, de->namelen, filp->f_pos,
  432. de->low_ino, de->mode >> 12) < 0) {
  433. de_put(de);
  434. goto out;
  435. }
  436. spin_lock(&proc_subdir_lock);
  437. filp->f_pos++;
  438. next = de->next;
  439. de_put(de);
  440. de = next;
  441. } while (de);
  442. spin_unlock(&proc_subdir_lock);
  443. }
  444. ret = 1;
  445. out: unlock_kernel();
  446. return ret;
  447. }
  448. /*
  449. * These are the generic /proc directory operations. They
  450. * use the in-memory "struct proc_dir_entry" tree to parse
  451. * the /proc directory.
  452. */
  453. static const struct file_operations proc_dir_operations = {
  454. .read = generic_read_dir,
  455. .readdir = proc_readdir,
  456. };
  457. /*
  458. * proc directories can do almost nothing..
  459. */
  460. static const struct inode_operations proc_dir_inode_operations = {
  461. .lookup = proc_lookup,
  462. .getattr = proc_getattr,
  463. .setattr = proc_notify_change,
  464. };
  465. static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
  466. {
  467. unsigned int i;
  468. i = get_inode_number();
  469. if (i == 0)
  470. return -EAGAIN;
  471. dp->low_ino = i;
  472. spin_lock(&proc_subdir_lock);
  473. dp->next = dir->subdir;
  474. dp->parent = dir;
  475. dir->subdir = dp;
  476. spin_unlock(&proc_subdir_lock);
  477. if (S_ISDIR(dp->mode)) {
  478. if (dp->proc_iops == NULL) {
  479. dp->proc_fops = &proc_dir_operations;
  480. dp->proc_iops = &proc_dir_inode_operations;
  481. }
  482. dir->nlink++;
  483. } else if (S_ISLNK(dp->mode)) {
  484. if (dp->proc_iops == NULL)
  485. dp->proc_iops = &proc_link_inode_operations;
  486. } else if (S_ISREG(dp->mode)) {
  487. if (dp->proc_fops == NULL)
  488. dp->proc_fops = &proc_file_operations;
  489. if (dp->proc_iops == NULL)
  490. dp->proc_iops = &proc_file_inode_operations;
  491. }
  492. return 0;
  493. }
  494. /*
  495. * Kill an inode that got unregistered..
  496. */
  497. static void proc_kill_inodes(struct proc_dir_entry *de)
  498. {
  499. struct list_head *p;
  500. struct super_block *sb = proc_mnt->mnt_sb;
  501. /*
  502. * Actually it's a partial revoke().
  503. */
  504. file_list_lock();
  505. list_for_each(p, &sb->s_files) {
  506. struct file * filp = list_entry(p, struct file, f_u.fu_list);
  507. struct dentry * dentry = filp->f_path.dentry;
  508. struct inode * inode;
  509. const struct file_operations *fops;
  510. if (dentry->d_op != &proc_dentry_operations)
  511. continue;
  512. inode = dentry->d_inode;
  513. if (PDE(inode) != de)
  514. continue;
  515. fops = filp->f_op;
  516. filp->f_op = NULL;
  517. fops_put(fops);
  518. }
  519. file_list_unlock();
  520. }
  521. static struct proc_dir_entry *proc_create(struct proc_dir_entry **parent,
  522. const char *name,
  523. mode_t mode,
  524. nlink_t nlink)
  525. {
  526. struct proc_dir_entry *ent = NULL;
  527. const char *fn = name;
  528. int len;
  529. /* make sure name is valid */
  530. if (!name || !strlen(name)) goto out;
  531. if (!(*parent) && xlate_proc_name(name, parent, &fn) != 0)
  532. goto out;
  533. /* At this point there must not be any '/' characters beyond *fn */
  534. if (strchr(fn, '/'))
  535. goto out;
  536. len = strlen(fn);
  537. ent = kmalloc(sizeof(struct proc_dir_entry) + len + 1, GFP_KERNEL);
  538. if (!ent) goto out;
  539. memset(ent, 0, sizeof(struct proc_dir_entry));
  540. memcpy(((char *) ent) + sizeof(struct proc_dir_entry), fn, len + 1);
  541. ent->name = ((char *) ent) + sizeof(*ent);
  542. ent->namelen = len;
  543. ent->mode = mode;
  544. ent->nlink = nlink;
  545. out:
  546. return ent;
  547. }
  548. struct proc_dir_entry *proc_symlink(const char *name,
  549. struct proc_dir_entry *parent, const char *dest)
  550. {
  551. struct proc_dir_entry *ent;
  552. ent = proc_create(&parent,name,
  553. (S_IFLNK | S_IRUGO | S_IWUGO | S_IXUGO),1);
  554. if (ent) {
  555. ent->data = kmalloc((ent->size=strlen(dest))+1, GFP_KERNEL);
  556. if (ent->data) {
  557. strcpy((char*)ent->data,dest);
  558. if (proc_register(parent, ent) < 0) {
  559. kfree(ent->data);
  560. kfree(ent);
  561. ent = NULL;
  562. }
  563. } else {
  564. kfree(ent);
  565. ent = NULL;
  566. }
  567. }
  568. return ent;
  569. }
  570. struct proc_dir_entry *proc_mkdir_mode(const char *name, mode_t mode,
  571. struct proc_dir_entry *parent)
  572. {
  573. struct proc_dir_entry *ent;
  574. ent = proc_create(&parent, name, S_IFDIR | mode, 2);
  575. if (ent) {
  576. ent->proc_fops = &proc_dir_operations;
  577. ent->proc_iops = &proc_dir_inode_operations;
  578. if (proc_register(parent, ent) < 0) {
  579. kfree(ent);
  580. ent = NULL;
  581. }
  582. }
  583. return ent;
  584. }
  585. struct proc_dir_entry *proc_mkdir(const char *name,
  586. struct proc_dir_entry *parent)
  587. {
  588. return proc_mkdir_mode(name, S_IRUGO | S_IXUGO, parent);
  589. }
  590. struct proc_dir_entry *create_proc_entry(const char *name, mode_t mode,
  591. struct proc_dir_entry *parent)
  592. {
  593. struct proc_dir_entry *ent;
  594. nlink_t nlink;
  595. if (S_ISDIR(mode)) {
  596. if ((mode & S_IALLUGO) == 0)
  597. mode |= S_IRUGO | S_IXUGO;
  598. nlink = 2;
  599. } else {
  600. if ((mode & S_IFMT) == 0)
  601. mode |= S_IFREG;
  602. if ((mode & S_IALLUGO) == 0)
  603. mode |= S_IRUGO;
  604. nlink = 1;
  605. }
  606. ent = proc_create(&parent,name,mode,nlink);
  607. if (ent) {
  608. if (S_ISDIR(mode)) {
  609. ent->proc_fops = &proc_dir_operations;
  610. ent->proc_iops = &proc_dir_inode_operations;
  611. }
  612. if (proc_register(parent, ent) < 0) {
  613. kfree(ent);
  614. ent = NULL;
  615. }
  616. }
  617. return ent;
  618. }
  619. void free_proc_entry(struct proc_dir_entry *de)
  620. {
  621. unsigned int ino = de->low_ino;
  622. if (ino < PROC_DYNAMIC_FIRST)
  623. return;
  624. release_inode_number(ino);
  625. if (S_ISLNK(de->mode) && de->data)
  626. kfree(de->data);
  627. kfree(de);
  628. }
  629. /*
  630. * Remove a /proc entry and free it if it's not currently in use.
  631. * If it is in use, we set the 'deleted' flag.
  632. */
  633. void remove_proc_entry(const char *name, struct proc_dir_entry *parent)
  634. {
  635. struct proc_dir_entry **p;
  636. struct proc_dir_entry *de;
  637. const char *fn = name;
  638. int len;
  639. if (!parent && xlate_proc_name(name, &parent, &fn) != 0)
  640. goto out;
  641. len = strlen(fn);
  642. spin_lock(&proc_subdir_lock);
  643. for (p = &parent->subdir; *p; p=&(*p)->next ) {
  644. if (!proc_match(len, fn, *p))
  645. continue;
  646. de = *p;
  647. *p = de->next;
  648. de->next = NULL;
  649. if (S_ISDIR(de->mode))
  650. parent->nlink--;
  651. proc_kill_inodes(de);
  652. de->nlink = 0;
  653. WARN_ON(de->subdir);
  654. if (!atomic_read(&de->count))
  655. free_proc_entry(de);
  656. else {
  657. de->deleted = 1;
  658. printk("remove_proc_entry: %s/%s busy, count=%d\n",
  659. parent->name, de->name, atomic_read(&de->count));
  660. }
  661. break;
  662. }
  663. spin_unlock(&proc_subdir_lock);
  664. out:
  665. return;
  666. }