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
, unsigned int flags
)
23 struct inode
* inode
= NULL
;
26 if (dentry
->d_name
.len
> minix_sb(dir
->i_sb
)->s_namelen
)
27 return ERR_PTR(-ENAMETOOLONG
);
29 ino
= minix_inode_by_name(dentry
);
31 inode
= minix_iget(dir
->i_sb
, ino
);
33 return ERR_CAST(inode
);
39 static int minix_mknod(struct inode
* dir
, struct dentry
*dentry
, umode_t mode
, dev_t rdev
)
44 if (!old_valid_dev(rdev
))
47 inode
= minix_new_inode(dir
, mode
, &error
);
50 minix_set_inode(inode
, rdev
);
51 mark_inode_dirty(inode
);
52 error
= add_nondir(dentry
, inode
);
57 static int minix_tmpfile(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
)
60 struct inode
*inode
= minix_new_inode(dir
, mode
, &error
);
62 minix_set_inode(inode
, 0);
63 mark_inode_dirty(inode
);
64 d_tmpfile(dentry
, inode
);
69 static int minix_create(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
,
72 return minix_mknod(dir
, dentry
, mode
, 0);
75 static int minix_symlink(struct inode
* dir
, struct dentry
*dentry
,
78 int err
= -ENAMETOOLONG
;
79 int i
= strlen(symname
)+1;
82 if (i
> dir
->i_sb
->s_blocksize
)
85 inode
= minix_new_inode(dir
, S_IFLNK
| 0777, &err
);
89 minix_set_inode(inode
, 0);
90 err
= page_symlink(inode
, symname
, i
);
94 err
= add_nondir(dentry
, inode
);
99 inode_dec_link_count(inode
);
104 static int minix_link(struct dentry
* old_dentry
, struct inode
* dir
,
105 struct dentry
*dentry
)
107 struct inode
*inode
= d_inode(old_dentry
);
109 inode
->i_ctime
= current_time(inode
);
110 inode_inc_link_count(inode
);
112 return add_nondir(dentry
, inode
);
115 static int minix_mkdir(struct inode
* dir
, struct dentry
*dentry
, umode_t mode
)
117 struct inode
* inode
;
120 inode_inc_link_count(dir
);
122 inode
= minix_new_inode(dir
, S_IFDIR
| mode
, &err
);
126 minix_set_inode(inode
, 0);
128 inode_inc_link_count(inode
);
130 err
= minix_make_empty(inode
, dir
);
134 err
= minix_add_link(dentry
, inode
);
138 d_instantiate(dentry
, inode
);
143 inode_dec_link_count(inode
);
144 inode_dec_link_count(inode
);
147 inode_dec_link_count(dir
);
151 static int minix_unlink(struct inode
* dir
, struct dentry
*dentry
)
154 struct inode
* inode
= d_inode(dentry
);
156 struct minix_dir_entry
* de
;
158 de
= minix_find_entry(dentry
, &page
);
162 err
= minix_delete_entry(de
, page
);
166 inode
->i_ctime
= dir
->i_ctime
;
167 inode_dec_link_count(inode
);
172 static int minix_rmdir(struct inode
* dir
, struct dentry
*dentry
)
174 struct inode
* inode
= d_inode(dentry
);
175 int err
= -ENOTEMPTY
;
177 if (minix_empty_dir(inode
)) {
178 err
= minix_unlink(dir
, dentry
);
180 inode_dec_link_count(dir
);
181 inode_dec_link_count(inode
);
187 static int minix_rename(struct inode
* old_dir
, struct dentry
*old_dentry
,
188 struct inode
* new_dir
, struct dentry
*new_dentry
,
191 struct inode
* old_inode
= d_inode(old_dentry
);
192 struct inode
* new_inode
= d_inode(new_dentry
);
193 struct page
* dir_page
= NULL
;
194 struct minix_dir_entry
* dir_de
= NULL
;
195 struct page
* old_page
;
196 struct minix_dir_entry
* old_de
;
199 if (flags
& ~RENAME_NOREPLACE
)
202 old_de
= minix_find_entry(old_dentry
, &old_page
);
206 if (S_ISDIR(old_inode
->i_mode
)) {
208 dir_de
= minix_dotdot(old_inode
, &dir_page
);
214 struct page
* new_page
;
215 struct minix_dir_entry
* new_de
;
218 if (dir_de
&& !minix_empty_dir(new_inode
))
222 new_de
= minix_find_entry(new_dentry
, &new_page
);
225 minix_set_link(new_de
, new_page
, old_inode
);
226 new_inode
->i_ctime
= current_time(new_inode
);
228 drop_nlink(new_inode
);
229 inode_dec_link_count(new_inode
);
231 err
= minix_add_link(new_dentry
, old_inode
);
235 inode_inc_link_count(new_dir
);
238 minix_delete_entry(old_de
, old_page
);
239 mark_inode_dirty(old_inode
);
242 minix_set_link(dir_de
, dir_page
, new_dir
);
243 inode_dec_link_count(old_dir
);
260 * directories can handle most operations...
262 const struct inode_operations minix_dir_inode_operations
= {
263 .create
= minix_create
,
264 .lookup
= minix_lookup
,
266 .unlink
= minix_unlink
,
267 .symlink
= minix_symlink
,
268 .mkdir
= minix_mkdir
,
269 .rmdir
= minix_rmdir
,
270 .mknod
= minix_mknod
,
271 .rename
= minix_rename
,
272 .getattr
= minix_getattr
,
273 .tmpfile
= minix_tmpfile
,