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 int minix_hash(struct dentry *dentry, struct qstr *qstr)
25 const unsigned char *name;
27 i = minix_sb(dentry->d_inode->i_sb)->s_namelen;
30 /* Truncate the name in place, avoids having to define a compare
34 hash = init_name_hash();
36 hash = partial_name_hash(*name++, hash);
37 qstr->hash = end_name_hash(hash);
41 struct dentry_operations minix_dentry_operations = {
45 static struct dentry *minix_lookup(struct inode * dir, struct dentry *dentry, struct nameidata *nd)
47 struct inode * inode = NULL;
50 dentry->d_op = dir->i_sb->s_root->d_op;
52 if (dentry->d_name.len > minix_sb(dir->i_sb)->s_namelen)
53 return ERR_PTR(-ENAMETOOLONG);
55 ino = minix_inode_by_name(dentry);
57 inode = minix_iget(dir->i_sb, ino);
59 return ERR_CAST(inode);
65 static int minix_mknod(struct inode * dir, struct dentry *dentry, int mode, dev_t rdev)
70 if (!old_valid_dev(rdev))
73 inode = minix_new_inode(dir, &error);
77 minix_set_inode(inode, rdev);
78 mark_inode_dirty(inode);
79 error = add_nondir(dentry, inode);
84 static int minix_create(struct inode * dir, struct dentry *dentry, int mode,
87 return minix_mknod(dir, dentry, mode, 0);
90 static int minix_symlink(struct inode * dir, struct dentry *dentry,
93 int err = -ENAMETOOLONG;
94 int i = strlen(symname)+1;
97 if (i > dir->i_sb->s_blocksize)
100 inode = minix_new_inode(dir, &err);
104 inode->i_mode = S_IFLNK | 0777;
105 minix_set_inode(inode, 0);
106 err = page_symlink(inode, symname, i);
110 err = add_nondir(dentry, inode);
115 inode_dec_link_count(inode);
120 static int minix_link(struct dentry * old_dentry, struct inode * dir,
121 struct dentry *dentry)
123 struct inode *inode = old_dentry->d_inode;
125 if (inode->i_nlink >= minix_sb(inode->i_sb)->s_link_max)
128 inode->i_ctime = CURRENT_TIME_SEC;
129 inode_inc_link_count(inode);
130 atomic_inc(&inode->i_count);
131 return add_nondir(dentry, inode);
134 static int minix_mkdir(struct inode * dir, struct dentry *dentry, int mode)
136 struct inode * inode;
139 if (dir->i_nlink >= minix_sb(dir->i_sb)->s_link_max)
142 inode_inc_link_count(dir);
144 inode = minix_new_inode(dir, &err);
148 inode->i_mode = S_IFDIR | mode;
149 if (dir->i_mode & S_ISGID)
150 inode->i_mode |= S_ISGID;
151 minix_set_inode(inode, 0);
153 inode_inc_link_count(inode);
155 err = minix_make_empty(inode, dir);
159 err = minix_add_link(dentry, inode);
163 d_instantiate(dentry, inode);
168 inode_dec_link_count(inode);
169 inode_dec_link_count(inode);
172 inode_dec_link_count(dir);
176 static int minix_unlink(struct inode * dir, struct dentry *dentry)
179 struct inode * inode = dentry->d_inode;
181 struct minix_dir_entry * de;
183 de = minix_find_entry(dentry, &page);
187 err = minix_delete_entry(de, page);
191 inode->i_ctime = dir->i_ctime;
192 inode_dec_link_count(inode);
197 static int minix_rmdir(struct inode * dir, struct dentry *dentry)
199 struct inode * inode = dentry->d_inode;
200 int err = -ENOTEMPTY;
202 if (minix_empty_dir(inode)) {
203 err = minix_unlink(dir, dentry);
205 inode_dec_link_count(dir);
206 inode_dec_link_count(inode);
212 static int minix_rename(struct inode * old_dir, struct dentry *old_dentry,
213 struct inode * new_dir, struct dentry *new_dentry)
215 struct minix_sb_info * info = minix_sb(old_dir->i_sb);
216 struct inode * old_inode = old_dentry->d_inode;
217 struct inode * new_inode = new_dentry->d_inode;
218 struct page * dir_page = NULL;
219 struct minix_dir_entry * dir_de = NULL;
220 struct page * old_page;
221 struct minix_dir_entry * old_de;
224 old_de = minix_find_entry(old_dentry, &old_page);
228 if (S_ISDIR(old_inode->i_mode)) {
230 dir_de = minix_dotdot(old_inode, &dir_page);
236 struct page * new_page;
237 struct minix_dir_entry * new_de;
240 if (dir_de && !minix_empty_dir(new_inode))
244 new_de = minix_find_entry(new_dentry, &new_page);
247 inode_inc_link_count(old_inode);
248 minix_set_link(new_de, new_page, old_inode);
249 new_inode->i_ctime = CURRENT_TIME_SEC;
251 drop_nlink(new_inode);
252 inode_dec_link_count(new_inode);
256 if (new_dir->i_nlink >= info->s_link_max)
259 inode_inc_link_count(old_inode);
260 err = minix_add_link(new_dentry, old_inode);
262 inode_dec_link_count(old_inode);
266 inode_inc_link_count(new_dir);
269 minix_delete_entry(old_de, old_page);
270 inode_dec_link_count(old_inode);
273 minix_set_link(dir_de, dir_page, new_dir);
274 inode_dec_link_count(old_dir);
281 page_cache_release(dir_page);
285 page_cache_release(old_page);
291 * directories can handle most operations...
293 const struct inode_operations minix_dir_inode_operations = {
294 .create = minix_create,
295 .lookup = minix_lookup,
297 .unlink = minix_unlink,
298 .symlink = minix_symlink,
299 .mkdir = minix_mkdir,
300 .rmdir = minix_rmdir,
301 .mknod = minix_mknod,
302 .rename = minix_rename,
303 .getattr = minix_getattr,