Author: cperciva
Date: Wed Jun 24 04:56:13 2009
New Revision: 194807
URL: http://svn.freebsd.org/changeset/base/194807

Log:
  Add detection of UFS filesystems.
  
  PR:           bin/135565
  Submitted by: Daniel O'Connor
  Reviewed by:  randi
  MFC after:    1 month

Modified:
  head/usr.sbin/sysinstall/devices.c
  head/usr.sbin/sysinstall/ufs.c

Modified: head/usr.sbin/sysinstall/devices.c
==============================================================================
--- head/usr.sbin/sysinstall/devices.c  Wed Jun 24 04:45:03 2009        
(r194806)
+++ head/usr.sbin/sysinstall/devices.c  Wed Jun 24 04:56:13 2009        
(r194807)
@@ -421,7 +421,7 @@ skipif:
        }
     }
 
-    /* Finally, go get the disks and look for DOS partitions to register */
+    /* Finally, go get the disks and look for partitions to register */
     if ((names = Disk_Names()) != NULL) {
        int i;
 
@@ -458,7 +458,11 @@ skipif:
            if (isDebug())
                msgDebug("Found a disk device named %s\n", names[i]);
 
-           /* Look for existing DOS partitions to register as "DOS media 
devices" */
+           /* Look for existing DOS partitions to register as "DOS media 
devices"
+            * XXX: libdisks handling of extended partitions is too
+            * simplistic - it does not handle them containing (for
+            * example) UFS partitions
+            */
            for (c1 = d->chunks->part; c1; c1 = c1->next) {
                if (c1->type == fat || c1->type == efi || c1->type == extended) 
{
                    Device *dev;
@@ -470,8 +474,25 @@ skipif:
                                         mediaInitDOS, mediaGetDOS, 
mediaShutdownDOS, NULL);
                    dev->private = c1;
                    if (isDebug())
-                       msgDebug("Found a DOS partition %s on drive %s\n", 
c1->name, d->name);
+                       msgDebug("Found a DOS partition %s\n", c1->name);
+               } else if (c1->type == freebsd) {
+                   Device *dev;
+                   char devname[80];
+                   Chunk *c2;
+                       
+                   for (c2 = c1->part; c2; c2 = c2->next) {
+                       if (c2->type != part || c2->subtype != 7)
+                           continue;
+                       /* Got one! */
+                       snprintf(devname, sizeof devname, "/dev/%s", c1->name);
+                       dev = deviceRegister(c2->name, c2->name, 
strdup(devname), DEVICE_TYPE_UFS, TRUE,
+                                            mediaInitUFS, mediaGetUFS, 
mediaShutdownUFS, NULL);
+                       dev->private = c2;
+                       if (isDebug())
+                           msgDebug("Found a UFS sub-partition %s\n", 
c2->name);
+                   }
                }
+               
            }
        }
        free(names);

Modified: head/usr.sbin/sysinstall/ufs.c
==============================================================================
--- head/usr.sbin/sysinstall/ufs.c      Wed Jun 24 04:45:03 2009        
(r194806)
+++ head/usr.sbin/sysinstall/ufs.c      Wed Jun 24 04:56:13 2009        
(r194807)
@@ -39,11 +39,47 @@
 #include "sysinstall.h"
 #include <sys/fcntl.h>
 #include <sys/param.h>
+#include <sys/mount.h>
+#include <ufs/ufs/ufsmount.h>
 
-/* No init or shutdown routines necessary - all done in mediaSetUFS() */
+static Boolean UFSMounted;
+static char mountpoint[] = "/dist";
+
+Boolean
+mediaInitUFS(Device *dev)
+{
+    struct ufs_args args;
+
+    if (UFSMounted)
+       return TRUE;
+     
+    Mkdir(mountpoint);
+    memset(&args, 0, sizeof(args));
+    args.fspec = dev->devname;
+
+    if (mount("ufs", mountpoint, MNT_RDONLY, (caddr_t)&args) == -1) {
+       msgConfirm("Error mounting %s on %s: %s (%u)", args.fspec, mountpoint, 
strerror(errno), errno);
+       return FALSE;
+    }
+    UFSMounted = TRUE;
+    return TRUE;
+}
 
 FILE *
 mediaGetUFS(Device *dev, char *file, Boolean probe)
 {
     return mediaGenericGet((char *)dev->private, file);
 }
+
+void
+mediaShutdownUFS(Device *dev)
+{
+    if (!UFSMounted)
+       return;
+    if (unmount(mountpoint, MNT_FORCE) != 0)
+       msgConfirm("Could not unmount the UFS partition from %s: %s",
+                  mountpoint, strerror(errno));
+    else
+       UFSMounted = FALSE;
+    return;
+}
_______________________________________________
svn-src-all@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/svn-src-all
To unsubscribe, send any mail to "svn-src-all-unsubscr...@freebsd.org"

Reply via email to