From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.33) id 1Bbtbh-0000PG-6U for qemu-devel@nongnu.org; Sun, 20 Jun 2004 00:07:01 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.33) id 1Bbtbg-0000Ou-JF for qemu-devel@nongnu.org; Sun, 20 Jun 2004 00:07:00 -0400 Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.33) id 1Bbtbg-0000Op-Gg for qemu-devel@nongnu.org; Sun, 20 Jun 2004 00:07:00 -0400 Received: from [38.113.3.51] (helo=snickers.hotpop.com) by monty-python.gnu.org with esmtp (Exim 4.34) id 1BbtaH-00019N-J7 for qemu-devel@nongnu.org; Sun, 20 Jun 2004 00:05:33 -0400 Received: from phreaker.net (kubrick.hotpop.com [38.113.3.103]) by snickers.hotpop.com (Postfix) with SMTP id 806DF71EBA for ; Sun, 20 Jun 2004 03:04:25 +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 922D71A7498 for ; Sat, 19 Jun 2004 22:49:50 +0000 (UTC) Date: Sat, 19 Jun 2004 19:48:35 -0400 From: "Jim C. Brown" Subject: Re: [Qemu-devel] Mounting a disk image under Linux Message-ID: <20040619234835.GA14521@jbrown.mylinuxbox.org> References: <1087396951.40d05c57252a0@www.raysa.org> <40D0AD00.7050207@silentsoftware.co.uk> <40D0B569.8070204@bellard.org> <40D0BE89.4070904@silentsoftware.co.uk> <40D46B1B.9070704@silentsoftware.co.uk> <20040619173111.GB11948@jbrown.mylinuxbox.org> <1087675230.9477.296.camel@sherbert> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="h31gzZEtNLTqOjlF" Content-Disposition: inline In-Reply-To: <1087675230.9477.296.camel@sherbert> 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 --h31gzZEtNLTqOjlF Content-Type: text/plain; charset=us-ascii Content-Disposition: inline On Sat, Jun 19, 2004 at 09:00:30PM +0100, Gianni Tedesco wrote: > On Sat, 2004-06-19 at 13:31 -0400, Jim C. Brown wrote: > > lomount -t vfat -diskimage /opt/qemu/tempImage -partition 1 /mnt/tempImage > > > > It works great but has a bug if you try to mount a partition which doesnt > > exist. > > Sounds great. Perhaps it could be included with qemu, (at least in souce > dist!)? Sure. I have no problems with that. > > Do you want to post it on the list to fix it? Or have you just not had > time? I wrote it in under an hour, right before I went to bed. I've attached the source code here but be warned: its very ugly. Very little error checking. Expects fdisk to work right (which in turns means it assumes fdisk is being passed a valid image with a valid parition table). When I have some free time I'll try to clean it up. Right now it's full of ugly hacks. (It was originally meant to be a shell script not a C program, only my shell programming skills did not extend so far.) > > -- > // Gianni Tedesco (gianni at scaramanga dot co dot uk) > lynx --source www.scaramanga.co.uk/scaramanga.asc | gpg --import > 8646BE7D: 6D9F 2287 870E A2C9 8F60 3A3C 91B5 7669 8646 BE7D > _______________________________________________ > Qemu-devel mailing list > Qemu-devel@nongnu.org > http://lists.nongnu.org/mailman/listinfo/qemu-devel -- Infinite complexity begets infinite beauty. Infinite precision begets infinite perfection. --h31gzZEtNLTqOjlF Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="lomount.c" #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; 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, "fdisk -lu %s > %s 2>&1", diskimage, TEMPFILE); system(buf); temp = fopen(TEMPFILE, "r"); fgets(buf, BUF, temp); /* skip first line */ #ifdef DEBUG printf("spare line: %s\n", buf); #endif fgets(buf, BUF, temp); /* skip second line */ #ifdef DEBUG printf("spare line: %s\n", buf); #endif fgets(buf, BUF, temp); /* skip third line */ #ifdef DEBUG printf("spare line: %s\n", buf); #endif fgets(buf, BUF, temp); /* skip fourth line */ #ifdef DEBUG printf("spare line: %s\n", buf); #endif fscanf(temp, "Units = sectors of %d * %d bytes\n", &sec1, &sec2); #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); } fclose(temp); pnum = sec1 * sec2 * num; #ifdef DEBUG printf("offset = %d\n", pnum); #endif snprintf(buf, BUF, "echo mount -oloop,offset=%d %s %s", pnum, diskimage, argv2); return system(buf); } --h31gzZEtNLTqOjlF--