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
, mode
, &error
);
52 minix_set_inode(inode
, rdev
);
53 mark_inode_dirty(inode
);
54 error
= add_nondir(dentry
, inode
);
59 static int minix_create(struct inode
* dir
, struct dentry
*dentry
, int mode
,
62 return minix_mknod(dir
, dentry
, mode
, 0);
65 static int minix_symlink(struct inode
* dir
, struct dentry
*dentry
,
68 int err
= -ENAMETOOLONG
;
69 int i
= strlen(symname
)+1;
72 if (i
> dir
->i_sb
->s_blocksize
)
75 inode
= minix_new_inode(dir
, S_IFLNK
| 0777, &err
);
79 minix_set_inode(inode
, 0);
80 err
= page_symlink(inode
, symname
, i
);
84 err
= add_nondir(dentry
, inode
);
89 inode_dec_link_count(inode
);
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
)
102 inode
->i_ctime
= CURRENT_TIME_SEC
;
103 inode_inc_link_count(inode
);
105 return add_nondir(dentry
, inode
);
108 static int minix_mkdir(struct inode
* dir
, struct dentry
*dentry
, int mode
)
110 struct inode
* inode
;
113 if (dir
->i_nlink
>= minix_sb(dir
->i_sb
)->s_link_max
)
116 inode_inc_link_count(dir
);
118 inode
= minix_new_inode(dir
, S_IFDIR
| mode
, &err
);
122 minix_set_inode(inode
, 0);
124 inode_inc_link_count(inode
);
126 err
= minix_make_empty(inode
, dir
);
130 err
= minix_add_link(dentry
, inode
);
134 d_instantiate(dentry
, inode
);
139 inode_dec_link_count(inode
);
140 inode_dec_link_count(inode
);
143 inode_dec_link_count(dir
);
147 static int minix_unlink(struct inode
* dir
, struct dentry
*dentry
)
150 struct inode
* inode
= dentry
->d_inode
;
152 struct minix_dir_entry
* de
;
154 de
= minix_find_entry(dentry
, &page
);
158 err
= minix_delete_entry(de
, page
);
162 inode
->i_ctime
= dir
->i_ctime
;
163 inode_dec_link_count(inode
);
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
);
176 inode_dec_link_count(dir
);
177 inode_dec_link_count(inode
);
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
;
195 old_de
= minix_find_entry(old_dentry
, &old_page
);
199 if (S_ISDIR(old_inode
->i_mode
)) {
201 dir_de
= minix_dotdot(old_inode
, &dir_page
);
207 struct page
* new_page
;
208 struct minix_dir_entry
* new_de
;
211 if (dir_de
&& !minix_empty_dir(new_inode
))
215 new_de
= minix_find_entry(new_dentry
, &new_page
);
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
;
222 drop_nlink(new_inode
);
223 inode_dec_link_count(new_inode
);
227 if (new_dir
->i_nlink
>= info
->s_link_max
)
230 inode_inc_link_count(old_inode
);
231 err
= minix_add_link(new_dentry
, old_inode
);
233 inode_dec_link_count(old_inode
);
237 inode_inc_link_count(new_dir
);
240 minix_delete_entry(old_de
, old_page
);
241 inode_dec_link_count(old_inode
);
244 minix_set_link(dir_de
, dir_page
, new_dir
);
245 inode_dec_link_count(old_dir
);
252 page_cache_release(dir_page
);
256 page_cache_release(old_page
);
262 * directories can handle most operations...
264 const struct inode_operations minix_dir_inode_operations
= {
265 .create
= minix_create
,
266 .lookup
= minix_lookup
,
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
,