aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2018-04-24 11:08:36 -0400
committerChristoph Hellwig <hch@lst.de>2018-05-16 01:23:35 -0400
commit7aed53d1dfd14d468e065212ce45068e2b50c1fa (patch)
tree4fc1d297c3c308d37222e350f0a54f7bb100045e
parent61172eaea1adf64a77e563b0cb30d7ee88d9aa80 (diff)
proc: add a proc_create_reg helper
Common code for creating a regular file. Factor out of proc_create_data, to be reused by other functions soon. Signed-off-by: Christoph Hellwig <hch@lst.de>
-rw-r--r--fs/proc/generic.c44
-rw-r--r--fs/proc/internal.h2
2 files changed, 27 insertions, 19 deletions
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index bd8480ff0d35..ab6a321076b8 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -511,33 +511,39 @@ struct proc_dir_entry *proc_create_mount_point(const char *name)
511} 511}
512EXPORT_SYMBOL(proc_create_mount_point); 512EXPORT_SYMBOL(proc_create_mount_point);
513 513
514struct proc_dir_entry *proc_create_data(const char *name, umode_t mode, 514struct proc_dir_entry *proc_create_reg(const char *name, umode_t mode,
515 struct proc_dir_entry *parent, 515 struct proc_dir_entry **parent, void *data)
516 const struct file_operations *proc_fops,
517 void *data)
518{ 516{
519 struct proc_dir_entry *pde; 517 struct proc_dir_entry *p;
518
520 if ((mode & S_IFMT) == 0) 519 if ((mode & S_IFMT) == 0)
521 mode |= S_IFREG; 520 mode |= S_IFREG;
522 521 if ((mode & S_IALLUGO) == 0)
523 if (!S_ISREG(mode)) { 522 mode |= S_IRUGO;
524 WARN_ON(1); /* use proc_mkdir() */ 523 if (WARN_ON_ONCE(!S_ISREG(mode)))
525 return NULL; 524 return NULL;
525
526 p = __proc_create(parent, name, mode, 1);
527 if (p) {
528 p->proc_iops = &proc_file_inode_operations;
529 p->data = data;
526 } 530 }
531 return p;
532}
533
534struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
535 struct proc_dir_entry *parent,
536 const struct file_operations *proc_fops, void *data)
537{
538 struct proc_dir_entry *p;
527 539
528 BUG_ON(proc_fops == NULL); 540 BUG_ON(proc_fops == NULL);
529 541
530 if ((mode & S_IALLUGO) == 0) 542 p = proc_create_reg(name, mode, &parent, data);
531 mode |= S_IRUGO; 543 if (!p)
532 pde = __proc_create(&parent, name, mode, 1); 544 return NULL;
533 if (!pde) 545 p->proc_fops = proc_fops;
534 goto out; 546 return proc_register(parent, p);
535 pde->proc_fops = proc_fops;
536 pde->data = data;
537 pde->proc_iops = &proc_file_inode_operations;
538 return proc_register(parent, pde);
539out:
540 return NULL;
541} 547}
542EXPORT_SYMBOL(proc_create_data); 548EXPORT_SYMBOL(proc_create_data);
543 549
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 488e67490312..dd1e11400b97 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -162,6 +162,8 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
162/* 162/*
163 * generic.c 163 * generic.c
164 */ 164 */
165struct proc_dir_entry *proc_create_reg(const char *name, umode_t mode,
166 struct proc_dir_entry **parent, void *data);
165struct proc_dir_entry *proc_register(struct proc_dir_entry *dir, 167struct proc_dir_entry *proc_register(struct proc_dir_entry *dir,
166 struct proc_dir_entry *dp); 168 struct proc_dir_entry *dp);
167extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int); 169extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);