4 * Migration to usage of "page cache" on May 2006 by
5 * Evgeniy Dushistov <dushistov@mail.ru> based on ext2 code base.
8 * Daniel Pirkl <daniel.pirkl@email.cz>
9 * Charles University, Faculty of Mathematics and Physics
13 * linux/fs/ext2/namei.c
15 * Copyright (C) 1992, 1993, 1994, 1995
16 * Remy Card (card@masi.ibp.fr)
17 * Laboratoire MASI - Institut Blaise Pascal
18 * Universite Pierre et Marie Curie (Paris VI)
22 * linux/fs/minix/namei.c
24 * Copyright (C) 1991, 1992 Linus Torvalds
26 * Big-endian to little-endian byte-swapping/bitmaps by
27 * David S. Miller (davem@caip.rutgers.edu), 1995
30 #include <linux/time.h>
32 #include <linux/smp_lock.h>
33 #include <linux/quotaops.h>
39 static inline int ufs_add_nondir(struct dentry
*dentry
, struct inode
*inode
)
41 int err
= ufs_add_link(dentry
, inode
);
43 d_instantiate(dentry
, inode
);
46 inode_dec_link_count(inode
);
51 static struct dentry
*ufs_lookup(struct inode
* dir
, struct dentry
*dentry
, struct nameidata
*nd
)
53 struct inode
* inode
= NULL
;
56 if (dentry
->d_name
.len
> UFS_MAXNAMLEN
)
57 return ERR_PTR(-ENAMETOOLONG
);
60 ino
= ufs_inode_by_name(dir
, &dentry
->d_name
);
62 inode
= ufs_iget(dir
->i_sb
, ino
);
65 return ERR_CAST(inode
);
74 * By the time this is called, we already have created
75 * the directory cache entry for the new file, but it
76 * is so far negative - it has no inode.
78 * If the create succeeds, we fill in the inode information
79 * with d_instantiate().
81 static int ufs_create (struct inode
* dir
, struct dentry
* dentry
, int mode
,
89 dquot_initialize(dir
);
91 inode
= ufs_new_inode(dir
, mode
);
95 inode
->i_op
= &ufs_file_inode_operations
;
96 inode
->i_fop
= &ufs_file_operations
;
97 inode
->i_mapping
->a_ops
= &ufs_aops
;
98 mark_inode_dirty(inode
);
100 err
= ufs_add_nondir(dentry
, inode
);
103 UFSD("END: err=%d\n", err
);
107 static int ufs_mknod (struct inode
* dir
, struct dentry
*dentry
, int mode
, dev_t rdev
)
112 if (!old_valid_dev(rdev
))
115 dquot_initialize(dir
);
117 inode
= ufs_new_inode(dir
, mode
);
118 err
= PTR_ERR(inode
);
119 if (!IS_ERR(inode
)) {
120 init_special_inode(inode
, mode
, rdev
);
121 ufs_set_inode_dev(inode
->i_sb
, UFS_I(inode
), rdev
);
122 mark_inode_dirty(inode
);
124 err
= ufs_add_nondir(dentry
, inode
);
130 static int ufs_symlink (struct inode
* dir
, struct dentry
* dentry
,
131 const char * symname
)
133 struct super_block
* sb
= dir
->i_sb
;
134 int err
= -ENAMETOOLONG
;
135 unsigned l
= strlen(symname
)+1;
136 struct inode
* inode
;
138 if (l
> sb
->s_blocksize
)
141 dquot_initialize(dir
);
144 inode
= ufs_new_inode(dir
, S_IFLNK
| S_IRWXUGO
);
145 err
= PTR_ERR(inode
);
149 if (l
> UFS_SB(sb
)->s_uspi
->s_maxsymlinklen
) {
151 inode
->i_op
= &page_symlink_inode_operations
;
152 inode
->i_mapping
->a_ops
= &ufs_aops
;
153 err
= page_symlink(inode
, symname
, l
);
158 inode
->i_op
= &ufs_fast_symlink_inode_operations
;
159 memcpy(UFS_I(inode
)->i_u1
.i_symlink
, symname
, l
);
162 mark_inode_dirty(inode
);
164 err
= ufs_add_nondir(dentry
, inode
);
171 inode_dec_link_count(inode
);
176 static int ufs_link (struct dentry
* old_dentry
, struct inode
* dir
,
177 struct dentry
*dentry
)
179 struct inode
*inode
= old_dentry
->d_inode
;
183 if (inode
->i_nlink
>= UFS_LINK_MAX
) {
188 dquot_initialize(dir
);
190 inode
->i_ctime
= CURRENT_TIME_SEC
;
191 inode_inc_link_count(inode
);
192 atomic_inc(&inode
->i_count
);
194 error
= ufs_add_nondir(dentry
, inode
);
199 static int ufs_mkdir(struct inode
* dir
, struct dentry
* dentry
, int mode
)
201 struct inode
* inode
;
204 if (dir
->i_nlink
>= UFS_LINK_MAX
)
207 dquot_initialize(dir
);
210 inode_inc_link_count(dir
);
212 inode
= ufs_new_inode(dir
, S_IFDIR
|mode
);
213 err
= PTR_ERR(inode
);
217 inode
->i_op
= &ufs_dir_inode_operations
;
218 inode
->i_fop
= &ufs_dir_operations
;
219 inode
->i_mapping
->a_ops
= &ufs_aops
;
221 inode_inc_link_count(inode
);
223 err
= ufs_make_empty(inode
, dir
);
227 err
= ufs_add_link(dentry
, inode
);
232 d_instantiate(dentry
, inode
);
237 inode_dec_link_count(inode
);
238 inode_dec_link_count(inode
);
241 inode_dec_link_count(dir
);
246 static int ufs_unlink(struct inode
*dir
, struct dentry
*dentry
)
248 struct inode
* inode
= dentry
->d_inode
;
249 struct ufs_dir_entry
*de
;
253 dquot_initialize(dir
);
255 de
= ufs_find_entry(dir
, &dentry
->d_name
, &page
);
259 err
= ufs_delete_entry(dir
, de
, page
);
263 inode
->i_ctime
= dir
->i_ctime
;
264 inode_dec_link_count(inode
);
270 static int ufs_rmdir (struct inode
* dir
, struct dentry
*dentry
)
272 struct inode
* inode
= dentry
->d_inode
;
276 if (ufs_empty_dir (inode
)) {
277 err
= ufs_unlink(dir
, dentry
);
280 inode_dec_link_count(inode
);
281 inode_dec_link_count(dir
);
288 static int ufs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
289 struct inode
*new_dir
, struct dentry
*new_dentry
)
291 struct inode
*old_inode
= old_dentry
->d_inode
;
292 struct inode
*new_inode
= new_dentry
->d_inode
;
293 struct page
*dir_page
= NULL
;
294 struct ufs_dir_entry
* dir_de
= NULL
;
295 struct page
*old_page
;
296 struct ufs_dir_entry
*old_de
;
299 dquot_initialize(old_dir
);
300 dquot_initialize(new_dir
);
302 old_de
= ufs_find_entry(old_dir
, &old_dentry
->d_name
, &old_page
);
306 if (S_ISDIR(old_inode
->i_mode
)) {
308 dir_de
= ufs_dotdot(old_inode
, &dir_page
);
314 struct page
*new_page
;
315 struct ufs_dir_entry
*new_de
;
318 if (dir_de
&& !ufs_empty_dir(new_inode
))
322 new_de
= ufs_find_entry(new_dir
, &new_dentry
->d_name
, &new_page
);
325 inode_inc_link_count(old_inode
);
326 ufs_set_link(new_dir
, new_de
, new_page
, old_inode
);
327 new_inode
->i_ctime
= CURRENT_TIME_SEC
;
329 drop_nlink(new_inode
);
330 inode_dec_link_count(new_inode
);
334 if (new_dir
->i_nlink
>= UFS_LINK_MAX
)
337 inode_inc_link_count(old_inode
);
338 err
= ufs_add_link(new_dentry
, old_inode
);
340 inode_dec_link_count(old_inode
);
344 inode_inc_link_count(new_dir
);
348 * Like most other Unix systems, set the ctime for inodes on a
350 * inode_dec_link_count() will mark the inode dirty.
352 old_inode
->i_ctime
= CURRENT_TIME_SEC
;
354 ufs_delete_entry(old_dir
, old_de
, old_page
);
355 inode_dec_link_count(old_inode
);
358 ufs_set_link(old_inode
, dir_de
, dir_page
, new_dir
);
359 inode_dec_link_count(old_dir
);
367 page_cache_release(dir_page
);
371 page_cache_release(old_page
);
376 const struct inode_operations ufs_dir_inode_operations
= {
377 .create
= ufs_create
,
378 .lookup
= ufs_lookup
,
380 .unlink
= ufs_unlink
,
381 .symlink
= ufs_symlink
,
385 .rename
= ufs_rename
,