From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1BdwTs-0008AY-W5 for qemu-devel@nongnu.org; Fri, 25 Jun 2004 15:35:25 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1BdwTs-0008AM-Be for qemu-devel@nongnu.org; Fri, 25 Jun 2004 15:35:24 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1BdwTs-0008AJ-7d for qemu-devel@nongnu.org; Fri, 25 Jun 2004 15:35:24 -0400 Received: from [38.113.3.61] (helo=babyruth.hotpop.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BdwSC-00018R-Jd for qemu-devel@nongnu.org; Fri, 25 Jun 2004 15:33:40 -0400 Received: from phreaker.net (kubrick.hotpop.com [38.113.3.103]) by babyruth.hotpop.com (Postfix) with SMTP id F0BD966DAC4 for ; Fri, 25 Jun 2004 18:53:05 +0000 (UTC) Received: from jbrown.mylinuxbox.org (pcp03144805pcs.midval01.tn.comcast.net [68.59.228.236]) by smtp-1.hotpop.com (Postfix) with ESMTP id 299FB1A01F3 for ; Fri, 25 Jun 2004 18:30:47 +0000 (UTC) Date: Fri, 25 Jun 2004 15:30:43 -0400 From: "Jim C. Brown" Message-ID: <20040625193042.GA10063@jbrown.mylinuxbox.org> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="DocE+STaALJfprDB" Content-Disposition: inline Subject: [Qemu-devel] updated vqemu and lomount.c Reply-To: qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --DocE+STaALJfprDB Content-Type: text/plain; charset=us-ascii Content-Disposition: inline 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. --DocE+STaALJfprDB Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="lomount.c" #include #include #include #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; } --DocE+STaALJfprDB Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename=vqemu #! /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 "$@" --DocE+STaALJfprDB--