2 * Copyright 2000 by Hans Reiser, licensing governed by reiserfs/README
4 * Trivial changes by Alan Cox to remove EHASHCOLLISION for compatibility
7 * Rights granted to Hans Reiser to redistribute under other terms providing
8 * he accepts all liability including but not limited to patent, fitness
9 * for purpose, and direct or indirect claims arising from failure to perform.
14 #include <linux/time.h>
15 #include <linux/bitops.h>
16 #include <linux/reiserfs_fs.h>
17 #include <linux/reiserfs_acl.h>
18 #include <linux/reiserfs_xattr.h>
19 #include <linux/smp_lock.h>
20 #include <linux/quotaops.h>
22 #define INC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) { inc_nlink(i); if (i->i_nlink >= REISERFS_LINK_MAX) i->i_nlink=1; }
23 #define DEC_DIR_INODE_NLINK(i) if (i->i_nlink != 1) drop_nlink(i);
25 // directory item contains array of entry headers. This performs
26 // binary search through that array
27 static int bin_search_in_dir_item(struct reiserfs_dir_entry
*de
, loff_t off
)
29 struct item_head
*ih
= de
->de_ih
;
30 struct reiserfs_de_head
*deh
= de
->de_deh
;
31 int rbound
, lbound
, j
;
34 rbound
= I_ENTRY_COUNT(ih
) - 1;
36 for (j
= (rbound
+ lbound
) / 2; lbound
<= rbound
;
37 j
= (rbound
+ lbound
) / 2) {
38 if (off
< deh_offset(deh
+ j
)) {
42 if (off
> deh_offset(deh
+ j
)) {
46 // this is not name found, but matched third key component
51 de
->de_entry_num
= lbound
;
52 return NAME_NOT_FOUND
;
55 // comment? maybe something like set de to point to what the path points to?
56 static inline void set_de_item_location(struct reiserfs_dir_entry
*de
,
59 de
->de_bh
= get_last_bh(path
);
60 de
->de_ih
= get_ih(path
);
61 de
->de_deh
= B_I_DEH(de
->de_bh
, de
->de_ih
);
62 de
->de_item_num
= PATH_LAST_POSITION(path
);
65 // de_bh, de_ih, de_deh (points to first element of array), de_item_num is set
66 inline void set_de_name_and_namelen(struct reiserfs_dir_entry
*de
)
68 struct reiserfs_de_head
*deh
= de
->de_deh
+ de
->de_entry_num
;
70 BUG_ON(de
->de_entry_num
>= ih_entry_count(de
->de_ih
));
72 de
->de_entrylen
= entry_length(de
->de_bh
, de
->de_ih
, de
->de_entry_num
);
73 de
->de_namelen
= de
->de_entrylen
- (de_with_sd(deh
) ? SD_SIZE
: 0);
74 de
->de_name
= B_I_PITEM(de
->de_bh
, de
->de_ih
) + deh_location(deh
);
75 if (de
->de_name
[de
->de_namelen
- 1] == 0)
76 de
->de_namelen
= strlen(de
->de_name
);
79 // what entry points to
80 static inline void set_de_object_key(struct reiserfs_dir_entry
*de
)
82 BUG_ON(de
->de_entry_num
>= ih_entry_count(de
->de_ih
));
83 de
->de_dir_id
= deh_dir_id(&(de
->de_deh
[de
->de_entry_num
]));
84 de
->de_objectid
= deh_objectid(&(de
->de_deh
[de
->de_entry_num
]));
87 static inline void store_de_entry_key(struct reiserfs_dir_entry
*de
)
89 struct reiserfs_de_head
*deh
= de
->de_deh
+ de
->de_entry_num
;
91 BUG_ON(de
->de_entry_num
>= ih_entry_count(de
->de_ih
));
93 /* store key of the found entry */
94 de
->de_entry_key
.version
= KEY_FORMAT_3_5
;
95 de
->de_entry_key
.on_disk_key
.k_dir_id
=
96 le32_to_cpu(de
->de_ih
->ih_key
.k_dir_id
);
97 de
->de_entry_key
.on_disk_key
.k_objectid
=
98 le32_to_cpu(de
->de_ih
->ih_key
.k_objectid
);
99 set_cpu_key_k_offset(&(de
->de_entry_key
), deh_offset(deh
));
100 set_cpu_key_k_type(&(de
->de_entry_key
), TYPE_DIRENTRY
);
103 /* We assign a key to each directory item, and place multiple entries
104 in a single directory item. A directory item has a key equal to the
105 key of the first directory entry in it.
107 This function first calls search_by_key, then, if item whose first
108 entry matches is not found it looks for the entry inside directory
109 item found by search_by_key. Fills the path to the entry, and to the
110 entry position in the item
114 /* The function is NOT SCHEDULE-SAFE! */
115 int search_by_entry_key(struct super_block
*sb
, const struct cpu_key
*key
,
116 struct path
*path
, struct reiserfs_dir_entry
*de
)
120 retval
= search_item(sb
, key
, path
);
123 if (!PATH_LAST_POSITION(path
)) {
125 "vs-7000: search_by_entry_key: search_by_key returned item position == 0");
129 PATH_LAST_POSITION(path
)--;
140 "vs-7002: search_by_entry_key: no path to here");
144 set_de_item_location(de
, path
);
146 #ifdef CONFIG_REISERFS_CHECK
147 if (!is_direntry_le_ih(de
->de_ih
) ||
148 COMP_SHORT_KEYS(&(de
->de_ih
->ih_key
), key
)) {
149 print_block(de
->de_bh
, 0, -1, -1);
151 "vs-7005: search_by_entry_key: found item %h is not directory item or "
152 "does not belong to the same directory as key %K",
155 #endif /* CONFIG_REISERFS_CHECK */
157 /* binary search in directory item by third componen t of the
158 key. sets de->de_entry_num of de */
159 retval
= bin_search_in_dir_item(de
, cpu_key_k_offset(key
));
160 path
->pos_in_item
= de
->de_entry_num
;
161 if (retval
!= NAME_NOT_FOUND
) {
162 // ugly, but rename needs de_bh, de_deh, de_name, de_namelen, de_objectid set
163 set_de_name_and_namelen(de
);
164 set_de_object_key(de
);
169 /* Keyed 32-bit hash function using TEA in a Davis-Meyer function */
171 /* The third component is hashed, and you can choose from more than
172 one hash function. Per directory hashes are not yet implemented
173 but are thought about. This function should be moved to hashes.c
174 Jedi, please do so. -Hans */
176 static __u32
get_third_component(struct super_block
*s
,
177 const char *name
, int len
)
181 if (!len
|| (len
== 1 && name
[0] == '.'))
183 if (len
== 2 && name
[0] == '.' && name
[1] == '.')
184 return DOT_DOT_OFFSET
;
186 res
= REISERFS_SB(s
)->s_hash_function(name
, len
);
188 // take bits from 7-th to 30-th including both bounds
189 res
= GET_HASH_VALUE(res
);
191 // needed to have no names before "." and ".." those have hash
192 // value == 0 and generation conters 1 and 2 accordingly
194 return res
+ MAX_GENERATION_NUMBER
;
197 static int reiserfs_match(struct reiserfs_dir_entry
*de
,
198 const char *name
, int namelen
)
200 int retval
= NAME_NOT_FOUND
;
202 if ((namelen
== de
->de_namelen
) &&
203 !memcmp(de
->de_name
, name
, de
->de_namelen
))
205 (de_visible(de
->de_deh
+ de
->de_entry_num
) ? NAME_FOUND
:
206 NAME_FOUND_INVISIBLE
);
211 /* de's de_bh, de_ih, de_deh, de_item_num, de_entry_num are set already */
213 /* used when hash collisions exist */
215 static int linear_search_in_dir_item(struct cpu_key
*key
,
216 struct reiserfs_dir_entry
*de
,
217 const char *name
, int namelen
)
219 struct reiserfs_de_head
*deh
= de
->de_deh
;
223 i
= de
->de_entry_num
;
225 if (i
== I_ENTRY_COUNT(de
->de_ih
) ||
226 GET_HASH_VALUE(deh_offset(deh
+ i
)) !=
227 GET_HASH_VALUE(cpu_key_k_offset(key
))) {
231 RFALSE(de
->de_deh
!= B_I_DEH(de
->de_bh
, de
->de_ih
),
232 "vs-7010: array of entry headers not found");
236 for (; i
>= 0; i
--, deh
--) {
237 if (GET_HASH_VALUE(deh_offset(deh
)) !=
238 GET_HASH_VALUE(cpu_key_k_offset(key
))) {
239 // hash value does not match, no need to check whole name
240 return NAME_NOT_FOUND
;
243 /* mark, that this generation number is used */
244 if (de
->de_gen_number_bit_string
)
245 set_bit(GET_GENERATION_NUMBER(deh_offset(deh
)),
246 de
->de_gen_number_bit_string
);
248 // calculate pointer to name and namelen
249 de
->de_entry_num
= i
;
250 set_de_name_and_namelen(de
);
253 reiserfs_match(de
, name
, namelen
)) != NAME_NOT_FOUND
) {
254 // de's de_name, de_namelen, de_recordlen are set. Fill the rest:
256 // key of pointed object
257 set_de_object_key(de
);
259 store_de_entry_key(de
);
261 // retval can be NAME_FOUND or NAME_FOUND_INVISIBLE
266 if (GET_GENERATION_NUMBER(le_ih_k_offset(de
->de_ih
)) == 0)
267 /* we have reached left most entry in the node. In common we
268 have to go to the left neighbor, but if generation counter
269 is 0 already, we know for sure, that there is no name with
270 the same hash value */
271 // FIXME: this work correctly only because hash value can not
272 // be 0. Btw, in case of Yura's hash it is probably possible,
274 return NAME_NOT_FOUND
;
276 RFALSE(de
->de_item_num
,
277 "vs-7015: two diritems of the same directory in one node?");
279 return GOTO_PREVIOUS_ITEM
;
282 // may return NAME_FOUND, NAME_FOUND_INVISIBLE, NAME_NOT_FOUND
283 // FIXME: should add something like IOERROR
284 static int reiserfs_find_entry(struct inode
*dir
, const char *name
, int namelen
,
285 struct path
*path_to_entry
,
286 struct reiserfs_dir_entry
*de
)
288 struct cpu_key key_to_search
;
291 if (namelen
> REISERFS_MAX_NAME(dir
->i_sb
->s_blocksize
))
292 return NAME_NOT_FOUND
;
294 /* we will search for this key in the tree */
295 make_cpu_key(&key_to_search
, dir
,
296 get_third_component(dir
->i_sb
, name
, namelen
),
301 search_by_entry_key(dir
->i_sb
, &key_to_search
,
303 if (retval
== IO_ERROR
) {
304 reiserfs_warning(dir
->i_sb
, "zam-7001: io error in %s",
309 /* compare names for all entries having given hash value */
311 linear_search_in_dir_item(&key_to_search
, de
, name
,
313 if (retval
!= GOTO_PREVIOUS_ITEM
) {
314 /* there is no need to scan directory anymore. Given entry found or does not exist */
315 path_to_entry
->pos_in_item
= de
->de_entry_num
;
319 /* there is left neighboring item of this directory and given entry can be there */
320 set_cpu_key_k_offset(&key_to_search
,
321 le_ih_k_offset(de
->de_ih
) - 1);
322 pathrelse(path_to_entry
);
327 static struct dentry
*reiserfs_lookup(struct inode
*dir
, struct dentry
*dentry
,
328 struct nameidata
*nd
)
331 struct inode
*inode
= NULL
;
332 struct reiserfs_dir_entry de
;
333 INITIALIZE_PATH(path_to_entry
);
335 if (REISERFS_MAX_NAME(dir
->i_sb
->s_blocksize
) < dentry
->d_name
.len
)
336 return ERR_PTR(-ENAMETOOLONG
);
338 reiserfs_write_lock(dir
->i_sb
);
339 de
.de_gen_number_bit_string
= NULL
;
341 reiserfs_find_entry(dir
, dentry
->d_name
.name
, dentry
->d_name
.len
,
342 &path_to_entry
, &de
);
343 pathrelse(&path_to_entry
);
344 if (retval
== NAME_FOUND
) {
345 /* Hide the .reiserfs_priv directory */
346 if (reiserfs_xattrs(dir
->i_sb
) &&
347 !old_format_only(dir
->i_sb
) &&
348 REISERFS_SB(dir
->i_sb
)->priv_root
&&
349 REISERFS_SB(dir
->i_sb
)->priv_root
->d_inode
&&
351 le32_to_cpu(INODE_PKEY
352 (REISERFS_SB(dir
->i_sb
)->priv_root
->d_inode
)->
354 reiserfs_write_unlock(dir
->i_sb
);
355 return ERR_PTR(-EACCES
);
359 reiserfs_iget(dir
->i_sb
, (struct cpu_key
*)&(de
.de_dir_id
));
360 if (!inode
|| IS_ERR(inode
)) {
361 reiserfs_write_unlock(dir
->i_sb
);
362 return ERR_PTR(-EACCES
);
365 /* Propogate the priv_object flag so we know we're in the priv tree */
366 if (is_reiserfs_priv_object(dir
))
367 reiserfs_mark_inode_private(inode
);
369 reiserfs_write_unlock(dir
->i_sb
);
370 if (retval
== IO_ERROR
) {
371 return ERR_PTR(-EIO
);
374 return d_splice_alias(inode
, dentry
);
378 ** looks up the dentry of the parent directory for child.
379 ** taken from ext2_get_parent
381 struct dentry
*reiserfs_get_parent(struct dentry
*child
)
384 struct inode
*inode
= NULL
;
385 struct reiserfs_dir_entry de
;
386 INITIALIZE_PATH(path_to_entry
);
387 struct dentry
*parent
;
388 struct inode
*dir
= child
->d_inode
;
390 if (dir
->i_nlink
== 0) {
391 return ERR_PTR(-ENOENT
);
393 de
.de_gen_number_bit_string
= NULL
;
395 reiserfs_write_lock(dir
->i_sb
);
396 retval
= reiserfs_find_entry(dir
, "..", 2, &path_to_entry
, &de
);
397 pathrelse(&path_to_entry
);
398 if (retval
!= NAME_FOUND
) {
399 reiserfs_write_unlock(dir
->i_sb
);
400 return ERR_PTR(-ENOENT
);
402 inode
= reiserfs_iget(dir
->i_sb
, (struct cpu_key
*)&(de
.de_dir_id
));
403 reiserfs_write_unlock(dir
->i_sb
);
405 if (!inode
|| IS_ERR(inode
)) {
406 return ERR_PTR(-EACCES
);
408 parent
= d_alloc_anon(inode
);
411 parent
= ERR_PTR(-ENOMEM
);
416 /* add entry to the directory (entry can be hidden).
418 insert definition of when hidden directories are used here -Hans
420 Does not mark dir inode dirty, do it after successesfull call to it */
422 static int reiserfs_add_entry(struct reiserfs_transaction_handle
*th
,
423 struct inode
*dir
, const char *name
, int namelen
,
424 struct inode
*inode
, int visible
)
426 struct cpu_key entry_key
;
427 struct reiserfs_de_head
*deh
;
428 INITIALIZE_PATH(path
);
429 struct reiserfs_dir_entry de
;
430 DECLARE_BITMAP(bit_string
, MAX_GENERATION_NUMBER
+ 1);
432 char small_buf
[32 + DEH_SIZE
]; /* 48 bytes now and we avoid kmalloc
433 if we create file with short name */
435 int buflen
, paste_size
;
438 BUG_ON(!th
->t_trans_id
);
440 /* cannot allow items to be added into a busy deleted directory */
444 if (namelen
> REISERFS_MAX_NAME(dir
->i_sb
->s_blocksize
))
445 return -ENAMETOOLONG
;
447 /* each entry has unique key. compose it */
448 make_cpu_key(&entry_key
, dir
,
449 get_third_component(dir
->i_sb
, name
, namelen
),
452 /* get memory for composing the entry */
453 buflen
= DEH_SIZE
+ ROUND_UP(namelen
);
454 if (buflen
> sizeof(small_buf
)) {
455 buffer
= kmalloc(buflen
, GFP_NOFS
);
462 (get_inode_sd_version(dir
) ==
463 STAT_DATA_V1
) ? (DEH_SIZE
+ namelen
) : buflen
;
465 /* fill buffer : directory entry head, name[, dir objectid | , stat data | ,stat data, dir objectid ] */
466 deh
= (struct reiserfs_de_head
*)buffer
;
467 deh
->deh_location
= 0; /* JDM Endian safe if 0 */
468 put_deh_offset(deh
, cpu_key_k_offset(&entry_key
));
469 deh
->deh_state
= 0; /* JDM Endian safe if 0 */
470 /* put key (ino analog) to de */
471 deh
->deh_dir_id
= INODE_PKEY(inode
)->k_dir_id
; /* safe: k_dir_id is le */
472 deh
->deh_objectid
= INODE_PKEY(inode
)->k_objectid
; /* safe: k_objectid is le */
475 memcpy((char *)(deh
+ 1), name
, namelen
);
476 /* padd by 0s to the 4 byte boundary */
477 padd_item((char *)(deh
+ 1), ROUND_UP(namelen
), namelen
);
479 /* entry is ready to be pasted into tree, set 'visibility' and 'stat data in entry' attributes */
480 mark_de_without_sd(deh
);
481 visible
? mark_de_visible(deh
) : mark_de_hidden(deh
);
483 /* find the proper place for the new entry */
484 memset(bit_string
, 0, sizeof(bit_string
));
485 de
.de_gen_number_bit_string
= bit_string
;
486 retval
= reiserfs_find_entry(dir
, name
, namelen
, &path
, &de
);
487 if (retval
!= NAME_NOT_FOUND
) {
488 if (buffer
!= small_buf
)
492 if (retval
== IO_ERROR
) {
496 if (retval
!= NAME_FOUND
) {
497 reiserfs_warning(dir
->i_sb
,
498 "zam-7002:%s: \"reiserfs_find_entry\" "
499 "has returned unexpected value (%d)",
500 __FUNCTION__
, retval
);
507 find_first_zero_bit(bit_string
,
508 MAX_GENERATION_NUMBER
+ 1);
509 if (gen_number
> MAX_GENERATION_NUMBER
) {
510 /* there is no free generation number */
511 reiserfs_warning(dir
->i_sb
,
512 "reiserfs_add_entry: Congratulations! we have got hash function screwed up");
513 if (buffer
!= small_buf
)
518 /* adjust offset of directory enrty */
519 put_deh_offset(deh
, SET_GENERATION_NUMBER(deh_offset(deh
), gen_number
));
520 set_cpu_key_k_offset(&entry_key
, deh_offset(deh
));
522 /* update max-hash-collisions counter in reiserfs_sb_info */
523 PROC_INFO_MAX(th
->t_super
, max_hash_collisions
, gen_number
);
525 if (gen_number
!= 0) { /* we need to re-search for the insertion point */
526 if (search_by_entry_key(dir
->i_sb
, &entry_key
, &path
, &de
) !=
528 reiserfs_warning(dir
->i_sb
,
529 "vs-7032: reiserfs_add_entry: "
530 "entry with this key (%K) already exists",
533 if (buffer
!= small_buf
)
540 /* perform the insertion of the entry that we have prepared */
542 reiserfs_paste_into_item(th
, &path
, &entry_key
, dir
, buffer
,
544 if (buffer
!= small_buf
)
547 reiserfs_check_path(&path
);
551 dir
->i_size
+= paste_size
;
552 dir
->i_mtime
= dir
->i_ctime
= CURRENT_TIME_SEC
;
553 if (!S_ISDIR(inode
->i_mode
) && visible
)
554 // reiserfs_mkdir or reiserfs_rename will do that by itself
555 reiserfs_update_sd(th
, dir
);
557 reiserfs_check_path(&path
);
561 /* quota utility function, call if you've had to abort after calling
562 ** new_inode_init, and have not called reiserfs_new_inode yet.
563 ** This should only be called on inodes that do not have stat data
564 ** inserted into the tree yet.
566 static int drop_new_inode(struct inode
*inode
)
569 make_bad_inode(inode
);
570 inode
->i_flags
|= S_NOQUOTA
;
575 /* utility function that does setup for reiserfs_new_inode.
576 ** DQUOT_INIT needs lots of credits so it's better to have it
577 ** outside of a transaction, so we had to pull some bits of
578 ** reiserfs_new_inode out into this func.
580 static int new_inode_init(struct inode
*inode
, struct inode
*dir
, int mode
)
583 /* the quota init calls have to know who to charge the quota to, so
584 ** we have to set uid and gid here
586 inode
->i_uid
= current
->fsuid
;
587 inode
->i_mode
= mode
;
588 /* Make inode invalid - just in case we are going to drop it before
589 * the initialization happens */
590 INODE_PKEY(inode
)->k_objectid
= 0;
592 if (dir
->i_mode
& S_ISGID
) {
593 inode
->i_gid
= dir
->i_gid
;
595 inode
->i_mode
|= S_ISGID
;
597 inode
->i_gid
= current
->fsgid
;
603 static int reiserfs_create(struct inode
*dir
, struct dentry
*dentry
, int mode
,
604 struct nameidata
*nd
)
608 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
610 JOURNAL_PER_BALANCE_CNT
* 2 +
611 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir
->i_sb
) +
612 REISERFS_QUOTA_TRANS_BLOCKS(dir
->i_sb
));
613 struct reiserfs_transaction_handle th
;
616 if (!(inode
= new_inode(dir
->i_sb
))) {
619 new_inode_init(inode
, dir
, mode
);
621 locked
= reiserfs_cache_default_acl(dir
);
623 reiserfs_write_lock(dir
->i_sb
);
626 reiserfs_write_lock_xattrs(dir
->i_sb
);
628 retval
= journal_begin(&th
, dir
->i_sb
, jbegin_count
);
630 drop_new_inode(inode
);
635 reiserfs_new_inode(&th
, dir
, mode
, NULL
, 0 /*i_size */ , dentry
,
641 reiserfs_write_unlock_xattrs(dir
->i_sb
);
645 inode
->i_op
= &reiserfs_file_inode_operations
;
646 inode
->i_fop
= &reiserfs_file_operations
;
647 inode
->i_mapping
->a_ops
= &reiserfs_address_space_operations
;
650 reiserfs_add_entry(&th
, dir
, dentry
->d_name
.name
,
651 dentry
->d_name
.len
, inode
, 1 /*visible */ );
655 reiserfs_update_sd(&th
, inode
);
656 err
= journal_end(&th
, dir
->i_sb
, jbegin_count
);
662 reiserfs_update_inode_transaction(inode
);
663 reiserfs_update_inode_transaction(dir
);
665 d_instantiate(dentry
, inode
);
666 retval
= journal_end(&th
, dir
->i_sb
, jbegin_count
);
670 reiserfs_write_unlock_xattrs(dir
->i_sb
);
671 reiserfs_write_unlock(dir
->i_sb
);
675 static int reiserfs_mknod(struct inode
*dir
, struct dentry
*dentry
, int mode
,
680 struct reiserfs_transaction_handle th
;
681 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
683 JOURNAL_PER_BALANCE_CNT
* 3 +
684 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir
->i_sb
) +
685 REISERFS_QUOTA_TRANS_BLOCKS(dir
->i_sb
));
688 if (!new_valid_dev(rdev
))
691 if (!(inode
= new_inode(dir
->i_sb
))) {
694 new_inode_init(inode
, dir
, mode
);
696 locked
= reiserfs_cache_default_acl(dir
);
698 reiserfs_write_lock(dir
->i_sb
);
701 reiserfs_write_lock_xattrs(dir
->i_sb
);
703 retval
= journal_begin(&th
, dir
->i_sb
, jbegin_count
);
705 drop_new_inode(inode
);
710 reiserfs_new_inode(&th
, dir
, mode
, NULL
, 0 /*i_size */ , dentry
,
717 reiserfs_write_unlock_xattrs(dir
->i_sb
);
721 inode
->i_op
= &reiserfs_special_inode_operations
;
722 init_special_inode(inode
, inode
->i_mode
, rdev
);
724 //FIXME: needed for block and char devices only
725 reiserfs_update_sd(&th
, inode
);
727 reiserfs_update_inode_transaction(inode
);
728 reiserfs_update_inode_transaction(dir
);
731 reiserfs_add_entry(&th
, dir
, dentry
->d_name
.name
,
732 dentry
->d_name
.len
, inode
, 1 /*visible */ );
736 reiserfs_update_sd(&th
, inode
);
737 err
= journal_end(&th
, dir
->i_sb
, jbegin_count
);
744 d_instantiate(dentry
, inode
);
745 retval
= journal_end(&th
, dir
->i_sb
, jbegin_count
);
749 reiserfs_write_unlock_xattrs(dir
->i_sb
);
750 reiserfs_write_unlock(dir
->i_sb
);
754 static int reiserfs_mkdir(struct inode
*dir
, struct dentry
*dentry
, int mode
)
758 struct reiserfs_transaction_handle th
;
759 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
761 JOURNAL_PER_BALANCE_CNT
* 3 +
762 2 * (REISERFS_QUOTA_INIT_BLOCKS(dir
->i_sb
) +
763 REISERFS_QUOTA_TRANS_BLOCKS(dir
->i_sb
));
766 #ifdef DISPLACE_NEW_PACKING_LOCALITIES
767 /* set flag that new packing locality created and new blocks for the content * of that directory are not displaced yet */
768 REISERFS_I(dir
)->new_packing_locality
= 1;
770 mode
= S_IFDIR
| mode
;
771 if (!(inode
= new_inode(dir
->i_sb
))) {
774 new_inode_init(inode
, dir
, mode
);
776 locked
= reiserfs_cache_default_acl(dir
);
778 reiserfs_write_lock(dir
->i_sb
);
780 reiserfs_write_lock_xattrs(dir
->i_sb
);
782 retval
= journal_begin(&th
, dir
->i_sb
, jbegin_count
);
784 drop_new_inode(inode
);
788 /* inc the link count now, so another writer doesn't overflow it while
789 ** we sleep later on.
791 INC_DIR_INODE_NLINK(dir
)
793 retval
= reiserfs_new_inode(&th
, dir
, mode
, NULL
/*symlink */ ,
794 old_format_only(dir
->i_sb
) ?
795 EMPTY_DIR_SIZE_V1
: EMPTY_DIR_SIZE
,
803 reiserfs_write_unlock_xattrs(dir
->i_sb
);
807 reiserfs_update_inode_transaction(inode
);
808 reiserfs_update_inode_transaction(dir
);
810 inode
->i_op
= &reiserfs_dir_inode_operations
;
811 inode
->i_fop
= &reiserfs_dir_operations
;
813 // note, _this_ add_entry will not update dir's stat data
815 reiserfs_add_entry(&th
, dir
, dentry
->d_name
.name
,
816 dentry
->d_name
.len
, inode
, 1 /*visible */ );
820 DEC_DIR_INODE_NLINK(dir
);
821 reiserfs_update_sd(&th
, inode
);
822 err
= journal_end(&th
, dir
->i_sb
, jbegin_count
);
828 // the above add_entry did not update dir's stat data
829 reiserfs_update_sd(&th
, dir
);
831 d_instantiate(dentry
, inode
);
832 retval
= journal_end(&th
, dir
->i_sb
, jbegin_count
);
835 reiserfs_write_unlock_xattrs(dir
->i_sb
);
836 reiserfs_write_unlock(dir
->i_sb
);
840 static inline int reiserfs_empty_dir(struct inode
*inode
)
842 /* we can cheat because an old format dir cannot have
843 ** EMPTY_DIR_SIZE, and a new format dir cannot have
844 ** EMPTY_DIR_SIZE_V1. So, if the inode is either size,
845 ** regardless of disk format version, the directory is empty.
847 if (inode
->i_size
!= EMPTY_DIR_SIZE
&&
848 inode
->i_size
!= EMPTY_DIR_SIZE_V1
) {
854 static int reiserfs_rmdir(struct inode
*dir
, struct dentry
*dentry
)
858 struct reiserfs_transaction_handle th
;
860 INITIALIZE_PATH(path
);
861 struct reiserfs_dir_entry de
;
863 /* we will be doing 2 balancings and update 2 stat data, we change quotas
864 * of the owner of the directory and of the owner of the parent directory.
865 * The quota structure is possibly deleted only on last iput => outside
866 * of this transaction */
868 JOURNAL_PER_BALANCE_CNT
* 2 + 2 +
869 4 * REISERFS_QUOTA_TRANS_BLOCKS(dir
->i_sb
);
871 reiserfs_write_lock(dir
->i_sb
);
872 retval
= journal_begin(&th
, dir
->i_sb
, jbegin_count
);
876 de
.de_gen_number_bit_string
= NULL
;
878 reiserfs_find_entry(dir
, dentry
->d_name
.name
, dentry
->d_name
.len
,
879 &path
, &de
)) == NAME_NOT_FOUND
) {
882 } else if (retval
== IO_ERROR
) {
887 inode
= dentry
->d_inode
;
889 reiserfs_update_inode_transaction(inode
);
890 reiserfs_update_inode_transaction(dir
);
892 if (de
.de_objectid
!= inode
->i_ino
) {
893 // FIXME: compare key of an object and a key found in the
898 if (!reiserfs_empty_dir(inode
)) {
903 /* cut entry from dir directory */
904 retval
= reiserfs_cut_from_item(&th
, &path
, &(de
.de_entry_key
), dir
, NULL
, /* page */
905 0 /*new file size - not used here */ );
909 if (inode
->i_nlink
!= 2 && inode
->i_nlink
!= 1)
910 reiserfs_warning(inode
->i_sb
, "%s: empty directory has nlink "
911 "!= 2 (%d)", __FUNCTION__
, inode
->i_nlink
);
914 inode
->i_ctime
= dir
->i_ctime
= dir
->i_mtime
= CURRENT_TIME_SEC
;
915 reiserfs_update_sd(&th
, inode
);
917 DEC_DIR_INODE_NLINK(dir
)
918 dir
->i_size
-= (DEH_SIZE
+ de
.de_entrylen
);
919 reiserfs_update_sd(&th
, dir
);
921 /* prevent empty directory from getting lost */
922 add_save_link(&th
, inode
, 0 /* not truncate */ );
924 retval
= journal_end(&th
, dir
->i_sb
, jbegin_count
);
925 reiserfs_check_path(&path
);
927 reiserfs_write_unlock(dir
->i_sb
);
931 /* we must release path, because we did not call
932 reiserfs_cut_from_item, or reiserfs_cut_from_item does not
933 release path if operation was not complete */
935 err
= journal_end(&th
, dir
->i_sb
, jbegin_count
);
936 reiserfs_write_unlock(dir
->i_sb
);
937 return err
? err
: retval
;
940 static int reiserfs_unlink(struct inode
*dir
, struct dentry
*dentry
)
944 struct reiserfs_dir_entry de
;
945 INITIALIZE_PATH(path
);
946 struct reiserfs_transaction_handle th
;
948 unsigned long savelink
;
950 inode
= dentry
->d_inode
;
952 /* in this transaction we can be doing at max two balancings and update
953 * two stat datas, we change quotas of the owner of the directory and of
954 * the owner of the parent directory. The quota structure is possibly
955 * deleted only on iput => outside of this transaction */
957 JOURNAL_PER_BALANCE_CNT
* 2 + 2 +
958 4 * REISERFS_QUOTA_TRANS_BLOCKS(dir
->i_sb
);
960 reiserfs_write_lock(dir
->i_sb
);
961 retval
= journal_begin(&th
, dir
->i_sb
, jbegin_count
);
965 de
.de_gen_number_bit_string
= NULL
;
967 reiserfs_find_entry(dir
, dentry
->d_name
.name
, dentry
->d_name
.len
,
968 &path
, &de
)) == NAME_NOT_FOUND
) {
971 } else if (retval
== IO_ERROR
) {
976 reiserfs_update_inode_transaction(inode
);
977 reiserfs_update_inode_transaction(dir
);
979 if (de
.de_objectid
!= inode
->i_ino
) {
980 // FIXME: compare key of an object and a key found in the
986 if (!inode
->i_nlink
) {
987 reiserfs_warning(inode
->i_sb
, "%s: deleting nonexistent file "
988 "(%s:%lu), %d", __FUNCTION__
,
989 reiserfs_bdevname(inode
->i_sb
), inode
->i_ino
,
997 * we schedule before doing the add_save_link call, save the link
998 * count so we don't race
1000 savelink
= inode
->i_nlink
;
1003 reiserfs_cut_from_item(&th
, &path
, &(de
.de_entry_key
), dir
, NULL
,
1009 inode
->i_ctime
= CURRENT_TIME_SEC
;
1010 reiserfs_update_sd(&th
, inode
);
1012 dir
->i_size
-= (de
.de_entrylen
+ DEH_SIZE
);
1013 dir
->i_ctime
= dir
->i_mtime
= CURRENT_TIME_SEC
;
1014 reiserfs_update_sd(&th
, dir
);
1017 /* prevent file from getting lost */
1018 add_save_link(&th
, inode
, 0 /* not truncate */ );
1020 retval
= journal_end(&th
, dir
->i_sb
, jbegin_count
);
1021 reiserfs_check_path(&path
);
1022 reiserfs_write_unlock(dir
->i_sb
);
1027 err
= journal_end(&th
, dir
->i_sb
, jbegin_count
);
1028 reiserfs_check_path(&path
);
1032 reiserfs_write_unlock(dir
->i_sb
);
1036 static int reiserfs_symlink(struct inode
*parent_dir
,
1037 struct dentry
*dentry
, const char *symname
)
1040 struct inode
*inode
;
1043 struct reiserfs_transaction_handle th
;
1044 int mode
= S_IFLNK
| S_IRWXUGO
;
1045 /* We need blocks for transaction + (user+group)*(quotas for new inode + update of quota for directory owner) */
1047 JOURNAL_PER_BALANCE_CNT
* 3 +
1048 2 * (REISERFS_QUOTA_INIT_BLOCKS(parent_dir
->i_sb
) +
1049 REISERFS_QUOTA_TRANS_BLOCKS(parent_dir
->i_sb
));
1051 if (!(inode
= new_inode(parent_dir
->i_sb
))) {
1054 new_inode_init(inode
, parent_dir
, mode
);
1056 reiserfs_write_lock(parent_dir
->i_sb
);
1057 item_len
= ROUND_UP(strlen(symname
));
1058 if (item_len
> MAX_DIRECT_ITEM_LEN(parent_dir
->i_sb
->s_blocksize
)) {
1059 retval
= -ENAMETOOLONG
;
1060 drop_new_inode(inode
);
1064 name
= kmalloc(item_len
, GFP_NOFS
);
1066 drop_new_inode(inode
);
1070 memcpy(name
, symname
, strlen(symname
));
1071 padd_item(name
, item_len
, strlen(symname
));
1073 /* We would inherit the default ACL here, but symlinks don't get ACLs */
1075 retval
= journal_begin(&th
, parent_dir
->i_sb
, jbegin_count
);
1077 drop_new_inode(inode
);
1083 reiserfs_new_inode(&th
, parent_dir
, mode
, name
, strlen(symname
),
1086 if (retval
) { /* reiserfs_new_inode iputs for us */
1090 reiserfs_update_inode_transaction(inode
);
1091 reiserfs_update_inode_transaction(parent_dir
);
1093 inode
->i_op
= &reiserfs_symlink_inode_operations
;
1094 inode
->i_mapping
->a_ops
= &reiserfs_address_space_operations
;
1096 // must be sure this inode is written with this transaction
1098 //reiserfs_update_sd (&th, inode, READ_BLOCKS);
1100 retval
= reiserfs_add_entry(&th
, parent_dir
, dentry
->d_name
.name
,
1101 dentry
->d_name
.len
, inode
, 1 /*visible */ );
1105 reiserfs_update_sd(&th
, inode
);
1106 err
= journal_end(&th
, parent_dir
->i_sb
, jbegin_count
);
1113 d_instantiate(dentry
, inode
);
1114 retval
= journal_end(&th
, parent_dir
->i_sb
, jbegin_count
);
1116 reiserfs_write_unlock(parent_dir
->i_sb
);
1120 static int reiserfs_link(struct dentry
*old_dentry
, struct inode
*dir
,
1121 struct dentry
*dentry
)
1124 struct inode
*inode
= old_dentry
->d_inode
;
1125 struct reiserfs_transaction_handle th
;
1126 /* We need blocks for transaction + update of quotas for the owners of the directory */
1128 JOURNAL_PER_BALANCE_CNT
* 3 +
1129 2 * REISERFS_QUOTA_TRANS_BLOCKS(dir
->i_sb
);
1131 reiserfs_write_lock(dir
->i_sb
);
1132 if (inode
->i_nlink
>= REISERFS_LINK_MAX
) {
1133 //FIXME: sd_nlink is 32 bit for new files
1134 reiserfs_write_unlock(dir
->i_sb
);
1137 if (inode
->i_nlink
== 0) {
1138 reiserfs_write_unlock(dir
->i_sb
);
1142 /* inc before scheduling so reiserfs_unlink knows we are here */
1145 retval
= journal_begin(&th
, dir
->i_sb
, jbegin_count
);
1148 reiserfs_write_unlock(dir
->i_sb
);
1152 /* create new entry */
1154 reiserfs_add_entry(&th
, dir
, dentry
->d_name
.name
,
1155 dentry
->d_name
.len
, inode
, 1 /*visible */ );
1157 reiserfs_update_inode_transaction(inode
);
1158 reiserfs_update_inode_transaction(dir
);
1163 err
= journal_end(&th
, dir
->i_sb
, jbegin_count
);
1164 reiserfs_write_unlock(dir
->i_sb
);
1165 return err
? err
: retval
;
1168 inode
->i_ctime
= CURRENT_TIME_SEC
;
1169 reiserfs_update_sd(&th
, inode
);
1171 atomic_inc(&inode
->i_count
);
1172 d_instantiate(dentry
, inode
);
1173 retval
= journal_end(&th
, dir
->i_sb
, jbegin_count
);
1174 reiserfs_write_unlock(dir
->i_sb
);
1178 // de contains information pointing to an entry which
1179 static int de_still_valid(const char *name
, int len
,
1180 struct reiserfs_dir_entry
*de
)
1182 struct reiserfs_dir_entry tmp
= *de
;
1184 // recalculate pointer to name and name length
1185 set_de_name_and_namelen(&tmp
);
1186 // FIXME: could check more
1187 if (tmp
.de_namelen
!= len
|| memcmp(name
, de
->de_name
, len
))
1192 static int entry_points_to_object(const char *name
, int len
,
1193 struct reiserfs_dir_entry
*de
,
1194 struct inode
*inode
)
1196 if (!de_still_valid(name
, len
, de
))
1200 if (!de_visible(de
->de_deh
+ de
->de_entry_num
))
1201 reiserfs_panic(NULL
,
1202 "vs-7042: entry_points_to_object: entry must be visible");
1203 return (de
->de_objectid
== inode
->i_ino
) ? 1 : 0;
1206 /* this must be added hidden entry */
1207 if (de_visible(de
->de_deh
+ de
->de_entry_num
))
1208 reiserfs_panic(NULL
,
1209 "vs-7043: entry_points_to_object: entry must be visible");
1214 /* sets key of objectid the entry has to point to */
1215 static void set_ino_in_dir_entry(struct reiserfs_dir_entry
*de
,
1216 struct reiserfs_key
*key
)
1218 /* JDM These operations are endian safe - both are le */
1219 de
->de_deh
[de
->de_entry_num
].deh_dir_id
= key
->k_dir_id
;
1220 de
->de_deh
[de
->de_entry_num
].deh_objectid
= key
->k_objectid
;
1224 * process, that is going to call fix_nodes/do_balance must hold only
1225 * one path. If it holds 2 or more, it can get into endless waiting in
1226 * get_empty_nodes or its clones
1228 static int reiserfs_rename(struct inode
*old_dir
, struct dentry
*old_dentry
,
1229 struct inode
*new_dir
, struct dentry
*new_dentry
)
1232 INITIALIZE_PATH(old_entry_path
);
1233 INITIALIZE_PATH(new_entry_path
);
1234 INITIALIZE_PATH(dot_dot_entry_path
);
1235 struct item_head new_entry_ih
, old_entry_ih
, dot_dot_ih
;
1236 struct reiserfs_dir_entry old_de
, new_de
, dot_dot_de
;
1237 struct inode
*old_inode
, *new_dentry_inode
;
1238 struct reiserfs_transaction_handle th
;
1240 umode_t old_inode_mode
;
1241 unsigned long savelink
= 1;
1242 struct timespec ctime
;
1244 /* three balancings: (1) old name removal, (2) new name insertion
1245 and (3) maybe "save" link insertion
1246 stat data updates: (1) old directory,
1247 (2) new directory and (3) maybe old object stat data (when it is
1248 directory) and (4) maybe stat data of object to which new entry
1249 pointed initially and (5) maybe block containing ".." of
1251 quota updates: two parent directories */
1253 JOURNAL_PER_BALANCE_CNT
* 3 + 5 +
1254 4 * REISERFS_QUOTA_TRANS_BLOCKS(old_dir
->i_sb
);
1256 old_inode
= old_dentry
->d_inode
;
1257 new_dentry_inode
= new_dentry
->d_inode
;
1259 // make sure, that oldname still exists and points to an object we
1260 // are going to rename
1261 old_de
.de_gen_number_bit_string
= NULL
;
1262 reiserfs_write_lock(old_dir
->i_sb
);
1264 reiserfs_find_entry(old_dir
, old_dentry
->d_name
.name
,
1265 old_dentry
->d_name
.len
, &old_entry_path
,
1267 pathrelse(&old_entry_path
);
1268 if (retval
== IO_ERROR
) {
1269 reiserfs_write_unlock(old_dir
->i_sb
);
1273 if (retval
!= NAME_FOUND
|| old_de
.de_objectid
!= old_inode
->i_ino
) {
1274 reiserfs_write_unlock(old_dir
->i_sb
);
1278 old_inode_mode
= old_inode
->i_mode
;
1279 if (S_ISDIR(old_inode_mode
)) {
1280 // make sure, that directory being renamed has correct ".."
1281 // and that its new parent directory has not too many links
1284 if (new_dentry_inode
) {
1285 if (!reiserfs_empty_dir(new_dentry_inode
)) {
1286 reiserfs_write_unlock(old_dir
->i_sb
);
1291 /* directory is renamed, its parent directory will be changed,
1292 ** so find ".." entry
1294 dot_dot_de
.de_gen_number_bit_string
= NULL
;
1296 reiserfs_find_entry(old_inode
, "..", 2, &dot_dot_entry_path
,
1298 pathrelse(&dot_dot_entry_path
);
1299 if (retval
!= NAME_FOUND
) {
1300 reiserfs_write_unlock(old_dir
->i_sb
);
1304 /* inode number of .. must equal old_dir->i_ino */
1305 if (dot_dot_de
.de_objectid
!= old_dir
->i_ino
) {
1306 reiserfs_write_unlock(old_dir
->i_sb
);
1311 retval
= journal_begin(&th
, old_dir
->i_sb
, jbegin_count
);
1313 reiserfs_write_unlock(old_dir
->i_sb
);
1317 /* add new entry (or find the existing one) */
1319 reiserfs_add_entry(&th
, new_dir
, new_dentry
->d_name
.name
,
1320 new_dentry
->d_name
.len
, old_inode
, 0);
1321 if (retval
== -EEXIST
) {
1322 if (!new_dentry_inode
) {
1323 reiserfs_panic(old_dir
->i_sb
,
1324 "vs-7050: new entry is found, new inode == 0\n");
1326 } else if (retval
) {
1327 int err
= journal_end(&th
, old_dir
->i_sb
, jbegin_count
);
1328 reiserfs_write_unlock(old_dir
->i_sb
);
1329 return err
? err
: retval
;
1332 reiserfs_update_inode_transaction(old_dir
);
1333 reiserfs_update_inode_transaction(new_dir
);
1335 /* this makes it so an fsync on an open fd for the old name will
1336 ** commit the rename operation
1338 reiserfs_update_inode_transaction(old_inode
);
1340 if (new_dentry_inode
)
1341 reiserfs_update_inode_transaction(new_dentry_inode
);
1344 // look for old name using corresponding entry key (found by reiserfs_find_entry)
1346 search_by_entry_key(new_dir
->i_sb
, &old_de
.de_entry_key
,
1348 &old_de
)) != NAME_FOUND
) {
1349 pathrelse(&old_entry_path
);
1350 journal_end(&th
, old_dir
->i_sb
, jbegin_count
);
1351 reiserfs_write_unlock(old_dir
->i_sb
);
1355 copy_item_head(&old_entry_ih
, get_ih(&old_entry_path
));
1357 reiserfs_prepare_for_journal(old_inode
->i_sb
, old_de
.de_bh
, 1);
1359 // look for new name by reiserfs_find_entry
1360 new_de
.de_gen_number_bit_string
= NULL
;
1362 reiserfs_find_entry(new_dir
, new_dentry
->d_name
.name
,
1363 new_dentry
->d_name
.len
, &new_entry_path
,
1365 // reiserfs_add_entry should not return IO_ERROR, because it is called with essentially same parameters from
1366 // reiserfs_add_entry above, and we'll catch any i/o errors before we get here.
1367 if (retval
!= NAME_FOUND_INVISIBLE
&& retval
!= NAME_FOUND
) {
1368 pathrelse(&new_entry_path
);
1369 pathrelse(&old_entry_path
);
1370 journal_end(&th
, old_dir
->i_sb
, jbegin_count
);
1371 reiserfs_write_unlock(old_dir
->i_sb
);
1375 copy_item_head(&new_entry_ih
, get_ih(&new_entry_path
));
1377 reiserfs_prepare_for_journal(old_inode
->i_sb
, new_de
.de_bh
, 1);
1379 if (S_ISDIR(old_inode
->i_mode
)) {
1381 search_by_entry_key(new_dir
->i_sb
,
1382 &dot_dot_de
.de_entry_key
,
1383 &dot_dot_entry_path
,
1384 &dot_dot_de
)) != NAME_FOUND
) {
1385 pathrelse(&dot_dot_entry_path
);
1386 pathrelse(&new_entry_path
);
1387 pathrelse(&old_entry_path
);
1388 journal_end(&th
, old_dir
->i_sb
, jbegin_count
);
1389 reiserfs_write_unlock(old_dir
->i_sb
);
1392 copy_item_head(&dot_dot_ih
,
1393 get_ih(&dot_dot_entry_path
));
1394 // node containing ".." gets into transaction
1395 reiserfs_prepare_for_journal(old_inode
->i_sb
,
1396 dot_dot_de
.de_bh
, 1);
1398 /* we should check seals here, not do
1399 this stuff, yes? Then, having
1400 gathered everything into RAM we
1401 should lock the buffers, yes? -Hans */
1402 /* probably. our rename needs to hold more
1403 ** than one path at once. The seals would
1404 ** have to be written to deal with multi-path
1407 /* sanity checking before doing the rename - avoid races many
1408 ** of the above checks could have scheduled. We have to be
1409 ** sure our items haven't been shifted by another process.
1411 if (item_moved(&new_entry_ih
, &new_entry_path
) ||
1412 !entry_points_to_object(new_dentry
->d_name
.name
,
1413 new_dentry
->d_name
.len
,
1414 &new_de
, new_dentry_inode
) ||
1415 item_moved(&old_entry_ih
, &old_entry_path
) ||
1416 !entry_points_to_object(old_dentry
->d_name
.name
,
1417 old_dentry
->d_name
.len
,
1418 &old_de
, old_inode
)) {
1419 reiserfs_restore_prepared_buffer(old_inode
->i_sb
,
1421 reiserfs_restore_prepared_buffer(old_inode
->i_sb
,
1423 if (S_ISDIR(old_inode_mode
))
1424 reiserfs_restore_prepared_buffer(old_inode
->
1430 if (S_ISDIR(old_inode_mode
)) {
1431 if (item_moved(&dot_dot_ih
, &dot_dot_entry_path
) ||
1432 !entry_points_to_object("..", 2, &dot_dot_de
,
1434 reiserfs_restore_prepared_buffer(old_inode
->
1437 reiserfs_restore_prepared_buffer(old_inode
->
1440 reiserfs_restore_prepared_buffer(old_inode
->
1448 RFALSE(S_ISDIR(old_inode_mode
) &&
1449 !buffer_journal_prepared(dot_dot_de
.de_bh
), "");
1454 /* ok, all the changes can be done in one fell swoop when we
1455 have claimed all the buffers needed. */
1457 mark_de_visible(new_de
.de_deh
+ new_de
.de_entry_num
);
1458 set_ino_in_dir_entry(&new_de
, INODE_PKEY(old_inode
));
1459 journal_mark_dirty(&th
, old_dir
->i_sb
, new_de
.de_bh
);
1461 mark_de_hidden(old_de
.de_deh
+ old_de
.de_entry_num
);
1462 journal_mark_dirty(&th
, old_dir
->i_sb
, old_de
.de_bh
);
1463 ctime
= CURRENT_TIME_SEC
;
1464 old_dir
->i_ctime
= old_dir
->i_mtime
= ctime
;
1465 new_dir
->i_ctime
= new_dir
->i_mtime
= ctime
;
1466 /* thanks to Alex Adriaanse <alex_a@caltech.edu> for patch which adds ctime update of
1468 old_inode
->i_ctime
= ctime
;
1470 if (new_dentry_inode
) {
1471 // adjust link number of the victim
1472 if (S_ISDIR(new_dentry_inode
->i_mode
)) {
1473 clear_nlink(new_dentry_inode
);
1475 drop_nlink(new_dentry_inode
);
1477 new_dentry_inode
->i_ctime
= ctime
;
1478 savelink
= new_dentry_inode
->i_nlink
;
1481 if (S_ISDIR(old_inode_mode
)) {
1482 // adjust ".." of renamed directory
1483 set_ino_in_dir_entry(&dot_dot_de
, INODE_PKEY(new_dir
));
1484 journal_mark_dirty(&th
, new_dir
->i_sb
, dot_dot_de
.de_bh
);
1486 if (!new_dentry_inode
)
1487 /* there (in new_dir) was no directory, so it got new link
1488 (".." of renamed directory) */
1489 INC_DIR_INODE_NLINK(new_dir
);
1491 /* old directory lost one link - ".. " of renamed directory */
1492 DEC_DIR_INODE_NLINK(old_dir
);
1494 // looks like in 2.3.99pre3 brelse is atomic. so we can use pathrelse
1495 pathrelse(&new_entry_path
);
1496 pathrelse(&dot_dot_entry_path
);
1498 // FIXME: this reiserfs_cut_from_item's return value may screw up
1499 // anybody, but it will panic if will not be able to find the
1500 // entry. This needs one more clean up
1501 if (reiserfs_cut_from_item
1502 (&th
, &old_entry_path
, &(old_de
.de_entry_key
), old_dir
, NULL
,
1504 reiserfs_warning(old_dir
->i_sb
,
1505 "vs-7060: reiserfs_rename: couldn't not cut old name. Fsck later?");
1507 old_dir
->i_size
-= DEH_SIZE
+ old_de
.de_entrylen
;
1509 reiserfs_update_sd(&th
, old_dir
);
1510 reiserfs_update_sd(&th
, new_dir
);
1511 reiserfs_update_sd(&th
, old_inode
);
1513 if (new_dentry_inode
) {
1515 add_save_link(&th
, new_dentry_inode
,
1516 0 /* not truncate */ );
1517 reiserfs_update_sd(&th
, new_dentry_inode
);
1520 retval
= journal_end(&th
, old_dir
->i_sb
, jbegin_count
);
1521 reiserfs_write_unlock(old_dir
->i_sb
);
1526 * directories can handle most operations...
1528 struct inode_operations reiserfs_dir_inode_operations
= {
1529 //&reiserfs_dir_operations, /* default_file_ops */
1530 .create
= reiserfs_create
,
1531 .lookup
= reiserfs_lookup
,
1532 .link
= reiserfs_link
,
1533 .unlink
= reiserfs_unlink
,
1534 .symlink
= reiserfs_symlink
,
1535 .mkdir
= reiserfs_mkdir
,
1536 .rmdir
= reiserfs_rmdir
,
1537 .mknod
= reiserfs_mknod
,
1538 .rename
= reiserfs_rename
,
1539 .setattr
= reiserfs_setattr
,
1540 .setxattr
= reiserfs_setxattr
,
1541 .getxattr
= reiserfs_getxattr
,
1542 .listxattr
= reiserfs_listxattr
,
1543 .removexattr
= reiserfs_removexattr
,
1544 .permission
= reiserfs_permission
,
1548 * symlink operations.. same as page_symlink_inode_operations, with xattr
1551 struct inode_operations reiserfs_symlink_inode_operations
= {
1552 .readlink
= generic_readlink
,
1553 .follow_link
= page_follow_link_light
,
1554 .put_link
= page_put_link
,
1555 .setattr
= reiserfs_setattr
,
1556 .setxattr
= reiserfs_setxattr
,
1557 .getxattr
= reiserfs_getxattr
,
1558 .listxattr
= reiserfs_listxattr
,
1559 .removexattr
= reiserfs_removexattr
,
1560 .permission
= reiserfs_permission
,
1565 * special file operations.. just xattr/acl stuff
1567 struct inode_operations reiserfs_special_inode_operations
= {
1568 .setattr
= reiserfs_setattr
,
1569 .setxattr
= reiserfs_setxattr
,
1570 .getxattr
= reiserfs_getxattr
,
1571 .listxattr
= reiserfs_listxattr
,
1572 .removexattr
= reiserfs_removexattr
,
1573 .permission
= reiserfs_permission
,