inode.c 17 KB

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