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 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_create(struct inode
*dir
, struct dentry
*dentry
, umode_t mode
,
60 return minix_mknod(dir
, dentry
, mode
, 0);
63 static int minix_symlink(struct inode
* dir
, struct dentry
*dentry
,
66 int err
= -ENAMETOOLONG
;
67 int i
= strlen(symname
)+1;
70 if (i
> dir
->i_sb
->s_blocksize
)
73 inode
= minix_new_inode(dir
, S_IFLNK
| 0777, &err
);
77 minix_set_inode(inode
, 0);
78 err
= page_symlink(inode
, symname
, i
);
82 err
= add_nondir(dentry
, inode
);
87 inode_dec_link_count(inode
);
92 static int minix_link(struct dentry
* old_dentry
, struct inode
* dir
,
93 struct dentry
*dentry
)
95 struct inode
*inode
= old_dentry
->d_inode
;
97 inode
->i_ctime
= CURRENT_TIME_SEC
;
98 inode_inc_link_count(inode
);
100 return add_nondir(dentry
, inode
);
103 static int minix_mkdir(struct inode
* dir
, struct dentry
*dentry
, umode_t mode
)
105 struct inode
* inode
;
108 inode_inc_link_count(dir
);
110 inode
= minix_new_inode(dir
, S_IFDIR
| mode
, &err
);
114 minix_set_inode(inode
, 0);
116 inode_inc_link_count(inode
);
118 err
= minix_make_empty(inode
, dir
);
122 err
= minix_add_link(dentry
, inode
);
126 d_instantiate(dentry
, inode
);
131 inode_dec_link_count(inode
);
132 inode_dec_link_count(inode
);
135 inode_dec_link_count(dir
);
139 static int minix_unlink(struct inode
* dir
, struct dentry
*dentry
)
142 struct inode
* inode
= dentry
->d_inode
;
144 struct minix_dir_entry
* de
;
146 de
= minix_find_entry(dentry
, &page
);
150 err
= minix_delete_entry(de
, page
);
154 inode
->i_ctime
= dir
->i_ctime
;
155 inode_dec_link_count(inode
);
160 static int minix_rmdir(struct inode
* dir
, struct dentry
*dentry
)
162 struct inode
* inode
= dentry
->d_inode
;
163 int err
= -ENOTEMPTY
;
165 if (minix_empty_dir(inode
)) {
166 err
= minix_unlink(dir
, dentry
);
168 inode_dec_link_count(dir
);
169 inode_dec_link_count(inode
);
175 static int minix_rename(struct inode
* old_dir
, struct dentry
*old_dentry
,
176 struct inode
* new_dir
, struct dentry
*new_dentry
)
178 struct inode
* old_inode
= old_dentry
->d_inode
;
179 struct inode
* new_inode
= new_dentry
->d_inode
;
180 struct page
* dir_page
= NULL
;
181 struct minix_dir_entry
* dir_de
= NULL
;
182 struct page
* old_page
;
183 struct minix_dir_entry
* old_de
;
186 old_de
= minix_find_entry(old_dentry
, &old_page
);
190 if (S_ISDIR(old_inode
->i_mode
)) {
192 dir_de
= minix_dotdot(old_inode
, &dir_page
);
198 struct page
* new_page
;
199 struct minix_dir_entry
* new_de
;
202 if (dir_de
&& !minix_empty_dir(new_inode
))
206 new_de
= minix_find_entry(new_dentry
, &new_page
);
209 minix_set_link(new_de
, new_page
, old_inode
);
210 new_inode
->i_ctime
= CURRENT_TIME_SEC
;
212 drop_nlink(new_inode
);
213 inode_dec_link_count(new_inode
);
215 err
= minix_add_link(new_dentry
, old_inode
);
219 inode_inc_link_count(new_dir
);
222 minix_delete_entry(old_de
, old_page
);
223 mark_inode_dirty(old_inode
);
226 minix_set_link(dir_de
, dir_page
, new_dir
);
227 inode_dec_link_count(old_dir
);
234 page_cache_release(dir_page
);
238 page_cache_release(old_page
);
244 * directories can handle most operations...
246 const struct inode_operations minix_dir_inode_operations
= {
247 .create
= minix_create
,
248 .lookup
= minix_lookup
,
250 .unlink
= minix_unlink
,
251 .symlink
= minix_symlink
,
252 .mkdir
= minix_mkdir
,
253 .rmdir
= minix_rmdir
,
254 .mknod
= minix_mknod
,
255 .rename
= minix_rename
,
256 .getattr
= minix_getattr
,