From daf18f9631bdf96db3941fb37ecee3310bd64220 Mon Sep 17 00:00:00 2001 From: cperciva Date: Wed, 24 Jun 2009 04:56:13 +0000 Subject: Add detection of UFS filesystems. PR: bin/135565 Submitted by: Daniel O'Connor Reviewed by: randi MFC after: 1 month --- usr.sbin/sysinstall/devices.c | 27 ++++++++++++++++++++++++--- usr.sbin/sysinstall/ufs.c | 38 +++++++++++++++++++++++++++++++++++++- 2 files changed, 61 insertions(+), 4 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/sysinstall/devices.c b/usr.sbin/sysinstall/devices.c index b742c69..e78c268 100644 --- a/usr.sbin/sysinstall/devices.c +++ b/usr.sbin/sysinstall/devices.c @@ -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); diff --git a/usr.sbin/sysinstall/ufs.c b/usr.sbin/sysinstall/ufs.c index c9515ae..d8a6fcf 100644 --- a/usr.sbin/sysinstall/ufs.c +++ b/usr.sbin/sysinstall/ufs.c @@ -39,11 +39,47 @@ #include "sysinstall.h" #include #include +#include +#include -/* 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; +} -- cgit v1.1