-mountfs(devvp, mp)
- struct vnode *devvp;
- struct mount *mp;
-{
- register struct ufsmount *ump;
- struct ufsmount *fmp = NULL;
- struct buf *bp = NULL;
- register struct fs *fs;
- dev_t dev = devvp->v_rdev;
- struct partinfo dpart;
- int havepart = 0, blks;
- caddr_t base, space;
- int havepart = 0, blks;
- int error, i, size;
- int needclose = 0;
- int ronly = (mp->m_flag & M_RDONLY) != 0;
-
- for (ump = &mounttab[0]; ump < &mounttab[NMOUNT]; ump++) {
- if (ump->um_fs == NULL) {
- if (fmp == NULL)
- fmp = ump;
- } else if (dev == ump->um_dev) {
- return (EBUSY); /* needs translation */
- }
- }
- (*bdevsw[major(dev)].d_open)(dev, ronly ? FREAD : FREAD|FWRITE,
- S_IFBLK);
- if (error) {
- ump->um_fs = NULL;
- return (error);
- }
- needclose = 1;
- if (VOP_IOCTL(devvp, DIOCGPART, (caddr_t)&dpart, FREAD, NOCRED) != 0)
- size = DEV_BSIZE;
- else {
- havepart = 1;
- size = dpart.disklab->d_secsize;
- }
- if (error = bread(devvp, SBLOCK, SBSIZE, NOCRED, &bp)) {
- ump->um_fs = NULL;
- goto out;
- }
- fs = bp->b_un.b_fs;
- ump->um_fs = NULL;
- error = EINVAL; /* XXX also needs translation */
- goto out;
- }
- ump->um_fs = (struct fs *)malloc((u_long)fs->fs_sbsize, M_SUPERBLK,
- M_WAITOK);
- bcopy((caddr_t)bp->b_un.b_addr, (caddr_t)ump->um_fs,
- (u_int)fs->fs_sbsize);
- brelse(bp);
- bp = NULL;
- fs = ump->um_fs;
- fs->fs_ronly = ronly;
- if (ronly == 0)
- fs->fs_fmod = 1;
- if (havepart) {
- dpart.part->p_fstype = FS_BSDFFS;
- dpart.part->p_fsize = fs->fs_fsize;
- dpart.part->p_frag = fs->fs_frag;
- dpart.part->p_cpg = fs->fs_cpg;
- }
-#ifdef SECSIZE
- /*
- * If we have a disk label, force per-partition
- * filesystem information to be correct
- * and set correct current fsbtodb shift.
- */
-#endif SECSIZE
- if (havepart) {
- dpart.part->p_fstype = FS_BSDFFS;
- dpart.part->p_fsize = fs->fs_fsize;
- dpart.part->p_frag = fs->fs_frag;
-#ifdef SECSIZE
-#ifdef tahoe
- /*
- * Save the original fsbtodb shift to restore on updates.
- * (Console doesn't understand fsbtodb changes.)
- */
- fs->fs_sparecon[0] = fs->fs_fsbtodb;
-#endif
- i = fs->fs_fsize / size;
- for (fs->fs_fsbtodb = 0; i > 1; i >>= 1)
- fs->fs_fsbtodb++;
-#endif SECSIZE
- fs->fs_dbsize = size;
- }
- blks = howmany(fs->fs_cssize, fs->fs_fsize);
- base = space = (caddr_t)malloc((u_long)fs->fs_cssize, M_SUPERBLK,
- M_WAITOK);
- for (i = 0; i < blks; i += fs->fs_frag) {
- size = fs->fs_bsize;
- if (i + fs->fs_frag > blks)
- size = (blks - i) * fs->fs_fsize;
-#ifdef SECSIZE
- tp = bread(dev, fsbtodb(fs, fs->fs_csaddr + i), size,
- fs->fs_dbsize);
-#else SECSIZE
- error = bread(devvp, fsbtodb(fs, fs->fs_csaddr + i), size,
- NOCRED, &bp);
- if (error) {
- free((caddr_t)base, M_SUPERBLK);
- goto out;
- }
- bcopy((caddr_t)bp->b_un.b_addr, space, (u_int)size);
- fs->fs_csp[fragstoblks(fs, i)] = (struct csum *)space;
- space += size;
- brelse(bp);
- bp = NULL;
- }
- mp->m_data = (qaddr_t)ump;
- mp->m_bsize = fs->fs_bsize;
- mp->m_fsize = fs->fs_fsize;
- mp->m_fsid.val[0] = (long)dev;
- mp->m_fsid.val[1] = MOUNT_UFS;
- ump->um_mountp = mp;
- ump->um_dev = dev;
- ump->um_devvp = devvp;
- ump->um_qinod = NULL;
- devvp->v_mount = mp;
-
- /* Sanity checks for old file systems. XXX */
- fs->fs_npsect = MAX(fs->fs_npsect, fs->fs_nsect); /* XXX */
- fs->fs_interleave = MAX(fs->fs_interleave, 1); /* XXX */
- if (fs->fs_postblformat == FS_42POSTBLFMT) /* XXX */
- fs->fs_nrpos = 8; /* XXX */
-
- return (0);
-out:
- if (needclose)
- (void) VOP_CLOSE(devvp, ronly ? FREAD : FREAD|FWRITE, NOCRED);
- if (ump->um_fs) {
- free((caddr_t)ump->um_fs, M_SUPERBLK);
- ump->um_fs = NULL;
- }
- if (bp)
- brelse(bp);
- return (error);
-}