Hi,
here is a patch to put the AppleUFS detection code inside a function.

This changes the behavior a bit: if the kernel cannot determine whether the
disk is an AppleUFS one or not, it now considers it as a normal UFS rather
than returning an error and not mounting/reloading it.

Ok?

Tested on amd64, no regression seen.


Index: ffs_vfsops.c
===================================================================
RCS file: /cvsroot/src/sys/ufs/ffs/ffs_vfsops.c,v
retrieving revision 1.328
diff -u -r1.328 ffs_vfsops.c
--- ffs_vfsops.c        4 Apr 2015 06:00:12 -0000       1.328
+++ ffs_vfsops.c        4 Apr 2015 13:14:09 -0000
@@ -113,6 +113,7 @@
 
 static int ffs_vfs_fsync(vnode_t *, int);
 static int ffs_superblock_validate(struct fs *);
+static int ffs_is_appleufs(struct vnode *, struct fs *);
 
 static int ffs_init_vnode(struct ufsmount *, struct vnode *, ino_t);
 static void ffs_deinit_vnode(struct ufsmount *, struct vnode *);
@@ -693,7 +694,6 @@
        void *space;
        struct buf *bp;
        struct fs *fs, *newfs;
-       struct dkwedge_info dkw;
        int i, bsize, blks, error;
        int32_t *lp, fs_sbsize;
        struct ufsmount *ump;
@@ -776,41 +776,18 @@
        memcpy(fs, newfs, (u_int)fs_sbsize);
        kmem_free(newfs, fs_sbsize);
 
-       /* Recheck for apple UFS filesystem */
-       ump->um_flags &= ~UFS_ISAPPLEUFS;
-       /* First check to see if this is tagged as an Apple UFS filesystem
-        * in the disklabel
+       /*
+        * Recheck for Apple UFS filesystem.
         */
-       if (getdiskinfo(devvp, &dkw) == 0 &&
-           strcmp(dkw.dkw_ptype, DKW_PTYPE_APPLEUFS) == 0)
-               ump->um_flags |= UFS_ISAPPLEUFS;
+       ump->um_flags &= ~UFS_ISAPPLEUFS;
+       if (ffs_is_appleufs(devvp, fs)) {
 #ifdef APPLE_UFS
-       else {
-               /* Manually look for an apple ufs label, and if a valid one
-                * is found, then treat it like an Apple UFS filesystem anyway
-                *
-                * EINVAL is most probably a blocksize or alignment problem,
-                * it is unlikely that this is an Apple UFS filesystem then.
-                */
-               error = bread(devvp,
-                   (daddr_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE),
-                   APPLEUFS_LABEL_SIZE, 0, &bp);
-               if (error && error != EINVAL) {
-                       return error;
-               }
-               if (error == 0) {
-                       error = ffs_appleufs_validate(fs->fs_fsmnt,
-                               (struct appleufslabel *)bp->b_data, NULL);
-                       if (error == 0)
-                               ump->um_flags |= UFS_ISAPPLEUFS;
-                       brelse(bp, 0);
-               }
-               bp = NULL;
-       }
+               ump->um_flags |= UFS_ISAPPLEUFS;
 #else
-       if (ump->um_flags & UFS_ISAPPLEUFS)
-               return (EIO);
+               DPRINTF("AppleUFS not supported");
+               return (EIO); /* XXX: really? */
 #endif
+       }
 
        if (UFS_MPISAPPLEUFS(ump)) {
                /* see comment about NeXT below */
@@ -1006,6 +983,46 @@
        return 1;
 }
 
+static int
+ffs_is_appleufs(struct vnode *devvp, struct fs *fs)
+{
+       struct dkwedge_info dkw;
+       int ret = 0;
+
+       /*
+        * First check to see if this is tagged as an Apple UFS filesystem
+        * in the disklabel.
+        */
+       if (getdiskinfo(devvp, &dkw) == 0 &&
+           strcmp(dkw.dkw_ptype, DKW_PTYPE_APPLEUFS) == 0)
+               ret = 1;
+#ifdef APPLE_UFS
+       else {
+               struct appleufslabel *applefs;
+               struct buf *bp;
+               daddr_t blkno = APPLEUFS_LABEL_OFFSET / DEV_BSIZE;
+               int error;
+
+               /*
+                * Manually look for an Apple UFS label, and if a valid one
+                * is found, then treat it like an Apple UFS filesystem anyway.
+                */
+               error = bread(devvp, blkno, APPLEUFS_LABEL_SIZE, 0, &bp);
+               if (error) {
+                       DPRINTF("bread@0x%jx returned %d", (intmax_t)blkno, 
error);
+                       return 0;
+               }
+               applefs = (struct appleufslabel *)bp->b_data;
+               error = ffs_appleufs_validate(fs->fs_fsmnt, applefs, NULL);
+               if (error == 0)
+                       ret = 1;
+               brelse(bp, 0);
+       }
+#endif
+
+       return ret;
+}
+
 /*
  * Common code for mount and mountroot
  */
@@ -1016,7 +1033,6 @@
        struct buf *bp = NULL;
        struct fs *fs = NULL;
        dev_t dev;
-       struct dkwedge_info dkw;
        void *space;
        daddr_t sblockloc = 0;
        int blks, fstype = 0;
@@ -1239,42 +1255,15 @@
                brelse(bp, 0);
        bp = NULL;
 
-       /*
-        * First check to see if this is tagged as an Apple UFS filesystem
-        * in the disklabel
-        */
-       if (getdiskinfo(devvp, &dkw) == 0 &&
-           strcmp(dkw.dkw_ptype, DKW_PTYPE_APPLEUFS) == 0)
-               ump->um_flags |= UFS_ISAPPLEUFS;
+       if (ffs_is_appleufs(devvp, fs)) {
 #ifdef APPLE_UFS
-       else {
-               /*
-                * Manually look for an apple ufs label, and if a valid one
-                * is found, then treat it like an Apple UFS filesystem anyway
-                */
-               error = bread(devvp,
-                   (daddr_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE),
-                   APPLEUFS_LABEL_SIZE, 0, &bp);
-               if (error) {
-                       DPRINTF("apple bread@0x%jx returned %d",
-                           (intmax_t)(APPLEUFS_LABEL_OFFSET / DEV_BSIZE),
-                           error);
-                       goto out;
-               }
-               error = ffs_appleufs_validate(fs->fs_fsmnt,
-                   (struct appleufslabel *)bp->b_data, NULL);
-               if (error == 0)
-                       ump->um_flags |= UFS_ISAPPLEUFS;
-               brelse(bp, 0);
-               bp = NULL;
-       }
+               ump->um_flags |= UFS_ISAPPLEUFS;
 #else
-       if (ump->um_flags & UFS_ISAPPLEUFS) {
                DPRINTF("AppleUFS not supported");
                error = EINVAL;
                goto out;
-       }
 #endif
+       }
 
 #if 0
 /*

Reply via email to