2 * linux/fs/minix/namei.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
9 static int add_nondir(struct dentry *dentry, struct inode *inode)
11 int err = minix_add_link(dentry, inode);
13 d_instantiate(dentry, inode);
16 inode_dec_link_count(inode);
21 static struct dentry *minix_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
23 struct inode * inode = NULL;
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);
33 inode = minix_iget(dir->i_sb, ino);
35 return ERR_CAST(inode);
41 static int minix_mknod(struct inode * dir, struct dentry *dentry, int mode, dev_t rdev)
46 if (!old_valid_dev(rdev))
49 inode = minix_new_inode(dir, &error);
53 minix_set_inode(inode, rdev);
54 mark_inode_dirty(inode);
55 error = add_nondir(dentry, inode);
60 static int minix_create(struct inode * dir, struct dentry *dentry, int mode,
63 return minix_mknod(dir, dentry, mode, 0);
66 static int minix_symlink(struct inode * dir, struct dentry *dentry,
69 int err = -ENAMETOOLONG;
70 int i = strlen(symname)+1;
73 if (i > dir->i_sb->s_blocksize)
76 inode = minix_new_inode(dir, &err);
80 inode->i_mode = S_IFLNK | 0777;
81 minix_set_inode(inode, 0);
82 err = page_symlink(inode, symname, i);
86 err = add_nondir(dentry, inode);
91 inode_dec_link_count(inode);
96 static int minix_link(struct dentry * old_dentry, struct inode * dir,
97 struct dentry *dentry)
99 struct inode *inode = old_dentry->d_inode;
101 if (inode->i_nlink >= minix_sb(inode->i_sb)->s_link_max)
104 inode->i_ctime = CURRENT_TIME_SEC;
105 inode_inc_link_count(inode);
106 atomic_inc(&inode->i_count);
107 return add_nondir(dentry, inode);
110 static int minix_mkdir(struct inode * dir, struct dentry *dentry, int mode)
112 struct inode * inode;
115 if (dir->i_nlink >= minix_sb(dir->i_sb)->s_link_max)
118 inode_inc_link_count(dir);
120 inode = minix_new_inode(dir, &err);
124 inode->i_mode = S_IFDIR | mode;
125 if (dir->i_mode & S_ISGID)
126 inode->i_mode |= S_ISGID;
127 minix_set_inode(inode, 0);
129 inode_inc_link_count(inode);
131 err = minix_make_empty(inode, dir);
135 err = minix_add_link(dentry, inode);
139 d_instantiate(dentry, inode);
144 inode_dec_link_count(inode);
145 inode_dec_link_count(inode);
148 inode_dec_link_count(dir);
152 static int minix_unlink(struct inode * dir, struct dentry *dentry)
155 struct inode * inode = dentry->d_inode;
157 struct minix_dir_entry * de;
159 de = minix_find_entry(dentry, &page);
163 err = minix_delete_entry(de, page);
167 inode->i_ctime = dir->i_ctime;
168 inode_dec_link_count(inode);
173 static int minix_rmdir(struct inode * dir, struct dentry *dentry)
175 struct inode * inode = dentry->d_inode;
176 int err = -ENOTEMPTY;
178 if (minix_empty_dir(inode)) {
179 err = minix_unlink(dir, dentry);
181 inode_dec_link_count(dir);
182 inode_dec_link_count(inode);
188 static int minix_rename(struct inode * old_dir, struct dentry *old_dentry,
189 struct inode * new_dir, struct dentry *new_dentry)
191 struct minix_sb_info * info = minix_sb(old_dir->i_sb);
192 struct inode * old_inode = old_dentry->d_inode;
193 struct inode * new_inode = new_dentry->d_inode;
194 struct page * dir_page = NULL;
195 struct minix_dir_entry * dir_de = NULL;
196 struct page * old_page;
197 struct minix_dir_entry * old_de;
200 old_de = minix_find_entry(old_dentry, &old_page);
204 if (S_ISDIR(old_inode->i_mode)) {
206 dir_de = minix_dotdot(old_inode, &dir_page);
212 struct page * new_page;
213 struct minix_dir_entry * new_de;
216 if (dir_de && !minix_empty_dir(new_inode))
220 new_de = minix_find_entry(new_dentry, &new_page);
223 inode_inc_link_count(old_inode);
224 minix_set_link(new_de, new_page, old_inode);
225 new_inode->i_ctime = CURRENT_TIME_SEC;
227 drop_nlink(new_inode);
228 inode_dec_link_count(new_inode);
232 if (new_dir->i_nlink >= info->s_link_max)
235 inode_inc_link_count(old_inode);
236 err = minix_add_link(new_dentry, old_inode);
238 inode_dec_link_count(old_inode);
242 inode_inc_link_count(new_dir);
245 minix_delete_entry(old_de, old_page);
246 inode_dec_link_count(old_inode);
249 minix_set_link(dir_de, dir_page, new_dir);
250 inode_dec_link_count(old_dir);
257 page_cache_release(dir_page);
261 page_cache_release(old_page);
267 * directories can handle most operations...
269 const struct inode_operations minix_dir_inode_operations = {
270 .create = minix_create,
271 .lookup = minix_lookup,
273 .unlink = minix_unlink,
274 .symlink = minix_symlink,
275 .mkdir = minix_mkdir,
276 .rmdir = minix_rmdir,
277 .mknod = minix_mknod,
278 .rename = minix_rename,
279 .getattr = minix_getattr,