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",
119 /* Ignore inodes related to stale file handles. */
127 * If we are done with the inode, reclaim it so that it can be reused
130 if (ip->i_mode == 0) {
131 reiserfs_log(LOG_DEBUG, "recyling\n");
139 reiserfs_reclaim(struct vop_reclaim_args *ap)
141 struct reiserfs_node *ip;
146 reiserfs_log(LOG_DEBUG, "reclaiming inode used %d times\n",
150 /* XXX Update this node (write to the disk) */
152 /* Remove the inode from its hash chain. */
155 reiserfs_log(LOG_DEBUG, "free private data\n");
156 free(vp->v_data, M_REISERFSNODE);
158 vnode_destroy_vobject(vp);
163 /* -------------------------------------------------------------------
164 * Functions from linux/fs/reiserfs/inode.c
165 * -------------------------------------------------------------------*/
168 _make_cpu_key(struct cpu_key *key, int version,
169 uint32_t dirid, uint32_t objectid, off_t offset, int type, int length)
172 key->version = version;
174 key->on_disk_key.k_dir_id = dirid;
175 key->on_disk_key.k_objectid = objectid;
176 set_cpu_key_k_offset(key, offset);
177 set_cpu_key_k_type(key, type);
178 key->key_length = length;
182 * Take base of inode_key (it comes from inode always) (dirid, objectid)
183 * and version from an inode, set offset and type of key
186 make_cpu_key(struct cpu_key *key, struct reiserfs_node *ip, off_t offset,
187 int type, int length)
190 _make_cpu_key(key, get_inode_item_key_version(ip),
191 le32toh(INODE_PKEY(ip)->k_dir_id),
192 le32toh(INODE_PKEY(ip)->k_objectid),
193 offset, type, length);
197 reiserfs_get_block(struct reiserfs_node *ip, long block, off_t offset,
200 caddr_t blk = NULL, p;
202 /* unsigned long offset; */
203 INITIALIZE_PATH(path);
204 struct buf *bp, *blk_bp;
205 struct item_head *ih;
206 struct reiserfs_sb_info *sbi;
207 int blocknr, chars, done = 0, ret = 0, args = 0;
209 sbi = ip->i_reiserfs;
211 /* Prepare the key to look for the 'block'-th block of file */
212 reiserfs_log(LOG_DEBUG, "prepare cpu key\n");
213 make_cpu_key(&key, ip, (off_t)block * sbi->s_blocksize + 1, TYPE_ANY, 3);
216 reiserfs_log(LOG_DEBUG, "search for position\n");
217 if (search_for_position_by_key(sbi, &key, &path) != POSITION_FOUND) {
218 reiserfs_log(LOG_DEBUG, "position not found\n");
222 kunmap(bh_result->b_page);
225 * We do not return ENOENT if there is a hole but page is
226 * uptodate, because it means that there is some MMAPED data
227 * associated with it that is yet to be written to disk.
229 if ((args & GET_BLOCK_NO_HOLE)/* &&
230 !PageUptodate(bh_result->b_page)*/)
234 reiserfs_log(LOG_DEBUG, "position found\n");
236 bp = get_last_bp(&path);
239 if (is_indirect_le_ih(ih)) {
241 uint32_t *ind_item = (uint32_t *)B_I_PITEM(bp, ih);
243 reiserfs_log(LOG_DEBUG, "item is INDIRECT\n");
245 blocknr = get_block_num(ind_item, path.pos_in_item);
246 reiserfs_log(LOG_DEBUG, "block number: %d "
247 "(ind_item=%p, pos_in_item=%u)\n",
248 blocknr, ind_item, path.pos_in_item);
250 xfersize = MIN(sbi->s_blocksize - offset,
251 ip->i_size - uio->uio_offset);
252 xfersize = MIN(xfersize, uio->uio_resid);
255 ret = bread(sbi->s_devvp,
256 blocknr * btodb(sbi->s_blocksize),
257 sbi->s_blocksize, NOCRED, &blk_bp);
258 reiserfs_log(LOG_DEBUG, "xfersize: %ju\n",
260 ret = uiomove(blk_bp->b_data + offset, xfersize, uio);
264 * We do not return ENOENT if there is a hole but
265 * page is uptodate, because it means That there
266 * is some MMAPED data associated with it that
267 * is yet to be written to disk.
269 if ((args & GET_BLOCK_NO_HOLE)/* &&
270 !PageUptodate(bh_result->b_page)*/)
274 uio->uio_resid -= xfersize;
275 uio->uio_offset += xfersize;
282 reiserfs_log(LOG_DEBUG, "item should be DIRECT\n");
285 /* Requested data are in direct item(s) */
286 if (!(args & GET_BLOCK_READ_DIRECT)) {
288 * We are called by bmap. FIXME: we can not map block of
289 * file when it is stored in direct item(s)
294 kunmap(bh_result->b_page);
302 * If we've got a direct item, and the buffer or page was uptodate, we
303 * don't want to pull data off disk again. Skip to the end, where we
304 * map the buffer and return
306 if (buffer_uptodate(bh_result)) {
310 * grab_tail_page can trigger calls to reiserfs_get_block
311 * on up to date pages without any buffers. If the page
312 * is up to date, we don't want read old data off disk.
313 * Set the up to date bit on the buffer instead and jump
316 if (!bh_result->b_page || PageUptodate(bh_result->b_page)) {
317 set_buffer_uptodate(bh_result);
323 /* Read file tail into part of page */
324 offset = (cpu_key_k_offset(&key) - 1) & (PAGE_CACHE_SIZE - 1);
325 fs_gen = get_generation(ip->i_reiserfs);
326 copy_item_head(&tmp_ih, ih);
331 * We only want to kmap if we are reading the tail into the page. this
332 * is not the common case, so we don't kmap until we are sure we need
333 * to. But, this means the item might move if kmap schedules
336 blk = (char *)kmap(bh_result->b_page);
337 if (fs_changed (fs_gen, sbi) && item_moved(&tmp_ih, &path))
341 memset(blk, 0, sbi->s_blocksize);
344 reiserfs_log(LOG_DEBUG, "allocating buffer\n");
345 blk = malloc(ip->i_size, M_REISERFSNODE, M_WAITOK | M_ZERO);
353 if (!is_direct_le_ih(ih)) {
354 reiserfs_log(LOG_ERR, "BUG\n");
355 return (ENOENT); /* XXX Wrong error code */
359 * Make sure we don't read more bytes than actually exist
360 * in the file. This can happen in odd cases where i_size
361 * isn't correct, and when direct item padding results in
362 * a few extra bytes at the end of the direct item
364 if ((le_ih_k_offset(ih) + path.pos_in_item) > ip->i_size)
367 if ((le_ih_k_offset(ih) - 1 + ih_item_len(ih)) > ip->i_size) {
368 chars = ip->i_size - (le_ih_k_offset(ih) - 1) -
372 chars = ih_item_len(ih) - path.pos_in_item;
374 reiserfs_log(LOG_DEBUG, "copying %d bytes\n", chars);
375 memcpy(p, B_I_PITEM(bp, ih) + path.pos_in_item, chars);
377 reiserfs_log(LOG_DEBUG, "copy done\n");
383 if (PATH_LAST_POSITION(&path) != (B_NR_ITEMS(bp) - 1))
385 * We done, if read direct item is not the last
387 * FIXME: we could try to check right delimiting
388 * key to see whether direct item continues in
389 * the right neighbor or rely on i_size
393 /* Update key to look for the next piece */
394 set_cpu_key_k_offset(&key, cpu_key_k_offset(&key) + chars);
395 if (search_for_position_by_key(sbi, &key, &path) !=
398 * We read something from tail, even if now we got
403 bp = get_last_bp(&path);
410 * This buffer has valid data, but isn't valid for io. mapping it to
411 * block #0 tells the rest of reiserfs it just has a tail in it
413 ret = uiomove(blk, ip->i_size, uio);
414 free(blk, M_REISERFSNODE);
419 * Compute real number of used bytes by file
420 * Following three functions can go away when we'll have enough space in
424 real_space_diff(struct reiserfs_node *ip, int sd_size)
427 off_t blocksize = ip->i_reiserfs->s_blocksize;
429 if (S_ISLNK(ip->i_mode) || S_ISDIR(ip->i_mode))
432 /* End of file is also in full block with indirect reference, so round
433 * up to the next block.
435 * There is just no way to know if the tail is actually packed on the
436 * file, so we have to assume it isn't. When we pack the tail, we add
437 * 4 bytes to pretend there really is an unformatted node pointer. */
438 bytes = ((ip->i_size + (blocksize - 1)) >>
439 ip->i_reiserfs->s_blocksize_bits) * UNFM_P_SIZE + sd_size;
445 to_real_used_space(struct reiserfs_node *ip, unsigned long blocks, int sd_size)
448 if (S_ISLNK(ip->i_mode) || S_ISDIR(ip->i_mode)) {
449 return ip->i_size + (off_t)(real_space_diff(ip, sd_size));
452 return ((off_t)real_space_diff(ip, sd_size)) + (((off_t)blocks) << 9);
456 inode_set_bytes(struct reiserfs_node *ip, off_t bytes)
459 ip->i_blocks = bytes >> 9;
460 ip->i_bytes = bytes & 511;
463 /* Called by read_locked_inode */
465 init_inode(struct reiserfs_node *ip, struct path *path)
468 struct item_head *ih;
471 bp = PATH_PLAST_BUFFER(path);
472 ih = PATH_PITEM_HEAD(path);
474 reiserfs_log(LOG_DEBUG, "copy the key (objectid=%d, dirid=%d)\n",
475 ih->ih_key.k_objectid, ih->ih_key.k_dir_id);
476 copy_key(INODE_PKEY(ip), &(ih->ih_key));
477 /* ip->i_blksize = reiserfs_default_io_size; */
479 reiserfs_log(LOG_DEBUG, "reset some inode structure members\n");
480 REISERFS_I(ip)->i_flags = 0;
482 REISERFS_I(ip)->i_prealloc_block = 0;
483 REISERFS_I(ip)->i_prealloc_count = 0;
484 REISERFS_I(ip)->i_trans_id = 0;
485 REISERFS_I(ip)->i_jl = NULL;
486 REISERFS_I(ip)->i_acl_access = NULL;
487 REISERFS_I(ip)->i_acl_default = NULL;
490 if (stat_data_v1(ih)) {
491 reiserfs_log(LOG_DEBUG, "reiserfs/init_inode: stat data v1\n");
492 struct stat_data_v1 *sd;
493 unsigned long blocks;
495 sd = (struct stat_data_v1 *)B_I_PITEM(bp, ih);
497 reiserfs_log(LOG_DEBUG,
498 "reiserfs/init_inode: filling more members\n");
499 set_inode_item_key_version(ip, KEY_FORMAT_3_5);
500 set_inode_sd_version(ip, STAT_DATA_V1);
501 ip->i_mode = sd_v1_mode(sd);
502 ip->i_nlink = sd_v1_nlink(sd);
503 ip->i_uid = sd_v1_uid(sd);
504 ip->i_gid = sd_v1_gid(sd);
505 ip->i_size = sd_v1_size(sd);
506 ip->i_atime.tv_sec = sd_v1_atime(sd);
507 ip->i_mtime.tv_sec = sd_v1_mtime(sd);
508 ip->i_ctime.tv_sec = sd_v1_ctime(sd);
509 ip->i_atime.tv_nsec = 0;
510 ip->i_ctime.tv_nsec = 0;
511 ip->i_mtime.tv_nsec = 0;
513 reiserfs_log(LOG_DEBUG, " mode = %08x\n", ip->i_mode);
514 reiserfs_log(LOG_DEBUG, " nlink = %d\n", ip->i_nlink);
515 reiserfs_log(LOG_DEBUG, " owner = %d:%d\n", ip->i_uid,
517 reiserfs_log(LOG_DEBUG, " size = %ju\n",
518 (intmax_t)ip->i_size);
519 reiserfs_log(LOG_DEBUG, " atime = %jd\n",
520 (intmax_t)ip->i_atime.tv_sec);
521 reiserfs_log(LOG_DEBUG, " mtime = %jd\n",
522 (intmax_t)ip->i_mtime.tv_sec);
523 reiserfs_log(LOG_DEBUG, " ctime = %jd\n",
524 (intmax_t)ip->i_ctime.tv_sec);
526 ip->i_blocks = sd_v1_blocks(sd);
527 ip->i_generation = le32toh(INODE_PKEY(ip)->k_dir_id);
528 blocks = (ip->i_size + 511) >> 9;
529 blocks = _ROUND_UP(blocks, ip->i_reiserfs->s_blocksize >> 9);
530 if (ip->i_blocks > blocks) {
532 * There was a bug in <= 3.5.23 when i_blocks could
533 * take negative values. Starting from 3.5.17 this
534 * value could even be stored in stat data. For such
535 * files we set i_blocks based on file size. Just 2
536 * notes: this can be wrong for sparce files. On-disk
537 * value will be only updated if file's inode will
540 ip->i_blocks = blocks;
543 rdev = sd_v1_rdev(sd);
544 REISERFS_I(ip)->i_first_direct_byte =
545 sd_v1_first_direct_byte(sd);
548 * An early bug in the quota code can give us an odd number
549 * for the block count. This is incorrect, fix it here.
551 if (ip->i_blocks & 1) {
554 inode_set_bytes(ip, to_real_used_space(ip, ip->i_blocks,
558 * nopack is initially zero for v1 objects. For v2 objects,
559 * nopack is initialised from sd_attrs
561 REISERFS_I(ip)->i_flags &= ~i_nopack_mask;
562 reiserfs_log(LOG_DEBUG, "...done\n");
564 reiserfs_log(LOG_DEBUG, "stat data v2\n");
566 * New stat data found, but object may have old items
567 * (directories and symlinks)
569 struct stat_data *sd = (struct stat_data *)B_I_PITEM(bp, ih);
571 reiserfs_log(LOG_DEBUG, "filling more members\n");
572 ip->i_mode = sd_v2_mode(sd);
573 ip->i_nlink = sd_v2_nlink(sd);
574 ip->i_uid = sd_v2_uid(sd);
575 ip->i_size = sd_v2_size(sd);
576 ip->i_gid = sd_v2_gid(sd);
577 ip->i_mtime.tv_sec = sd_v2_mtime(sd);
578 ip->i_atime.tv_sec = sd_v2_atime(sd);
579 ip->i_ctime.tv_sec = sd_v2_ctime(sd);
580 ip->i_ctime.tv_nsec = 0;
581 ip->i_mtime.tv_nsec = 0;
582 ip->i_atime.tv_nsec = 0;
584 reiserfs_log(LOG_DEBUG, " mode = %08x\n", ip->i_mode);
585 reiserfs_log(LOG_DEBUG, " nlink = %d\n", ip->i_nlink);
586 reiserfs_log(LOG_DEBUG, " owner = %d:%d\n", ip->i_uid,
588 reiserfs_log(LOG_DEBUG, " size = %ju\n",
589 (intmax_t)ip->i_size);
590 reiserfs_log(LOG_DEBUG, " atime = %jd\n",
591 (intmax_t)ip->i_atime.tv_sec);
592 reiserfs_log(LOG_DEBUG, " mtime = %jd\n",
593 (intmax_t)ip->i_mtime.tv_sec);
594 reiserfs_log(LOG_DEBUG, " ctime = %jd\n",
595 (intmax_t)ip->i_ctime.tv_sec);
597 ip->i_blocks = sd_v2_blocks(sd);
598 rdev = sd_v2_rdev(sd);
599 reiserfs_log(LOG_DEBUG, " blocks = %u\n", ip->i_blocks);
601 if (S_ISCHR(ip->i_mode) || S_ISBLK(ip->i_mode))
602 ip->i_generation = le32toh(INODE_PKEY(ip)->k_dir_id);
604 ip->i_generation = sd_v2_generation(sd);
606 if (S_ISDIR(ip->i_mode) || S_ISLNK(ip->i_mode))
607 set_inode_item_key_version(ip, KEY_FORMAT_3_5);
609 set_inode_item_key_version(ip, KEY_FORMAT_3_6);
611 REISERFS_I(ip)->i_first_direct_byte = 0;
612 set_inode_sd_version(ip, STAT_DATA_V2);
613 inode_set_bytes(ip, to_real_used_space(ip, ip->i_blocks,
617 * Read persistent inode attributes from sd and initalise
618 * generic inode flags from them
620 REISERFS_I(ip)->i_attrs = sd_v2_attrs(sd);
621 sd_attrs_to_i_attrs(sd_v2_attrs(sd), ip);
622 reiserfs_log(LOG_DEBUG, "...done\n");
626 if (S_ISREG(ip->i_mode)) {
627 reiserfs_log(LOG_DEBUG, "this inode is a regular file\n");
628 //ip->i_op = &reiserfs_file_ip_operations;
629 //ip->i_fop = &reiserfs_file_operations;
630 //ip->i_mapping->a_ops = &reiserfs_address_space_operations ;
631 } else if (S_ISDIR(ip->i_mode)) {
632 reiserfs_log(LOG_DEBUG, "this inode is a directory\n");
633 //ip->i_op = &reiserfs_dir_ip_operations;
634 //ip->i_fop = &reiserfs_dir_operations;
635 } else if (S_ISLNK(ip->i_mode)) {
636 reiserfs_log(LOG_DEBUG, "this inode is a symlink\n");
637 //ip->i_op = &reiserfs_symlink_ip_operations;
638 //ip->i_mapping->a_ops = &reiserfs_address_space_operations;
640 reiserfs_log(LOG_DEBUG, "this inode is something unknown in "
643 //ip->i_op = &reiserfs_special_ip_operations;
644 //init_special_ip(ip, ip->i_mode, new_decode_dev(rdev));
649 * reiserfs_read_locked_inode is called to read the inode off disk, and
650 * it does a make_bad_inode when things go wrong. But, we need to make
651 * sure and clear the key in the private portion of the inode, otherwise
652 * a corresponding iput might try to delete whatever object the inode
656 reiserfs_make_bad_inode(struct reiserfs_node *ip) {
658 memset(INODE_PKEY(ip), 0, KEY_SIZE);
659 //make_bad_inode(inode);
663 reiserfs_read_locked_inode(struct reiserfs_node *ip,
664 struct reiserfs_iget_args *args)
666 INITIALIZE_PATH(path_to_sd);
668 unsigned long dirino;
671 dirino = args->dirid;
674 * Set version 1, version 2 could be used too, because stat data
675 * key is the same in both versions
677 key.version = KEY_FORMAT_3_5;
678 key.on_disk_key.k_dir_id = dirino;
679 key.on_disk_key.k_objectid = ip->i_number;
680 key.on_disk_key.u.k_offset_v1.k_offset = SD_OFFSET;
681 key.on_disk_key.u.k_offset_v1.k_uniqueness = SD_UNIQUENESS;
683 /* Look for the object's stat data */
684 retval = search_item(ip->i_reiserfs, &key, &path_to_sd);
685 if (retval == IO_ERROR) {
686 reiserfs_log(LOG_ERR,
687 "I/O failure occured trying to find stat"
689 key.on_disk_key.k_dir_id, key.on_disk_key.k_objectid);
690 reiserfs_make_bad_inode(ip);
693 if (retval != ITEM_FOUND) {
695 * A stale NFS handle can trigger this without it being
698 reiserfs_log(LOG_ERR,
699 "item not found (objectid=%u, dirid=%u)\n",
700 key.on_disk_key.k_objectid, key.on_disk_key.k_dir_id);
701 pathrelse(&path_to_sd);
702 reiserfs_make_bad_inode(ip);
707 init_inode(ip, &path_to_sd);
710 * It is possible that knfsd is trying to access inode of a file
711 * that is being removed from the disk by some other thread. As
712 * we update sd on unlink all that is required is to check for
713 * nlink here. This bug was first found by Sizif when debugging
714 * SquidNG/Butterfly, forgotten, and found again after Philippe
715 * Gramoulle <philippe.gramoulle@mmania.com> reproduced it.
717 * More logical fix would require changes in fs/inode.c:iput() to
718 * remove inode from hash-table _after_ fs cleaned disk stuff up and
719 * in iget() to return NULL if I_FREEING inode is found in hash-table.
722 * Currently there is one place where it's ok to meet inode with
723 * nlink == 0: processing of open-unlinked and half-truncated files
724 * during mount (fs/reiserfs/super.c:finish_unfinished()).
726 if((ip->i_nlink == 0) &&
727 !REISERFS_SB(ip->i_reiserfs)->s_is_unlinked_ok ) {
728 reiserfs_log(LOG_WARNING, "dead inode read from disk. This is "
729 "likely to be race with knfsd. Ignore");
730 reiserfs_make_bad_inode(ip);
733 /* Init inode should be relsing */
734 reiserfs_check_path(&path_to_sd);
739 struct mount *mp, const struct cpu_key *key,
740 struct vnode **vpp, struct thread *td)
745 struct reiserfs_node *ip;
746 struct reiserfs_mount *rmp;
748 struct reiserfs_iget_args args;
751 /* Check if the inode cache contains it */
752 // XXX LK_EXCLUSIVE ?
753 flags = LK_EXCLUSIVE;
754 error = vfs_hash_get(mp, key->on_disk_key.k_objectid, flags,
755 td, vpp, NULL, NULL);
756 if (error || *vpp != NULL)
759 rmp = VFSTOREISERFS(mp);
763 * If this malloc() is performed after the getnewvnode() it might
764 * block, leaving a vnode with a NULL v_data to be found by
765 * reiserfs_sync() if a sync happens to fire right then, which
766 * will cause a panic because reiserfs_sync() blindly dereferences
767 * vp->v_data (as well it should).
769 reiserfs_log(LOG_DEBUG, "malloc(struct reiserfs_node)\n");
770 ip = malloc(sizeof(struct reiserfs_node), M_REISERFSNODE,
773 /* Allocate a new vnode/inode. */
774 reiserfs_log(LOG_DEBUG, "getnewvnode\n");
776 getnewvnode("reiserfs", mp, &reiserfs_vnodeops, &vp)) != 0) {
778 free(ip, M_REISERFSNODE);
779 reiserfs_log(LOG_DEBUG, "getnewvnode FAILED\n");
783 args.dirid = key->on_disk_key.k_dir_id;
784 args.objectid = key->on_disk_key.k_objectid;
786 reiserfs_log(LOG_DEBUG, "filling *ip\n");
790 ip->i_number = args.objectid;
791 ip->i_ino = args.dirid;
792 ip->i_reiserfs = rmp->rm_reiserfs;
794 vp->v_bufobj.bo_ops = &reiserfs_vnbufops;
795 vp->v_bufobj.bo_private = vp;
797 /* If this is the root node, set the VV_ROOT flag */
798 if (ip->i_number == REISERFS_ROOT_OBJECTID &&
799 ip->i_ino == REISERFS_ROOT_PARENT_OBJECTID)
800 vp->v_vflag |= VV_ROOT;
803 if (VOP_LOCK(vp, LK_EXCLUSIVE) != 0)
804 panic("reiserfs/iget: unexpected lock failure");
807 * Exclusively lock the vnode before adding to hash. Note, that we
808 * must not release nor downgrade the lock (despite flags argument
809 * says) till it is fully initialized.
811 lockmgr(vp->v_vnlock, LK_EXCLUSIVE, (struct mtx *)0);
814 lockmgr(vp->v_vnlock, LK_EXCLUSIVE, NULL);
815 error = insmntque(vp, mp);
817 free(ip, M_REISERFSNODE);
819 reiserfs_log(LOG_DEBUG, "insmntque FAILED\n");
822 error = vfs_hash_insert(vp, key->on_disk_key.k_objectid, flags,
823 td, vpp, NULL, NULL);
824 if (error || *vpp != NULL)
828 reiserfs_log(LOG_DEBUG, "call reiserfs_read_locked_inode ("
829 "objectid=%d,dirid=%d)\n", args.objectid, args.dirid);
830 reiserfs_read_locked_inode(ip, &args);
832 ip->i_devvp = rmp->rm_devvp;
834 switch(vp->v_type = IFTOVT(ip->i_mode)) {
836 reiserfs_log(LOG_DEBUG, "vnode type VBLK\n");
837 vp->v_op = &reiserfs_specops;
841 reiserfs_log(LOG_DEBUG, "vnode type VCHR\n");
842 vp->v_op = &reiserfs_specops;
843 vp = addaliasu(vp, ip->i_rdev);
847 reiserfs_log(LOG_DEBUG, "vnode type VFIFO\n");
848 vp->v_op = reiserfs_fifoop_p;
860 sd_attrs_to_i_attrs(uint16_t sd_attrs, struct reiserfs_node *ip)
863 if (reiserfs_attrs(ip->i_reiserfs)) {
865 if (sd_attrs & REISERFS_SYNC_FL)
866 ip->i_flags |= S_SYNC;
868 ip->i_flags &= ~S_SYNC;
870 if (sd_attrs & REISERFS_IMMUTABLE_FL)
871 ip->i_flags |= IMMUTABLE;
873 ip->i_flags &= ~IMMUTABLE;
874 if (sd_attrs & REISERFS_APPEND_FL)
875 ip->i_flags |= APPEND;
877 ip->i_flags &= ~APPEND;
879 if (sd_attrs & REISERFS_NOATIME_FL)
880 ip->i_flags |= S_NOATIME;
882 ip->i_flags &= ~S_NOATIME;
883 if (sd_attrs & REISERFS_NOTAIL_FL)
884 REISERFS_I(ip)->i_flags |= i_nopack_mask;
886 REISERFS_I(ip)->i_flags &= ~i_nopack_mask;
892 i_attrs_to_sd_attrs(struct reiserfs_node *ip, uint16_t *sd_attrs)
895 if (reiserfs_attrs(ip->i_reiserfs)) {
897 if (ip->i_flags & S_SYNC)
898 *sd_attrs |= REISERFS_SYNC_FL;
900 *sd_attrs &= ~REISERFS_SYNC_FL;
902 if (ip->i_flags & IMMUTABLE)
903 *sd_attrs |= REISERFS_IMMUTABLE_FL;
905 *sd_attrs &= ~REISERFS_IMMUTABLE_FL;
906 if (ip->i_flags & APPEND)
907 *sd_attrs |= REISERFS_APPEND_FL;
909 *sd_attrs &= ~REISERFS_APPEND_FL;
911 if (ip->i_flags & S_NOATIME)
912 *sd_attrs |= REISERFS_NOATIME_FL;
914 *sd_attrs &= ~REISERFS_NOATIME_FL;
915 if (REISERFS_I(ip)->i_flags & i_nopack_mask)
916 *sd_attrs |= REISERFS_NOTAIL_FL;
918 *sd_attrs &= ~REISERFS_NOTAIL_FL;