2 * Copyright 2000 Hans Reiser
3 * See README for licensing and copyright details
5 * Ported to FreeBSD by Jean-Sébastien Pédron <dumbbell@FreeBSD.org>
10 #include <gnu/fs/reiserfs/reiserfs_fs.h>
12 static b_strategy_t reiserfs_bufstrategy;
15 * Buffer operations for ReiserFS vnodes.
16 * We punt on VOP_BMAP, so we need to do strategy on the file's vnode
17 * rather than the underlying device's.
19 static struct buf_ops reiserfs_vnbufops = {
20 .bop_name = "ReiserFS",
21 .bop_strategy = reiserfs_bufstrategy,
24 /* Default io size devuned in super.c */
25 extern int reiserfs_default_io_size;
26 void inode_set_bytes(struct reiserfs_node *ip, off_t bytes);
28 /* Args for the create parameter of reiserfs_get_block */
29 #define GET_BLOCK_NO_CREATE 0 /* Don't create new blocks or convert
31 #define GET_BLOCK_CREATE 1 /* Add anything you need to find block */
32 #define GET_BLOCK_NO_HOLE 2 /* Return ENOENT for file holes */
33 #define GET_BLOCK_READ_DIRECT 4 /* Read the tail if indirect item not
35 #define GET_BLOCK_NO_ISEM 8 /* i_sem is not held, don't preallocate */
36 #define GET_BLOCK_NO_DANGLE 16 /* Don't leave any transactions running */
38 /* -------------------------------------------------------------------
40 * -------------------------------------------------------------------*/
43 reiserfs_read(struct vop_read_args *ap)
47 struct reiserfs_node *ip;
48 struct reiserfs_sb_info *sbi;
53 off_t bytesinfile, offset;
60 size = sbi->s_blocksize;
62 for (error = 0; uio->uio_resid > 0;) {
63 if ((bytesinfile = ip->i_size - uio->uio_offset) <= 0)
66 /* Compute the logical block number and its offset */
67 lbn = uio->uio_offset / size;
68 offset = uio->uio_offset % size;
69 reiserfs_log(LOG_DEBUG, "logical block number: %ju\n",
71 reiserfs_log(LOG_DEBUG, "block offset: %ju\n",
74 /* Read file blocks */
75 reiserfs_log(LOG_DEBUG, "reiserfs_get_block(%ju)\n",
77 if ((error = reiserfs_get_block(ip, lbn, offset, uio)) != 0) {
78 reiserfs_log(LOG_DEBUG,
79 "reiserfs_get_block returned the error %d\n",
89 reiserfs_bufstrategy(struct bufobj *bo, struct buf *bp)
95 KASSERT(bo == &vp->v_bufobj, ("BO/VP mismatch: vp %p bo %p != %p",
96 vp, &vp->v_bufobj, bo));
97 rc = VOP_STRATEGY(vp, bp);
98 KASSERT(rc == 0, ("ReiserFS VOP_STRATEGY failed: bp=%p, "
99 "vp=%p, rc=%d", bp, vp, rc));
103 reiserfs_inactive(struct vop_inactive_args *ap)
108 struct reiserfs_node *ip;
115 reiserfs_log(LOG_DEBUG, "deactivating inode used %d times\n",
117 if (prtactive && vrefcnt(vp) != 0)
118 vprint("ReiserFS/reclaim: pushing active", vp);
121 /* Ignore inodes related to stale file handles. */
129 * If we are done with the inode, reclaim it so that it can be reused
132 if (ip->i_mode == 0) {
133 reiserfs_log(LOG_DEBUG, "recyling\n");
141 reiserfs_reclaim(struct vop_reclaim_args *ap)
143 struct reiserfs_node *ip;
148 reiserfs_log(LOG_DEBUG, "reclaiming inode used %d times\n",
150 if (prtactive && vrefcnt(vp) != 0)
151 vprint("ReiserFS/reclaim: pushing active", vp);
154 /* XXX Update this node (write to the disk) */
156 /* Remove the inode from its hash chain. */
159 reiserfs_log(LOG_DEBUG, "free private data\n");
160 FREE(vp->v_data, M_REISERFSNODE);
162 vnode_destroy_vobject(vp);
167 /* -------------------------------------------------------------------
168 * Functions from linux/fs/reiserfs/inode.c
169 * -------------------------------------------------------------------*/
172 _make_cpu_key(struct cpu_key *key, int version,
173 uint32_t dirid, uint32_t objectid, off_t offset, int type, int length)
176 key->version = version;
178 key->on_disk_key.k_dir_id = dirid;
179 key->on_disk_key.k_objectid = objectid;
180 set_cpu_key_k_offset(key, offset);
181 set_cpu_key_k_type(key, type);
182 key->key_length = length;
186 * Take base of inode_key (it comes from inode always) (dirid, objectid)
187 * and version from an inode, set offset and type of key
190 make_cpu_key(struct cpu_key *key, struct reiserfs_node *ip, off_t offset,
191 int type, int length)
194 _make_cpu_key(key, get_inode_item_key_version(ip),
195 le32toh(INODE_PKEY(ip)->k_dir_id),
196 le32toh(INODE_PKEY(ip)->k_objectid),
197 offset, type, length);
201 reiserfs_get_block(struct reiserfs_node *ip, long block, off_t offset,
204 caddr_t blk = NULL, p;
206 /* unsigned long offset; */
207 INITIALIZE_PATH(path);
208 struct buf *bp, *blk_bp;
209 struct item_head *ih;
210 struct reiserfs_sb_info *sbi;
211 int blocknr, chars, done = 0, ret = 0, args = 0;
213 sbi = ip->i_reiserfs;
215 /* Prepare the key to look for the 'block'-th block of file */
216 reiserfs_log(LOG_DEBUG, "prepare cpu key\n");
217 make_cpu_key(&key, ip, (off_t)block * sbi->s_blocksize + 1, TYPE_ANY, 3);
220 reiserfs_log(LOG_DEBUG, "search for position\n");
221 if (search_for_position_by_key(sbi, &key, &path) != POSITION_FOUND) {
222 reiserfs_log(LOG_DEBUG, "position not found\n");
226 kunmap(bh_result->b_page);
229 * We do not return ENOENT if there is a hole but page is
230 * uptodate, because it means that there is some MMAPED data
231 * associated with it that is yet to be written to disk.
233 if ((args & GET_BLOCK_NO_HOLE)/* &&
234 !PageUptodate(bh_result->b_page)*/)
238 reiserfs_log(LOG_DEBUG, "position found\n");
240 bp = get_last_bp(&path);
243 if (is_indirect_le_ih(ih)) {
245 uint32_t *ind_item = (uint32_t *)B_I_PITEM(bp, ih);
247 reiserfs_log(LOG_DEBUG, "item is INDIRECT\n");
249 blocknr = get_block_num(ind_item, path.pos_in_item);
250 reiserfs_log(LOG_DEBUG, "block number: %d "
251 "(ind_item=%p, pos_in_item=%u)\n",
252 blocknr, ind_item, path.pos_in_item);
254 xfersize = MIN(sbi->s_blocksize - offset,
255 ip->i_size - uio->uio_offset);
256 xfersize = MIN(xfersize, uio->uio_resid);
259 ret = bread(sbi->s_devvp,
260 blocknr * btodb(sbi->s_blocksize),
261 sbi->s_blocksize, NOCRED, &blk_bp);
262 reiserfs_log(LOG_DEBUG, "xfersize: %ju\n",
264 ret = uiomove(blk_bp->b_data + offset, xfersize, uio);
268 * We do not return ENOENT if there is a hole but
269 * page is uptodate, because it means That there
270 * is some MMAPED data associated with it that
271 * is yet to be written to disk.
273 if ((args & GET_BLOCK_NO_HOLE)/* &&
274 !PageUptodate(bh_result->b_page)*/)
278 uio->uio_resid -= xfersize;
279 uio->uio_offset += xfersize;
286 reiserfs_log(LOG_DEBUG, "item should be DIRECT\n");
289 /* Requested data are in direct item(s) */
290 if (!(args & GET_BLOCK_READ_DIRECT)) {
292 * We are called by bmap. FIXME: we can not map block of
293 * file when it is stored in direct item(s)
298 kunmap(bh_result->b_page);
306 * If we've got a direct item, and the buffer or page was uptodate, we
307 * don't want to pull data off disk again. Skip to the end, where we
308 * map the buffer and return
310 if (buffer_uptodate(bh_result)) {
314 * grab_tail_page can trigger calls to reiserfs_get_block
315 * on up to date pages without any buffers. If the page
316 * is up to date, we don't want read old data off disk.
317 * Set the up to date bit on the buffer instead and jump
320 if (!bh_result->b_page || PageUptodate(bh_result->b_page)) {
321 set_buffer_uptodate(bh_result);
327 /* Read file tail into part of page */
328 offset = (cpu_key_k_offset(&key) - 1) & (PAGE_CACHE_SIZE - 1);
329 fs_gen = get_generation(ip->i_reiserfs);
330 copy_item_head(&tmp_ih, ih);
335 * We only want to kmap if we are reading the tail into the page. this
336 * is not the common case, so we don't kmap until we are sure we need
337 * to. But, this means the item might move if kmap schedules
340 blk = (char *)kmap(bh_result->b_page);
341 if (fs_changed (fs_gen, sbi) && item_moved(&tmp_ih, &path))
345 memset(blk, 0, sbi->s_blocksize);
348 reiserfs_log(LOG_DEBUG, "allocating buffer\n");
349 blk = malloc(ip->i_size, M_REISERFSNODE, M_WAITOK | M_ZERO);
357 if (!is_direct_le_ih(ih)) {
358 reiserfs_log(LOG_ERR, "BUG\n");
359 return (ENOENT); /* XXX Wrong error code */
363 * Make sure we don't read more bytes than actually exist
364 * in the file. This can happen in odd cases where i_size
365 * isn't correct, and when direct item padding results in
366 * a few extra bytes at the end of the direct item
368 if ((le_ih_k_offset(ih) + path.pos_in_item) > ip->i_size)
371 if ((le_ih_k_offset(ih) - 1 + ih_item_len(ih)) > ip->i_size) {
372 chars = ip->i_size - (le_ih_k_offset(ih) - 1) -
376 chars = ih_item_len(ih) - path.pos_in_item;
378 reiserfs_log(LOG_DEBUG, "copying %d bytes\n", chars);
379 memcpy(p, B_I_PITEM(bp, ih) + path.pos_in_item, chars);
381 reiserfs_log(LOG_DEBUG, "copy done\n");
387 if (PATH_LAST_POSITION(&path) != (B_NR_ITEMS(bp) - 1))
389 * We done, if read direct item is not the last
391 * FIXME: we could try to check right delimiting
392 * key to see whether direct item continues in
393 * the right neighbor or rely on i_size
397 /* Update key to look for the next piece */
398 set_cpu_key_k_offset(&key, cpu_key_k_offset(&key) + chars);
399 if (search_for_position_by_key(sbi, &key, &path) !=
402 * We read something from tail, even if now we got
407 bp = get_last_bp(&path);
414 * This buffer has valid data, but isn't valid for io. mapping it to
415 * block #0 tells the rest of reiserfs it just has a tail in it
417 ret = uiomove(blk, ip->i_size, uio);
418 free(blk, M_REISERFSNODE);
423 * Compute real number of used bytes by file
424 * Following three functions can go away when we'll have enough space in
428 real_space_diff(struct reiserfs_node *ip, int sd_size)
431 off_t blocksize = ip->i_reiserfs->s_blocksize;
433 if (S_ISLNK(ip->i_mode) || S_ISDIR(ip->i_mode))
436 /* End of file is also in full block with indirect reference, so round
437 * up to the next block.
439 * There is just no way to know if the tail is actually packed on the
440 * file, so we have to assume it isn't. When we pack the tail, we add
441 * 4 bytes to pretend there really is an unformatted node pointer. */
442 bytes = ((ip->i_size + (blocksize - 1)) >>
443 ip->i_reiserfs->s_blocksize_bits) * UNFM_P_SIZE + sd_size;
449 to_real_used_space(struct reiserfs_node *ip, unsigned long blocks, int sd_size)
452 if (S_ISLNK(ip->i_mode) || S_ISDIR(ip->i_mode)) {
453 return ip->i_size + (off_t)(real_space_diff(ip, sd_size));
456 return ((off_t)real_space_diff(ip, sd_size)) + (((off_t)blocks) << 9);
460 inode_set_bytes(struct reiserfs_node *ip, off_t bytes)
463 ip->i_blocks = bytes >> 9;
464 ip->i_bytes = bytes & 511;
467 /* Called by read_locked_inode */
469 init_inode(struct reiserfs_node *ip, struct path *path)
472 struct item_head *ih;
475 bp = PATH_PLAST_BUFFER(path);
476 ih = PATH_PITEM_HEAD(path);
478 reiserfs_log(LOG_DEBUG, "copy the key (objectid=%d, dirid=%d)\n",
479 ih->ih_key.k_objectid, ih->ih_key.k_dir_id);
480 copy_key(INODE_PKEY(ip), &(ih->ih_key));
481 /* ip->i_blksize = reiserfs_default_io_size; */
483 reiserfs_log(LOG_DEBUG, "reset some inode structure members\n");
484 REISERFS_I(ip)->i_flags = 0;
486 REISERFS_I(ip)->i_prealloc_block = 0;
487 REISERFS_I(ip)->i_prealloc_count = 0;
488 REISERFS_I(ip)->i_trans_id = 0;
489 REISERFS_I(ip)->i_jl = NULL;
490 REISERFS_I(ip)->i_acl_access = NULL;
491 REISERFS_I(ip)->i_acl_default = NULL;
494 if (stat_data_v1(ih)) {
495 reiserfs_log(LOG_DEBUG, "reiserfs/init_inode: stat data v1\n");
496 struct stat_data_v1 *sd;
497 unsigned long blocks;
499 sd = (struct stat_data_v1 *)B_I_PITEM(bp, ih);
501 reiserfs_log(LOG_DEBUG,
502 "reiserfs/init_inode: filling more members\n");
503 set_inode_item_key_version(ip, KEY_FORMAT_3_5);
504 set_inode_sd_version(ip, STAT_DATA_V1);
505 ip->i_mode = sd_v1_mode(sd);
506 ip->i_nlink = sd_v1_nlink(sd);
507 ip->i_uid = sd_v1_uid(sd);
508 ip->i_gid = sd_v1_gid(sd);
509 ip->i_size = sd_v1_size(sd);
510 ip->i_atime.tv_sec = sd_v1_atime(sd);
511 ip->i_mtime.tv_sec = sd_v1_mtime(sd);
512 ip->i_ctime.tv_sec = sd_v1_ctime(sd);
513 ip->i_atime.tv_nsec = 0;
514 ip->i_ctime.tv_nsec = 0;
515 ip->i_mtime.tv_nsec = 0;
517 reiserfs_log(LOG_DEBUG, " mode = %08x\n", ip->i_mode);
518 reiserfs_log(LOG_DEBUG, " nlink = %d\n", ip->i_nlink);
519 reiserfs_log(LOG_DEBUG, " owner = %d:%d\n", ip->i_uid,
521 reiserfs_log(LOG_DEBUG, " size = %ju\n",
522 (intmax_t)ip->i_size);
523 reiserfs_log(LOG_DEBUG, " atime = %jd\n",
524 (intmax_t)ip->i_atime.tv_sec);
525 reiserfs_log(LOG_DEBUG, " mtime = %jd\n",
526 (intmax_t)ip->i_mtime.tv_sec);
527 reiserfs_log(LOG_DEBUG, " ctime = %jd\n",
528 (intmax_t)ip->i_ctime.tv_sec);
530 ip->i_blocks = sd_v1_blocks(sd);
531 ip->i_generation = le32toh(INODE_PKEY(ip)->k_dir_id);
532 blocks = (ip->i_size + 511) >> 9;
533 blocks = _ROUND_UP(blocks, ip->i_reiserfs->s_blocksize >> 9);
534 if (ip->i_blocks > blocks) {
536 * There was a bug in <= 3.5.23 when i_blocks could
537 * take negative values. Starting from 3.5.17 this
538 * value could even be stored in stat data. For such
539 * files we set i_blocks based on file size. Just 2
540 * notes: this can be wrong for sparce files. On-disk
541 * value will be only updated if file's inode will
544 ip->i_blocks = blocks;
547 rdev = sd_v1_rdev(sd);
548 REISERFS_I(ip)->i_first_direct_byte =
549 sd_v1_first_direct_byte(sd);
552 * An early bug in the quota code can give us an odd number
553 * for the block count. This is incorrect, fix it here.
555 if (ip->i_blocks & 1) {
558 inode_set_bytes(ip, to_real_used_space(ip, ip->i_blocks,
562 * nopack is initially zero for v1 objects. For v2 objects,
563 * nopack is initialised from sd_attrs
565 REISERFS_I(ip)->i_flags &= ~i_nopack_mask;
566 reiserfs_log(LOG_DEBUG, "...done\n");
568 reiserfs_log(LOG_DEBUG, "stat data v2\n");
570 * New stat data found, but object may have old items
571 * (directories and symlinks)
573 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bp, ih);
575 reiserfs_log(LOG_DEBUG, "filling more members\n");
576 ip->i_mode = sd_v2_mode(sd);
577 ip->i_nlink = sd_v2_nlink(sd);
578 ip->i_uid = sd_v2_uid(sd);
579 ip->i_size = sd_v2_size(sd);
580 ip->i_gid = sd_v2_gid(sd);
581 ip->i_mtime.tv_sec = sd_v2_mtime(sd);
582 ip->i_atime.tv_sec = sd_v2_atime(sd);
583 ip->i_ctime.tv_sec = sd_v2_ctime(sd);
584 ip->i_ctime.tv_nsec = 0;
585 ip->i_mtime.tv_nsec = 0;
586 ip->i_atime.tv_nsec = 0;
588 reiserfs_log(LOG_DEBUG, " mode = %08x\n", ip->i_mode);
589 reiserfs_log(LOG_DEBUG, " nlink = %d\n", ip->i_nlink);
590 reiserfs_log(LOG_DEBUG, " owner = %d:%d\n", ip->i_uid,
592 reiserfs_log(LOG_DEBUG, " size = %ju\n",
593 (intmax_t)ip->i_size);
594 reiserfs_log(LOG_DEBUG, " atime = %jd\n",
595 (intmax_t)ip->i_atime.tv_sec);
596 reiserfs_log(LOG_DEBUG, " mtime = %jd\n",
597 (intmax_t)ip->i_mtime.tv_sec);
598 reiserfs_log(LOG_DEBUG, " ctime = %jd\n",
599 (intmax_t)ip->i_ctime.tv_sec);
601 ip->i_blocks = sd_v2_blocks(sd);
602 rdev = sd_v2_rdev(sd);
603 reiserfs_log(LOG_DEBUG, " blocks = %u\n", ip->i_blocks);
605 if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode))
606 ip->i_generation = le32toh(INODE_PKEY(ip)->k_dir_id);
608 ip->i_generation = sd_v2_generation(sd);
610 if (S_ISDIR(ip->i_mode) || S_ISLNK(ip->i_mode))
611 set_inode_item_key_version(ip, KEY_FORMAT_3_5);
613 set_inode_item_key_version(ip, KEY_FORMAT_3_6);
615 REISERFS_I(ip)->i_first_direct_byte = 0;
616 set_inode_sd_version(ip, STAT_DATA_V2);
617 inode_set_bytes(ip, to_real_used_space(ip, ip->i_blocks,
621 * Read persistent inode attributes from sd and initalise
622 * generic inode flags from them
624 REISERFS_I(ip)->i_attrs = sd_v2_attrs(sd);
625 sd_attrs_to_i_attrs(sd_v2_attrs(sd), ip);
626 reiserfs_log(LOG_DEBUG, "...done\n");
630 if (S_ISREG(ip->i_mode)) {
631 reiserfs_log(LOG_DEBUG, "this inode is a regular file\n");
632 //ip->i_op = &reiserfs_file_ip_operations;
633 //ip->i_fop = &reiserfs_file_operations;
634 //ip->i_mapping->a_ops = &reiserfs_address_space_operations ;
635 } else if (S_ISDIR(ip->i_mode)) {
636 reiserfs_log(LOG_DEBUG, "this inode is a directory\n");
637 //ip->i_op = &reiserfs_dir_ip_operations;
638 //ip->i_fop = &reiserfs_dir_operations;
639 } else if (S_ISLNK(ip->i_mode)) {
640 reiserfs_log(LOG_DEBUG, "this inode is a symlink\n");
641 //ip->i_op = &reiserfs_symlink_ip_operations;
642 //ip->i_mapping->a_ops = &reiserfs_address_space_operations;
644 reiserfs_log(LOG_DEBUG, "this inode is something unknown in "
647 //ip->i_op = &reiserfs_special_ip_operations;
648 //init_special_ip(ip, ip->i_mode, new_decode_dev(rdev));
653 * reiserfs_read_locked_inode is called to read the inode off disk, and
654 * it does a make_bad_inode when things go wrong. But, we need to make
655 * sure and clear the key in the private portion of the inode, otherwise
656 * a corresponding iput might try to delete whatever object the inode
660 reiserfs_make_bad_inode(struct reiserfs_node *ip) {
662 memset(INODE_PKEY(ip), 0, KEY_SIZE);
663 //make_bad_inode(inode);
667 reiserfs_read_locked_inode(struct reiserfs_node *ip,
668 struct reiserfs_iget_args *args)
670 INITIALIZE_PATH(path_to_sd);
672 unsigned long dirino;
675 dirino = args->dirid;
678 * Set version 1, version 2 could be used too, because stat data
679 * key is the same in both versions
681 key.version = KEY_FORMAT_3_5;
682 key.on_disk_key.k_dir_id = dirino;
683 key.on_disk_key.k_objectid = ip->i_number;
684 key.on_disk_key.u.k_offset_v1.k_offset = SD_OFFSET;
685 key.on_disk_key.u.k_offset_v1.k_uniqueness = SD_UNIQUENESS;
687 /* Look for the object's stat data */
688 retval = search_item(ip->i_reiserfs, &key, &path_to_sd);
689 if (retval == IO_ERROR) {
690 reiserfs_log(LOG_ERR,
691 "I/O failure occured trying to find stat"
693 key.on_disk_key.k_dir_id, key.on_disk_key.k_objectid);
694 reiserfs_make_bad_inode(ip);
697 if (retval != ITEM_FOUND) {
699 * A stale NFS handle can trigger this without it being
702 reiserfs_log(LOG_ERR,
703 "item not found (objectid=%u, dirid=%u)\n",
704 key.on_disk_key.k_objectid, key.on_disk_key.k_dir_id);
705 pathrelse(&path_to_sd);
706 reiserfs_make_bad_inode(ip);
711 init_inode(ip, &path_to_sd);
714 * It is possible that knfsd is trying to access inode of a file
715 * that is being removed from the disk by some other thread. As
716 * we update sd on unlink all that is required is to check for
717 * nlink here. This bug was first found by Sizif when debugging
718 * SquidNG/Butterfly, forgotten, and found again after Philippe
719 * Gramoulle <philippe.gramoulle@mmania.com> reproduced it.
721 * More logical fix would require changes in fs/inode.c:iput() to
722 * remove inode from hash-table _after_ fs cleaned disk stuff up and
723 * in iget() to return NULL if I_FREEING inode is found in hash-table.
726 * Currently there is one place where it's ok to meet inode with
727 * nlink == 0: processing of open-unlinked and half-truncated files
728 * during mount (fs/reiserfs/super.c:finish_unfinished()).
730 if((ip->i_nlink == 0) &&
731 !REISERFS_SB(ip->i_reiserfs)->s_is_unlinked_ok ) {
732 reiserfs_log(LOG_WARNING, "dead inode read from disk. This is "
733 "likely to be race with knfsd. Ignore");
734 reiserfs_make_bad_inode(ip);
737 /* Init inode should be relsing */
738 reiserfs_check_path(&path_to_sd);
743 struct mount *mp, const struct cpu_key *key,
744 struct vnode **vpp, struct thread *td)
749 struct reiserfs_node *ip;
750 struct reiserfs_mount *rmp;
752 struct reiserfs_iget_args args;
755 /* Check if the inode cache contains it */
756 // XXX LK_EXCLUSIVE ?
757 flags = LK_EXCLUSIVE;
758 error = vfs_hash_get(mp, key->on_disk_key.k_objectid, flags,
759 td, vpp, NULL, NULL);
760 if (error || *vpp != NULL)
763 rmp = VFSTOREISERFS(mp);
767 * If this MALLOC() is performed after the getnewvnode() it might
768 * block, leaving a vnode with a NULL v_data to be found by
769 * reiserfs_sync() if a sync happens to fire right then, which
770 * will cause a panic because reiserfs_sync() blindly dereferences
771 * vp->v_data (as well it should).
773 reiserfs_log(LOG_DEBUG, "malloc(struct reiserfs_node)\n");
774 ip = malloc(sizeof(struct reiserfs_node), M_REISERFSNODE,
777 /* Allocate a new vnode/inode. */
778 reiserfs_log(LOG_DEBUG, "getnewvnode\n");
780 getnewvnode("reiserfs", mp, &reiserfs_vnodeops, &vp)) != 0) {
782 free(ip, M_REISERFSNODE);
783 reiserfs_log(LOG_DEBUG, "getnewvnode FAILED\n");
787 args.dirid = key->on_disk_key.k_dir_id;
788 args.objectid = key->on_disk_key.k_objectid;
790 reiserfs_log(LOG_DEBUG, "filling *ip\n");
794 ip->i_number = args.objectid;
795 ip->i_ino = args.dirid;
796 ip->i_reiserfs = rmp->rm_reiserfs;
798 vp->v_bufobj.bo_ops = &reiserfs_vnbufops;
799 vp->v_bufobj.bo_private = vp;
801 /* If this is the root node, set the VV_ROOT flag */
802 if (ip->i_number == REISERFS_ROOT_OBJECTID &&
803 ip->i_ino == REISERFS_ROOT_PARENT_OBJECTID)
804 vp->v_vflag |= VV_ROOT;
807 if (VOP_LOCK(vp, LK_EXCLUSIVE, td) != 0)
808 panic("reiserfs/iget: unexpected lock failure");
811 * Exclusively lock the vnode before adding to hash. Note, that we
812 * must not release nor downgrade the lock (despite flags argument
813 * says) till it is fully initialized.
815 lockmgr(vp->v_vnlock, LK_EXCLUSIVE, (struct mtx *)0, td);
818 lockmgr(vp->v_vnlock, LK_EXCLUSIVE, NULL, td);
819 error = insmntque(vp, mp);
821 free(ip, M_REISERFSNODE);
823 reiserfs_log(LOG_DEBUG, "insmntque FAILED\n");
826 error = vfs_hash_insert(vp, key->on_disk_key.k_objectid, flags,
827 td, vpp, NULL, NULL);
828 if (error || *vpp != NULL)
832 reiserfs_log(LOG_DEBUG, "call reiserfs_read_locked_inode ("
833 "objectid=%d,dirid=%d)\n", args.objectid, args.dirid);
834 reiserfs_read_locked_inode(ip, &args);
836 ip->i_devvp = rmp->rm_devvp;
838 switch(vp->v_type = IFTOVT(ip->i_mode)) {
840 reiserfs_log(LOG_DEBUG, "vnode type VBLK\n");
841 vp->v_op = &reiserfs_specops;
845 reiserfs_log(LOG_DEBUG, "vnode type VCHR\n");
846 vp->v_op = &reiserfs_specops;
847 vp = addaliasu(vp, ip->i_rdev);
851 reiserfs_log(LOG_DEBUG, "vnode type VFIFO\n");
852 vp->v_op = reiserfs_fifoop_p;
864 sd_attrs_to_i_attrs(uint16_t sd_attrs, struct reiserfs_node *ip)
867 if (reiserfs_attrs(ip->i_reiserfs)) {
869 if (sd_attrs & REISERFS_SYNC_FL)
870 ip->i_flags |= S_SYNC;
872 ip->i_flags &= ~S_SYNC;
874 if (sd_attrs & REISERFS_IMMUTABLE_FL)
875 ip->i_flags |= IMMUTABLE;
877 ip->i_flags &= ~IMMUTABLE;
878 if (sd_attrs & REISERFS_APPEND_FL)
879 ip->i_flags |= APPEND;
881 ip->i_flags &= ~APPEND;
883 if (sd_attrs & REISERFS_NOATIME_FL)
884 ip->i_flags |= S_NOATIME;
886 ip->i_flags &= ~S_NOATIME;
887 if (sd_attrs & REISERFS_NOTAIL_FL)
888 REISERFS_I(ip)->i_flags |= i_nopack_mask;
890 REISERFS_I(ip)->i_flags &= ~i_nopack_mask;
896 i_attrs_to_sd_attrs(struct reiserfs_node *ip, uint16_t *sd_attrs)
899 if (reiserfs_attrs(ip->i_reiserfs)) {
901 if (ip->i_flags & S_SYNC)
902 *sd_attrs |= REISERFS_SYNC_FL;
904 *sd_attrs &= ~REISERFS_SYNC_FL;
906 if (ip->i_flags & IMMUTABLE)
907 *sd_attrs |= REISERFS_IMMUTABLE_FL;
909 *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
910 if (ip->i_flags & APPEND)
911 *sd_attrs |= REISERFS_APPEND_FL;
913 *sd_attrs &= ~REISERFS_APPEND_FL;
915 if (ip->i_flags & S_NOATIME)
916 *sd_attrs |= REISERFS_NOATIME_FL;
918 *sd_attrs &= ~REISERFS_NOATIME_FL;
919 if (REISERFS_I(ip)->i_flags & i_nopack_mask)
920 *sd_attrs |= REISERFS_NOTAIL_FL;
922 *sd_attrs &= ~REISERFS_NOTAIL_FL;