2 * Copyright 2000 Hans Reiser
3 * See README for licensing and copyright details
5 * Ported to FreeBSD by Jean-Sébastien Pédron <jspedron@club-internet.fr>
10 #include <gnu/fs/reiserfs/reiserfs_fs.h>
12 const char reiserfs_3_5_magic_string[] = REISERFS_SUPER_MAGIC_STRING;
13 const char reiserfs_3_6_magic_string[] = REISER2FS_SUPER_MAGIC_STRING;
14 const char reiserfs_jr_magic_string[] = REISER2FS_JR_SUPER_MAGIC_STRING;
17 * Default recommended I/O size is 128k. There might be broken
18 * applications that are confused by this. Use nolargeio mount option to
19 * get usual i/o size = PAGE_SIZE.
21 int reiserfs_default_io_size = 128 * 1024;
23 static vfs_cmount_t reiserfs_cmount;
24 static vfs_fhtovp_t reiserfs_fhtovp;
25 static vfs_mount_t reiserfs_mount;
26 static vfs_root_t reiserfs_root;
27 static vfs_statfs_t reiserfs_statfs;
28 static vfs_unmount_t reiserfs_unmount;
30 static int reiserfs_mountfs(struct vnode *devvp, struct mount *mp,
32 static void load_bitmap_info_data(struct reiserfs_sb_info *sbi,
33 struct reiserfs_bitmap_info *bi);
34 static int read_bitmaps(struct reiserfs_mount *rmp);
35 static int read_old_bitmaps(struct reiserfs_mount *rmp);
36 static int read_super_block(struct reiserfs_mount *rmp, int offset);
37 static hashf_t hash_function(struct reiserfs_mount *rmp);
39 static int get_root_node(struct reiserfs_mount *rmp,
40 struct reiserfs_node **root);
41 uint32_t find_hash_out(struct reiserfs_mount *rmp);
43 MALLOC_DEFINE(M_REISERFSMNT, "reiserfs_mount", "ReiserFS mount structure");
44 MALLOC_DEFINE(M_REISERFSPATH, "reiserfs_path", "ReiserFS path structure");
45 MALLOC_DEFINE(M_REISERFSNODE, "reiserfs_node", "ReiserFS vnode private part");
47 /* -------------------------------------------------------------------
49 * -------------------------------------------------------------------*/
52 reiserfs_cmount(struct mntarg *ma, void *data, int flags)
54 struct reiserfs_args args;
55 struct export_args exp;
58 error = copyin(data, &args, sizeof(args));
61 vfs_oexport_conv(&args.export, &exp);
63 ma = mount_argsu(ma, "from", args.fspec, MAXPATHLEN);
64 ma = mount_arg(ma, "export", &exp, sizeof(exp));
66 error = kernel_mount(ma, flags);
75 reiserfs_mount(struct mount *mp)
82 struct vfsoptlist *opts;
83 struct reiserfs_mount *rmp;
84 struct reiserfs_sb_info *sbi;
85 struct nameidata nd, *ndp = &nd;
89 if (!(mp->mnt_flag & MNT_RDONLY))
92 /* Get the new options passed to mount */
93 opts = mp->mnt_optnew;
95 /* `fspath' contains the mount point (eg. /mnt/linux); REQUIRED */
96 vfs_getopt(opts, "fspath", (void **)&path, NULL);
97 reiserfs_log(LOG_INFO, "mount point is `%s'\n", path);
99 /* `from' contains the device name (eg. /dev/ad0s1); REQUIRED */
101 error = vfs_getopt(opts, "from", (void **)&fspec, &len);
102 if (!error && fspec[len - 1] != '\0')
104 reiserfs_log(LOG_INFO, "device is `%s'\n", fspec);
106 /* Handle MNT_UPDATE (mp->mnt_flag) */
107 if (mp->mnt_flag & MNT_UPDATE) {
108 /* For now, only NFS export is supported. */
109 if (vfs_flagopt(opts, "export", NULL, 0))
113 /* Not an update, or updating the name: look up the name
114 * and verify that it refers to a sensible disk device. */
118 NDINIT(ndp, LOOKUP, FOLLOW | LOCKLEAF, UIO_SYSSPACE, fspec, td);
119 if ((error = namei(ndp)) != 0)
121 NDFREE(ndp, NDF_ONLY_PNBUF);
124 if (!vn_isdisk(devvp, &error)) {
129 /* If mount by non-root, then verify that user has necessary
130 * permissions on the device. */
132 if ((mp->mnt_flag & MNT_RDONLY) == 0)
134 error = VOP_ACCESS(devvp, accmode, td->td_ucred, td);
136 error = priv_check(td, PRIV_VFS_MOUNT_PERM);
142 if ((mp->mnt_flag & MNT_UPDATE) == 0) {
143 error = reiserfs_mountfs(devvp, mp, td);
145 /* TODO Handle MNT_UPDATE */
155 rmp = VFSTOREISERFS(mp);
156 sbi = rmp->rm_reiserfs;
159 * Note that this strncpy() is ok because of a check at the start
160 * of reiserfs_mount().
162 reiserfs_log(LOG_DEBUG, "prepare statfs data\n");
163 (void)copystr(fspec, mp->mnt_stat.f_mntfromname, MNAMELEN - 1, &size);
164 bzero(mp->mnt_stat.f_mntfromname + size, MNAMELEN - size);
165 (void)reiserfs_statfs(mp, &mp->mnt_stat);
167 reiserfs_log(LOG_DEBUG, "done\n");
172 * Unmount system call
175 reiserfs_unmount(struct mount *mp, int mntflags)
177 int error, flags = 0;
178 struct reiserfs_mount *rmp;
179 struct reiserfs_sb_info *sbi;
181 reiserfs_log(LOG_DEBUG, "get private data\n");
182 rmp = VFSTOREISERFS(mp);
183 sbi = rmp->rm_reiserfs;
185 /* Flangs handling */
186 reiserfs_log(LOG_DEBUG, "handle mntflags\n");
187 if (mntflags & MNT_FORCE)
190 /* Flush files -> vflush */
191 reiserfs_log(LOG_DEBUG, "flush vnodes\n");
192 if ((error = vflush(mp, 0, flags, curthread)))
195 /* XXX Super block update */
198 if (SB_AP_BITMAP(sbi)) {
200 reiserfs_log(LOG_DEBUG,
201 "release bitmap buffers (total: %d)\n",
203 for (i = 0; i < SB_BMAP_NR(sbi); i++) {
204 if (SB_AP_BITMAP(sbi)[i].bp_data) {
205 free(SB_AP_BITMAP(sbi)[i].bp_data,
207 SB_AP_BITMAP(sbi)[i].bp_data = NULL;
211 reiserfs_log(LOG_DEBUG, "free bitmaps structure\n");
212 free(SB_AP_BITMAP(sbi), M_REISERFSMNT);
213 SB_AP_BITMAP(sbi) = NULL;
217 reiserfs_log(LOG_DEBUG, "free super block data\n");
218 free(sbi->s_rs, M_REISERFSMNT);
223 reiserfs_log(LOG_DEBUG, "close device\n");
224 #if defined(si_mountpoint)
225 rmp->rm_devvp->v_rdev->si_mountpoint = NULL;
230 g_wither_geom_close(rmp->rm_cp->geom, ENXIO);
233 vrele(rmp->rm_devvp);
236 reiserfs_log(LOG_DEBUG, "free sbi\n");
237 free(sbi, M_REISERFSMNT);
238 sbi = rmp->rm_reiserfs = NULL;
241 reiserfs_log(LOG_DEBUG, "free rmp\n");
242 free(rmp, M_REISERFSMNT);
248 mp->mnt_flag &= ~MNT_LOCAL;
251 reiserfs_log(LOG_DEBUG, "done\n");
256 * Return the root of a filesystem.
259 reiserfs_root(struct mount *mp, int flags, struct vnode **vpp)
263 struct cpu_key rootkey;
265 rootkey.on_disk_key.k_dir_id = REISERFS_ROOT_PARENT_OBJECTID;
266 rootkey.on_disk_key.k_objectid = REISERFS_ROOT_OBJECTID;
268 error = reiserfs_iget(mp, &rootkey, &vp, curthread);
279 reiserfs_statfs(struct mount *mp, struct statfs *sbp)
281 struct reiserfs_mount *rmp;
282 struct reiserfs_sb_info *sbi;
283 struct reiserfs_super_block *rs;
285 reiserfs_log(LOG_DEBUG, "get private data\n");
286 rmp = VFSTOREISERFS(mp);
287 sbi = rmp->rm_reiserfs;
290 reiserfs_log(LOG_DEBUG, "fill statfs structure\n");
291 sbp->f_bsize = sbi->s_blocksize;
292 sbp->f_iosize = sbp->f_bsize;
293 sbp->f_blocks = sb_block_count(rs) - sb_bmap_nr(rs) - 1;
294 sbp->f_bfree = sb_free_blocks(rs);
295 sbp->f_bavail = sbp->f_bfree;
298 reiserfs_log(LOG_DEBUG, " block size = %ju\n",
299 (intmax_t)sbp->f_bsize);
300 reiserfs_log(LOG_DEBUG, " IO size = %ju\n",
301 (intmax_t)sbp->f_iosize);
302 reiserfs_log(LOG_DEBUG, " block count = %ju\n",
303 (intmax_t)sbp->f_blocks);
304 reiserfs_log(LOG_DEBUG, " free blocks = %ju\n",
305 (intmax_t)sbp->f_bfree);
306 reiserfs_log(LOG_DEBUG, " avail blocks = %ju\n",
307 (intmax_t)sbp->f_bavail);
308 reiserfs_log(LOG_DEBUG, "...done\n");
310 if (sbp != &mp->mnt_stat) {
311 reiserfs_log(LOG_DEBUG, "copying monut point info\n");
312 sbp->f_type = mp->mnt_vfc->vfc_typenum;
313 bcopy((caddr_t)mp->mnt_stat.f_mntonname,
314 (caddr_t)&sbp->f_mntonname[0], MNAMELEN);
315 bcopy((caddr_t)mp->mnt_stat.f_mntfromname,
316 (caddr_t)&sbp->f_mntfromname[0], MNAMELEN);
317 reiserfs_log(LOG_DEBUG, " mount from: %s\n",
319 reiserfs_log(LOG_DEBUG, " mount on: %s\n",
321 reiserfs_log(LOG_DEBUG, "...done\n");
328 * File handle to vnode
330 * Have to be really careful about stale file handles:
331 * - check that the inode key is valid
332 * - call ffs_vget() to get the locked inode
333 * - check for an unallocated inode (i_mode == 0)
334 * - check that the given client host has export rights and return
335 * those rights via. exflagsp and credanonp
338 reiserfs_fhtovp(struct mount *mp, struct fid *fhp, int flags,
345 struct reiserfs_node *ip;
346 struct reiserfs_sb_info *sbi;
347 struct thread *td = curthread;
349 rfhp = (struct rfid *)fhp;
350 sbi = VFSTOREISERFS(mp)->rm_reiserfs;
352 /* Check that the key is valid */
353 if (rfhp->rfid_dirid < REISERFS_ROOT_PARENT_OBJECTID &&
354 rfhp->rfid_objectid < REISERFS_ROOT_OBJECTID)
357 reiserfs_log(LOG_DEBUG,
358 "file handle key is (dirid=%d, objectid=%d)\n",
359 rfhp->rfid_dirid, rfhp->rfid_objectid);
360 key.on_disk_key.k_dir_id = rfhp->rfid_dirid;
361 key.on_disk_key.k_objectid = rfhp->rfid_objectid;
363 reiserfs_log(LOG_DEBUG, "read this inode\n");
364 error = reiserfs_iget(mp, &key, &nvp, td);
370 reiserfs_log(LOG_DEBUG, "check validity\n");
372 if (ip->i_mode == 0 || ip->i_generation != rfhp->rfid_gen) {
378 reiserfs_log(LOG_DEBUG, "return it\n");
383 /* -------------------------------------------------------------------
384 * Functions for the journal
385 * -------------------------------------------------------------------*/
388 is_reiserfs_3_5(struct reiserfs_super_block *rs)
391 return (!strncmp(rs->s_v1.s_magic, reiserfs_3_5_magic_string,
392 strlen(reiserfs_3_5_magic_string)));
396 is_reiserfs_3_6(struct reiserfs_super_block *rs)
399 return (!strncmp(rs->s_v1.s_magic, reiserfs_3_6_magic_string,
400 strlen(reiserfs_3_6_magic_string)));
404 is_reiserfs_jr(struct reiserfs_super_block *rs)
407 return (!strncmp(rs->s_v1.s_magic, reiserfs_jr_magic_string,
408 strlen(reiserfs_jr_magic_string)));
412 is_any_reiserfs_magic_string(struct reiserfs_super_block *rs)
415 return ((is_reiserfs_3_5(rs) || is_reiserfs_3_6(rs) ||
416 is_reiserfs_jr(rs)));
419 /* -------------------------------------------------------------------
421 * -------------------------------------------------------------------*/
424 * Common code for mount and mountroot
427 reiserfs_mountfs(struct vnode *devvp, struct mount *mp, struct thread *td)
429 int error, old_format = 0;
430 struct reiserfs_mount *rmp;
431 struct reiserfs_sb_info *sbi;
432 struct reiserfs_super_block *rs;
433 struct cdev *dev = devvp->v_rdev;
435 struct g_consumer *cp;
438 //ronly = (mp->mnt_flag & MNT_RDONLY) != 0;
442 error = g_vfs_open(devvp, &cp, "reiserfs", /* read-only */ 0);
445 VOP_UNLOCK(devvp, 0);
449 bo = &devvp->v_bufobj;
451 bo->bo_ops = g_vfs_bufops;
453 if (devvp->v_rdev->si_iosize_max != 0)
454 mp->mnt_iosize_max = devvp->v_rdev->si_iosize_max;
455 if (mp->mnt_iosize_max > MAXPHYS)
456 mp->mnt_iosize_max = MAXPHYS;
461 /* rmp contains any information about this specific mount */
462 rmp = malloc(sizeof *rmp, M_REISERFSMNT, M_WAITOK | M_ZERO);
467 sbi = malloc(sizeof *sbi, M_REISERFSMNT, M_WAITOK | M_ZERO);
472 rmp->rm_reiserfs = sbi;
474 rmp->rm_devvp = devvp;
476 rmp->rm_bo = &devvp->v_bufobj;
479 /* Set default values for options: non-aggressive tails */
480 REISERFS_SB(sbi)->s_mount_opt = (1 << REISERFS_SMALLTAIL);
481 REISERFS_SB(sbi)->s_rd_only = 1;
482 REISERFS_SB(sbi)->s_devvp = devvp;
484 /* Read the super block */
485 if ((error = read_super_block(rmp, REISERFS_OLD_DISK_OFFSET)) == 0) {
486 /* The read process succeeded, it's an old format */
488 } else if ((error = read_super_block(rmp, REISERFS_DISK_OFFSET)) != 0) {
489 reiserfs_log(LOG_ERR, "can not find a ReiserFS filesystem\n");
493 rs = SB_DISK_SUPER_BLOCK(sbi);
496 * Let's do basic sanity check to verify that underlying device is
497 * not smaller than the filesystem. If the check fails then abort and
498 * scream, because bad stuff will happen otherwise.
501 if (s->s_bdev && s->s_bdev->bd_inode &&
502 i_size_read(s->s_bdev->bd_inode) <
503 sb_block_count(rs) * sb_blocksize(rs)) {
504 reiserfs_log(LOG_ERR,
505 "reiserfs: filesystem cannot be mounted because it is "
506 "bigger than the device.\n");
507 reiserfs_log(LOG_ERR, "reiserfs: you may need to run fsck "
508 "rr may be you forgot to reboot after fdisk when it "
515 * XXX This is from the original Linux code, but why affecting 2 values
516 * to the same variable?
518 sbi->s_mount_state = SB_REISERFS_STATE(sbi);
519 sbi->s_mount_state = REISERFS_VALID_FS;
521 if ((error = (old_format ?
522 read_old_bitmaps(rmp) : read_bitmaps(rmp)))) {
523 reiserfs_log(LOG_ERR, "unable to read bitmap\n");
527 /* Make data=ordered the default */
528 if (!reiserfs_data_log(sbi) && !reiserfs_data_ordered(sbi) &&
529 !reiserfs_data_writeback(sbi)) {
530 REISERFS_SB(sbi)->s_mount_opt |= (1 << REISERFS_DATA_ORDERED);
533 if (reiserfs_data_log(sbi)) {
534 reiserfs_log(LOG_INFO, "using journaled data mode\n");
535 } else if (reiserfs_data_ordered(sbi)) {
536 reiserfs_log(LOG_INFO, "using ordered data mode\n");
538 reiserfs_log(LOG_INFO, "using writeback data mode\n");
541 /* TODO Not yet supported */
543 if(journal_init(sbi, jdev_name, old_format, commit_max_age)) {
544 reiserfs_log(LOG_ERR, "unable to initialize journal space\n");
547 jinit_done = 1 ; /* once this is set, journal_release must
548 be called if we error out of the mount */
551 if (reread_meta_blocks(sbi)) {
552 reiserfs_log(LOG_ERR,
553 "unable to reread meta blocks after journal init\n");
558 /* Define and initialize hash function */
559 sbi->s_hash_function = hash_function(rmp);
561 if (sbi->s_hash_function == NULL) {
562 reiserfs_log(LOG_ERR, "couldn't determined hash function\n");
567 if (is_reiserfs_3_5(rs) ||
568 (is_reiserfs_jr(rs) && SB_VERSION(sbi) == REISERFS_VERSION_1))
569 bit_set(&(sbi->s_properties), REISERFS_3_5);
571 bit_set(&(sbi->s_properties), REISERFS_3_6);
574 mp->mnt_stat.f_fsid.val[0] = dev2udev(dev);
575 mp->mnt_stat.f_fsid.val[1] = mp->mnt_vfc->vfc_typenum;
577 mp->mnt_flag |= MNT_LOCAL;
579 #if defined(si_mountpoint)
580 devvp->v_rdev->si_mountpoint = mp;
586 reiserfs_log(LOG_INFO, "*** error during mount ***\n");
588 if (SB_AP_BITMAP(sbi)) {
590 for (i = 0; i < SB_BMAP_NR(sbi); i++) {
591 if (!SB_AP_BITMAP(sbi)[i].bp_data)
593 free(SB_AP_BITMAP(sbi)[i].bp_data, M_REISERFSMNT);
595 free(SB_AP_BITMAP(sbi), M_REISERFSMNT);
599 free(sbi->s_rs, M_REISERFSMNT);
607 g_wither_geom_close(cp->geom, ENXIO);
613 free(sbi, M_REISERFSMNT);
615 free(rmp, M_REISERFSMNT);
620 * Read the super block
623 read_super_block(struct reiserfs_mount *rmp, int offset)
627 struct reiserfs_super_block *rs;
628 struct reiserfs_sb_info *sbi;
629 uint16_t fs_blocksize;
631 if (offset == REISERFS_OLD_DISK_OFFSET) {
632 reiserfs_log(LOG_DEBUG,
633 "reiserfs/super: read old format super block\n");
635 reiserfs_log(LOG_DEBUG,
636 "reiserfs/super: read new format super block\n");
639 /* Read the super block */
640 if ((error = bread(rmp->rm_devvp, offset * btodb(REISERFS_BSIZE),
641 REISERFS_BSIZE, NOCRED, &bp)) != 0) {
642 reiserfs_log(LOG_ERR, "can't read device\n");
646 /* Get it from the buffer data */
647 rs = (struct reiserfs_super_block *)bp->b_data;
648 if (!is_any_reiserfs_magic_string(rs)) {
653 fs_blocksize = sb_blocksize(rs);
657 if (fs_blocksize <= 0) {
658 reiserfs_log(LOG_ERR, "unexpected null block size");
662 /* Read the super block (for double check)
663 * We can't read the same blkno with a different size: it causes
664 * panic() if INVARIANTS is set. So we keep REISERFS_BSIZE */
665 if ((error = bread(rmp->rm_devvp,
666 offset * REISERFS_BSIZE / fs_blocksize * btodb(fs_blocksize),
667 REISERFS_BSIZE, NOCRED, &bp)) != 0) {
668 reiserfs_log(LOG_ERR, "can't reread the super block\n");
672 rs = (struct reiserfs_super_block *)bp->b_data;
673 if (sb_blocksize(rs) != fs_blocksize) {
674 reiserfs_log(LOG_ERR, "unexpected block size "
675 "(found=%u, expected=%u)\n",
676 sb_blocksize(rs), fs_blocksize);
681 reiserfs_log(LOG_DEBUG, "magic: `%s'\n", rs->s_v1.s_magic);
682 reiserfs_log(LOG_DEBUG, "label: `%s'\n", rs->s_label);
683 reiserfs_log(LOG_DEBUG, "block size: %6d\n", sb_blocksize(rs));
684 reiserfs_log(LOG_DEBUG, "block count: %6u\n",
685 rs->s_v1.s_block_count);
686 reiserfs_log(LOG_DEBUG, "bitmaps number: %6u\n",
689 if (rs->s_v1.s_root_block == -1) {
691 "reiserfs: Unfinished reiserfsck --rebuild-tree run "
693 "run reiserfsck --rebuild-tree and wait for a "
694 "completion. If that\n"
695 "fails, get newer reiserfsprogs package");
700 sbi = rmp->rm_reiserfs;
701 sbi->s_blocksize = fs_blocksize;
703 for (bits = 9, fs_blocksize >>= 9; fs_blocksize >>= 1; bits++)
705 sbi->s_blocksize_bits = bits;
707 /* Copy the buffer and release it */
708 sbi->s_rs = malloc(sizeof *rs, M_REISERFSMNT, M_WAITOK | M_ZERO);
710 reiserfs_log(LOG_ERR, "can not read the super block\n");
714 bcopy(rs, sbi->s_rs, sizeof(struct reiserfs_super_block));
717 if (is_reiserfs_jr(rs)) {
718 if (sb_version(rs) == REISERFS_VERSION_2)
719 reiserfs_log(LOG_INFO, "found reiserfs format \"3.6\""
720 " with non-standard journal");
721 else if (sb_version(rs) == REISERFS_VERSION_1)
722 reiserfs_log(LOG_INFO, "found reiserfs format \"3.5\""
723 " with non-standard journal");
725 reiserfs_log(LOG_ERR, "found unknown "
726 "format \"%u\" of reiserfs with non-standard magic",
732 * s_version of standard format may contain incorrect
733 * information, so we just look at the magic string
735 reiserfs_log(LOG_INFO,
736 "found reiserfs format \"%s\" with standard journal\n",
737 is_reiserfs_3_5(rs) ? "3.5" : "3.6");
744 * load_bitmap_info_data - Sets up the reiserfs_bitmap_info structure
746 * @sbi - superblock info for this filesystem
747 * @bi - the bitmap info to be loaded. Requires that bi->bp is valid.
749 * This routine counts how many free bits there are, finding the first
750 * zero as a side effect. Could also be implemented as a loop of
751 * test_bit() calls, or a loop of find_first_zero_bit() calls. This
752 * implementation is similar to find_first_zero_bit(), but doesn't
753 * return after it finds the first bit. Should only be called on fs
754 * mount, but should be fairly efficient anyways.
756 * bi->first_zero_hint is considered unset if it == 0, since the bitmap
757 * itself will invariably occupt block 0 represented in the bitmap. The
758 * only exception to this is when free_count also == 0, since there will
759 * be no free blocks at all.
762 load_bitmap_info_data(struct reiserfs_sb_info *sbi,
763 struct reiserfs_bitmap_info *bi)
767 cur = (unsigned long *)bi->bp_data;
768 while ((char *)cur < (bi->bp_data + sbi->s_blocksize)) {
770 * No need to scan if all 0's or all 1's.
771 * Since we're only counting 0's, we can simply ignore
775 if (bi->first_zero_hint == 0) {
776 bi->first_zero_hint =
777 ((char *)cur - bi->bp_data) << 3;
779 bi->free_count += sizeof(unsigned long) * 8;
780 } else if (*cur != ~0L) {
783 for (b = 0; b < sizeof(unsigned long) * 8; b++) {
784 if (!reiserfs_test_le_bit(b, cur)) {
786 if (bi->first_zero_hint == 0)
787 bi->first_zero_hint =
789 bi->bp_data) << 3) + b;
801 read_bitmaps(struct reiserfs_mount *rmp)
804 struct buf *bp = NULL;
805 struct reiserfs_sb_info *sbi = rmp->rm_reiserfs;
807 /* Allocate memory for the table of bitmaps */
809 malloc(sizeof(struct reiserfs_bitmap_info) * SB_BMAP_NR(sbi),
810 M_REISERFSMNT, M_WAITOK | M_ZERO);
811 if (!SB_AP_BITMAP(sbi))
814 /* Read all the bitmaps */
816 bmap_nr = (REISERFS_DISK_OFFSET_IN_BYTES / sbi->s_blocksize + 1) *
817 btodb(sbi->s_blocksize);
818 i < SB_BMAP_NR(sbi); i++, bmap_nr = sbi->s_blocksize * 8 * i) {
819 SB_AP_BITMAP(sbi)[i].bp_data = malloc(sbi->s_blocksize,
820 M_REISERFSMNT, M_WAITOK | M_ZERO);
821 if (!SB_AP_BITMAP(sbi)[i].bp_data)
823 bread(rmp->rm_devvp, bmap_nr, sbi->s_blocksize, NOCRED, &bp);
824 bcopy(bp->b_data, SB_AP_BITMAP(sbi)[i].bp_data,
829 /*if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh))
830 ll_rw_block(READ, 1, &SB_AP_BITMAP(s)[i].bh);*/
833 for (i = 0; i < SB_BMAP_NR(sbi); i++) {
834 /*if (!buffer_uptodate(SB_AP_BITMAP(s)[i].bh)) {
835 reiserfs_warning(s,"sh-2029: reiserfs read_bitmaps: "
836 "bitmap block (#%lu) reading failed",
837 SB_AP_BITMAP(s)[i].bh->b_blocknr);
838 for (i = 0; i < SB_BMAP_NR(s); i++)
839 brelse(SB_AP_BITMAP(s)[i].bh);
840 vfree(SB_AP_BITMAP(s));
841 SB_AP_BITMAP(s) = NULL;
844 load_bitmap_info_data(sbi, SB_AP_BITMAP(sbi) + i);
845 reiserfs_log(LOG_DEBUG,
846 "%d free blocks (starting at block %ld)\n",
847 SB_AP_BITMAP(sbi)[i].free_count,
848 (long)SB_AP_BITMAP(sbi)[i].first_zero_hint);
854 // TODO Not supported
856 read_old_bitmaps(struct reiserfs_mount *rmp)
862 struct reiserfs_sb_info *sbi = rmp->rm_reiserfs;
863 struct reiserfs_super_block *rs = SB_DISK_SUPER_BLOCK(sbi);
865 /* First of bitmap blocks */
866 int bmp1 = (REISERFS_OLD_DISK_OFFSET / sbi->s_blocksize) *
867 btodb(sbi->s_blocksize);
869 /* Read true bitmap */
871 malloc(sizeof (struct reiserfs_buffer_info *) * sb_bmap_nr(rs),
872 M_REISERFSMNT, M_WAITOK | M_ZERO);
873 if (!SB_AP_BITMAP(sbi))
876 for (i = 0; i < sb_bmap_nr(rs); i ++) {
877 SB_AP_BITMAP(sbi)[i].bp = getblk(rmp->rm_devvp,
878 (bmp1 + i) * btodb(sbi->s_blocksize), sbi->s_blocksize, 0, 0, 0);
879 if (!SB_AP_BITMAP(sbi)[i].bp)
881 load_bitmap_info_data(sbi, SB_AP_BITMAP(sbi) + i);
888 /* -------------------------------------------------------------------
889 * Hash detection stuff
890 * -------------------------------------------------------------------*/
893 get_root_node(struct reiserfs_mount *rmp, struct reiserfs_node **root)
895 struct reiserfs_node *ip;
896 struct reiserfs_iget_args args;
898 /* Allocate the node structure */
899 reiserfs_log(LOG_DEBUG, "malloc(struct reiserfs_node)\n");
900 ip = malloc(sizeof(struct reiserfs_node),
901 M_REISERFSNODE, M_WAITOK | M_ZERO);
903 /* Fill the structure */
904 reiserfs_log(LOG_DEBUG, "filling *ip\n");
905 ip->i_dev = rmp->rm_dev;
906 ip->i_number = REISERFS_ROOT_OBJECTID;
907 ip->i_ino = REISERFS_ROOT_PARENT_OBJECTID;
908 ip->i_reiserfs = rmp->rm_reiserfs;
911 args.objectid = ip->i_number;
912 args.dirid = ip->i_ino;
913 reiserfs_log(LOG_DEBUG, "call reiserfs_read_locked_inode("
914 "objectid=%d,dirid=%d)\n", args.objectid, args.dirid);
915 reiserfs_read_locked_inode(ip, &args);
917 ip->i_devvp = rmp->rm_devvp;
918 //XXX VREF(ip->i_devvp); Is it necessary ?
925 * If root directory is empty - we set default - Yura's - hash and warn
927 * FIXME: we look for only one name in a directory. If tea and yura both
928 * have the same value - we ask user to send report to the mailing list
930 uint32_t find_hash_out(struct reiserfs_mount *rmp)
934 INITIALIZE_PATH(path);
935 struct reiserfs_node *ip;
936 struct reiserfs_sb_info *sbi;
937 struct reiserfs_dir_entry de;
938 uint32_t hash = DEFAULT_HASH;
940 get_root_node(rmp, &ip);
944 sbi = rmp->rm_reiserfs;
947 uint32_t teahash, r5hash, yurahash;
949 reiserfs_log(LOG_DEBUG, "make_cpu_key\n");
950 make_cpu_key(&key, ip, ~0, TYPE_DIRENTRY, 3);
951 reiserfs_log(LOG_DEBUG, "search_by_entry_key for "
952 "key(objectid=%d,dirid=%d)\n",
953 key.on_disk_key.k_objectid, key.on_disk_key.k_dir_id);
954 retval = search_by_entry_key(sbi, &key, &path, &de);
955 if (retval == IO_ERROR) {
959 if (retval == NAME_NOT_FOUND)
962 reiserfs_log(LOG_DEBUG, "name found\n");
964 set_de_name_and_namelen(&de);
966 if (deh_offset(&(de.de_deh[de.de_entry_num])) == DOT_DOT_OFFSET) {
967 /* Allow override in this case */
968 if (reiserfs_rupasov_hash(sbi)) {
971 reiserfs_log(LOG_DEBUG,
972 "FS seems to be empty, autodetect "
973 "is using the default hash");
977 r5hash = GET_HASH_VALUE(r5_hash(de.de_name, de.de_namelen));
978 teahash = GET_HASH_VALUE(keyed_hash(de.de_name,
980 yurahash = GET_HASH_VALUE(yura_hash(de.de_name, de.de_namelen));
981 if (((teahash == r5hash) &&
983 deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash)) ||
984 ((teahash == yurahash) &&
987 deh_offset(&(de.de_deh[de.de_entry_num]))))) ||
988 ((r5hash == yurahash) &&
991 deh_offset(&(de.de_deh[de.de_entry_num])))))) {
992 reiserfs_log(LOG_ERR,
993 "unable to automatically detect hash "
994 "function. Please mount with -o "
995 "hash={tea,rupasov,r5}");
1001 deh_offset(&(de.de_deh[de.de_entry_num]))) == yurahash) {
1002 reiserfs_log(LOG_DEBUG, "detected YURA hash\n");
1004 } else if (GET_HASH_VALUE(
1005 deh_offset(&(de.de_deh[de.de_entry_num]))) == teahash) {
1006 reiserfs_log(LOG_DEBUG, "detected TEA hash\n");
1008 } else if (GET_HASH_VALUE(
1009 deh_offset(&(de.de_deh[de.de_entry_num]))) == r5hash) {
1010 reiserfs_log(LOG_DEBUG, "detected R5 hash\n");
1013 reiserfs_log(LOG_WARNING, "unrecognised hash function");
1022 /* Finds out which hash names are sorted with */
1024 what_hash(struct reiserfs_mount *rmp)
1027 struct reiserfs_sb_info *sbi = rmp->rm_reiserfs;
1030 code = sb_hash_function_code(SB_DISK_SUPER_BLOCK(sbi));
1033 * reiserfs_hash_detect() == true if any of the hash mount options
1034 * were used. We must check them to make sure the user isn't using a
1037 if (code == UNSET_HASH || reiserfs_hash_detect(sbi))
1038 code = find_hash_out(rmp);
1040 if (code != UNSET_HASH && reiserfs_hash_detect(sbi)) {
1042 * Detection has found the hash, and we must check against
1045 if (reiserfs_rupasov_hash(sbi) && code != YURA_HASH) {
1046 reiserfs_log(LOG_ERR, "error, %s hash detected, "
1047 "unable to force rupasov hash",
1048 reiserfs_hashname(code));
1050 } else if (reiserfs_tea_hash(sbi) && code != TEA_HASH) {
1051 reiserfs_log(LOG_ERR, "error, %s hash detected, "
1052 "unable to force tea hash",
1053 reiserfs_hashname(code));
1055 } else if (reiserfs_r5_hash(sbi) && code != R5_HASH) {
1056 reiserfs_log(LOG_ERR, "error, %s hash detected, "
1057 "unable to force r5 hash",
1058 reiserfs_hashname(code));
1063 * Find_hash_out was not called or could not determine
1066 if (reiserfs_rupasov_hash(sbi)) {
1068 } else if (reiserfs_tea_hash(sbi)) {
1070 } else if (reiserfs_r5_hash(sbi)) {
1075 /* TODO Not supported yet */
1077 /* If we are mounted RW, and we have a new valid hash code, update
1079 if (code != UNSET_HASH &&
1080 !(s->s_flags & MS_RDONLY) &&
1081 code != sb_hash_function_code(SB_DISK_SUPER_BLOCK(s))) {
1082 set_sb_hash_function_code(SB_DISK_SUPER_BLOCK(s), code);
1089 /* Return pointer to appropriate function */
1091 hash_function(struct reiserfs_mount *rmp)
1094 switch (what_hash(rmp)) {
1096 reiserfs_log(LOG_INFO, "using tea hash to sort names\n");
1097 return (keyed_hash);
1099 reiserfs_log(LOG_INFO, "using rupasov hash to sort names\n");
1102 reiserfs_log(LOG_INFO, "using r5 hash to sort names\n");
1109 /* -------------------------------------------------------------------
1111 * -------------------------------------------------------------------*/
1113 static struct vfsops reiser_vfsops = {
1114 .vfs_cmount = reiserfs_cmount,
1115 .vfs_mount = reiserfs_mount,
1116 .vfs_unmount = reiserfs_unmount,
1117 //.vfs_checkexp = reiserfs_checkexp,
1118 //.vfs_extattrctl = reiserfs_extattrctl,
1119 .vfs_fhtovp = reiserfs_fhtovp,
1120 //.vfs_quotactl = reiserfs_quotactl,
1121 .vfs_root = reiserfs_root,
1122 //.vfs_start = reiserfs_start,
1123 .vfs_statfs = reiserfs_statfs,
1124 //.vfs_sync = reiserfs_sync,
1125 //.vfs_vget = reiserfs_vget,
1128 VFS_SET(reiser_vfsops, reiserfs, VFCF_READONLY);