qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] updated vqemu and lomount.c
@ 2004-06-25 19:30 Jim C. Brown
  0 siblings, 0 replies; only message in thread
From: Jim C. Brown @ 2004-06-25 19:30 UTC (permalink / raw)
  To: qemu-devel

[-- Attachment #1: Type: text/plain, Size: 416 bytes --]

BUG FIXED: lomount will now report an error if it cant find your partition
on the disk image.

vqemu now has some sanity checks in it to make sure the config file is ok.
It should also work w/o a config file. PCI option overrides ISA option.
Added floppy, harddisk, and cdrom to replace a, c, and d for the boot option.

-- 
Infinite complexity begets infinite beauty.
Infinite precision begets infinite perfection.

[-- Attachment #2: lomount.c --]
[-- Type: text/plain, Size: 2910 bytes --]

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

#define BUF 4096
#define TEMPFILE "/tmp/temp.minix"

int partnum(char * diskimage, FILE * temp, int * pnum)
{
	int num=0, c, i;
	char buf[BUF], buf2[BUF];
	strncpy(buf, diskimage, BUF);
	strncat(buf, "%d", BUF-strlen(buf));
	fscanf(temp, buf, pnum); /* skip start of line */
#ifdef DEBUG
	printf("pnum = %d\n", *pnum);
#endif
	c = fgetc(temp);
	while (c == ' ' || c == '*' || c == '@')
	{
		c = fgetc(temp);
#ifdef DEBUG
		printf("c = %d ", c);
#endif
	}
	/*ungetc(c, temp);
	fscanf(temp, "%d", &num);*/
#ifdef DEBUG
	printf("c = %d\n", c);
#endif
	buf2[0] = c;
	c = fgetc(temp);
	i = 1;
	while (c == '0' || c == '1' || c == '2' || c == '3' || c == '4' || c == '5' || c == '6' || c == '7' || c == '8' || c == '9')
	{
		buf2[i] = c;
		c = fgetc(temp);
		i++;
	}
	buf2[i] = '\0';
	num = atoi(buf2);
#ifdef DEBUG
	printf("buf2 = %s num = %d\n", buf2, num);
#endif
	fgets(buf, BUF, temp); /* skip rest of line */
	return num;
}

int main(int argc, char ** argv)
{
	FILE * temp;
	char buf[BUF], argv2[BUF], diskimage[BUF];
	int partition = 1, sec1, sec2, num = 0, pnum = 0, len = BUF, i, f = 0;
	int total_sec;
	int pressed_key=0;
	for (i = 1; i < argc; i ++)
	{
		if (strncmp(argv[i], "-diskimage", BUF)==0)
		{
			strncpy(diskimage, argv[i+1], BUF);
			i++; f = 1;
		}
		else if (strncmp(argv[i], "-partition", BUF)==0)
		{
			partition = atoi(argv[i+1]);
			i++;
			if (partition < 1) partition = 1;
		}
		else
		{
			strncat(argv2, argv[i], len);
			strncat(argv2, " ", len-1);
			len -= strlen(argv[i]);
			len--;
		}
	}
	if (!f)
	{
		printf("You must specify -diskimage and -partition\n");
		printf("ex. lomount -t fs-type -diskimage hda.img -partition 1 /mnt\n");
		return 0;
	}
	snprintf(buf, BUF, "/sbin/fdisk -lu %s > %s 2>&1", diskimage, TEMPFILE);
	system(buf);
	temp = fopen(TEMPFILE, "r");

	do
	{
		fgets(buf, BUF, temp); /* skip until we get "Disk" */
#ifdef DEBUG
		printf("spare line: %s\n", buf);
#endif
		
	} while (strncasecmp(buf, "Disk", 4)!=0);
	fgets(buf, BUF, temp); //skip once more
	fscanf(temp, "Units = sectors of %d * %d = %d bytes\n", &sec1, &sec2, &total_sec);
#ifdef DEBUG
	printf("sec1: %d sec2: %d\n", sec1, sec2);
#endif
	fgets(buf, BUF, temp); /* skip sixth line */
#ifdef DEBUG
	printf("spare line: %s\n", buf);
#endif
	while (pnum != partition)
	{
		num = partnum(diskimage, temp, &pnum);
		if (feof(temp))
		{
/* This means that we went through the entire file, but we couldn't find the
partition that we were told to mount. If we get here it means something
fishy is going on (or the user had a typo). */
			printf("Partition %d was not found in %s.\n", partition, diskimage);
			fclose(temp);
			return 1;
		}
	}
	fclose(temp);
	pnum = sec1 * sec2 * num;
#ifdef DEBUG
	printf("offset = %d\n", pnum);
#endif
	snprintf(buf, BUF, "mount -oloop,offset=%d %s %s", pnum, diskimage, argv2);
	system(buf);
	return 0;
}

[-- Attachment #3: vqemu --]
[-- Type: text/plain, Size: 3398 bytes --]

#! /bin/sh

# locate the config file
if [ "$1" = "-config" ]; then
	conffile=$2
	shift 2
else
	conffile=./.qemurc
fi

# hard-coded defaults here
qemu=
vde=off
boot=harddisk
megs=32
fda=
fdb=
hda=
hdachs=
hdb=
cdrom=
hdc=
hdd=
audio=off
pci=on
macaddr=
cirrus=off
localtime=off
usernet=off
nics=1
netscript=/etc/qemu-ifup
graphic=on

# if we have a valid config file, load it
if [ -f $conffile ]; then
	. $conffile
fi

# sanity check
if [ -z "$boot" ]; then
	echo 'Option boot must be set to floppy, harddisk, or cdrom, or'
	echo 'the decapriated options a, c, or d!'
	exit 1
fi
if [ -z "$megs" ]; then
#TODO: make sure this is a number
	echo 'Option megs must be set to a valid number!'
	exit 1
fi
if [ -z "$nics" ]; then
#TODO: make sure this is a number
	echo 'Option nics must be set to a valid number! (most likely this number will be 1)'
	exit 1
fi
if [ -z "$netscript" ]; then
	echo 'Warning: option netscript is not set. Will use /etc/qemu-ifup if asked.'
fi

#if [ "$boot" = "floppy" -o "$boot" = "a" ]; then
	#if [ -z "$fda" ]; then
		#echo 'Option fda must be set to a valid floppy image!'
		#exit 1
	#fi
#elif [ "$boot" = "harddisk" -o "$boot" = "c" ]; then
	#if [ -z "$hda" ]; then
		#echo 'Option hda must be set to a valid hard disk image!'
		#exit 1
	#fi
#elif [ "$boot" = "cdrom" -o "$boot" = "d" ]; then
	#if [ -z "$cdrom" ]; then
		#echo 'Option cdrom must be set to a valid cdrom iso image!'
		#exit 1
	#fi
#else
	# sanity check
	#echo -n "Option boot set to unknown value $boot. "
	#echo 'I don't know what to do!'
	#exit 1
#fi

# convert recommended values to the one qemu expects
if [ "$boot" = "floppy" ]; then
	boot=a
elif [ "$boot" = "harddisk" ]; then
	boot=c
elif [ "$boot" = "cdrom" ]; then
	boot=d
fi

# isa hack (Note that setting $pci overrides $isa completely)
if [ -z "$pci" ]; then
	if [ "$isa" = "on" ]; then
		pci = off
	else
		pci = on
	fi
fi

# interpret out configuration
comline=`which qemu`
if [ -n "$qemu" ]; then
	comline="$qemu"
fi
if [ "$vde" = "on" ]; then
	comline="vdeq $comline"
fi
comline="$comline -boot $boot"
comline="$comline -m $megs"
if [ -n "$fda" ]; then
	comline="$comline -fda $fda"
fi
if [ -n "$fdb" ]; then
	comline="$comline -fdb $fdb"
fi
if [ -n "$hda" ]; then
	comline="$comline -hda $hda"
fi
if [ -n "$hdachs" ]; then
	comline="$comline -hdachs $hdachs"
fi
if [ -n "$hdb" ]; then
	comline="$comline -hdb $hdb"
fi
if [ -n "$cdrom" ]; then
	comline="$comline -cdrom $cdrom"
fi
if [ -n "$hdc" ]; then
	comline="$comline -hda $hdc"
fi
if [ -n "$hdd" ]; then
	comline="$comline -hda $hdd"
fi
if [ "$audio" = "on" ]; then
	comline="$comline -enable-audio"
fi
if [ "$pci" != "on" ]; then
	comline="$comline -isa"
fi
if [ -n "$macaddr" ]; then
	comline="$comline -macaddr $macaddr"
fi
if [ "$cirrus" = "on" ]; then
	comline="$comline -cirrusvga"
fi
if [ "$localtime" = "on" ]; then
	comline="$comline -localtime"
fi
if [ "$usernet" = "on" ]; then
	comline="$comline -user-net"
elif [ "$usernet" = "dummy" ]; then
	comline="$comline -dummy-net"
fi
# Don't pass the parameter if it is the qemu default
if [ "$nics" != "1" ]; then
	comline="$comline -nics $nics"
fi
if [ -n "$netscript" ]; then
	# Don't pass the parameter if it is the qemu default
	if [ "$netscript" != "/etc/qemu-ifup" ]; then
		comline="$comline -n $netscript"
	fi
fi
if [ "$graphic" != "on" ]; then
	comline="$comline -nographic"
fi
echo $comline "$@"
exec $comline "$@"


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2004-06-25 19:35 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-06-25 19:30 [Qemu-devel] updated vqemu and lomount.c Jim C. Brown

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).