2 * linux/fs/minix/namei.c
4 * Copyright (C) 1991, 1992 Linus Torvalds
9 static inline void inc_count(struct inode
*inode
)
12 mark_inode_dirty(inode
);
15 static inline void dec_count(struct inode
*inode
)
18 mark_inode_dirty(inode
);
21 static int add_nondir(struct dentry
*dentry
, struct inode
*inode
)
23 int err
= minix_add_link(dentry
, inode
);
25 d_instantiate(dentry
, inode
);
33 static int minix_hash(struct dentry
*dentry
, struct qstr
*qstr
)
37 const unsigned char *name
;
39 i
= minix_sb(dentry
->d_inode
->i_sb
)->s_namelen
;
42 /* Truncate the name in place, avoids having to define a compare
46 hash
= init_name_hash();
48 hash
= partial_name_hash(*name
++, hash
);
49 qstr
->hash
= end_name_hash(hash
);
53 struct dentry_operations minix_dentry_operations
= {
57 static struct dentry
*minix_lookup(struct inode
* dir
, struct dentry
*dentry
, struct nameidata
*nd
)
59 struct inode
* inode
= NULL
;
62 dentry
->d_op
= dir
->i_sb
->s_root
->d_op
;
64 if (dentry
->d_name
.len
> minix_sb(dir
->i_sb
)->s_namelen
)
65 return ERR_PTR(-ENAMETOOLONG
);
67 ino
= minix_inode_by_name(dentry
);
69 inode
= iget(dir
->i_sb
, ino
);
72 return ERR_PTR(-EACCES
);
78 static int minix_mknod(struct inode
* dir
, struct dentry
*dentry
, int mode
, dev_t rdev
)
83 if (!old_valid_dev(rdev
))
86 inode
= minix_new_inode(dir
, &error
);
90 minix_set_inode(inode
, rdev
);
91 mark_inode_dirty(inode
);
92 error
= add_nondir(dentry
, inode
);
97 static int minix_create(struct inode
* dir
, struct dentry
*dentry
, int mode
,
100 return minix_mknod(dir
, dentry
, mode
, 0);
103 static int minix_symlink(struct inode
* dir
, struct dentry
*dentry
,
104 const char * symname
)
106 int err
= -ENAMETOOLONG
;
107 int i
= strlen(symname
)+1;
108 struct inode
* inode
;
110 if (i
> dir
->i_sb
->s_blocksize
)
113 inode
= minix_new_inode(dir
, &err
);
117 inode
->i_mode
= S_IFLNK
| 0777;
118 minix_set_inode(inode
, 0);
119 err
= page_symlink(inode
, symname
, i
);
123 err
= add_nondir(dentry
, inode
);
133 static int minix_link(struct dentry
* old_dentry
, struct inode
* dir
,
134 struct dentry
*dentry
)
136 struct inode
*inode
= old_dentry
->d_inode
;
138 if (inode
->i_nlink
>= minix_sb(inode
->i_sb
)->s_link_max
)
141 inode
->i_ctime
= CURRENT_TIME_SEC
;
143 atomic_inc(&inode
->i_count
);
144 return add_nondir(dentry
, inode
);
147 static int minix_mkdir(struct inode
* dir
, struct dentry
*dentry
, int mode
)
149 struct inode
* inode
;
152 if (dir
->i_nlink
>= minix_sb(dir
->i_sb
)->s_link_max
)
157 inode
= minix_new_inode(dir
, &err
);
161 inode
->i_mode
= S_IFDIR
| mode
;
162 if (dir
->i_mode
& S_ISGID
)
163 inode
->i_mode
|= S_ISGID
;
164 minix_set_inode(inode
, 0);
168 err
= minix_make_empty(inode
, dir
);
172 err
= minix_add_link(dentry
, inode
);
176 d_instantiate(dentry
, inode
);
189 static int minix_unlink(struct inode
* dir
, struct dentry
*dentry
)
192 struct inode
* inode
= dentry
->d_inode
;
194 struct minix_dir_entry
* de
;
196 de
= minix_find_entry(dentry
, &page
);
200 err
= minix_delete_entry(de
, page
);
204 inode
->i_ctime
= dir
->i_ctime
;
210 static int minix_rmdir(struct inode
* dir
, struct dentry
*dentry
)
212 struct inode
* inode
= dentry
->d_inode
;
213 int err
= -ENOTEMPTY
;
215 if (minix_empty_dir(inode
)) {
216 err
= minix_unlink(dir
, dentry
);
225 static int minix_rename(struct inode
* old_dir
, struct dentry
*old_dentry
,
226 struct inode
* new_dir
, struct dentry
*new_dentry
)
228 struct minix_sb_info
* info
= minix_sb(old_dir
->i_sb
);
229 struct inode
* old_inode
= old_dentry
->d_inode
;
230 struct inode
* new_inode
= new_dentry
->d_inode
;
231 struct page
* dir_page
= NULL
;
232 struct minix_dir_entry
* dir_de
= NULL
;
233 struct page
* old_page
;
234 struct minix_dir_entry
* old_de
;
237 old_de
= minix_find_entry(old_dentry
, &old_page
);
241 if (S_ISDIR(old_inode
->i_mode
)) {
243 dir_de
= minix_dotdot(old_inode
, &dir_page
);
249 struct page
* new_page
;
250 struct minix_dir_entry
* new_de
;
253 if (dir_de
&& !minix_empty_dir(new_inode
))
257 new_de
= minix_find_entry(new_dentry
, &new_page
);
260 inc_count(old_inode
);
261 minix_set_link(new_de
, new_page
, old_inode
);
262 new_inode
->i_ctime
= CURRENT_TIME_SEC
;
264 new_inode
->i_nlink
--;
265 dec_count(new_inode
);
269 if (new_dir
->i_nlink
>= info
->s_link_max
)
272 inc_count(old_inode
);
273 err
= minix_add_link(new_dentry
, old_inode
);
275 dec_count(old_inode
);
282 minix_delete_entry(old_de
, old_page
);
283 dec_count(old_inode
);
286 minix_set_link(dir_de
, dir_page
, new_dir
);
294 page_cache_release(dir_page
);
298 page_cache_release(old_page
);
304 * directories can handle most operations...
306 struct inode_operations minix_dir_inode_operations
= {
307 .create
= minix_create
,
308 .lookup
= minix_lookup
,
310 .unlink
= minix_unlink
,
311 .symlink
= minix_symlink
,
312 .mkdir
= minix_mkdir
,
313 .rmdir
= minix_rmdir
,
314 .mknod
= minix_mknod
,
315 .rename
= minix_rename
,
316 .getattr
= minix_getattr
,