diff options
| -rw-r--r-- | drivers/infiniband/hw/cxgb4/device.c | 35 | ||||
| -rw-r--r-- | drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c | 9 | ||||
| -rw-r--r-- | drivers/scsi/csiostor/csio_init.c | 9 | ||||
| -rw-r--r-- | drivers/usb/gadget/udc/atmel_usba_udc.c | 15 | ||||
| -rw-r--r-- | fs/debugfs/inode.c | 291 | ||||
| -rw-r--r-- | include/linux/debugfs.h | 18 |
6 files changed, 212 insertions, 165 deletions
diff --git a/drivers/infiniband/hw/cxgb4/device.c b/drivers/infiniband/hw/cxgb4/device.c index aafdbcd84fc4..8fb295e4a9ab 100644 --- a/drivers/infiniband/hw/cxgb4/device.c +++ b/drivers/infiniband/hw/cxgb4/device.c | |||
| @@ -700,37 +700,24 @@ static const struct file_operations ep_debugfs_fops = { | |||
| 700 | 700 | ||
| 701 | static int setup_debugfs(struct c4iw_dev *devp) | 701 | static int setup_debugfs(struct c4iw_dev *devp) |
| 702 | { | 702 | { |
| 703 | struct dentry *de; | ||
| 704 | |||
| 705 | if (!devp->debugfs_root) | 703 | if (!devp->debugfs_root) |
| 706 | return -1; | 704 | return -1; |
| 707 | 705 | ||
| 708 | de = debugfs_create_file("qps", S_IWUSR, devp->debugfs_root, | 706 | debugfs_create_file_size("qps", S_IWUSR, devp->debugfs_root, |
| 709 | (void *)devp, &qp_debugfs_fops); | 707 | (void *)devp, &qp_debugfs_fops, 4096); |
| 710 | if (de && de->d_inode) | ||
| 711 | de->d_inode->i_size = 4096; | ||
| 712 | 708 | ||
| 713 | de = debugfs_create_file("stags", S_IWUSR, devp->debugfs_root, | 709 | debugfs_create_file_size("stags", S_IWUSR, devp->debugfs_root, |
| 714 | (void *)devp, &stag_debugfs_fops); | 710 | (void *)devp, &stag_debugfs_fops, 4096); |
| 715 | if (de && de->d_inode) | ||
| 716 | de->d_inode->i_size = 4096; | ||
| 717 | 711 | ||
| 718 | de = debugfs_create_file("stats", S_IWUSR, devp->debugfs_root, | 712 | debugfs_create_file_size("stats", S_IWUSR, devp->debugfs_root, |
| 719 | (void *)devp, &stats_debugfs_fops); | 713 | (void *)devp, &stats_debugfs_fops, 4096); |
| 720 | if (de && de->d_inode) | ||
| 721 | de->d_inode->i_size = 4096; | ||
| 722 | 714 | ||
| 723 | de = debugfs_create_file("eps", S_IWUSR, devp->debugfs_root, | 715 | debugfs_create_file_size("eps", S_IWUSR, devp->debugfs_root, |
| 724 | (void *)devp, &ep_debugfs_fops); | 716 | (void *)devp, &ep_debugfs_fops, 4096); |
| 725 | if (de && de->d_inode) | ||
| 726 | de->d_inode->i_size = 4096; | ||
| 727 | 717 | ||
| 728 | if (c4iw_wr_log) { | 718 | if (c4iw_wr_log) |
| 729 | de = debugfs_create_file("wr_log", S_IWUSR, devp->debugfs_root, | 719 | debugfs_create_file_size("wr_log", S_IWUSR, devp->debugfs_root, |
| 730 | (void *)devp, &wr_log_debugfs_fops); | 720 | (void *)devp, &wr_log_debugfs_fops, 4096); |
| 731 | if (de && de->d_inode) | ||
| 732 | de->d_inode->i_size = 4096; | ||
| 733 | } | ||
| 734 | return 0; | 721 | return 0; |
| 735 | } | 722 | } |
| 736 | 723 | ||
diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c index d221f6b28fcd..78854ceb0870 100644 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_debugfs.c | |||
| @@ -1950,12 +1950,9 @@ static void set_debugfs_file_size(struct dentry *de, loff_t size) | |||
| 1950 | static void add_debugfs_mem(struct adapter *adap, const char *name, | 1950 | static void add_debugfs_mem(struct adapter *adap, const char *name, |
| 1951 | unsigned int idx, unsigned int size_mb) | 1951 | unsigned int idx, unsigned int size_mb) |
| 1952 | { | 1952 | { |
| 1953 | struct dentry *de; | 1953 | debugfs_create_file_size(name, S_IRUSR, adap->debugfs_root, |
| 1954 | 1954 | (void *)adap + idx, &mem_debugfs_fops, | |
| 1955 | de = debugfs_create_file(name, S_IRUSR, adap->debugfs_root, | 1955 | size_mb << 20); |
| 1956 | (void *)adap + idx, &mem_debugfs_fops); | ||
| 1957 | if (de && de->d_inode) | ||
| 1958 | de->d_inode->i_size = size_mb << 20; | ||
| 1959 | } | 1956 | } |
| 1960 | 1957 | ||
| 1961 | /* Add an array of Debug FS files. | 1958 | /* Add an array of Debug FS files. |
diff --git a/drivers/scsi/csiostor/csio_init.c b/drivers/scsi/csiostor/csio_init.c index 9b9794d42ffe..d9631e15f7b5 100644 --- a/drivers/scsi/csiostor/csio_init.c +++ b/drivers/scsi/csiostor/csio_init.c | |||
| @@ -113,12 +113,9 @@ static const struct file_operations csio_mem_debugfs_fops = { | |||
| 113 | void csio_add_debugfs_mem(struct csio_hw *hw, const char *name, | 113 | void csio_add_debugfs_mem(struct csio_hw *hw, const char *name, |
| 114 | unsigned int idx, unsigned int size_mb) | 114 | unsigned int idx, unsigned int size_mb) |
| 115 | { | 115 | { |
| 116 | struct dentry *de; | 116 | debugfs_create_file_size(name, S_IRUSR, hw->debugfs_root, |
| 117 | 117 | (void *)hw + idx, &csio_mem_debugfs_fops, | |
| 118 | de = debugfs_create_file(name, S_IRUSR, hw->debugfs_root, | 118 | size_mb << 20); |
| 119 | (void *)hw + idx, &csio_mem_debugfs_fops); | ||
| 120 | if (de && de->d_inode) | ||
| 121 | de->d_inode->i_size = size_mb << 20; | ||
| 122 | } | 119 | } |
| 123 | 120 | ||
| 124 | static int csio_setup_debugfs(struct csio_hw *hw) | 121 | static int csio_setup_debugfs(struct csio_hw *hw) |
diff --git a/drivers/usb/gadget/udc/atmel_usba_udc.c b/drivers/usb/gadget/udc/atmel_usba_udc.c index c0410862c2a1..d79cb35dbf8a 100644 --- a/drivers/usb/gadget/udc/atmel_usba_udc.c +++ b/drivers/usb/gadget/udc/atmel_usba_udc.c | |||
| @@ -265,14 +265,17 @@ static void usba_init_debugfs(struct usba_udc *udc) | |||
| 265 | goto err_root; | 265 | goto err_root; |
| 266 | udc->debugfs_root = root; | 266 | udc->debugfs_root = root; |
| 267 | 267 | ||
| 268 | regs = debugfs_create_file("regs", 0400, root, udc, ®s_dbg_fops); | ||
| 269 | if (!regs) | ||
| 270 | goto err_regs; | ||
| 271 | |||
| 272 | regs_resource = platform_get_resource(udc->pdev, IORESOURCE_MEM, | 268 | regs_resource = platform_get_resource(udc->pdev, IORESOURCE_MEM, |
| 273 | CTRL_IOMEM_ID); | 269 | CTRL_IOMEM_ID); |
| 274 | regs->d_inode->i_size = resource_size(regs_resource); | 270 | |
| 275 | udc->debugfs_regs = regs; | 271 | if (regs_resource) { |
| 272 | regs = debugfs_create_file_size("regs", 0400, root, udc, | ||
| 273 | ®s_dbg_fops, | ||
| 274 | resource_size(regs_resource)); | ||
| 275 | if (!regs) | ||
| 276 | goto err_regs; | ||
| 277 | udc->debugfs_regs = regs; | ||
| 278 | } | ||
| 276 | 279 | ||
| 277 | usba_ep_init_debugfs(udc, to_usba_ep(udc->gadget.ep0)); | 280 | usba_ep_init_debugfs(udc, to_usba_ep(udc->gadget.ep0)); |
| 278 | 281 | ||
diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index 05f2960ed7c3..45b18a5e225c 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c | |||
| @@ -34,93 +34,16 @@ static struct vfsmount *debugfs_mount; | |||
| 34 | static int debugfs_mount_count; | 34 | static int debugfs_mount_count; |
| 35 | static bool debugfs_registered; | 35 | static bool debugfs_registered; |
| 36 | 36 | ||
| 37 | static struct inode *debugfs_get_inode(struct super_block *sb, umode_t mode, dev_t dev, | 37 | static struct inode *debugfs_get_inode(struct super_block *sb) |
| 38 | void *data, const struct file_operations *fops) | ||
| 39 | |||
| 40 | { | 38 | { |
| 41 | struct inode *inode = new_inode(sb); | 39 | struct inode *inode = new_inode(sb); |
| 42 | |||
| 43 | if (inode) { | 40 | if (inode) { |
| 44 | inode->i_ino = get_next_ino(); | 41 | inode->i_ino = get_next_ino(); |
| 45 | inode->i_mode = mode; | ||
| 46 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; | 42 | inode->i_atime = inode->i_mtime = inode->i_ctime = CURRENT_TIME; |
| 47 | switch (mode & S_IFMT) { | ||
| 48 | default: | ||
| 49 | init_special_inode(inode, mode, dev); | ||
| 50 | break; | ||
| 51 | case S_IFREG: | ||
| 52 | inode->i_fop = fops ? fops : &debugfs_file_operations; | ||
| 53 | inode->i_private = data; | ||
| 54 | break; | ||
| 55 | case S_IFLNK: | ||
| 56 | inode->i_op = &debugfs_link_operations; | ||
| 57 | inode->i_private = data; | ||
| 58 | break; | ||
| 59 | case S_IFDIR: | ||
| 60 | inode->i_op = &simple_dir_inode_operations; | ||
| 61 | inode->i_fop = &simple_dir_operations; | ||
| 62 | |||
| 63 | /* directory inodes start off with i_nlink == 2 | ||
| 64 | * (for "." entry) */ | ||
| 65 | inc_nlink(inode); | ||
| 66 | break; | ||
| 67 | } | ||
| 68 | } | 43 | } |
| 69 | return inode; | 44 | return inode; |
| 70 | } | 45 | } |
| 71 | 46 | ||
| 72 | /* SMP-safe */ | ||
| 73 | static int debugfs_mknod(struct inode *dir, struct dentry *dentry, | ||
| 74 | umode_t mode, dev_t dev, void *data, | ||
| 75 | const struct file_operations *fops) | ||
| 76 | { | ||
| 77 | struct inode *inode; | ||
| 78 | int error = -EPERM; | ||
| 79 | |||
| 80 | if (dentry->d_inode) | ||
| 81 | return -EEXIST; | ||
| 82 | |||
| 83 | inode = debugfs_get_inode(dir->i_sb, mode, dev, data, fops); | ||
| 84 | if (inode) { | ||
| 85 | d_instantiate(dentry, inode); | ||
| 86 | dget(dentry); | ||
| 87 | error = 0; | ||
| 88 | } | ||
| 89 | return error; | ||
| 90 | } | ||
| 91 | |||
| 92 | static int debugfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) | ||
| 93 | { | ||
| 94 | int res; | ||
| 95 | |||
| 96 | mode = (mode & (S_IRWXUGO | S_ISVTX)) | S_IFDIR; | ||
| 97 | res = debugfs_mknod(dir, dentry, mode, 0, NULL, NULL); | ||
| 98 | if (!res) { | ||
| 99 | inc_nlink(dir); | ||
| 100 | fsnotify_mkdir(dir, dentry); | ||
| 101 | } | ||
| 102 | return res; | ||
| 103 | } | ||
| 104 | |||
| 105 | static int debugfs_link(struct inode *dir, struct dentry *dentry, umode_t mode, | ||
| 106 | void *data) | ||
| 107 | { | ||
| 108 | mode = (mode & S_IALLUGO) | S_IFLNK; | ||
| 109 | return debugfs_mknod(dir, dentry, mode, 0, data, NULL); | ||
| 110 | } | ||
| 111 | |||
| 112 | static int debugfs_create(struct inode *dir, struct dentry *dentry, umode_t mode, | ||
| 113 | void *data, const struct file_operations *fops) | ||
| 114 | { | ||
| 115 | int res; | ||
| 116 | |||
| 117 | mode = (mode & S_IALLUGO) | S_IFREG; | ||
| 118 | res = debugfs_mknod(dir, dentry, mode, 0, data, fops); | ||
| 119 | if (!res) | ||
| 120 | fsnotify_create(dir, dentry); | ||
| 121 | return res; | ||
| 122 | } | ||
| 123 | |||
| 124 | static inline int debugfs_positive(struct dentry *dentry) | 47 | static inline int debugfs_positive(struct dentry *dentry) |
| 125 | { | 48 | { |
| 126 | return dentry->d_inode && !d_unhashed(dentry); | 49 | return dentry->d_inode && !d_unhashed(dentry); |
| @@ -252,6 +175,18 @@ static const struct super_operations debugfs_super_operations = { | |||
| 252 | .show_options = debugfs_show_options, | 175 | .show_options = debugfs_show_options, |
| 253 | }; | 176 | }; |
| 254 | 177 | ||
| 178 | static struct vfsmount *debugfs_automount(struct path *path) | ||
| 179 | { | ||
| 180 | struct vfsmount *(*f)(void *); | ||
| 181 | f = (struct vfsmount *(*)(void *))path->dentry->d_fsdata; | ||
| 182 | return f(path->dentry->d_inode->i_private); | ||
| 183 | } | ||
| 184 | |||
| 185 | static const struct dentry_operations debugfs_dops = { | ||
| 186 | .d_delete = always_delete_dentry, | ||
| 187 | .d_automount = debugfs_automount, | ||
| 188 | }; | ||
| 189 | |||
| 255 | static int debug_fill_super(struct super_block *sb, void *data, int silent) | 190 | static int debug_fill_super(struct super_block *sb, void *data, int silent) |
| 256 | { | 191 | { |
| 257 | static struct tree_descr debug_files[] = {{""}}; | 192 | static struct tree_descr debug_files[] = {{""}}; |
| @@ -276,6 +211,7 @@ static int debug_fill_super(struct super_block *sb, void *data, int silent) | |||
| 276 | goto fail; | 211 | goto fail; |
| 277 | 212 | ||
| 278 | sb->s_op = &debugfs_super_operations; | 213 | sb->s_op = &debugfs_super_operations; |
| 214 | sb->s_d_op = &debugfs_dops; | ||
| 279 | 215 | ||
| 280 | debugfs_apply_options(sb); | 216 | debugfs_apply_options(sb); |
| 281 | 217 | ||
| @@ -302,11 +238,9 @@ static struct file_system_type debug_fs_type = { | |||
| 302 | }; | 238 | }; |
| 303 | MODULE_ALIAS_FS("debugfs"); | 239 | MODULE_ALIAS_FS("debugfs"); |
| 304 | 240 | ||
| 305 | static struct dentry *__create_file(const char *name, umode_t mode, | 241 | static struct dentry *start_creating(const char *name, struct dentry *parent) |
| 306 | struct dentry *parent, void *data, | ||
| 307 | const struct file_operations *fops) | ||
| 308 | { | 242 | { |
| 309 | struct dentry *dentry = NULL; | 243 | struct dentry *dentry; |
| 310 | int error; | 244 | int error; |
| 311 | 245 | ||
| 312 | pr_debug("debugfs: creating file '%s'\n",name); | 246 | pr_debug("debugfs: creating file '%s'\n",name); |
| @@ -314,7 +248,7 @@ static struct dentry *__create_file(const char *name, umode_t mode, | |||
| 314 | error = simple_pin_fs(&debug_fs_type, &debugfs_mount, | 248 | error = simple_pin_fs(&debug_fs_type, &debugfs_mount, |
| 315 | &debugfs_mount_count); | 249 | &debugfs_mount_count); |
| 316 | if (error) | 250 | if (error) |
| 317 | goto exit; | 251 | return ERR_PTR(error); |
| 318 | 252 | ||
| 319 | /* If the parent is not specified, we create it in the root. | 253 | /* If the parent is not specified, we create it in the root. |
| 320 | * We need the root dentry to do this, which is in the super | 254 | * We need the root dentry to do this, which is in the super |
| @@ -326,31 +260,26 @@ static struct dentry *__create_file(const char *name, umode_t mode, | |||
| 326 | 260 | ||
| 327 | mutex_lock(&parent->d_inode->i_mutex); | 261 | mutex_lock(&parent->d_inode->i_mutex); |
| 328 | dentry = lookup_one_len(name, parent, strlen(name)); | 262 | dentry = lookup_one_len(name, parent, strlen(name)); |
| 329 | if (!IS_ERR(dentry)) { | 263 | if (!IS_ERR(dentry) && dentry->d_inode) { |
| 330 | switch (mode & S_IFMT) { | ||
| 331 | case S_IFDIR: | ||
| 332 | error = debugfs_mkdir(parent->d_inode, dentry, mode); | ||
| 333 | |||
| 334 | break; | ||
| 335 | case S_IFLNK: | ||
| 336 | error = debugfs_link(parent->d_inode, dentry, mode, | ||
| 337 | data); | ||
| 338 | break; | ||
| 339 | default: | ||
| 340 | error = debugfs_create(parent->d_inode, dentry, mode, | ||
| 341 | data, fops); | ||
| 342 | break; | ||
| 343 | } | ||
| 344 | dput(dentry); | 264 | dput(dentry); |
| 345 | } else | 265 | dentry = ERR_PTR(-EEXIST); |
| 346 | error = PTR_ERR(dentry); | ||
| 347 | mutex_unlock(&parent->d_inode->i_mutex); | ||
| 348 | |||
| 349 | if (error) { | ||
| 350 | dentry = NULL; | ||
| 351 | simple_release_fs(&debugfs_mount, &debugfs_mount_count); | ||
| 352 | } | 266 | } |
| 353 | exit: | 267 | if (IS_ERR(dentry)) |
| 268 | mutex_unlock(&parent->d_inode->i_mutex); | ||
| 269 | return dentry; | ||
| 270 | } | ||
| 271 | |||
| 272 | static struct dentry *failed_creating(struct dentry *dentry) | ||
| 273 | { | ||
| 274 | mutex_unlock(&dentry->d_parent->d_inode->i_mutex); | ||
| 275 | dput(dentry); | ||
| 276 | simple_release_fs(&debugfs_mount, &debugfs_mount_count); | ||
| 277 | return NULL; | ||
| 278 | } | ||
| 279 | |||
| 280 | static struct dentry *end_creating(struct dentry *dentry) | ||
| 281 | { | ||
| 282 | mutex_unlock(&dentry->d_parent->d_inode->i_mutex); | ||
| 354 | return dentry; | 283 | return dentry; |
| 355 | } | 284 | } |
| 356 | 285 | ||
| @@ -384,19 +313,71 @@ struct dentry *debugfs_create_file(const char *name, umode_t mode, | |||
| 384 | struct dentry *parent, void *data, | 313 | struct dentry *parent, void *data, |
| 385 | const struct file_operations *fops) | 314 | const struct file_operations *fops) |
| 386 | { | 315 | { |
| 387 | switch (mode & S_IFMT) { | 316 | struct dentry *dentry; |
| 388 | case S_IFREG: | 317 | struct inode *inode; |
| 389 | case 0: | 318 | |
| 390 | break; | 319 | if (!(mode & S_IFMT)) |
| 391 | default: | 320 | mode |= S_IFREG; |
| 392 | BUG(); | 321 | BUG_ON(!S_ISREG(mode)); |
| 393 | } | 322 | dentry = start_creating(name, parent); |
| 323 | |||
| 324 | if (IS_ERR(dentry)) | ||
| 325 | return NULL; | ||
| 394 | 326 | ||
| 395 | return __create_file(name, mode, parent, data, fops); | 327 | inode = debugfs_get_inode(dentry->d_sb); |
| 328 | if (unlikely(!inode)) | ||
| 329 | return failed_creating(dentry); | ||
| 330 | |||
| 331 | inode->i_mode = mode; | ||
| 332 | inode->i_fop = fops ? fops : &debugfs_file_operations; | ||
| 333 | inode->i_private = data; | ||
| 334 | d_instantiate(dentry, inode); | ||
| 335 | fsnotify_create(dentry->d_parent->d_inode, dentry); | ||
| 336 | return end_creating(dentry); | ||
| 396 | } | 337 | } |
| 397 | EXPORT_SYMBOL_GPL(debugfs_create_file); | 338 | EXPORT_SYMBOL_GPL(debugfs_create_file); |
| 398 | 339 | ||
| 399 | /** | 340 | /** |
| 341 | * debugfs_create_file_size - create a file in the debugfs filesystem | ||
| 342 | * @name: a pointer to a string containing the name of the file to create. | ||
| 343 | * @mode: the permission that the file should have. | ||
| 344 | * @parent: a pointer to the parent dentry for this file. This should be a | ||
| 345 | * directory dentry if set. If this parameter is NULL, then the | ||
| 346 | * file will be created in the root of the debugfs filesystem. | ||
| 347 | * @data: a pointer to something that the caller will want to get to later | ||
| 348 | * on. The inode.i_private pointer will point to this value on | ||
| 349 | * the open() call. | ||
| 350 | * @fops: a pointer to a struct file_operations that should be used for | ||
| 351 | * this file. | ||
| 352 | * @file_size: initial file size | ||
| 353 | * | ||
| 354 | * This is the basic "create a file" function for debugfs. It allows for a | ||
| 355 | * wide range of flexibility in creating a file, or a directory (if you want | ||
| 356 | * to create a directory, the debugfs_create_dir() function is | ||
| 357 | * recommended to be used instead.) | ||
| 358 | * | ||
| 359 | * This function will return a pointer to a dentry if it succeeds. This | ||
| 360 | * pointer must be passed to the debugfs_remove() function when the file is | ||
| 361 | * to be removed (no automatic cleanup happens if your module is unloaded, | ||
| 362 | * you are responsible here.) If an error occurs, %NULL will be returned. | ||
| 363 | * | ||
| 364 | * If debugfs is not enabled in the kernel, the value -%ENODEV will be | ||
| 365 | * returned. | ||
| 366 | */ | ||
| 367 | struct dentry *debugfs_create_file_size(const char *name, umode_t mode, | ||
| 368 | struct dentry *parent, void *data, | ||
| 369 | const struct file_operations *fops, | ||
| 370 | loff_t file_size) | ||
| 371 | { | ||
| 372 | struct dentry *de = debugfs_create_file(name, mode, parent, data, fops); | ||
| 373 | |||
| 374 | if (de) | ||
| 375 | de->d_inode->i_size = file_size; | ||
| 376 | return de; | ||
| 377 | } | ||
| 378 | EXPORT_SYMBOL_GPL(debugfs_create_file_size); | ||
| 379 | |||
| 380 | /** | ||
| 400 | * debugfs_create_dir - create a directory in the debugfs filesystem | 381 | * debugfs_create_dir - create a directory in the debugfs filesystem |
| 401 | * @name: a pointer to a string containing the name of the directory to | 382 | * @name: a pointer to a string containing the name of the directory to |
| 402 | * create. | 383 | * create. |
| @@ -416,12 +397,65 @@ EXPORT_SYMBOL_GPL(debugfs_create_file); | |||
| 416 | */ | 397 | */ |
| 417 | struct dentry *debugfs_create_dir(const char *name, struct dentry *parent) | 398 | struct dentry *debugfs_create_dir(const char *name, struct dentry *parent) |
| 418 | { | 399 | { |
| 419 | return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO, | 400 | struct dentry *dentry = start_creating(name, parent); |
| 420 | parent, NULL, NULL); | 401 | struct inode *inode; |
| 402 | |||
| 403 | if (IS_ERR(dentry)) | ||
| 404 | return NULL; | ||
| 405 | |||
| 406 | inode = debugfs_get_inode(dentry->d_sb); | ||
| 407 | if (unlikely(!inode)) | ||
| 408 | return failed_creating(dentry); | ||
| 409 | |||
| 410 | inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; | ||
| 411 | inode->i_op = &simple_dir_inode_operations; | ||
| 412 | inode->i_fop = &simple_dir_operations; | ||
| 413 | |||
| 414 | /* directory inodes start off with i_nlink == 2 (for "." entry) */ | ||
| 415 | inc_nlink(inode); | ||
| 416 | d_instantiate(dentry, inode); | ||
| 417 | inc_nlink(dentry->d_parent->d_inode); | ||
| 418 | fsnotify_mkdir(dentry->d_parent->d_inode, dentry); | ||
| 419 | return end_creating(dentry); | ||
| 421 | } | 420 | } |
| 422 | EXPORT_SYMBOL_GPL(debugfs_create_dir); | 421 | EXPORT_SYMBOL_GPL(debugfs_create_dir); |
| 423 | 422 | ||
| 424 | /** | 423 | /** |
| 424 | * debugfs_create_automount - create automount point in the debugfs filesystem | ||
| 425 | * @name: a pointer to a string containing the name of the file to create. | ||
| 426 | * @parent: a pointer to the parent dentry for this file. This should be a | ||
| 427 | * directory dentry if set. If this parameter is NULL, then the | ||
| 428 | * file will be created in the root of the debugfs filesystem. | ||
| 429 | * @f: function to be called when pathname resolution steps on that one. | ||
| 430 | * @data: opaque argument to pass to f(). | ||
| 431 | * | ||
| 432 | * @f should return what ->d_automount() would. | ||
| 433 | */ | ||
| 434 | struct dentry *debugfs_create_automount(const char *name, | ||
| 435 | struct dentry *parent, | ||
| 436 | struct vfsmount *(*f)(void *), | ||
| 437 | void *data) | ||
| 438 | { | ||
| 439 | struct dentry *dentry = start_creating(name, parent); | ||
| 440 | struct inode *inode; | ||
| 441 | |||
| 442 | if (IS_ERR(dentry)) | ||
| 443 | return NULL; | ||
| 444 | |||
| 445 | inode = debugfs_get_inode(dentry->d_sb); | ||
| 446 | if (unlikely(!inode)) | ||
| 447 | return failed_creating(dentry); | ||
| 448 | |||
| 449 | inode->i_mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO; | ||
| 450 | inode->i_flags |= S_AUTOMOUNT; | ||
| 451 | inode->i_private = data; | ||
| 452 | dentry->d_fsdata = (void *)f; | ||
| 453 | d_instantiate(dentry, inode); | ||
| 454 | return end_creating(dentry); | ||
| 455 | } | ||
| 456 | EXPORT_SYMBOL(debugfs_create_automount); | ||
| 457 | |||
| 458 | /** | ||
| 425 | * debugfs_create_symlink- create a symbolic link in the debugfs filesystem | 459 | * debugfs_create_symlink- create a symbolic link in the debugfs filesystem |
| 426 | * @name: a pointer to a string containing the name of the symbolic link to | 460 | * @name: a pointer to a string containing the name of the symbolic link to |
| 427 | * create. | 461 | * create. |
| @@ -447,17 +481,28 @@ EXPORT_SYMBOL_GPL(debugfs_create_dir); | |||
| 447 | struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent, | 481 | struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent, |
| 448 | const char *target) | 482 | const char *target) |
| 449 | { | 483 | { |
| 450 | struct dentry *result; | 484 | struct dentry *dentry; |
| 451 | char *link; | 485 | struct inode *inode; |
| 452 | 486 | char *link = kstrdup(target, GFP_KERNEL); | |
| 453 | link = kstrdup(target, GFP_KERNEL); | ||
| 454 | if (!link) | 487 | if (!link) |
| 455 | return NULL; | 488 | return NULL; |
| 456 | 489 | ||
| 457 | result = __create_file(name, S_IFLNK | S_IRWXUGO, parent, link, NULL); | 490 | dentry = start_creating(name, parent); |
| 458 | if (!result) | 491 | if (IS_ERR(dentry)) { |
| 459 | kfree(link); | 492 | kfree(link); |
| 460 | return result; | 493 | return NULL; |
| 494 | } | ||
| 495 | |||
| 496 | inode = debugfs_get_inode(dentry->d_sb); | ||
| 497 | if (unlikely(!inode)) { | ||
| 498 | kfree(link); | ||
| 499 | return failed_creating(dentry); | ||
| 500 | } | ||
| 501 | inode->i_mode = S_IFLNK | S_IRWXUGO; | ||
| 502 | inode->i_op = &debugfs_link_operations; | ||
| 503 | inode->i_private = link; | ||
| 504 | d_instantiate(dentry, inode); | ||
| 505 | return end_creating(dentry); | ||
| 461 | } | 506 | } |
| 462 | EXPORT_SYMBOL_GPL(debugfs_create_symlink); | 507 | EXPORT_SYMBOL_GPL(debugfs_create_symlink); |
| 463 | 508 | ||
diff --git a/include/linux/debugfs.h b/include/linux/debugfs.h index da4c4983adbe..cb25af461054 100644 --- a/include/linux/debugfs.h +++ b/include/linux/debugfs.h | |||
| @@ -51,11 +51,21 @@ struct dentry *debugfs_create_file(const char *name, umode_t mode, | |||
| 51 | struct dentry *parent, void *data, | 51 | struct dentry *parent, void *data, |
| 52 | const struct file_operations *fops); | 52 | const struct file_operations *fops); |
| 53 | 53 | ||
| 54 | struct dentry *debugfs_create_file_size(const char *name, umode_t mode, | ||
| 55 | struct dentry *parent, void *data, | ||
| 56 | const struct file_operations *fops, | ||
| 57 | loff_t file_size); | ||
| 58 | |||
| 54 | struct dentry *debugfs_create_dir(const char *name, struct dentry *parent); | 59 | struct dentry *debugfs_create_dir(const char *name, struct dentry *parent); |
| 55 | 60 | ||
| 56 | struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent, | 61 | struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent, |
| 57 | const char *dest); | 62 | const char *dest); |
| 58 | 63 | ||
| 64 | struct dentry *debugfs_create_automount(const char *name, | ||
| 65 | struct dentry *parent, | ||
| 66 | struct vfsmount *(*f)(void *), | ||
| 67 | void *data); | ||
| 68 | |||
| 59 | void debugfs_remove(struct dentry *dentry); | 69 | void debugfs_remove(struct dentry *dentry); |
| 60 | void debugfs_remove_recursive(struct dentry *dentry); | 70 | void debugfs_remove_recursive(struct dentry *dentry); |
| 61 | 71 | ||
| @@ -124,6 +134,14 @@ static inline struct dentry *debugfs_create_file(const char *name, umode_t mode, | |||
| 124 | return ERR_PTR(-ENODEV); | 134 | return ERR_PTR(-ENODEV); |
| 125 | } | 135 | } |
| 126 | 136 | ||
| 137 | static inline struct dentry *debugfs_create_file_size(const char *name, umode_t mode, | ||
| 138 | struct dentry *parent, void *data, | ||
| 139 | const struct file_operations *fops, | ||
| 140 | loff_t file_size) | ||
| 141 | { | ||
| 142 | return ERR_PTR(-ENODEV); | ||
| 143 | } | ||
| 144 | |||
| 127 | static inline struct dentry *debugfs_create_dir(const char *name, | 145 | static inline struct dentry *debugfs_create_dir(const char *name, |
| 128 | struct dentry *parent) | 146 | struct dentry *parent) |
| 129 | { | 147 | { |
