gpio: adp5588-gpio: support interrupt controller
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / fs / minix / namei.c
blobc0d35a3accef98dd5ed7619214146e0f0f5d3260
1 /*
2 * linux/fs/minix/namei.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
5 */
7 #include "minix.h"
9 static int add_nondir(struct dentry *dentry, struct inode *inode)
11 int err = minix_add_link(dentry, inode);
12 if (!err) {
13 d_instantiate(dentry, inode);
14 return 0;
16 inode_dec_link_count(inode);
17 iput(inode);
18 return err;
21 static struct dentry *minix_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
23 struct inode * inode = NULL;
24 ino_t ino;
26 dentry->d_op = dir->i_sb->s_root->d_op;
28 if (dentry->d_name.len > minix_sb(dir->i_sb)->s_namelen)
29 return ERR_PTR(-ENAMETOOLONG);
31 ino = minix_inode_by_name(dentry);
32 if (ino) {
33 inode = minix_iget(dir->i_sb, ino);
34 if (IS_ERR(inode))
35 return ERR_CAST(inode);
37 d_add(dentry, inode);
38 return NULL;
41 static int minix_mknod(struct inode * dir, struct dentry *dentry, int mode, dev_t rdev)
43 int error;
44 struct inode *inode;
46 if (!old_valid_dev(rdev))
47 return -EINVAL;
49 inode = minix_new_inode(dir, mode, &error);
51 if (inode) {
52 minix_set_inode(inode, rdev);
53 mark_inode_dirty(inode);
54 error = add_nondir(dentry, inode);
56 return error;
59 static int minix_create(struct inode * dir, struct dentry *dentry, int mode,
60 struct nameidata *nd)
62 return minix_mknod(dir, dentry, mode, 0);
65 static int minix_symlink(struct inode * dir, struct dentry *dentry,
66 const char * symname)
68 int err = -ENAMETOOLONG;
69 int i = strlen(symname)+1;
70 struct inode * inode;
72 if (i > dir->i_sb->s_blocksize)
73 goto out;
75 inode = minix_new_inode(dir, S_IFLNK | 0777, &err);
76 if (!inode)
77 goto out;
79 minix_set_inode(inode, 0);
80 err = page_symlink(inode, symname, i);
81 if (err)
82 goto out_fail;
84 err = add_nondir(dentry, inode);
85 out:
86 return err;
88 out_fail:
89 inode_dec_link_count(inode);
90 iput(inode);
91 goto out;
94 static int minix_link(struct dentry * old_dentry, struct inode * dir,
95 struct dentry *dentry)
97 struct inode *inode = old_dentry->d_inode;
99 if (inode->i_nlink >= minix_sb(inode->i_sb)->s_link_max)
100 return -EMLINK;
102 inode->i_ctime = CURRENT_TIME_SEC;
103 inode_inc_link_count(inode);
104 ihold(inode);
105 return add_nondir(dentry, inode);
108 static int minix_mkdir(struct inode * dir, struct dentry *dentry, int mode)
110 struct inode * inode;
111 int err = -EMLINK;
113 if (dir->i_nlink >= minix_sb(dir->i_sb)->s_link_max)
114 goto out;
116 inode_inc_link_count(dir);
118 inode = minix_new_inode(dir, S_IFDIR | mode, &err);
119 if (!inode)
120 goto out_dir;
122 minix_set_inode(inode, 0);
124 inode_inc_link_count(inode);
126 err = minix_make_empty(inode, dir);
127 if (err)
128 goto out_fail;
130 err = minix_add_link(dentry, inode);
131 if (err)
132 goto out_fail;
134 d_instantiate(dentry, inode);
135 out:
136 return err;
138 out_fail:
139 inode_dec_link_count(inode);
140 inode_dec_link_count(inode);
141 iput(inode);
142 out_dir:
143 inode_dec_link_count(dir);
144 goto out;
147 static int minix_unlink(struct inode * dir, struct dentry *dentry)
149 int err = -ENOENT;
150 struct inode * inode = dentry->d_inode;
151 struct page * page;
152 struct minix_dir_entry * de;
154 de = minix_find_entry(dentry, &page);
155 if (!de)
156 goto end_unlink;
158 err = minix_delete_entry(de, page);
159 if (err)
160 goto end_unlink;
162 inode->i_ctime = dir->i_ctime;
163 inode_dec_link_count(inode);
164 end_unlink:
165 return err;
168 static int minix_rmdir(struct inode * dir, struct dentry *dentry)
170 struct inode * inode = dentry->d_inode;
171 int err = -ENOTEMPTY;
173 if (minix_empty_dir(inode)) {
174 err = minix_unlink(dir, dentry);
175 if (!err) {
176 inode_dec_link_count(dir);
177 inode_dec_link_count(inode);
180 return err;
183 static int minix_rename(struct inode * old_dir, struct dentry *old_dentry,
184 struct inode * new_dir, struct dentry *new_dentry)
186 struct minix_sb_info * info = minix_sb(old_dir->i_sb);
187 struct inode * old_inode = old_dentry->d_inode;
188 struct inode * new_inode = new_dentry->d_inode;
189 struct page * dir_page = NULL;
190 struct minix_dir_entry * dir_de = NULL;
191 struct page * old_page;
192 struct minix_dir_entry * old_de;
193 int err = -ENOENT;
195 old_de = minix_find_entry(old_dentry, &old_page);
196 if (!old_de)
197 goto out;
199 if (S_ISDIR(old_inode->i_mode)) {
200 err = -EIO;
201 dir_de = minix_dotdot(old_inode, &dir_page);
202 if (!dir_de)
203 goto out_old;
206 if (new_inode) {
207 struct page * new_page;
208 struct minix_dir_entry * new_de;
210 err = -ENOTEMPTY;
211 if (dir_de && !minix_empty_dir(new_inode))
212 goto out_dir;
214 err = -ENOENT;
215 new_de = minix_find_entry(new_dentry, &new_page);
216 if (!new_de)
217 goto out_dir;
218 inode_inc_link_count(old_inode);
219 minix_set_link(new_de, new_page, old_inode);
220 new_inode->i_ctime = CURRENT_TIME_SEC;
221 if (dir_de)
222 drop_nlink(new_inode);
223 inode_dec_link_count(new_inode);
224 } else {
225 if (dir_de) {
226 err = -EMLINK;
227 if (new_dir->i_nlink >= info->s_link_max)
228 goto out_dir;
230 inode_inc_link_count(old_inode);
231 err = minix_add_link(new_dentry, old_inode);
232 if (err) {
233 inode_dec_link_count(old_inode);
234 goto out_dir;
236 if (dir_de)
237 inode_inc_link_count(new_dir);
240 minix_delete_entry(old_de, old_page);
241 inode_dec_link_count(old_inode);
243 if (dir_de) {
244 minix_set_link(dir_de, dir_page, new_dir);
245 inode_dec_link_count(old_dir);
247 return 0;
249 out_dir:
250 if (dir_de) {
251 kunmap(dir_page);
252 page_cache_release(dir_page);
254 out_old:
255 kunmap(old_page);
256 page_cache_release(old_page);
257 out:
258 return err;
262 * directories can handle most operations...
264 const struct inode_operations minix_dir_inode_operations = {
265 .create = minix_create,
266 .lookup = minix_lookup,
267 .link = minix_link,
268 .unlink = minix_unlink,
269 .symlink = minix_symlink,
270 .mkdir = minix_mkdir,
271 .rmdir = minix_rmdir,
272 .mknod = minix_mknod,
273 .rename = minix_rename,
274 .getattr = minix_getattr,