Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1KxiwD-00038L-Gf for qemu-devel@nongnu.org; Wed, 05 Nov 2008 09:00:49 -0500 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1KxiwA-00037f-V7 for qemu-devel@nongnu.org; Wed, 05 Nov 2008 09:00:48 -0500 Received: from [199.232.76.173] (port=41373 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1KxiwA-00037c-OW for qemu-devel@nongnu.org; Wed, 05 Nov 2008 09:00:46 -0500 Received: from smtp-out3.tiscali.nl ([195.241.79.178]:39776) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1Kxiw9-0001WS-WA for qemu-devel@nongnu.org; Wed, 05 Nov 2008 09:00:46 -0500 Received: from [212.123.169.34] (helo=[192.168.1.42]) by smtp-out3.tiscali.nl with esmtp id 1Kxiw4-00065b-DD for ; Wed, 05 Nov 2008 15:00:40 +0100 From: Paul Bolle Content-Type: text/plain Date: Wed, 05 Nov 2008 15:00:38 +0100 Message-Id: <1225893639.2813.13.camel@test.thuisdomein> Mime-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] [PATCH][VVFAT] Print meaningful error on oversized directories 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 There are size limits for directories to be used for vvfat disk images. These size limits seem to be undocumented. Moreover, going over those size limits will return in a cryptic assert error, which basically hides the actual problem. Below is a patch to correct that. Paul Bolle --- Currently trying to turn an oversized directory into a VVFAT image will result in a cryptic error (and an abort): qemu: block-vvfat.c:97: array_get: Assertion `index < array->next' failed. Aborted Turn this into an actually useful error message: Directory does not fit in FAT16 (capacity 504MB) qemu: could not open disk image fat:$DIR/ Signed-off-by: Paul Bolle diff --git a/block-vvfat.c b/block-vvfat.c index 9e2841a..5fcf746 100644 --- a/block-vvfat.c +++ b/block-vvfat.c @@ -890,7 +890,6 @@ static int init_directories(BDRVVVFATState* s, s->path = mapping->path; for (i = 0, cluster = 0; i < s->mapping.next; i++) { - int j; /* MS-DOS expects the FAT to be 0 for the root directory * (except for the media byte). */ /* LATER TODO: still true for FAT32? */ @@ -923,20 +922,25 @@ static int init_directories(BDRVVVFATState* s, assert(mapping->begin < mapping->end); + /* next free cluster */ + cluster = mapping->end; + + if(cluster > s->cluster_count) { + fprintf(stderr,"Directory does not fit in FAT%d (capacity %s)\n", + s->fat_type, + s->fat_type == 12 ? s->sector_count == 2880 ? "1.44 MB" + : "2.88 MB" + : "504MB"); + return -EINVAL; + } + /* fix fat for entry */ if (fix_fat) { + int j; for(j = mapping->begin; j < mapping->end - 1; j++) fat_set(s, j, j+1); fat_set(s, mapping->end - 1, s->max_fat_value); } - - /* next free cluster */ - cluster = mapping->end; - - if(cluster > s->cluster_count) { - fprintf(stderr,"Directory does not fit in FAT%d\n",s->fat_type); - return -1; - } } mapping = array_get(&(s->mapping), 0);