Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /*****************************************************************************/ |
| 2 | |
| 3 | /* |
| 4 | * inode.c -- Inode/Dentry functions for the USB device file system. |
| 5 | * |
| 6 | * Copyright (C) 2000 Thomas Sailer (sailer@ife.ee.ethz.ch) |
| 7 | * Copyright (C) 2001,2002,2004 Greg Kroah-Hartman (greg@kroah.com) |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
| 18 | * |
| 19 | * You should have received a copy of the GNU General Public License |
| 20 | * along with this program; if not, write to the Free Software |
| 21 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 22 | * |
| 23 | * History: |
| 24 | * 0.1 04.01.2000 Created |
| 25 | * 0.2 10.12.2001 converted to use the vfs layer better |
| 26 | */ |
| 27 | |
| 28 | /*****************************************************************************/ |
| 29 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/module.h> |
| 31 | #include <linux/fs.h> |
| 32 | #include <linux/mount.h> |
| 33 | #include <linux/pagemap.h> |
| 34 | #include <linux/init.h> |
| 35 | #include <linux/proc_fs.h> |
| 36 | #include <linux/usb.h> |
| 37 | #include <linux/namei.h> |
| 38 | #include <linux/usbdevice_fs.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include <linux/parser.h> |
Greg Kroah-Hartman | 54a5c4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 40 | #include <linux/notifier.h> |
Miklos Szeredi | 2e4f3c0 | 2008-01-24 20:34:07 +0100 | [diff] [blame] | 41 | #include <linux/seq_file.h> |
Eric Lescouet | 27729aa | 2010-04-24 23:21:52 +0200 | [diff] [blame] | 42 | #include <linux/usb/hcd.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <asm/byteorder.h> |
| 44 | #include "usb.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Miklos Szeredi | 2e4f3c0 | 2008-01-24 20:34:07 +0100 | [diff] [blame] | 46 | #define USBFS_DEFAULT_DEVMODE (S_IWUSR | S_IRUGO) |
| 47 | #define USBFS_DEFAULT_BUSMODE (S_IXUGO | S_IRUGO) |
| 48 | #define USBFS_DEFAULT_LISTMODE S_IRUGO |
| 49 | |
Luiz Fernando N. Capitulino | 066202d | 2006-08-05 20:37:11 -0300 | [diff] [blame] | 50 | static const struct file_operations default_file_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | static struct vfsmount *usbfs_mount; |
| 52 | static int usbfs_mount_count; /* = 0 */ |
| 53 | static int ignore_mount = 0; |
| 54 | |
| 55 | static struct dentry *devices_usbfs_dentry; |
| 56 | static int num_buses; /* = 0 */ |
| 57 | |
| 58 | static uid_t devuid; /* = 0 */ |
| 59 | static uid_t busuid; /* = 0 */ |
| 60 | static uid_t listuid; /* = 0 */ |
| 61 | static gid_t devgid; /* = 0 */ |
| 62 | static gid_t busgid; /* = 0 */ |
| 63 | static gid_t listgid; /* = 0 */ |
Miklos Szeredi | 2e4f3c0 | 2008-01-24 20:34:07 +0100 | [diff] [blame] | 64 | static umode_t devmode = USBFS_DEFAULT_DEVMODE; |
| 65 | static umode_t busmode = USBFS_DEFAULT_BUSMODE; |
| 66 | static umode_t listmode = USBFS_DEFAULT_LISTMODE; |
| 67 | |
Al Viro | 34c80b1 | 2011-12-08 21:32:45 -0500 | [diff] [blame] | 68 | static int usbfs_show_options(struct seq_file *seq, struct dentry *root) |
Miklos Szeredi | 2e4f3c0 | 2008-01-24 20:34:07 +0100 | [diff] [blame] | 69 | { |
| 70 | if (devuid != 0) |
| 71 | seq_printf(seq, ",devuid=%u", devuid); |
| 72 | if (devgid != 0) |
| 73 | seq_printf(seq, ",devgid=%u", devgid); |
| 74 | if (devmode != USBFS_DEFAULT_DEVMODE) |
| 75 | seq_printf(seq, ",devmode=%o", devmode); |
| 76 | if (busuid != 0) |
| 77 | seq_printf(seq, ",busuid=%u", busuid); |
| 78 | if (busgid != 0) |
| 79 | seq_printf(seq, ",busgid=%u", busgid); |
| 80 | if (busmode != USBFS_DEFAULT_BUSMODE) |
| 81 | seq_printf(seq, ",busmode=%o", busmode); |
| 82 | if (listuid != 0) |
| 83 | seq_printf(seq, ",listuid=%u", listuid); |
| 84 | if (listgid != 0) |
| 85 | seq_printf(seq, ",listgid=%u", listgid); |
| 86 | if (listmode != USBFS_DEFAULT_LISTMODE) |
| 87 | seq_printf(seq, ",listmode=%o", listmode); |
| 88 | |
| 89 | return 0; |
| 90 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 91 | |
| 92 | enum { |
| 93 | Opt_devuid, Opt_devgid, Opt_devmode, |
| 94 | Opt_busuid, Opt_busgid, Opt_busmode, |
| 95 | Opt_listuid, Opt_listgid, Opt_listmode, |
| 96 | Opt_err, |
| 97 | }; |
| 98 | |
Steven Whitehouse | a447c09 | 2008-10-13 10:46:57 +0100 | [diff] [blame] | 99 | static const match_table_t tokens = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 100 | {Opt_devuid, "devuid=%u"}, |
| 101 | {Opt_devgid, "devgid=%u"}, |
| 102 | {Opt_devmode, "devmode=%o"}, |
| 103 | {Opt_busuid, "busuid=%u"}, |
| 104 | {Opt_busgid, "busgid=%u"}, |
| 105 | {Opt_busmode, "busmode=%o"}, |
| 106 | {Opt_listuid, "listuid=%u"}, |
| 107 | {Opt_listgid, "listgid=%u"}, |
| 108 | {Opt_listmode, "listmode=%o"}, |
| 109 | {Opt_err, NULL} |
| 110 | }; |
| 111 | |
| 112 | static int parse_options(struct super_block *s, char *data) |
| 113 | { |
| 114 | char *p; |
| 115 | int option; |
| 116 | |
| 117 | /* (re)set to defaults. */ |
| 118 | devuid = 0; |
| 119 | busuid = 0; |
| 120 | listuid = 0; |
| 121 | devgid = 0; |
| 122 | busgid = 0; |
| 123 | listgid = 0; |
Miklos Szeredi | 2e4f3c0 | 2008-01-24 20:34:07 +0100 | [diff] [blame] | 124 | devmode = USBFS_DEFAULT_DEVMODE; |
| 125 | busmode = USBFS_DEFAULT_BUSMODE; |
| 126 | listmode = USBFS_DEFAULT_LISTMODE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | while ((p = strsep(&data, ",")) != NULL) { |
| 129 | substring_t args[MAX_OPT_ARGS]; |
| 130 | int token; |
| 131 | if (!*p) |
| 132 | continue; |
| 133 | |
| 134 | token = match_token(p, tokens, args); |
| 135 | switch (token) { |
| 136 | case Opt_devuid: |
| 137 | if (match_int(&args[0], &option)) |
| 138 | return -EINVAL; |
| 139 | devuid = option; |
| 140 | break; |
| 141 | case Opt_devgid: |
| 142 | if (match_int(&args[0], &option)) |
| 143 | return -EINVAL; |
| 144 | devgid = option; |
| 145 | break; |
| 146 | case Opt_devmode: |
| 147 | if (match_octal(&args[0], &option)) |
| 148 | return -EINVAL; |
| 149 | devmode = option & S_IRWXUGO; |
| 150 | break; |
| 151 | case Opt_busuid: |
| 152 | if (match_int(&args[0], &option)) |
| 153 | return -EINVAL; |
| 154 | busuid = option; |
| 155 | break; |
| 156 | case Opt_busgid: |
| 157 | if (match_int(&args[0], &option)) |
| 158 | return -EINVAL; |
| 159 | busgid = option; |
| 160 | break; |
| 161 | case Opt_busmode: |
| 162 | if (match_octal(&args[0], &option)) |
| 163 | return -EINVAL; |
| 164 | busmode = option & S_IRWXUGO; |
| 165 | break; |
| 166 | case Opt_listuid: |
| 167 | if (match_int(&args[0], &option)) |
| 168 | return -EINVAL; |
| 169 | listuid = option; |
| 170 | break; |
| 171 | case Opt_listgid: |
| 172 | if (match_int(&args[0], &option)) |
| 173 | return -EINVAL; |
| 174 | listgid = option; |
| 175 | break; |
| 176 | case Opt_listmode: |
| 177 | if (match_octal(&args[0], &option)) |
| 178 | return -EINVAL; |
| 179 | listmode = option & S_IRWXUGO; |
| 180 | break; |
| 181 | default: |
Greg Kroah-Hartman | 69a8594 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 182 | printk(KERN_ERR "usbfs: unrecognised mount option " |
| 183 | "\"%s\" or missing value\n", p); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | return -EINVAL; |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
| 191 | static void update_special(struct dentry *special) |
| 192 | { |
| 193 | special->d_inode->i_uid = listuid; |
| 194 | special->d_inode->i_gid = listgid; |
| 195 | special->d_inode->i_mode = S_IFREG | listmode; |
| 196 | } |
| 197 | |
| 198 | static void update_dev(struct dentry *dev) |
| 199 | { |
| 200 | dev->d_inode->i_uid = devuid; |
| 201 | dev->d_inode->i_gid = devgid; |
| 202 | dev->d_inode->i_mode = S_IFREG | devmode; |
| 203 | } |
| 204 | |
| 205 | static void update_bus(struct dentry *bus) |
| 206 | { |
| 207 | struct dentry *dev = NULL; |
| 208 | |
| 209 | bus->d_inode->i_uid = busuid; |
| 210 | bus->d_inode->i_gid = busgid; |
| 211 | bus->d_inode->i_mode = S_IFDIR | busmode; |
| 212 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 213 | mutex_lock(&bus->d_inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | |
Eric Dumazet | 5160ee6 | 2006-01-08 01:03:32 -0800 | [diff] [blame] | 215 | list_for_each_entry(dev, &bus->d_subdirs, d_u.d_child) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | if (dev->d_inode) |
| 217 | update_dev(dev); |
| 218 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 219 | mutex_unlock(&bus->d_inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | } |
| 221 | |
| 222 | static void update_sb(struct super_block *sb) |
| 223 | { |
| 224 | struct dentry *root = sb->s_root; |
| 225 | struct dentry *bus = NULL; |
| 226 | |
| 227 | if (!root) |
| 228 | return; |
| 229 | |
Ingo Molnar | f2eace2 | 2006-07-03 00:25:05 -0700 | [diff] [blame] | 230 | mutex_lock_nested(&root->d_inode->i_mutex, I_MUTEX_PARENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | |
Eric Dumazet | 5160ee6 | 2006-01-08 01:03:32 -0800 | [diff] [blame] | 232 | list_for_each_entry(bus, &root->d_subdirs, d_u.d_child) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | if (bus->d_inode) { |
| 234 | switch (S_IFMT & bus->d_inode->i_mode) { |
| 235 | case S_IFDIR: |
| 236 | update_bus(bus); |
| 237 | break; |
| 238 | case S_IFREG: |
| 239 | update_special(bus); |
| 240 | break; |
| 241 | default: |
Greg Kroah-Hartman | 3b6004f | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 242 | printk(KERN_WARNING "usbfs: Unknown node %s " |
| 243 | "mode %x found on remount!\n", |
| 244 | bus->d_name.name, bus->d_inode->i_mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | break; |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 250 | mutex_unlock(&root->d_inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | static int remount(struct super_block *sb, int *flags, char *data) |
| 254 | { |
| 255 | /* If this is not a real mount, |
| 256 | * i.e. it's a simple_pin_fs from create_special_files, |
| 257 | * then ignore it. |
| 258 | */ |
| 259 | if (ignore_mount) |
| 260 | return 0; |
| 261 | |
| 262 | if (parse_options(sb, data)) { |
Greg Kroah-Hartman | 3b6004f | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 263 | printk(KERN_WARNING "usbfs: mount parameter error.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | return -EINVAL; |
| 265 | } |
| 266 | |
Al Viro | c972b4b | 2011-12-08 23:01:06 -0500 | [diff] [blame] | 267 | if (usbfs_mount) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | update_sb(usbfs_mount->mnt_sb); |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
Al Viro | 5b91aca | 2011-07-24 23:36:12 -0400 | [diff] [blame] | 273 | static struct inode *usbfs_get_inode (struct super_block *sb, umode_t mode, dev_t dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | { |
| 275 | struct inode *inode = new_inode(sb); |
| 276 | |
| 277 | if (inode) { |
Christoph Hellwig | 85fe402 | 2010-10-23 11:19:54 -0400 | [diff] [blame] | 278 | inode->i_ino = get_next_ino(); |
Al Viro | 5b91aca | 2011-07-24 23:36:12 -0400 | [diff] [blame] | 279 | inode_init_owner(inode, NULL, mode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 281 | switch (mode & S_IFMT) { |
| 282 | default: |
| 283 | init_special_inode(inode, mode, dev); |
| 284 | break; |
| 285 | case S_IFREG: |
| 286 | inode->i_fop = &default_file_operations; |
| 287 | break; |
| 288 | case S_IFDIR: |
OGAWA Hirofumi | bc7cb32 | 2005-11-17 09:47:07 -0800 | [diff] [blame] | 289 | inode->i_op = &simple_dir_inode_operations; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | inode->i_fop = &simple_dir_operations; |
| 291 | |
| 292 | /* directory inodes start off with i_nlink == 2 (for "." entry) */ |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 293 | inc_nlink(inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | break; |
| 295 | } |
| 296 | } |
| 297 | return inode; |
| 298 | } |
| 299 | |
| 300 | /* SMP-safe */ |
Al Viro | 5b91aca | 2011-07-24 23:36:12 -0400 | [diff] [blame] | 301 | static int usbfs_mknod (struct inode *dir, struct dentry *dentry, umode_t mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | dev_t dev) |
| 303 | { |
| 304 | struct inode *inode = usbfs_get_inode(dir->i_sb, mode, dev); |
| 305 | int error = -EPERM; |
| 306 | |
| 307 | if (dentry->d_inode) |
| 308 | return -EEXIST; |
| 309 | |
| 310 | if (inode) { |
| 311 | d_instantiate(dentry, inode); |
| 312 | dget(dentry); |
| 313 | error = 0; |
| 314 | } |
| 315 | return error; |
| 316 | } |
| 317 | |
Al Viro | 5b91aca | 2011-07-24 23:36:12 -0400 | [diff] [blame] | 318 | static int usbfs_mkdir (struct inode *dir, struct dentry *dentry, umode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | { |
| 320 | int res; |
| 321 | |
| 322 | mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR; |
| 323 | res = usbfs_mknod (dir, dentry, mode, 0); |
| 324 | if (!res) |
Dave Hansen | d8c76e6 | 2006-09-30 23:29:04 -0700 | [diff] [blame] | 325 | inc_nlink(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 326 | return res; |
| 327 | } |
| 328 | |
Al Viro | 5b91aca | 2011-07-24 23:36:12 -0400 | [diff] [blame] | 329 | static int usbfs_create (struct inode *dir, struct dentry *dentry, umode_t mode) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | { |
| 331 | mode = (mode & S_IALLUGO) | S_IFREG; |
| 332 | return usbfs_mknod (dir, dentry, mode, 0); |
| 333 | } |
| 334 | |
| 335 | static inline int usbfs_positive (struct dentry *dentry) |
| 336 | { |
| 337 | return dentry->d_inode && !d_unhashed(dentry); |
| 338 | } |
| 339 | |
| 340 | static int usbfs_empty (struct dentry *dentry) |
| 341 | { |
| 342 | struct list_head *list; |
| 343 | |
Nick Piggin | 2fd6b7f | 2011-01-07 17:49:34 +1100 | [diff] [blame] | 344 | spin_lock(&dentry->d_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | list_for_each(list, &dentry->d_subdirs) { |
Eric Dumazet | 5160ee6 | 2006-01-08 01:03:32 -0800 | [diff] [blame] | 346 | struct dentry *de = list_entry(list, struct dentry, d_u.d_child); |
Nick Piggin | 2fd6b7f | 2011-01-07 17:49:34 +1100 | [diff] [blame] | 347 | |
| 348 | spin_lock_nested(&de->d_lock, DENTRY_D_LOCK_NESTED); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | if (usbfs_positive(de)) { |
Nick Piggin | da50295 | 2011-01-07 17:49:33 +1100 | [diff] [blame] | 350 | spin_unlock(&de->d_lock); |
Nick Piggin | 2fd6b7f | 2011-01-07 17:49:34 +1100 | [diff] [blame] | 351 | spin_unlock(&dentry->d_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | return 0; |
| 353 | } |
Nick Piggin | da50295 | 2011-01-07 17:49:33 +1100 | [diff] [blame] | 354 | spin_unlock(&de->d_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } |
Nick Piggin | 2fd6b7f | 2011-01-07 17:49:34 +1100 | [diff] [blame] | 356 | spin_unlock(&dentry->d_lock); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 357 | return 1; |
| 358 | } |
| 359 | |
| 360 | static int usbfs_unlink (struct inode *dir, struct dentry *dentry) |
| 361 | { |
| 362 | struct inode *inode = dentry->d_inode; |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 363 | mutex_lock(&inode->i_mutex); |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 364 | drop_nlink(dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | dput(dentry); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 366 | mutex_unlock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | d_delete(dentry); |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | static int usbfs_rmdir(struct inode *dir, struct dentry *dentry) |
| 372 | { |
| 373 | int error = -ENOTEMPTY; |
| 374 | struct inode * inode = dentry->d_inode; |
| 375 | |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 376 | mutex_lock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | dentry_unhash(dentry); |
| 378 | if (usbfs_empty(dentry)) { |
Al Viro | d83c49f | 2010-04-30 17:17:09 -0400 | [diff] [blame] | 379 | dont_mount(dentry); |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 380 | drop_nlink(dentry->d_inode); |
| 381 | drop_nlink(dentry->d_inode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | dput(dentry); |
| 383 | inode->i_flags |= S_DEAD; |
Dave Hansen | 9a53c3a | 2006-09-30 23:29:03 -0700 | [diff] [blame] | 384 | drop_nlink(dir); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | error = 0; |
| 386 | } |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 387 | mutex_unlock(&inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | if (!error) |
| 389 | d_delete(dentry); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 390 | return error; |
| 391 | } |
| 392 | |
| 393 | |
| 394 | /* default file operations */ |
| 395 | static ssize_t default_read_file (struct file *file, char __user *buf, |
| 396 | size_t count, loff_t *ppos) |
| 397 | { |
| 398 | return 0; |
| 399 | } |
| 400 | |
| 401 | static ssize_t default_write_file (struct file *file, const char __user *buf, |
| 402 | size_t count, loff_t *ppos) |
| 403 | { |
| 404 | return count; |
| 405 | } |
| 406 | |
| 407 | static loff_t default_file_lseek (struct file *file, loff_t offset, int orig) |
| 408 | { |
| 409 | loff_t retval = -EINVAL; |
| 410 | |
Josef Sipek | 33cb899 | 2006-12-08 02:37:46 -0800 | [diff] [blame] | 411 | mutex_lock(&file->f_path.dentry->d_inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | switch(orig) { |
| 413 | case 0: |
| 414 | if (offset > 0) { |
| 415 | file->f_pos = offset; |
| 416 | retval = file->f_pos; |
| 417 | } |
| 418 | break; |
| 419 | case 1: |
| 420 | if ((offset + file->f_pos) > 0) { |
| 421 | file->f_pos += offset; |
| 422 | retval = file->f_pos; |
| 423 | } |
| 424 | break; |
| 425 | default: |
| 426 | break; |
| 427 | } |
Josef Sipek | 33cb899 | 2006-12-08 02:37:46 -0800 | [diff] [blame] | 428 | mutex_unlock(&file->f_path.dentry->d_inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | return retval; |
| 430 | } |
| 431 | |
| 432 | static int default_open (struct inode *inode, struct file *file) |
| 433 | { |
Theodore Ts'o | 8e18e29 | 2006-09-27 01:50:46 -0700 | [diff] [blame] | 434 | if (inode->i_private) |
| 435 | file->private_data = inode->i_private; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | |
| 437 | return 0; |
| 438 | } |
| 439 | |
Luiz Fernando N. Capitulino | 066202d | 2006-08-05 20:37:11 -0300 | [diff] [blame] | 440 | static const struct file_operations default_file_operations = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 441 | .read = default_read_file, |
| 442 | .write = default_write_file, |
| 443 | .open = default_open, |
| 444 | .llseek = default_file_lseek, |
| 445 | }; |
| 446 | |
Alexey Dobriyan | b87221d | 2009-09-21 17:01:09 -0700 | [diff] [blame] | 447 | static const struct super_operations usbfs_ops = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | .statfs = simple_statfs, |
| 449 | .drop_inode = generic_delete_inode, |
| 450 | .remount_fs = remount, |
Miklos Szeredi | 2e4f3c0 | 2008-01-24 20:34:07 +0100 | [diff] [blame] | 451 | .show_options = usbfs_show_options, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | }; |
| 453 | |
| 454 | static int usbfs_fill_super(struct super_block *sb, void *data, int silent) |
| 455 | { |
| 456 | struct inode *inode; |
| 457 | struct dentry *root; |
| 458 | |
| 459 | sb->s_blocksize = PAGE_CACHE_SIZE; |
| 460 | sb->s_blocksize_bits = PAGE_CACHE_SHIFT; |
| 461 | sb->s_magic = USBDEVICE_SUPER_MAGIC; |
| 462 | sb->s_op = &usbfs_ops; |
| 463 | sb->s_time_gran = 1; |
| 464 | inode = usbfs_get_inode(sb, S_IFDIR | 0755, 0); |
| 465 | |
| 466 | if (!inode) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 467 | dbg("%s: could not get inode!",__func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | return -ENOMEM; |
| 469 | } |
| 470 | |
| 471 | root = d_alloc_root(inode); |
| 472 | if (!root) { |
Harvey Harrison | 441b62c | 2008-03-03 16:08:34 -0800 | [diff] [blame] | 473 | dbg("%s: could not get root dentry!",__func__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | iput(inode); |
| 475 | return -ENOMEM; |
| 476 | } |
| 477 | sb->s_root = root; |
| 478 | return 0; |
| 479 | } |
| 480 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 481 | /* |
| 482 | * fs_create_by_name - create a file, given a name |
| 483 | * @name: name of file |
| 484 | * @mode: type of file |
| 485 | * @parent: dentry of directory to create it in |
| 486 | * @dentry: resulting dentry of file |
| 487 | * |
| 488 | * This function handles both regular files and directories. |
| 489 | */ |
Al Viro | 5b91aca | 2011-07-24 23:36:12 -0400 | [diff] [blame] | 490 | static int fs_create_by_name (const char *name, umode_t mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | struct dentry *parent, struct dentry **dentry) |
| 492 | { |
| 493 | int error = 0; |
| 494 | |
| 495 | /* If the parent is not specified, we create it in the root. |
| 496 | * We need the root dentry to do this, which is in the super |
| 497 | * block. A pointer to that is in the struct vfsmount that we |
| 498 | * have around. |
| 499 | */ |
| 500 | if (!parent ) { |
Al Viro | c972b4b | 2011-12-08 23:01:06 -0500 | [diff] [blame] | 501 | if (usbfs_mount) |
Al Viro | 4c1d5a6 | 2011-12-07 18:21:57 -0500 | [diff] [blame] | 502 | parent = usbfs_mount->mnt_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
| 504 | |
| 505 | if (!parent) { |
| 506 | dbg("Ah! can not find a parent!"); |
| 507 | return -EFAULT; |
| 508 | } |
| 509 | |
| 510 | *dentry = NULL; |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 511 | mutex_lock(&parent->d_inode->i_mutex); |
Christoph Hellwig | 5f45f1a | 2005-06-23 00:09:12 -0700 | [diff] [blame] | 512 | *dentry = lookup_one_len(name, parent, strlen(name)); |
Dan Carpenter | fa7fe7a | 2010-04-22 12:00:52 +0200 | [diff] [blame] | 513 | if (!IS_ERR(*dentry)) { |
Al Viro | 5b91aca | 2011-07-24 23:36:12 -0400 | [diff] [blame] | 514 | if (S_ISDIR(mode)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | error = usbfs_mkdir (parent->d_inode, *dentry, mode); |
| 516 | else |
| 517 | error = usbfs_create (parent->d_inode, *dentry, mode); |
| 518 | } else |
Dan Carpenter | fa7fe7a | 2010-04-22 12:00:52 +0200 | [diff] [blame] | 519 | error = PTR_ERR(*dentry); |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 520 | mutex_unlock(&parent->d_inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | |
| 522 | return error; |
| 523 | } |
| 524 | |
Al Viro | 5b91aca | 2011-07-24 23:36:12 -0400 | [diff] [blame] | 525 | static struct dentry *fs_create_file (const char *name, umode_t mode, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 526 | struct dentry *parent, void *data, |
Luiz Fernando N. Capitulino | 066202d | 2006-08-05 20:37:11 -0300 | [diff] [blame] | 527 | const struct file_operations *fops, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | uid_t uid, gid_t gid) |
| 529 | { |
| 530 | struct dentry *dentry; |
| 531 | int error; |
| 532 | |
| 533 | dbg("creating file '%s'",name); |
| 534 | |
| 535 | error = fs_create_by_name (name, mode, parent, &dentry); |
| 536 | if (error) { |
| 537 | dentry = NULL; |
| 538 | } else { |
| 539 | if (dentry->d_inode) { |
| 540 | if (data) |
Theodore Ts'o | 8e18e29 | 2006-09-27 01:50:46 -0700 | [diff] [blame] | 541 | dentry->d_inode->i_private = data; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | if (fops) |
| 543 | dentry->d_inode->i_fop = fops; |
| 544 | dentry->d_inode->i_uid = uid; |
| 545 | dentry->d_inode->i_gid = gid; |
| 546 | } |
| 547 | } |
| 548 | |
| 549 | return dentry; |
| 550 | } |
| 551 | |
| 552 | static void fs_remove_file (struct dentry *dentry) |
| 553 | { |
| 554 | struct dentry *parent = dentry->d_parent; |
| 555 | |
| 556 | if (!parent || !parent->d_inode) |
| 557 | return; |
| 558 | |
Arjan van de Ven | 8e7795e | 2006-07-03 00:25:21 -0700 | [diff] [blame] | 559 | mutex_lock_nested(&parent->d_inode->i_mutex, I_MUTEX_PARENT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | if (usbfs_positive(dentry)) { |
| 561 | if (dentry->d_inode) { |
| 562 | if (S_ISDIR(dentry->d_inode->i_mode)) |
| 563 | usbfs_rmdir(parent->d_inode, dentry); |
| 564 | else |
| 565 | usbfs_unlink(parent->d_inode, dentry); |
| 566 | dput(dentry); |
| 567 | } |
| 568 | } |
Jes Sorensen | 1b1dcc1 | 2006-01-09 15:59:24 -0800 | [diff] [blame] | 569 | mutex_unlock(&parent->d_inode->i_mutex); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | /* --------------------------------------------------------------------- */ |
| 573 | |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 574 | static struct dentry *usb_mount(struct file_system_type *fs_type, |
| 575 | int flags, const char *dev_name, void *data) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 576 | { |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 577 | return mount_single(fs_type, flags, data, usbfs_fill_super); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | } |
| 579 | |
| 580 | static struct file_system_type usb_fs_type = { |
| 581 | .owner = THIS_MODULE, |
| 582 | .name = "usbfs", |
Al Viro | fc14f2f | 2010-07-25 01:48:30 +0400 | [diff] [blame] | 583 | .mount = usb_mount, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | .kill_sb = kill_litter_super, |
| 585 | }; |
| 586 | |
| 587 | /* --------------------------------------------------------------------- */ |
| 588 | |
| 589 | static int create_special_files (void) |
| 590 | { |
| 591 | struct dentry *parent; |
| 592 | int retval; |
| 593 | |
| 594 | /* the simple_pin_fs calls will call remount with no options |
| 595 | * without this flag that would overwrite the real mount options (if any) |
| 596 | */ |
| 597 | ignore_mount = 1; |
| 598 | |
| 599 | /* create the devices special file */ |
Trond Myklebust | 1f5ce9e | 2006-06-09 09:34:16 -0400 | [diff] [blame] | 600 | retval = simple_pin_fs(&usb_fs_type, &usbfs_mount, &usbfs_mount_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | if (retval) { |
Greg Kroah-Hartman | 69a8594 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 602 | printk(KERN_ERR "Unable to get usbfs mount\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | goto exit; |
| 604 | } |
| 605 | |
| 606 | ignore_mount = 0; |
| 607 | |
Al Viro | 4c1d5a6 | 2011-12-07 18:21:57 -0500 | [diff] [blame] | 608 | parent = usbfs_mount->mnt_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | devices_usbfs_dentry = fs_create_file ("devices", |
| 610 | listmode | S_IFREG, parent, |
| 611 | NULL, &usbfs_devices_fops, |
| 612 | listuid, listgid); |
| 613 | if (devices_usbfs_dentry == NULL) { |
Greg Kroah-Hartman | 69a8594 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 614 | printk(KERN_ERR "Unable to create devices usbfs file\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | retval = -ENODEV; |
| 616 | goto error_clean_mounts; |
| 617 | } |
| 618 | |
| 619 | goto exit; |
| 620 | |
| 621 | error_clean_mounts: |
| 622 | simple_release_fs(&usbfs_mount, &usbfs_mount_count); |
| 623 | exit: |
| 624 | return retval; |
| 625 | } |
| 626 | |
| 627 | static void remove_special_files (void) |
| 628 | { |
| 629 | if (devices_usbfs_dentry) |
| 630 | fs_remove_file (devices_usbfs_dentry); |
| 631 | devices_usbfs_dentry = NULL; |
| 632 | simple_release_fs(&usbfs_mount, &usbfs_mount_count); |
| 633 | } |
| 634 | |
| 635 | void usbfs_update_special (void) |
| 636 | { |
| 637 | struct inode *inode; |
| 638 | |
| 639 | if (devices_usbfs_dentry) { |
| 640 | inode = devices_usbfs_dentry->d_inode; |
| 641 | if (inode) |
| 642 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 643 | } |
| 644 | } |
| 645 | |
Greg Kroah-Hartman | 54a5c4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 646 | static void usbfs_add_bus(struct usb_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | { |
| 648 | struct dentry *parent; |
| 649 | char name[8]; |
| 650 | int retval; |
| 651 | |
| 652 | /* create the special files if this is the first bus added */ |
| 653 | if (num_buses == 0) { |
| 654 | retval = create_special_files(); |
| 655 | if (retval) |
| 656 | return; |
| 657 | } |
| 658 | ++num_buses; |
| 659 | |
| 660 | sprintf (name, "%03d", bus->busnum); |
| 661 | |
Al Viro | 4c1d5a6 | 2011-12-07 18:21:57 -0500 | [diff] [blame] | 662 | parent = usbfs_mount->mnt_root; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 663 | bus->usbfs_dentry = fs_create_file (name, busmode | S_IFDIR, parent, |
| 664 | bus, NULL, busuid, busgid); |
| 665 | if (bus->usbfs_dentry == NULL) { |
Greg Kroah-Hartman | 69a8594 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 666 | printk(KERN_ERR "Error creating usbfs bus entry\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | return; |
| 668 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 669 | } |
| 670 | |
Greg Kroah-Hartman | 54a5c4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 671 | static void usbfs_remove_bus(struct usb_bus *bus) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 672 | { |
| 673 | if (bus->usbfs_dentry) { |
| 674 | fs_remove_file (bus->usbfs_dentry); |
| 675 | bus->usbfs_dentry = NULL; |
| 676 | } |
| 677 | |
| 678 | --num_buses; |
| 679 | if (num_buses <= 0) { |
| 680 | remove_special_files(); |
| 681 | num_buses = 0; |
| 682 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | } |
| 684 | |
Greg Kroah-Hartman | 54a5c4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 685 | static void usbfs_add_device(struct usb_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 686 | { |
| 687 | char name[8]; |
| 688 | int i; |
| 689 | int i_size; |
| 690 | |
| 691 | sprintf (name, "%03d", dev->devnum); |
| 692 | dev->usbfs_dentry = fs_create_file (name, devmode | S_IFREG, |
| 693 | dev->bus->usbfs_dentry, dev, |
Kay Sievers | 9f8b17e | 2007-03-13 15:59:31 +0100 | [diff] [blame] | 694 | &usbdev_file_operations, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | devuid, devgid); |
| 696 | if (dev->usbfs_dentry == NULL) { |
Greg Kroah-Hartman | 69a8594 | 2008-08-14 09:37:34 -0700 | [diff] [blame] | 697 | printk(KERN_ERR "Error creating usbfs device entry\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | return; |
| 699 | } |
| 700 | |
| 701 | /* Set the size of the device's file to be |
| 702 | * equal to the size of the device descriptors. */ |
| 703 | i_size = sizeof (struct usb_device_descriptor); |
| 704 | for (i = 0; i < dev->descriptor.bNumConfigurations; ++i) { |
| 705 | struct usb_config_descriptor *config = |
| 706 | (struct usb_config_descriptor *)dev->rawdescriptors[i]; |
| 707 | i_size += le16_to_cpu(config->wTotalLength); |
| 708 | } |
| 709 | if (dev->usbfs_dentry->d_inode) |
| 710 | dev->usbfs_dentry->d_inode->i_size = i_size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | } |
| 712 | |
Greg Kroah-Hartman | 54a5c4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 713 | static void usbfs_remove_device(struct usb_device *dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 715 | if (dev->usbfs_dentry) { |
| 716 | fs_remove_file (dev->usbfs_dentry); |
| 717 | dev->usbfs_dentry = NULL; |
| 718 | } |
Greg Kroah-Hartman | 54a5c4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 719 | } |
| 720 | |
| 721 | static int usbfs_notify(struct notifier_block *self, unsigned long action, void *dev) |
| 722 | { |
| 723 | switch (action) { |
| 724 | case USB_DEVICE_ADD: |
| 725 | usbfs_add_device(dev); |
| 726 | break; |
| 727 | case USB_DEVICE_REMOVE: |
| 728 | usbfs_remove_device(dev); |
| 729 | break; |
| 730 | case USB_BUS_ADD: |
| 731 | usbfs_add_bus(dev); |
| 732 | break; |
| 733 | case USB_BUS_REMOVE: |
| 734 | usbfs_remove_bus(dev); |
| 735 | } |
| 736 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | usbfs_update_special(); |
| 738 | usbfs_conn_disc_event(); |
Greg Kroah-Hartman | 54a5c4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 739 | return NOTIFY_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | } |
| 741 | |
Greg Kroah-Hartman | 54a5c4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 742 | static struct notifier_block usbfs_nb = { |
| 743 | .notifier_call = usbfs_notify, |
| 744 | }; |
| 745 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 746 | /* --------------------------------------------------------------------- */ |
| 747 | |
| 748 | static struct proc_dir_entry *usbdir = NULL; |
| 749 | |
| 750 | int __init usbfs_init(void) |
| 751 | { |
| 752 | int retval; |
| 753 | |
Kay Sievers | fbf82fd | 2005-07-31 01:05:53 +0200 | [diff] [blame] | 754 | retval = register_filesystem(&usb_fs_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 755 | if (retval) |
| 756 | return retval; |
| 757 | |
Greg Kroah-Hartman | 54a5c4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 758 | usb_register_notify(&usbfs_nb); |
| 759 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 760 | /* create mount point for usbfs */ |
Alexey Dobriyan | 9c37066 | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 761 | usbdir = proc_mkdir("bus/usb", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 762 | |
| 763 | return 0; |
| 764 | } |
| 765 | |
| 766 | void usbfs_cleanup(void) |
| 767 | { |
Greg Kroah-Hartman | 54a5c4c | 2005-06-20 21:15:16 -0700 | [diff] [blame] | 768 | usb_unregister_notify(&usbfs_nb); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 769 | unregister_filesystem(&usb_fs_type); |
| 770 | if (usbdir) |
Alexey Dobriyan | 9c37066 | 2008-04-29 01:01:41 -0700 | [diff] [blame] | 771 | remove_proc_entry("bus/usb", NULL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | } |
| 773 | |