- 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,
- (struct ucred *)0) != 0)
- size = DEV_BSIZE;
- else {
- havepart = 1;
- size = dpart.disklab->d_secsize;
- }
- if (error = bread(devvp, SBLOCK, SBSIZE, &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, &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;