diff options
author | Joel Becker <joel.becker@oracle.com> | 2006-09-13 14:01:19 -0400 |
---|---|---|
committer | Mark Fasheh <mark.fasheh@oracle.com> | 2006-09-20 18:46:14 -0400 |
commit | b4c98f625fffee3a6f633082e9e4be3e952ca2ab (patch) | |
tree | ff7832706aeab7b16cbe18dd7976be7b56c49e55 /fs/configfs/dir.c | |
parent | e478bec0ba0a83a48a0f6982934b6de079e7e6b3 (diff) |
configfs: Prevent duplicate subsystem names.
For all child objects, creation comes through mkdir(2), so duplicate names
are prevented.
Subsystems, though, are registered by client drivers at init_module()/__init
time. This patch prevents duplicate subsystem names.
Signed-off-by: Joel Becker <joel.becker@oracle.com>
Signed-off-by: Mark Fasheh <mark.fasheh@oracle.com>
Diffstat (limited to 'fs/configfs/dir.c')
-rw-r--r-- | fs/configfs/dir.c | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c index df025453dd97..816e8ef64560 100644 --- a/fs/configfs/dir.c +++ b/fs/configfs/dir.c | |||
@@ -86,6 +86,32 @@ static struct configfs_dirent *configfs_new_dirent(struct configfs_dirent * pare | |||
86 | return sd; | 86 | return sd; |
87 | } | 87 | } |
88 | 88 | ||
89 | /* | ||
90 | * | ||
91 | * Return -EEXIST if there is already a configfs element with the same | ||
92 | * name for the same parent. | ||
93 | * | ||
94 | * called with parent inode's i_mutex held | ||
95 | */ | ||
96 | int configfs_dirent_exists(struct configfs_dirent *parent_sd, | ||
97 | const unsigned char *new) | ||
98 | { | ||
99 | struct configfs_dirent * sd; | ||
100 | |||
101 | list_for_each_entry(sd, &parent_sd->s_children, s_sibling) { | ||
102 | if (sd->s_element) { | ||
103 | const unsigned char *existing = configfs_get_name(sd); | ||
104 | if (strcmp(existing, new)) | ||
105 | continue; | ||
106 | else | ||
107 | return -EEXIST; | ||
108 | } | ||
109 | } | ||
110 | |||
111 | return 0; | ||
112 | } | ||
113 | |||
114 | |||
89 | int configfs_make_dirent(struct configfs_dirent * parent_sd, | 115 | int configfs_make_dirent(struct configfs_dirent * parent_sd, |
90 | struct dentry * dentry, void * element, | 116 | struct dentry * dentry, void * element, |
91 | umode_t mode, int type) | 117 | umode_t mode, int type) |
@@ -136,8 +162,10 @@ static int create_dir(struct config_item * k, struct dentry * p, | |||
136 | int error; | 162 | int error; |
137 | umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO; | 163 | umode_t mode = S_IFDIR| S_IRWXU | S_IRUGO | S_IXUGO; |
138 | 164 | ||
139 | error = configfs_make_dirent(p->d_fsdata, d, k, mode, | 165 | error = configfs_dirent_exists(p->d_fsdata, d->d_name.name); |
140 | CONFIGFS_DIR); | 166 | if (!error) |
167 | error = configfs_make_dirent(p->d_fsdata, d, k, mode, | ||
168 | CONFIGFS_DIR); | ||
141 | if (!error) { | 169 | if (!error) { |
142 | error = configfs_create(d, mode, init_dir); | 170 | error = configfs_create(d, mode, init_dir); |
143 | if (!error) { | 171 | if (!error) { |