inode.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765
  1. /*****************************************************************************/
  2. /*
  3. * inode.c -- Inode/Dentry functions for the USB device file system.
  4. *
  5. * Copyright (C) 2000 Thomas Sailer (sailer@ife.ee.ethz.ch)
  6. * Copyright (C) 2001,2002,2004 Greg Kroah-Hartman (greg@kroah.com)
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. *
  22. * History:
  23. * 0.1 04.01.2000 Created
  24. * 0.2 10.12.2001 converted to use the vfs layer better
  25. */
  26. /*****************************************************************************/
  27. #include <linux/config.h>
  28. #include <linux/module.h>
  29. #include <linux/fs.h>
  30. #include <linux/mount.h>
  31. #include <linux/pagemap.h>
  32. #include <linux/init.h>
  33. #include <linux/proc_fs.h>
  34. #include <linux/usb.h>
  35. #include <linux/namei.h>
  36. #include <linux/usbdevice_fs.h>
  37. #include <linux/smp_lock.h>
  38. #include <linux/parser.h>
  39. #include <linux/notifier.h>
  40. #include <asm/byteorder.h>
  41. #include "usb.h"
  42. #include "hcd.h"
  43. static struct super_operations usbfs_ops;
  44. static struct file_operations default_file_operations;
  45. static struct inode_operations usbfs_dir_inode_operations;
  46. static struct vfsmount *usbfs_mount;
  47. static int usbfs_mount_count; /* = 0 */
  48. static int ignore_mount = 0;
  49. static struct dentry *devices_usbfs_dentry;
  50. static int num_buses; /* = 0 */
  51. static uid_t devuid; /* = 0 */
  52. static uid_t busuid; /* = 0 */
  53. static uid_t listuid; /* = 0 */
  54. static gid_t devgid; /* = 0 */
  55. static gid_t busgid; /* = 0 */
  56. static gid_t listgid; /* = 0 */
  57. static umode_t devmode = S_IWUSR | S_IRUGO;
  58. static umode_t busmode = S_IXUGO | S_IRUGO;
  59. static umode_t listmode = S_IRUGO;
  60. enum {
  61. Opt_devuid, Opt_devgid, Opt_devmode,
  62. Opt_busuid, Opt_busgid, Opt_busmode,
  63. Opt_listuid, Opt_listgid, Opt_listmode,
  64. Opt_err,
  65. };
  66. static match_table_t tokens = {
  67. {Opt_devuid, "devuid=%u"},
  68. {Opt_devgid, "devgid=%u"},
  69. {Opt_devmode, "devmode=%o"},
  70. {Opt_busuid, "busuid=%u"},
  71. {Opt_busgid, "busgid=%u"},
  72. {Opt_busmode, "busmode=%o"},
  73. {Opt_listuid, "listuid=%u"},
  74. {Opt_listgid, "listgid=%u"},
  75. {Opt_listmode, "listmode=%o"},
  76. {Opt_err, NULL}
  77. };
  78. static int parse_options(struct super_block *s, char *data)
  79. {
  80. char *p;
  81. int option;
  82. /* (re)set to defaults. */
  83. devuid = 0;
  84. busuid = 0;
  85. listuid = 0;
  86. devgid = 0;
  87. busgid = 0;
  88. listgid = 0;
  89. devmode = S_IWUSR | S_IRUGO;
  90. busmode = S_IXUGO | S_IRUGO;
  91. listmode = S_IRUGO;
  92. while ((p = strsep(&data, ",")) != NULL) {
  93. substring_t args[MAX_OPT_ARGS];
  94. int token;
  95. if (!*p)
  96. continue;
  97. token = match_token(p, tokens, args);
  98. switch (token) {
  99. case Opt_devuid:
  100. if (match_int(&args[0], &option))
  101. return -EINVAL;
  102. devuid = option;
  103. break;
  104. case Opt_devgid:
  105. if (match_int(&args[0], &option))
  106. return -EINVAL;
  107. devgid = option;
  108. break;
  109. case Opt_devmode:
  110. if (match_octal(&args[0], &option))
  111. return -EINVAL;
  112. devmode = option & S_IRWXUGO;
  113. break;
  114. case Opt_busuid:
  115. if (match_int(&args[0], &option))
  116. return -EINVAL;
  117. busuid = option;
  118. break;
  119. case Opt_busgid:
  120. if (match_int(&args[0], &option))
  121. return -EINVAL;
  122. busgid = option;
  123. break;
  124. case Opt_busmode:
  125. if (match_octal(&args[0], &option))
  126. return -EINVAL;
  127. busmode = option & S_IRWXUGO;
  128. break;
  129. case Opt_listuid:
  130. if (match_int(&args[0], &option))
  131. return -EINVAL;
  132. listuid = option;
  133. break;
  134. case Opt_listgid:
  135. if (match_int(&args[0], &option))
  136. return -EINVAL;
  137. listgid = option;
  138. break;
  139. case Opt_listmode:
  140. if (match_octal(&args[0], &option))
  141. return -EINVAL;
  142. listmode = option & S_IRWXUGO;
  143. break;
  144. default:
  145. err("usbfs: unrecognised mount option \"%s\" "
  146. "or missing value\n", p);
  147. return -EINVAL;
  148. }
  149. }
  150. return 0;
  151. }
  152. static void update_special(struct dentry *special)
  153. {
  154. special->d_inode->i_uid = listuid;
  155. special->d_inode->i_gid = listgid;
  156. special->d_inode->i_mode = S_IFREG | listmode;
  157. }
  158. static void update_dev(struct dentry *dev)
  159. {
  160. dev->d_inode->i_uid = devuid;
  161. dev->d_inode->i_gid = devgid;
  162. dev->d_inode->i_mode = S_IFREG | devmode;
  163. }
  164. static void update_bus(struct dentry *bus)
  165. {
  166. struct dentry *dev = NULL;
  167. bus->d_inode->i_uid = busuid;
  168. bus->d_inode->i_gid = busgid;
  169. bus->d_inode->i_mode = S_IFDIR | busmode;
  170. down(&bus->d_inode->i_sem);
  171. list_for_each_entry(dev, &bus->d_subdirs, d_child)
  172. if (dev->d_inode)
  173. update_dev(dev);
  174. up(&bus->d_inode->i_sem);
  175. }
  176. static void update_sb(struct super_block *sb)
  177. {
  178. struct dentry *root = sb->s_root;
  179. struct dentry *bus = NULL;
  180. if (!root)
  181. return;
  182. down(&root->d_inode->i_sem);
  183. list_for_each_entry(bus, &root->d_subdirs, d_child) {
  184. if (bus->d_inode) {
  185. switch (S_IFMT & bus->d_inode->i_mode) {
  186. case S_IFDIR:
  187. update_bus(bus);
  188. break;
  189. case S_IFREG:
  190. update_special(bus);
  191. break;
  192. default:
  193. warn("Unknown node %s mode %x found on remount!\n",bus->d_name.name,bus->d_inode->i_mode);
  194. break;
  195. }
  196. }
  197. }
  198. up(&root->d_inode->i_sem);
  199. }
  200. static int remount(struct super_block *sb, int *flags, char *data)
  201. {
  202. /* If this is not a real mount,
  203. * i.e. it's a simple_pin_fs from create_special_files,
  204. * then ignore it.
  205. */
  206. if (ignore_mount)
  207. return 0;
  208. if (parse_options(sb, data)) {
  209. warn("usbfs: mount parameter error:");
  210. return -EINVAL;
  211. }
  212. if (usbfs_mount && usbfs_mount->mnt_sb)
  213. update_sb(usbfs_mount->mnt_sb);
  214. return 0;
  215. }
  216. static struct inode *usbfs_get_inode (struct super_block *sb, int mode, dev_t dev)
  217. {
  218. struct inode *inode = new_inode(sb);
  219. if (inode) {
  220. inode->i_mode = mode;
  221. inode->i_uid = current->fsuid;
  222. inode->i_gid = current->fsgid;
  223. inode->i_blksize = PAGE_CACHE_SIZE;
  224. inode->i_blocks = 0;
  225. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  226. switch (mode & S_IFMT) {
  227. default:
  228. init_special_inode(inode, mode, dev);
  229. break;
  230. case S_IFREG:
  231. inode->i_fop = &default_file_operations;
  232. break;
  233. case S_IFDIR:
  234. inode->i_op = &usbfs_dir_inode_operations;
  235. inode->i_fop = &simple_dir_operations;
  236. /* directory inodes start off with i_nlink == 2 (for "." entry) */
  237. inode->i_nlink++;
  238. break;
  239. }
  240. }
  241. return inode;
  242. }
  243. /* SMP-safe */
  244. static int usbfs_mknod (struct inode *dir, struct dentry *dentry, int mode,
  245. dev_t dev)
  246. {
  247. struct inode *inode = usbfs_get_inode(dir->i_sb, mode, dev);
  248. int error = -EPERM;
  249. if (dentry->d_inode)
  250. return -EEXIST;
  251. if (inode) {
  252. d_instantiate(dentry, inode);
  253. dget(dentry);
  254. error = 0;
  255. }
  256. return error;
  257. }
  258. static int usbfs_mkdir (struct inode *dir, struct dentry *dentry, int mode)
  259. {
  260. int res;
  261. mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR;
  262. res = usbfs_mknod (dir, dentry, mode, 0);
  263. if (!res)
  264. dir->i_nlink++;
  265. return res;
  266. }
  267. static int usbfs_create (struct inode *dir, struct dentry *dentry, int mode)
  268. {
  269. mode = (mode & S_IALLUGO) | S_IFREG;
  270. return usbfs_mknod (dir, dentry, mode, 0);
  271. }
  272. static inline int usbfs_positive (struct dentry *dentry)
  273. {
  274. return dentry->d_inode && !d_unhashed(dentry);
  275. }
  276. static int usbfs_empty (struct dentry *dentry)
  277. {
  278. struct list_head *list;
  279. spin_lock(&dcache_lock);
  280. list_for_each(list, &dentry->d_subdirs) {
  281. struct dentry *de = list_entry(list, struct dentry, d_child);
  282. if (usbfs_positive(de)) {
  283. spin_unlock(&dcache_lock);
  284. return 0;
  285. }
  286. }
  287. spin_unlock(&dcache_lock);
  288. return 1;
  289. }
  290. static int usbfs_unlink (struct inode *dir, struct dentry *dentry)
  291. {
  292. struct inode *inode = dentry->d_inode;
  293. down(&inode->i_sem);
  294. dentry->d_inode->i_nlink--;
  295. dput(dentry);
  296. up(&inode->i_sem);
  297. d_delete(dentry);
  298. return 0;
  299. }
  300. static int usbfs_rmdir(struct inode *dir, struct dentry *dentry)
  301. {
  302. int error = -ENOTEMPTY;
  303. struct inode * inode = dentry->d_inode;
  304. down(&inode->i_sem);
  305. dentry_unhash(dentry);
  306. if (usbfs_empty(dentry)) {
  307. dentry->d_inode->i_nlink -= 2;
  308. dput(dentry);
  309. inode->i_flags |= S_DEAD;
  310. dir->i_nlink--;
  311. error = 0;
  312. }
  313. up(&inode->i_sem);
  314. if (!error)
  315. d_delete(dentry);
  316. dput(dentry);
  317. return error;
  318. }
  319. /* default file operations */
  320. static ssize_t default_read_file (struct file *file, char __user *buf,
  321. size_t count, loff_t *ppos)
  322. {
  323. return 0;
  324. }
  325. static ssize_t default_write_file (struct file *file, const char __user *buf,
  326. size_t count, loff_t *ppos)
  327. {
  328. return count;
  329. }
  330. static loff_t default_file_lseek (struct file *file, loff_t offset, int orig)
  331. {
  332. loff_t retval = -EINVAL;
  333. down(&file->f_dentry->d_inode->i_sem);
  334. switch(orig) {
  335. case 0:
  336. if (offset > 0) {
  337. file->f_pos = offset;
  338. retval = file->f_pos;
  339. }
  340. break;
  341. case 1:
  342. if ((offset + file->f_pos) > 0) {
  343. file->f_pos += offset;
  344. retval = file->f_pos;
  345. }
  346. break;
  347. default:
  348. break;
  349. }
  350. up(&file->f_dentry->d_inode->i_sem);
  351. return retval;
  352. }
  353. static int default_open (struct inode *inode, struct file *file)
  354. {
  355. if (inode->u.generic_ip)
  356. file->private_data = inode->u.generic_ip;
  357. return 0;
  358. }
  359. static struct file_operations default_file_operations = {
  360. .read = default_read_file,
  361. .write = default_write_file,
  362. .open = default_open,
  363. .llseek = default_file_lseek,
  364. };
  365. static struct inode_operations usbfs_dir_inode_operations = {
  366. .lookup = simple_lookup,
  367. };
  368. static struct super_operations usbfs_ops = {
  369. .statfs = simple_statfs,
  370. .drop_inode = generic_delete_inode,
  371. .remount_fs = remount,
  372. };
  373. static int usbfs_fill_super(struct super_block *sb, void *data, int silent)
  374. {
  375. struct inode *inode;
  376. struct dentry *root;
  377. sb->s_blocksize = PAGE_CACHE_SIZE;
  378. sb->s_blocksize_bits = PAGE_CACHE_SHIFT;
  379. sb->s_magic = USBDEVICE_SUPER_MAGIC;
  380. sb->s_op = &usbfs_ops;
  381. sb->s_time_gran = 1;
  382. inode = usbfs_get_inode(sb, S_IFDIR | 0755, 0);
  383. if (!inode) {
  384. dbg("%s: could not get inode!",__FUNCTION__);
  385. return -ENOMEM;
  386. }
  387. root = d_alloc_root(inode);
  388. if (!root) {
  389. dbg("%s: could not get root dentry!",__FUNCTION__);
  390. iput(inode);
  391. return -ENOMEM;
  392. }
  393. sb->s_root = root;
  394. return 0;
  395. }
  396. /*
  397. * fs_create_by_name - create a file, given a name
  398. * @name: name of file
  399. * @mode: type of file
  400. * @parent: dentry of directory to create it in
  401. * @dentry: resulting dentry of file
  402. *
  403. * This function handles both regular files and directories.
  404. */
  405. static int fs_create_by_name (const char *name, mode_t mode,
  406. struct dentry *parent, struct dentry **dentry)
  407. {
  408. int error = 0;
  409. /* If the parent is not specified, we create it in the root.
  410. * We need the root dentry to do this, which is in the super
  411. * block. A pointer to that is in the struct vfsmount that we
  412. * have around.
  413. */
  414. if (!parent ) {
  415. if (usbfs_mount && usbfs_mount->mnt_sb) {
  416. parent = usbfs_mount->mnt_sb->s_root;
  417. }
  418. }
  419. if (!parent) {
  420. dbg("Ah! can not find a parent!");
  421. return -EFAULT;
  422. }
  423. *dentry = NULL;
  424. down(&parent->d_inode->i_sem);
  425. *dentry = lookup_one_len(name, parent, strlen(name));
  426. if (!IS_ERR(dentry)) {
  427. if ((mode & S_IFMT) == S_IFDIR)
  428. error = usbfs_mkdir (parent->d_inode, *dentry, mode);
  429. else
  430. error = usbfs_create (parent->d_inode, *dentry, mode);
  431. } else
  432. error = PTR_ERR(dentry);
  433. up(&parent->d_inode->i_sem);
  434. return error;
  435. }
  436. static struct dentry *fs_create_file (const char *name, mode_t mode,
  437. struct dentry *parent, void *data,
  438. struct file_operations *fops,
  439. uid_t uid, gid_t gid)
  440. {
  441. struct dentry *dentry;
  442. int error;
  443. dbg("creating file '%s'",name);
  444. error = fs_create_by_name (name, mode, parent, &dentry);
  445. if (error) {
  446. dentry = NULL;
  447. } else {
  448. if (dentry->d_inode) {
  449. if (data)
  450. dentry->d_inode->u.generic_ip = data;
  451. if (fops)
  452. dentry->d_inode->i_fop = fops;
  453. dentry->d_inode->i_uid = uid;
  454. dentry->d_inode->i_gid = gid;
  455. }
  456. }
  457. return dentry;
  458. }
  459. static void fs_remove_file (struct dentry *dentry)
  460. {
  461. struct dentry *parent = dentry->d_parent;
  462. if (!parent || !parent->d_inode)
  463. return;
  464. down(&parent->d_inode->i_sem);
  465. if (usbfs_positive(dentry)) {
  466. if (dentry->d_inode) {
  467. if (S_ISDIR(dentry->d_inode->i_mode))
  468. usbfs_rmdir(parent->d_inode, dentry);
  469. else
  470. usbfs_unlink(parent->d_inode, dentry);
  471. dput(dentry);
  472. }
  473. }
  474. up(&parent->d_inode->i_sem);
  475. }
  476. /* --------------------------------------------------------------------- */
  477. static struct super_block *usb_get_sb(struct file_system_type *fs_type,
  478. int flags, const char *dev_name, void *data)
  479. {
  480. return get_sb_single(fs_type, flags, data, usbfs_fill_super);
  481. }
  482. static struct file_system_type usb_fs_type = {
  483. .owner = THIS_MODULE,
  484. .name = "usbfs",
  485. .get_sb = usb_get_sb,
  486. .kill_sb = kill_litter_super,
  487. };
  488. /* --------------------------------------------------------------------- */
  489. static int create_special_files (void)
  490. {
  491. struct dentry *parent;
  492. int retval;
  493. /* the simple_pin_fs calls will call remount with no options
  494. * without this flag that would overwrite the real mount options (if any)
  495. */
  496. ignore_mount = 1;
  497. /* create the devices special file */
  498. retval = simple_pin_fs("usbfs", &usbfs_mount, &usbfs_mount_count);
  499. if (retval) {
  500. err ("Unable to get usbfs mount");
  501. goto exit;
  502. }
  503. ignore_mount = 0;
  504. parent = usbfs_mount->mnt_sb->s_root;
  505. devices_usbfs_dentry = fs_create_file ("devices",
  506. listmode | S_IFREG, parent,
  507. NULL, &usbfs_devices_fops,
  508. listuid, listgid);
  509. if (devices_usbfs_dentry == NULL) {
  510. err ("Unable to create devices usbfs file");
  511. retval = -ENODEV;
  512. goto error_clean_mounts;
  513. }
  514. goto exit;
  515. error_clean_mounts:
  516. simple_release_fs(&usbfs_mount, &usbfs_mount_count);
  517. exit:
  518. return retval;
  519. }
  520. static void remove_special_files (void)
  521. {
  522. if (devices_usbfs_dentry)
  523. fs_remove_file (devices_usbfs_dentry);
  524. devices_usbfs_dentry = NULL;
  525. simple_release_fs(&usbfs_mount, &usbfs_mount_count);
  526. }
  527. void usbfs_update_special (void)
  528. {
  529. struct inode *inode;
  530. if (devices_usbfs_dentry) {
  531. inode = devices_usbfs_dentry->d_inode;
  532. if (inode)
  533. inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME;
  534. }
  535. }
  536. static void usbfs_add_bus(struct usb_bus *bus)
  537. {
  538. struct dentry *parent;
  539. char name[8];
  540. int retval;
  541. /* create the special files if this is the first bus added */
  542. if (num_buses == 0) {
  543. retval = create_special_files();
  544. if (retval)
  545. return;
  546. }
  547. ++num_buses;
  548. sprintf (name, "%03d", bus->busnum);
  549. parent = usbfs_mount->mnt_sb->s_root;
  550. bus->usbfs_dentry = fs_create_file (name, busmode | S_IFDIR, parent,
  551. bus, NULL, busuid, busgid);
  552. if (bus->usbfs_dentry == NULL) {
  553. err ("error creating usbfs bus entry");
  554. return;
  555. }
  556. }
  557. static void usbfs_remove_bus(struct usb_bus *bus)
  558. {
  559. if (bus->usbfs_dentry) {
  560. fs_remove_file (bus->usbfs_dentry);
  561. bus->usbfs_dentry = NULL;
  562. }
  563. --num_buses;
  564. if (num_buses <= 0) {
  565. remove_special_files();
  566. num_buses = 0;
  567. }
  568. }
  569. static void usbfs_add_device(struct usb_device *dev)
  570. {
  571. char name[8];
  572. int i;
  573. int i_size;
  574. sprintf (name, "%03d", dev->devnum);
  575. dev->usbfs_dentry = fs_create_file (name, devmode | S_IFREG,
  576. dev->bus->usbfs_dentry, dev,
  577. &usbfs_device_file_operations,
  578. devuid, devgid);
  579. if (dev->usbfs_dentry == NULL) {
  580. err ("error creating usbfs device entry");
  581. return;
  582. }
  583. /* Set the size of the device's file to be
  584. * equal to the size of the device descriptors. */
  585. i_size = sizeof (struct usb_device_descriptor);
  586. for (i = 0; i < dev->descriptor.bNumConfigurations; ++i) {
  587. struct usb_config_descriptor *config =
  588. (struct usb_config_descriptor *)dev->rawdescriptors[i];
  589. i_size += le16_to_cpu(config->wTotalLength);
  590. }
  591. if (dev->usbfs_dentry->d_inode)
  592. dev->usbfs_dentry->d_inode->i_size = i_size;
  593. }
  594. static void usbfs_remove_device(struct usb_device *dev)
  595. {
  596. struct dev_state *ds;
  597. struct siginfo sinfo;
  598. if (dev->usbfs_dentry) {
  599. fs_remove_file (dev->usbfs_dentry);
  600. dev->usbfs_dentry = NULL;
  601. }
  602. while (!list_empty(&dev->filelist)) {
  603. ds = list_entry(dev->filelist.next, struct dev_state, list);
  604. wake_up_all(&ds->wait);
  605. list_del_init(&ds->list);
  606. if (ds->discsignr) {
  607. sinfo.si_signo = SIGPIPE;
  608. sinfo.si_errno = EPIPE;
  609. sinfo.si_code = SI_ASYNCIO;
  610. sinfo.si_addr = ds->disccontext;
  611. kill_proc_info_as_uid(ds->discsignr, &sinfo, ds->disc_pid, ds->disc_uid, ds->disc_euid);
  612. }
  613. }
  614. }
  615. static int usbfs_notify(struct notifier_block *self, unsigned long action, void *dev)
  616. {
  617. switch (action) {
  618. case USB_DEVICE_ADD:
  619. usbfs_add_device(dev);
  620. break;
  621. case USB_DEVICE_REMOVE:
  622. usbfs_remove_device(dev);
  623. break;
  624. case USB_BUS_ADD:
  625. usbfs_add_bus(dev);
  626. break;
  627. case USB_BUS_REMOVE:
  628. usbfs_remove_bus(dev);
  629. }
  630. usbfs_update_special();
  631. usbfs_conn_disc_event();
  632. return NOTIFY_OK;
  633. }
  634. static struct notifier_block usbfs_nb = {
  635. .notifier_call = usbfs_notify,
  636. };
  637. /* --------------------------------------------------------------------- */
  638. static struct proc_dir_entry *usbdir = NULL;
  639. int __init usbfs_init(void)
  640. {
  641. int retval;
  642. retval = register_filesystem(&usb_fs_type);
  643. if (retval)
  644. return retval;
  645. usb_register_notify(&usbfs_nb);
  646. /* create mount point for usbfs */
  647. usbdir = proc_mkdir("usb", proc_bus);
  648. return 0;
  649. }
  650. void usbfs_cleanup(void)
  651. {
  652. usb_unregister_notify(&usbfs_nb);
  653. unregister_filesystem(&usb_fs_type);
  654. if (usbdir)
  655. remove_proc_entry("usb", proc_bus);
  656. }