2 * linux/fs/minix/namei.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
8 #include <linux/minix_fs.h>
9 #include <linux/pagemap.h>
11 static inline void inc_count(struct inode *inode)
14 mark_inode_dirty(inode);
17 static inline void dec_count(struct inode *inode)
20 mark_inode_dirty(inode);
23 static int add_nondir(struct dentry *dentry, struct inode *inode)
25 int err = minix_add_link(dentry, inode);
27 d_instantiate(dentry, inode);
35 static int minix_hash(struct dentry *dentry, struct qstr *qstr)
39 const unsigned char *name;
41 i = dentry->d_inode->i_sb->u.minix_sb.s_namelen;
44 /* Truncate the name in place, avoids having to define a compare
48 hash = init_name_hash();
50 hash = partial_name_hash(*name++, hash);
51 qstr->hash = end_name_hash(hash);
55 struct dentry_operations minix_dentry_operations = {
59 static struct dentry *minix_lookup(struct inode * dir, struct dentry *dentry)
61 struct inode * inode = NULL;
64 dentry->d_op = dir->i_sb->s_root->d_op;
66 if (dentry->d_name.len > dir->i_sb->u.minix_sb.s_namelen)
67 return ERR_PTR(-ENAMETOOLONG);
69 ino = minix_inode_by_name(dentry);
71 inode = iget(dir->i_sb, ino);
74 return ERR_PTR(-EACCES);
80 static int minix_mknod(struct inode * dir, struct dentry *dentry, int mode, int rdev)
83 struct inode * inode = minix_new_inode(dir, &error);
87 minix_set_inode(inode, rdev);
88 mark_inode_dirty(inode);
89 error = add_nondir(dentry, inode);
94 static int minix_create(struct inode * dir, struct dentry *dentry, int mode)
96 return minix_mknod(dir, dentry, mode, 0);
99 static int minix_symlink(struct inode * dir, struct dentry *dentry,
100 const char * symname)
102 int err = -ENAMETOOLONG;
103 int i = strlen(symname)+1;
104 struct inode * inode;
106 if (i > dir->i_sb->s_blocksize)
109 inode = minix_new_inode(dir, &err);
113 inode->i_mode = S_IFLNK | 0777;
114 minix_set_inode(inode, 0);
115 err = block_symlink(inode, symname, i);
119 err = add_nondir(dentry, inode);
129 static int minix_link(struct dentry * old_dentry, struct inode * dir,
130 struct dentry *dentry)
132 struct inode *inode = old_dentry->d_inode;
134 if (S_ISDIR(inode->i_mode))
137 if (inode->i_nlink >= inode->i_sb->u.minix_sb.s_link_max)
140 inode->i_ctime = CURRENT_TIME;
142 atomic_inc(&inode->i_count);
143 return add_nondir(dentry, inode);
146 static int minix_mkdir(struct inode * dir, struct dentry *dentry, int mode)
148 struct inode * inode;
151 if (dir->i_nlink >= dir->i_sb->u.minix_sb.s_link_max)
156 inode = minix_new_inode(dir, &err);
160 inode->i_mode = S_IFDIR | mode;
161 if (dir->i_mode & S_ISGID)
162 inode->i_mode |= S_ISGID;
163 minix_set_inode(inode, 0);
167 err = minix_make_empty(inode, dir);
171 err = minix_add_link(dentry, inode);
175 d_instantiate(dentry, inode);
188 static int minix_unlink(struct inode * dir, struct dentry *dentry)
191 struct inode * inode = dentry->d_inode;
193 struct minix_dir_entry * de;
195 de = minix_find_entry(dentry, &page);
199 err = minix_delete_entry(de, page);
203 inode->i_ctime = dir->i_ctime;
209 static int minix_rmdir(struct inode * dir, struct dentry *dentry)
211 struct inode * inode = dentry->d_inode;
212 int err = -ENOTEMPTY;
214 if (minix_empty_dir(inode)) {
215 err = minix_unlink(dir, dentry);
224 static int minix_rename(struct inode * old_dir, struct dentry *old_dentry,
225 struct inode * new_dir, struct dentry *new_dentry)
227 struct minix_sb_info * info = &old_dir->i_sb->u.minix_sb;
228 struct inode * old_inode = old_dentry->d_inode;
229 struct inode * new_inode = new_dentry->d_inode;
230 struct page * dir_page = NULL;
231 struct minix_dir_entry * dir_de = NULL;
232 struct page * old_page;
233 struct minix_dir_entry * old_de;
236 old_de = minix_find_entry(old_dentry, &old_page);
240 if (S_ISDIR(old_inode->i_mode)) {
242 dir_de = minix_dotdot(old_inode, &dir_page);
248 struct page * new_page;
249 struct minix_dir_entry * new_de;
252 if (dir_de && !minix_empty_dir(new_inode))
256 new_de = minix_find_entry(new_dentry, &new_page);
259 inc_count(old_inode);
260 minix_set_link(new_de, new_page, old_inode);
261 new_inode->i_ctime = CURRENT_TIME;
263 new_inode->i_nlink--;
264 dec_count(new_inode);
268 if (new_dir->i_nlink >= info->s_link_max)
271 inc_count(old_inode);
272 err = minix_add_link(new_dentry, old_inode);
274 dec_count(old_inode);
281 minix_delete_entry(old_de, old_page);
282 dec_count(old_inode);
285 minix_set_link(dir_de, dir_page, new_dir);
293 page_cache_release(dir_page);
297 page_cache_release(old_page);
303 * directories can handle most operations...
305 struct inode_operations minix_dir_inode_operations = {
306 create: minix_create,
307 lookup: minix_lookup,
309 unlink: minix_unlink,
310 symlink: minix_symlink,
314 rename: minix_rename,